Skip to content

[Hackathon] fix(test): test diff compares runs that have no verdict yet — in-flight runs diff as "unchanged" (exit 0), and backend runs can never fail the gate #378

Closed as not planned

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?

test diff <run-a> <run-b> (added in #168 for #124) is documented as a CI gate: "Exit 0 when the verdicts match, 1 when they differ — so a script can assert 'this rerun behaves like the last known-good run' in one call." It reads both runs with GET /runs/{id} and compares status directly, without checking that either run has finished. A run's in-flight status is therefore scored as if it were a verdict:

run A run B test diff says exit
passed failed verdict: passed -> failed 1 ✓
passed queued verdict: passed -> queued, "verdicts differ" 1: a "regression" that is just a run in progress
running running verdict: unchanged (running) 0: a green gate with no verdict on either side

Backend tests are always in the last row. The CLI's own code says backend run rows never reach a terminal status on the run surface. From src/commands/test.run.spec.ts: "BE run rows never finalize server-side, so test run --wait falls back to…". That is why test run --wait, test rerun --wait, test wait and test flaky all go through makeBackendWaitFallback, which reads the verdict from GET /tests/{id}/result instead. test diff is the one run reader that does not. Diffing two backend runs compares two non-terminal rows, so the gate reports "unchanged" (exit 0) whether the second run passed or failed. As written, test diff cannot catch a backend regression.

(I have no account to observe a live backend run, so the backend part rests on the CLI's own fallback and its tests. The in-flight behaviour is reproduced below.)

Reproduction (offline). A local mock answers GET /runs/<id> with a run row whose status is given per id. Everything else is the stock CLI:

// mock-runs.mjs — node mock-runs.mjs <port> run_a=passed run_b=running …
import http from 'node:http';
const [port, ...pairs] = process.argv.slice(2);
const statuses = Object.fromEntries(pairs.map(p => p.split('=')));
const terminal = new Set(['passed', 'failed', 'blocked', 'cancelled']);
http.createServer((req, res) => {
  const m = /\/runs\/([^/?]+)/.exec(req.url); const status = m && statuses[m[1]];
  if (!status) { res.writeHead(404, {'content-type':'application/json'}); return res.end('{"error":{"code":"NOT_FOUND","message":"x","nextAction":"","requestId":"r"}}'); }
  const done = terminal.has(status);
  res.writeHead(200, {'content-type':'application/json'});
  res.end(JSON.stringify({ runId: m[1], testId: 'test_x', projectId: 'project_abc', userId: 'user_1', status, source: 'cli',
    createdAt: '2026-06-03T10:00:00.000Z', startedAt: '2026-06-03T10:00:01.000Z', finishedAt: done ? '2026-06-03T10:00:30.000Z' : null,
    codeVersion: 'v1', targetUrl: 'https://example.com', createdFrom: 'cli', failedStepIndex: status === 'failed' ? 2 : null,
    failureKind: status === 'failed' ? 'assertion' : null, error: null, videoUrl: null,
    stepSummary: { total: 5, completed: done ? 5 : 1, passedCount: done ? 5 : 1, failedCount: 0 } }));
}).listen(Number(port), '127.0.0.1');
node mock-runs.mjs 18762 run_good=passed run_bad=failed run_q=queued run_r1=running run_r2=running &
export TESTSPRITE_API_KEY=sk-user-abcdefghijklmnopqrstuvwxyz0123456789
ts() { testsprite --endpoint-url http://127.0.0.1:18762 "$@"; echo "exit=$?"; }
ts test diff run_good run_bad    # verdict: passed -> failed          exit=1
ts test diff run_good run_q      # verdict: passed -> queued          exit=1
ts test diff run_r1 run_r2       # verdict: unchanged (running)       exit=0

Expected. test diff reports a verdict comparison only between runs that have verdicts. When a run is still in flight, it says so and does not exit 0, and it points at the command that waits for the verdict.

Details / implementation notes

Root cause. runDiff in src/commands/test.ts sets verdictChanged: runA.status !== runB.status on the raw run rows, and enforceDiffExitContract maps that straight to exit 1 / exit 0. Nothing calls isTerminalStatus (src/lib/runs.types.ts) or the backend fallback.

Proposed change (contained in runDiff; the --dry-run sample stays as it is):

  1. After the two reads, for each run whose status is not terminal, try the existing backend path. If the test is backend and GET /tests/{testId}/result passes backendResultIsForThisRun(result, run.runId, …), overlay it with backendResultToRunResponse, the same helpers makeBackendWaitFallback uses. This resolves the test's latest backend run.

  2. If either run is still non-terminal after that, print no diff and refuse with a typed error. It names the run(s) without a verdict, gives nextAction: testsprite test wait <run-id>, and uses a non-zero, non-1 exit so a CI gate can't read it as "unchanged" or "regressed". My suggestion is a local PRECONDITION_FAILED (exit 6); I'm happy to use whatever the maintainers prefer.

  3. Tests in the describe('runDiff') block of src/commands/test.test.ts:

    • passed vs queued → refused (not exit 1);
    • running vs running → refused (not exit 0);
    • a backend run row that is non-terminal but whose /tests/{id}/result is for that run → diffed on the resolved verdict;
    • the existing terminal-vs-terminal cases unchanged.

    The first three fail on main today.

Out of scope: resolving verdicts for older backend runs that are no longer the test's latest result. Those get the refusal in step 2, which is still better than a silent "unchanged".

I already hold #372–#374, so this is free for anyone to pick up 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 detailed report and repro. We're closing this as not planned: test flaky and test diff are planned for removal in 1.0, so we're not taking changes to them.

    Your reading is right. test diff sets verdictChanged from a plain runA.status !== runB.status, and the exit contract maps that to exit 1 or 0, so two in-flight runs with the same status diff as unchanged. We haven't seen the backend-test case live.

    For gating, run testsprite test wait <run-id> on both runs (it becomes run wait in 1.0), then compare the final verdicts yourself.

    Closing as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions