Skip to content

Test: revive two step-7 assertions in the sbx smoke that could not fail - #655

Merged
pdettori merged 1 commit into
rossoctl:mainfrom
cwiklik:fix/653-smoke-dead-assertions
Oct 28, 2026
Merged

pdettori merged 1 commit into
rossoctl:mainfrom
cwiklik:fix/653-smoke-dead-assertions

Conversation

@cwiklik

@cwiklik cwiklik commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Two assertions in deploy/sbx/tests/smoke.test.sh's egress-credential step were structurally
incapable 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

Was Now
LOGS_KEPT is undefined if [[ -d "${LOGS_KEPT:-}" ]]; then ! grep -rqF -- "$PAT" "$LOGS_KEPT" || fail — LOGS_KEPT is set nowhere in the repository, so this tested [[ -d "" ]]: always false, never ran the path is read from the one place that names it, smoke.sh's cleanup line # logs kept in DIR (smoke.sh:201); every directory named is checked, and one that does not resolve fails rather than skipping
a || true on 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 way the fake mocactl keeps the add's stdin as cred-NAME.read (the delete leaves it behind); the test cmps it against the token file

The 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 file
whole (smoke.sh:685), so the bytes the fake receives still carry it. The assertion is for the
bytes 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_logs plants a PAT
canary in a failing run's kept logs and asserts nopat fails. It runs after the first
credfail, since a failing run is what keeps its logs. 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

Verification

Each new assertion was verified to fail against the defect it guards, not merely to pass:

Mutation Result
the dead LOGS_KEPT line restored nopat passed with the PAT planted in the kept logs: the kept-logs check is a no-op
smoke.sh made to write the PAT into a kept log the PAT is in the kept logs (...) — the real leak the old line would have missed
an empty stdin to credentials add the add's stdin is not the token file: EOF on ...cred-smoke-gh.read
a wrong token of the same length the add's stdin is not the token file: ... differ: char 5, line 1

smoke.sh was restored byte-identical after each mutation (git diff clean).

smoke.test.sh                        20/20 ok
install-host, setup, janitor, status, overlay   all exit 0

shellcheck is unchanged from the baseline on this file — the same pre-existing SC2016 infos on
backticks in message strings, no new findings.

What this does not do

#653's other sections are untouched, hence Refs rather than Closes. The second bullet of the
same "do first" group (drop_branch reporting success on a 404; a failed add triggering a
spurious delete; the fixed smoke-gh name colliding between concurrent runs) is in smoke.sh
itself, not the test, and is left for its own change.

Refs #653

Assisted-By: Claude Code

`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]>
@cwiklik
cwiklik requested a review from pdettori as a code owner October 28, 2026 18:58
@cwiklik cwiklik added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 28, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

@pdettori
pdettori merged commit c3a55b8 into rossoctl:main Oct 28, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants