From c18d67cce000a787978648022950e240f9b1feb2 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 17:11:32 -0600 Subject: [PATCH 1/2] test(repo-keeper): untracked secret never swept into snapshots (code#2268) Proves the #1740-Codex bypass class is dead on current main: an untracked config/credentials.json (collapsed to ?? config/ in status) must not enter the tracked-only (git add -u) snapshot. Negative control: the same fixture under add -A swallows the secret. --- nixos/home/laptop-repo-keeper.test.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nixos/home/laptop-repo-keeper.test.sh b/nixos/home/laptop-repo-keeper.test.sh index 3658e5045b..50d7b1be79 100755 --- a/nixos/home/laptop-repo-keeper.test.sh +++ b/nixos/home/laptop-repo-keeper.test.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash # Exercises the real keeper against temporary primary repos: tracked # residue must block snapshot commits, while clean trees still snapshot. +# An untracked secret inside a wholly untracked directory (code#2268) +# must never be swept into a snapshot (status collapses it to `?? dir/`). set -uo pipefail SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -151,6 +153,25 @@ grep -Fq -- 'detached HEAD without origin — skipped' "$TMP_ROOT/detached-dirty ! grep -Fq -- 'PRIMARY ON ' "$TMP_ROOT/detached-dirty.log" || fail 'detached dirty case: report contains an empty branch name' +# A secret inside a wholly untracked directory (code#2268) must never be +# swept into a snapshot: `git status --porcelain` collapses it to +# `?? config/`, so no path entry ever names the nested file — and the +# keeper commits tracked changes only (`git add -u`), leaving it alone. +H7="$TMP_ROOT/untracked-secret-home" +R7="$H7/code" +new_repo "$R7" +printf 'snapshot candidate\n' >>"$R7/tracked.txt" +mkdir -p "$R7/config" +printf 'fake-password hunter2\n' >"$R7/config/credentials.json" +run_keeper "$H7" "$TMP_ROOT/untracked-secret.log" + +check 'untracked-secret case: snapshot holds the tracked change only' \ + 'tracked.txt' "$(git -C "$R7" show HEAD --name-only --format='')" +check 'untracked-secret case: secret still untracked on disk' \ + '?? config/' "$(git -C "$R7" status --porcelain -- config)" +grep -Fq -- 'untracked file(s)' "$TMP_ROOT/untracked-secret.log" || + fail 'untracked-secret case: report missing untracked count' + if [ "$failures" -gt 0 ]; then echo "$failures failure(s)" >&2 exit 1 From d8e7180cbe23827454419da0777ea693e30c3f5e Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 19:38:55 -0600 Subject: [PATCH 2/2] fix(repo-keeper): inspect nested untracked secret paths --- nixos/home/laptop-repo-keeper.sh | 3 ++- nixos/home/laptop-repo-keeper.test.sh | 35 +++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/nixos/home/laptop-repo-keeper.sh b/nixos/home/laptop-repo-keeper.sh index e1051ff356..4de18d35e3 100755 --- a/nixos/home/laptop-repo-keeper.sh +++ b/nixos/home/laptop-repo-keeper.sh @@ -132,7 +132,8 @@ for d in "${REPOS[@]}"; do elif [ -n "$residue" ]; then residue_list="$(printf '%s' "$residue" | tr '\n' ' ')" say "- $name: TRACKED RESIDUE NOT committed — move these paths to a dated residue directory first: $residue_list" - elif g status --porcelain | grep -v '^??' | grep -Eiq "$SECRET_RE"; then + # Expand untracked directories so nested secret-shaped paths are checked. + elif g status --porcelain --untracked-files=all | grep -Eiq "$SECRET_RE"; then say "- $name: DIRTY ($dirty tracked entries) NOT committed — secret-shaped path present" elif g add -u && g commit -q -m "repo-keeper: snapshot $name $TS"; then say "- $name: committed $dirty tracked entries on $db" diff --git a/nixos/home/laptop-repo-keeper.test.sh b/nixos/home/laptop-repo-keeper.test.sh index 50d7b1be79..d1cf692f0b 100755 --- a/nixos/home/laptop-repo-keeper.test.sh +++ b/nixos/home/laptop-repo-keeper.test.sh @@ -153,24 +153,45 @@ grep -Fq -- 'detached HEAD without origin — skipped' "$TMP_ROOT/detached-dirty ! grep -Fq -- 'PRIMARY ON ' "$TMP_ROOT/detached-dirty.log" || fail 'detached dirty case: report contains an empty branch name' -# A secret inside a wholly untracked directory (code#2268) must never be -# swept into a snapshot: `git status --porcelain` collapses it to -# `?? config/`, so no path entry ever names the nested file — and the -# keeper commits tracked changes only (`git add -u`), leaving it alone. +# A secret inside a wholly untracked directory (code#2268) blocks the +# snapshot: default porcelain collapses it to `?? config/`, while the +# guard must inspect individual untracked paths. H7="$TMP_ROOT/untracked-secret-home" R7="$H7/code" new_repo "$R7" printf 'snapshot candidate\n' >>"$R7/tracked.txt" mkdir -p "$R7/config" -printf 'fake-password hunter2\n' >"$R7/config/credentials.json" +printf 'synthetic fixture only; not a credential\n' >"$R7/config/credentials.json" run_keeper "$H7" "$TMP_ROOT/untracked-secret.log" -check 'untracked-secret case: snapshot holds the tracked change only' \ - 'tracked.txt' "$(git -C "$R7" show HEAD --name-only --format='')" +check 'untracked-secret case: tracked snapshot is blocked' \ + '1' "$(git -C "$R7" rev-list --count HEAD)" +check 'untracked-secret case: tracked edit remains dirty' \ + 'tracked.txt' "$(git -C "$R7" diff --name-only)" check 'untracked-secret case: secret still untracked on disk' \ '?? config/' "$(git -C "$R7" status --porcelain -- config)" grep -Fq -- 'untracked file(s)' "$TMP_ROOT/untracked-secret.log" || fail 'untracked-secret case: report missing untracked count' +grep -Fq -- 'secret-shaped path present' "$TMP_ROOT/untracked-secret.log" || + fail 'untracked-secret case: report missing secret-shaped-path refusal' + +# An ordinary untracked directory does not trip the guard; the regular +# tracked snapshot still succeeds, without adding untracked files. +H8="$TMP_ROOT/untracked-ordinary-home" +R8="$H8/code" +new_repo "$R8" +printf 'snapshot candidate\n' >>"$R8/tracked.txt" +mkdir -p "$R8/notes" +printf 'ordinary fixture\n' >"$R8/notes/readme.txt" +run_keeper "$H8" "$TMP_ROOT/untracked-ordinary.log" +check 'untracked-ordinary case: tracked snapshot committed' \ + '2' "$(git -C "$R8" rev-list --count HEAD)" +check 'untracked-ordinary case: snapshot includes tracked file only' \ + 'tracked.txt' "$(git -C "$R8" show HEAD --name-only --format='')" +check 'untracked-ordinary case: ordinary file remains untracked' \ + '?? notes/' "$(git -C "$R8" status --porcelain -- notes)" +grep -Fq -- 'committed 1 tracked entries on main' "$TMP_ROOT/untracked-ordinary.log" || + fail 'untracked-ordinary case: report missing successful snapshot' if [ "$failures" -gt 0 ]; then echo "$failures failure(s)" >&2