refactor(observation): internalize capture budgets
This commit is contained in:
@@ -12,19 +12,21 @@ describeBrowser("CdpBrowserProvider: document script 1", () => {
|
||||
it("captures bounded accessibility text only after independent approval", async () => {
|
||||
const browser = await startFakeCdpBrowser();
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_accessibility_text: true,
|
||||
limits: {
|
||||
max_ax_text_field_bytes: 6,
|
||||
max_total_ax_text_bytes: 6,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const request = inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_accessibility_text: true,
|
||||
});
|
||||
const result = await new CdpBrowserProvider().inspectPage({
|
||||
...request,
|
||||
limits: {
|
||||
...request.limits,
|
||||
max_ax_text_field_bytes: 6,
|
||||
max_total_ax_text_bytes: 6,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.accessibility).toMatchObject({
|
||||
@@ -333,29 +335,31 @@ describeBrowser("CdpBrowserProvider: document script 3", () => {
|
||||
it("reports configured truncation without over-reading DOM or script source", async () => {
|
||||
const browser = await startFakeCdpBrowser();
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_script_sources: true,
|
||||
limits: {
|
||||
max_frames: 1,
|
||||
max_dom_nodes: 1,
|
||||
max_ax_nodes: 1,
|
||||
max_scripts: 1,
|
||||
max_resources: 1,
|
||||
max_workers: 1,
|
||||
max_storage_keys: 1,
|
||||
max_script_source_bytes: 10,
|
||||
max_total_script_source_bytes: 10,
|
||||
max_network_events: 1,
|
||||
max_console_events: 1,
|
||||
max_websocket_events: 1,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const request = inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_script_sources: true,
|
||||
});
|
||||
const result = await new CdpBrowserProvider().inspectPage({
|
||||
...request,
|
||||
limits: {
|
||||
...request.limits,
|
||||
max_frames: 1,
|
||||
max_dom_nodes: 1,
|
||||
max_ax_nodes: 1,
|
||||
max_scripts: 1,
|
||||
max_resources: 1,
|
||||
max_workers: 1,
|
||||
max_storage_keys: 1,
|
||||
max_script_source_bytes: 10,
|
||||
max_total_script_source_bytes: 10,
|
||||
max_network_events: 1,
|
||||
max_console_events: 1,
|
||||
max_websocket_events: 1,
|
||||
},
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.completeness).toMatchObject({
|
||||
status: "truncated",
|
||||
@@ -377,29 +381,31 @@ describeBrowser("CdpBrowserProvider: document script 4", () => {
|
||||
it("bounds frames, resources, workers, accessibility, and storage inventories", async () => {
|
||||
const browser = await startFakeCdpBrowser({ extraCollections: true });
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_storage_keys: true,
|
||||
limits: {
|
||||
max_frames: 1,
|
||||
max_dom_nodes: 2,
|
||||
max_ax_nodes: 1,
|
||||
max_scripts: 1,
|
||||
max_resources: 1,
|
||||
max_workers: 1,
|
||||
max_storage_keys: 1,
|
||||
max_script_source_bytes: 10,
|
||||
max_total_script_source_bytes: 10,
|
||||
max_network_events: 1,
|
||||
max_console_events: 1,
|
||||
max_websocket_events: 1,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const request = inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_storage_keys: true,
|
||||
});
|
||||
const result = await new CdpBrowserProvider().inspectPage({
|
||||
...request,
|
||||
limits: {
|
||||
...request.limits,
|
||||
max_frames: 1,
|
||||
max_dom_nodes: 2,
|
||||
max_ax_nodes: 1,
|
||||
max_scripts: 1,
|
||||
max_resources: 1,
|
||||
max_workers: 1,
|
||||
max_storage_keys: 1,
|
||||
max_script_source_bytes: 10,
|
||||
max_total_script_source_bytes: 10,
|
||||
max_network_events: 1,
|
||||
max_console_events: 1,
|
||||
max_websocket_events: 1,
|
||||
},
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.completeness).toMatchObject({
|
||||
status: "truncated",
|
||||
|
||||
@@ -251,25 +251,27 @@ describeBrowser("CdpBrowserProvider: sensitive data 3", () => {
|
||||
it("reports independent sensitive-capture truncation at aggregate byte limits", async () => {
|
||||
const browser = await startFakeCdpBrowser({ sensitiveShapes: true });
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_console_text: true,
|
||||
include_json_body_shapes: true,
|
||||
include_websocket_shapes: true,
|
||||
limits: {
|
||||
max_console_text_field_bytes: 5,
|
||||
max_total_console_text_bytes: 5,
|
||||
max_json_body_bytes: 10,
|
||||
max_total_json_body_bytes: 10,
|
||||
max_websocket_shape_bytes: 5,
|
||||
max_total_websocket_shape_bytes: 5,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const request = inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_console_text: true,
|
||||
include_json_body_shapes: true,
|
||||
include_websocket_shapes: true,
|
||||
});
|
||||
const result = await new CdpBrowserProvider().inspectPage({
|
||||
...request,
|
||||
limits: {
|
||||
...request.limits,
|
||||
max_console_text_field_bytes: 5,
|
||||
max_total_console_text_bytes: 5,
|
||||
max_json_body_bytes: 10,
|
||||
max_total_json_body_bytes: 10,
|
||||
max_websocket_shape_bytes: 5,
|
||||
max_total_websocket_shape_bytes: 5,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.console.events[0]?.text_capture).toEqual({
|
||||
|
||||
@@ -18,6 +18,7 @@ import type {
|
||||
JavaScriptRuntimeObservation,
|
||||
ObserveJavaScriptRuntimeInput,
|
||||
} from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { observeJavaScriptRuntimeToolInputSchema } from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { javascriptRuntimeReconciliationResultSchema } from "../../../src/domain/javascriptRuntimeReconciliationSchemas.js";
|
||||
import type {
|
||||
PermissionCeiling,
|
||||
@@ -27,6 +28,18 @@ import { startFakeV8Inspector } from "../../fixtures/fakeV8Inspector.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("passive V8 Inspector provider", () => {
|
||||
test("keeps collection budgets out of the caller schema", () => {
|
||||
expect(
|
||||
observeJavaScriptRuntimeToolInputSchema.safeParse({
|
||||
inspector_endpoint: "http://127.0.0.1:9229",
|
||||
allowed_file_roots: ["/tmp/app"],
|
||||
allowed_origins: [],
|
||||
target_id: "target-1",
|
||||
limits: {},
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test("returns every approved Inspector target inline", async () => {
|
||||
const fixture = await runtimeFixture();
|
||||
const fake = await startFakeV8Inspector({
|
||||
|
||||
@@ -9,6 +9,7 @@ import { afterEach, describe, expect, test } from "vitest";
|
||||
import { loadConfiguredPermissionAuthority } from "../../../src/application/PermissionConfiguration.js";
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/JavaScriptRuntimeObservationService.js";
|
||||
import { V8InspectorProvider } from "../../../src/browser/V8InspectorProvider.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { parseConfig } from "../../../src/config.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/fakeV8Inspector.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
@@ -93,21 +94,14 @@ describe("JavaScript runtime observation CLI parity", () => {
|
||||
const direct = await observeJavaScriptRuntime(
|
||||
new V8InspectorProvider(),
|
||||
authority.value,
|
||||
{
|
||||
observeJavaScriptRuntimeInputSchema.parse({
|
||||
inspector_endpoint: inspector.endpoint,
|
||||
allowed_file_roots: [root],
|
||||
allowed_origins: [],
|
||||
target_id: inspector.targetId,
|
||||
runtime_kind: "node",
|
||||
observation_ms: 10,
|
||||
limits: {
|
||||
max_events: 10_000,
|
||||
max_scripts: 2_000,
|
||||
max_execution_contexts: 1_000,
|
||||
max_location_bytes: 16_384,
|
||||
max_total_metadata_bytes: 4_194_304,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(direct.ok).toBe(true);
|
||||
if (direct.ok)
|
||||
|
||||
@@ -9,6 +9,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { loadConfiguredPermissionAuthority } from "../../../src/application/PermissionConfiguration.js";
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/JavaScriptRuntimeObservationService.js";
|
||||
import { V8InspectorProvider } from "../../../src/browser/V8InspectorProvider.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { parseConfig } from "../../../src/config.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
@@ -118,21 +119,14 @@ describe("JavaScript runtime observation MCP tools", () => {
|
||||
const direct = await observeJavaScriptRuntime(
|
||||
new V8InspectorProvider(),
|
||||
authority.value,
|
||||
{
|
||||
observeJavaScriptRuntimeInputSchema.parse({
|
||||
inspector_endpoint: inspector.endpoint,
|
||||
allowed_file_roots: [root],
|
||||
allowed_origins: [],
|
||||
target_id: inspector.targetId,
|
||||
runtime_kind: "node",
|
||||
observation_ms: 10,
|
||||
limits: {
|
||||
max_events: 10_000,
|
||||
max_scripts: 2_000,
|
||||
max_execution_contexts: 1_000,
|
||||
max_location_bytes: 16_384,
|
||||
max_total_metadata_bytes: 4_194_304,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(direct.ok).toBe(true);
|
||||
if (direct.ok) expect(evidenceId).toBe(direct.value.evidence_id);
|
||||
|
||||
Reference in New Issue
Block a user