Debian Codegraph @

ansible_collections/community/clickhouse/AGENTS.md

raw
1 # AGENTS.md
2
3 This file is intended for AI coding agents. It is kept human-readable so contributors can also use it as a quick-reference guide.
4
5 When official documentation is not explicitly provided or it's insufficient, you MUST delegate to the `docs-explorer` subagent (see `.agents/subagents/docs-explorer.md`) to look up current official documentation for the relevant libraries and technologies.
6
7 ## What This Project Is
8
9 An Ansible collection (`community.clickhouse`) providing modules for managing ClickHouse databases. No roles exist — only modules and shared utilities.
10 To save your session context, see `SPEC.md` for full technical reference only if needed or asked explicitly.
11
12 ## Development Environment
13
14 The collection must reside at `ansible_collections/community/clickhouse/` (relative to a directory on `ANSIBLE_COLLECTIONS_PATHS`) for imports to resolve correctly.
15
16 All required packages are listed in `requirements.txt`.
17
18 For test commands, patterns, and requirements see `.agents/skills/run-tests/SKILL.md`.
19
20 ## Architecture
21
22 ### Shared Foundation
23
24 Every module follows the same bootstrap pattern:
25
26 ```python
27 argument_spec = client_common_argument_spec() # from module_utils/clickhouse.py
28 argument_spec.update({...}) # module-specific params
29 module = AnsibleModule(argument_spec=argument_spec, ...)
30 check_clickhouse_driver(module)
31 client = connect_to_db_via_client(module, ...)
32 ```
33
34 Connection parameters (`login_host`, `login_port`, `login_user`, `login_password`, `login_db`, `client_kwargs`) are defined once in `plugins/doc_fragments/client_inst_opts.py` and shared via `extends_documentation_fragment`.
35
36 ### Idempotency Pattern
37
38 State-management modules (db, user, role, quota, grants) all follow: query `system.*` table → compare current vs desired → execute DDL only if different → return `executed_statements`. The comparison logic lives in module-level classes (e.g., `ClickHouseDB`, `ClickHouseUser`).
39
40 ### check_mode
41
42 All modules support `check_mode` except `clickhouse_client` (which executes arbitrary SQL and cannot know whether it changes state). In check_mode, modules populate `executed_statements` with what *would* run.
43
44 ### clickhouse_client Type Conversion
45
46 Query results containing `uuid.UUID`, `decimal.Decimal`, or `ipaddress.IPv4/IPv6Address` are converted to `str` before returning to Ansible (these types are not JSON-serializable by Ansible's output layer).
47
48 ## Coding Guidelines
49
50 - Follow these software development principles: KISS (Keep It Simple, Stupid), DRY (Don't Repeat Yourself), YAGNI (You Aren't Gonna Need It), Separation of Concerns, Composition over Inheritance, and Convention Over Configuration.
51 - Prioritize code simplicity and readability over flexibility.
52 - Favor simple, short, and easily testable functions with no side effects over classes. Use classes only when they naturally fit the problem and help avoid boilerplate code while grouping tightly related functionality.
53 - Use `snake_case` for all variable and parameter names.
54 - Shared code used by multiple modules belongs in `plugins/module_utils/clickhouse.py` (DRY principle). Do not duplicate connection or utility logic in individual modules.
55 - Do not add connection parameters to individual modules. Extend the `client_inst_opts` doc fragment in `plugins/doc_fragments/client_inst_opts.py` instead.
56 - All modules must pass sanity, unit, and integration tests before merging.
57 - Keep each piece of work focused on solving a single, specific issue or task. Do not mix unrelated changes (e.g., a bugfix and an unrelated refactoring) in the same branch or PR.
58 - Use conventional commit message prefixes: `feat:`, `fix:`, `docs:`, `test:`, `refactor:`, `chore:`, `ci:`. Example: `fix: handle empty database list in clickhouse_info`.
59
60 ## Development Conventions
61
62 - Every new module parameter and new module requires `version_added: 'x.y.z'` in its DOCUMENTATION block, set to the next planned release version.
63 - Every PR that changes module behavior needs a changelog fragment in `changelogs/fragments/<something>.yaml`. Docs/tests/refactoring PRs are exempt. Valid fragment sections: `major_changes`, `minor_changes`, `bugfixes`, `breaking_changes`, `deprecated_features`, `removed_features`, `security_fixes`, `known_issues`. Fragments are consumed (deleted) at release time (`keep_fragments: false` in `changelogs/config.yaml`).
64 - Tests are required for code changes; see `.agents/skills/run-tests/SKILL.md` for test commands, patterns, and requirements.
65
66 ## Subagents
67
68 Subagent definitions live in `.agents/subagents/`. When a task matches a subagent's trigger conditions, delegate to it.
69
70 - `.agents/subagents/docs-explorer.md` — documentation lookup for external libraries/tools
71
72 ## Agent Skills
73
74 Skills live in `.agents/skills/*/SKILL.md` (YAML frontmatter + instructions). At session start, scan and register all skills. When a request matches a skill's trigger, load and apply it.