Skip to content

test(browser-extension): add MV3 behavior harness and package gate #649

Closed

Description

@Sinity

Problem

#622 needs concrete browser-extension behavior tests. The Python receiver has normal pytest coverage, but the JavaScript/MV3 extension still lacks a behavior harness and package smoke gate.

This should be owned separately from receiver hardening: the missing contract is browser-extension behavior before data reaches the Python receiver.

Current state

browser-extension/
  manifest.json
  README.md
  src/

Receiver side:

polylogue/browser_capture/
  models.py
  receiver.py
  server.py

The extension and receiver are loosely coupled through an HTTP envelope POST. The harness should test the JS/MV3 side in isolation where possible, and reserve Python receiver integration for envelope compatibility checks.

Scope

Add a browser-extension test/package gate for the behavior contract in #622.

Likely implementation shape:

  • Add a browser-extension/package.json with focused test, lint, and package/build scripts if none exists.
  • Use a CI-friendly JS test harness for content-script/background/popup behavior without requiring a full interactive browser unless a browser runner proves necessary.
  • Add a packaging smoke that verifies the shipped zip/artifact contains the expected manifest, content scripts, background/popup files, and no checkout-only assumptions.
  • Wire the gate into the verification surface for browser-extension changes, either via a focused devtools command, CI job, or documented package-local command that Proof Pack can point to.

Required behavior coverage

  • Default mode performs no POST from content scripts before explicit manual capture.
  • Auto-capture mode is persisted opt-in and visible in popup/badge state.
  • Ambiguous role extraction yields unknown or skips with diagnostics; no index-parity user/assistant fallback.
  • Envelope shape stays compatible with polylogue/browser_capture/models.py without requiring receiver internals in every JS test.
  • The harness can exercise both ChatGPT and Claude content-script paths, or documents a phased split with linked follow-up.

Non-goals

  • Do not use this issue to redesign browser capture storage semantics.
  • Do not make the JS harness depend on a live ChatGPT/Claude page unless no deterministic fixture approach works.
  • Do not duplicate all Python receiver tests in JavaScript.
  • Do not route this through the broader verification-lab abstraction unless it adds real value over a standard package-local JS gate.

Acceptance criteria

  • MV3 behavior harness verifies the required coverage above.
  • Build/lint/package smoke runs in the normal verification surface chosen for browser-extension changes.
  • Package gate proves the shipped artifact contains the expected manifest/content scripts and no checkout-only assumptions.
  • The PR body records the exact JS/package command and any devtools/CI command that exercises it.
  • If full ChatGPT + Claude path coverage is split, the remaining provider path has a linked follow-up issue with concrete missing fixtures.

Refs #622, #593, #852, #853.

