Milestone v1 (v2.0.0): Mokosh — Session Capture #1

Merged
strategy155 merged 297 commits from gsd/phase-04-harden-clean-up-optional into main 2026-05-31 15:34:17 +00:00
7 changed files with 228 additions and 13 deletions
Showing only changes of commit b467123578 - Show all commits

View File

@@ -267,11 +267,27 @@ async function startRecording(): Promise<void> {
// Use a typed widening through `DisplayMediaStreamOptions &
// {video: Record<...>}` instead of `as any` to stay explicit
// about the precise field we're adding.
//
// Plan 01-14: `monitorTypeSurfaces: 'include'` is a TOP-LEVEL member
// of DisplayMediaStreamOptions (W3C Screen Capture spec §6.1 — NOT
// nested in `video:`; that would route it to MediaTrackConstraints).
// Chrome ≥ 119 (Chrome screen-sharing-controls release notes:
// https://developer.chrome.com/docs/web-platform/screen-sharing-controls)
// honors the constraint by narrowing the picker dialog to ONLY
// monitor surfaces — the Window and Chrome-Tab panes are elided.
// The post-grant validation block immediately below remains the
// actual enforcement (constraints are HINT-class per spec — the
// operator can still override via the picker UI on older Chrome
// versions, and managed-policy / DevTools can override anywhere).
// Belt (picker-UI narrowing) + suspenders (post-grant tear-down)
// per Plan 01-10 RESEARCH §5 + §Pitfall-5 recommendation.
const stream = await navigator.mediaDevices.getDisplayMedia({
video: { displaySurface: 'monitor', cursor: 'always' },
monitorTypeSurfaces: 'include', // Plan 01-14 — Chrome ≥ 119 picker narrowing per W3C spec §6.1
audio: false, // SPEC §9 — Phase 2 / CAP-01 territory
} as DisplayMediaStreamOptions & {
video: { displaySurface: 'monitor'; cursor: 'always' };
monitorTypeSurfaces: 'include';
});
mediaStream = stream;
// Plan 01-11 Task 2: wire the live MediaStream into the test hook

View File

@@ -99,6 +99,22 @@ let fakeCanvas: HTMLCanvasElement | null = null;
let fakeAnimationHandle: number | null = null;
let fakeDrawInterval: ReturnType<typeof setInterval> | null = null;
/**
* Plan 01-14 A23 contract — record the last-received constraints object
* from every `fakeGetDisplayMedia` invocation. The `installFakeDisplayMedia`
* shim already accepts the `constraints` parameter (previously prefixed
* `_constraints` as received-but-unused — see below), so the production
* call site's `monitorTypeSurfaces: 'include'` sibling lands here. The
* `get-last-getDisplayMedia-constraints` bridge op (later in this file)
* reads it for harness inspection.
*
* `null` until any `getDisplayMedia` call has been made — A23 always
* runs AFTER A2's `setupFreshRecording` so the cell is populated by
* then. Test bundle only; gated identically to the rest of this module
* by the top-of-module `__MOKOSH_UAT__` import in src/offscreen/recorder.ts.
*/
let lastGetDisplayMediaConstraints: DisplayMediaStreamOptions | null = null;
/**
* Replace `navigator.mediaDevices.getDisplayMedia` with a synthetic
* implementation backed by a hidden 30 fps canvas. The returned
@@ -233,8 +249,13 @@ export function installFakeDisplayMedia(): void {
// straight assignment would trip the type checker. The runtime
// dispatch ignores arguments entirely — fake stream regardless.
const fakeGetDisplayMedia = async (
_constraints?: DisplayMediaStreamOptions,
constraints?: DisplayMediaStreamOptions,
): Promise<MediaStream> => {
// Plan 01-14 A23: capture the production call's constraints object
// so the harness can verify `monitorTypeSurfaces: 'include'` reached
// the call site. Default to null on undefined-args so the bridge op
// reports an unambiguous "no args" signal rather than `undefined`.
lastGetDisplayMediaConstraints = constraints ?? null;
return mintStream();
};
(navigator.mediaDevices as unknown as {
@@ -355,6 +376,14 @@ globalThis.__mokoshTest = {
// zero count is meaningful. The 10s rotation cadence (D-13;
// SEGMENT_DURATION_MS) means a recording that has been live for
// ~35s should report count ≥ 3 (3 × 10s = 30s = MAX_SEGMENTS).
// op='get-last-getDisplayMedia-constraints' → { constraints: object|null }
// — Plan 01-14 A23 contract. Returns the most-recent constraints
// object captured by `fakeGetDisplayMedia`. Used by the harness to
// verify the production call site passes `monitorTypeSurfaces: 'include'`
// (W3C Screen Capture spec §6.1; Chrome ≥ 119 picker-narrowing
// semantics). `null` only when no getDisplayMedia call has happened
// yet — A23 always runs AFTER A2's setupFreshRecording so a non-null
// value is the expected case.
// Unknown ops respond { ok: false, error: 'unknown-op' }.
//
// The bridge handler MUST run BEFORE the production offscreen bridge
@@ -433,6 +462,34 @@ chrome.runtime.onMessage.addListener((rawMessage, _sender, sendResponse) => {
}
return false;
}
if (op === 'get-last-getDisplayMedia-constraints') {
// Plan 01-14 A23 contract — return the most-recent constraints object
// captured by the `fakeGetDisplayMedia` shim. Production code at
// src/offscreen/recorder.ts:270 calls `navigator.mediaDevices.getDisplayMedia({
// video: {...}, monitorTypeSurfaces: 'include', audio: false })`; this op
// exposes that object so the harness can assert
// `constraints.monitorTypeSurfaces === 'include'`.
//
// `null` is returned in two cases:
// (a) No `getDisplayMedia` call has been made yet — A23 always runs
// AFTER A2's setupFreshRecording so this is unreachable in the
// orchestrated sequence;
// (b) The call was made with `undefined` args — also unreachable for
// the production call site which always supplies the constraints
// object.
// try/catch is defensive — bridge handlers must never propagate
// exceptions to chrome.runtime.sendMessage (the dispatcher contract
// shared by all ops above).
try {
sendResponse({ constraints: lastGetDisplayMediaConstraints });
} catch (err) {
sendResponse({
ok: false,
error: err instanceof Error ? err.message : String(err),
});
}
return false;
}
if (op === 'get-segment-count') {
// Plan 01-13 Wave 3D A11 contract — return the offscreen recorder's
// live segment count via the `segmentCountGetter` closure wired at

View File

@@ -60,13 +60,16 @@
// - `__mokoshOffscreenQuery` — 01-13 page→offscreen bridge message type
// - `get-display-surface` — 01-13 Wave 3A bridge op string (A3 contract)
// - `get-segment-count` — 01-13 Wave 3D bridge op string (A11 contract)
// - `lastGetDisplayMediaConstraints` — 01-14 A23 offscreen-side cell name
// - `get-last-getDisplayMedia-constraints` — 01-14 A23 bridge op string
//
// Total: 10 surface strings. Each MUST be absent from EVERY file under
// Total: 12 surface strings. Each MUST be absent from EVERY file under
// `dist/` post-build. The list is mirrored by the harness's A0
// assertion (tests/uat/harness.test.ts in Wave 3A) so the same
// invariant is enforced at unit-test time (fast, every CI run) AND
// at UAT-harness time (belt+suspenders per the orchestrator-loaded
// `feedback-pre-checkpoint-bundle-gates.md` memory).
// assertion (tests/uat/harness.test.ts in Wave 3A; Plan 01-14 lockstep
// extension) so the same invariant is enforced at unit-test time
// (fast, every CI run) AND at UAT-harness time (belt+suspenders per
// the orchestrator-loaded `feedback-pre-checkpoint-bundle-gates.md`
// memory).
//
// Implementation mirrors `sw-bundle-import.test.ts`'s execFile pattern:
// - Spawn `npm run build` via execFile so the build is reproducible
@@ -113,6 +116,13 @@ const FORBIDDEN_HOOK_STRINGS: ReadonlyArray<string> = [
'__mokoshOffscreenQuery',
'get-display-surface',
'get-segment-count',
// Plan 01-14 A23 surface — lockstep with UAT A0 inventory at
// tests/uat/harness.test.ts:85. Verifies the `__MOKOSH_UAT__` Vite
// define-token dead-branch tree-shake correctly elides the new
// `lastGetDisplayMediaConstraints` cell + the `get-last-getDisplayMedia-constraints`
// bridge op from production `dist/` (T-01-14-04 mitigation).
'lastGetDisplayMediaConstraints',
'get-last-getDisplayMedia-constraints',
];
/** How long the build child has to finish (`npm run build` is ~10s).

View File

@@ -219,9 +219,13 @@ describe('Plan 01-09 D-15-display-surface: getDisplayMedia constraints + post-gr
expect(getDisplayMediaSpy).toHaveBeenCalledTimes(1);
// Strict deep-equality — NOT expect.objectContaining. Catches a
// future drop of either `displaySurface` or `cursor`.
// future drop of either `displaySurface` or `cursor` (D-15) OR
// the Plan 01-14 top-level `monitorTypeSurfaces: 'include'` picker-
// narrowing constraint. Key ordering matches the source call at
// src/offscreen/recorder.ts: video → monitorTypeSurfaces → audio.
expect(getDisplayMediaSpy).toHaveBeenCalledWith({
video: { displaySurface: 'monitor', cursor: 'always' },
monitorTypeSurfaces: 'include',
audio: false,
});
});

View File

@@ -1903,6 +1903,81 @@ async function assertA14(): Promise<AssertionResult> {
return result;
}
/**
* A23 — Plan 01-14 picker-narrowing constraint verification.
*
* Asserts that the production `getDisplayMedia` call at
* src/offscreen/recorder.ts:270 passes `monitorTypeSurfaces: 'include'`
* as a top-level constraint sibling of `video:` (W3C Screen Capture
* spec §6.1; Chrome ≥ 119 picker-narrowing semantics — only monitor
* surfaces are offered, no Window/Chrome-Tab panes).
*
* Queries the offscreen bridge `get-last-getDisplayMedia-constraints` op
* which reads the recorded constraints from the `fakeGetDisplayMedia`
* shim's last invocation. A23 chains AFTER A14 (A14 is the final read-
* only post-SAVE state check; A23 is independent because A2's
* setupFreshRecording already invoked getDisplayMedia and the recorded
* cell is read-only from A23's perspective — no side effects).
*
* Mirrors `assertA3` (line 686): bridge query → structured AssertionResult
* with two checks (non-null constraints + monitorTypeSurfaces value).
*
* @returns Structured result with the monitorTypeSurfaces check.
*/
async function assertA23(): Promise<AssertionResult> {
const result: AssertionResult = {
passed: false,
name: 'A23 — getDisplayMedia called with monitorTypeSurfaces:\'include\' (Plan 01-14 picker narrowing)',
checks: [],
diagnostics: [],
};
try {
diag(result, "Step 1: bridge query 'get-last-getDisplayMedia-constraints'");
const resp = await offscreenQuery<{
constraints?: DisplayMediaStreamOptions | null;
ok?: boolean;
error?: string;
}>('get-last-getDisplayMedia-constraints');
diag(result, `Step 1 result: ${JSON.stringify(resp)}`);
if (resp.ok === false) {
throw new Error(
`get-last-getDisplayMedia-constraints returned ok=false: ${resp.error ?? '(no error)'}`,
);
}
const constraints = resp.constraints ?? null;
result.checks.push({
name: 'A23.1: constraints object recorded by fakeGetDisplayMedia (non-null)',
expected: 'non-null DisplayMediaStreamOptions',
actual: constraints === null ? '<null>' : JSON.stringify(constraints),
passed: constraints !== null,
});
// The constraints object MAY be widened by the production cast (per
// Plan 01-14 source change) to include the top-level field, so we
// dot-access via the same indexed-property shape (`as any`) since
// monitorTypeSurfaces is not in the lib.dom.d.ts DisplayMediaStreamOptions
// ambient (TypeScript bundled types lag the W3C spec — same lag that
// forced the `cursor: 'always'` typed-widening cast on recorder.ts:268).
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- constraints widening for top-level monitorTypeSurfaces sibling per W3C spec §6.1 (lib.dom.d.ts lag)
const monitorTypeSurfaces = (constraints as any)?.monitorTypeSurfaces ?? null;
result.checks.push({
name: 'A23.2: constraints.monitorTypeSurfaces === \'include\' (W3C spec §6.1; Chrome ≥ 119 picker narrowing)',
expected: 'include',
actual: monitorTypeSurfaces,
passed: monitorTypeSurfaces === 'include',
});
result.passed = result.checks.every((c) => c.passed);
} catch (err) {
result.error = err instanceof Error ? err.message : String(err);
diag(result, `THREW: ${result.error}`);
}
return result;
}
/**
* Read `chrome.runtime.getManifest().version`. Used by the host-side
* orchestrator at startup to capture the expected version for A13's
@@ -1934,6 +2009,7 @@ declare global {
assertA12: () => Promise<AssertionResult>;
assertA13: () => Promise<AssertionResult>;
assertA14: () => Promise<AssertionResult>;
assertA23: () => Promise<AssertionResult>;
getManifestVersion: () => Promise<string>;
};
}
@@ -1954,14 +2030,15 @@ window.__mokoshHarness = {
assertA12,
assertA13,
assertA14,
assertA23,
getManifestVersion,
};
const statusEl = document.getElementById('status');
if (statusEl !== null) {
statusEl.textContent = 'Harness ready. window.__mokoshHarness.{assertA1..assertA14, getManifestVersion} available.';
statusEl.textContent = 'Harness ready. window.__mokoshHarness.{assertA1..assertA14, assertA23, getManifestVersion} available.';
}
console.log('[harness-page] ready — window.__mokoshHarness installed (Plan 01-13 Task 9: A1..A14 + getManifestVersion)');
console.log('[harness-page] ready — window.__mokoshHarness installed (Plan 01-13 Task 9: A1..A14 + Plan 01-14: A23 + getManifestVersion)');
export {};

View File

@@ -19,7 +19,17 @@
// Plan 01-13 Task 9 closure (debug 01-09-save-stops-recording) adds A14:
// post-SAVE auto-stop state check (badge='', popup='', no new
// mokosh-recovery-*). Chains off A13's SAVE_ARCHIVE — read-only
// observation, no new dispatch. Final target: 15/15 GREEN.
// observation, no new dispatch.
//
// Plan 01-14 adds A23 as the final functional assertion (post-A14 chain):
// read-only inspection of the last `getDisplayMedia` constraints from
// A2's setupFreshRecording; verifies the production call site passes
// `monitorTypeSurfaces: 'include'` (W3C Screen Capture spec §6.1; Chrome
// ≥ 119 picker-narrowing semantics — removes the Window + Chrome-Tab
// panes from the operator's picker dialog). A23 has no side effects
// (the constraints cell is populated by A2 and read by the bridge op);
// hence independent of A14's no-side-effects post-SAVE contract.
// Final target: 16/16 GREEN.
//
// The orchestrator structure is final from Wave 3A onward; future waves
// only fill in the assertion-driver stubs.
@@ -67,6 +77,7 @@ import {
driveA12,
driveA13,
driveA14,
driveA23,
getManifestVersion,
} from './lib/harness-page-driver';
import {
@@ -93,6 +104,10 @@ const FORBIDDEN_HOOK_STRINGS: ReadonlyArray<string> = [
'__mokoshOffscreenQuery',
'get-display-surface',
'get-segment-count',
// Plan 01-14 A23 surface — lockstep with unit-gate inventory at
// tests/background/no-test-hooks-in-prod-bundle.test.ts:105.
'lastGetDisplayMediaConstraints',
'get-last-getDisplayMedia-constraints',
];
/** Build timeout for the pre-flight production rebuild (matches unit-gate value). */
@@ -230,8 +245,8 @@ async function assertA0_GrepGate(): Promise<{
* @returns Process exit code: 0 on 15/15 GREEN, 1 on any failure.
*/
async function main(): Promise<number> {
process.stdout.write('\nMokosh Plan 01-13 — UAT harness orchestrator\n');
process.stdout.write('Architecture: A0 pre-flight + extension-internal page driver (A1..A13)\n');
process.stdout.write('\nMokosh Plan 01-13 + 01-14 — UAT harness orchestrator\n');
process.stdout.write('Architecture: A0 pre-flight + extension-internal page driver (A1..A14, A23)\n');
process.stdout.write('='.repeat(72) + '\n');
// A0 pre-flight (no Chrome launch needed; runs against built dist/).
@@ -309,6 +324,13 @@ async function main(): Promise<number> {
// notification ids state; no new SAVE dispatch — A13's already
// exercised the SAVE path. Recording stays stopped after A14.
{ name: 'A14', drive: driveA14 },
// Plan 01-14 A23: read-only inspection of the last getDisplayMedia
// constraints object captured by A2's setupFreshRecording. Verifies
// the production call at src/offscreen/recorder.ts:270 passes
// `monitorTypeSurfaces: 'include'` (W3C Screen Capture spec §6.1;
// Chrome ≥ 119 picker-narrowing semantics). Independent of A14 —
// no new getDisplayMedia call, no new state change.
{ name: 'A23', drive: driveA23 },
];
const buffers = { swConsole: handles.swConsole, offConsole: handles.offConsole };
@@ -351,7 +373,9 @@ async function main(): Promise<number> {
}
const passedCount = results.filter((r) => r.passed).length;
// Total = 1 (A0) + drivers.length (A1..A14) = 15.
// Total = 1 (A0) + drivers.length (A1..A14, A23) = 16. Plan 01-14
// appended A23 after A14 — the running count adapts via `drivers.length`
// so no manual update is needed when future plans extend the chain.
const total = drivers.length + 1;
const finalPassed = passedCount + 1; // +1 for A0 (we already passed it to reach here)

View File

@@ -993,6 +993,33 @@ export async function driveA14(page: Page): Promise<AssertionRecord> {
}) as AssertionRecord;
}
/* ─── Plan 01-14 — driveA23 (monitorTypeSurfaces picker-narrowing) ─── */
/**
* Drive A23 (Plan 01-14 picker-narrowing constraint verification).
* Standard page.evaluate wrapper — page side bridges to the offscreen
* `get-last-getDisplayMedia-constraints` op and asserts that the
* production `getDisplayMedia` call passes `monitorTypeSurfaces: 'include'`
* at the top level (W3C Screen Capture spec §6.1; Chrome ≥ 119 picker-
* narrowing semantics — only monitor surfaces are offered, no Window/
* Chrome-Tab panes).
*
* Chains AFTER driveA14 in the orchestrator. Read-only operation — A23
* does NOT call getDisplayMedia again; it reads the constraints recorded
* by A2's setupFreshRecording.
*
* @param page - The harness page from `launchHarnessBrowser`.
* @returns Structured AssertionRecord with 2 checks (A23.1 non-null + A23.2 monitorTypeSurfaces value).
*/
export async function driveA23(page: Page): Promise<AssertionRecord> {
return await page.evaluate(async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- evaluate runs in browser context where Window types are loose.
const harness = (window as any).__mokoshHarness;
const r: AssertionRecord = await harness.assertA23();
return r;
}) as AssertionRecord;
}
// Note (Wave 3D): the AssertionWithBytes interface is retained at the
// top of this file as a public export — but Wave 3D's drivers no
// longer use it (the host side now does all bytes-handling internally