Skip to content

feat(browser): validate browser scenarios with --dry-run before launching - #7116

Closed
kaoru0822-kitauji wants to merge 2 commits into
mainfrom
feat/browser-scenario-dry-run
Closed

kaoru0822-kitauji wants to merge 2 commits into
mainfrom
feat/browser-scenario-dry-run

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

What broke: The only way to check a browser scenario file was to run it. A run discovers, launches or attaches to a browser and may change page state before a typo, a duplicate step ID or a missing secret variable is reported.
Fix: rea capture-browser-scenario <json> --dry-run applies the same JSON and path resolution, the same canonical schema and semantic rules, and the same secret-availability rule as a capture, all through shared owners. It then stops before any provider is created and returns either the same projected input error or a compact plan.
Risk: Low. The flag is opt-in. Without it the command is unchanged. The secret-availability rule moved verbatim from BrowserScenarioSecrets.resolve into the domain, and capture still uses it.

Summary

Fixes #5488

A dry run reports schema and semantic errors with field paths, using the exact projection a capture returns. On success it returns the browser mode, the start origin, every step in capture order, each declared secret with only environment_value: "present", and an explicit not_checked list. It creates no browser provider, profile, file or connection, and it never reads a secret value into its output.

Problem and expected behavior

  • Before: invalid input was reported only by running the command. A valid scenario immediately started browser acquisition.
  • Expected ([Feature] Add a validation-only command for browser scenario files #5488): an explicit validation-only workflow using the same rules as execution, reporting errors with field paths, catching duplicate step IDs and undeclared secret references, exiting successfully without a browser, never printing secret values, and with boundary tests showing that no browser or provider factory is invoked.

Change and scope

  • src/domain/browserScenario.ts: new browserScenarioSecretAvailability. This is the presence rule capture applied at session open: the variable must be an own property with a string value, and an empty string counts as set. It is moved from BrowserScenarioSecrets.resolve, which now calls it and then reads the values, so the rule has one owner and both paths return the same error.
  • src/application/BrowserScenarioCaptureService.ts: planBrowserScenario(scenario, environment) builds the plan from an already parsed scenario.
  • src/cliBrowserScenarioCommands.ts: adds the --dry-run option. Argument parsing, resolveCliJsonPaths and browserScenarioSchema are the same code path as a capture. The branch returns before the Playwright composition is imported or createProvider is called. Failures are labelled Browser scenario validation failed, with the same projected body.
  • Docs: a "Validate without a browser" section in docs/browser-scenario-contract.md, with an example plan.
  • Not included: an MCP tool. It would add catalog tokens for every agent, and MCP capture_browser_scenario already rejects schema-invalid input and missing secrets before acquiring a browser. Executable, endpoint and locator checks are also excluded, because they need discovery or a page; they are listed in not_checked instead.

Contribution scope: not applicable. This is an opt-in, read-only mode of an existing command that adds no target interaction.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the scenario schema (unchanged) and the secret-availability rule, now owned by the domain. BrowserScenarioSecrets is its consumer.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: the CLI gains --dry-run. MCP is unchanged.

  • Provider, bridge, target-format, or platform compatibility: none. The dry run never loads Playwright.

  • Evidence, artifact, provenance, or reconstruction contract: a dry run produces no Evidence. Its plan is not Evidence and claims nothing about the target.

  • Target selection, authority, upstream behavior, and cleanup details: no browser, profile, process or network access, and nothing to clean up.

  • Generated metadata, package, or installation impact: none. metadata:check passes.

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests added (tests/boundary/cli/browserScenarioDryRun.test.ts):
    • In process, with a createProvider spy that throws: a valid dry run returns the exact plan, the stdout never contains the secret value, and the spy is never called.
    • A missing secret variable returns exactly projectAnalysisError(BrowserScenarioSecrets.resolve(...).error), which is the capture rule's error, at ["secrets", 0, "environment_variable"]. An inherited (prototype) variable also counts as missing.
    • Duplicate step IDs plus an undeclared secret reference produce a projection identical to the non-dry-run command; only the error label differs. No provider is created in either mode.
    • Without the flag, the provider factory is called once, so execution is unchanged.
    • Through the compiled CLI process, with a nonexistent browser executable, a valid dry run exits 0 and never prints the secret value, and a missing secret exits non-zero with the field path.
  • Existing scenario suites still pass, including the BrowserScenarioSecrets producer tests.
  • User-visible CLI output (built CLI, on this branch):
    $ REA_DEMO_TOKEN=… rea capture-browser-scenario scenario.json --dry-run --json   # exit 0
    {"operation":"capture_browser_scenario","dry_run":true,"browser_mode":"launch","start_origin":"https://example.com","steps":[{"step_id":"scenario_start","action":"goto_start"},{"step_id":"open_account","action":"goto"}],"secrets":[{"secret_id":"api_token","environment_variable":"REA_DEMO_TOKEN","environment_value":"present"}],"not_checked":["browser executable, CDP endpoint and target discovery","browser launch or attachment","navigation, network reachability and page state","locator resolution, action outcomes and capture limits"]}
    $ rea capture-browser-scenario scenario.json --dry-run --json   # exit 1
    {"error":"Browser scenario validation failed","code":"invalid_request",…,"details":{"operation":"capture_browser_scenario","issues":[{"path":["secrets",0,"environment_variable"],"reason":"missing_argument",…}]}}
    
  • Remaining proof gaps: no real browser capture was run after the BrowserScenarioSecrets.resolve refactor, because no browser is installed on this host. The refactor is covered by the existing producer tests and by the equality assertion above.

Boundary regressions: input parsing and projection parity between modes, secret-environment admission (missing, inherited, present) and provider non-creation. There is no lifecycle stage, because no resource is acquired.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/cli/browserScenarioDryRun.test.ts tests/boundary/cli/scenarioCliInputDiagnostics.test.ts tests/boundary/cli/cliJsonCallerPath.test.ts tests/process-global/browserScenarioCleanup.test.ts tests/boundary/mcp/browserScenarioInputDiagnosticsMcp.test.ts: 23 passed.
  • npm run test:local -- src/browser/BrowserScenario.test.ts src/browser/PlaywrightScenarioRequest.test.ts: 51 passed.
  • npm run check:fast: passed.
  • npm run format:check: passed.
  • npm run docs:check: passed.
  • npm run metadata:check: passed.
  • Manual run of the built CLI: see the output above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: no browser by design; macOS arm64.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the dry run checks only whether secret variables are present. Values are never copied into the plan, and tests assert they never reach stdout.

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

…hing

Checking a scenario file meant running it, which discovers, launches or
attaches to a browser and can change page state before a typo surfaces.

`rea capture-browser-scenario <json> --dry-run` reuses the same JSON and
path resolution, the canonical scenario schema and its semantic rules, and
the secret-availability rule capture applies before acquiring a browser,
now shared from one domain owner. It returns the same projected input
errors, or a compact plan of steps, secret availability and the stages it
did not check, and never creates a provider or reads secret values.

Fixes #5488

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added enhancement New feature or request track:feature Feature/enhancement automation track labels Oct 25, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-25T09:58:53.905263Z c3b79ce PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The reviewed changes appear safe to merge; no blocking issues were found.

Summary

Adds --dry-run to validate browser scenarios and report a compact plan before creating a browser provider.

  • Browser scenarios can be checked without creating a browser provider.

Reviews (2) · Last reviewed commit: "docs(browser): fence the dry-run plan ex..." · Reviewed by Greptile

Every JSON block in the scenario contract guide is admitted as a scenario
by the product catalog test; the plan is output, not input.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator Author

Closing as superseded: #7343 resolved #5488 with rea validate-browser-scenario, which covers the same validation-only workflow.

@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation enhancement New feature or request track:feature Feature/enhancement automation track

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add a validation-only command for browser scenario files

2 participants