Skip to content

[Hackathon] Fresh batch --wait returns exit 7 instead of auth exit 3 when tests remain deferred #471

Closed

Description

@luckyzd

Verified against (commit SHA or released version)

commit 988c035 (public main checked 2026-10-17; package v0.14.0), Node v22.23.2, macOS

Discord Username / User ID

luckyzd.

What does this improvement do?

When test run --all --wait has an accepted run whose poll fails with 401 AUTH_INVALID, adding one unresolved rate-deferred test changes the command's exit code from 3 to 7. The emitted accepted row still contains AUTH_INVALID and exitCode: 3, but the top-level error tells the operator to retry the deferred test after ~60 seconds.

CI/agents that branch on the documented exit code miss the need to replace credentials. Authentication precedence should remain higher than incomplete/deferred status; a genuinely incomplete batch without a higher-priority error must still be nonzero.

Details / implementation notes

Reproduction and results

Mock one accepted run t1/r1; its poll returns HTTP 401 with AUTH_INVALID. Compare the same response with and without a deferred t2 (which stays deferred across retry attempts):

Case Accepted row error Actual command exit Expected
No deferred test (control) AUTH_INVALID, exitCode 3 3 3
One unresolved deferred test AUTH_INVALID, exitCode 3 7, “retry ... after ~60s” 3 with authentication remediation

Both cases were rerun on the stated public main commit. This is an offline command-handler reproduction, not a claim about a live service outage. Build passed.

Cause and proposed scope

The deferred gate in runTestRunAll throws before resolveWaitFailure(freshRunResults). The existing result correctly preserves the auth error; final precedence is the problem. The shared wait-error precedence is documented in DOCUMENTATION.md.

Preserve the existing deferred output and incomplete-batch behavior while resolving higher-priority auth/client errors first. Add a regression for auth plus deferred, the no-deferred control, and deferred-only incomplete behavior. No new dependency or API change is needed.

Related reports checked

This is an issue-first Season 4 hackathon submission. No fix PR is being opened yet; I will wait for maintainer acceptance and claim the issue before implementing it.

Self-contained offline reproduction

Save this as repro-b06.mjs, run npm run build in the repository, then run node repro-b06.mjs /path/to/testsprite-cli with Node 22. It uses dependency-injected fetch responses, a fake key, and temporary files; no external requests or paid runs.

import { resolve, join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import assert from 'node:assert/strict';

// Offline injected HTTP responses only; no live credentials or paid runs.
const root = resolve(process.argv[2] ?? 'work/testsprite-cli');
const { runTestRunAll } = await import(pathToFileURL(join(root, 'dist/commands/test.js')));
const dir = await mkdtemp(join(tmpdir(), 'testsprite-b06-'));
try {
  for (const deferred of [false, true]) {
    const output = [], requests = [];
    let dispatches = 0, failure;
    try {
      await runTestRunAll({ profile: 'default', output: 'json', debug: false,
        projectId: 'project_local', wait: true, timeoutSeconds: 1, maxConcurrency: 2,
        environmentResolutionComplete: true, idempotencyKey: 'offline-b06' }, {
        env: { TESTSPRITE_API_KEY: 'sk-user-offline-repro', TESTSPRITE_API_URL: 'https://mock.example.com' },
        credentialsPath: join(dir, 'absent'), stdout: s => output.push(s), stderr: () => {}, sleep: async () => {},
        fetchImpl: async (url, init = {}) => {
          requests.push({ url: String(url), method: init.method ?? 'GET' });
          if (init.method === 'POST') return new Response(JSON.stringify({
            accepted: dispatches++ === 0 ? [{ testId: 't1', runId: 'r1', enqueuedAt: '2026-10-17T00:00:00Z' }] : [],
            deferred: deferred ? [{ testId: 't2' }] : [], conflicts: [], skippedFrontend: [], skippedIntegration: [],
          }), { status: 202 });
          return new Response(JSON.stringify({ error: { code: 'AUTH_INVALID',
            message: 'Offline authentication error', nextAction: 'Replace key', requestId: 'req_b06' } }), { status: 401 });
        },
      });
    } catch (err) { failure = err; }
    assert.equal(failure?.exitCode, deferred ? 7 : 3);
    assert.ok(output.some(s => s.includes('AUTH_INVALID')));
    console.log(JSON.stringify({ candidate: 'B06', deferred, exitCode: failure.exitCode,
      code: failure.code, message: failure.message, output, requests }));
  }
} finally { await rm(dir, { recursive: true, force: true }); }

Confirmations

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

Activity

  1. added
    needs-triage
    hackathon
    on Oct 17, 2026
  2. zeshi-du commented on Oct 20, 2026

    @zeshi-du
    Contributor

    Thanks @luckyzd, accepted. Confirmed on v0.15.0: in runTestRunAll the rate-deferred gate throws exit 7 before resolveWaitFailure(freshRunResults, ...) runs, masking an auth error. Batch rerun already checks auth first.

    Scope:

    • Run the auth check ahead of the deferred gate, mirroring the rerun path and reusing resolveWaitFailure. Don't copy or reorder the precedence table in src/lib/wait-exit.ts.
    • Only change: auth (3) beats deferred 7. Deferred-only still exits 7 with the same message; timeouts and ordinary test failures must not outrank the deferred gate.
    • Mocked-fetch tests: auth plus deferred expects 3 (must fail before your fix), no-deferred control expects 3, deferred-only expects 7. Assert exit code, not the error code string.
    • [Hackathon] Batch --wait auth failure exits 3 but the JSON envelope says CLI_ERROR #398 changes that string in the same path and we'll merge the two together, so rebase if it lands first.
    • Keep the diff small; this command is being reshaped later.

    Comment /assign to claim it.

  3. added
    accepted
    and removed
    needs-triage
    on Oct 20, 2026
  4. luckyzd commented on Oct 20, 2026

    @luckyzd
    ContributorAuthor

    /assign

  5. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Thanks @luckyzd! You're at the 3-issue limit, so I haven't assigned this one. Please finish or /unassign one first, then comment again here.

    Your open assigned issues (3/3):

  6. Lexiie commented on Oct 20, 2026

    @Lexiie
    Contributor

    /assign

  7. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Thanks @Lexiie! You're at the 3-issue limit, so I haven't assigned this one. Please finish or /unassign one first, then comment again here.

    Your open assigned issues (3/3):

  8. yeziR4 commented on Oct 20, 2026

    @yeziR4
    Contributor

    /assign

    I will implement the accepted auth-before-deferred precedence fix, reusing resolveWaitFailure and adding the three requested mocked-fetch regression cases. Discord: ___h___r

  9. added
    in-progress
    on Oct 20, 2026
  10. testsprite-hob commented on Oct 20, 2026

    @testsprite-hob

    Assigned to @yeziR4. Thanks for taking this on. (1 more slot available.)

    Your open assigned issues (2/3):

  11. added a commit that references this issue on Nov 11, 2026
    93108a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedhackathonin-progress

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions