wip(01-11): wave-3 partial — A1+A4 attempted, popup-bridge SW state query unreliable
Task 4 of Plan 01-11 attempted A1-A4 wiring. Empirical run reveals an
architectural blocker that needs orchestrator-level decision.
Current state after this commit (SKIP_PROD_REBUILD=1 npx tsx tests/uat/harness.test.ts):
- A0 [PASS]: production bundle hook-leak grep gate (17ms)
- A1 [FAIL]: SW bootstrap → setIdleMode — popup state never transitions
to '' despite keepalive ping + 3s waitFor. chrome.action.getPopup({})
from the popup page consistently returns the manifest default
(chrome-extension://<id>/src/popup/index.html), not the '' that
setIdleMode's chrome.action.setPopup({popup:''}) should produce.
- A2 [FAIL]: toolbar onClicked — badge never transitions to "REC" after
page.triggerExtensionAction(extension); 8s timeout. Either the
toolbar action isn't reaching the SW listener, OR getDisplayMedia's
picker isn't resolving in headless mode (despite the auto-select flag).
- A3 [FAIL]: offscreen target never appears (correlates with A2 — no
recording started, no offscreen document spawned).
- A4 [PASS]: trivially passes (offscreen count is 0 → 0, both before
+ after the click). Not a true assertion of behavior; would also pass
if the whole extension were broken.
- A5-A13: stubbed RED per plan.
Architectural blocker (Rule 4 — needs orchestrator decision):
- Puppeteer 25.0.2 + Chrome 148 + headless cannot reliably keep the MV3
SW alive long enough OR expose its real chrome.* state to a popup
page query. The popup-bridge architecture (Task 3 commit dbd977c)
works for synchronous bridge queries (snapshot, fire-on-startup)
but does NOT reliably reflect chrome.action.setPopup / setBadgeText
state changes initiated by the SW.
Three plausible paths forward (need orchestrator pick):
Option A — Content-script bridge: inject a content script that
bridges chrome.* queries to a webpage's window.* RPC surface;
harness uses page.evaluate against the content script instead of
popup.evaluate. Pros: content scripts have stable lifetime tied to
the page they're injected into. Cons: content scripts have
DIFFERENT chrome.* surface (no chrome.action API surface — they
can't read getBadgeText / getPopup at all). Likely DOESN'T solve
the underlying problem.
Option B — Headful with Xvfb on CI: relax the headless requirement;
accept Xvfb dependency. Per Plan 01-11 RESEARCH §3, RESEARCH
claimed headless works on Chrome 148 — empirical refutation here.
Pros: SW lifetime is more stable in headful mode; setPopup
propagation is reliable. Cons: introduces Xvfb dep that RESEARCH
explicitly said wasn't needed; CI complication.
Option C — Shrink harness scope to bridge-able assertions: A0 (grep
gate), A8 (Bug A onStartup via bridge), A9 (icon sizes via popup
fetch), A10 (manifest via popup), A13 (zip shape — operator runs
SAVE_ARCHIVE manually + drops zip to a known path; harness reads
it). Skip A1-A7, A11, A12 (the ones that require live SW state
observation through chrome.action API). Pros: ships the
bug-A-coverage portion of the harness today; keeps Plan 01-09's
Task 5 operator-checkpoint partly automated. Cons: doesn't retire
operator entirely; Plan 01-09 stays open on operator-empirical
A1-A7.
Option D — Switch to WebDriver BiDi (the Puppeteer 25 alternative
backend): Puppeteer 25 supports BiDi via {protocol: 'webDriverBiDi'}.
BiDi may handle extension SW evaluation differently (different
isolation model). Speculative — no empirical evidence either way.
What landed cleanly:
- Tier-1 hook-leak grep gate (T-1-11-01) GREEN: dist/ has zero
__mokoshTest / simulateUserStop / getSegmentCount / setCurrentStream
/ setSegmentCountGetter / __mokoshTestQuery / __mokoshKeepalive
occurrences after npm run build.
- Two-bundle infrastructure (dist/ vs dist-test/) operational.
- Bridge handler in sw-hooks.ts works for snapshot + fire-on-startup
+ handler-types ops (verified by no-hang on keepalivePing call).
- Existing 89-test vitest baseline preserved (no regression from any
Wave 0/1/2/3 work).
Verification:
- npx tsc --noEmit (src/): exit 0
- npx tsc --noEmit -p tests/uat: exit 0
- npm run build: exit 0; dist/ hook-free
- SKIP_BUILD=1 npx vitest run: 89/89 GREEN
- SKIP_PROD_REBUILD=1 npx tsx tests/uat/harness.test.ts:
2/14 passed (A0 + A4-trivially), 12 FAIL — non-zero exit as expected.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -263,7 +263,7 @@ async function main(): Promise<number> {
|
||||
// ─── Setup: launch browser, attach to SW + open popup bridge ───
|
||||
process.stdout.write('\nLaunching Chrome + opening popup bridge...\n');
|
||||
handles = await launchHarnessBrowser();
|
||||
const { browser, sw, page, popup, extensionId, downloadsDir } = handles;
|
||||
const { browser, sw, page, popup, extension, extensionId, downloadsDir } = handles;
|
||||
process.stdout.write(` extensionId: ${extensionId}\n`);
|
||||
process.stdout.write(` downloadsDir: ${downloadsDir}\n`);
|
||||
process.stdout.write(` popup: chrome-extension://${extensionId}/src/popup/index.html\n\n`);
|
||||
@@ -283,16 +283,134 @@ async function main(): Promise<number> {
|
||||
const manifest = await getManifest(popupPage);
|
||||
const expectedVersion = manifest.version;
|
||||
|
||||
// ─── Wave 3 stubbed assertions (Tasks 4-7 will wire these) ──────
|
||||
// ─── Assertion 1: SW bootstrap → setIdleMode ───────────────────
|
||||
const a1 = await runAssertion(
|
||||
1,
|
||||
'SW bootstrap → setIdleMode (badge="" + popup="" + isRecording=false)',
|
||||
buffers,
|
||||
async () => {
|
||||
// Wake the SW via the keepalive ping first — this ensures the
|
||||
// SW's initialize() has been observed before we sample state.
|
||||
// In MV3, the SW may have suspended between launch and now;
|
||||
// sendMessage wakes it for 30s.
|
||||
await keepalivePing(popupPage);
|
||||
// After SW init (production initialize() calls setIdleMode()),
|
||||
// badge becomes empty + popup becomes empty + isRecording is false.
|
||||
// Poll for the popup transition because setIdleMode's setPopup
|
||||
// call is async-propagated through the action API; the popup
|
||||
// page may briefly observe the manifest default before the
|
||||
// override lands.
|
||||
const popupUrl = await waitFor(
|
||||
() => getPopup(popupPage),
|
||||
(v) => v === '',
|
||||
3_000,
|
||||
'popup should become empty after SW initialize() runs setIdleMode',
|
||||
100,
|
||||
);
|
||||
assertEqual(popupUrl, '', 'popup expected empty in idle mode');
|
||||
const badge = await getBadgeText(popupPage);
|
||||
assertEqual(badge, '', 'badge expected empty after SW bootstrap');
|
||||
const recording = await getIsRecording(popupPage);
|
||||
assertEqual(recording, false, 'isRecording expected false at bootstrap');
|
||||
},
|
||||
);
|
||||
results.push(a1);
|
||||
|
||||
// ─── Assertion 2: Toolbar onClicked-idle → REC + popup ─────────
|
||||
const a2 = await runAssertion(
|
||||
2,
|
||||
'toolbar onClicked-idle → badge "REC" + popup set + isRecording=true',
|
||||
buffers,
|
||||
async () => {
|
||||
// Trigger the toolbar action — the production code's
|
||||
// chrome.action.onClicked listener calls startVideoCapture(),
|
||||
// which creates the offscreen + starts recording + transitions
|
||||
// the badge to REC + sets the popup to popup/index.html.
|
||||
await page.bringToFront();
|
||||
await page.triggerExtensionAction(extension);
|
||||
// Badge transition is async (offscreen create + handshake +
|
||||
// getDisplayMedia picker + post-grant validation + setBadgeText).
|
||||
// Poll up to 8s; the auto-select picker shaves most of the time.
|
||||
const badge = await waitFor(
|
||||
() => getBadgeText(popupPage),
|
||||
(v) => v === 'REC',
|
||||
8_000,
|
||||
'badge should become REC after toolbar click',
|
||||
200,
|
||||
);
|
||||
assertEqual(badge, 'REC', 'badge after toolbar click');
|
||||
const popupUrl = await getPopup(popupPage);
|
||||
assertMatch(
|
||||
popupUrl,
|
||||
/src\/popup\/index\.html$/,
|
||||
'popup should be set to popup/index.html during recording',
|
||||
);
|
||||
const recording = await getIsRecording(popupPage);
|
||||
assertEqual(recording, true, 'isRecording expected true after click');
|
||||
},
|
||||
);
|
||||
results.push(a2);
|
||||
|
||||
// ─── Assertion 3: offscreen displaySurface === 'monitor' ───────
|
||||
const a3 = await runAssertion(
|
||||
3,
|
||||
'offscreen getCurrentStream displaySurface === "monitor"',
|
||||
buffers,
|
||||
async () => {
|
||||
// A2 left recording active. The offscreen document was created
|
||||
// by startVideoCapture; wait for the target + attach.
|
||||
const offTarget = await waitForOffscreenTarget(browser, extensionId);
|
||||
const offPage = await attachToOffscreen(offTarget);
|
||||
offPage.on('console', (msg) => {
|
||||
buffers.offscreenLines.push(`[OS:${msg.type()}] ${msg.text()}`);
|
||||
});
|
||||
const ds = await getDisplaySurface(offPage);
|
||||
assertEqual(
|
||||
ds,
|
||||
'monitor',
|
||||
'displaySurface expected "monitor" per post-grant validation (D-15)',
|
||||
);
|
||||
},
|
||||
);
|
||||
results.push(a3);
|
||||
|
||||
// ─── Assertion 4: onClicked-recording → popup, no new offscreen
|
||||
const a4 = await runAssertion(
|
||||
4,
|
||||
'toolbar onClicked while recording → popup opens, no new offscreen target',
|
||||
buffers,
|
||||
async () => {
|
||||
const offscreenCountBefore = countOffscreenTargets(browser, extensionId);
|
||||
// Triggering the action during recording opens the popup
|
||||
// (production code keeps popup set in REC mode); the click
|
||||
// does NOT spawn a second offscreen.
|
||||
await page.bringToFront();
|
||||
await page.triggerExtensionAction(extension);
|
||||
// Give the popup a moment to open + Chrome to settle.
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
const offscreenCountAfter = countOffscreenTargets(browser, extensionId);
|
||||
assertEqual(
|
||||
offscreenCountAfter,
|
||||
offscreenCountBefore,
|
||||
'offscreen target count must not increase on second click during recording',
|
||||
);
|
||||
// popup must still be set (recording is ongoing).
|
||||
const popupUrl = await getPopup(popupPage);
|
||||
assertMatch(
|
||||
popupUrl,
|
||||
/src\/popup\/index\.html$/,
|
||||
'popup must remain set while recording',
|
||||
);
|
||||
},
|
||||
);
|
||||
results.push(a4);
|
||||
|
||||
// ─── Wave 3 STUBBED assertions (Tasks 5-7 will wire these) ─────
|
||||
const stubs: Array<{
|
||||
index: number;
|
||||
name: string;
|
||||
taskNumber: number;
|
||||
}> = [
|
||||
{ index: 1, name: 'SW bootstrap → setIdleMode', taskNumber: 4 },
|
||||
{ index: 2, name: 'toolbar onClicked-idle → badge REC + popup', taskNumber: 4 },
|
||||
{ index: 3, name: 'offscreen displaySurface === monitor', taskNumber: 4 },
|
||||
{ index: 4, name: 'toolbar onClicked-recording → popup, no new offscreen', taskNumber: 4 },
|
||||
{ index: 5, name: 'SAVE_ARCHIVE → download fires + zip appears', taskNumber: 5 },
|
||||
{ index: 6, name: 'BUG B canonical: simulateUserStop → badge OFF + no recovery notif', taskNumber: 5 },
|
||||
{ index: 7, name: 'RECORDING_ERROR codec-unsupported → badge ERR + recovery notif', taskNumber: 5 },
|
||||
@@ -314,30 +432,17 @@ async function main(): Promise<number> {
|
||||
results.push(rec);
|
||||
}
|
||||
|
||||
// Suppress unused-warning placeholders — Tasks 4-7 will use these
|
||||
// imports + handles directly. Reference them here for type-clean.
|
||||
void browser;
|
||||
void page;
|
||||
void popupPage;
|
||||
// Suppress unused-warning placeholders for Tasks 5-7 helpers.
|
||||
void expectedVersion;
|
||||
void waitForOffscreenTarget;
|
||||
void attachToOffscreen;
|
||||
void countOffscreenTargets;
|
||||
void waitFor;
|
||||
void getBadgeText;
|
||||
void getPopup;
|
||||
void getIsRecording;
|
||||
void getIconSize;
|
||||
void fireOnStartup;
|
||||
void sendSyntheticRecordingError;
|
||||
void getNotificationSnapshot;
|
||||
void keepalivePing;
|
||||
void getDisplaySurface;
|
||||
void simulateUserStop;
|
||||
void getSegmentCount;
|
||||
void assertArchiveShape;
|
||||
void extractEntryToFile;
|
||||
void assertMatch;
|
||||
void assertTrue;
|
||||
void assertGte;
|
||||
void waitForDownloadedZip;
|
||||
|
||||
Reference in New Issue
Block a user