Skip to content

[Hackathon] fix(test): multi-id test cancel and test delete-batch exit 1 on a rejected API key (or too-old CLI) instead of 3 / 14 #373

Closed

Description

@protonjls

Verified against (commit SHA or released version)

commit 988c0355bb05631e9c6c1785e443937ff2a88c0e (main, v0.14.0)

Discord Username / User ID

1149447580477042769

What does this improvement do?

The exit-code table in DOCUMENTATION.md is a scripting contract: 3 means auth, 14 means the client is too old. The single-id forms of test cancel and test delete honour it. So does multi-id test wait, and since #33 (fixing #78, reported by @crypticsaiyan) so does batch test rerun, where "any auth failure escalates the whole batch to exit 3". The two remaining multi-id commands do not:

  • test cancel <run-a> <run-b> (the multi-id summary path)
  • test delete-batch <id-a> <id-b> --confirm

Each catches every member error other than 404/409 into a generic error row and then throws CLIError(…, 1). A revoked or mistyped key (AUTH_INVALID/AUTH_REQUIRED/AUTH_FORBIDDEN) or a too-old CLI (CLIENT_TOO_OLD) therefore exits 1, the "generic failure" bucket. Under --output json the error envelope says "code": "CLI_ERROR", so a script or agent cannot tell "re-authenticate / upgrade" apart from "something failed on the server". This is exactly the signal the multi-id test wait and batch-rerun paths were fixed to preserve.

Reproduction. A local mock API that answers every request with a typed error envelope stands in for a revoked key, so no account is needed:

// mock.mjs — node mock.mjs <port> <status> <code>
import http from 'node:http';
const [port, status, code] = [Number(process.argv[2]), Number(process.argv[3]), process.argv[4]];
http.createServer((req, res) => {
  res.writeHead(status, { 'content-type': 'application/json' });
  res.end(JSON.stringify({ error: { code, message: `mock ${code}`, nextAction: '', requestId: 'req_1' } }));
}).listen(port, '127.0.0.1');
node mock.mjs 18733 401 AUTH_INVALID &
export TESTSPRITE_API_KEY=sk-user-abcdefghijklmnopqrstuvwxyz0123456789
ts() { testsprite --endpoint-url http://127.0.0.1:18733 "$@" >/dev/null 2>&1; echo "exit=$?  $*"; }
ts test cancel run_a
ts test cancel run_a run_b
ts test delete t_a --confirm
ts test delete-batch t_a t_b --confirm
ts test wait run_a run_b --timeout 5

Actual output:

exit=3  test cancel run_a
exit=1  test cancel run_a run_b          <- expected 3
exit=3  test delete t_a --confirm
exit=1  test delete-batch t_a t_b --confirm   <- expected 3
exit=3  test wait run_a run_b --timeout 5

With the mock answering 426 CLIENT_TOO_OLD instead, test cancel run_a exits 14, but test cancel run_a run_b and test delete-batch t_a t_b --confirm both exit 1.

Multi-id test cancel --output json puts this on stderr:

{ "error": { "code": "CLI_ERROR", "message": "2 cancel requests failed: run_a run_b", ... } }

Expected. These two commands should give the same answer for the same batch-wide failure as their single-id forms and the other fan-outs: exit 3 for an auth error and 14 for CLIENT_TOO_OLD. They should also keep printing the per-id summary on stdout as they do today.

Details / implementation notes

Root cause (src/commands/test.ts):

  • runTestCancel, multi-id loop: rows.push({ runId, status: 'error', error: message }), then throw new CLIError(${errorRows.length} cancel request… failed: …, 1).
  • runDeleteBatch: results.push({ testId, status: 'error', error: msg }), then throw new CLIError(${failed} deletion… failed. …, 1).

The precedence already exists. src/lib/wait-exit.ts documents auth (3) and CLIENT_TOO_OLD (14) as batch-wide, sitting at the top of WAIT_EXIT_PRIORITY, because "a bad credential / too-old client fails EVERY poll and retrying can never succeed". isAuthCode() in src/lib/errors.ts is the shared classifier.

Proposed change (small, no output-shape change):

  1. In both loops, keep the caught ApiError beside its row; the row's printed/JSON shape stays unchanged.
  2. After the summary is printed, if any errored member carries a batch-wide code (isAuthCode(code) or CLIENT_TOO_OLD), rethrow that member's ApiError. That gives exit 3 or 14 and a typed --output json envelope (AUTH_INVALID plus its nextAction), the same as the single-id form. This check runs before the existing notFound → 4, errors → 1, conflict → 6 ordering, which is otherwise left as it is.
  3. Add the new row to the "Exit codes" block in both commands' --help.

Tests (mock-based, in src/commands/test.cancel.spec.ts and next to the existing runDeleteBatch tests):

  • 401 on every id → exit 3, summary still on stdout;
  • 426 → exit 14;
  • a mix of cancelled + 401 → exit 3;
  • the existing notFound/conflict precedence tests unchanged.

Each new test fails on main today.

Out of scope: stopping the loop early after the first auth failure. The other fan-outs don't do that either.

I'd like to work on this once it's triaged.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. zeshi-du commented on Oct 20, 2026

    @zeshi-du
    Contributor

    Thanks @protonjls for the thorough report and repro. Accepted: in v0.15.0 both multi-id paths fold any error other than not-found/conflict into a generic row and exit 1.

    Scope:

    • Only the multi-id path of test cancel and test delete-batch in src/commands/test.ts.
    • Keep the caught ApiError with its row. After the summary prints, rethrow it (keeps the real code and nextAction in --output json) if any member failed with an auth code (isAuthCode, exit 3), else CLIENT_TOO_OLD (exit 14). Auth wins, as in src/lib/wait-exit.ts. Don't call resolveWaitFailure; it promotes other codes.
    • Leave exit 1, the 4/6 behaviour, other codes and the stdout summary shape alone.
    • Add both rows to the --help exit-code blocks and DOCUMENTATION.md.

    Mock tests: 401 -> 3 with summary printed, 426 -> 14, cancelled + 401 -> 3; each must fail on current main. /assign to claim.

  2. added
    accepted
    on Oct 20, 2026
  3. protonjls commented on Oct 20, 2026

    @protonjls
    ContributorAuthor

    /assign

    Thanks @zeshi-du. I'll follow that scope: auth wins over CLIENT_TOO_OLD, no resolveWaitFailure, 1/4/6 and the summary shape unchanged, and help + DOCUMENTATION rows added. I'll rebase onto v0.15.0 first.

  4. added
    in-progress
    on Oct 20, 2026
  5. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Assigned to @protonjls. Thanks for taking this on. (2 more slots available.)

    Your open assigned issues (1/3):
    (none)

  6. added a commit that references this issue on Nov 1, 2026
    1e70dfa
  7. added a commit that references this issue on Nov 10, 2026
    2924160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedin-progress

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions