Skip to content

[Hackathon] fix(test): batch --wait 409 auto-attach skips the environment/targetUrl checks the single-run path enforces #387

Closed

Description

@Herbicide7665

Verified against (commit SHA or released version)

commit 988c035 (v0.14.0)

Discord Username / User ID

weili_yang33

What does this improvement do?

Summary

When a batch create-and-run under --wait hits 409 run_in_flight for a test, runBatchRun attaches to the in-flight run by currentRunId without checking that the run's environment matches the requested --env, or that its target URL matches the requested --target-url. The batch then reports the in-flight run's verdict as if it were this invocation's result. The single-run path (runTestRun) validates both before attaching and refuses with incompatibleRun — the batch path skips that validation entirely.

What happened

  • src/commands/test.ts:4594-4633 — runBatchRun's triggerOne catches 409 run_in_flight, takes currentRunId from the error details, builds a synthetic triggerResponse (its targetUrl field is even filled with the requested value, not the running run's), and attaches the poll. The only guard is a tunnel-target exclusion; there is no environment comparison and no targetUrl comparison.
  • src/commands/test.ts:8030-8186 — the single test run path handles the same 409 by validating the in-flight run's environment against --env (null/missing counts as a mismatch) and requiring strict targetUrl equality before attaching, with a comment explaining that attaching blindly would "report a different environment's verdict as if it were the local one".

The batch path dispatches environment/targetUrl in its trigger body (test.ts:4470-4477), so the information needed for the same check is available there too.

Reproduction

  1. Test T already has a run in flight against the project default environment (started elsewhere).
  2. Run a batch that targets a different environment:
$ testsprite test create-batch --plans plans.jsonl --run --wait --env staging

where plans.jsonl re-declares T (same project, new spec), so the server answers 409 run_in_flight with the default-environment run's currentRunId.

  1. The CLI attaches silently, polls the default-environment run to a verdict, and reports it as the outcome of this --env staging batch. The exit code and JSON results[] carry the wrong environment's verdict. The single-run command in the same situation refuses with incompatibleRun instead.

Expected

The batch attach path should apply the same checks as runTestRun: verify the in-flight run's environment matches the requested --env (treating null/missing as a mismatch) and, when a --target-url was requested, require strict equality. On mismatch, do not attach — surface the conflict (exit 6) instead of reporting a foreign verdict.

Related

Details / implementation notes

The fix can reuse the validation block from runTestRun's 409 handler (the poll-fetch of the in-flight run's environment/targetUrl) as a shared helper for both paths. The existing batch 409 tests in test.create-batch-run.spec.ts provide the harness; the single-run attach tests in test.run.spec.ts show the mismatch assertions to mirror. Happy to pick this up.

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 12, 2026
  2. zeshi-du commented on Oct 20, 2026

    @zeshi-du
    Contributor

    Thanks @Herbicide7665, accepted, with a narrower scope. In v0.15.0 test run --all --wait already has this gate (runTestRunAll resume check using verifyInFlightRunEnvironment). The gap is only create-batch --run --wait: the 409 run_in_flight handler in runBatchRun attaches by currentRunId with no environment/targetUrl check. Please retitle the issue accordingly.

    Scope:

    • Reuse verifyInFlightRunEnvironment, mirroring the runTestRunAll gate (per-batch cached env listing per project).
    • On mismatch, don't attach: return the existing per-test CONFLICT error row (exit 6) with test wait <run-id> as next step. Other exit codes and no-flag attach behaviour unchanged.
    • Don't fill targetUrl from the request when attaching.
    • Mock-suite tests per branch, including one that fails on current main.
    • Don't touch poll/tail code or the output JSON.

    Feel free to claim it with /assign.

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

    @yeziR4
    Contributor

    /assign

    I will implement the accepted create-batch-only environment/target URL compatibility check, reusing verifyInFlightRunEnvironment and the existing per-test conflict row, with mocked regression tests. Discord: ___h___r

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

    @testsprite-hob

    Assigned to @yeziR4. Thanks for taking this on. (0 more slots available.)

    Your open assigned issues (3/3):

  7. added a commit that references this issue on Nov 10, 2026
    bb780d7
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