Skip to content

🔧 fix(test): derive the ui-removal scan set from tracked files - #338

Merged
konih merged 3 commits into
mainfrom
lane/gate-uiref-01-r4
Aug 30, 2026
Merged

konih merged 3 commits into
mainfrom
lane/gate-uiref-01-r4

Conversation

@konih

@konih konih commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

GATE-UIREF-01 — derive the UI-removal scan set from tracked files

hack/test/ui_removal_reference_test.sh built its content-scan set with find against a
hardcoded prune denylist that omitted the gitignored kollect-repos/ and .cursor/, so the
UI-removal gate redded on a maintainer's machine and nowhere else — structurally invisible
on CI, whose fresh clone has neither directory.

The lane derives the scan set from tracked files (git ls-files) instead, keeping the
forbidden_paths working-tree existence probes intact.

Verification

  • Scan-set equivalence: 601 files, symmetric difference 0.
  • All 440 files the old scan covered and the new one does not are gitignored, with an
    empty untracked-but-not-ignored casualty set.
  • Round 2 additionally closed a P0/P1 pair that the self-test's new git calls had introduced —
    hostile git environment variables could destroy the ambient index or make the gate pass
    vacuously — by sanitising the git environment. A fresh reviewer probed 20 git env vars
    (14 outside the unset list) and found no remaining vector.

Scope

Exactly one file: hack/test/ui_removal_reference_test.sh (mode 100755). Zero Go files.

Local gates on the rebased head

  • bash hack/test/ui_removal_reference_test.sh → ui removal reference: ok, 18 ok - self-test lines, self-test ok
  • task lint:shell → pass
  • task lint → 0 issues. + go-arch-lint: OK - No warnings found
  • task verify → verify: ok

Review status

lane/gate-uiref-01-r2 was APPROVED by an independent reviewer. -r3 is a commit-message-only
rebuild — tree hash identical (33d2026e3910c36f7328ba63b1fe5f82edcfee90), empty diff against
-r2. -r4 is -r3 rebased onto current main; the blob for the single changed file is
unchanged (6dfe831d771e624d58a0f9963d9079a1c0e64fe1).

konih added 3 commits August 30, 2026 09:28
The content scan walked the WORKING TREE with `find` and a hardcoded prune list.
That list is a denylist of remembered paths, not a statement of what the repo
contains, so any gitignored directory nobody thought to add carried untracked
files into the scan. Two of them exist on a maintainer's checkout today --
`kollect-repos/` (a nested kollect-lab checkout) and `.cursor/` -- and both hold
the literal `kollect-ui`, so the gate redded with 12 hits across 7 files:

  ./kollect-repos/kollect-lab/platform/manifests/kollect/lab-values.yaml:36:    repository: kollect-ui
  ./kollect-repos/kollect-lab/scripts/kollect-install.sh:37:  docker build -t kollect-ui:dev "${KOLLECT_SRC}/ui"
  ./kollect-repos/kollect-lab/scripts/logs.sh:35:  kollect-ui)
  ./kollect-repos/kollect-lab/PROPOSAL.md:21:| P-OP-01 | Fix **kollect-ui** nginx writable dirs [...]
  ./.cursor/skills/kollect-coordinator/SKILL.md:35:| **ui** | `ui/**`, `charts/kollect-ui/**` | **Frozen** [...]
  ui removal reference: residual product UI references remain (see above)

Five of the twelve hits are shown; the other seven are elided, and `[...]`
marks a line truncated for width. Captured read-only from the maintainer's
checkout at /Users/A242168/Projects/PlatformRelay/kollect on 2026-08-30 by
running main's verbatim find | grep | awk pipeline against it -- nothing was
written and no git command was run.

A fresh CI clone has neither directory, so this was structurally invisible on CI
and fired only locally -- exactly where a false red destroys trust in the gate
matrix. A 2026-08-23 session hit it, misread it as a stray `ui/` directory, and
left it in place.

The scan set now comes from `git ls-files`, the same set CI sees. On this
checkout old and new sets are identical (601 files, empty symmetric difference),
so no coverage was traded away; the three `find` exclusions are ported with
their original meaning (CHANGELOG.md by basename at any depth, and the demo
helper and this script without the `./` prefix `ls-files` does not emit).
`--others --exclude-standard` is deliberately not added: widening the set back
to the working tree is how the local-only failure mode returns.

The forbidden_paths probes still read the working tree on purpose -- a
re-created `ui/` must red whether or not anyone staged it.

A scan that silently covers nothing would be worse than the bug, so a missing
git, a non-repository root, a root that is not its repository's toplevel, an
empty scan set and a scan set that has lost its mkdocs.yml anchor are all hard
failures. Equality against `rev-parse --show-toplevel` rather than
`--is-inside-work-tree` is load-bearing: the latter walks upward, so a plain
directory nested in a checkout resolves to the parent's toplevel and the scan no
longer describes the directory under test.

Because a CI clone cannot reproduce the regression, the gate now builds
throwaway fixture repositories and re-proves all four directions on every run:
gitignored noise is ignored, a tracked file reintroducing product-UI wiring
still reds and names itself, an untracked `ui/` still reds, and each unusable
scan set fails with its own message. The ignored-noise fixture is guarded twice
-- the files must really be gitignored and must really carry a forbidden literal
-- so accepting them cannot become vacuous.
`gate_rejects` requires the failure to carry the message of the check the mutation
was built to trip, because any nonzero exit -- including a broken fixture -- proves
only that something died. Nothing proved that requirement stays in place, which is
the exact hole `f70a22106` closed for the CI wiring gate with `self_test_guard_holds`.

Adds the same guard: a rejection carrying an unreachable expected message must not
count as proof. Measured, not asserted -- deleting the `${expect}` comparison from
`gate_rejects` leaves every other line green, including both tracked-wiring
assertions, and reds only this one:

  ok - self-test: gate rejects a tracked file reintroduces product-UI wiring
  ok - self-test: gate rejects the scan root is not a git repository
  ui removal reference: self-test: gate_rejects counted a root that fails for an
  unrelated reason as proof of the intended check; it is tautological
…nment

Deriving the scan set from `git ls-files` made this gate the first version of it
to run git at all, and it ran it with the ambient environment. Two consequences,
both created by that change and neither present on main.

DATA LOSS. `GIT_INDEX_FILE` is exported by every pre-commit, commit-msg and
prepare-commit-msg hook and by `git commit --interactive`, and is inherited by
anything they spawn -- including `task docs:verify`, which runs this gate. The
self-test's throwaway `git init`/`git add` fixtures therefore staged themselves
into the REAL repository's index, against blobs in a temp object store that the
`trap ... EXIT` then deleted. Unrecoverable, and the gate exited 0. Measured on a
victim repository, before and after:

  BEFORE  gate exit 0, "self-test ok"
          index sha 33bcf6ac... -> a0c146c2...
          git status: AM .gitignore AD README.md AM mkdocs.yml AD notes.txt
          git show :mkdocs.yml -> fatal: bad object :mkdocs.yml
  AFTER   gate exit 0, index sha byte-identical

VACUOUS PASS. With `GIT_DIR` or `GIT_INDEX_FILE` exported, `ls-files` reads a
FOREIGN index while `rev-parse --show-toplevel` still answers with the cwd -- so
the toplevel-equality guard added in 188b76a did not merely miss this, it
certified it. On a clone carrying a tracked `bad.md` with
`ghcr.io/platformrelay/kollect-ui:v1`, `GIT_INDEX_FILE` pointed elsewhere gave
exit 0 and "ui removal reference: ok"; main's find-based version correctly reds
in the same environment. After this change both variables are ignored and the
gate reds naming `bad.md`.

Both are closed by unsetting the six git environment variables, inside
check_ui_removal -- the unit the self-test exercises, and the one that has to be
fixed for the assertions below to mean anything -- and again at the top of the
script. Be precise about that second site: it is redundant by ordering today,
because check_ui_removal runs in the main shell and its own `unset` sanitises
before the fixture harness ever reaches `git init`. Deleting it alone changes no
observable behaviour. It stays as defence in depth, so that reordering the file
-- moving the self-test above the real check, or wrapping the check in a
subshell -- cannot quietly reintroduce the data loss.
`GIT_OBJECT_DIRECTORY` is not optional: without it a sanitised index can still be
written against foreign object storage.

Two new self-tests pin the read side -- a fixture that tracks UI wiring must
still red with `GIT_DIR`, and again with `GIT_INDEX_FILE`, pointed at another
repository. Ablation, measured: deleting the in-function `unset` reds at the
`GIT_DIR` assertion with 15 self-test lines green ahead of it; the
`GIT_INDEX_FILE` assertion never runs, because `set -e` stops the script at the
first failure. Nothing else reds. A tripwire sits after the top-level `unset` and
guards that specific line: with the `unset` deleted but the tripwire kept, a
hook-context run dies loudly before any git command instead of eating the index
-- verified, victim index byte-identical. It is unreachable while the `unset` is
present, which is the point; a reachable version placed before the `unset` would
make the gate refuse to run from any hook at all.

Also in this round, all from the same review:

  * `git ls-files` output is captured to a file so its exit status is testable --
    streamed into the loop, a truncated listing was indistinguishable from a
    short repository and the files it never emitted were never scanned;
  * the scan set must hold the mkdocs.yml anchor AND at least one other file, so
    a listing truncated to its first entry cannot read as a scanned repository;
  * the ignored-noise fixture guard is now proven to fire -- it previously could
    be deleted with every assertion still green;
  * the two bare fixture `git init`/`git add` calls get the `|| fail` the others
    already had;
  * two comments corrected: the Docs workflow is path-filtered and not a required
    check, so "CI reds it the moment it is committed" was overstated, and
    `ls-files` is prefix-scoped, so a subdirectory root yields an empty set
    rather than the parent's files -- the equality guard is right, the stated
    reason was not.
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@konih
konih merged commit 02925c3 into main Aug 30, 2026
33 of 34 checks passed
@konih
konih deleted the lane/gate-uiref-01-r4 branch August 30, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant