Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49ada44d9b | ||
|
|
64041e3072 | ||
|
|
39f96d7188 | ||
|
|
1ed755ac60 | ||
|
|
bfcc9526a3 | ||
|
|
a742936108 | ||
|
|
82bcf0814d | ||
|
|
474b34c570 | ||
|
|
de1d3f2a24 | ||
|
|
0e92dd8e60 | ||
|
|
d32287ebf6 |
@@ -186,6 +186,28 @@ describe("analysis provider registry: binding failures and cancellation", () =>
|
|||||||
expect(explicit.error.reason).toBe("target_unsupported");
|
expect(explicit.error.reason).toBe("target_unsupported");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("rejects an unknown environment preference even when every candidate rejects the target", async () => {
|
||||||
|
const alpha = candidate("alpha");
|
||||||
|
const misconfigured = new AnalysisProviderRegistry(
|
||||||
|
[alpha.provider],
|
||||||
|
"missing",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const selected of [
|
||||||
|
await misconfigured.select(ARTIFACT_TARGET),
|
||||||
|
await misconfigured.select(ARTIFACT_TARGET, "missing"),
|
||||||
|
]) {
|
||||||
|
if (selected.ok) throw new Error("expected unknown provider rejection");
|
||||||
|
expect(projectAnalysisError(selected.error)).toMatchObject({
|
||||||
|
details: {
|
||||||
|
selection_reason: "unknown_provider",
|
||||||
|
requested_provider_id: "missing",
|
||||||
|
candidate_ids: ["alpha"],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("does not bind a profile with unresolved version or adapter failure", async () => {
|
it("does not bind a profile with unresolved version or adapter failure", async () => {
|
||||||
const unresolved = candidate("unresolved", { profile: "missing" });
|
const unresolved = candidate("unresolved", { profile: "missing" });
|
||||||
const failed = candidate("failed", { profile: "error" });
|
const failed = candidate("failed", { profile: "error" });
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ export class AnalysisProviderRegistry {
|
|||||||
return err(new AnalysisCancelledError("open_binary"));
|
return err(new AnalysisCancelledError("open_binary"));
|
||||||
if (
|
if (
|
||||||
request === undefined &&
|
request === undefined &&
|
||||||
selector !== "auto" &&
|
this.#byId.has(selector) &&
|
||||||
baseline.length > 0 &&
|
baseline.length > 0 &&
|
||||||
baseline.every(
|
baseline.every(
|
||||||
({ targetSupport }) => targetSupport.status === "unsupported",
|
({ targetSupport }) => targetSupport.status === "unsupported",
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ import {
|
|||||||
type WebScreenshotDiff,
|
type WebScreenshotDiff,
|
||||||
} from "../domain/webScreenshot.js";
|
} from "../domain/webScreenshot.js";
|
||||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
import {
|
||||||
|
AnalysisCancelledError,
|
||||||
|
AnalysisInputError,
|
||||||
|
} from "../domain/analysisErrorCore.js";
|
||||||
import { BrowserObservationError } from "../domain/browserObservationError.js";
|
import { BrowserObservationError } from "../domain/browserObservationError.js";
|
||||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||||
import type { BrowserObservationOperation } from "../domain/browserObservationErrors.js";
|
import type { BrowserObservationOperation } from "../domain/browserObservationErrors.js";
|
||||||
@@ -164,6 +167,8 @@ export class CdpBrowserProvider implements BrowserObservationPort {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
|
if (options.signal?.aborted === true)
|
||||||
|
return err(new AnalysisCancelledError("analyze_web_bundle", { cause }));
|
||||||
return err(providerError(cause, "analyze_web_bundle"));
|
return err(providerError(cause, "analyze_web_bundle"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,6 +340,10 @@ const withTargetSession = async <
|
|||||||
);
|
);
|
||||||
// An unadopted browser socket is closed here; closing is idempotent.
|
// An unadopted browser socket is closed here; closing is idempotent.
|
||||||
await endpoint.connection?.close();
|
await endpoint.connection?.close();
|
||||||
|
// Cleanup can observe an interrupt after work returns. Do not publish its
|
||||||
|
// result once cancellation arrived while the target session was closing.
|
||||||
|
if (options.signal?.aborted === true)
|
||||||
|
throw new AnalysisCancelledError(operation);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,21 @@ it("excludes structural auth material and explicit normalized values without gue
|
|||||||
expect(traces[0]?.incomplete_fact_records).toContain(2);
|
expect(traces[0]?.incomplete_fact_records).toContain(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("omits a hidden derived total for a stream with more contributions than call arguments allow", () => {
|
||||||
|
const events = Array.from({ length: 130 }, (_, index) =>
|
||||||
|
event(
|
||||||
|
Array.from({ length: 1_000 }, (_, offset) =>
|
||||||
|
frame(index * 1_000 + offset, 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const { traces } = facts(capture(events), ["130000"]);
|
||||||
|
expect(traces[0]?.streams).toEqual([]);
|
||||||
|
expect(traces[0]?.incomplete_fact_records).toEqual(
|
||||||
|
Array.from({ length: 130 }, (_, ordinal) => ordinal),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("hides marked ancestor keys and safe derived sums while still validating hidden subtrees", () => {
|
it("hides marked ancestor keys and safe derived sums while still validating hidden subtrees", () => {
|
||||||
const text = capture([event([frame(0, 3), frame(3, 4)])]);
|
const text = capture([event([frame(0, 3), frame(3, 4)])]);
|
||||||
expect(facts(text, ["7"]).traces[0]?.streams).toEqual([]);
|
expect(facts(text, ["7"]).traces[0]?.streams).toEqual([]);
|
||||||
|
|||||||
@@ -95,10 +95,10 @@ export const decodeQlogCapture = (
|
|||||||
...stream.reported_final_sizes,
|
...stream.reported_final_sizes,
|
||||||
...stream.covered_ranges.flatMap((r) => [r.start, r.end]),
|
...stream.covered_ranges.flatMap((r) => [r.start, r.end]),
|
||||||
];
|
];
|
||||||
|
// A stream can have more contributions than call arguments allow.
|
||||||
if (numericValues.some(excluded))
|
if (numericValues.some(excluded))
|
||||||
fact.incomplete_fact_records.push(
|
for (const contribution of stream.contributions)
|
||||||
...stream.contributions.map((c) => c.record_ordinal),
|
fact.incomplete_fact_records.push(contribution.record_ordinal);
|
||||||
);
|
|
||||||
else fact.streams.push(stream);
|
else fact.streams.push(stream);
|
||||||
}
|
}
|
||||||
fact.incomplete_fact_records = [...new Set(fact.incomplete_fact_records)];
|
fact.incomplete_fact_records = [...new Set(fact.incomplete_fact_records)];
|
||||||
|
|||||||
@@ -7,12 +7,205 @@ import {
|
|||||||
} from "../../../src/domain/browserObservation.js";
|
} from "../../../src/domain/browserObservation.js";
|
||||||
import { analyzeWebBundleInputSchema } from "../../../src/domain/webBundleAnalysis.js";
|
import { analyzeWebBundleInputSchema } from "../../../src/domain/webBundleAnalysis.js";
|
||||||
import { observeWebSessionInputSchema } from "../../../src/domain/browserSession.js";
|
import { observeWebSessionInputSchema } from "../../../src/domain/browserSession.js";
|
||||||
|
import { discoverWebMcpToolsInputSchema } from "../../../src/domain/webMcpDiscovery.js";
|
||||||
|
import { captureWebScreenshotInputSchema } from "../../../src/domain/webScreenshot.js";
|
||||||
import {
|
import {
|
||||||
startFakeCdpBrowser,
|
startFakeCdpBrowser,
|
||||||
type FakeCdpBrowser,
|
type FakeCdpBrowser,
|
||||||
} from "../../fixtures/fakeCdpBrowser.js";
|
} from "../../fixtures/fakeCdpBrowser.js";
|
||||||
import { trackBrowser } from "./cdpBrowserProvider.support.js";
|
import { trackBrowser } from "./cdpBrowserProvider.support.js";
|
||||||
|
|
||||||
|
const waitFor = async (ready: () => boolean, description: string) => {
|
||||||
|
const deadline = Date.now() + 5_000;
|
||||||
|
while (!ready()) {
|
||||||
|
if (Date.now() > deadline) throw new Error(description);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("CdpBrowserProvider: cancellation during cleanup", () => {
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
name: "WebMCP discovery",
|
||||||
|
operation: "discover_webmcp_tools",
|
||||||
|
invoke: (
|
||||||
|
provider: CdpBrowserProvider,
|
||||||
|
browser: FakeCdpBrowser,
|
||||||
|
signal: AbortSignal,
|
||||||
|
) =>
|
||||||
|
provider.discoverWebMcpTools(
|
||||||
|
discoverWebMcpToolsInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
observation_ms: 0,
|
||||||
|
}),
|
||||||
|
{ signal },
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "screenshot capture",
|
||||||
|
operation: "capture_web_screenshot",
|
||||||
|
invoke: (
|
||||||
|
provider: CdpBrowserProvider,
|
||||||
|
browser: FakeCdpBrowser,
|
||||||
|
signal: AbortSignal,
|
||||||
|
) =>
|
||||||
|
provider.captureScreenshot(
|
||||||
|
captureWebScreenshotInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
}),
|
||||||
|
{ signal },
|
||||||
|
),
|
||||||
|
},
|
||||||
|
])(
|
||||||
|
"reports cancellation during $name cleanup",
|
||||||
|
async ({ operation, invoke }) => {
|
||||||
|
const browser = await startFakeCdpBrowser({
|
||||||
|
hangOnMethod: "Page.disable",
|
||||||
|
webMcpTools: true,
|
||||||
|
});
|
||||||
|
trackBrowser(browser);
|
||||||
|
const controller = new AbortController();
|
||||||
|
const pending = invoke(
|
||||||
|
new CdpBrowserProvider(),
|
||||||
|
browser,
|
||||||
|
controller.signal,
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() => browser.commands.some(({ method }) => method === "Page.disable"),
|
||||||
|
"page cleanup did not start",
|
||||||
|
);
|
||||||
|
controller.abort();
|
||||||
|
await expect(pending).resolves.toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: { _tag: "AnalysisCancelledError", operation },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it("reports cancellation when an interrupt arrives during page cleanup", async () => {
|
||||||
|
const browser = await startFakeCdpBrowser({
|
||||||
|
hangOnMethod: "Network.disable",
|
||||||
|
});
|
||||||
|
trackBrowser(browser);
|
||||||
|
const controller = new AbortController();
|
||||||
|
const pending = new CdpBrowserProvider().inspectPage(
|
||||||
|
inspectWebPageInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
observation_ms: 0,
|
||||||
|
}),
|
||||||
|
{ signal: controller.signal },
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() => browser.commands.some(({ method }) => method === "Network.disable"),
|
||||||
|
"page cleanup did not start",
|
||||||
|
);
|
||||||
|
controller.abort();
|
||||||
|
|
||||||
|
await expect(pending).resolves.toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: {
|
||||||
|
_tag: "AnalysisCancelledError",
|
||||||
|
operation: "inspect_web_page",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports cancellation when an interrupt arrives during session cleanup", async () => {
|
||||||
|
const browser = await startFakeCdpBrowser({
|
||||||
|
hangOnMethod: "Network.disable",
|
||||||
|
});
|
||||||
|
trackBrowser(browser);
|
||||||
|
const controller = new AbortController();
|
||||||
|
const pending = new CdpBrowserProvider().observeSession(
|
||||||
|
observeWebSessionInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
observation_ms: 1,
|
||||||
|
}),
|
||||||
|
{ signal: controller.signal },
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() => browser.commands.some(({ method }) => method === "Network.disable"),
|
||||||
|
"session cleanup did not start",
|
||||||
|
);
|
||||||
|
controller.abort();
|
||||||
|
|
||||||
|
await expect(pending).resolves.toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: {
|
||||||
|
_tag: "AnalysisCancelledError",
|
||||||
|
operation: "observe_web_session",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports cancellation when an interrupt arrives during source-map download", async () => {
|
||||||
|
const browser = await startFakeCdpBrowser({ hangSourceMap: true });
|
||||||
|
trackBrowser(browser);
|
||||||
|
const controller = new AbortController();
|
||||||
|
const pending = new CdpBrowserProvider().analyzeBundle(
|
||||||
|
analyzeWebBundleInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
observation_ms: 0,
|
||||||
|
fetch_source_maps: true,
|
||||||
|
}),
|
||||||
|
{ signal: controller.signal },
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() =>
|
||||||
|
browser.httpRequests.some(({ url }) => url.startsWith("/app.js.map")),
|
||||||
|
"source-map download did not start",
|
||||||
|
);
|
||||||
|
controller.abort();
|
||||||
|
|
||||||
|
await expect(pending).resolves.toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: {
|
||||||
|
_tag: "AnalysisCancelledError",
|
||||||
|
operation: "analyze_web_bundle",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("classifies custom source-map abort reasons as cancellation", async () => {
|
||||||
|
const browser = await startFakeCdpBrowser({ hangSourceMap: true });
|
||||||
|
trackBrowser(browser);
|
||||||
|
const controller = new AbortController();
|
||||||
|
const pending = new CdpBrowserProvider().analyzeBundle(
|
||||||
|
analyzeWebBundleInputSchema.parse({
|
||||||
|
cdp_endpoint: browser.endpoint,
|
||||||
|
allowed_origins: [browser.allowedOrigin],
|
||||||
|
target_id: "allowed-page",
|
||||||
|
observation_ms: 0,
|
||||||
|
fetch_source_maps: true,
|
||||||
|
}),
|
||||||
|
{ signal: controller.signal },
|
||||||
|
);
|
||||||
|
await waitFor(
|
||||||
|
() =>
|
||||||
|
browser.httpRequests.some(({ url }) => url.startsWith("/app.js.map")),
|
||||||
|
"source-map download did not start",
|
||||||
|
);
|
||||||
|
controller.abort(new Error("stopped"));
|
||||||
|
await expect(pending).resolves.toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: {
|
||||||
|
_tag: "AnalysisCancelledError",
|
||||||
|
operation: "analyze_web_bundle",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("CdpBrowserProvider: cancellation and session events", () => {
|
describe("CdpBrowserProvider: cancellation and session events", () => {
|
||||||
it("honors cancellation during the final progress callback before publishing inspection", async () => {
|
it("honors cancellation during the final progress callback before publishing inspection", async () => {
|
||||||
const browser = await startFakeCdpBrowser();
|
const browser = await startFakeCdpBrowser();
|
||||||
|
|||||||
@@ -73,7 +73,13 @@ it("releases cleanup when cancellation arrives after capture completes", async (
|
|||||||
});
|
});
|
||||||
controller.abort();
|
controller.abort();
|
||||||
const result = await pending;
|
const result = await pending;
|
||||||
expect(result.ok).toBe(true);
|
expect(result).toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: {
|
||||||
|
_tag: "AnalysisCancelledError",
|
||||||
|
operation: "observe_web_session",
|
||||||
|
},
|
||||||
|
});
|
||||||
expect(browser.commands.map(({ method }) => method)).toContain(
|
expect(browser.commands.map(({ method }) => method)).toContain(
|
||||||
"Target.detachFromTarget",
|
"Target.detachFromTarget",
|
||||||
);
|
);
|
||||||
|
|||||||
Vendored
+5
@@ -229,6 +229,11 @@ const serveSourceMap = (
|
|||||||
response: ServerResponse,
|
response: ServerResponse,
|
||||||
options: FakeOptions,
|
options: FakeOptions,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
|
if (
|
||||||
|
options.hangSourceMap === true &&
|
||||||
|
request.url?.startsWith("/app.js.map") === true
|
||||||
|
)
|
||||||
|
return true;
|
||||||
if (options.sourceMapBody === undefined) return false;
|
if (options.sourceMapBody === undefined) return false;
|
||||||
if (request.url?.startsWith("/app.js.map") === true) {
|
if (request.url?.startsWith("/app.js.map") === true) {
|
||||||
if (options.sourceMapRedirect !== undefined)
|
if (options.sourceMapRedirect !== undefined)
|
||||||
|
|||||||
+2
@@ -95,6 +95,8 @@ export interface FakeOptions {
|
|||||||
readonly webSocketWithoutFrames?: boolean;
|
readonly webSocketWithoutFrames?: boolean;
|
||||||
readonly invalidBinaryWebSocketEvent?: boolean;
|
readonly invalidBinaryWebSocketEvent?: boolean;
|
||||||
readonly sourceMapBody?: string;
|
readonly sourceMapBody?: string;
|
||||||
|
/** Accept a source-map request and leave the response open. */
|
||||||
|
readonly hangSourceMap?: boolean;
|
||||||
readonly sourceMapRedirect?: string;
|
readonly sourceMapRedirect?: string;
|
||||||
readonly sessionTimeline?:
|
readonly sessionTimeline?:
|
||||||
| "same_origin"
|
| "same_origin"
|
||||||
|
|||||||
Reference in New Issue
Block a user