Repository navigation
Test: revive two step-7 assertions in the sbx smoke that could not fail - #655
Conversation
`deploy/sbx/tests/smoke.test.sh` carried two checks on the egress-credential
step that were structurally incapable of failing, so step 7 reported a PAT
containment it never verified.
LOGS_KEPT is set nowhere in the repository, so
if [[ -d "${LOGS_KEPT:-}" ]]; then ! grep -rqF -- "$PAT" "$LOGS_KEPT" || fail
tested `[[ -d "" ]]`, always false. The kept logs of a failed run are the one
place the PAT can leak to that outlives the run, and that was the assertion
meant to cover it. It covered nothing for the whole of SBX0.2b. The path is
knowable: smoke.sh's cleanup prints `# logs kept in DIR` (smoke.sh:201). Read
it from there instead, check every directory named, and fail -- not skip -- on
one that does not resolve, so the check cannot go quiet again by losing its
input.
The second:
[[ "$(cat "$MOCK_DIR/cred-smoke-gh" 2>/dev/null || true)" == '' ]] || true
reads a file the run already deleted, compares it to '', and discards the
result either way. Its comment claims the add reads the PAT from stdin, which
is the property that keeps the PAT out of argv -- an empty stdin, or the PAT
passed on argv, would both have satisfied it. The fake mocactl now keeps the
add's stdin as cred-NAME.read, which the delete leaves behind, and the test
compares it to the token file with cmp.
Dropping the trailing newline is mocactl's own contract, not the smoke's: it
pipes the file whole (smoke.sh:685), so the bytes the fake receives still carry
it, and the assertion is for the bytes actually sent.
Added nopat_sees_kept_logs, run after the first credfail (a failing run is what
keeps its logs): it plants a PAT canary in the kept logs and asserts nopat
fails. Restoring the old LOGS_KEPT line makes it report
nopat passed with the PAT planted in the kept logs: the kept-logs check is a no-op
so the revived check is pinned by a test of its own rather than trusted.
Each new assertion was verified to fail against the defect it guards, not
merely to pass:
- the dead LOGS_KEPT line restored -> nopat_sees_kept_logs fails
- smoke.sh made to write the PAT into a kept log -> nopat fails (this is the
real leak the old line would have missed)
- an empty stdin to `credentials add` -> cmp reports EOF
- a wrong token of the same length -> cmp reports char 5
Test-only; no production file is touched. smoke.test.sh 20/20, the five sibling
deploy/sbx suites pass, and shellcheck is unchanged from the baseline (the same
pre-existing SC2016 infos on backticks in message strings).
Refs rossoctl#653
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Test-only fix that revives two step-7 assertions in deploy/sbx/tests/smoke.test.sh that could never fail: the kept-logs PAT check (it keyed on an unset LOGS_KEPT) and the stdin check (a || true that compared an already-deleted file to ''). Both now do real checks. The kept-logs path is parsed from smoke.sh's # logs kept in DIR line (smoke.sh:201) and fails when the path does not resolve, and the fake mocactl keeps the add's stdin as .read for a byte-exact cmp against the token file. nopat_sees_kept_logs plants a canary to show the check bites. I checked that fail inside the (nopat) subshell probe still fires in an if context, because every check calls fail/exit 1 explicitly instead of relying on set -e. I also checked that the while … < <(kept_logs) loop runs in the main shell, so its fail exits the test, and that no other code globs cred-* in a way the new .read side file would disturb.
Non-blocking, outside this diff: smoke.sh's LOGS="$(mktemp -d)" uses the system TMPDIR, so every failing-run case in this test (and now the canary dir) leaves a kept-logs directory in /tmp after the test's own $TMP trap. Exporting TMPDIR="$TMP" in smoke() would contain them. Could go in a follow-up with the rest of #653.
Author: cwiklik (MEMBER — maintainer)
Areas reviewed: Shell (tests), Security (PAT containment)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (15/15)
Summary
Two assertions in
deploy/sbx/tests/smoke.test.sh's egress-credential step were structurallyincapable of failing, so step 7 reported a PAT containment it never checked. First section of
#653 ("test gaps that hide real checks (do first)"). Test-only; no production file is touched.
The two defects
LOGS_KEPTis undefinedif [[ -d "${LOGS_KEPT:-}" ]]; then ! grep -rqF -- "$PAT" "$LOGS_KEPT" || fail—LOGS_KEPTis set nowhere in the repository, so this tested[[ -d "" ]]: always false, never ran# logs kept in DIR(smoke.sh:201); every directory named is checked, and one that does not resolve fails rather than skipping|| trueon both sides[[ "$(cat "$MOCK_DIR/cred-smoke-gh" 2>/dev/null || true)" == '' ]] || true— reads a file the run already deleted, compares it to'', discards the result either waycred-NAME.read(the delete leaves it behind); the testcmps it against the token fileThe kept logs of a failed run are the one place the PAT can leak to that outlives the run, and
that first line was the assertion meant to cover it. It covered nothing for the whole of SBX0.2b.
The second line's comment claims the add reads the PAT from stdin — the property that keeps the PAT
out of argv. An empty stdin, or the PAT passed on argv, would both have satisfied it.
Dropping the trailing newline is
mocactl's own contract, not the smoke's: it pipes the token filewhole (
smoke.sh:685), so the bytes the fake receives still carry it. The assertion is for thebytes actually sent, which is what this test can observe.
Guarding the guard
A revived assertion that can go quiet again is worth little, so
nopat_sees_kept_logsplants a PATcanary in a failing run's kept logs and asserts
nopatfails. It runs after the firstcredfail, since a failing run is what keeps its logs. Restoring the oldLOGS_KEPTline makes itreport:
Verification
Each new assertion was verified to fail against the defect it guards, not merely to pass:
LOGS_KEPTline restorednopat passed with the PAT planted in the kept logs: the kept-logs check is a no-opsmoke.shmade to write the PAT into a kept logthe PAT is in the kept logs (...)— the real leak the old line would have missedcredentials addthe add's stdin is not the token file: EOF on ...cred-smoke-gh.readthe add's stdin is not the token file: ... differ: char 5, line 1smoke.shwas restored byte-identical after each mutation (git diffclean).shellcheckis unchanged from the baseline on this file — the same pre-existingSC2016infos onbackticks in message strings, no new findings.
What this does not do
#653's other sections are untouched, hence
Refsrather thanCloses. The second bullet of thesame "do first" group (
drop_branchreporting success on a 404; a failedaddtriggering aspurious
delete; the fixedsmoke-ghname colliding between concurrent runs) is insmoke.shitself, not the test, and is left for its own change.
Refs #653
Assisted-By: Claude Code