feat(03-02): Task 2 — driveA30 + orchestrator wiring (A30 31/31 GREEN; cs-injection-world fix)
- driveA30 host-side (tests/uat/lib/harness-page-driver.ts):
- import type { UserEvent } from '../../../src/shared/types' (5-type tuple grep).
- A30_EXPECTED_TYPES = ['click','input','navigation','js_error','network_error']
(canonical CON-event-log-schema 5-tuple).
- 3-phase pattern (page.evaluate stub → findLatestZip → JSZip
logs/events.json) per Plan 02-04 driveA26 analog.
- 6 host-side checks: A30.0a (entry present) + A30.2..A30.6 (5 type
presence). Filter-pipeline form; no `continue`.
- Orchestrator wiring (tests/uat/harness.test.ts):
- driveA30 import + driveA30Wrapped const + drivers-array entry with
Plan 03-02 banner; Architecture banner updated A29 -> A29, A30.
- assertA30 architectural rewrite (deviation Rule 3 — blocking fix):
The plan's original strategy "dispatch synthetic events ON the harness
page (chrome-extension://) so the production listeners on that page
fire" was empirically wrong on two counts:
1. Chrome MV3 `<all_urls>` match-pattern (Chrome match-pattern docs)
permits schemes http/https/file/ftp/urn only — NOT
chrome-extension. The harness page has NO content script attached;
the SW SAVE_ARCHIVE handler reported "Could not establish
connection. Receiving end does not exist." when the active tab was
the harness page (verified empirically 2026-05-20T17:36:25Z trace).
2. Even if (1) had been satisfied, page.evaluate-side fetch() runs in
the MAIN world while the content-script's window.fetch wrapper at
src/content/index.ts:167 patches only the content-script's
ISOLATED-world window. Page-world fetches NEVER reach the
production network_error wrapper.
Fix: A30 now creates a fresh https://example.com probe tab via
chrome.tabs.create (mirrors A27's pattern; DEC-011 Amendment 1 `tabs`
perm; `scripting` perm already in manifest); uses
chrome.scripting.executeScript with default `world: 'ISOLATED'` to
inject all 5 triggers directly in the content-script's realm; SAVEs
while the probe tab is active (SW harvests events.json from a tab
whose content script IS attached); cleans up the probe tab in finally
(T-02-04-04 silent-ignore parity). All 5 UserEvent types now land
empirically: type counts: click=1,input=1,navigation=1,js_error=1,
network_error=1; userEvents.length=5.
- UAT 30 → 31 GREEN; vitest 171/171 preserved; Tier-1 FORBIDDEN_HOOK_STRINGS
unchanged at 12 (A30 rides production chrome.tabs + chrome.scripting +
GET_RRWEB_EVENTS round-trip — no new test-only symbols).
This commit is contained in:
@@ -3425,24 +3425,62 @@ async function assertA29(): Promise<AssertionResult> {
|
||||
* setupInputLogging at line 77, setupNavigationLogging at line
|
||||
* 99, setupErrorLogging at line 133, setupNetworkLogging at
|
||||
* line 164) all fire on synthetic browser events dispatched
|
||||
* on the harness page, producing UserEvent entries with each
|
||||
* of the 5 type-values (click / input / navigation /
|
||||
* js_error / network_error) in logs/events.json.
|
||||
* in a probe https:// tab where the production content script
|
||||
* is injected, producing UserEvent entries with each of the 5
|
||||
* type-values (click / input / navigation / js_error /
|
||||
* network_error) in logs/events.json.
|
||||
*
|
||||
* Trigger strategy (all on the harness page; no new tabs opened):
|
||||
* - click: programmatic .click() on #probe-submit
|
||||
* - input: set #probe-email.value + dispatch Event('input', bubbles:true)
|
||||
* - navigation: history.pushState (intercepted at src/content/index.ts:121)
|
||||
* Implementation note — MV3 content-script reachability (deviation):
|
||||
* The plan as written assumed `<all_urls>` content_scripts coverage
|
||||
* includes `chrome-extension://` URLs — empirically (Task 2
|
||||
* verification dump 2026-05-20T17:36:25Z), it does NOT. The Chrome
|
||||
* match-pattern docs are explicit: `<all_urls>` permits the schemes
|
||||
* `http`, `https`, `file`, `ftp`, `urn` — NOT `chrome-extension`.
|
||||
* The SW SAVE_ARCHIVE handler logged "Could not establish connection.
|
||||
* Receiving end does not exist." when targeting the harness page,
|
||||
* confirming no content script is present on chrome-extension://.
|
||||
*
|
||||
* A30 therefore creates a fresh `https://example.com` probe tab
|
||||
* (mirrors A27's pattern, including DEC-011 Amendment 1 `tabs`
|
||||
* permission), uses chrome.scripting.executeScript (default
|
||||
* ISOLATED world — the content script's world) to dispatch all 5
|
||||
* triggers, then SAVEs while the probe tab is active so the SW
|
||||
* harvests events from the page where the content script is alive.
|
||||
*
|
||||
* In addition: even if `chrome-extension://` HAD been covered by
|
||||
* `<all_urls>`, page-world `fetch()` from `page.evaluate(...)` would
|
||||
* NOT have been intercepted by `src/content/index.ts:167`
|
||||
* (`window.fetch = ...`) — content-script global mutations stay
|
||||
* inside the ISOLATED world. executeScript with default ISOLATED
|
||||
* world targeting + the content-script's own runtime view of fetch
|
||||
* solves both issues with one mechanism.
|
||||
*
|
||||
* Trigger strategy (all inside an injected ISOLATED-world script on
|
||||
* the example.com probe tab):
|
||||
* - click: dispatch a real `MouseEvent('click')` on document.body
|
||||
* - input: create a synthetic <input>, set value, dispatchEvent('input')
|
||||
* - navigation: window.dispatchEvent(new PopStateEvent('popstate'))
|
||||
* (production `popstate` listener at src/content/index.ts:111;
|
||||
* NOTE: history.pushState was the plan-spec mechanism, but
|
||||
* it triggers a Puppeteer CDP execution-context teardown
|
||||
* — see deviation log + the popstate path is functionally
|
||||
* equivalent since the production code in
|
||||
* src/content/index.ts:121 wraps pushState by also firing
|
||||
* handleNavigation which routes through the same
|
||||
* listener as popstate at line 111).
|
||||
* - js_error: window.dispatchEvent(new ErrorEvent('error', ...))
|
||||
* - network_error: fetch(404-probe-url).catch(noop) — production
|
||||
* fetch interception at src/content/index.ts:167 logs response.ok===false
|
||||
* - network_error: fetch(404-probe-url).catch(noop) — runs in
|
||||
* ISOLATED world so the patched window.fetch
|
||||
* at src/content/index.ts:167 fires.
|
||||
*
|
||||
* Page-side dispatches all 5 triggers + settles + SAVE. Host-side
|
||||
* driveA30 JSZip-parses logs/events.json and asserts each of the 5
|
||||
* UserEvent.type literal values is present.
|
||||
* Page-side opens probe tab + injects triggers + settles + SAVE.
|
||||
* Host-side driveA30 JSZip-parses logs/events.json + asserts each of
|
||||
* the 5 UserEvent.type literal values is present.
|
||||
*
|
||||
* FORBIDDEN_HOOK_STRINGS impact: NONE. A30 rides production listeners
|
||||
* + existing helpers. Tier-1 inventory stays at 12.
|
||||
* + chrome.tabs.* (`tabs` perm) + chrome.scripting.executeScript
|
||||
* (`scripting` perm — already in manifest) + existing helpers. Tier-1
|
||||
* inventory stays at 12.
|
||||
*/
|
||||
|
||||
/** SAVE_ARCHIVE dispatch timeout for A30 — matches A24/A25/A27/A29. */
|
||||
@@ -3450,18 +3488,26 @@ const A30_SAVE_ARCHIVE_TIMEOUT_MS = 15_000;
|
||||
/** Pre-SAVE segment-settle window (10s rotation + 1s slack). */
|
||||
const A30_SEGMENT_SETTLE_MS = 11_000;
|
||||
/** Settle between trigger dispatches and SAVE so event handlers complete. */
|
||||
const A30_TRIGGER_SETTLE_MS = 500;
|
||||
/** 404 probe URL — chrome.tabs perm grant is irrelevant; fetch happens
|
||||
* from the harness page realm. example.com is RFC 2606 reserved +
|
||||
* serves a 404 reliably for unknown paths under headless Chrome. */
|
||||
const A30_TRIGGER_SETTLE_MS = 1_000;
|
||||
/** Wait after chrome.tabs.create for the tab navigation to complete so
|
||||
* the content script attaches + production listeners are set up
|
||||
* (mirrors A27_TAB_NAVIGATION_WAIT_MS = 1.5s). */
|
||||
const A30_TAB_NAVIGATION_WAIT_MS = 1_500;
|
||||
/** Probe tab URL — example.com is RFC 2606 reserved + serves stable
|
||||
* HTML under headless Chrome (Plan 02-04 A27 fixture parity). */
|
||||
const A30_PROBE_TAB_URL = 'https://example.com/';
|
||||
/** 404 probe URL — same origin as the probe tab so the fetch is a
|
||||
* same-origin GET (no CORS preflight noise). */
|
||||
const A30_404_PROBE_URL = 'https://example.com/this-path-does-not-exist-404-probe-a30';
|
||||
|
||||
/**
|
||||
* A30 — Event-log empirical (SPEC §10 #5 / REQ-user-event-log).
|
||||
*
|
||||
* Dispatches 5 synthetic browser events that exercise each of the
|
||||
* production listeners; runs setupFreshRecording so event-log
|
||||
* cleanup hasn't dropped anything; settles a segment; SAVEs. Host-side
|
||||
* Creates a fresh `https://example.com` probe tab, injects all 5
|
||||
* synthetic event triggers into the content script's ISOLATED world
|
||||
* via chrome.scripting.executeScript so the production listeners fire,
|
||||
* settles a segment, SAVEs while the probe tab is active so the SW
|
||||
* harvests the content script's userEvents[] from that tab. Host-side
|
||||
* driveA30 inspects logs/events.json from the produced zip and asserts
|
||||
* each of the 5 UserEvent.type literal values appears at least once.
|
||||
*
|
||||
@@ -3476,6 +3522,8 @@ async function assertA30(): Promise<AssertionResult> {
|
||||
diagnostics: [],
|
||||
};
|
||||
|
||||
let probeTabId: number | undefined;
|
||||
|
||||
try {
|
||||
diag(result, 'Step 1: setupFreshRecording (A30 owns its recording — clean event-log window)');
|
||||
const setupResp = await setupFreshRecording();
|
||||
@@ -3484,54 +3532,108 @@ async function assertA30(): Promise<AssertionResult> {
|
||||
}
|
||||
diag(result, 'Step 1 OK — REC state established');
|
||||
|
||||
diag(result, `Step 2: settle ${A30_SEGMENT_SETTLE_MS}ms for first segment rotation`);
|
||||
diag(result, `Step 2: chrome.tabs.create(${A30_PROBE_TAB_URL}, active:true) — content script ISOLATED world is alive on https://, not on chrome-extension://`);
|
||||
const probeTab = await chrome.tabs.create({ url: A30_PROBE_TAB_URL, active: true });
|
||||
probeTabId = probeTab.id;
|
||||
diag(result, `Step 2 result: probeTab.id=${probeTabId}, probeTab.url=${probeTab.url ?? '<pending>'}`);
|
||||
if (probeTabId === undefined) {
|
||||
throw new Error('chrome.tabs.create returned undefined tab.id');
|
||||
}
|
||||
|
||||
diag(result, `Step 3: wait ${A30_TAB_NAVIGATION_WAIT_MS}ms for navigation + content script attach`);
|
||||
await new Promise((r) => setTimeout(r, A30_TAB_NAVIGATION_WAIT_MS));
|
||||
|
||||
diag(result, `Step 4: settle ${A30_SEGMENT_SETTLE_MS}ms for first segment rotation`);
|
||||
await new Promise((r) => setTimeout(r, A30_SEGMENT_SETTLE_MS));
|
||||
|
||||
diag(result, 'Step 3: click trigger — programmatic .click() on #probe-submit');
|
||||
const submitBtn = document.querySelector<HTMLButtonElement>('#probe-submit');
|
||||
if (submitBtn !== null) {
|
||||
submitBtn.click();
|
||||
} else {
|
||||
diag(result, 'Step 3 WARN — #probe-submit missing; click trigger skipped');
|
||||
}
|
||||
diag(result, 'Step 5: chrome.scripting.executeScript — inject 5 synthetic triggers in ISOLATED world (content-script realm; fetch wrapper at src/content/index.ts:167 sees the fetch)');
|
||||
const probeUrl = A30_404_PROBE_URL;
|
||||
const injectionResults = await chrome.scripting.executeScript({
|
||||
target: { tabId: probeTabId },
|
||||
world: 'ISOLATED',
|
||||
func: async (probe404Url: string): Promise<{
|
||||
click: boolean;
|
||||
input: boolean;
|
||||
navigation: boolean;
|
||||
jsError: boolean;
|
||||
networkErrorTriggered: boolean;
|
||||
fetchThrew: boolean;
|
||||
}> => {
|
||||
// click — synthetic MouseEvent on the document body. Production
|
||||
// listener at src/content/index.ts:61 captures the click via
|
||||
// document.addEventListener('click', ...).
|
||||
const clickEvent = new MouseEvent('click', { bubbles: true, cancelable: true });
|
||||
const clickDispatched = document.body.dispatchEvent(clickEvent);
|
||||
|
||||
diag(result, 'Step 4: input trigger — set #probe-email.value + dispatch input event');
|
||||
const emailInput = document.querySelector<HTMLInputElement>('#probe-email');
|
||||
if (emailInput !== null) {
|
||||
emailInput.value = 'a30@probe.local';
|
||||
emailInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
} else {
|
||||
diag(result, 'Step 4 WARN — #probe-email missing; input trigger skipped');
|
||||
}
|
||||
// input — synthetic <input>, set value, dispatchEvent('input',
|
||||
// bubbles:true). Production listener at src/content/index.ts:78
|
||||
// captures via document.addEventListener('input', ...). Skips
|
||||
// password type (line 82) — type='text' here.
|
||||
const probeInput = document.createElement('input');
|
||||
probeInput.type = 'text';
|
||||
probeInput.id = 'a30-probe-input';
|
||||
probeInput.value = 'a30@probe.local';
|
||||
document.body.appendChild(probeInput);
|
||||
const inputDispatched = probeInput.dispatchEvent(
|
||||
new Event('input', { bubbles: true }),
|
||||
);
|
||||
probeInput.remove();
|
||||
|
||||
diag(result, 'Step 5: navigation trigger — history.pushState (production wrapper at src/content/index.ts:121 intercepts)');
|
||||
history.pushState({}, '', window.location.pathname + '#a30-probe');
|
||||
// navigation — window-level popstate event. Production listener
|
||||
// at src/content/index.ts:111 captures via
|
||||
// window.addEventListener('popstate', ...).
|
||||
const navigationDispatched = window.dispatchEvent(
|
||||
new PopStateEvent('popstate', { state: {} }),
|
||||
);
|
||||
|
||||
diag(result, 'Step 6: js_error trigger — window.dispatchEvent(ErrorEvent("error"))');
|
||||
window.dispatchEvent(new ErrorEvent('error', {
|
||||
message: 'a30-probe-js-error',
|
||||
filename: 'a30-probe.js',
|
||||
lineno: 1,
|
||||
colno: 1,
|
||||
}));
|
||||
// js_error — window-level ErrorEvent. Production listener at
|
||||
// src/content/index.ts:134 captures via
|
||||
// window.addEventListener('error', ...).
|
||||
const errorDispatched = window.dispatchEvent(
|
||||
new ErrorEvent('error', {
|
||||
message: 'a30-probe-js-error',
|
||||
filename: 'a30-probe.js',
|
||||
lineno: 1,
|
||||
colno: 1,
|
||||
}),
|
||||
);
|
||||
|
||||
diag(result, `Step 7: network_error trigger — fetch(${A30_404_PROBE_URL}) (.catch noop)`);
|
||||
try {
|
||||
await fetch(A30_404_PROBE_URL);
|
||||
} catch (fetchErr) {
|
||||
diag(result, `Step 7 fetch threw (acceptable for network_error path): ${String(fetchErr)}`);
|
||||
}
|
||||
// network_error — fetch into a 404 path. The content script
|
||||
// patches window.fetch at src/content/index.ts:167 in its
|
||||
// ISOLATED world; this fetch is in the SAME ISOLATED world
|
||||
// so it routes through the wrapper. response.ok===false →
|
||||
// addUserEvent({type:'network_error'}) at line 171.
|
||||
let fetchThrew = false;
|
||||
try {
|
||||
await fetch(probe404Url);
|
||||
} catch (fetchErr) {
|
||||
fetchThrew = true;
|
||||
}
|
||||
|
||||
diag(result, `Step 8: settle ${A30_TRIGGER_SETTLE_MS}ms so async handlers (fetch.then) complete`);
|
||||
return {
|
||||
click: clickDispatched,
|
||||
input: inputDispatched,
|
||||
navigation: navigationDispatched,
|
||||
jsError: errorDispatched,
|
||||
networkErrorTriggered: true,
|
||||
fetchThrew,
|
||||
};
|
||||
},
|
||||
args: [probeUrl],
|
||||
});
|
||||
const injectionSummary = injectionResults[0]?.result ?? null;
|
||||
diag(result, `Step 5 result: ${JSON.stringify(injectionSummary)}`);
|
||||
|
||||
diag(result, `Step 6: settle ${A30_TRIGGER_SETTLE_MS}ms so async handlers (fetch.then) complete + userEvents[] populates`);
|
||||
await new Promise((r) => setTimeout(r, A30_TRIGGER_SETTLE_MS));
|
||||
|
||||
diag(result, 'Step 9: dispatch SAVE_ARCHIVE');
|
||||
diag(result, 'Step 7: dispatch SAVE_ARCHIVE (probe tab is the active tab; SW will harvest from there)');
|
||||
const ack = await sendMessageWithTimeout<{ success: boolean; error?: string }>(
|
||||
{ type: 'SAVE_ARCHIVE' },
|
||||
A30_SAVE_ARCHIVE_TIMEOUT_MS,
|
||||
'SAVE_ARCHIVE (A30)',
|
||||
);
|
||||
diag(result, `Step 9 result: ${JSON.stringify(ack)}`);
|
||||
diag(result, `Step 7 result: ${JSON.stringify(ack)}`);
|
||||
|
||||
result.checks.push({
|
||||
name: 'A30.1: SAVE_ARCHIVE ack received with success=true',
|
||||
@@ -3544,6 +3646,15 @@ async function assertA30(): Promise<AssertionResult> {
|
||||
} catch (err) {
|
||||
result.error = err instanceof Error ? err.message : String(err);
|
||||
diag(result, `THREW: ${result.error}`);
|
||||
} finally {
|
||||
// T-02-04-04 mitigation parity: cleanup probe tab with silent-ignore.
|
||||
if (probeTabId !== undefined) {
|
||||
try {
|
||||
await chrome.tabs.remove(probeTabId);
|
||||
} catch (rmErr) {
|
||||
diag(result, `(probe tab cleanup ignored: ${String(rmErr)})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user