Skip to content

accel_sampler selftest: the fixture owns its source, so the deployed copy can verify itself (engine#3069) - #3071

Merged
bong-water-water-bong merged 1 commit into
mainfrom
fix/3069-sampler-selftest-fixture
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
fix/3069-sampler-selftest-fixture

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

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

selftest passed 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_sampler "$0" "$d/derived.sh" >/dev/null 2>&1
grep -q '^commit=unknown$' "$(provenance_file "$d/derived.sh")" &&
    { echo "FAIL: install recorded commit=unknown while running inside a git checkout"; fail=1; }

install_sampler reads the commit from the source's own directory (git -C "$(dirname "$src")" rev-parse), so for the deployed copy commit=unknown is the correct answer and the arm red-lined it. Measured against origin/main's file, deployed shape (a copy under ~/.cache/accel-sampler-test/):

FAIL: install recorded commit=unknown while running inside a git checkout

That is the copy check-deployed tells 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:

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 && git -C "$1" -c user.email=t@t -c user.name=t add -A &&
      git -C "$1" -c user.email=t@t -c user.name=t commit -qm fixture
}

…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

deployed copy, this change     : accel-sampler self-test: ok (nearest+distance, fields+ticket, empty window,
                                 no-holder sample, rotation, summary replaced not truncated, faults split by device)  rc 0
deployed copy, main's file     : FAIL: install recorded commit=unknown while running inside a git checkout
repo copy, this change         : same ok line — the arm no longer depends on the caller

No network: two git -c user.email=… -c user.name=… commit calls 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.sh rc 0, copyright.py --check rc 0.

🤖 Generated with Claude Code

…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.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3069 - Partially compliant

Compliant requirements:

  • The selftest now passes on the deployed copy
  • The deployed copy can verify itself correctly
  • The fixture now owns its source, ensuring proper commit detection
  • The mirror arm ensures sources outside any checkout correctly record unknown

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Selftest Location Dependency

The selftest previously failed on the deployed copy because it asserted a commit was found based on the caller's location rather than the actual source. The fix ensures that the fixture owns its source by creating a throwaway git repository, which correctly records the commit for the deployed copy.

# ... and a destination that is given gets its commit from the checkout the SOURCE came from, not `unknown`.
# engine#3069: this arm used to install from `$0` and then assert a commit was found -- which asserts a fact about where
# the CALLER happens to sit. The deployed copy lives in ~/.cache/accel-sampler, not in a checkout, so `commit=unknown`
# is the right answer there and `selftest` failed on the one copy lanes are told to run. The fixture now owns its
# source: a throwaway repo under $d, the script committed into it, installed from there.
fixture_repo() {  # <dir> -- 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 && git -C "$1" -c user.email=t@t -c user.name=t add -A &&
    git -C "$1" -c user.email=t@t -c user.name=t commit -qm fixture
}
mkdir -p "$d/repo" && fixture_repo "$d/repo" \
  && install_sampler "$d/repo/tools/diag/accel_sampler.sh" "$d/derived.sh" >/dev/null 2>&1
grep -q '^commit=unknown$' "$(provenance_file "$d/derived.sh")" \
  && { echo "FAIL: install recorded commit=unknown for a source inside its own git checkout"; fail=1; }
# the mirror arm: a source that is inside NO checkout must record `unknown`, because that is what it can know. Without
# this half, "install finds a commit" could be satisfied by inventing one.
mkdir -p "$d/bare" && cp "${0}" "$d/bare/accel_sampler.sh" \
  && install_sampler "$d/bare/accel_sampler.sh" "$d/bare-installed.sh" >/dev/null 2>&1
grep -q '^commit=unknown$' "$(provenance_file "$d/bare-installed.sh")" \
  || { echo "FAIL: a source outside any checkout must record commit=unknown"; fail=1; }

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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;
  2. and whether install_sampler should refuse an untracked source — if reading the commit from the source directory yields unknown inside 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 recording unknown there 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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 3d448d3: READY — the bug is real and I reproduced it on main, and your fixture is what makes the selftest location-independent

The before/after is exactly the shape the PR describes, measured by running the script from a directory that is not a checkout (the deployed-copy case):

# main (241ff14): copy the script out of the tree, run its selftest there
$ cd /tmp/not-a-checkout && bash accel_sampler.sh selftest
FAIL: install recorded commit=unknown while running inside a git checkout           rc=1

# this head: same thing
$ cd /tmp/not-a-checkout && bash accel_sampler.sh selftest
accel-sampler self-test: ok (nearest+distance, fields+ticket, empty window, no-holder sample, rotation,
                            summary replaced not truncated, faults split by device)     rc=0

# and from the checkout, unchanged
$ bash tools/diag/accel_sampler.sh selftest
accel-sampler self-test: ok …                                                        rc=0

So the arm was asserting a fact about where the caller sits — $0 inside a checkout — which is true for the lane running it from the tree and false for the copy in ~/.cache/accel-sampler that lanes are told to run. That is the worst kind of selftest failure: a red row for the correct install.

Two things make the fix hold rather than just move the passing:

  • the fixture owns its source (a throwaway repo under $d, the script committed in, installed from there), so provenance has a commit to find without depending on the caller's cwd;
  • the mirror arm — a source inside no checkout must record unknown — which is what stops "install finds a commit" from being satisfiable by inventing one. Without it, the fix would have traded a false failure for a false pass.

Nothing to change. Merge note: this and #3068 both edit tools/diag/accel_sampler.sh; git merge-tree --write-tree says they merge cleanly (rc 0), so no ordering constraint — but #3068 has an open CHANGES from me (its widened FAULT_RE still misses three classes scripts/gpu-hold acts on), so this one can go first.

@bong-water-water-bong
bong-water-water-bong merged commit da5ebda into main Nov 21, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/3069-sampler-selftest-fixture branch November 21, 2026 00:28
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 3d448d31: READY — a self-test that asserted a fact about where the caller sits is exactly the class of test that fails on the one copy lanes are told to run.

The old arm installed from $0 and then asserted a commit was found, which is a statement about the caller's checkout, not about install_sampler. The deployed copy lives in ~/.cache/accel-sampler with no git — so commit=unknown is the correct answer there and selftest failed on the only copy that matters, which is worse than a test that does not exist: it teaches lanes to ignore the command.

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 unknown — is the half that makes the pair meaningful. Without it, the first arm would be satisfied by a tool that always writes a commit string from anywhere.

One small thing to keep in mind if this file grows: cp "${0}" inside a self-test is a fixture borrowing the very thing under test, so if ${0} is ever a symlink (a lane's ~/.local/bin staging) the copy is the link target's content — fine here, but a readlink -f "${0}" first would remove the question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

accel_sampler: selftest FAILs on the deployed copy (its arm assumes $0 is inside a git checkout), so the instrument cannot verify the bytes that run

1 participant