* feat(browser): attribute native execution and listener sources Integrate finite native precise-coverage windows and direct DOM listener inspection through shared CLI/MCP workflows, exact session script identities, inline source evidence and owned instrumentation cleanup. Refs #881, #774 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): preserve runtime identity and settle fixture cleanup Retain complete reported initiator objects, reject changing loader availability, propagate the selected operation through main-frame authorization and complete effect/help inventories. Close only the synthetic owned Chrome via its native endpoint, await process-group settlement and preserve primary verification errors during cleanup. Refs #881 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): settle invalid events and preserve document evidence Accept same-document URL changes with proven stable loader identity, retain metadata without inventing ownership, terminate malformed event collection immediately, and sanitize known transport URLs without erasing sourceURL declarations. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): end detached target windows and sanitize coverage identities Reuse the existing flat-session event matcher, retain prearming termination, and apply the source identity policy to coverage URLs. Add real MCP target-close verification and producer regressions for detachment orderings. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): retain final sample metadata and settle fatal protocol failures Keep source inventory open through the resetting sample, propagate fatal wire failures without outstanding commands, and check listener collection failures after final document validation. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): require default execution worlds for website attribution Preserve native context and world metadata without treating same-frame isolated or unknown contexts as website sources. Verify actual Chrome isolated function execution before excluding its coverage, and cover ambiguous world metadata with producer regressions. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): revalidate runtime source joins and selector failures Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
141 lines
4.9 KiB
TypeScript
141 lines
4.9 KiB
TypeScript
import { describe, expect, it, onTestFinished } from "vitest";
|
|
import { CdpWebRuntimeProvider } from "../../../src/browser/execution/CdpWebRuntimeProvider.js";
|
|
import type { CdpEvent } from "../../../src/browser/CdpConnection.js";
|
|
import { observeWebExecutionInputSchema } from "../../../src/domain/webExecution.js";
|
|
import { inspectWebEventListenersInputSchema } from "../../../src/domain/webEventListeners.js";
|
|
import { startRuntimeBrowser } from "../../fixtures/webRuntime.js";
|
|
|
|
describe("runtime final collection boundaries", () => {
|
|
it("retains a script parsed during the final resetting coverage command", async () => {
|
|
let emitEvent: ((event: CdpEvent) => void) | undefined;
|
|
const browser = await startRuntimeBrowser({
|
|
commandResult: (command, origin) => {
|
|
if (command.method === "Profiler.takePreciseCoverage") {
|
|
emitEvent?.({
|
|
method: "Debugger.scriptParsed",
|
|
sessionId: "session-1",
|
|
params: {
|
|
scriptId: "late-script",
|
|
url: `${origin}/late.js`,
|
|
executionContextId: 1,
|
|
executionContextAuxData: { frameId: "runtime-main" },
|
|
startLine: 0,
|
|
startColumn: 0,
|
|
endLine: 0,
|
|
endColumn: 1,
|
|
},
|
|
});
|
|
return {
|
|
timestamp: 12,
|
|
result: [
|
|
{
|
|
scriptId: "late-script",
|
|
url: `${origin}/late.js`,
|
|
functions: [
|
|
{
|
|
functionName: "late",
|
|
isBlockCoverage: true,
|
|
ranges: [{ startOffset: 0, endOffset: 1, count: 1 }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (
|
|
command.method === "Debugger.getScriptSource" &&
|
|
command.params.scriptId === "late-script"
|
|
)
|
|
return { scriptSource: ";" };
|
|
return undefined;
|
|
},
|
|
});
|
|
emitEvent = browser.emitEvent;
|
|
onTestFinished(() => browser.close());
|
|
const result = await new CdpWebRuntimeProvider().observeExecution(
|
|
observeWebExecutionInputSchema.parse({
|
|
cdp_endpoint: browser.endpoint,
|
|
target_id: "allowed-page",
|
|
observation_ms: 5,
|
|
}),
|
|
);
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.coverage.scripts[0]).toMatchObject({
|
|
script_id: "late-script",
|
|
functions: [{ ranges: [{ count: 1, source_bounds: "verified" }] }],
|
|
});
|
|
expect(
|
|
result.value.sources.find(({ script_id }) => script_id === "late-script")
|
|
?.source,
|
|
).toMatchObject({ state: "captured", text: ";" });
|
|
expect(result.value.coverage.excluded_scripts).toBe(0);
|
|
});
|
|
|
|
it.each(["#selected", "#missing"])(
|
|
"rejects known malformed source metadata during final listener assertion for %s",
|
|
async (selector) => {
|
|
let emitEvent: ((event: CdpEvent) => void) | undefined;
|
|
const browser = await startRuntimeBrowser({
|
|
commandResult: (command, _origin, reads) => {
|
|
if (command.method === "Page.getFrameTree" && reads === 3)
|
|
emitEvent?.({
|
|
method: "Debugger.scriptParsed",
|
|
sessionId: "session-1",
|
|
params: {},
|
|
});
|
|
return undefined;
|
|
},
|
|
});
|
|
emitEvent = browser.emitEvent;
|
|
onTestFinished(() => browser.close());
|
|
const result = await new CdpWebRuntimeProvider().inspectEventListeners(
|
|
inspectWebEventListenersInputSchema.parse({
|
|
cdp_endpoint: browser.endpoint,
|
|
target_id: "allowed-page",
|
|
selector,
|
|
}),
|
|
);
|
|
if (result.ok)
|
|
throw new Error(
|
|
"Known producer failure cannot return partial listener success",
|
|
);
|
|
expect(result.error._tag).toBe("AnalysisOutputError");
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("runtime fatal protocol stream", () => {
|
|
it.each(["{not-json", JSON.stringify({ method: 42 })])(
|
|
"stops an armed command-free window on malformed wire data %s",
|
|
async (message) => {
|
|
const browser = await startRuntimeBrowser();
|
|
onTestFinished(() => browser.close());
|
|
const result = await new CdpWebRuntimeProvider().observeExecution(
|
|
observeWebExecutionInputSchema.parse({
|
|
cdp_endpoint: browser.endpoint,
|
|
target_id: "allowed-page",
|
|
observation_ms: 2_147_483_647,
|
|
}),
|
|
{
|
|
signal: AbortSignal.timeout(2_000),
|
|
progress: {
|
|
report: async (update) => {
|
|
if (update.completed === 1) browser.emitRawMessage(message);
|
|
},
|
|
},
|
|
},
|
|
);
|
|
if (result.ok)
|
|
throw new Error(
|
|
"Malformed wire data must not produce successful evidence",
|
|
);
|
|
expect(result.error).toMatchObject({
|
|
cleanupIncomplete: true,
|
|
diagnostics: {
|
|
previous_error: expect.stringMatching(/protocol|malformed/iu),
|
|
},
|
|
});
|
|
},
|
|
);
|
|
});
|