Skip to content

test: pin bootstrap-scoped root launch defaults under ambient args - #451

Open
draarivpatel-ui wants to merge 2 commits into
fitchmultz:mainfrom
draarivpatel-ui:test/332-root-launch-env-contract
Open

draarivpatel-ui wants to merge 2 commits into
fitchmultz:mainfrom
draarivpatel-ui:test/332-root-launch-env-contract

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

For #332.

What this covers

The reported relaunch came from upstream's pre-0.43 launch envelope hash: AGENT_BROWSER_ARGS forced a launch envelope on every call, and the wrapper sent AGENT_BROWSER_PROFILE / AGENT_BROWSER_EXECUTABLE_PATH only at bootstrap, so the first follow-up hashed differently and the daemon relaunched.

Since 0.43, upstream applies a settings patch instead: a key the patch does not name never produces a change, and the reported launchHash is informational. On the current floor (0.44.0) the wrapper's bootstrap-scoped forwarding is exactly the contract that keeps a follow-up's patch from differing from the running launch.

This adds a regression test for that configuration: configured browser.defaultProfile and browser.executablePath plus ambient AGENT_BROWSER_ARGS. It asserts the bootstrapping call carries the configured profile and executable, every invocation (including daemon inspection and helpers) sees the same ambient args, and follow-up calls on the active daemon resend no wrapper launch environment.

Verified locally against agent-browser 0.44.0 with Chrome: a follow-up get url with AGENT_BROWSER_ARGS still set reused the running browser with the same launchHash (reused: true, relaunchedBrowser: false).

Verification

  • node --import tsx --test test/agent-browser.shared-defaults.test.ts: 53 pass, 6 skip (real-upstream gated)
  • npm run verify -- typecheck: pass
  • npm run lint: pass
  • npx oxfmt --check: pass

Not verified: real-upstream runs (PI_AGENT_BROWSER_REAL_UPSTREAM=1) and the Pi/tmux checkout smoke; this is a test-only change asserting the existing contract.

For fitchmultz#332. With browser.defaultProfile, browser.executablePath and
AGENT_BROWSER_ARGS configured, the first root call must carry the
configured profile and executable while later calls on the active
daemon resend nothing: upstream 0.43+ preserves launch settings a
patch does not name, so resending identical defaults is unnecessary
and sending different ones would relaunch the browser. Ambient
AGENT_BROWSER_ARGS must reach every invocation, including daemon
inspection and helper calls, unchanged.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

root,
`
const args = process.argv.slice(2);
require("node:fs").appendFileSync(${JSON.stringify(log)}, JSON.stringify({ args, profile: process.env.AGENT_BROWSER_PROFILE ?? null, executablePath: process.env.AGENT_BROWSER_EXECUTABLE_PATH ?? null, launchArgs: process.env.AGENT_BROWSER_ARGS ?? null }) + "\\n");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fake binary only records which env vars the wrapper forwards. #332 was the browser silently relaunching on the second call (wrong page, profile lost), and that happens inside real agent-browser, so this test would still pass if upstream brought the relaunch back. Could this use the same file's PI_AGENT_BROWSER_REAL_UPSTREAM-gated real-browser pattern (like the "real root group retains explicit profile…" test below) instead?

const followup = await executeRegisteredTool(harness.tool, harness.ctx, {
args: ["get", "title"],
});
assert.equal(followup.isError, false, getMessageText(followup.content));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the follow-up, please assert what #332 actually broke: relaunchedBrowser: false, the same URL as the open, and a ref from the first snapshot still working. Run it once with AGENT_BROWSER_ARGS and once with native config args. The 0.44.0 check on #332 only covered AGENT_BROWSER_ARGS + get url; the original repro also failed with config args and on a ref-based follow-up. If the real-browser version passes on 0.44.0, we can close #332 with that result and drop this env-forwarding-only test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7844dfd. The fake-binary test is removed and the real upstream regression now runs once with AGENT_BROWSER_ARGS and once with native config args. Against agent-browser 0.44.0 both cases pass while asserting relaunchedBrowser is false, the follow-up URL is unchanged, and the first snapshot ref still works.

[...firstCalls, ...laterCalls].every(
(call) => readRecord(call).launchArgs === "--caller-launch-arg",
),
"every invocation sees the same ambient launch args",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] test: ambient-env assertion cannot observe the claimed daemon-inspection call

Trigger: The new regression test asserts [...firstCalls, ...laterCalls].every(call => call.launchArgs === "--caller-launch-arg") with the message "every invocation sees the same ambient launch args", while the PR description and commit message claim coverage of every invocation, "including daemon inspection and helper calls". The wrapper's daemon inspection is a session info invocation (inspectManagedSessionDaemon, managed-session-daemon-inspection.ts:191-200). writeFakeAgentBrowserBinary prepends a session info branch that returns the fake daemon reply and calls process.exit(0) before the test-supplied body can append to calls.jsonl (test/helpers/agent-browser-harness.ts:1102-1106); the new test does not set PI_AGENT_BROWSER_TEST_CUSTOM_SESSION_INFO. The test also never asserts that an incidental live-page helper call actually occurred.

Impact: The assertion only covers the open and get title browser calls (plus any helper that happens to run), so a regression that drops or rewrites AGENT_BROWSER_ARGS for session info — the inspection the PR specifically claims to pin — would still pass. The PR's stated regression coverage for the #332 ambient-args contract is therefore overstated and gives false confidence.

Evidence: Added lines test/agent-browser.shared-defaults.test.ts:1486-1490. writeFakeAgentBrowserBinary builds wrappedScriptBody = defaultSessionInfo + scriptBody; the default session info branch exits at helper lines 1102-1106 before the log line in the test body (line 1440). The wrapper invokes session info before every withRootBrowserLaunch browserRun (native-root-launch.ts:107-115), so those invocations are absent from firstCalls/laterCalls. Correction: set PI_AGENT_BROWSER_TEST_CUSTOM_SESSION_INFO=1 and have the fake log the session info env while returning a matching active runtime, then assert that record's launchArgs; alternatively narrow the assertion message and PR description to the logged browser calls and add an explicit assertion for a helper invocation if helpers are claimed.

AGENT_BROWSER_ARGS: scenario.envArgs,
AGENT_BROWSER_CONFIG: undefined,
AGENT_BROWSER_NAMESPACE: undefined,
AGENT_BROWSER_PROFILE: undefined,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving this onto the real browser. The fake-binary test is gone, both AGENT_BROWSER_ARGS and config args are covered, and the no-relaunch, same-URL and old-ref checks are what #332 needs.

One gap remains: #332 only happened with a package config that set browser.defaultProfile (policy "always") plus browser.executablePath. This scenario sets neither and clears AGENT_BROWSER_PROFILE here, so the test would still pass if the bug came back.

Fix: point PI_AGENT_BROWSER_CONFIG at a config with defaultProfile: { name: "Default", policy: "always" } and a real executablePath. Seed a throwaway profile with a localStorage value, then assert it survives the follow-up call. Please also update the PR body, which still describes the removed fake-binary test.

@fitchmultz

Copy link
Copy Markdown
Owner

The agent-browser 0.45.0 upgrade just landed in #453–#457. Since this PR adds a real-upstream launch test, please use 0.45.0 when you update the branch and verify it. The command-reference check now expects that version.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants