Repository navigation
fix(browser): reserve the initial scenario step id from action inputs - #3493
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; the reserved-ID check stops collisions before browser capture. SummaryReserves
Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
|
TL;DR: The new test fails on main and passes with this PR. A browser scenario action can no longer use the id scenario_start. Similar ids such as scenario_start_2 still work. Thanks, NIU-123370, for the fix. I ran the PR's new test on main 62bf098 (#4169). The file is
The test also checks that scenario_start_2 stays valid. That check passed. Not run
Commands# main 62bf09809 extracted to a work tree, then npm ci, npm run build, npm run test:prepare
patch -p1 -d <tree> < 3493.tests.diff
npm run test:focused -- src/domain/browserScenario.test.ts # exit 1
patch -p1 -d <tree> < 3493.src.diff
npm run test:focused -- src/domain/browserScenario.test.ts # exit 0Test setup🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
# Conflicts: # src/domain/browserScenario.test.ts # src/domain/browserScenarioValues.ts
|
CI-track update: I merged latest
Locally |
Summary
Fixes #3391.
capture-browser-scenarioaccepted a caller action whosestep_idwasscenario_start, the identity the provider independently gives to theinitial-state step, so one capture carried two steps with the same ID and could
not even be compared with itself.
validateBrowserScenarioalready requires caller step IDs to be unique amongthemselves (
src/domain/browserScenario.ts), but nothing reserved thegenerated identity. This adds that missing reservation at the accepted-input
boundary and names the identity in one owner instead of leaving it as a bare
literal in the provider.
Problem and expected behavior
step_id: "scenario_start".docs/browser-scenario-contract.mdpromises an initialstate followed by one record per declared action, and comparison "aligns only
by exact, unique
step_id". A colliding identity makes a complete captureambiguous (
overall_status: "unknown"with alignment failures).runs rather than accepted and turned into ambiguous Evidence — that is what
this does.
Before/after, executed through the compiled CLI (no browser involved, because
validation now precedes launch):
The control proves the rejection is specific to the reserved identity rather
than a general input problem.
Change and scope
src/domain/browserScenarioValues.ts— one exported owner,BROWSER_SCENARIO_START_STEP_ID, documented as the identity the provider owns.src/domain/browserScenario.ts— the input refinement rejects any declaredaction that claims it and reports the exact offending path
(
actions[i].step_id), next to the existing uniqueness rule.src/browser/PlaywrightBrowserScenarioProvider.ts— the initial-state stepnow uses the constant instead of a local literal, so the accepted-input rule
and the producer cannot drift apart.
src/domain/browserScenario.test.ts— the new case asserts three things: thereserved id is refused, the issue path points at the second action (not just
the first), and a similar-but-distinct id (
scenario_start_2) still validates,so the rule stays exact rather than prefix- or substring-based.
Equivalence class checked:
PlaywrightBrowserScenarioProvider.tsis the onlyproducer of a synthetic step identity in
src/browser(stepId: "…"occursonce), and the Electron active path
(
src/browser/PlaywrightBrowserScenarioProvider.tssiblingPlaywrightElectronActiveActions.ts:104,118) records only caller-supplied ids,so it has no reserved identity to collide with and is untouched.
Intentionally not included:
rewriting would make step Evidence depend on positional luck.
docs/browser-scenario-contract.md: its existing"exact, unique
step_id" sentence already covers the invariant, and two openPRs (fix(browser): compare concurrent scenario network events by their request step, not receipt order #2637, fix(security): bound scenario retention and loopback admission #2961) currently touch that file. A one-line "the initial-state ID
is reserved" note is worth adding, but I would rather do it after those land.
browserScenarioInputSchemawhilesrc/server/registerBrowserScenarioTool.ts:37and
src/cliBrowserScenarioCommands.ts:39re-parse accepted input withbrowserScenarioSchema; the new rule therefore rides the same path as thepre-existing uniqueness rule rather than inventing a second gate.
Contract and boundary impact
browserScenarioValues.tsowns theidentity; earliest stage is accepted-input validation, before any browser
launch or Evidence construction.
existing boundary — not applicable.
change; one previously accepted (and broken) input now returns
invalid_requestwith a located issue path.scenario path only.
longer contain two steps with one identity, so
compare-web-capturesalignment for complete scenario captures stays well-defined. No existing
retained field changes.
launches — a colliding scenario now stops before the browser starts.
docs/public/product-catalog.json) / package /installation impact: none.
Expected effects:
Evidence and regression coverage
Tests added or updated: one new case in
src/domain/browserScenario.test.ts(rejection + offending-path precision + non-overbroad control).
Executed CLI pair: quoted above;
rea capture-browser-scenarioon the builtruntime, base
3b79af28.Mutation arms, each actually run against
src/domain/browserScenario.test.tsplussrc/browser/PlaywrightBrowserScenarioProvider.test.ts, tree restored andre-verified between arms:
22 passed (22)1 failed | 21 passed (22)1 failed | 21 passed (22)goto_start)1 failed | 21 passed (22)20 failed | 2 passed (22)1 failed | 21 passed (22)1 failed | 21 passed (22)3 failed | 19 passed (22)M2/M6 are killed only because the reserved id is placed at index 1 and the
path is asserted; M5 is killed by the
scenario_start_2control; M7 is whatbinds the producer to the same owner as the rule.
Remaining proof gaps: no end-to-end
capture-browser-scenariorun against areal browser in this session (the collision it prevents is now unreachable
through validation, and the browser-dependent suites are quoted below); the
advertised MCP schema still accepts the ID until the handler rejects it, which
matches how the existing uniqueness rule behaves.
Validation performed
npx vitest run src/domain/browserScenario.test.tsbefore the source change —1 failed | 4 passed (5); after — green.npx vitest run src/domain/browserScenario.test.ts src/browser/PlaywrightBrowserScenarioProvider.test.ts src/domain/browserScenarioDiff.test.ts tests/boundary/mcp/browserScenarioMcp.test.ts tests/boundary/cli/browserCli.test.ts—Test Files 5 passed (5),Tests 51 passed (51)(re-run after formatting).npx vitest run tests/boundary/cli/ tests/boundary/mcp/—
Test Files 213 passed | 2 skipped,Tests 1184 passed | 7 skipped; the twoinitially failing files (
contractPresentation,toolSchemaValidity) failedonly on the gitignored generated
.cache/mcp-tool-catalog.json, then passed(14 tests) after
node scripts/generate-mcp-catalog.mjs, so they are notaffected by this patch.
npm run build— exit 0 (Node 24.18.0), needed for the CLI proof.npm run typecheck— exit 0;npm run lint— exit 0(
Checked resolved module boundaries in 1878 source files.)../node_modules/.bin/oxfmt --check <the four changed files>— first passflagged one file, fixed with
oxfmt(not prettier), re-check exit 0,All matched files use the correct format.npm run jscpdwith the change —Duplication: 2715 files, 2006 clones, 3.22%; the same tree with the change reverted — byte-identical2715 files, 2006 clones, 3.22%, so this patch contributes zero clones(
.jscpd.jsonthreshold 3.5).check:ci, real browser scenario execution, other platforms.Compatibility, safety, and release
rejected. That input could only produce an ambiguous capture, so callers hit
by the rejection were already losing the comparison they asked for; the error
names the offending action index and is
retryable: true. No previouslyvalid, non-colliding call changes behavior.
touched; CLI validation proof executed on macOS arm64.
process launches; strictly an earlier refusal.
Author readiness
Human owner: @NIU-123370
Before merge
type(scope): outcome.