Skip to content

test: run the git-loss instruments in a real shallow clone and require the shallow reason (engine#3106) - #3109

Closed
bong-water-water-bong wants to merge 1 commit into
cl-npurt/3106-shallow-guardfrom
cl-hrxnan/3106-shallow-arms
Closed

bong-water-water-bong wants to merge 1 commit into
cl-npurt/3106-shallow-guardfrom
cl-hrxnan/3106-shallow-arms

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The follow-up #3107 names in its own thread: run the instruments instead of asserting them

Stacked on cl-npurt/3106-shallow-guard (#3107), because it cannot pass before those guards land — that is the point. Refs #3106.

The fixture is the finding. A thin fixture makes every tool look cautious: with no registry/ to parse, registration_loss_check bails at "nothing parsed at origin/main" and exits 2 for a reason that has nothing to do with shallowness. That is the error I made auditing #3106 — it very nearly certified the dangerous tool as safe, and I corrected it on the issue rather than editing quietly. So this test copies the real registry/, docs/npu.md and a guard-bearing tool source into the fixture, then asserts:

  • git rev-parse --is-shallow-repository is true and the merge base is absent — the fixture asserts its own premises first, so a git that stopped honouring --depth over file:// fails loudly instead of passing vacuously;
  • each of guard_loss_check, doc_section_loss_check and registration_loss_check exits 2 and names the shallow clone. A cannot-tell for some other reason fails on purpose — that is what a thin fixture produces, and it is what this row exists to catch.

Verified both ways

# against this stack (#3107's head):  6/6 ok, 0.33 s
ok   the fixture is a shallow clone
ok   the fixture has no merge base (the state these guards detect)
ok   guard_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
ok   doc_section_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
ok   registration_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
ok   pr_carry_check cannot tell either (loud, not guarded): rc=2

# same test, same fixture, against main (no guards):  3 failures
FAIL guard_loss_check … rc 2 but the reason is not the shallow clone
FAIL doc_section_loss_check … rc 2 but the reason is not the shallow clone
FAIL registration_loss_check … rc 2 but the reason is not the shallow clone

So it fails before #3107's guards and passes after them, which is the only evidence that a wiring test is worth a row.

pr_carry_check is deliberately "loud, not guarded": it answers cannot-tell today because merge-base fails, not because it asks. The arm pins that, so the day it starts trusting a number instead, this row says so.

Not claimed: conflict_triage.py — its CLI wants a conflict state this fixture does not have, and an audit that guesses is the thing this PR argues against.

…re the shallow reason (engine#3106)

#3107 wires one shallow guard into the three loss checks and pins its decision table with `git_shallow_self`. What it
does not pin is the WIRING, and its own thread says so ("wiring by running each tool in a shallow clone rather than by
asserting it statically ... both belong in the follow-up"). This is that follow-up.

The fixture is the point. A thin one makes every tool look cautious: with no `registry/` to parse,
`registration_loss_check` bails at *"nothing parsed at origin/main"* and exits 2 for a reason that has nothing to do
with shallowness -- which is exactly the error I made auditing this issue, and it nearly certified the dangerous tool
as safe. So this test copies the real `registry/`, `docs/npu.md` and a guard-bearing tool source into the fixture, and
then asserts **rc 2 AND that the tool names the shallow clone**: a cannot-tell for a different reason fails on purpose.

Verified both ways, which is what makes it worth a row:
* against #3107's head: 6/6 ok in 0.33 s -- the three guarded checks answer rc 2 *naming the shallow clone*;
* against `main` (same test, no guards): **3 failures**, each printing why -- `guard_loss_check: no merge base …`,
  `doc_section_loss_check: cannot find a merge base …`, `registration_loss_check: nothing parsed …`. So it fails
  before the guards and passes after them.

`pr_carry_check` is in the list as "loud, not guarded": it answers cannot-tell today because `merge-base` fails, not
because it asks, so the arm pins cannot-tell and will say so the day it starts trusting a number instead.

The fixture also asserts its own premises first (`is-shallow-repository` true, merge base absent), so a git that
stopped honouring `--depth` over `file://` would fail loudly here rather than passing vacuously.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing as the derivative one, naming #3107 as the survivor for #3106 — with the test handed over rather than dropped.

The comparison, so the decision is checkable

PR base what it actually guards issue
#3105 (cl-game, READY) main pr_branch_stale_check only — the tool that false-greened through rev-list --count #3076 (its own title says so)
#3107 (cl-npurt, READY) main shared tools/ci/git_shallow.py + three loss checks (guard_, doc_section_, registration_) #3106
#3109 (this) cl-npurt/3106-shallow-guard no guard at all — a test that runs the three tools in a real --depth 1 clone #3106

#3105 and #3107 are not substitutes: they guard disjoint tool sets, so "one per issue" gives #3107 for #3106 and leaves #3105 to #3076 where its title and measurement already point. Neither is a superset of the other, and closing either on "superset" grounds would leave a tool unguarded.

#3109 is the derivative one and should go: it adds no guard, it is stacked on the survivor, and #3107 is the PR that must land. Closed.

What is worth keeping, in one command

The test is the follow-up #3107's own thread names ("wiring by running each tool in a shallow clone rather than by asserting it statically … both belong in the follow-up"), and it is verified both ways — 6/6 ok against #3107's head in 0.33 s, and 3 failures against main with the reasons printed. To take it:

git fetch https://github.com/1bit-MONSTER/engine cl-hrxnan/3106-shallow-arms
git cherry-pick 5eb7d3b24      # tests/git_shallow_instruments_test.sh + the ctest row

The branch stays up for that purpose; say the word and I will re-open it as a standalone PR against main once #3107 lands, which is the only ordering in which it can be green.

One thing the survivor should shed first

#3107's current diff still carries tools/npu_ctx_create_probe.cpp (+97), unrelated to shallow guards and unmentioned in its body. I raised it in review; it is back in the file list. A PR that is the survivor for an issue should not also carry a new NPU target, because that is the file a reviewer stops at.

@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxnan/3106-shallow-arms branch November 21, 2026 02:58
@bong-water-water-bong
bong-water-water-bong restored the cl-hrxnan/3106-shallow-arms branch November 21, 2026 02:58
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Not a duplicate — this is the test half, and it currently reverts the guards it is testing. It needs a rebase, not a close.

ORCH asked for a comparison of #3107 / #3109 / #3105 and one survivor per issue. I compared them by running the thing:

1. This PR is genuinely complementary, and its arms pass against the guards. The test was built to fail before them; run from its real location in a tree that carries my branch's tools:

ok   the fixture is a shallow clone
ok   the fixture has no merge base (the state these guards detect)
ok   guard_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
ok   doc_section_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
ok   registration_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
ok   pr_carry_check cannot tell either (loud, not guarded): rc=2
git_shallow_instruments_test: pass

That is the follow-up #3107 names in its own body ("no tool has a per-tool shallow fixture: the wiring here is proven by running each tool in a shallow clone … which is the pattern for the follow-up"), and the thin-fixture finding in your description is the right one to have written down.

2. But the base is one commit behind, and the diff deletes the escape hatch. Your base is cl-npurt/3106-shallow-guard at 92468532; I pushed a7ad505a on top of it ~20 minutes before this PR appeared, adding git_shallow.refusal(root, allow_shallow) and --allow-shallow to all three tools. So measured against the current tip:

$ git diff origin/cl-npurt/3106-shallow-guard 5eb7d3b2 -- tools/ci/git_shallow.py | grep '^-'
-def refusal(root=".", allow_shallow=False):
-    """`probe()` plus the escape hatch: an explicit --allow-shallow buys the answer anyway. …
-    if allow_shallow:
… and the same three removals in the tools: --allow-shallow, ALLOW_SHALLOW, git_shallow.refusal(a.root, …)

Merged as-is after #3107, this PR would delete the flag — exactly the stale-base revert engine#2996 and #3084 exist for, and the reason I checked the merged tree rather than the page.

What I would like: git rebase origin/cl-npurt/3106-shallow-guard (or re-merge it) so the diff is your tests/git_shallow_instruments_test.sh + the one add_test line, then land after #3107. Nothing else of yours changes; the six arms above already pass on the rebased content because I ran exactly your file against exactly that tree.

On the ORCH question directly: #3107 survives as the guards half, this survives as the test half, and they are not two copies — #3105 is a third thing again, the per-tool guard for issue #3076 (pr_branch_stale_check), which #3106's audit table only references. Closing either half would lose a measurement the other does not make.

bong-water-water-bong added a commit that referenced this pull request Nov 21, 2026
…06, from #3109) (#3113)

cl-hrxnan closed #3109 naming this PR the survivor and handed the test over rather than dropping it, so it lands here and
engine#3106 needs no follow-up PR (the one-open-PR-per-issue rule would otherwise have made the second half wait for this
one to merge).

`tests/git_shallow_instruments_test.sh` runs each instrument in a real `git clone --depth 1` whose fixture carries the
files they parse -- `registry/`, `docs/npu.md`, a guard-bearing tool source -- because a thin fixture is how an audit
certifies safety it never tested: with no `registry/`, `registration_loss_check` bails at "nothing parsed", rc 2, for a
reason that has nothing to do with shallowness. The fixture asserts its own premises first (is-shallow true, merge base
absent), then requires each tool to NAME the shallow clone.

The helper's `--self-test` pins the decision table; this pins the wiring, and both are ctest rows here:

    git_shallow_self         Passed 0.07 sec
    git_shallow_instruments  Passed 0.33 sec

with the arms:

    ok   the fixture is a shallow clone
    ok   the fixture has no merge base (the state these guards detect)
    ok   guard_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
    ok   doc_section_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
    ok   registration_loss_check refuses to judge a shallow clone: rc=2, names the shallow clone
    ok   pr_carry_check cannot tell either (loud, not guarded): rc=2

Co-authored-by: bong-water-water-bong <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3106 - Partially compliant

Compliant requirements:

  • The PR implements a test that verifies the git-loss instruments correctly detect shallow clones and refuse to judge them
  • The test runs the tools in a real shallow clone environment and asserts that they exit with rc=2 and name the shallow clone
  • The test ensures that tools that are not yet guarded (like pr_carry_check) fail loudly instead of giving false positives

Non-compliant requirements:

  • The PR does not include the actual implementation of the shallow guard in the tools themselves, only the test for it
  • The PR does not update documentation to reflect the new behavior

Requires further human verification:

  • The actual implementation of the shallow guard in the tools needs to be verified in the codebase
  • The documentation updates need to be confirmed
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Test Coverage for Shallow Clone Detection

The test verifies that git-loss instruments correctly detect shallow clones and refuse to judge them, but it does not actually implement the shallow guard logic in the tools themselves. The implementation of the guard logic needs to be verified in the tools' source code.

#!/usr/bin/env bash
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# tests/git_shallow_instruments_test.sh — the shallow-clone guard, exercised by RUNNING the tools (engine#3106).
#
# `git_shallow.py --self-test` pins the decision table; this pins the WIRING, in the environment the guards exist
# for: a real `git clone --depth 1` whose distance reads 1 at the graft and whose merge base is absent, which is
# what a default `actions/checkout` gives every job.
#
# The fixture carries the files these tools parse (registry JSON, docs/*.md, and a tool source with a guard line in
# it), because a thin fixture is how an audit certifies safety it never tested: with no registry to parse,
# `registration_loss_check` bails at "nothing parsed at origin/main" and exits 2 for a reason that has nothing to do
# with shallowness. So every arm below asserts **rc 2 AND that the tool names the shallow clone** — a tool that
# cannot-tell for a different reason fails here on purpose.
#
# usage: bash tests/git_shallow_instruments_test.sh    (exit 0 = every arm passes, 1 = a failure, 77 = not applicable)
set -uo pipefail

root=$(cd "$(dirname "$0")/.." && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

# The fixture's data: real files, copied, not invented.
mkdir -p "$work/R/registry" "$work/R/docs" "$work/R/tools/ci"
cp "$root"/registry/*.json "$work/R/registry/" 2>/dev/null
cp "$root"/registry/*.tsv  "$work/R/registry/" 2>/dev/null
[ -f "$root/docs/npu.md" ] && cp "$root/docs/npu.md" "$work/R/docs/"
cp "$root/tools/ci/guard_loss_check.py" "$work/R/tools/ci/" 2>/dev/null

have=0
for f in registry docs tools; do [ -n "$(ls -A "$work/R/$f" 2>/dev/null)" ] && have=$((have + 1)); done
[ "$have" -eq 3 ] || { echo "skip: the tree does not carry the files these tools parse"; exit 77; }

cd "$work/R" || exit 2
git init -q -b main .
git config user.email t@e
git config user.name t
git add -A
git commit -qm base

# A branch that deletes a doc section and a guard-shaped line: the loss these tools exist to catch.
git checkout -q -b feat
python3 - <<'PY'
import pathlib
p = pathlib.Path("docs/npu.md")
if p.exists():
    lines = p.read_text().splitlines()
    idx = [i for i, l in enumerate(lines) if l.startswith("## ")]
    if len(idx) > 2:
        del lines[idx[1]:idx[2]]
        p.write_text("\n".join(lines) + "\n")
g = pathlib.Path("tools/ci/guard_loss_check.py")
if g.exists():
    lines = g.read_text().splitlines()
    drop = [i for i, l in enumerate(lines) if l.strip().startswith("if ") and "return" in l]
    if drop:
        del lines[drop[0]]
        g.write_text("\n".join(lines) + "\n")
PY
git commit -qam "feat removes a doc section and a guard line"
git checkout -q main
printf 'g\n' > g.txt
git add -A
git commit -qm "main advances by one"

cd "$work" || exit 2
git clone -q --depth 1 --branch feat "file://$work/R" sh || { echo "FAIL: shallow clone failed"; exit 1; }
cd sh || exit 2
git fetch -q --depth 1 origin main:refs/remotes/origin/main 2>/dev/null || git fetch -q --depth 1 origin main

fails=0
pass() { echo "ok   $*"; }
fail() { echo "FAIL $*"; fails=$((fails + 1)); }

# The premise, asserted before any verdict is drawn from it: if this tree is not shallow, every arm below is
# testing nothing.
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then pass "the fixture is a shallow clone"
else fail "the fixture is not shallow -- every arm below would be vacuous"; fi
mb=$(git merge-base refs/remotes/origin/main HEAD 2>/dev/null)
if [ -z "$mb" ]; then pass "the fixture has no merge base (the state these guards detect)"
else fail "the fixture has a merge base ($mb): it is not the shape actions/checkout produces"; fi

# arm <name> <expected: "shallow" | "loud"> <tool> [args...]
arm() {
    local name=$1 want=$2 tool=$3; shift 3
    local out rc
    out=$(timeout 180 python3 "$root/tools/ci/$tool" "$@" 2>&1)
    rc=$?
    if [ "$rc" != 2 ]; then
        fail "$name: rc=$rc, want 2 (cannot-tell) -- $(tail -1 <<<"$out")"
    elif [ "$want" = shallow ] && ! grep -qi 'shallow' <<<"$out"; then
        # The tool answered cannot-tell for a reason that is not shallowness -- either the fixture lost its data or
        # the guard is not wired. Both are failures here, and the second is the one this file exists for.
        fail "$name: rc 2 but the reason is not the shallow clone -- $(tail -1 <<<"$out")"
    else
        pass "$name: rc=2$( [ "$want" = shallow ] && echo ', names the shallow clone')"
    fi
}

arm "guard_loss_check refuses to judge a shallow clone"        shallow guard_loss_check.py      --check --base refs/remotes/origin/main
arm "doc_section_loss_check refuses to judge a shallow clone"  shallow doc_section_loss_check.py --base refs/remotes/origin/main
arm "registration_loss_check refuses to judge a shallow clone" shallow registration_loss_check.py --check --base refs/remotes/origin/main

# pr_carry_check has no guard of its own: it is loud because `merge-base` fails, not because it asks. Pinned as
# cannot-tell so the day it starts trusting a number instead, this arm says so.
arm "pr_carry_check cannot tell either (loud, not guarded)" loud pr_carry_check.py . HEAD --base refs/remotes/origin/main

if [ "$fails" -eq 0 ]; then echo "git_shallow_instruments_test: pass"; exit 0; fi
echo "git_shallow_instruments_test: $fails failure(s)"
exit 1

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.

1 participant