Skip to content

Test hygiene: no CDP port in unit-test WebView2s; reset Program statics#8076

Merged
andrew-polk merged 1 commit into
masterfrom
dontExposeCdpPortInUnitTests
Jul 17, 2026
Merged

Test hygiene: no CDP port in unit-test WebView2s; reset Program statics#8076
andrew-polk merged 1 commit into
masterfrom
dontExposeCdpPortInUnitTests

Conversation

@andrew-polk

@andrew-polk andrew-polk commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Two test-hygiene fixes found while investigating CI failures in the upload integration tests. (The actual cause of those CI failures is server-side — POST https://api.bloomlibrary.org/v1/books/new:upload-start?env=unit-test currently returns a bare 500, reproducible with curl — so this PR does not fix them; it fixes two real hazards the investigation surfaced.)

  1. Don't request a CDP port for unit-test WebView2s. WebView2Browser passed --remote-debugging-port=<BloomServer http port + 2> to every WebView2 whenever a BloomServer was listening in the process — including unit tests. Nothing ever attaches to a test-run WebView2, and on a CI machine that also runs real Bloom instances the port can already be taken, which breaks WebView2 startup and fails whatever test needed the browser. Now skipped when Program.RunningUnitTests.

  2. ProgramTests no longer leaks StartupAutomation=true. Its ParseStartupPortArguments("--automation", …) tests left the Program statics set for every later fixture in the run, which made BloomServer print BLOOM_AUTOMATION_READY banners in unrelated tests' output (and would defeat fix Modify .gitignore file #1's gate-adjacent reasoning about automation state). A TearDown now re-parses empty args, which resets all the startup statics.

🤖 Generated with Claude Code

Devin review


This change is Reviewable

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Two targeted test-hygiene fixes that prevent CI flakiness without changing any production behavior. Both are straightforward and well-explained in code comments.

  • WebView2Browser.cs: Gates the CDP remote-debugging-port argument behind !Program.RunningUnitTests so test-run WebView2 instances never compete for a port that a real Bloom instance on the same CI machine may already hold.
  • ProgramTests.cs / ShellTests.cs: Adds a [TearDown] to each fixture that re-parses empty args, resetting all Program startup statics between tests and preventing StartupAutomation=true from leaking into unrelated fixtures later in the run.

Important Files Changed

Filename Overview
src/BloomExe/WebView2Browser.cs Adds !Program.RunningUnitTests guard so CDP debugging port is never requested when running in a test process, preventing port-collision failures on CI machines.
src/BloomTests/ProgramTests.cs Adds a [TearDown] that re-parses empty args to reset all Program statics after each test, preventing StartupAutomation=true from leaking into later fixtures.
src/BloomTests/ShellTests.cs Adds the same [TearDown] reset pattern as ProgramTests, guarding against static state leak from its own --automation call.

Reviews (3): Last reviewed commit: "Test hygiene: no CDP port in unit-test W..." | Re-trigger Greptile

@andrew-polk

Copy link
Copy Markdown
Contributor Author

[Claude/Fable] Consulted Devin on 2026-07-17 up to commit 47cd1f2 — review clean (0 bugs, 0 flags).

Two issues found while investigating CI failures in the upload
integration tests (whose actual cause is server-side: the bloomlibrary
API's upload-start endpoint intermittently returns a bare 500 for
env=unit-test — reproducible with curl, nothing to do with client
code):

- WebView2Browser passed --remote-debugging-port (BloomServer http
  port + 2) to every WebView2 whenever a BloomServer was listening in
  the process, including in unit tests. Nothing attaches to a test-run
  WebView2, and on a CI machine that also runs real Bloom instances
  the port can already be taken, which breaks WebView2 startup and
  fails whatever test needed the browser. Now skipped when running
  unit tests.

- ProgramTests and ShellTests called
  Program.ParseStartupPortArguments("--automation") and left
  StartupAutomation=true in the Program statics for every later
  fixture in the run, making BloomServer print BLOOM_AUTOMATION_READY
  banners in unrelated tests' output. Both fixtures now re-parse empty
  args in a TearDown, which resets all the startup statics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@andrew-polk

Copy link
Copy Markdown
Contributor Author

[Claude/Fable] Squashed the branch to one commit (3a4f158). The tree is byte-identical to 47cd1f2, which Devin reviewed clean (0 bugs, 0 flags) and Greptile passed — git diff 47cd1f293a 3a4f1586a5 is empty.

@andrew-polk
andrew-polk force-pushed the dontExposeCdpPortInUnitTests branch from 47cd1f2 to 3a4f158 Compare July 17, 2026 17:12
@andrew-polk
andrew-polk marked this pull request as ready for review July 17, 2026 17:15
@andrew-polk
andrew-polk merged commit 4ab6872 into master Jul 17, 2026
3 checks passed
@andrew-polk
andrew-polk deleted the dontExposeCdpPortInUnitTests branch July 17, 2026 17:18
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.

2 participants