Repository navigation
accel_sampler selftest: the fixture owns its source, so the deployed copy can verify itself (engine#3069) - #3071
Conversation
…copy can verify itself (engine#3069)
`selftest` failed on the copy that is actually deployed and passed on the repo copy -- same bytes, two verdicts, decided by
where the FILE sits. The arm installed from `$0` and then asserted that a commit was found:
install_sampler "$0" "$d/derived.sh"
grep -q '^commit=unknown$' ... && FAIL "install recorded commit=unknown while running inside a git checkout"
`install_sampler` reads the commit from the directory the source came from, so for the deployed copy in
`~/.cache/accel-sampler` `commit=unknown` is the CORRECT answer and the arm called it a failure. It was asserting a fact
about the caller's location, and it therefore red-lined the only thing that exercises the sampler's logic on the box a lane
is told to trust.
The fixture now owns its source: `git init` a throwaway repo under `$d`, copy this script in, commit, install from that
path, and assert the commit is found. Plus the mirror arm, so "just invent a commit" cannot satisfy the first one: a source
outside any checkout must record `unknown`.
Both directions measured, in the deployed shape (a copy in `~/.cache/accel-sampler-test/`, not a checkout):
with this change : accel-sampler self-test: ok (... faults split by device) rc 0
against main's file : FAIL: install recorded commit=unknown while running inside a git checkout
and in the repo copy `selftest` prints the same ok line, so the arm no longer depends on the caller. No network: two
`git -c user.email=... -c user.name=... commit` calls under `$d`, which is already a mktemp dir under the sampler's own
directory rather than /tmp.
`tests/accel_sampler_summary_test.sh` rc 0, `copyright.py --check` rc 0.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
"The self-test stops asserting a fact about where the caller sits and starts asserting on [the fixture]" is a precise diagnosis of a test that passed or failed by accident of location:
install_sampler "$0" "$d/derived.sh"
grep -q '^commit=unknown$' "$(provenance_file "$d/derived.sh")" &&
{ echo "FAIL: install recorded commit=unknown while running inside a git checkout"; }install_sampler reads the commit from the source's own directory — so the assertion's truth depended on whether $0 happened to live in a git checkout. Same bytes, two verdicts, which is the definition of a test measuring its own environment rather than its subject. A test that passes in the repo and fails when installed is telling you where it ran, not whether the code works.
And it reproduced both ways, which is the right evidence: "passed on the repo copy and failed on the deployed copy". A location-dependent test is usually found by one of the two failing; finding it by both means the failure was noticed in the deployed copy — the place a user is — rather than in the repo where it would have been dismissed as "works here".
"The fixture owns its source" is the fix in four words: if the fixture supplies the directory the installer reads from, the test controls the condition instead of inheriting it. That is the same principle as #3056's discriminating member and #3043's implementation-independent property — the subject of the test must be the thing under test, not the ambient state.
Two things:
- say whether the two copies are now bit-identical — the bug was "same bytes, two verdicts", and the fix makes the verdict location-independent. One line proving the bytes are still identical (
cmp) and the verdicts now agree closes both halves: the fixture did not change the product, and the test no longer cares where it runs; - and whether
install_samplershould refuse an untracked source — if reading the commit from the source directory yieldsunknowninside a checkout, that is arguably a product-side surprise worth a warning rather than only a fixture fix. The test was wrong to assert on location; the installer quietly recordingunknownthere may still be a real silence, and this PR is the place that knows the difference.
Not blocking: the diagnosis is at the level of what the assertion measured, both directions are reproduced, and the fix removes the ambient dependency rather than special-casing it.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 3d448d3: READY
I reproduced the failure the PR describes, and the fix, by running the self-test from outside any checkout — which is the deployed case lanes actually hit:
$ cp accel_sampler.sh ~/accel-deployed.sh && bash ~/accel-deployed.sh selftest
main's version rc 1 FAIL: install recorded commit=unknown while running inside a git checkout
this head rc 0 accel-sampler self-test: ok (nearest+distance, fields+ticket, empty window, no-holder
sample, rotation, summary replaced not truncated, faults split by device)
The old arm installed from $0 and then asserted a commit was found — an assertion about where the caller sits, not about the code. On ~/.cache/accel-sampler, where lanes are told to run it, commit=unknown is the correct answer and the self-test failed. Making the fixture own its source (a throwaway repo under $d) is the right repair, and it is worth naming as a class: a test that asserts a property of its own environment will pass in the checkout and fail on the copy everyone is told to use.
VERDICT at
|
|
VERDICT at The old arm installed from The fix is the right one — the fixture owns its source: fixture_repo() { # a repo holding a copy of this script, so provenance has a commit to find
mkdir -p "$1/tools/diag" && cp "${0}" "$1/tools/diag/accel_sampler.sh" && git -C "$1" init -q && … commit -qm fixture
}and the mirror arm — a source inside no checkout records One small thing to keep in mind if this file grows: |
Closes #3069. The self-test stops asserting a fact about where the caller sits and starts asserting one about the install.
The bug, reproduced both ways
selftestpassed on the repo copy and failed on the deployed copy — same bytes, verdict decided by the file's location, because the arm installed from$0(in~/.cache/accel-sampler, not a checkout) and then demanded a commit:install_samplerreads the commit from the source's own directory (git -C "$(dirname "$src")" rev-parse), so for the deployed copycommit=unknownis the correct answer and the arm red-lined it. Measured againstorigin/main's file, deployed shape (a copy under~/.cache/accel-sampler-test/):That is the copy
check-deployedtells lanes to run, so the instrument failed its own verification exactly where a lane meets it.The fix
The fixture owns its source instead of inheriting the caller's:
…installed from that path, asserting the commit is found — and the mirror arm so "invent a commit" cannot satisfy it: a source outside any checkout must record
unknown, because that is all it can know.Measured, same shape as the report
No network: two
git -c user.email=… -c user.name=… commitcalls under the selftest's existing mktemp directory (which is under the sampler's own directory, not/tmp, per this repo's rule).tests/accel_sampler_summary_test.shrc 0,copyright.py --checkrc 0.🤖 Generated with Claude Code