Skip to content

Tests: never set PLANNOTATOR_BROWSER=none (it opens the system browser); use a real no-op program - #1923

Merged
backnotprop merged 1 commit into
mainfrom
test/no-browser-sentinel
Oct 14, 2026
Merged

backnotprop merged 1 commit into
mainfrom
test/no-browser-sentinel

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

The bug

PLANNOTATOR_BROWSER=none does not stop a browser from opening. packages/server/browser.ts (and Pi's apps/pi-extension/server/network.ts) treats none, true, false, :, 0 and 1 as no-op sentinels (NOOP_BROWSER_VALUES, #756). openBrowser then drops them as if the variable were unset and falls through to the system default (open <url> on macOS, xdg-open on Linux).

About 25 tests and specs set PLANNOTATOR_BROWSER: 'none' and expected no browser. Any of them that reaches openBrowser opens real tabs on the developer's screen. Examples: a foreground plannotator inbox, or a session started without --background. This happened on the owner's Mac today.

I confirmed it with the compiled binary. plannotator inbox (foreground) ran with a PATH that held only trap open/xdg-open scripts, so the real opener could not be reached:

PLANNOTATOR_BROWSER="/usr/bin/true" -> system opener called: (nothing)
PLANNOTATOR_BROWSER="none"          -> system opener called: open http://localhost:55439/

The fix (tests only; no product change)

  • tests/helpers/no-browser.ts exports NO_BROWSER, an absolute path to a program that exits at once:
    • POSIX: /usr/bin/true (present on macOS and on Linux CI images), else /bin/true, else the first true on PATH. On both macOS and Linux, openBrowser runs a value that contains a / directly, never through open -a.
    • Windows: %SystemRoot%\System32\whoami.exe, the no-op test.yml already uses. openBrowser runs it as cmd.exe /c start "" <path> <url>, so no browser opens (a console window may flash).
    • The module is node-safe, because the Playwright specs import it.
    • It never falls back to a sentinel: if it finds no program, it throws.
  • Every sentinel value replaced: tests/helpers/inbox-world.ts (worldEnv), 23 specs in tests/e2e/*.spec.ts, apps/hook/server/annotate-cli.test.ts and apps/hook/server/inbox-connect-cli.test.ts. inbox-search.spec.ts had a literal /usr/bin/true; it now uses the helper too. No playwright config or workflow sets a sentinel on PLANNOTATOR_BROWSER. Two places set BROWSER: true (the $BROWSER sentinel): release.yml's binary smoke tests on CI runners, and scripts/dast/target.ts, which also sets PLANNOTATOR_SKIP_BROWSER_OPEN=1. I left both as they are.
  • The preload (tests/setup/feedback-archive-off.ts, the file every bunfig.toml loads) now sets PLANNOTATOR_BROWSER=NO_BROWSER unconditionally for every bun test. With this, an in-process openBrowser and every child that inherits process.env open nothing. It also overrides a contributor's own value: a VS Code terminal injects open-in-vscode, which would otherwise send every test session into an editor tab. Tests of the launch itself already set and restore their own value inside their bodies. The Playwright specs run under node with no preload, so they set the value in the env they build.
  • The guard, tests/no-browser-sentinel.test.ts (with the scanner in tests/helpers/no-browser-scan.ts):
    • It scans every test and script, .sh / .ps1 / .cmd under tests/ and scripts/, every package.json, and .github/workflows/*.yml. It fails on a sentinel value given to PLANNOTATOR_BROWSER or to the CLI's --browser flag, in any spelling (object key, process.env assignment, shell VAR=, YAML, PowerShell $env:; any case, surrounding spaces).
    • Comments are blanked first. A line that tests the sentinel handling itself, in process, may carry no-browser-guard: sentinel under test. Only packages/server/browser.test.ts does (it calls shouldTryRemoteBrowserFallback and launches nothing).
    • It also checks that NO_BROWSER runs and exits 0, that browser.ts does not read it as a sentinel, and that the preload sets it.
    • Fixtures prove the scan catches each form. Run against origin/main, the scan reports every old 'none'.
  • AGENTS.md (= CLAUDE.md) Testing Rules gets one bullet about this.

Windows

No CI job runs any of the changed files on Windows. The Windows jobs run uninstall.test.ts, cli.test.ts, auto-update.test.ts, a filtered review-workspace.test.ts, the Pi runtime smoke and the install scripts. The Inbox helpers and e2e specs already assume POSIX (#!/bin/sh fakes, :-joined PATHs). The helper still has a Windows answer: whoami.exe. The preload loads it on Windows too, and it resolves there.

Question for the owner: should PLANNOTATOR_BROWSER=none mean "never open"?

This PR does not change browser.ts. The trade-off:

  • fix(browser): treat no-op BROWSER values as unset so headless sessions can fall back #756's intent: headless and agent environments set BROWSER=true (Claude Code's agent view), and if Plannotator shelled out to true <url> the server would hang in waitForDecision() with nothing open. Treating the sentinels as "unset" makes Plannotator open its own window there, which is right for $BROWSER.
  • For PLANNOTATOR_BROWSER, the same rule is surprising. Nobody sets the Plannotator-specific variable to none by accident, and a person who writes PLANNOTATOR_BROWSER=none almost certainly means "do not open anything". Today they get the system browser.
  • Options: (a) leave it as it is; (b) make sentinels in PLANNOTATOR_BROWSER (only) mean "open nothing", and keep fix(browser): treat no-op BROWSER values as unset so headless sessions can fall back #756's fall-through for $BROWSER; (c) (b) plus a stderr line that prints the URL, so a person can still open it by hand. (b) or (c) would make PLANNOTATOR_SKIP_BROWSER_OPEN partly redundant for callers. They would also change remote-mode behaviour, because shouldTryRemoteBrowserFallback also reads the sentinel as "no handler". Which do you want?

Tested

  • bun test tests/no-browser-sentinel.test.ts: 7 pass.
  • bun test tests/ apps/hook/server/annotate-cli.test.ts apps/hook/server/inbox-connect-cli.test.ts packages/server/browser.test.ts: 129 pass, 0 fail.
  • Full bun test with the new preload: 7888 pass, 1 fail. The failure was auto-update.test.ts "group SIGINT" (a 30 s timeout under a load average of about 17). It passes alone (43/43) and is not browser-related.
  • apps/pi-extension/server/network.test.ts flaked 2 times in 12 runs with the preload and 0 in 4 runs without it. Both flakes were the existing race where waitForFile sees the file that printf ... > file created before the write lands. The env value is not involved.
  • tsc for packages/server and apps/hook/tsconfig.server.json: clean.
  • e2e on the compiled binary (.local/plannotator, PLANNOTATOR_INBOX_CONNECT=0, temp dirs): inbox-order, inbox-archived, inbox-tailscale (its PATH holds only fakes, so this checks the absolute path), surface: 21 passed.

browser.ts reads none/true/false/0/1/: as unset (#756) and falls through
to the system default, so every test that set PLANNOTATOR_BROWSER=none
opened real tabs on the developer's screen whenever it reached
openBrowser (a foreground plannotator inbox, a session without
--background).

- tests/helpers/no-browser.ts: NO_BROWSER, an absolute path to a program
  that exits at once (/usr/bin/true, /bin/true, true on PATH; whoami.exe
  on Windows).
- Every 'none' in tests/e2e, tests/helpers/inbox-world.ts and the CLI
  tests now uses it.
- The bun test preload sets PLANNOTATOR_BROWSER=NO_BROWSER for every test.
- tests/no-browser-sentinel.test.ts scans tests, scripts, package.json
  files and the workflows for a sentinel value.

No product change.
@backnotprop
backnotprop merged commit e1ca250 into main Oct 14, 2026
32 checks passed
@backnotprop
backnotprop deleted the test/no-browser-sentinel branch October 14, 2026 21:56
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.

1 participant