Repository navigation
Description
Verified against (commit SHA or released version)
Public main commit 988c0355bb05631e9c6c1785e443937ff2a88c0e (checked 2026-10-17), package v0.14.0, Node v22.23.2, macOS. Reproduced through the compiled CLI entry point with local HTTP fixtures; no live service mutations.
Discord Username / User ID
luckyzd.
What does this improvement do?
test rerun --all --env staging --status failed --wait selects tests using the default environment's status, then dispatches that selected subset to staging. It can skip the actual staging failures, rerun only already-passing staging tests, and exit 0.
The environment is forwarded to the POST but omitted from the GET used for status-based selection. This affects which tests execute, not just the displayed status.
Reproduction scenario
Use a frontend project whose default environment is production, with these latest environment-specific results:
| Test | Production (default) | Staging |
|---|---|---|
test_staging_failure |
passed | failed |
test_production_failure |
failed | passed |
Compare:
testsprite test list --project project_env --env staging --status failed --output json
# Correctly selects test_staging_failure.
testsprite test rerun --all --project project_env --env staging --status failed --wait --output json
# Actually dispatches only test_production_failure.
# It passes in staging; summary: passed=1, failed=0, total=1; exit 0.
# test_staging_failure is never dispatched.
testsprite test rerun --all --project project_env --env staging --wait --output json
# Control without the status filter: both tests dispatch.
# test_staging_failure fails; exit 1.Expected: the first rerun selects test_staging_failure, using the same environment-scoped statuses as test list --env staging. If that test still fails, the wait returns a failing verdict.
Observed request trace for the incorrect command:
GET /api/cli/v1/tests?projectId=project_env&pageSize=25
(environment omitted)
POST /api/cli/v1/tests/batch/rerun
{"source":"cli","testIds":["test_production_failure"],"autoHeal":true,"environment":"staging"}
GET /api/cli/v1/runs/run_test_production_failure?waitSeconds=...
-> passed
stdout summary: {"passed":1,"failed":0,"timedOut":0,"deferred":0,"conflicts":0,"notFound":0,"total":1}
process exit: 0
With only test_staging_failure in the project, the filtered rerun instead reports no matches and exits 5, despite staging having a failed test. --skip-terminal has the same environment-selection gap: a test terminal in production but nonterminal in staging is excluded based on production.
Details / implementation notes
Root cause
In the all-project enumeration and filters, runTestRerunCore fetches:
query: { projectId: opts.projectId!, pageSize, cursor }It then applies --skip-terminal and --status to t.status. The normalized environment is available in this function, but only reaches the later dispatch body.
By contrast, runList already sends environment in the list query. Its older-server guard also refuses to pretend an unscoped answer is environment-scoped.
Suggested scope: carry the selected environment through every page of rerun enumeration before applying status/terminal filters, and preserve the existing fail-closed behavior for servers that cannot supply environment-scoped statuses. Keep behavior without --env unchanged.
Validation
Eight subprocess scenarios ran the unmodified dist/index.js, with a disposable HOME, fake API key, telemetry/update checks disabled, and a fetch fixture that rejects unexpected routes instead of sending network requests:
| Scenario | Observed |
|---|---|
test list --env staging --status failed |
Correct staging-failure selection |
rerun --all --env staging --status failed --wait |
Wrong test dispatched; false-green exit 0 |
| Same filtered rerun, only the staging-failed test exists | No dispatch; false empty selection, exit 5 |
| Unfiltered staging rerun | Both tests run; real failure, exit 1 |
| Default-environment status filter | Correct default selection, exit 1 |
| Explicit production status filter | Correct production selection, exit 1 |
| Staging status filter with two list pages | Environment omitted on both GETs; wrong selection, exit 0 |
Staging --skip-terminal with opposite terminal/nonterminal states |
Wrong environment's terminal test excluded |
Existing focused suites also pass: 554 tests across src/commands/test.rerun.spec.ts and src/commands/test.test.ts. The current rerun --env tests cover dispatch forwarding, but do not cover environment-aware --all selection.
This is a deterministic CLI-side reproduction against the environment-aware response shape already supported in this repository, not a claim that I reproduced it against a live customer account.
Self-contained offline reproduction (eight complete CLI invocations)
After npm ci && npm run build, save the following as reproduce-rerun-environment-selection.mjs in the repository root and run node reproduce-rerun-environment-selection.mjs .. It asserts the currently observed behavior and prints request/response evidence.
import assert from 'node:assert/strict';
import { execFile } from 'node:child_process';
import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { promisify } from 'node:util';
// Runs the real compiled CLI with a local fetch fixture. No live requests,
// real API keys, tests, deployments, or charges are involved.
const exec = promisify(execFile);
const root = resolve(process.argv[2] ?? 'work/testsprite-cli');
const temp = await mkdtemp(join(tmpdir(), 'testsprite-rerun-env-'));
const preload = join(temp, 'fixture.mjs');
await writeFile(preload, `
import assert from 'node:assert/strict';
import { writeFileSync } from 'node:fs';
const scenario = JSON.parse(process.env.REPRO_SCENARIO);
const seen = [];
const runs = new Map();
process.on('exit', () => writeFileSync(process.env.REPRO_TRACE, JSON.stringify(seen)));
const json = body => new Response(JSON.stringify(body), {status: 200, headers: {'content-type':'application/json'}});
const rows = scenario.rows.map(row => ({
id: row.id, name: row.id, projectId: 'project_env', type: 'frontend',
createdFrom: 'cli', createdAt: '2026-10-16T00:00:00Z', updatedAt: '2026-10-17T00:00:00Z',
status: row.production, headlineEnvironment: {id:'env_production',name:'production'},
statusByEnvironment: [
{environmentId:'env_production',environmentName:'production',status:row.production},
{environmentId:'env_staging',environmentName:'staging',status:row.staging},
],
}));
globalThis.fetch = async (input, init = {}) => {
const url = new URL(typeof input === 'string' ? input : input.url ?? input.href);
const method = init.method ?? 'GET';
const body = init.body ? JSON.parse(String(init.body)) : undefined;
seen.push({method, path:url.pathname, query:Object.fromEntries(url.searchParams), ...(body ? {body} : {})});
assert.equal(url.hostname, 'mock.example.com', 'unexpected network destination');
const path = url.pathname.replace('/api/cli/v1', '');
if (method === 'GET' && path === '/tests') {
const environment = url.searchParams.get('environment') ?? 'production';
assert.ok(['production','staging'].includes(environment));
let items = rows.map(row => ({...row,
status:row.statusByEnvironment.find(item => item.environmentName === environment).status,
headlineEnvironment:{id:'env_'+environment,name:environment},
}));
const statuses = url.searchParams.get('status')?.split(',');
if (statuses) items = items.filter(row => statuses.includes(row.status));
if (scenario.paged && items.length > 1) {
const later = url.searchParams.get('cursor') === 'page-2';
return json({items:later ? items.slice(1) : items.slice(0,1),nextToken:later ? null : 'page-2'});
}
return json({items,nextToken:null});
}
if (method === 'GET' && path === '/projects/project_env/env') return json({
environments:[
{id:'env_production',name:'production',url:'https://production.example.com',isDefault:true,isTemporary:false},
{id:'env_staging',name:'staging',url:'https://staging.example.com',isDefault:false,isTemporary:false},
],
});
if (method === 'GET' && path.startsWith('/tests/')) {
const row = rows.find(row => path === '/tests/'+row.id);
if (row) return json(row);
}
if (method === 'POST' && path === '/tests/batch/rerun') {
const environment = body.environment ?? 'production';
const accepted = body.testIds.map(id => {
const row = scenario.rows.find(row => row.id === id);
assert.ok(row, 'unexpected test id');
const runId = 'run_'+id;
runs.set(runId, {testId:id, status:row[environment] === 'failed' ? 'failed' : 'passed'});
return {testId:id,runId,enqueuedAt:'2026-10-17T00:00:00Z'};
});
return json({accepted,conflicts:[],deferred:[],notFound:[],closure:{byProject:[]}});
}
if (method === 'GET' && path.startsWith('/runs/')) {
const runId = path.slice('/runs/'.length);
const run = runs.get(runId);
assert.ok(run, 'unexpected run');
return json({runId,...run,projectId:'project_env',userId:'fixture_user',source:'cli',
createdAt:'2026-10-17T00:00:00Z',startedAt:'2026-10-17T00:00:01Z',finishedAt:'2026-10-17T00:00:02Z',
codeVersion:'v1',targetUrl:'https://staging.example.com',createdFrom:'rerun:previous',
failedStepIndex:run.status === 'failed' ? 1 : null,failureKind:run.status === 'failed' ? 'assertion' : null,
error:null,videoUrl:null,stepSummary:{total:1,completed:1,passedCount:run.status === 'passed' ? 1 : 0,failedCount:run.status === 'failed' ? 1 : 0},
});
}
throw new Error('Unexpected fixture route: '+method+' '+path);
};
`);
const rows = [
{id:'test_staging_failure',production:'passed',staging:'failed'},
{id:'test_production_failure',production:'failed',staging:'passed'},
];
const rerun = ['test','rerun','--all','--project','project_env','--wait','--timeout','5'];
const cases = [
{name:'list-staging-control',args:['test','list','--project','project_env','--env','staging','--status','failed'],rows,code:0,selected:['test_staging_failure']},
{name:'rerun-staging-wrong-test-green',args:[...rerun,'--env','staging','--status','failed'],rows,code:0,selected:['test_production_failure']},
{name:'rerun-staging-empty-despite-failure',args:[...rerun,'--env','staging','--status','failed'],rows:rows.slice(0,1),code:5,selected:[]},
{name:'rerun-staging-unfiltered-control',args:[...rerun,'--env','staging'],rows,code:1,selected:rows.map(row=>row.id)},
{name:'rerun-default-control',args:[...rerun,'--status','failed'],rows,code:1,selected:['test_production_failure']},
{name:'rerun-production-control',args:[...rerun,'--env','production','--status','failed'],rows,code:1,selected:['test_production_failure']},
{name:'rerun-staging-paginated',args:[...rerun,'--env','staging','--status','failed'],rows,paged:true,code:0,selected:['test_production_failure']},
{name:'rerun-staging-skip-terminal',args:[...rerun,'--env','staging','--skip-terminal'],rows:[
{id:'test_staging_ready',production:'passed',staging:'ready'},
{id:'test_production_ready',production:'ready',staging:'passed'},
],code:0,selected:['test_production_ready']},
];
const results = [];
try {
for (const item of cases) {
const traceFile = join(temp, item.name+'.json');
let stdout = '', stderr = '', code = 0;
try {
({stdout,stderr} = await exec(process.execPath,['--import',preload,join(root,'dist/index.js'),...item.args,'--output','json'],{
cwd:temp,timeout:15000,
env:{PATH:dirname(process.execPath)+':/usr/bin:/bin',HOME:temp,
TESTSPRITE_API_KEY:'sk-user-offline-fixture',TESTSPRITE_API_URL:'https://mock.example.com',
TESTSPRITE_NO_TELEMETRY:'1',TESTSPRITE_NO_UPDATE_NOTIFIER:'1',
REPRO_SCENARIO:JSON.stringify(item),REPRO_TRACE:traceFile},
}));
} catch (err) {
if (typeof err.code !== 'number') throw err;
({stdout,stderr,code} = err);
}
const trace = JSON.parse(await readFile(traceFile,'utf8'));
const payload = JSON.parse(stdout);
const dispatches = trace.filter(req=>req.method === 'POST');
const selected = item.name.startsWith('list') ? payload.items.map(row=>row.id) : dispatches.flatMap(req=>req.body.testIds);
assert.equal(code,item.code,item.name+' exit');
assert.deepEqual(selected,item.selected,item.name+' selected tests');
const listRequests = trace.filter(req=>req.path === '/api/cli/v1/tests');
assert.ok(listRequests.length > 0);
if (item.name.startsWith('list')) assert.equal(listRequests[0].query.environment,'staging');
else assert.ok(listRequests.every(req=>req.query.environment === undefined));
if (item.paged) assert.equal(listRequests.length,2);
if (item.name === 'rerun-staging-wrong-test-green') {
assert.equal(payload.summary.passed,1);
assert.equal(payload.summary.total,1);
assert.equal(dispatches[0].body.environment,'staging');
}
results.push({name:item.name,args:item.args,rows:item.rows,exitCode:code,selected,listRequests,dispatches,stdout,stderr});
}
console.log(JSON.stringify({node:process.version,platform:process.platform,results},null,2));
} finally { await rm(temp,{recursive:true,force:true}); }Deduplication and workflow
Searched open/closed Issues and PRs for rerun, environment, status, staging/filter, and statusByEnvironment on 2026-10-17; no matching report found.
- [Hackathon] test rerun: explicit IDs + --all silently reruns the ENTIRE project; --status/--skip-terminal silently ignored without --all #160 / fix(rerun): reject explicit IDs with --all and --status/--skip-terminal without --all #163 concern invalid flag combinations (
--statuswithout--all, or explicit IDs plus--all). This reproducer uses a valid--allcombination; the status filter executes against the wrong environment projection. - [Hackathon] fix(test): flags documented "with --history / --run / --all" are silently ignored without that flag (their siblings exit 5) #376 concerns options ignored when their required enabling flag is absent;
--allis present here. - [Hackathon] fix(test): batch
--wait409 auto-attach skips the environment/targetUrl checks the single-run path enforces #387 concerns attaching to an existing run from another environment after a 409. This reproducer has no conflict or auto-attach: the wrong test IDs are selected before successful fresh rerun dispatch. - [Hackathon] fix(rerun): batch
--waitexits 0 when refused conflicts leave the rerun incomplete #380 concerns accepted-plus-conflict batches; this reproducer has no conflicts or deferred tests.
This is a TestSprite Season 4 CLI hackathon submission. Awaiting maintainer triage before claiming and implementing; no implementation PR opened.
Confirmations
- I have searched existing issues and this is not a duplicate.
- I have provided my Discord identity above for reward coordination.
Activity
zeshi-du commentedon Oct 20, 2026
Thanks @luckyzd. Your root-cause reading matches v0.15.0:
test rerun --allfetches the test list without the environment (L13223-L13227) before applying--skip-terminaland--status, whereastest listsends it (L1061-L1067). We did not re-run your scenario.test rerunis being folded intotest run, deprecated in an upcoming release and removed in 1.0, so we're not taking changes to rerun-only paths. We've noted that status selection with--envshould use that environment's status for thetest run --all --statuswork. Tracked internally as DEV-2028.Closing as not planned.