Skip to content

fix(cli): --no-publish stops the auto-publish attempt (#404) - #417

Merged
nc9 merged 1 commit into
mainfrom
fix/no-publish-404
Sep 30, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/no-publish-404

Conversation

@nc9

@nc9 nc9 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Closes #404

What was wrong

citty (0.1.6, and 0.2.x) turns any --no-X token into X: false and never sets a declared "no-X" arg. squirrel audit read args["no-publish"], which was always undefined, so a signed-in run auto-published anyway (or printed "Could not auto-publish" when the API call failed, as in the issue).

Passing both forms was also broken. Once both are in argv, citty's publish value depends on their order: --publish --no-publish gives false, --no-publish --publish gives [false, true], and -p --no-publish gives true. None of these hit the "cannot be combined" error, and every one ignored --no-publish.

Fix

  • New apps/cli/src/cli/flags.ts with hasNegatedFlag(rawArgs, name) and hasFlag(rawArgs, name, aliases). Both read citty's rawArgs from the command context, tokenized the way citty does it (stops at --; dash-led tokens are always flags, never values; single-dash clusters). The header comment covers the citty behaviour. The pattern for any --no-* flag: declare it for help and completions, then read it with hasNegatedFlag, never from args.
  • audit.ts: noPublish comes from hasNegatedFlag(rawArgs, "publish") and feeds all three resolvePublishDecision calls. When --no-publish is present, validateAuditFlags also counts any --publish/-p token in argv, so the pair errors in every order. Without --no-publish the parsed value is used as before, so --offline --publish=false is still valid.
  • validateAuditFlags takes one noPublish key (the no_publish spelling is gone).

Other no-* flags

rg -n '"no-' apps/cli/src finds only audit's no-publish. --no-incremental works: nothing declares no-incremental, and the code reads args.incremental. squirrel crawl has no publish flag and never publishes, so it needs no change.

Tests

  • tests/commands/audit-no-publish-wiring.test.ts runs the real audit command through citty.runCommand with raw argv, signed in with a fake token and a stubbed fetch. The control (no flag) sends POST /v1/reports and shows the warning. --no-publish sends no /v1/reports request and shows no warning. All four pair orders exit 1 with the error before any request. --offline --publish=false still runs. The test fails on main: 5 of 6 cases.
  • tests/cli/flags.test.ts pins citty's parse (no-publish is never set) and checks every hasFlag case against citty's own parse of the audit args.
  • Verified end to end: a subprocess squirrel audit https://example.com/ -m 1 with a scratch HOME and SQUIRREL_API_SERVER pointed at a local stub that records requests. Before the fix, --no-publish sent POST /v1/reports. After it, --no-publish sends only GET /v1/credits and POST /v1/agent-runs/register: run registration is by design, and the code comments say --no-publish still registers the run. The control still publishes.

Docs already describe the intended behaviour (--publish and --no-publish cannot be combined), so they are unchanged.

citty turns --no-publish into publish: false and never sets the declared
no-publish arg, so args["no-publish"] was always undefined and a
signed-in run published anyway. Read negated flags from rawArgs through
new cli/flags.ts helpers (hasNegatedFlag, hasFlag), and refuse
--publish/-p next to --no-publish in any order: citty's parsed publish
value depends on argv order once both are passed.

Tests drive the flags through citty's real parser: a wiring test runs
the audit command via runCommand with raw argv against a stubbed API
(control publishes, --no-publish makes no /v1/reports call, the pair is
refused before any request), and the helpers are checked against
citty's own parse of the audit args.

Closes #404

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/no-publish-404 branch from 2c90a65 to 9d25f81 Compare September 30, 2026 00:42
@nc9
nc9 marked this pull request as ready for review September 30, 2026 00:51
@nc9
nc9 merged commit ee95f19 into main Sep 30, 2026
14 checks passed
@nc9
nc9 deleted the fix/no-publish-404 branch September 30, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--no-publish does not stop the auto-publish attempt

1 participant