|
| 1 | +# OpenDataHub-Tests Constitution |
| 2 | + |
| 3 | +This constitution defines the non-negotiable principles and governance rules for the opendatahub-tests repository. It applies to all test development, whether performed by humans or AI assistants. |
| 4 | + |
| 5 | +## Core Principles |
| 6 | + |
| 7 | +### I. Simplicity First |
| 8 | + |
| 9 | +All changes MUST favor the simplest solution that works. Complexity MUST be justified. |
| 10 | + |
| 11 | +- Aim for the simplest solution that works while keeping the code clean |
| 12 | +- Do not prepare code for the future just because it may be useful (YAGNI) |
| 13 | +- Every function, variable, fixture, and test written MUST be used, or else removed |
| 14 | +- Flexible code MUST NOT come at the expense of readability |
| 15 | + |
| 16 | +**Rationale**: The codebase is maintained by multiple teams; simplicity ensures maintainability and reduces cognitive load. |
| 17 | + |
| 18 | +### II. Code Consistency |
| 19 | + |
| 20 | +All changes MUST follow existing code patterns and architecture. |
| 21 | + |
| 22 | +- Follow the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html) |
| 23 | +- Use pre-commit hooks to enforce style (ruff, mypy, flake8) |
| 24 | +- Use absolute import paths; import specific functions rather than modules |
| 25 | +- Use descriptive names; meaningful names are better than short names |
| 26 | +- Add type annotations to all new code; follow the rules defined in [pyproject.toml](./pyproject.toml) |
| 27 | + |
| 28 | +**Rationale**: Consistent patterns reduce the learning curve and prevent architectural drift. |
| 29 | + |
| 30 | +### III. Test Clarity and Dependencies |
| 31 | + |
| 32 | +Each test MUST verify a single aspect of the product and may be dependent on other tests. |
| 33 | + |
| 34 | +- Tests MUST have a clear purpose and be easy to understand |
| 35 | +- Tests MUST be properly documented with docstrings explaining what the test does |
| 36 | +- When test dependencies exist, use pytest-dependency plugin to declare them explicitly, encourage use of dependency marker(s) when possible |
| 37 | +- Group related tests in classes only when they share fixtures; never group unrelated tests |
| 38 | + |
| 39 | +### IV. Fixture Discipline |
| 40 | + |
| 41 | +Fixtures MUST do one thing only and follow proper scoping. |
| 42 | + |
| 43 | +- Fixture names MUST be nouns describing what they provide (e.g., `storage_secret` not `create_secret`) |
| 44 | +- Fixtures MUST handle setup and teardown using context managers where appropriate |
| 45 | +- Use the narrowest fixture scope that meets the need (function > class > module > session) |
| 46 | +- Conftest.py files MUST contain fixtures only; no utility functions or constants |
| 47 | +- Use `request.param` with dict structures for parameterized fixtures |
| 48 | + |
| 49 | +**Rationale**: Single-responsibility fixtures are easier to debug, reuse, and compose. |
| 50 | + |
| 51 | +### V. Interacting with Kubernetes Resources |
| 52 | + |
| 53 | +All cluster interactions MUST use openshift-python-wrapper or oc CLI. |
| 54 | + |
| 55 | +- Use [openshift-python-wrapper](https://github.com/RedHatQE/openshift-python-wrapper) for all K8s API calls |
| 56 | +- For missing resources, generate them using class_generator and contribute to wrapper |
| 57 | +- Use oc CLI only when wrapper is not relevant (e.g., must-gather generation) |
| 58 | +- Resource lifecycle MUST be managed via context managers to ensure cleanup |
| 59 | + |
| 60 | +**Rationale**: Consistent API abstraction ensures portability between ODH (upstream) and RHOAI (downstream). |
| 61 | + |
| 62 | +### VI. Locality of Behavior |
| 63 | + |
| 64 | +Keep code close to where it is used. |
| 65 | + |
| 66 | +- Keep functions and fixtures close to where they're used initially |
| 67 | +- Move to shared locations (utilities, common conftest) only when multiple modules need them |
| 68 | +- Avoid creating abstractions prematurely |
| 69 | +- Small, focused changes are preferred unless explicitly asked otherwise |
| 70 | + |
| 71 | +**Rationale**: Locality reduces navigation overhead and makes the impact of changes obvious. |
| 72 | + |
| 73 | +### VII. Security Awareness |
| 74 | + |
| 75 | +All code MUST consider security implications. |
| 76 | + |
| 77 | +- Never log/expose secrets; redact/mask if printing is unavoidable |
| 78 | +- Avoid running destructive commands without explicit user confirmation |
| 79 | +- Use detect-secrets and gitleaks pre-commit hooks to prevent secret leakage |
| 80 | +- Test code MUST NOT introduce vulnerabilities into the tested systems |
| 81 | + |
| 82 | +**Rationale**: Tests interact with production-like clusters; security lapses can have real consequences. |
| 83 | + |
| 84 | +## Test Development Standards |
| 85 | + |
| 86 | +### Test Documentation |
| 87 | + |
| 88 | +- Every test or test class MUST have a docstring explaining what it tests |
| 89 | +- Docstrings MUST be understandable by engineers from other components, managers, or PMs |
| 90 | +- Use Google-format docstrings |
| 91 | +- Comments are allowed only for complex code blocks (e.g., complex regex) |
| 92 | + |
| 93 | +### Test Markers |
| 94 | + |
| 95 | +- All tests MUST apply relevant markers from pytest.ini |
| 96 | +- Use tier markers (smoke, sanity, tier1, tier2) to indicate test priority |
| 97 | +- Use component markers (model_explainability, llama_stack, rag) for ownership |
| 98 | +- Use infrastructure markers (gpu, parallel, slow) for execution filtering |
| 99 | + |
| 100 | +### Test Organization |
| 101 | + |
| 102 | +- Tests are organized by component in `tests/<component>/` |
| 103 | +- Each component has its own conftest.py for scoped fixtures |
| 104 | +- Utilities go in `utilities/` with topic-specific modules |
| 105 | + |
| 106 | +## AI-Assisted Development Guidelines |
| 107 | + |
| 108 | +### Developer Responsibility |
| 109 | + |
| 110 | +Developers are ultimately responsible for all code, regardless of whether AI tools assisted. |
| 111 | + |
| 112 | +- Always assume AI-generated code is unsafe and incorrect until verified |
| 113 | +- Double-check all AI suggestions against project patterns and this constitution |
| 114 | +- AI tools MUST be guided by AGENTS.md (symlink to CLAUDE.md if needed) |
| 115 | + |
| 116 | +### AI Code Generation Rules |
| 117 | + |
| 118 | +- AI MUST follow existing patterns; never introduce new architectural concepts without justification |
| 119 | +- AI MUST NOT add unnecessary complexity or "helpful" abstractions |
| 120 | +- AI-generated tests MUST have proper docstrings and markers |
| 121 | +- AI MUST ask when in doubt about requirements or patterns |
| 122 | + |
| 123 | +### Specification-Driven Development |
| 124 | + |
| 125 | +When adopting AI-driven spec development: |
| 126 | + |
| 127 | +- Specifications MUST be in structured format (YAML/JSON with defined schema) |
| 128 | +- Tests MUST include requirement traceability (Polarion, Jira markers) |
| 129 | +- Docstrings MUST follow Given-When-Then pattern for behavioral clarity |
| 130 | +- Generated tests MUST pass pre-commit checks before review |
| 131 | + |
| 132 | +## Governance |
| 133 | + |
| 134 | +### Constitution Authority |
| 135 | + |
| 136 | +This constitution supersedes all other practices when there is a conflict. All PRs and reviews MUST verify compliance. |
| 137 | + |
| 138 | +### Amendment Process |
| 139 | + |
| 140 | +1. Propose changes via PR to `CONSTITUTION.md` |
| 141 | +2. Changes require review by at least two maintainers |
| 142 | +3. Breaking changes (principle removal/redefinition) require team discussion |
| 143 | + |
| 144 | +### Versioning Policy |
| 145 | + |
| 146 | +No versioning policy is enforced. |
| 147 | + |
| 148 | +### Compliance Review |
| 149 | + |
| 150 | +- All PRs MUST be verified against constitution principles |
| 151 | +- Pre-commit hooks enforce code quality standards |
| 152 | +- CI (tox) validates test structure and typing |
| 153 | +- Two reviewers required; verified label required before merge |
| 154 | + |
| 155 | +### Guidance Reference |
| 156 | + |
| 157 | +For development runtime guidance, consult: |
| 158 | +- [AGENTS.md](./AGENTS.md) for AI assistant instructions |
| 159 | +- [DEVELOPER_GUIDE.md](./docs/DEVELOPER_GUIDE.md) for contribution details |
| 160 | +- [STYLE_GUIDE.md](./docs/STYLE_GUIDE.md) for code style |
| 161 | + |
| 162 | +**Version**: 1.0.0 | **Ratified**: 2026-01-08 | **Last Amended**: 2026-01-08 |
0 commit comments