Skip to content

[architect] refactor: enforce elements/targets.json image_paths ownership invariant in tests/test_catalog_conformance.py - #218

Open
kubestellar-hive[bot] wants to merge 1 commit into
mainfrom
arch/targets-path-ownership-invariant
Open

[architect] refactor: enforce elements/targets.json image_paths ownership invariant in tests/test_catalog_conformance.py#218
kubestellar-hive[bot] wants to merge 1 commit into
mainfrom
arch/targets-path-ownership-invariant

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

Refactor

Claimed ground: tests/test_catalog_conformance.py only (one new class,
PathOwnershipTests). No other file is touched — not elements/targets.json, not the
Justfile, not any workflow.

Cluster: the elements/targets.json manifest-integrity cluster (issue #217).

What this changes structurally

elements/targets.json calls itself the single source of truth, but it holds two
independent structures that must agree and only one was enforced:

structure consumer enforced before this PR
oci_images build/manifest matrices yes — CatalogCoverageTests, both directions against catalog/
image_paths just changed-targets (Justfile:154-216) no

changed-targets selects an image only when a changed file matches one of its
image_paths prefixes. An image absent from image_paths, or whose prefixes miss the
files that actually define it, can never be selected — and the pull-request build gate
then fails open, reporting success having built nothing. That is precisely the
regression class the changed-targets job was introduced to prevent (see the comment in
.github/workflows/build.yml: "a PR could be green while main went red on the merge
commit — which is exactly what happened, repeatedly").

PathOwnershipTests closes the loop with five assertions:

  1. every image in oci_images has an image_paths entry;
  2. every image_paths key is in oci_images;
  3. each image owns the four files that define it — catalog/<n>.yaml,
    elements/oci/<n>.bst, and the <n>-runtime.bst / <n>-stack.bst that
    scripts/generate_image_elements.py emits from its record;
  4. no image claims another image's defining files;
  5. shared_paths still lists the gate's own inputs, and canary_image is published.

Assertion 3 reuses the prefix/exact-match semantics of the changed-targets recipe
(*/ is a directory prefix, anything else is an exact path) so the test measures the
real selector rather than an idealised one.

Why no other file changes

The committed manifest already satisfies all five assertions — this is enforcement of an
existing invariant, not a change to it. tests/test_catalog_conformance.py is already
picked up by the test_catalog*.py discovery pattern in both just catalog-check and
.github/workflows/image-catalog.yml, which already triggers on elements/** and
catalog/**. So no Justfile recipe and no workflow trigger needs editing.

Verification

$ python3 -m unittest discover -s tests -p test_catalog*.py
Ran 25 tests in 0.405s
OK

Mutation-checked — each assertion was confirmed to actually fail:

  • dropping qemu-img from image_paths"images in oci_images with no image_paths
    entry: their pull-request build gate can never select them"
  • narrowing python to only elements/oci/python.bst"python does not own
    catalog/python.yaml: a change to it would select no build target"

elements/targets.json was restored after each mutation; the diff is one file, +101/-0.

Refs #217


Filed by architect agent (ACMM L5 — hold-gated mode). Hold-gated: human review required.

— hive: agent=architect backend=copilot model=claude-opus-5

…ship invariant

elements/targets.json holds two independent structures that must agree:
oci_images (matrix membership, cross-checked against catalog/ in both
directions) and image_paths (path ownership consumed by the Justfile
changed-targets recipe). Only the first was enforced.

changed-targets selects an image only when a changed file matches one of
its image_paths prefixes, so an image missing from image_paths -- or whose
prefixes do not cover the files that define it -- can never be selected.
The pull-request build gate then fails open: it reports success having
built nothing, which is the exact regression class that job was added to
prevent.

Add PathOwnershipTests to tests/test_catalog_conformance.py asserting
oci_images and image_paths are the same set both directions, that each
image owns its catalog record and its three generated elements, that no
image claims another's defining files, that shared_paths still lists the
gate's own inputs, and that canary_image is published. The ownership
assertion reuses the prefix/exact-match semantics of the changed-targets
recipe so it measures the real selector.

No behaviour change and no manifest edit: the committed manifest already
satisfies every assertion. The file is already discovered by the existing
test_catalog*.py pattern in image-catalog.yml and 'just catalog-check',
so no workflow or Justfile change is needed.

Refs #217

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sec-check[bot] <sec-check[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/architect Approved by a Hive merger/owner for auto-merge on green CI hive/hosted-projectbluefin-knuckle-gjvq Approved by a Hive merger/owner for auto-merge on green CI hold Work is intentionally paused.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants