refactor(observation): internalize capture budgets

This commit is contained in:
morluto
2026-09-29 12:16:10 +08:00
parent 8c24272ee7
commit 7b3c797237
24 changed files with 202 additions and 466 deletions
-84
View File
@@ -15,13 +15,6 @@ export const boundedCount = (
.default(fallback)
.describe(`Maximum ${subject}`);
/** Bound a CLI observation byte budget. */
export const boundedBytes = (
subject: string,
maximum: number,
fallback: number,
) => boundedCount(`${subject} in bytes`, maximum, fallback);
/** Shared passive browser origin options. */
export const browserScopeOptions = {
allowedOrigins: z
@@ -68,68 +61,6 @@ export const browserPageInspectionOptions = z.object({
.boolean()
.default(false)
.describe("Include content-derived storage fingerprints"),
maxFrames: boundedCount("page frames", 1_000, 200),
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
maxAxNodes: boundedCount("accessibility nodes", 10_000, 2_000),
maxAxTextFieldBytes: boundedBytes(
"one accessibility text field",
16 * 1_024,
1_024,
),
maxTotalAxTextBytes: boundedBytes(
"total accessibility text",
1_024 * 1_024,
64 * 1_024,
),
maxScripts: boundedCount("scripts", 1_000, 200),
maxResources: boundedCount("resources", 10_000, 2_000),
maxWorkers: boundedCount("workers", 5_000, 500),
maxStorageKeys: boundedCount("storage keys", 10_000, 1_000),
maxScriptSourceBytes: boundedBytes(
"one script source",
4 * 1_024 * 1_024,
1_024 * 1_024,
),
maxTotalScriptSourceBytes: boundedBytes(
"total script source",
16 * 1_024 * 1_024,
4 * 1_024 * 1_024,
),
maxNetworkEvents: boundedCount("network events", 10_000, 1_000),
maxConsoleEvents: boundedCount("console events", 2_000, 200),
maxConsoleTextFieldBytes: boundedBytes(
"one console text field",
16 * 1_024,
1_024,
),
maxTotalConsoleTextBytes: boundedBytes(
"total console text",
1_024 * 1_024,
64 * 1_024,
),
maxJsonBodyBytes: boundedBytes(
"one JSON response body",
4 * 1_024 * 1_024,
1_024 * 1_024,
),
maxTotalJsonBodyBytes: boundedBytes(
"total JSON response bodies",
16 * 1_024 * 1_024,
4 * 1_024 * 1_024,
),
maxJsonShapeNodes: boundedCount("JSON shape nodes", 100_000, 5_000),
maxJsonShapeDepth: boundedCount("JSON shape depth", 100, 20),
maxWebsocketEvents: boundedCount("WebSocket events", 5_000, 500),
maxWebsocketShapeBytes: boundedBytes(
"one WebSocket shape",
1_024 * 1_024,
64 * 1_024,
),
maxTotalWebsocketShapeBytes: boundedBytes(
"total WebSocket shapes",
16 * 1_024 * 1_024,
1_024 * 1_024,
),
});
/** Shared passive Electron root options. */
@@ -152,21 +83,6 @@ export const electronPageInspectionOptions = z.object({
.boolean()
.default(false)
.describe("Include bounded JavaScript source text"),
maxFrames: boundedCount("page frames", 1_000, 200),
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
maxScripts: boundedCount("scripts", 2_000, 500),
maxResources: boundedCount("resources", 10_000, 2_000),
maxWorkers: boundedCount("workers", 5_000, 500),
maxScriptSourceBytes: boundedBytes(
"one captured script source",
4 * 1_024 * 1_024,
1_024 * 1_024,
),
maxTotalScriptSourceBytes: boundedBytes(
"total captured script source",
16 * 1_024 * 1_024,
4 * 1_024 * 1_024,
),
});
export const javascriptApplicationOptions = z.object({