Activity

  1. added
    area:core
    on May 1, 2026
  2. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Current browser extension state

    browser-extension/
      manifest.json      # MV3 manifest
      README.md
      src/               # content scripts, background, popup
    

    Four Python modules on the receiver side:

    polylogue/browser_capture/
      __init__.py        # (33 lines) re-exports
      models.py          # (168 lines) envelope, turn, attachment, provenance models
      receiver.py        # (145 lines) file-system write + artifact path
      server.py          # (149 lines) HTTP server
    

    Implementation notes

    The Python receiver and JS extension are loosely coupled — the receiver is an HTTP server that accepts envelope POSTs. This issue's harness needs to test the JS side in isolation from the Python side.

    Key boundary: the harness should be self-contained JS/MV3 tests. The server.py / receiver.py Python side is already covered by existing pytest infrastructure. The gap this issue fills is the JS behavior contract:

    • Default mode: content scripts do NOT fire POSTs without explicit capture action
    • Auto-capture mode: persisted opt-in, visible badge state
    • Role extraction: unknown skip with diagnostics, not user/assistant fallback

    For build/lint/package smoke, the simplest CI-friendly approach: add a package.json with build and lint scripts to browser-extension/, wire them into a devtools command or CI step, and verify the produced zip contains the expected manifest + content script files.

  3. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Execution supplement

    Mass-execution wave: #852 Wave 0 or Wave 5, mostly independent.

    Focused verification:

    • package-local JS/MV3 test/lint/package commands for content scripts, background, popup, and manifest artifact contents;
    • deterministic fixtures for ChatGPT and Claude DOM/message extraction where possible;
    • envelope compatibility tests against polylogue/browser_capture/models.py only where the JS/Python boundary changes;
    • do not require a live ChatGPT/Claude page unless deterministic fixtures cannot prove the behavior;
    • devtools verify --quick, then full devtools verify before PR if repo-level tooling or Python receiver code changes.

    This should use standard JS/package gates unless a custom devtools hook clearly adds value.

  4. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Reconnaissance Report for #649

    Current codebase evidence

    Browser extension JS files (browser-extension/src/):

    File Lines Role
    common.js 82 Shared envelope builder (buildEnvelope), FNV-1a hashing, sendCapture, refreshArchiveState
    background.js 74 Service worker: message routing, HTTP to local receiver, badge state management
    popup.js 87 Popup UI: receiver config, status check, manual capture trigger
    popup.html 161 Popup layout with CSS, status/controls sections
    content/chatgpt.js 62 ChatGPT DOM scraper: turn collection, auto-capture via MutationObserver
    content/claude.js 57 Claude.ai DOM scraper: turn collection, auto-capture via MutationObserver

    No package.json exists -- confirmed zero match.

    No JS tests exist -- no test infrastructure of any kind.

    Python receiver (polylogue/browser_capture/):

    File Lines Role
    models.py 168 Pydantic models: BrowserCaptureEnvelope, BrowserCaptureTurn, BrowserCaptureSession, etc.
    receiver.py 145 File-system write helpers, artifact path, existing_capture_state
    server.py 149 HTTP server (stdlib ThreadingHTTPServer), origin auth, CORS
    __init__.py 33 Re-exports

    Existing tests:

    • tests/unit/sources/test_browser_capture.py -- Python-side tests (provider detection, parsing, deduplication)
    • No JS-side tests exist

    Critical behavioral gap -- #622 changed the contract but JS not updated for test harness requirements:

    Per #622 (latest revision 2026-05-01): Auto-capture is the default for supported pages. This supersedes the earlier "manual by default" language in this issue's body. The content scripts already implement auto-capture:

    • chatgpt.js line 45-48: scheduleCapture() called on load, MutationObserver watches for changes
    • claude.js line 40-43: same pattern

    Role extraction with index-parity fallback (known bug to fix per #622):

    • chatgpt.js line 11: return index % 2 === 0 ? "user" : "assistant" -- fallback when no DOM attribute found
    • claude.js line 8: return index % 2 === 0 ? "user" : "assistant" -- same issue
    • Per fix(browser-capture): harden capture mode, receiver, and adapters #622: "Ambiguous DOM nodes are skipped or marked unknown with diagnostics; no user/assistant role assignment by index parity." This is currently violated.

    Envelope compatibility:

    • JS buildEnvelope() in common.js (lines 25-57) builds the same shape as BrowserCaptureEnvelope in models.py
    • Fields match: polylogue_capture_kind, schema_version, capture_id, source, provenance (with all sub-fields), session (with provider, provider_session_id, title, updated_at, model, turns)
    • turns include provider_turn_id, role, text, ordinal, provider_meta

    Build this (concrete behavior)

    1. Add browser-extension/package.json:

      {
        "name": "polylogue-browser-capture",
        "version": "0.1.0",
        "private": true,
        "scripts": {
          "test": "...",
          "lint": "...",
          "build": "..."
        }
      }
      • build script: produce a zip artifact containing manifest.json, all src/ files, README
      • lint script: ESLint or similar JS linter for all .js and .html files
      • test script: JS test runner (vitest/jest with jsdom for DOM fixture testing)
    2. Test harness files (browser-extension/tests/ or browser-extension/src/__tests__/):

      • common.test.js -- buildEnvelope shape, fnv1a determinism, conversationIdFromUrl
      • chatgpt.test.js -- collectTurns with deterministic DOM fixtures, roleFromNode for known/unknown nodes
      • claude.test.js -- same for Claude DOM fixtures
      • envelope.test.js -- envelope compatibility against Python models.py contract (field names, types, required fields)
      • package.test.js or shell script -- verify zip contents (manifest.json present, src/ files present, no checkout-only files)
    3. Behavior coverage (updated for fix(browser-capture): harden capture mode, receiver, and adapters #622 final state):

      • Auto-capture mode is default = content scripts DO fire POSTs on load for supported pages
      • Badge shows capture state (green="captured", purple="online", red="offline")
      • Auto-capture can be disabled; persisted to chrome.storage.local
      • The @sitivityai suppression is no longer needed -- auto-capture ON by default
      • Role extraction returns "unknown" with diagnostics when DOM attributes are ambiguous (NOT index-parity user/assistant)
      • Envelope shape matches BrowserCaptureEnvelope model (all required fields present)
    4. Non-browser test strategy:

      • Use jsdom for DOM fixture tests (no live browser needed)
      • Mock chrome.runtime.sendMessage, chrome.storage.local, chrome.tabs.query via Jest/Vitest mocks
      • Deterministic HTML fixtures for ChatGPT and Claude DOM patterns
    5. Package gate:

      • npm run build produces dist/polylogue-browser-capture.zip
      • Gate verifies: manifest.json, src/background.js, src/common.js, src/popup.js, src/popup.html, src/content/chatgpt.js, src/content/claude.js are present
      • NO .git, node_modules, tests/, or checkout-only files in zip
    6. CI/Verification surface:

      • Wire into devtools or document exact command: cd browser-extension && npm ci && npm run lint && npm test && npm run build
      • Add to devtools verify --quick or document as separate gate

    Do NOT build this

    • Do NOT build a full browser automation harness (no Playwright/Puppeteer required unless deterministic fixtures fail)
    • Do NOT duplicate Python receiver tests in JS
    • Do NOT make the JS harness depend on a live ChatGPT/Claude page
    • Do NOT redesign browser capture storage semantics
    • Do NOT change the Python receiver code (server.py, receiver.py, models.py) unless envelope compatibility tests reveal a gap
    • Do NOT implement the fix(browser-capture): harden capture mode, receiver, and adapters #622 role-fix here unless it is a one-line "unknown" return change. The fix(browser-capture): harden capture mode, receiver, and adapters #622 fix should be its own PR; this issue tests the contract.
    • Do NOT create a complex custom devtools hook for JS testing -- standard npm scripts are fine
    • Do NOT require the Python receiver to be running for JS tests

    Files to touch

    File Change
    browser-extension/package.json NEW: npm package with test/lint/build scripts
    browser-extension/tests/common.test.js NEW: envelope builder and hashing tests
    browser-extension/tests/chatgpt.test.js NEW: ChatGPT DOM extraction with fixtures
    browser-extension/tests/claude.test.js NEW: Claude DOM extraction with fixtures
    browser-extension/tests/envelope.test.js NEW: envelope compatibility contract tests
    browser-extension/tests/package.test.js NEW: zip artifact content verification
    browser-extension/.eslintrc.json (or eslint.config.js) NEW: JS lint configuration
    browser-extension/vitest.config.js (or jest.config.js) NEW: test runner configuration
    browser-extension/README.md Update with test/lint/build commands
    browser-extension/.gitignore NEW: add node_modules/, dist/
    polylogue/browser_capture/models.py Only if envelope compatibility tests reveal a contract gap
    devtools/ (some file) Optional: wire npm gate into devtools verify

    Coordination

    Focused tests

    cd browser-extension && npm ci && npm run lint
    cd browser-extension && npm test
    cd browser-extension && npm run build && npm run test:package  # verify zip contents

    Final gates

    Acceptance criteria for #649

    1. npm test passes -- MV3 behavior harness verifies:
    2. npm run lint passes all JS files
    3. npm run build produces zip with expected manifest + content scripts
    4. Envelope shape tests pass against BrowserCaptureEnvelope contract
    5. No live ChatGPT/Claude page required for tests
    6. Package gate proves no checkout-only assumptions in artifact
    7. PR body records exact commands

    Ambiguities / stale comments

    • Comment 1 (2026-05-02): Says "Default mode: content scripts do NOT fire POSTs without explicit capture action." This is STALE per fix(browser-capture): harden capture mode, receiver, and adapters #622's 2026-05-01 revision which made auto-capture the default. The test harness should verify auto-capture behavior, not manual-only.
    • Comment 2 (2026-05-06): Execution supplement is valid -- package-local JS tests, deterministic fixtures, envelope compatibility tests. Still accurate.
    • Ambiguity: Should the role-extraction fix (index-parity -> "unknown") be done in this issue or fix(browser-capture): harden capture mode, receiver, and adapters #622? The issue body mentions it as required coverage ("Ambiguous role extraction yields unknown or skips with diagnostics; no index-parity user/assistant fallback"). Recommendation: make the fix here since the test harness needs to assert it, but keep it minimal (change return to "unknown" in both content scripts).
    • Ambiguity: Test framework choice (vitest vs jest). No existing preference in repo. Vitest recommended (simpler config, ESM-native, works with jsdom).
    • Ambiguity: Should the JS gate be wired into devtools verify or remain package-local? Issue body says "either via a focused devtools command, CI job, or documented package-local command." Recommend: start with package-local, document in README and PR; wire into devtools only if it proves useful.
  5. reopened this on May 7, 2026
  6. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Reopening after closed-issue/codebase reconciliation. This issue is not close enough to complete to fold into #944 as generic cleanup.

    Current evidence on master:

    • browser-extension/package.json:7-11 has test, test:watch, and lint, but no build or package/zip smoke script.
    • There is no browser-extension/package-lock.json; cd browser-extension && npm ci --ignore-scripts fails with npm ci requiring an existing lockfile.
    • cd browser-extension && npm run build fails with Missing script: "build".
    • browser-extension/src/content/chatgpt.js:11 and browser-extension/src/content/claude.js:8 still use index-parity role fallback, which violates the fix(browser-capture): harden capture mode, receiver, and adapters #622/test(browser-extension): add MV3 behavior harness and package gate #649 contract for ambiguous nodes.
    • browser-extension/tests/content/chatgpt.test.js:7-10,90-95,114-122 and browser-extension/tests/content/claude.test.js:7-10,90-94,124-133 document/assert the parity fallback as the current behavior rather than failing on it.
    • The content-script tests copy extracted functions instead of importing the extension source, so the harness can drift from the shipped scripts.
    • Operator text is still stale in extension surfaces: browser-extension/README.md:9 and browser-extension/src/popup.js:42 say polylogue browser-capture serve, while the current docs use polylogued browser-capture serve; browser-extension/manifest.json:5 still says captures go into the local inbox.

    What remains in this issue:

    • Add a reproducible JS install gate (npm ci with committed lockfile or chosen equivalent).
    • Add build/package smoke that proves the shipped MV3 artifact contents and excludes checkout-only files.
    • Make the content-script harness exercise the real extension source or a shared exported implementation, not copied functions.
    • Fix and assert ambiguous role behavior: unknown/skipped with diagnostics, no index-parity user/assistant guesses.
    • Cover popup/background state enough to prove auto-capture visibility/toggle and receiver status behavior.
    • Update extension README/popup/manifest wording to the current daemon-owned browser-capture model.

    Scope note: this should be excluded from #944's generic lint/baseline cleanup. #944 can reference it as a reopened specialized browser-extension gap.

  7. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Closing: core implementation landed. Remaining edges are incremental.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:qatype:test

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions