Skip to content

chore(dev): add real browser extension smoke (#2248) - #2280

Merged
Sinity merged 1 commit into
masterfrom
feature/chore/dev-loop-browser-e2e-2248
Jun 21, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/chore/dev-loop-browser-e2e-2248

Conversation

@Sinity

@Sinity Sinity commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Add a repo-owned real-browser dev-loop smoke for #2248. The new devtools workspace dev-loop --browser-smoke launches Chrome with the unpacked browser-extension/, discovers the Polylogue MV3 service worker over CDP, and exercises a temporary branch-local receiver from the extension-origin context. It writes browser smoke summaries, stdout/stderr, env, profile, spool, and dev-loop event rows under the run-local artifact directory.

Problem

The branch-local dev loop had preflight, daemon launch, CLI capture, browser-plan handoff, receiver smoke, and mocked extension-background smoke, but it still did not prove that a real Chrome instance could load the unpacked extension and reach the branch-local receiver. During the real-browser probe, receiver CORS preflight also rejected the extension's X-Request-ID header, which made request-id correlation fail in actual browser fetches despite passing non-browser mocks.

Solution

  • Added browser-extension/scripts/dev-loop-browser-smoke.mjs, a no-dependency Node/CDP script that launches Chrome headless with --load-extension, identifies the Polylogue service worker, and sends unauthenticated/authenticated receiver status/capture requests from the extension context.
  • Wired --browser-smoke into devtools workspace dev-loop, including run-local artifacts, event rows, human/JSON output, and --inspect-run summaries.
  • Updated docs/dev-loop.md to distinguish --extension-smoke, --browser-smoke, and --browser-plan.
  • Fixed browser-capture receiver CORS preflight to allow X-Request-ID, with focused receiver coverage.

Verification

  • node --check browser-extension/scripts/dev-loop-browser-smoke.mjs
  • devtools workspace dev-loop --isolated-ports --prepare --browser-smoke --json
    • run id: feature-chore-dev-loop-browser-e2e-2248-c6f0820c2-api45189-capture52773
    • result: ok=True
    • extension id: fignfifoniblkonapihmkfakmlgkbkcf
    • artifact: chatgpt/dev-loop-browser-smoke-097ac33d4373.json
  • devtools test tests/unit/devtools/test_dev_loop.py tests/unit/browser_capture/test_receiver.py -q
    • 33 passed
  • devtools verify --quick
    • exit code 0, run id 20260621T132155Z-quick-3804056-eace7b81

Ref #2248

Summary by CodeRabbit

Release Notes

  • New Features

    • Added browser smoke testing capability to verify the extension works in headless Chrome with the local receiver.
  • Bug Fixes

    • Added missing CORS header support for request tracing headers.
  • Documentation

    • Updated development workflow documentation with browser testing instructions.
  • Tests

    • Added automated test coverage for browser extension integration.

Problem: #2248 still lacked a repo-owned proof that a real Chrome instance could load the unpacked browser extension and reach a branch-local receiver. The existing extension smoke covered the background worker through a Chrome API mock, while browser-plan only produced an operator handoff.

What changed: add a no-dependency Node CDP smoke that launches Chrome with browser-extension loaded, discovers the Polylogue service worker, and posts unauthenticated/authenticated receiver requests from the extension-origin context. Wire it into devtools workspace dev-loop --browser-smoke with run-local artifacts/events, inspect-run summaries, docs, and focused tests. The real smoke exposed that receiver CORS preflight did not allow X-Request-ID, so the receiver now advertises that header.

Verification: node --check browser-extension/scripts/dev-loop-browser-smoke.mjs; devtools workspace dev-loop --isolated-ports --prepare --browser-smoke --json; devtools test tests/unit/devtools/test_dev_loop.py tests/unit/browser_capture/test_receiver.py -q; devtools verify --quick.

Ref #2248
@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds a --browser-smoke dev-loop mode that launches headless Chrome with the unpacked MV3 extension, discovers its service worker via Chrome DevTools Protocol, and probes a temporary local receiver with unauthenticated and authenticated requests. A new Node.js script handles the CDP interaction; a new Python function orchestrates it and emits dev-loop events. The receiver CORS handler gains X-Request-ID support.

Changes

Browser Smoke Test Pipeline

Layer / File(s) Summary
CORS preflight: add X-Request-ID header
polylogue/browser_capture/server.py, tests/unit/browser_capture/test_receiver.py
Access-Control-Allow-Headers in the OPTIONS handler is expanded to include X-Request-ID. The preflight unit test now requests and asserts that header.
Node.js CDP smoke script and npm wiring
browser-extension/package.json, browser-extension/scripts/dev-loop-browser-smoke.mjs
New dev-loop-browser-smoke.mjs spawns headless Chrome with a temporary profile and remote-debugging port, polls /json/list via waitJson until the MV3 service worker target appears, opens a WebSocket CDP connection via connectCdp, evaluates three receiver fetch probes (evaluateJson) from the service-worker context using a fixtureEnvelope payload, writes a JSON result summary, and exits non-zero on failure. Registered as dev-loop-browser-smoke in package.json.
Python dev_loop: orchestration, CLI, printer
devtools/dev_loop.py
run_browser_smoke() prepares artifact directories, starts a temporary in-process receiver with a fixed smoke auth token, sets env vars, runs npm run dev-loop-browser-smoke with a 35 s timeout, records stdout/stderr/result JSON, and emits browser_smoke_requested/finished events. summarize_dev_loop_run() is extended to load browser/browser-smoke.json. _print_browser_smoke() formats human-readable output. A --browser-smoke CLI flag, preflight condition, combined execution call, and combined output printer are all wired in.
Unit test and documentation
tests/unit/devtools/test_dev_loop.py, docs/dev-loop.md
New test monkeypatches subprocess.run to write fake smoke output JSON and spool artifact, runs dev_loop.main --browser-smoke, and asserts payload fields, artifact paths, and final preflight event rows. Documentation adds a browser-smoke workflow section with commands, artifact descriptions, and coverage scope notes.

Sequence Diagram(s)

sequenceDiagram
  actor Dev as Developer
  participant devloop as dev_loop.py run_browser_smoke()
  participant npm as npm run dev-loop-browser-smoke
  participant Chrome as Headless Chrome + MV3 Extension
  participant SW as Extension Service Worker (CDP)
  participant Receiver as Temporary Local Receiver

  Dev->>devloop: dev_loop.main --browser-smoke
  devloop->>Receiver: start in-process receiver (smoke auth token)
  devloop->>npm: subprocess.run with POLYLOGUE_BROWSER_SMOKE_OUT env
  npm->>Chrome: spawn --headless --load-extension --remote-debugging-port
  npm->>Chrome: waitJson /json/list → find SW target
  npm->>SW: connectCdp WebSocket → Runtime.enable
  npm->>SW: evaluateJson(unauthenticated POST /capture)
  SW->>Receiver: POST /capture (no auth)
  Receiver-->>SW: 401 Unauthorized
  npm->>SW: evaluateJson(authorized GET /status)
  SW->>Receiver: GET /status (Bearer token)
  Receiver-->>SW: 200 OK
  npm->>SW: evaluateJson(authorized POST /capture)
  SW->>Receiver: POST /capture (Bearer token + envelope)
  Receiver-->>SW: 200 OK + artifact_ref
  npm->>npm: write summary JSON to POLYLOGUE_BROWSER_SMOKE_OUT
  npm-->>devloop: exit 0 / exit 1
  devloop->>devloop: emit browser_smoke_finished event, write browser-smoke.json
  devloop-->>Dev: _print_browser_smoke() output + artifact paths
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐇 Ears perked, I launch Chrome in the dark,
A service worker glows—what a spark!
CDP whispers, fetch probes fly,
Unauthenticated? A polite deny.
Auth token passed, the artifact blooms,
The smoke clears out of headless rooms! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main change: adding a real browser extension smoke test to the dev-loop tooling, which is the central feature of this PR.
Description check ✅ Passed The PR description comprehensively covers all required template sections: Summary, Problem, Solution, Verification, and includes references to issue #2248.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/chore/dev-loop-browser-e2e-2248

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

github-actions Bot pushed a commit that referenced this pull request Jun 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 838dff9974

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity merged commit 9cab703 into master Jun 21, 2026
15 of 16 checks passed
@Sinity
Sinity deleted the feature/chore/dev-loop-browser-e2e-2248 branch June 21, 2026 13:27
Sinity added a commit that referenced this pull request Jun 21, 2026
## Summary

Completes the branch-local dev-loop close-out by making `devtools
workspace dev-loop --inspect-run` useful as the first diagnostic stop
after daemon, web, CLI, receiver, extension, or browser-loop failures.
The helper now surfaces failed summary files, failed terminal captures,
slowest timed events, and artifact paths grouped by surface, so a
developer can move directly from one run id to the log/stdout/stderr
artifact that explains the failure.

## Problem

#2248 had already landed branch-local preflight, isolated ports, daemon
launch artifacts, `/api/dev-loop`, CLI capture, receiver request ids,
extension diagnostics, browser plans, and real Chrome unpacked-extension
smoke. The remaining weakness was the final debugging step: when a run
produced many local artifacts, `--inspect-run` mostly reported counts
and raw failed events, so agents still had to scan the run directory to
find the useful next file.

## Solution

This PR extends the existing run inspector rather than adding a second
observability ledger:

- reads duration and artifact metadata from existing
`dev-loop.events.jsonl`, daemon/browser/extension/TUI summary JSON, and
terminal capture summaries;
- reports `failed_summaries`, `failed_terminal_captures`,
`slowest_events`, and `artifact_index` in JSON output;
- shows the slowest event and available artifact groups in human output;
- updates the dev-loop documentation to describe the postmortem
workflow;
- expands the focused dev-loop test to cover the new failure-postmortem
behavior.

## Acceptance Matrix

| Requirement | Evidence |
| --- | --- |
| Branch-local daemon/web/browser-capture runs are isolated from the
deployed service | Landed in prior #2248 PRs: preflight, isolated ports,
dev archive root, daemon launcher, `/api/dev-loop`; confirmed in issue
comments with local smoke run ids. |
| CLI/TUI capture artifacts are tied to the same run id | Existing
`--capture-cli` and `--tui-plan` write run-local artifacts; this PR
indexes terminal capture summaries in `--inspect-run`. |
| Browser-extension loop is exercised from the branch | #2280 added real
Chrome unpacked-extension smoke and fixed the CORS request-id preflight
gap; issue comment records `ok=True` local evidence. |
| Failed or slow dev-loop runs are diagnosable from local artifacts |
This PR adds failed summaries, failed terminal captures, slowest timed
events, and per-surface artifact index to `--inspect-run`. |
| No new ops-tier table unless logs are insufficient | No table added.
Existing structured launcher JSONL, summary files, `/api/dev-loop`, and
daemon events answer the current debugging questions. |
| Browser-control boundary stays local/operator-owned |
`docs/dev-loop.md` continues to treat real authenticated browser/profile
work as local operator/agent procedure; repo owns URLs/config/artifacts
and smokes only. |

## Verification

- `devtools test tests/unit/devtools/test_dev_loop.py -q` → `19 passed
in 41.44s` after formatting.
- `devtools render all --check` → all generated surfaces sync OK.
- `devtools verify --quick` → all checks passed in 13.1s locally.
- Pre-push `devtools verify --quick` → all checks passed in 11.83s, run
id `20260621T143839Z-quick-67399-bf5fa775`.

## Notes

I did not run a fresh real-browser smoke in this PR because #2280
already added and verified that path. This change is the postmortem
layer over the run artifacts produced by those existing commands.

Closes #2248
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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