Fix a failing architecture gate#
tests/unit/architecture/ holds the structural contracts of the code. CI runs it as the
job Architecture / layers, surface and two threads. It fails when an import, a
declaration or an allowlist no longer matches the contract, and the failure names the rule.
The list of every rule, with the file that holds it, is generated in
Architecture gates. This page says what to do for the common failures.
Run it#
python -m pytest tests/unit/architecture -q -n 2
To run one rule, name the file and select the test with -k. Most rules live in
test_layers.py (who reads whom), test_run_path.py (what the path of a run reads and
writes), test_surfaces.py (what is public and held) and test_code_rules.py (the
code rules that the syntax alone can check). The test name of the first failure says
which rule broke.
What to do, by failing test#
test_layers.py, the layer matrix“N layer-matrix violations: solver -> data 3 via from”. An import crosses a layer boundary that
layer_matrix.yamldoes not grant. The message counts the edges by pair, without the lines. List them:python - <<'PY' import pathlib from tools.audit.build_graph import scan_package for e in scan_package(pathlib.Path("hydromodpy")): if (e.src_pkg, e.tgt_pkg) == ("solver", "data"): print(f"{e.src_file}:{e.lineno} {e.kind} {e.target_module}") PY
Replace the pair with the one in the message, then fix the import. Move the symbol down to a layer both sides may import, often
core, or call it through a port the lower layer defines. Never add the edge to the YAML to make the test pass, because a new edge that breaks the matrix is a regression and needs an issue first. An import underTYPE_CHECKINGor inside a function counts like any other. The layers are rendered in Layer graph.test_layers.py, the generated matrix pageThe committed fragment is stale against the YAML. Run
python -m tools.doc_contractsand commit the result.test_package_layouts.pyA package with a
<package>_layout.yamlorders its parts, and a part may import only the parts in its row. The message names the part and the import. Either move the import, or, if the dependency is real, reorder the rows in the layout file and the sentences of the package page together. A row may name only rows above it, so a cycle cannot be declared. Another layer may import only the modules listed underpublic.test_layers.py, a port that stands aloneA port promises a third-party plugin that it needs nothing of HydroModPy beyond the port module and its contracts. Remove the import. A source must not reach a manager, a catalog or a workspace.
test_layers.py, the storage boundaryA direct
duckdb.connectoutside the files the rule allows. Go through the catalog or cache adapter, as Direct DuckDB access says.test_layers.py, private solver attributesA private name (
obj._name) read insidesolver/<package>/must be declared in that same sub-package. Expose the value through a public method or field of the owner. The two MODFLOW backends and the shared helpers are held to it.test_run_path.py, the payload keys of a stepA pipeline step declares the payload keys it reads and writes, as the class attributes
readsandwrites, and they must match what its code touches, in both directions. Edit the two tuples of the step. A key the step no longer touches must go.test_run_path.py, what a solver adapter readsA flow adapter reads the
Model, its options and itsRunSlot, and nothing ofctx.stateorctx.store. A transport adapter reads the viewctx.state, the runs inctx.upstreamand the catalog handlectx.store. A module that really needs a registry goes to the short allowlist of the test, a decision to state in the pull request.test_surfaces.py, typed exceptionsraise ValueErrorandraise RuntimeErrorare banned in the modules of itsSCOPE. Raise a typed exception fromhydromodpy.core.exceptions. Add a module toSCOPEonce it is clean.test_surfaces.py, one source for tolerancesA
tol('<slug>')call that matches no row oftests/TOLERANCES.md, or a documented scalar that is written inline again. Fix the slug, or add the row to the table, and read the value throughtol().test_surfaces.py, Whitebox tests run seriallyA CI step runs a Whitebox-backed test file in parallel. Exclude the file from the parallel step and keep it in the serial one. See Run the tests.
test_surfaces.py, no legacy surfaceA retired name appears in the docs, the examples, the package or the tests. Delete it.
When the contract is what is wrong#
Sometimes the code is right and the contract is old. The contract files are
layer_matrix.yaml and the *_layout.yaml files. Change them in a pull request of their
own that says why, then run python -m tools.doc_contracts. Never add an edge silently.