refactor(tools): return complete analysis results inline
This commit is contained in:
@@ -78,8 +78,6 @@ export const analysisErrorCategory = (
|
||||
return "unavailable";
|
||||
if (error instanceof ArtifactOperationError)
|
||||
return artifactErrorCategory(error.reason);
|
||||
if (error instanceof EvidenceFileError && error.reason === "disabled")
|
||||
return "unavailable";
|
||||
if (error instanceof WorkspaceStorageError)
|
||||
return workspaceStorageCategory(error.reason);
|
||||
return STATIC_ERROR_CATEGORIES[error._tag] ?? "execution_failure";
|
||||
@@ -255,14 +253,8 @@ const artifactMessage = (reason: ArtifactOperationError["reason"]): string => {
|
||||
};
|
||||
|
||||
const evidenceFileMessage = (reason: EvidenceFileError["reason"]): string => {
|
||||
if (reason === "disabled")
|
||||
return "Evidence file access is disabled. Enable an evidence directory or use inline evidence.";
|
||||
if (reason === "outside-root")
|
||||
return "Evidence path is outside the allowed directory. Choose a path inside the configured evidence directory.";
|
||||
if (reason === "not-file")
|
||||
return "Evidence path does not point to a file. Choose an evidence file and try again.";
|
||||
if (reason === "too-large")
|
||||
return "Evidence file is too large. Reduce its size and try again.";
|
||||
return "Evidence path does not point to a regular file. Choose a file and try again.";
|
||||
if (reason === "exists")
|
||||
return "Evidence file already exists. Choose another path or allow overwrite.";
|
||||
if (reason === "invalid-json")
|
||||
|
||||
@@ -209,7 +209,7 @@ describe("analysis error projection: caller contract", () => {
|
||||
const projected = projectAnalysisError(
|
||||
new PermissionRequiredError({
|
||||
requested: {
|
||||
capability: "evidence_read",
|
||||
capability: "process_capture",
|
||||
roots: ["/workspace/evidence.json"],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
|
||||
@@ -107,12 +107,10 @@ const artifactOperationCode = (
|
||||
|
||||
const evidenceFileCode = (
|
||||
reason: EvidenceFileError["reason"],
|
||||
): AnalysisErrorProjection["code"] => {
|
||||
if (reason === "outside-root") return "outside_approved_root";
|
||||
if (reason === "too-large") return "truncated";
|
||||
if (reason === "disabled") return "capability_unavailable";
|
||||
return "execution_failure";
|
||||
};
|
||||
): AnalysisErrorProjection["code"] =>
|
||||
reason === "invalid-json"
|
||||
? "evidence_integrity_mismatch"
|
||||
: "execution_failure";
|
||||
|
||||
const workspaceStorageCode = (
|
||||
reason: WorkspaceStorageError["reason"],
|
||||
|
||||
@@ -8,12 +8,12 @@ import { evidenceSchema } from "./evidence.js";
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const pathSchema = z.string().min(1).max(4_096);
|
||||
const pathSchema = z.string().min(1);
|
||||
const componentSchema = z.strictObject({
|
||||
path: pathSchema,
|
||||
artifact_id: z.string().regex(/^art_[a-f0-9]{64}$/u),
|
||||
sha256: digestSchema,
|
||||
format: z.string().min(1).max(100),
|
||||
format: z.string().min(1),
|
||||
});
|
||||
|
||||
/** Authenticated APK inventory pages projected as one Android application. */
|
||||
@@ -64,7 +64,7 @@ export const androidApplicationProjectionResultSchema = z.strictObject({
|
||||
status: z.enum(["complete-within-inventory", "partial"]),
|
||||
inventory_complete: z.boolean(),
|
||||
}),
|
||||
limitations: z.array(z.string().min(1).max(4_096)).max(100),
|
||||
limitations: z.array(z.string().min(1)),
|
||||
});
|
||||
|
||||
export type AndroidApplicationProjectionInput = z.infer<
|
||||
|
||||
@@ -4,7 +4,6 @@ import canonicalize from "canonicalize";
|
||||
import { z } from "zod";
|
||||
|
||||
import { parseArtifactInventoryEvidence } from "./artifactInventoryEvidence.js";
|
||||
import { projectBoundedCartesian } from "./boundedCartesianProjection.js";
|
||||
import { evidenceSchema } from "./evidence.js";
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
@@ -20,12 +19,7 @@ const componentSchema = z.strictObject({
|
||||
|
||||
/** Authenticated artifact inventory pages projected as one Apple application. */
|
||||
export const appleApplicationProjectionInputSchema = z.strictObject({
|
||||
inventory_evidence: z.array(evidenceSchema).min(1).max(100),
|
||||
limits: z
|
||||
.strictObject({
|
||||
max_components: z.number().int().min(1).max(10_000).default(1_000),
|
||||
})
|
||||
.default({ max_components: 1_000 }),
|
||||
inventory_evidence: z.array(evidenceSchema).min(1),
|
||||
});
|
||||
|
||||
/** Deterministic, execution-free Apple application inventory projection. */
|
||||
@@ -33,7 +27,7 @@ export const appleApplicationProjectionResultSchema = z.strictObject({
|
||||
projection_id: z.string().regex(/^aap_[a-f0-9]{64}$/u),
|
||||
root_sha256: digestSchema,
|
||||
root_format: z.literal("ipa"),
|
||||
source_evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
source_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
application_roots: z.array(boundedPathSchema),
|
||||
components: z.strictObject({
|
||||
bundle_metadata: z.array(componentSchema),
|
||||
@@ -66,12 +60,10 @@ export const appleApplicationProjectionResultSchema = z.strictObject({
|
||||
}),
|
||||
),
|
||||
coverage: z.strictObject({
|
||||
status: z.enum(["complete-within-inventory", "partial", "truncated"]),
|
||||
status: z.enum(["complete-within-inventory", "partial"]),
|
||||
inventory_complete: z.boolean(),
|
||||
omitted_components: z.number().int().min(0),
|
||||
omitted_bridge_candidates: z.number().int().min(0),
|
||||
}),
|
||||
limitations: z.array(z.string().min(1).max(4_096)).max(100),
|
||||
limitations: z.array(z.string().min(1).max(4_096)),
|
||||
});
|
||||
|
||||
export type AppleApplicationProjectionInput = z.infer<
|
||||
@@ -123,23 +115,15 @@ export const projectAppleApplication = (
|
||||
),
|
||||
].sort(compare);
|
||||
const classified = classifyComponents(all, roots);
|
||||
const retained = retainComponents(classified, parsed.limits.max_components);
|
||||
const omitted = componentCount(classified) - componentCount(retained);
|
||||
const runtimeFamilies = identifyRuntimeFamilies(all);
|
||||
const bridgeProjection = identifyBridgeCandidates(
|
||||
retained.javascript,
|
||||
classified.javascript,
|
||||
deduplicateComponents([
|
||||
...retained.executables,
|
||||
...retained.native_libraries,
|
||||
...classified.executables,
|
||||
...classified.native_libraries,
|
||||
]),
|
||||
parsed.limits.max_components,
|
||||
);
|
||||
const limitations = projectionLimitations(
|
||||
inventory.complete,
|
||||
omitted,
|
||||
bridgeProjection.omitted,
|
||||
roots,
|
||||
);
|
||||
const limitations = projectionLimitations(inventory.complete, roots);
|
||||
const withoutId = {
|
||||
root_sha256: inventory.manifest.root_sha256,
|
||||
root_format: "ipa" as const,
|
||||
@@ -147,19 +131,14 @@ export const projectAppleApplication = (
|
||||
.map(({ evidence_id: id }) => id)
|
||||
.sort(compare),
|
||||
application_roots: roots,
|
||||
components: retained,
|
||||
components: classified,
|
||||
runtime_families: runtimeFamilies,
|
||||
bridge_candidates: bridgeProjection.candidates,
|
||||
coverage: {
|
||||
status:
|
||||
omitted > 0 || bridgeProjection.omitted > 0
|
||||
? ("truncated" as const)
|
||||
: inventory.complete
|
||||
? ("complete-within-inventory" as const)
|
||||
: ("partial" as const),
|
||||
status: inventory.complete
|
||||
? ("complete-within-inventory" as const)
|
||||
: ("partial" as const),
|
||||
inventory_complete: inventory.complete,
|
||||
omitted_components: omitted,
|
||||
omitted_bridge_candidates: bridgeProjection.omitted,
|
||||
},
|
||||
limitations,
|
||||
};
|
||||
@@ -194,27 +173,6 @@ const classifyComponents = (
|
||||
};
|
||||
};
|
||||
|
||||
const retainComponents = <Groups extends Record<string, readonly Component[]>>(
|
||||
groups: Groups,
|
||||
maximum: number,
|
||||
): { [Key in keyof Groups]: Component[] } => {
|
||||
let remaining = maximum;
|
||||
// SAFETY: the projection preserves every key from Groups and replaces only
|
||||
// each readonly Component array with a bounded mutable Component array.
|
||||
return Object.fromEntries(
|
||||
Object.entries(groups).map(([key, values]) => {
|
||||
const retained = [...values]
|
||||
.sort((left, right) => compare(left.path, right.path))
|
||||
.slice(0, remaining);
|
||||
remaining -= retained.length;
|
||||
return [key, retained];
|
||||
}),
|
||||
) as { [Key in keyof Groups]: Component[] };
|
||||
};
|
||||
|
||||
const componentCount = (groups: Record<string, readonly Component[]>): number =>
|
||||
Object.values(groups).reduce((total, values) => total + values.length, 0);
|
||||
|
||||
const deduplicateComponents = (values: readonly Component[]): Component[] =>
|
||||
[...new Map(values.map((value) => [value.path, value])).values()].sort(
|
||||
(left, right) => compare(left.path, right.path),
|
||||
@@ -257,23 +215,15 @@ const identifyRuntimeFamilies = (all: readonly Component[]) => {
|
||||
const identifyBridgeCandidates = (
|
||||
scripts: readonly Component[],
|
||||
native: readonly Component[],
|
||||
maximum: number,
|
||||
) => {
|
||||
const projection = projectBoundedCartesian(
|
||||
scripts,
|
||||
native,
|
||||
maximum,
|
||||
(script, item) => ({
|
||||
) => ({
|
||||
candidates: scripts.flatMap((script) =>
|
||||
native.map((item) => ({
|
||||
source_path: script.path,
|
||||
native_path: item.path,
|
||||
basis: bridgeBasis(item.path),
|
||||
}),
|
||||
);
|
||||
return {
|
||||
candidates: projection.values,
|
||||
omitted: projection.omitted,
|
||||
};
|
||||
};
|
||||
})),
|
||||
),
|
||||
});
|
||||
|
||||
const bridgeBasis = (
|
||||
path: string,
|
||||
@@ -292,23 +242,11 @@ const bridgeBasis = (
|
||||
|
||||
const projectionLimitations = (
|
||||
complete: boolean,
|
||||
omitted: number,
|
||||
omittedBridges: number,
|
||||
roots: readonly string[],
|
||||
): string[] => [
|
||||
...(!complete
|
||||
? ["Source inventory pages are incomplete; absence is unknown."]
|
||||
: []),
|
||||
...(omitted > 0
|
||||
? [
|
||||
`${String(omitted)} component observations were omitted by the projection limit.`,
|
||||
]
|
||||
: []),
|
||||
...(omittedBridges > 0
|
||||
? [
|
||||
`${String(omittedBridges)} bridge hypotheses were omitted by the projection limit.`,
|
||||
]
|
||||
: []),
|
||||
...(roots.length === 0
|
||||
? [
|
||||
"No Payload/*.app directory was present in the supplied inventory pages.",
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { projectBoundedCartesian } from "./boundedCartesianProjection.js";
|
||||
|
||||
describe("bounded Cartesian projection", () => {
|
||||
it("stops projection work at the output limit", () => {
|
||||
const values = Array.from({ length: 10_000 }, (_, index) => index);
|
||||
let projections = 0;
|
||||
|
||||
const result = projectBoundedCartesian(values, values, 3, (left, right) => {
|
||||
projections += 1;
|
||||
return [left, right] as const;
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
values: [
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
],
|
||||
omitted: 100_000_000 - 3,
|
||||
});
|
||||
expect(projections).toBe(3);
|
||||
});
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
/** Project a Cartesian product without materializing values beyond the output limit. */
|
||||
export const projectBoundedCartesian = <Left, Right, Value>(
|
||||
left: readonly Left[],
|
||||
right: readonly Right[],
|
||||
maximum: number,
|
||||
project: (left: Left, right: Right) => Value,
|
||||
): { readonly values: Value[]; readonly omitted: number } => {
|
||||
const values: Value[] = [];
|
||||
for (const leftValue of left) {
|
||||
for (const rightValue of right) {
|
||||
if (values.length === maximum)
|
||||
return {
|
||||
values,
|
||||
omitted: left.length * right.length - values.length,
|
||||
};
|
||||
values.push(project(leftValue, rightValue));
|
||||
}
|
||||
}
|
||||
return { values, omitted: 0 };
|
||||
};
|
||||
@@ -71,3 +71,97 @@ it("accepts scenarios beyond former action, secret, storage, and replay-route co
|
||||
result.request_replay.mode === "exact" && result.request_replay.routes,
|
||||
).toHaveLength(257);
|
||||
});
|
||||
|
||||
it("accepts complete browser inputs beyond former string length caps", () => {
|
||||
const longValue = "value".repeat(20_000);
|
||||
const longToken = "a".repeat(70_000);
|
||||
const longEnvironmentVariable = "SECRET_A".repeat(10_000);
|
||||
const longPath = `/app/${"segment".repeat(3_000)}`;
|
||||
const result = browserScenarioSchema.parse({
|
||||
browser: {
|
||||
mode: "launch",
|
||||
executable_path: longPath,
|
||||
headless: true,
|
||||
user_data: "temporary-owned",
|
||||
cleanup: "close-and-delete-profile",
|
||||
},
|
||||
start_url: { url: `https://app.example.test${longPath}` },
|
||||
allowed_origins: ["https://app.example.test"],
|
||||
secrets: [
|
||||
{
|
||||
secret_id: longToken,
|
||||
environment_variable: longEnvironmentVariable,
|
||||
purpose: "input",
|
||||
redaction: "replace-with-secret-reference",
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
step_id: longToken,
|
||||
action: "fill",
|
||||
locator: { kind: "css", selector: `#${longValue}` },
|
||||
value: { source: "secret", secret_id: longToken },
|
||||
},
|
||||
],
|
||||
storage: {
|
||||
cookies: [
|
||||
{
|
||||
name: longToken,
|
||||
value: {
|
||||
source: "literal",
|
||||
value: longValue,
|
||||
classification: "public",
|
||||
},
|
||||
destination: { url: "https://app.example.test/" },
|
||||
http_only: false,
|
||||
secure: true,
|
||||
same_site: "Lax",
|
||||
},
|
||||
],
|
||||
},
|
||||
request_replay: {
|
||||
mode: "exact",
|
||||
unmatched: "abort",
|
||||
routes: [
|
||||
{
|
||||
route_id: longToken,
|
||||
method: "GET",
|
||||
request: { url: "https://app.example.test/" },
|
||||
response: {
|
||||
kind: "response",
|
||||
status: 200,
|
||||
headers: [
|
||||
{
|
||||
name: longToken,
|
||||
value: {
|
||||
source: "literal",
|
||||
value: longValue,
|
||||
classification: "public",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.actions[0]?.step_id).toBe(longToken);
|
||||
expect(
|
||||
result.actions[0]?.action === "fill" &&
|
||||
result.actions[0].value.source === "secret"
|
||||
? result.actions[0].value.secret_id
|
||||
: undefined,
|
||||
).toBe(longToken);
|
||||
expect(result.storage.cookies[0]?.name).toBe(longToken);
|
||||
expect(result.secrets[0]?.environment_variable).toBe(longEnvironmentVariable);
|
||||
const replayRoute =
|
||||
result.request_replay.mode === "exact"
|
||||
? result.request_replay.routes[0]
|
||||
: undefined;
|
||||
expect(
|
||||
replayRoute?.response.kind === "response"
|
||||
? replayRoute.response.headers[0]?.name
|
||||
: undefined,
|
||||
).toBe(longToken);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
BROWSER_SCENARIO_CAPTURE_LIMITS,
|
||||
browserScenarioActionSchema,
|
||||
browserScenarioAllowedOriginsSchema,
|
||||
browserScenarioBrowserSchema,
|
||||
@@ -18,7 +17,6 @@ import {
|
||||
} from "./browserScenarioValues.js";
|
||||
|
||||
export {
|
||||
BROWSER_SCENARIO_LIMITS,
|
||||
browserScenarioActionSchema,
|
||||
browserScenarioUrlSchema,
|
||||
browserScenarioValueSchema,
|
||||
@@ -54,14 +52,7 @@ export const browserScenarioInputSchema = z.strictObject({
|
||||
capture: browserScenarioCaptureSchema,
|
||||
});
|
||||
|
||||
const scenarioShapeSchema = browserScenarioInputSchema.transform(
|
||||
(scenario) => ({
|
||||
...scenario,
|
||||
limits: BROWSER_SCENARIO_CAPTURE_LIMITS,
|
||||
}),
|
||||
);
|
||||
|
||||
type ScenarioShape = z.infer<typeof scenarioShapeSchema>;
|
||||
type ScenarioShape = z.infer<typeof browserScenarioInputSchema>;
|
||||
|
||||
const addIssue = (
|
||||
context: z.RefinementCtx,
|
||||
@@ -348,8 +339,8 @@ const validateBrowserScenario = (
|
||||
validateRedactionCoverage(scenario, context);
|
||||
};
|
||||
|
||||
/** Strict provider-neutral contract for one bounded browser capture scenario. */
|
||||
export const browserScenarioSchema = scenarioShapeSchema.superRefine(
|
||||
/** Strict provider-neutral contract for one controlled browser scenario. */
|
||||
export const browserScenarioSchema = browserScenarioInputSchema.superRefine(
|
||||
validateBrowserScenario,
|
||||
);
|
||||
export type BrowserScenario = z.infer<typeof browserScenarioSchema>;
|
||||
|
||||
@@ -6,32 +6,13 @@ import {
|
||||
browserOriginSchema,
|
||||
} from "./browserObservation.js";
|
||||
|
||||
export const BROWSER_SCENARIO_LIMITS = {
|
||||
actionTimeoutMs: 60_000,
|
||||
} as const;
|
||||
|
||||
/** Fixed internal deadlines for provider-owned scenario capture. */
|
||||
export interface BrowserScenarioCaptureLimits {
|
||||
readonly max_duration_ms: number;
|
||||
readonly action_timeout_ms: number;
|
||||
readonly navigation_timeout_ms: number;
|
||||
}
|
||||
|
||||
export const BROWSER_SCENARIO_CAPTURE_LIMITS: BrowserScenarioCaptureLimits =
|
||||
Object.freeze({
|
||||
max_duration_ms: 60_000,
|
||||
action_timeout_ms: 5_000,
|
||||
navigation_timeout_ms: 10_000,
|
||||
});
|
||||
|
||||
export const scenarioIdentifierSchema = z
|
||||
.string()
|
||||
.regex(/^[A-Za-z][A-Za-z0-9._-]{0,63}$/u);
|
||||
.regex(/^[A-Za-z][A-Za-z0-9._-]*$/u);
|
||||
|
||||
const absoluteExecutablePathSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(4_096)
|
||||
.refine(
|
||||
(value) =>
|
||||
value.startsWith("/") ||
|
||||
@@ -43,7 +24,6 @@ const absoluteExecutablePathSchema = z
|
||||
const browserScenarioBaseUrlSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(65_536)
|
||||
.transform((value, context) => {
|
||||
let url: URL;
|
||||
try {
|
||||
@@ -72,7 +52,7 @@ const browserScenarioBaseUrlSchema = z
|
||||
export const browserScenarioValueSchema = z.discriminatedUnion("source", [
|
||||
z.strictObject({
|
||||
source: z.literal("literal"),
|
||||
value: z.string().max(65_536),
|
||||
value: z.string(),
|
||||
classification: z.literal("public"),
|
||||
}),
|
||||
z.strictObject({
|
||||
@@ -83,7 +63,7 @@ export const browserScenarioValueSchema = z.discriminatedUnion("source", [
|
||||
export type BrowserScenarioValue = z.infer<typeof browserScenarioValueSchema>;
|
||||
|
||||
const queryEntrySchema = z.strictObject({
|
||||
name: z.string().min(1).max(256),
|
||||
name: z.string().min(1),
|
||||
value: browserScenarioValueSchema,
|
||||
});
|
||||
|
||||
@@ -105,7 +85,7 @@ export const browserScenarioBrowserSchema = z.discriminatedUnion("mode", [
|
||||
z.strictObject({
|
||||
mode: z.literal("connect"),
|
||||
cdp_endpoint: browserEndpointSchema,
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
target_id: z.string().trim().min(1),
|
||||
ownership: z.literal("external"),
|
||||
cleanup: z.literal("disconnect-only"),
|
||||
}),
|
||||
@@ -123,13 +103,11 @@ export const browserScenarioEnvironmentSchema = z
|
||||
locale: z
|
||||
.string()
|
||||
.min(2)
|
||||
.max(64)
|
||||
.regex(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/u)
|
||||
.default("en-US"),
|
||||
timezone: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(128)
|
||||
.regex(/^[A-Za-z0-9_+-]+(?:\/[A-Za-z0-9_+-]+)*$/u)
|
||||
.default("UTC"),
|
||||
color_scheme: z.enum(["light", "dark", "no-preference"]).default("light"),
|
||||
@@ -151,7 +129,7 @@ export const browserScenarioEnvironmentSchema = z
|
||||
const locatorSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
kind: z.literal("test_id"),
|
||||
value: z.string().min(1).max(512),
|
||||
value: z.string().min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("role"),
|
||||
@@ -171,12 +149,12 @@ const locatorSchema = z.discriminatedUnion("kind", [
|
||||
"tab",
|
||||
"textbox",
|
||||
]),
|
||||
name: z.string().min(1).max(1_024),
|
||||
name: z.string().min(1),
|
||||
exact: z.literal(true),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("css"),
|
||||
selector: z.string().min(1).max(4_096),
|
||||
selector: z.string().min(1),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -186,8 +164,10 @@ const stepBase = {
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.actionTimeoutMs)
|
||||
.optional(),
|
||||
.optional()
|
||||
.describe(
|
||||
"Optional action deadline in milliseconds; omitted means wait until completion or request cancellation.",
|
||||
),
|
||||
};
|
||||
|
||||
export const browserScenarioActionSchema = z.discriminatedUnion("action", [
|
||||
@@ -214,7 +194,7 @@ export const browserScenarioActionSchema = z.discriminatedUnion("action", [
|
||||
...stepBase,
|
||||
action: z.literal("press"),
|
||||
locator: locatorSchema,
|
||||
key: z.string().min(1).max(64),
|
||||
key: z.string().min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
...stepBase,
|
||||
@@ -240,13 +220,15 @@ export const browserScenarioActionSchema = z.discriminatedUnion("action", [
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(BROWSER_SCENARIO_LIMITS.actionTimeoutMs),
|
||||
.describe(
|
||||
"Wait this many milliseconds; the wait ends early on cancellation.",
|
||||
),
|
||||
}),
|
||||
]);
|
||||
export type BrowserScenarioAction = z.infer<typeof browserScenarioActionSchema>;
|
||||
|
||||
const storageEntrySchema = z.strictObject({
|
||||
name: z.string().min(1).max(1_024),
|
||||
name: z.string().min(1),
|
||||
value: browserScenarioValueSchema,
|
||||
});
|
||||
|
||||
@@ -255,7 +237,7 @@ export const browserScenarioStorageSchema = z
|
||||
cookies: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
name: z.string().min(1).max(1_024),
|
||||
name: z.string().min(1),
|
||||
value: browserScenarioValueSchema,
|
||||
destination: browserScenarioUrlSchema,
|
||||
http_only: z.boolean(),
|
||||
@@ -289,7 +271,6 @@ export const browserScenarioStorageSchema = z
|
||||
const headerNameSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(256)
|
||||
.regex(/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u)
|
||||
.transform((value) => value.toLowerCase());
|
||||
|
||||
@@ -341,7 +322,7 @@ export const browserScenarioRequestReplaySchema = z
|
||||
|
||||
export const browserScenarioSecretSchema = z.strictObject({
|
||||
secret_id: scenarioIdentifierSchema,
|
||||
environment_variable: z.string().regex(/^[A-Z_][A-Z0-9_]{0,127}$/u),
|
||||
environment_variable: z.string().regex(/^[A-Z_][A-Z0-9_]*$/u),
|
||||
purpose: z.enum(["input", "storage", "request-replay"]),
|
||||
redaction: z.literal("replace-with-secret-reference"),
|
||||
});
|
||||
@@ -360,7 +341,6 @@ const normalizedNames = () =>
|
||||
.string()
|
||||
.trim()
|
||||
.min(1)
|
||||
.max(256)
|
||||
.transform((value) => value.toLowerCase()),
|
||||
)
|
||||
.transform((values) => [...new Set(values)].sort());
|
||||
|
||||
@@ -136,4 +136,25 @@ describe("bytecode provider", () => {
|
||||
const parsed = bytecodeAnalysisSchema.safeParse(result);
|
||||
expect(parsed.success).toBe(true);
|
||||
});
|
||||
|
||||
it("returns every artifact when the inventory exceeds ten thousand entries", () => {
|
||||
const artifacts = Array.from({ length: 10_001 }, (_, index) => ({
|
||||
path: `classes/${index}.class`,
|
||||
family: "jvm" as const,
|
||||
format: "class" as const,
|
||||
size: 1,
|
||||
digest: "a".repeat(64),
|
||||
symbols: [],
|
||||
is_standard_library: false,
|
||||
is_generated: false,
|
||||
is_vendored: false,
|
||||
}));
|
||||
|
||||
const result = analyzeBytecodeArtifacts(artifacts, "jvm");
|
||||
|
||||
expect(result.artifacts).toHaveLength(artifacts.length);
|
||||
expect(bytecodeAnalysisSchema.parse(result).artifacts).toHaveLength(
|
||||
artifacts.length,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ export const bytecodeAnalysisSchema = z.strictObject({
|
||||
/** Bytecode family. */
|
||||
family: bytecodeFamilySchema,
|
||||
/** All discovered artifacts. */
|
||||
artifacts: z.array(bytecodeArtifactSchema).min(0).max(10_000),
|
||||
artifacts: z.array(bytecodeArtifactSchema),
|
||||
/** Total symbols across all artifacts. */
|
||||
total_symbols: z.number().int().nonnegative(),
|
||||
/** Symbols classified as application code. */
|
||||
@@ -176,26 +176,29 @@ export function analyzeBytecodeArtifacts(
|
||||
artifacts: readonly BytecodeArtifact[],
|
||||
family: BytecodeFamily,
|
||||
): BytecodeAnalysis {
|
||||
const applicationSymbols = artifacts
|
||||
.flatMap((a) => a.symbols)
|
||||
.filter((s) => s.provenance === "application").length;
|
||||
const generatedSymbols = artifacts
|
||||
.flatMap((a) => a.symbols)
|
||||
.filter((s) => s.provenance === "generated").length;
|
||||
const vendoredSymbols = artifacts
|
||||
.flatMap((a) => a.symbols)
|
||||
.filter((s) => s.provenance === "vendored").length;
|
||||
const standardLibrarySymbols = artifacts
|
||||
.flatMap((a) => a.symbols)
|
||||
.filter((s) => s.provenance === "standard_library").length;
|
||||
const totals = artifacts.reduce(
|
||||
(counts, artifact) => {
|
||||
counts.total += artifact.symbols.length;
|
||||
for (const symbol of artifact.symbols) counts[symbol.provenance] += 1;
|
||||
return counts;
|
||||
},
|
||||
{
|
||||
total: 0,
|
||||
application: 0,
|
||||
generated: 0,
|
||||
vendored: 0,
|
||||
standard_library: 0,
|
||||
bundled: 0,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
family,
|
||||
artifacts: artifacts.slice(0, 10_000),
|
||||
total_symbols: artifacts.reduce((sum, a) => sum + a.symbols.length, 0),
|
||||
application_symbols: applicationSymbols,
|
||||
generated_symbols: generatedSymbols,
|
||||
vendored_symbols: vendoredSymbols,
|
||||
standard_library_symbols: standardLibrarySymbols,
|
||||
artifacts: [...artifacts],
|
||||
total_symbols: totals.total,
|
||||
application_symbols: totals.application,
|
||||
generated_symbols: totals.generated,
|
||||
vendored_symbols: totals.vendored,
|
||||
standard_library_symbols: totals.standard_library,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ const right = source("2");
|
||||
const comparison = (
|
||||
operation: "compare_process_captures" | "compare_artifacts",
|
||||
result: JsonValue,
|
||||
input: { readonly salt?: number; readonly evidenceLinks?: string[] } = {},
|
||||
): Evidence => {
|
||||
const process = operation === "compare_process_captures";
|
||||
return createEvidence(
|
||||
@@ -41,11 +42,14 @@ const comparison = (
|
||||
? "rea.process-comparison"
|
||||
: "rea.artifact-comparison",
|
||||
operation,
|
||||
parameters: {},
|
||||
parameters: input.salt === undefined ? {} : { salt: input.salt },
|
||||
result,
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
evidenceLinks: [left.evidence_id, right.evidence_id],
|
||||
evidenceLinks: input.evidenceLinks ?? [
|
||||
left.evidence_id,
|
||||
right.evidence_id,
|
||||
],
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -262,3 +266,30 @@ describe("changed behavior", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("changed behavior aggregation", () => {
|
||||
it("keeps all comparisons and their complete evidence closure", () => {
|
||||
const comparisons = Array.from({ length: 101 }, (_, comparisonIndex) =>
|
||||
comparison(
|
||||
"compare_process_captures",
|
||||
processResult({ status: "changed", terminal: "changed" }),
|
||||
{
|
||||
salt: comparisonIndex,
|
||||
evidenceLinks: Array.from(
|
||||
{ length: 200 },
|
||||
(_, linkIndex) =>
|
||||
`ev_${(comparisonIndex * 200 + linkIndex + 1)
|
||||
.toString(16)
|
||||
.padStart(64, "0")}`,
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const result = findChangedBehavior(comparisons);
|
||||
|
||||
expect(result.summary.observed_changes).toBe(comparisons.length);
|
||||
expect(result.evidence_links).toHaveLength(comparisons.length * 201);
|
||||
expect(result.findings.items[0]?.evidence_links).toHaveLength(201);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,9 +12,9 @@ import {
|
||||
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
|
||||
/** Strict bounded input for aggregating existing comparison Evidence. */
|
||||
/** Input for aggregating existing comparison Evidence. */
|
||||
export const changedBehaviorInputSchema = z.object({
|
||||
comparisons: z.array(evidenceSchema).max(100).default([]),
|
||||
comparisons: z.array(evidenceSchema).default([]),
|
||||
});
|
||||
|
||||
const findingSchema = z.object({
|
||||
@@ -28,7 +28,7 @@ const findingSchema = z.object({
|
||||
]),
|
||||
status: comparisonStatusSchema,
|
||||
source_comparison_id: evidenceIdSchema,
|
||||
evidence_links: z.array(evidenceIdSchema).min(3).max(201),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ export const changedBehaviorResultSchema = z
|
||||
findings: z.object({
|
||||
items: z.array(findingSchema),
|
||||
}),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3).max(20_100),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3),
|
||||
limitations: z.array(z.string()),
|
||||
})
|
||||
.superRefine((result, context) => {
|
||||
@@ -125,8 +125,6 @@ export const findChangedBehavior = (
|
||||
const links = uniqueSorted(
|
||||
evidence.flatMap((item) => [item.evidence_id, ...item.evidence_links]),
|
||||
);
|
||||
if (links.length > 20_100)
|
||||
throw new TypeError("Changed-behavior Evidence closure exceeds limit");
|
||||
return changedBehaviorResultSchema.parse({
|
||||
behavior_status: behaviorStatus(runtimeStatuses),
|
||||
summary: {
|
||||
|
||||
@@ -9,17 +9,17 @@ import {
|
||||
type EvidenceCompletionLedger,
|
||||
} from "./evidenceCompletionLedger.js";
|
||||
|
||||
const identifierSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]{0,99}$/u);
|
||||
const identifierSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]*$/u);
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const identitySchema = z.strictObject({
|
||||
id: identifierSchema,
|
||||
version: z.string().min(1).max(100),
|
||||
version: z.string().min(1),
|
||||
});
|
||||
const environmentSchema = z.strictObject({
|
||||
platform: identifierSchema,
|
||||
architecture: identifierSchema,
|
||||
runtime: identifierSchema,
|
||||
runtime_version: z.string().min(1).max(100),
|
||||
runtime_version: z.string().min(1),
|
||||
});
|
||||
const scenarioSchema = z.strictObject({
|
||||
id: identifierSchema,
|
||||
@@ -55,7 +55,7 @@ const verifierRunSchema = z
|
||||
launcher_pid: z.number().int().positive(),
|
||||
launcher_parent_pid: z.number().int().nonnegative(),
|
||||
process_group_id: z.number().int().positive().nullable(),
|
||||
reason: z.string().min(1).max(500),
|
||||
reason: z.string().min(1),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
@@ -76,7 +76,7 @@ const verifierRunSchema = z
|
||||
const reportClaimSchema = z.strictObject({
|
||||
claim_id: identifierSchema,
|
||||
scenario: scenarioSchema,
|
||||
artifact_sha256s: z.array(digestSchema).max(100),
|
||||
artifact_sha256s: z.array(digestSchema),
|
||||
provider: identitySchema,
|
||||
status: evidenceCompletionRecordSchema.shape.status,
|
||||
evidence_ids: evidenceCompletionRecordSchema.shape.evidence_ids,
|
||||
@@ -86,7 +86,7 @@ const completionVerifierReportObjectSchema = z.strictObject({
|
||||
verifier: identitySchema,
|
||||
verifier_run: verifierRunSchema,
|
||||
environment: environmentSchema,
|
||||
claims: z.array(reportClaimSchema).min(1).max(10_000),
|
||||
claims: z.array(reportClaimSchema).min(1),
|
||||
});
|
||||
|
||||
/** Strict output contract implemented by completion-aware verifiers. */
|
||||
@@ -113,8 +113,8 @@ const completionManifestObjectSchema = z.strictObject({
|
||||
manifest_id: z.string().regex(/^ecm_[a-f0-9]{64}$/u),
|
||||
verifier: identitySchema,
|
||||
environment: environmentSchema,
|
||||
skill_digests: z.array(skillDigestSchema).min(1).max(100),
|
||||
claims: z.array(manifestClaimSchema).min(1).max(10_000),
|
||||
skill_digests: z.array(skillDigestSchema).min(1),
|
||||
claims: z.array(manifestClaimSchema).min(1),
|
||||
});
|
||||
type CompletionManifestValue = z.infer<typeof completionManifestObjectSchema>;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { err, ok, type Result } from "./result.js";
|
||||
|
||||
const conformancePackageIdSchema = z.string().regex(/^cp_[a-f0-9]{64}$/u);
|
||||
|
||||
const scenarioIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]{0,99}$/u);
|
||||
const scenarioIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]*$/u);
|
||||
|
||||
const scenarioManifestSchema = z.strictObject({
|
||||
scenario_id: scenarioIdSchema,
|
||||
@@ -35,8 +35,7 @@ const replayPlanSchema = z.strictObject({
|
||||
timeout_ms: z.number().int().positive(),
|
||||
}),
|
||||
)
|
||||
.min(1)
|
||||
.max(100),
|
||||
.min(1),
|
||||
/** Environment variables to set (never inherit host paths). */
|
||||
environment: z.record(z.string(), z.string()).default({}),
|
||||
});
|
||||
@@ -44,22 +43,20 @@ const replayPlanSchema = z.strictObject({
|
||||
const shimPlanSchema = z.strictObject({
|
||||
scenario_id: scenarioIdSchema,
|
||||
/** Shims to install, each intercepting a named effect. */
|
||||
shims: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
shim_id: z.string().min(1),
|
||||
kind: z.enum(["filesystem", "network", "process", "signal"]),
|
||||
target: z.string().min(1),
|
||||
policy: z.enum(["observe", "allow", "block", "emulate"]),
|
||||
}),
|
||||
)
|
||||
.max(50),
|
||||
shims: z.array(
|
||||
z.strictObject({
|
||||
shim_id: z.string().min(1),
|
||||
kind: z.enum(["filesystem", "network", "process", "signal"]),
|
||||
target: z.string().min(1),
|
||||
policy: z.enum(["observe", "allow", "block", "emulate"]),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const expectedEvidenceSchema = z.strictObject({
|
||||
scenario_id: scenarioIdSchema,
|
||||
/** Expected evidence envelopes. */
|
||||
envelopes: z.array(evidenceEnvelopeSchema).max(100),
|
||||
envelopes: z.array(evidenceEnvelopeSchema),
|
||||
/** Expected evidence bundle. */
|
||||
bundle: evidenceBundleSchema.nullable(),
|
||||
/** Required dimensions that must be present in the evidence. */
|
||||
@@ -77,8 +74,7 @@ const verifierContractSchema = z.strictObject({
|
||||
comparison: z.enum(["exact", "semantic", "fuzzy"]),
|
||||
}),
|
||||
)
|
||||
.min(1)
|
||||
.max(50),
|
||||
.min(1),
|
||||
/** Tolerance for timing differences in milliseconds. */
|
||||
timing_tolerance_ms: z.number().int().nonnegative().default(0),
|
||||
});
|
||||
@@ -88,15 +84,15 @@ const conformancePackageContentsSchema = z.strictObject({
|
||||
description: z.string().min(1),
|
||||
created_at: z.string().datetime(),
|
||||
/** Scenario manifests. */
|
||||
scenarios: z.array(scenarioManifestSchema).min(1).max(100),
|
||||
scenarios: z.array(scenarioManifestSchema).min(1),
|
||||
/** Exactly one replay plan for each scenario. */
|
||||
replay_plans: z.array(replayPlanSchema).min(1).max(100),
|
||||
replay_plans: z.array(replayPlanSchema).min(1),
|
||||
/** At most one optional shim plan for each scenario. */
|
||||
shim_plans: z.array(shimPlanSchema).default([]),
|
||||
/** Exactly one expected-evidence record for each scenario. */
|
||||
expected_evidence: z.array(expectedEvidenceSchema).min(1).max(100),
|
||||
expected_evidence: z.array(expectedEvidenceSchema).min(1),
|
||||
/** Exactly one verifier contract for each scenario. */
|
||||
verifier_contracts: z.array(verifierContractSchema).min(1).max(100),
|
||||
verifier_contracts: z.array(verifierContractSchema).min(1),
|
||||
});
|
||||
|
||||
const conformancePackageRecordSchema = conformancePackageContentsSchema.extend({
|
||||
|
||||
@@ -5,7 +5,6 @@ import { z } from "zod";
|
||||
const absolutePathSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(16_384)
|
||||
.refine(isAbsolute, "path must be absolute");
|
||||
|
||||
const windowIndexSchema = z.number().int().min(0);
|
||||
@@ -13,7 +12,6 @@ const windowIndexSchema = z.number().int().min(0);
|
||||
const deepLinkUrlSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(4_096)
|
||||
.refine((value) => {
|
||||
try {
|
||||
return new URL(value).protocol.length > 0;
|
||||
@@ -24,29 +22,29 @@ const deepLinkUrlSchema = z
|
||||
|
||||
const actionSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
step_id: z.string().min(1).max(128),
|
||||
step_id: z.string().min(1),
|
||||
kind: z.literal("click"),
|
||||
selector: z.string().min(1).max(512),
|
||||
selector: z.string().min(1),
|
||||
window_index: windowIndexSchema.default(0),
|
||||
}),
|
||||
z.strictObject({
|
||||
step_id: z.string().min(1).max(128),
|
||||
step_id: z.string().min(1),
|
||||
kind: z.literal("wait"),
|
||||
duration_ms: z.number().int().min(0),
|
||||
window_index: windowIndexSchema.optional(),
|
||||
}),
|
||||
z.strictObject({
|
||||
step_id: z.string().min(1).max(128),
|
||||
step_id: z.string().min(1),
|
||||
kind: z.literal("renderer-reload"),
|
||||
window_index: windowIndexSchema.default(0),
|
||||
}),
|
||||
z.strictObject({
|
||||
step_id: z.string().min(1).max(128),
|
||||
step_id: z.string().min(1),
|
||||
kind: z.literal("renderer-crash"),
|
||||
window_index: windowIndexSchema.default(0),
|
||||
}),
|
||||
z.strictObject({
|
||||
step_id: z.string().min(1).max(128),
|
||||
step_id: z.string().min(1),
|
||||
kind: z.literal("deep-link"),
|
||||
delivery: z.enum(["open-url", "second-instance"]),
|
||||
url: deepLinkUrlSchema,
|
||||
@@ -58,7 +56,7 @@ export const electronActiveObservationInputSchema = z.strictObject({
|
||||
executable_path: absolutePathSchema,
|
||||
application_path: absolutePathSchema,
|
||||
application_root: absolutePathSchema,
|
||||
args: z.array(z.string().max(4_096)).default([]),
|
||||
args: z.array(z.string()).default([]),
|
||||
actions: z.array(actionSchema).default([]),
|
||||
});
|
||||
export type ElectronActiveObservationInput = z.infer<
|
||||
@@ -67,7 +65,7 @@ export type ElectronActiveObservationInput = z.infer<
|
||||
|
||||
const ipcEventSchema = z.strictObject({
|
||||
sequence: z.number().int().min(1),
|
||||
correlation_id: z.string().max(256).nullable().default(null),
|
||||
correlation_id: z.string().nullable().default(null),
|
||||
kind: z.enum([
|
||||
"main-handler-invocation",
|
||||
"main-event-invocation",
|
||||
@@ -79,13 +77,12 @@ const ipcEventSchema = z.strictObject({
|
||||
"ipc-renderer-invoke",
|
||||
"ipc-renderer-post-message",
|
||||
]),
|
||||
event: z.string().max(128).nullable().optional(),
|
||||
event: z.string().nullable().optional(),
|
||||
phase: z
|
||||
.enum(["attempted", "completed", "blocked", "failed", "observed"])
|
||||
.nullable()
|
||||
.optional(),
|
||||
channel: z.string().max(1_024).nullable(),
|
||||
channel_truncated: z.boolean().default(false),
|
||||
channel: z.string().nullable(),
|
||||
direction: z
|
||||
.enum([
|
||||
"renderer-to-main",
|
||||
@@ -95,19 +92,18 @@ const ipcEventSchema = z.strictObject({
|
||||
])
|
||||
.nullable()
|
||||
.optional(),
|
||||
sender: z.string().max(256).nullable().optional(),
|
||||
receiver: z.string().max(256).nullable().optional(),
|
||||
frame: z.string().max(256).nullable().default(null),
|
||||
target: z.string().max(256).nullable().optional(),
|
||||
argument_shapes: z.array(z.string().max(64)).max(32),
|
||||
argument_shapes_truncated: z.boolean().default(false),
|
||||
result_shape: z.string().max(64).nullable(),
|
||||
process_type: z.string().max(128).nullable(),
|
||||
source: z.string().max(64).default("electron-active-hook"),
|
||||
sender: z.string().nullable().optional(),
|
||||
receiver: z.string().nullable().optional(),
|
||||
frame: z.string().nullable().default(null),
|
||||
target: z.string().nullable().optional(),
|
||||
argument_shapes: z.array(z.string()),
|
||||
result_shape: z.string().nullable(),
|
||||
process_type: z.string().nullable(),
|
||||
source: z.string().default("electron-active-hook"),
|
||||
capture_method: z
|
||||
.enum(["api-wrapper", "event-emitter", "process-hook"])
|
||||
.default("api-wrapper"),
|
||||
artifact_path: z.string().max(16_384).nullable().default(null),
|
||||
artifact_path: z.string().nullable().default(null),
|
||||
artifact_sha256: z
|
||||
.string()
|
||||
.regex(/^[a-f0-9]{64}$/u)
|
||||
@@ -118,7 +114,7 @@ const ipcEventSchema = z.strictObject({
|
||||
|
||||
const timelineEventSchema = z.strictObject({
|
||||
sequence: z.number().int().min(1),
|
||||
correlation_id: z.string().max(256).nullable().default(null),
|
||||
correlation_id: z.string().nullable().default(null),
|
||||
kind: z.enum([
|
||||
"main-handler-invocation",
|
||||
"main-event-invocation",
|
||||
@@ -144,10 +140,9 @@ const timelineEventSchema = z.strictObject({
|
||||
"updater",
|
||||
"error",
|
||||
]),
|
||||
event: z.string().max(128).nullable(),
|
||||
event: z.string().nullable(),
|
||||
phase: z.enum(["attempted", "completed", "blocked", "failed", "observed"]),
|
||||
channel: z.string().max(1_024).nullable(),
|
||||
channel_truncated: z.boolean(),
|
||||
channel: z.string().nullable(),
|
||||
direction: z
|
||||
.enum([
|
||||
"renderer-to-main",
|
||||
@@ -156,17 +151,16 @@ const timelineEventSchema = z.strictObject({
|
||||
"utility-to-main",
|
||||
])
|
||||
.nullable(),
|
||||
sender: z.string().max(256).nullable(),
|
||||
receiver: z.string().max(256).nullable(),
|
||||
frame: z.string().max(256).nullable(),
|
||||
target: z.string().max(256).nullable(),
|
||||
argument_shapes: z.array(z.string().max(64)).max(32),
|
||||
argument_shapes_truncated: z.boolean(),
|
||||
result_shape: z.string().max(64).nullable(),
|
||||
process_type: z.string().max(128).nullable(),
|
||||
source: z.string().max(64),
|
||||
sender: z.string().nullable(),
|
||||
receiver: z.string().nullable(),
|
||||
frame: z.string().nullable(),
|
||||
target: z.string().nullable(),
|
||||
argument_shapes: z.array(z.string()),
|
||||
result_shape: z.string().nullable(),
|
||||
process_type: z.string().nullable(),
|
||||
source: z.string(),
|
||||
capture_method: z.enum(["api-wrapper", "event-emitter", "process-hook"]),
|
||||
artifact_path: z.string().max(16_384).nullable(),
|
||||
artifact_path: z.string().nullable(),
|
||||
artifact_sha256: z
|
||||
.string()
|
||||
.regex(/^[a-f0-9]{64}$/u)
|
||||
@@ -176,16 +170,16 @@ const timelineEventSchema = z.strictObject({
|
||||
|
||||
const processMetricSchema = z.strictObject({
|
||||
pid: z.number().int().min(1),
|
||||
type: z.string().min(1).max(128),
|
||||
name: z.string().max(256).nullable(),
|
||||
service_name: z.string().max(256).nullable(),
|
||||
type: z.string().min(1),
|
||||
name: z.string().nullable(),
|
||||
service_name: z.string().nullable(),
|
||||
});
|
||||
|
||||
const windowResultSchema = z.strictObject({
|
||||
window_id: z.string().max(256),
|
||||
web_contents_id: z.string().max(256),
|
||||
url: z.string().max(65_536),
|
||||
title: z.string().max(16_384),
|
||||
window_id: z.string(),
|
||||
web_contents_id: z.string(),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
visible: z.boolean().nullable(),
|
||||
destroyed: z.boolean(),
|
||||
});
|
||||
@@ -198,14 +192,14 @@ const coverageSchema = z.strictObject({
|
||||
"target_exited",
|
||||
"cleanup_failed",
|
||||
]),
|
||||
observed_event_families: z.array(z.string().max(128)).max(32),
|
||||
unavailable_event_families: z.array(z.string().max(128)).max(32),
|
||||
observed_roles: z.array(z.string().max(128)).max(16),
|
||||
observed_event_families: z.array(z.string()),
|
||||
unavailable_event_families: z.array(z.string()),
|
||||
observed_roles: z.array(z.string()),
|
||||
pre_capture_activity: z.literal("unavailable"),
|
||||
});
|
||||
|
||||
const actionResultContextShape = {
|
||||
step_id: z.string().min(1).max(128),
|
||||
step_id: z.string().min(1),
|
||||
kind: z.enum([
|
||||
"click",
|
||||
"wait",
|
||||
@@ -214,7 +208,7 @@ const actionResultContextShape = {
|
||||
"deep-link",
|
||||
]),
|
||||
window_index: windowIndexSchema.nullable(),
|
||||
target: z.string().max(256).nullable(),
|
||||
target: z.string().nullable(),
|
||||
elapsed_ms: z.number().int().min(0),
|
||||
};
|
||||
|
||||
@@ -236,7 +230,7 @@ export const electronActiveObservationResultSchema = z.strictObject({
|
||||
application: z.strictObject({
|
||||
executable_path: absolutePathSchema,
|
||||
application_path: absolutePathSchema,
|
||||
electron_version: z.string().min(1).max(256),
|
||||
electron_version: z.string().min(1),
|
||||
process_ownership: z.literal("provider-owned"),
|
||||
cleanup: z.literal("terminated-owned-process"),
|
||||
}),
|
||||
@@ -262,7 +256,7 @@ export const electronActiveObservationResultSchema = z.strictObject({
|
||||
observed_roles: [],
|
||||
pre_capture_activity: "unavailable",
|
||||
}),
|
||||
limitations: z.array(z.string().max(4_096)).max(100),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
export type ElectronActiveObservationResult = z.infer<
|
||||
typeof electronActiveObservationResultSchema
|
||||
|
||||
@@ -324,14 +324,7 @@ export class EvidenceFileError extends AnalysisError {
|
||||
|
||||
constructor(
|
||||
readonly operation: "read" | "write",
|
||||
readonly reason:
|
||||
| "disabled"
|
||||
| "outside-root"
|
||||
| "not-file"
|
||||
| "too-large"
|
||||
| "exists"
|
||||
| "invalid-json"
|
||||
| "io",
|
||||
readonly reason: "not-file" | "exists" | "invalid-json" | "io",
|
||||
options?: ErrorOptions,
|
||||
) {
|
||||
super(`Evidence bundle ${operation} failed: ${reason}`, options);
|
||||
|
||||
@@ -5,10 +5,42 @@ import {
|
||||
getDescendants,
|
||||
maxTreeDepth,
|
||||
reconstructProcessTree,
|
||||
type ProcessNode,
|
||||
type ProcessTreeEvent,
|
||||
} from "./eventProcessTree.js";
|
||||
|
||||
describe("event-backed process tree reconstruction", () => {
|
||||
it("walks trees larger than ten thousand nodes", () => {
|
||||
const childPids = Array.from({ length: 10_001 }, (_, index) => index + 2);
|
||||
const root: ProcessNode = {
|
||||
pid: 1,
|
||||
ppid: null,
|
||||
process_name: "root",
|
||||
executable: null,
|
||||
arguments: [],
|
||||
children: childPids,
|
||||
spawn_time_ms: null,
|
||||
exit_time_ms: null,
|
||||
exit_code: null,
|
||||
is_re_exec: false,
|
||||
is_reparented: false,
|
||||
previous_ppid: null,
|
||||
};
|
||||
const children = childPids.map(
|
||||
(pid): ProcessNode => ({
|
||||
...root,
|
||||
pid,
|
||||
ppid: 1,
|
||||
children: [],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(maxTreeDepth([root, ...children], 1)).toBe(1);
|
||||
expect(getDescendants([root, ...children], 1)).toHaveLength(
|
||||
childPids.length,
|
||||
);
|
||||
});
|
||||
|
||||
it("reconstructs a simple process tree", () => {
|
||||
const events: ProcessTreeEvent[] = [
|
||||
{
|
||||
@@ -78,7 +110,9 @@ describe("event-backed process tree reconstruction", () => {
|
||||
expect(result.events_unmatched).toBe(0);
|
||||
expect(result.short_lived_descendants).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("short-lived process descendants", () => {
|
||||
it("detects short-lived descendants", () => {
|
||||
const events: ProcessTreeEvent[] = [
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ export const processTreeReconstructionSchema = z.strictObject({
|
||||
/** Root PID of the process tree. */
|
||||
root_pid: z.number().int().positive(),
|
||||
/** All reconstructed process nodes. */
|
||||
processes: z.array(processNodeSchema).min(0).max(10_000),
|
||||
processes: z.array(processNodeSchema).min(0),
|
||||
/** Events that were consumed. */
|
||||
events_consumed: z.number().int().nonnegative(),
|
||||
/** Events that could not be matched. */
|
||||
@@ -207,9 +207,9 @@ export function getDescendants(
|
||||
const visited = new Set<number>();
|
||||
const result: number[] = [];
|
||||
const queue: number[] = [rootPid];
|
||||
while (queue.length > 0) {
|
||||
const pid = queue.shift();
|
||||
if (pid === undefined) break;
|
||||
for (let head = 0; head < queue.length; head += 1) {
|
||||
const pid = queue[head];
|
||||
if (pid === undefined) continue;
|
||||
if (visited.has(pid)) continue;
|
||||
visited.add(pid);
|
||||
const node = byPid.get(pid);
|
||||
@@ -239,12 +239,24 @@ export function maxTreeDepth(
|
||||
rootPid: number,
|
||||
): number {
|
||||
const byPid = new Map(processes.map((p) => [p.pid, p]));
|
||||
function depth(pid: number, visited: Set<number>): number {
|
||||
if (visited.has(pid)) return 0;
|
||||
visited.add(pid);
|
||||
const node = byPid.get(pid);
|
||||
if (!node || node.children.length === 0) return 0;
|
||||
return 1 + Math.max(...node.children.map((c) => depth(c, visited)));
|
||||
const pending = [{ pid: rootPid, depth: 0 }];
|
||||
const visited = new Set<number>();
|
||||
let maximumDepth = 0;
|
||||
|
||||
while (pending.length > 0) {
|
||||
const current = pending.pop();
|
||||
if (!current || visited.has(current.pid)) continue;
|
||||
visited.add(current.pid);
|
||||
|
||||
const node = byPid.get(current.pid);
|
||||
if (!node || node.children.length === 0) continue;
|
||||
|
||||
const childDepth = current.depth + 1;
|
||||
maximumDepth = Math.max(maximumDepth, childDepth);
|
||||
for (const childPid of node.children)
|
||||
if (!visited.has(childPid))
|
||||
pending.push({ pid: childPid, depth: childDepth });
|
||||
}
|
||||
return depth(rootPid, new Set());
|
||||
|
||||
return maximumDepth;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,19 @@ describe("Evidence completion ledger", () => {
|
||||
expect(left.ledger_id).toMatch(/^ecl_[a-f0-9]{64}$/u);
|
||||
});
|
||||
|
||||
it("accepts every Evidence ID supplied for one claim", () => {
|
||||
const evidenceIds = Array.from(
|
||||
{ length: 101 },
|
||||
(_, index) => `ev_${index.toString(16).padStart(64, "0")}`,
|
||||
);
|
||||
|
||||
expect(
|
||||
createEvidenceCompletionLedger([
|
||||
record("scenario.many-evidence-items", "pass", evidenceIds),
|
||||
]).records[0]?.evidence_ids,
|
||||
).toHaveLength(evidenceIds.length);
|
||||
});
|
||||
|
||||
it("rejects missing, malformed, and duplicate Evidence IDs", () => {
|
||||
expect(() =>
|
||||
createEvidenceCompletionLedger([record("scenario.empty", "pass", [])]),
|
||||
|
||||
@@ -4,7 +4,7 @@ import canonicalize from "canonicalize";
|
||||
import { z } from "zod";
|
||||
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const claimIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]{0,99}$/u);
|
||||
const claimIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]*$/u);
|
||||
|
||||
/** Terminal outcome recorded for one verifier claim. */
|
||||
export const evidenceCompletionStatusSchema = z.enum([
|
||||
@@ -19,11 +19,11 @@ export const evidenceCompletionStatusSchema = z.enum([
|
||||
export const evidenceCompletionRecordSchema = z.strictObject({
|
||||
claim_id: claimIdSchema,
|
||||
status: evidenceCompletionStatusSchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const completionSummarySchema = z.strictObject({
|
||||
total: z.number().int().min(1).max(10_000),
|
||||
total: z.number().int().min(1),
|
||||
pass: z.number().int().nonnegative(),
|
||||
fail: z.number().int().nonnegative(),
|
||||
unsupported: z.number().int().nonnegative(),
|
||||
@@ -34,7 +34,7 @@ const completionSummarySchema = z.strictObject({
|
||||
|
||||
const completionLedgerObjectSchema = z.strictObject({
|
||||
ledger_id: z.string().regex(/^ecl_[a-f0-9]{64}$/u),
|
||||
records: z.array(evidenceCompletionRecordSchema).min(1).max(10_000),
|
||||
records: z.array(evidenceCompletionRecordSchema).min(1),
|
||||
summary: completionSummarySchema,
|
||||
});
|
||||
|
||||
|
||||
@@ -122,11 +122,7 @@ describe("function comparison", () => {
|
||||
}),
|
||||
]),
|
||||
);
|
||||
for (const dimension of result.dimensions)
|
||||
expect(dimension.evidence_links).toEqual([
|
||||
FUNCTION_COMPARISON_EXAMPLE.left.evidence_id,
|
||||
FUNCTION_COMPARISON_EXAMPLE.right.evidence_id,
|
||||
]);
|
||||
expectInlineComparisonEvidence(result);
|
||||
expectFunctionDimensionAlgebra(result);
|
||||
});
|
||||
|
||||
@@ -252,6 +248,35 @@ describe("function comparison", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const expectInlineComparisonEvidence = (
|
||||
result: ReturnType<typeof compareFunctions>,
|
||||
): void => {
|
||||
for (const dimension of result.dimensions)
|
||||
expect(dimension.evidence_links).toEqual([
|
||||
FUNCTION_COMPARISON_EXAMPLE.left.evidence_id,
|
||||
FUNCTION_COMPARISON_EXAMPLE.right.evidence_id,
|
||||
]);
|
||||
const firstDimension = result.dimensions[0];
|
||||
expect(firstDimension).toBeDefined();
|
||||
if (firstDimension === undefined) return;
|
||||
expect(
|
||||
functionComparisonResultSchema.safeParse({
|
||||
...result,
|
||||
dimensions: result.dimensions.map((dimension, index) =>
|
||||
index === 0
|
||||
? {
|
||||
...dimension,
|
||||
evidence_links: Array.from(
|
||||
{ length: 201 },
|
||||
() => FUNCTION_COMPARISON_EXAMPLE.left.evidence_id,
|
||||
),
|
||||
}
|
||||
: dimension,
|
||||
),
|
||||
}).success,
|
||||
).toBe(true);
|
||||
};
|
||||
|
||||
const expectFunctionDimensionAlgebra = (
|
||||
result: ReturnType<typeof compareFunctions>,
|
||||
): void => {
|
||||
|
||||
@@ -35,7 +35,7 @@ const functionDimensionContextShape = {
|
||||
dimension: dimensionNameSchema,
|
||||
left_count: z.number().int().min(0).nullable(),
|
||||
right_count: z.number().int().min(0).nullable(),
|
||||
evidence_links: z.array(evidenceIdSchema).min(2).max(200),
|
||||
evidence_links: z.array(evidenceIdSchema).min(2),
|
||||
limitations: z.array(z.string()),
|
||||
};
|
||||
|
||||
|
||||
@@ -45,10 +45,7 @@ const electronBoundarySummarySchema = z.strictObject({
|
||||
const reconstructionStatisticsSchema = z.strictObject({
|
||||
relevant_files: countSchema,
|
||||
nested_asar_containers: countSchema,
|
||||
text_files_selected: countSchema,
|
||||
text_bytes_read: countSchema,
|
||||
omitted_text_files: countSchema,
|
||||
limit_omitted_text_files: countSchema,
|
||||
invalid_utf8_files: countSchema,
|
||||
parsed_javascript_files: countSchema,
|
||||
visited_ast_nodes: countSchema,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const boundedKeySchema = z.string().min(1).max(512);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
const boundedKeySchema = z.string().min(1);
|
||||
const unsafePathSegments = new Set(["", ".", ".."]);
|
||||
const isSafeRelativePath = (path: string): boolean => {
|
||||
if (path.startsWith("/") || path.includes("\\")) return false;
|
||||
@@ -11,7 +11,6 @@ const isSafeRelativePath = (path: string): boolean => {
|
||||
const relativePathSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(4_096)
|
||||
.refine(
|
||||
isSafeRelativePath,
|
||||
"Expected a normalized relative POSIX path without traversal",
|
||||
@@ -138,7 +137,7 @@ const applicationLocationSchema = z.discriminatedUnion("kind", [
|
||||
fileOffsetRangeSchema,
|
||||
z.strictObject({
|
||||
kind: z.literal("url"),
|
||||
url: z.string().min(1).max(16_384),
|
||||
url: z.string().min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("runtime"),
|
||||
@@ -170,14 +169,14 @@ const applicationLocationReferenceSchema = z.discriminatedUnion("available", [
|
||||
|
||||
/** Versioned extractor coordinates attached to every graph fact. */
|
||||
const applicationExtractorSchema = z.strictObject({
|
||||
name: z.string().min(1).max(128),
|
||||
version: z.string().min(1).max(128),
|
||||
operation: z.string().min(1).max(256),
|
||||
name: z.string().min(1),
|
||||
version: z.string().min(1),
|
||||
operation: z.string().min(1),
|
||||
executable_sha256: digestSchema.nullable(),
|
||||
});
|
||||
|
||||
const applicationLimitSchema = z.strictObject({
|
||||
name: z.string().min(1).max(128),
|
||||
name: z.string().min(1),
|
||||
value: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
||||
unit: z.enum([
|
||||
"items",
|
||||
@@ -265,8 +264,8 @@ const applicationGraphEvidenceBaseSchema = z.strictObject({
|
||||
location: applicationLocationReferenceSchema,
|
||||
extractor: applicationExtractorSchema,
|
||||
coverage: applicationCoverageSchema,
|
||||
limitations: z.array(boundedTextSchema).max(100),
|
||||
evidence_ids: z.array(z.string().regex(/^ev_[a-f0-9]{64}$/u)).max(100),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
evidence_ids: z.array(z.string().regex(/^ev_[a-f0-9]{64}$/u)),
|
||||
});
|
||||
|
||||
type EvidenceValue = z.infer<typeof applicationGraphEvidenceBaseSchema>;
|
||||
@@ -431,7 +430,7 @@ export const applicationNodeIdentitySchema = z.discriminatedUnion("strategy", [
|
||||
z.strictObject({
|
||||
strategy: z.literal("structural-fingerprint"),
|
||||
stability: z.literal("cross-version-inference"),
|
||||
algorithm: z.string().min(1).max(128),
|
||||
algorithm: z.string().min(1),
|
||||
fingerprint_sha256: digestSchema,
|
||||
basis: z
|
||||
.array(
|
||||
@@ -444,8 +443,7 @@ export const applicationNodeIdentitySchema = z.discriminatedUnion("strategy", [
|
||||
"api-usage",
|
||||
]),
|
||||
)
|
||||
.min(1)
|
||||
.max(6),
|
||||
.min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
strategy: z.literal("artifact-local-key"),
|
||||
|
||||
+68
-1
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
computeJavaScriptApplicationGraphSha256,
|
||||
createJavaScriptApplicationGraph,
|
||||
createJavaScriptApplicationNode,
|
||||
javascriptApplicationGraphSchema,
|
||||
parseJavaScriptApplicationGraph,
|
||||
serializeJavaScriptApplicationGraph,
|
||||
@@ -13,7 +14,11 @@ import {
|
||||
JAVASCRIPT_APPLICATION_NODE_KINDS,
|
||||
JAVASCRIPT_APPLICATION_RELATIONS,
|
||||
} from "./javascriptApplicationGraphSchemas.js";
|
||||
import { buildSyntheticJavaScriptApplicationGraph } from "./javascriptApplicationGraph.fixture.js";
|
||||
import {
|
||||
APPLICATION_GRAPH_DIGESTS,
|
||||
artifactEvidence,
|
||||
buildSyntheticJavaScriptApplicationGraph,
|
||||
} from "./javascriptApplicationGraph.fixture.js";
|
||||
|
||||
const nodeByLabel = (
|
||||
graph: JavaScriptApplicationGraph,
|
||||
@@ -26,6 +31,54 @@ const nodeByLabel = (
|
||||
return node;
|
||||
};
|
||||
|
||||
const createLargeNativeExportGraph = (): JavaScriptApplicationGraph => {
|
||||
const properties = Object.fromEntries(
|
||||
Array.from({ length: 1_001 }, (_, index) => [
|
||||
`${"export-property-"}${"k".repeat(120)}-${index}`,
|
||||
"v".repeat(4_097),
|
||||
]),
|
||||
);
|
||||
const nodes = Array.from({ length: 1_001 }, (_, index) => {
|
||||
const path = `native/exports/${index}.symbol`;
|
||||
return createJavaScriptApplicationNode({
|
||||
kind: "native-export",
|
||||
identity: {
|
||||
strategy: "canonical-path",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
path,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: index === 0 ? "large export graph label ".repeat(300) : path,
|
||||
properties: index === 0 ? properties : {},
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
path,
|
||||
"native-analysis-provider",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
const first = nodes[0];
|
||||
if (first === undefined) throw new TypeError("Missing native export");
|
||||
|
||||
return createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
root_node_ids: [first.node_id],
|
||||
nodes,
|
||||
edges: [],
|
||||
coverage: {
|
||||
status: "complete",
|
||||
truncated: false,
|
||||
omitted_count: 0,
|
||||
limits: [],
|
||||
},
|
||||
limitations: [],
|
||||
});
|
||||
};
|
||||
|
||||
describe("JavaScript Application Graph", () => {
|
||||
it("defines the complete provider-neutral node and relation vocabulary", () => {
|
||||
expect(JAVASCRIPT_APPLICATION_NODE_KINDS).toEqual([
|
||||
@@ -102,6 +155,20 @@ describe("JavaScript Application Graph", () => {
|
||||
).toEqual(graph);
|
||||
});
|
||||
|
||||
it("keeps large native-export graphs and their complete properties", () => {
|
||||
const graph = createLargeNativeExportGraph();
|
||||
const largeExport = graph.nodes.find(({ observations }) =>
|
||||
observations.some(({ label }) =>
|
||||
label?.startsWith("large export graph label "),
|
||||
),
|
||||
);
|
||||
|
||||
expect(graph.nodes).toHaveLength(1_001);
|
||||
expect(
|
||||
Object.keys(largeExport?.observations[0]?.properties ?? {}),
|
||||
).toHaveLength(1_001);
|
||||
});
|
||||
|
||||
it("represents the synthetic ASAR to preload to IPC to native chain", () => {
|
||||
const graph = buildSyntheticJavaScriptApplicationGraph();
|
||||
const labels = [
|
||||
|
||||
+4
-4
@@ -26,7 +26,7 @@ const contentNode = (
|
||||
});
|
||||
|
||||
describe("JavaScript Application Graph", () => {
|
||||
it("rejects false truncation claims and unbounded properties", () => {
|
||||
it("rejects false truncation claims and accepts large properties", () => {
|
||||
const truncated = artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/module.js",
|
||||
@@ -75,11 +75,11 @@ describe("JavaScript Application Graph", () => {
|
||||
const properties = Object.fromEntries(
|
||||
Array.from({ length: 65 }, (_, index) => [`key-${String(index)}`, index]),
|
||||
);
|
||||
expect(() =>
|
||||
expect(
|
||||
contentNode(
|
||||
artifactEvidence(APPLICATION_GRAPH_DIGESTS.asar, "dist/module.js"),
|
||||
properties,
|
||||
),
|
||||
).toThrow(/exceed 64 keys/u);
|
||||
).observations[0]?.properties,
|
||||
).toEqual(properties);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,10 +5,10 @@ import {
|
||||
applicationGraphEvidenceSchema,
|
||||
applicationNodeIdentitySchema,
|
||||
} from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import { isJsonWithinLimits } from "./jsonLimits.js";
|
||||
import { isJsonWithinDepth } from "./jsonLimits.js";
|
||||
import { jsonValueSchema } from "./jsonValue.js";
|
||||
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
|
||||
/** Node kinds admitted by JavaScript Application Graph. */
|
||||
export const JAVASCRIPT_APPLICATION_NODE_KINDS = [
|
||||
@@ -71,29 +71,18 @@ export const JAVASCRIPT_APPLICATION_RELATIONS = [
|
||||
const applicationRelationSchema = z.enum(JAVASCRIPT_APPLICATION_RELATIONS);
|
||||
|
||||
const applicationPropertiesSchema = z
|
||||
.record(z.string().min(1).max(128), jsonValueSchema)
|
||||
.record(z.string().min(1), jsonValueSchema)
|
||||
.superRefine((properties, context) => {
|
||||
if (Object.keys(properties).length > 64)
|
||||
if (!isJsonWithinDepth(properties, 6))
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
message: "Application graph properties exceed 64 keys",
|
||||
});
|
||||
if (
|
||||
!isJsonWithinLimits(properties, {
|
||||
maxDepth: 6,
|
||||
maxNodes: 512,
|
||||
maxStringLength: 4_096,
|
||||
})
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
message: "Application graph properties exceed structural limits",
|
||||
message: "Application graph properties exceed the supported depth",
|
||||
});
|
||||
});
|
||||
|
||||
/** One node observation before its semantic identifier is derived. */
|
||||
const applicationNodeObservationInputSchema = z.strictObject({
|
||||
label: z.string().min(1).max(1_024).nullable(),
|
||||
label: z.string().min(1).nullable(),
|
||||
properties: applicationPropertiesSchema,
|
||||
evidence: applicationGraphEvidenceSchema,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { parse } from "@babel/parser";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { fingerprintJavaScriptAst } from "../../src/domain/javascriptAstFingerprint.js";
|
||||
|
||||
describe("JavaScript AST fingerprints", () => {
|
||||
it("includes complete literal values in the fingerprint", () => {
|
||||
const prefix = "x".repeat(1_024);
|
||||
const left = parse(`const value = ${JSON.stringify(`${prefix}left`)};`);
|
||||
const right = parse(`const value = ${JSON.stringify(`${prefix}right`)};`);
|
||||
|
||||
expect(fingerprintJavaScriptAst(left, 100).sha256).not.toBe(
|
||||
fingerprintJavaScriptAst(right, 100).sha256,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -55,24 +55,24 @@ export const collectJavaScriptExports = (node: t.Node): StaticExports => {
|
||||
|
||||
const semanticTokens = (node: t.Node): string[] => {
|
||||
const tokens = [`node:${node.type}`];
|
||||
if (t.isStringLiteral(node)) tokens.push(`string:${bounded(node.value)}`);
|
||||
if (t.isStringLiteral(node)) tokens.push(`string:${node.value}`);
|
||||
else if (t.isNumericLiteral(node))
|
||||
tokens.push(`number:${String(node.value)}`);
|
||||
else if (t.isBooleanLiteral(node))
|
||||
tokens.push(`boolean:${String(node.value)}`);
|
||||
else if (t.isRegExpLiteral(node))
|
||||
tokens.push(`regexp:${bounded(node.pattern)}/${node.flags}`);
|
||||
tokens.push(`regexp:${node.pattern}/${node.flags}`);
|
||||
else if (t.isBinaryExpression(node) || t.isLogicalExpression(node))
|
||||
tokens.push(`operator:${node.operator}`);
|
||||
else if (t.isUnaryExpression(node) || t.isUpdateExpression(node))
|
||||
tokens.push(`operator:${node.operator}`);
|
||||
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
||||
const property = propertyName(node.property);
|
||||
if (property !== "") tokens.push(`property:${bounded(property)}`);
|
||||
if (property !== "") tokens.push(`property:${property}`);
|
||||
}
|
||||
if ((t.isObjectProperty(node) || t.isObjectMethod(node)) && !node.computed) {
|
||||
const key = propertyName(node.key);
|
||||
if (key !== "") tokens.push(`key:${bounded(key)}`);
|
||||
if (key !== "") tokens.push(`key:${key}`);
|
||||
}
|
||||
return tokens;
|
||||
};
|
||||
@@ -156,7 +156,5 @@ const propertyName = (node: t.Node): string => {
|
||||
const stringValue = (node: t.Node | null | undefined): string | undefined =>
|
||||
t.isStringLiteral(node) ? node.value : undefined;
|
||||
|
||||
const bounded = (value: string): string => value.slice(0, 1_024);
|
||||
|
||||
const compareCodePoints = (left: string, right: string): number =>
|
||||
left < right ? -1 : left > right ? 1 : 0;
|
||||
|
||||
@@ -106,7 +106,7 @@ const requestedExports = (nodes: readonly ApplicationNode[]): string[] => {
|
||||
...stringArray(observation.properties.members),
|
||||
]),
|
||||
);
|
||||
return [...new Set(values)].sort(compareCodePoints).slice(0, 1_000);
|
||||
return [...new Set(values)].sort(compareCodePoints);
|
||||
};
|
||||
|
||||
const stringArray = (value: unknown): string[] =>
|
||||
|
||||
@@ -3,11 +3,10 @@ import { z } from "zod";
|
||||
import { evidenceEnvelopeSchema } from "./evidence.js";
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const absolutePathSchema = z.string().startsWith("/").max(4096);
|
||||
const absolutePathSchema = z.string().startsWith("/");
|
||||
const aliasSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(256)
|
||||
.regex(/^[A-Za-z0-9_./:@-]+$/u);
|
||||
|
||||
const replayModuleSchema = z
|
||||
@@ -16,7 +15,7 @@ const replayModuleSchema = z
|
||||
path: absolutePathSchema,
|
||||
format: z.enum(["esm", "commonjs-factory"]),
|
||||
role: z.enum(["module", "stub"]).default("module"),
|
||||
dependencies: z.record(z.string().min(1).max(256), aliasSchema).default({}),
|
||||
dependencies: z.record(z.string().min(1), aliasSchema).default({}),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -24,13 +23,13 @@ const replaySideSchema = z
|
||||
.object({
|
||||
modules: z.array(replayModuleSchema).min(1),
|
||||
entry_alias: aliasSchema,
|
||||
entry_export: z.string().min(1).max(256).default("default"),
|
||||
entry_export: z.string().min(1).default("default"),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const explicitCaseSchema = z
|
||||
.object({
|
||||
case_id: z.string().min(1).max(128),
|
||||
case_id: z.string().min(1),
|
||||
arguments: z.array(z.json()),
|
||||
})
|
||||
.strict();
|
||||
@@ -43,59 +42,59 @@ const generatorSchema = z
|
||||
"clipboard-boundaries",
|
||||
]),
|
||||
seed: z.number().int().min(0).max(0xffff_ffff),
|
||||
count: z.number().int().min(1).max(64),
|
||||
count: z.number().int().safe().min(1),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const replayLimitsSchema = z
|
||||
.object({
|
||||
wall_time_ms: z.number().int().min(100).max(10_000).default(3_000),
|
||||
wall_time_ms: z.number().int().safe().min(1).default(3_000),
|
||||
memory_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(16 * 1024 * 1024)
|
||||
.max(512 * 1024 * 1024)
|
||||
.safe()
|
||||
.positive()
|
||||
.default(128 * 1024 * 1024),
|
||||
tasks: z.number().int().min(1).max(32).default(8),
|
||||
cpu_quota_percent: z.number().int().min(1).max(100).default(50),
|
||||
tasks: z.number().int().safe().min(1).default(8),
|
||||
cpu_quota_percent: z.number().int().safe().min(1).default(50),
|
||||
tmpfs_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1024 * 1024)
|
||||
.max(64 * 1024 * 1024)
|
||||
.safe()
|
||||
.min(1)
|
||||
.default(16 * 1024 * 1024),
|
||||
module_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.min(1)
|
||||
.max(16 * 1024 * 1024)
|
||||
.default(4 * 1024 * 1024),
|
||||
input_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.min(1)
|
||||
.max(1024 * 1024)
|
||||
.default(256 * 1024),
|
||||
protocol_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1024 * 1024)
|
||||
.max(64 * 1024 * 1024)
|
||||
.safe()
|
||||
.min(1)
|
||||
.default(16 * 1024 * 1024),
|
||||
output_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.min(1)
|
||||
.max(4 * 1024 * 1024)
|
||||
.default(512 * 1024),
|
||||
stderr_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.min(0)
|
||||
.max(256 * 1024)
|
||||
.default(32 * 1024),
|
||||
result_depth: z.number().int().min(1).max(64).default(16),
|
||||
result_nodes: z.number().int().min(1).max(100_000).default(10_000),
|
||||
result_depth: z.number().int().safe().min(1).default(16),
|
||||
result_nodes: z.number().int().safe().min(1).default(10_000),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -258,7 +257,6 @@ const replayPlanSchema = z
|
||||
.object({
|
||||
path: z.string().min(1),
|
||||
include_sources: z.boolean(),
|
||||
authority: z.literal("evidence_write"),
|
||||
})
|
||||
.strict()
|
||||
.nullable(),
|
||||
|
||||
@@ -7,24 +7,21 @@ import {
|
||||
browserOriginSchema,
|
||||
} from "./browserObservation.js";
|
||||
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const observationTextSchema = z.string().min(1);
|
||||
|
||||
const runtimeFileRootsSchema = z
|
||||
.array(
|
||||
z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(16_384)
|
||||
.refine(isAbsolute, "Runtime file roots must be absolute paths")
|
||||
.overwrite(resolve),
|
||||
)
|
||||
.max(32)
|
||||
.overwrite((roots) => [...new Set(roots)].sort())
|
||||
.default([]);
|
||||
|
||||
const runtimeOriginsSchema = z
|
||||
.array(browserOriginSchema)
|
||||
.max(32)
|
||||
.overwrite((origins) => [...new Set(origins)].sort())
|
||||
.default([]);
|
||||
|
||||
@@ -72,24 +69,21 @@ const observedJavaScriptRuntimeKindSchema = javascriptRuntimeKindSchema.or(
|
||||
z.literal("unknown"),
|
||||
);
|
||||
|
||||
/** Maximum accepted source location byte length in one inspector event. */
|
||||
export const MAX_JAVASCRIPT_RUNTIME_LOCATION_BYTES = 16_384;
|
||||
|
||||
/** Input for one bounded, attach-only V8 Inspector observation. */
|
||||
export const observeJavaScriptRuntimeToolInputSchema = z.strictObject({
|
||||
discovery_evidence_id: z.string().min(1),
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
target_id: z.string().trim().min(1),
|
||||
runtime_kind: javascriptRuntimeKindSchema.optional(),
|
||||
observation_ms: z.number().int().min(0).max(10_000).default(100),
|
||||
observation_ms: z.number().int().min(0).default(100),
|
||||
});
|
||||
|
||||
/** Input after discovery Evidence supplies the authorized target scope. */
|
||||
export const observeJavaScriptRuntimeInputSchema = z
|
||||
.strictObject({
|
||||
...runtimeScope,
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
target_id: z.string().trim().min(1),
|
||||
runtime_kind: javascriptRuntimeKindSchema.optional(),
|
||||
observation_ms: z.number().int().min(0).max(10_000).default(100),
|
||||
observation_ms: z.number().int().min(0).default(100),
|
||||
})
|
||||
.superRefine(requireRuntimeScope);
|
||||
export type ObserveJavaScriptRuntimeInput = z.infer<
|
||||
@@ -97,25 +91,25 @@ export type ObserveJavaScriptRuntimeInput = z.infer<
|
||||
>;
|
||||
|
||||
export const javascriptRuntimeVersionSchema = z.strictObject({
|
||||
product: z.string().min(1).max(1_024),
|
||||
protocol_version: z.string().min(1).max(100),
|
||||
v8_version: z.string().max(1_024).nullable(),
|
||||
product: z.string().min(1),
|
||||
protocol_version: z.string().min(1),
|
||||
v8_version: z.string().nullable(),
|
||||
});
|
||||
|
||||
export const javascriptRuntimeLocationSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
kind: z.literal("file"),
|
||||
file_path: z.string().min(1).max(16_384),
|
||||
file_path: z.string().min(1),
|
||||
authority: z.literal("scope-fallback").optional(),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("url"),
|
||||
origin: z.string().min(1).max(2_048),
|
||||
sanitized_url: z.string().min(1).max(65_536),
|
||||
origin: z.string().min(1),
|
||||
sanitized_url: z.string().min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("builtin"),
|
||||
specifier: z.string().min(1).max(4_096),
|
||||
specifier: z.string().min(1),
|
||||
}),
|
||||
]);
|
||||
export type JavaScriptRuntimeLocation = z.infer<
|
||||
@@ -123,8 +117,8 @@ export type JavaScriptRuntimeLocation = z.infer<
|
||||
>;
|
||||
|
||||
const javascriptRuntimeTargetSchema = z.strictObject({
|
||||
target_id: z.string().min(1).max(256),
|
||||
protocol_type: z.string().min(1).max(100),
|
||||
target_id: z.string().min(1),
|
||||
protocol_type: z.string().min(1),
|
||||
attached: z.boolean(),
|
||||
location: javascriptRuntimeLocationSchema,
|
||||
});
|
||||
@@ -139,7 +133,7 @@ export const javascriptRuntimeTargetListSchema = z.strictObject({
|
||||
unsupported_location: z.number().int().min(0),
|
||||
unconnectable: z.number().int().min(0),
|
||||
}),
|
||||
limitations: z.array(boundedTextSchema).max(100),
|
||||
limitations: z.array(observationTextSchema),
|
||||
});
|
||||
export type JavaScriptRuntimeTargetList = z.infer<
|
||||
typeof javascriptRuntimeTargetListSchema
|
||||
@@ -148,18 +142,18 @@ export type JavaScriptRuntimeTargetList = z.infer<
|
||||
const javascriptRuntimeScriptSchema = z.strictObject({
|
||||
script_key: z.string().regex(/^v8_script_[a-f0-9]{64}$/u),
|
||||
location: javascriptRuntimeLocationSchema,
|
||||
execution_context_key: z.string().max(64).nullable(),
|
||||
cdp_hash: z.string().max(512).nullable(),
|
||||
execution_context_key: z.string().nullable(),
|
||||
cdp_hash: z.string().nullable(),
|
||||
length: z.number().int().min(0),
|
||||
is_module: z.boolean(),
|
||||
status: z.literal("observed-loaded"),
|
||||
});
|
||||
|
||||
const javascriptRuntimeContextSchema = z.strictObject({
|
||||
context_key: z.string().min(1).max(64),
|
||||
context_key: z.string().min(1),
|
||||
state: z.enum(["created", "destroyed", "cleared"]),
|
||||
name: z.string().max(1_024).nullable(),
|
||||
origin: z.string().max(4_096).nullable(),
|
||||
name: z.string().nullable(),
|
||||
origin: z.string().nullable(),
|
||||
});
|
||||
|
||||
/** Deterministic passive script/context snapshot from one bounded window. */
|
||||
@@ -179,7 +173,7 @@ export const javascriptRuntimeObservationSchema = z.strictObject({
|
||||
events_dropped: z.number().int().min(0),
|
||||
metadata_bytes_retained: z.number().int().min(0),
|
||||
truncated: z.boolean(),
|
||||
truncation_reasons: z.array(boundedTextSchema).max(20),
|
||||
truncation_reasons: z.array(observationTextSchema),
|
||||
}),
|
||||
scripts: z.strictObject({
|
||||
items: z.array(javascriptRuntimeScriptSchema),
|
||||
@@ -192,10 +186,10 @@ export const javascriptRuntimeObservationSchema = z.strictObject({
|
||||
}),
|
||||
}),
|
||||
execution_contexts: z.array(javascriptRuntimeContextSchema),
|
||||
directly_observed: z.array(boundedTextSchema).max(20),
|
||||
unavailable_without_instrumentation: z.array(boundedTextSchema).max(20),
|
||||
unknowns: z.array(boundedTextSchema).max(100),
|
||||
limitations: z.array(boundedTextSchema).max(100),
|
||||
directly_observed: z.array(observationTextSchema),
|
||||
unavailable_without_instrumentation: z.array(observationTextSchema),
|
||||
unknowns: z.array(observationTextSchema),
|
||||
limitations: z.array(observationTextSchema),
|
||||
});
|
||||
export type JavaScriptRuntimeObservation = z.infer<
|
||||
typeof javascriptRuntimeObservationSchema
|
||||
|
||||
@@ -50,7 +50,7 @@ export const parseActiveElectronCapture = (
|
||||
};
|
||||
};
|
||||
|
||||
const absolutePathSchema = z.string().min(1).max(16_384).refine(isAbsolute);
|
||||
const absolutePathSchema = z.string().min(1).refine(isAbsolute);
|
||||
|
||||
const assertIdentity = (evidence: Evidence): void => {
|
||||
if (
|
||||
|
||||
@@ -279,11 +279,9 @@ const assertV8RuntimeParameters = (
|
||||
const parameters = z
|
||||
.object({
|
||||
inspector_endpoint: browserEndpointSchema,
|
||||
allowed_file_roots: z
|
||||
.array(z.string().min(1).max(16_384).refine(isAbsolute))
|
||||
.max(32),
|
||||
allowed_origins: z.array(browserOriginSchema).max(32),
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
allowed_file_roots: z.array(z.string().min(1).refine(isAbsolute)),
|
||||
allowed_origins: z.array(browserOriginSchema),
|
||||
target_id: z.string().trim().min(1),
|
||||
runtime_kind: javascriptRuntimeKindSchema.optional(),
|
||||
})
|
||||
.passthrough()
|
||||
@@ -405,7 +403,7 @@ const assertRuntimeParameters = (
|
||||
},
|
||||
): void => {
|
||||
const common = {
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
target_id: z.string().trim().min(1),
|
||||
cdp_endpoint: browserEndpointSchema,
|
||||
include_script_sources: z.boolean(),
|
||||
};
|
||||
|
||||
@@ -89,7 +89,7 @@ const targetEntity = (
|
||||
label: target.title,
|
||||
properties: {
|
||||
runtime_type: target.type,
|
||||
location: location.value.slice(0, 4_096),
|
||||
location: location.value,
|
||||
attached: target.attached,
|
||||
},
|
||||
section: "target",
|
||||
@@ -117,7 +117,7 @@ const frameEntities = (
|
||||
label: location.value,
|
||||
properties: {
|
||||
parent_frame_id: frame.parent_frame_id,
|
||||
location: location.value.slice(0, 4_096),
|
||||
location: location.value,
|
||||
},
|
||||
section: "frames",
|
||||
});
|
||||
@@ -145,7 +145,7 @@ const scriptEntities = (
|
||||
: null,
|
||||
label: location.value,
|
||||
properties: {
|
||||
location: location.value.slice(0, 4_096),
|
||||
location: location.value,
|
||||
cdp_hash: script.cdp_hash,
|
||||
length: script.length,
|
||||
is_module: script.is_module,
|
||||
@@ -186,7 +186,7 @@ const workerEntities = (
|
||||
label: location.value,
|
||||
properties: {
|
||||
runtime_type: worker.type,
|
||||
location: location.value.slice(0, 4_096),
|
||||
location: location.value,
|
||||
attached: worker.attached,
|
||||
opener_target_id: worker.opener_target_id,
|
||||
parent_frame_id: worker.parent_frame_id,
|
||||
@@ -233,7 +233,7 @@ const runtimeEntity = (
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: input.label.slice(0, 1_024) || null,
|
||||
label: input.label || null,
|
||||
properties: input.properties,
|
||||
evidence: runtimeEvidence(capture, input),
|
||||
},
|
||||
|
||||
@@ -11,10 +11,9 @@ import {
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const nodeIdSchema = z.string().regex(/^jag_node_[a-f0-9]{64}$/u);
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
const safePrefixSchema = z
|
||||
.string()
|
||||
.max(4_096)
|
||||
.refine(
|
||||
(value) =>
|
||||
value === "" ||
|
||||
@@ -29,7 +28,6 @@ const runtimeFileMappingSchema = z.strictObject({
|
||||
root: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(16_384)
|
||||
.refine(isAbsolute, "Runtime file mapping root must be absolute")
|
||||
.overwrite((value) => resolve(value)),
|
||||
artifact_prefix: safePrefixSchema.default(""),
|
||||
@@ -40,7 +38,6 @@ const runtimeUrlMappingSchema = z.strictObject({
|
||||
prefix: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(16_384)
|
||||
.refine(
|
||||
(value) => normalizeRuntimeUrlPrefix(value) !== null,
|
||||
"Runtime URL prefix must be HTTP(S) without credentials, query, or fragment",
|
||||
@@ -144,7 +141,7 @@ const layerSummarySchema = z.strictObject({
|
||||
evidence_id: evidenceIdSchema,
|
||||
graph_id: z.string().regex(/^jag_[a-f0-9]{64}$/u),
|
||||
root_artifact_sha256: digestSchema,
|
||||
input_path: z.string().min(1).max(16_384),
|
||||
input_path: z.string().min(1),
|
||||
format: z.enum(["asar", "directory"]),
|
||||
runtime_mappings: z.array(runtimeLocationMappingSchema),
|
||||
});
|
||||
@@ -155,7 +152,7 @@ const captureSummarySchema = z.strictObject({
|
||||
kind: z.enum(["browser", "electron", "v8-inspector", "electron-active"]),
|
||||
target_node_id: nodeIdSchema,
|
||||
target_key: boundedTextSchema,
|
||||
target_location: z.string().min(1).max(131_072),
|
||||
target_location: z.string().min(1),
|
||||
frames: z.number().int().min(0),
|
||||
scripts: z.number().int().min(0),
|
||||
workers: z.number().int().min(0),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { applicationGraphEvidenceSchema } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import { isJsonWithinLimits } from "./jsonLimits.js";
|
||||
import { isJsonWithinDepth } from "./jsonLimits.js";
|
||||
import { jsonValueSchema } from "./jsonValue.js";
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
const semanticNodeIdSchema = z.string().regex(/^jsrg_node_[a-f0-9]{64}$/u);
|
||||
const semanticRelationIdSchema = z
|
||||
.string()
|
||||
@@ -192,18 +192,12 @@ const sourceRangeSchema = z
|
||||
});
|
||||
|
||||
const semanticPropertiesSchema = z
|
||||
.record(z.string().min(1).max(128), jsonValueSchema)
|
||||
.record(z.string().min(1), jsonValueSchema)
|
||||
.superRefine((properties, context) => {
|
||||
if (
|
||||
!isJsonWithinLimits(properties, {
|
||||
maxDepth: 6,
|
||||
maxNodes: 512,
|
||||
maxStringLength: 4_096,
|
||||
})
|
||||
)
|
||||
if (!isJsonWithinDepth(properties, 6))
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
message: "Semantic properties exceed structural limits",
|
||||
message: "Semantic properties exceed the supported depth",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -211,7 +205,7 @@ const semanticNodeIdentitySchema = z.strictObject({
|
||||
artifact_sha256: digestSchema,
|
||||
module_path: relativePathSchema,
|
||||
source_range: sourceRangeSchema.nullable(),
|
||||
role_key: z.string().min(1).max(1_024),
|
||||
role_key: z.string().min(1),
|
||||
});
|
||||
|
||||
/** One semantic entity before its canonical identifier is derived. */
|
||||
@@ -220,7 +214,7 @@ export const javaScriptSemanticNodeInputSchema = z.strictObject({
|
||||
identity: semanticNodeIdentitySchema,
|
||||
function_node_id: semanticNodeIdSchema.nullable(),
|
||||
application_node_ids: z.array(z.string().regex(/^jag_node_[a-f0-9]{64}$/u)),
|
||||
label: z.string().min(1).max(1_024).nullable(),
|
||||
label: z.string().min(1).nullable(),
|
||||
properties: semanticPropertiesSchema,
|
||||
evidence: applicationGraphEvidenceSchema,
|
||||
});
|
||||
@@ -271,7 +265,7 @@ export const JAVASCRIPT_SEMANTIC_UNKNOWN_REASONS = [
|
||||
export const javaScriptSemanticUnknownInputSchema = z.strictObject({
|
||||
node_id: semanticNodeIdSchema.nullable(),
|
||||
family: z.enum(JAVASCRIPT_SEMANTIC_RELATION_FAMILIES),
|
||||
relation_kinds: z.array(z.enum(JAVASCRIPT_SEMANTIC_RELATIONS)).min(1).max(45),
|
||||
relation_kinds: z.array(z.enum(JAVASCRIPT_SEMANTIC_RELATIONS)).min(1),
|
||||
reason: z.enum(JAVASCRIPT_SEMANTIC_UNKNOWN_REASONS),
|
||||
detail: boundedTextSchema,
|
||||
candidate_node_ids: z.array(semanticNodeIdSchema),
|
||||
@@ -285,24 +279,22 @@ export const javaScriptSemanticUnknownSchema =
|
||||
});
|
||||
|
||||
const fingerprintComponentsSchema = z.strictObject({
|
||||
parameter_arity: z.number().int().min(0).max(10_000),
|
||||
parameter_arity: z.number().int().min(0),
|
||||
normalized_ast_sha256: digestSchema,
|
||||
control_flow_sha256: digestSchema,
|
||||
relation_shape_sha256: digestSchema,
|
||||
literal_set_sha256: digestSchema,
|
||||
effects: z
|
||||
.array(
|
||||
z.enum([
|
||||
"async",
|
||||
"child-process",
|
||||
"event",
|
||||
"network",
|
||||
"promise",
|
||||
"resource",
|
||||
"timer",
|
||||
]),
|
||||
)
|
||||
.max(7),
|
||||
effects: z.array(
|
||||
z.enum([
|
||||
"async",
|
||||
"child-process",
|
||||
"event",
|
||||
"network",
|
||||
"promise",
|
||||
"resource",
|
||||
"timer",
|
||||
]),
|
||||
),
|
||||
});
|
||||
|
||||
/** One bounded rename-resistant function fingerprint. */
|
||||
@@ -311,7 +303,7 @@ export const javaScriptSemanticFingerprintInputSchema = z.strictObject({
|
||||
algorithm: z.literal("rea.javascript-semantic-function"),
|
||||
status: z.enum(["complete", "partial", "unavailable"]),
|
||||
components: fingerprintComponentsSchema,
|
||||
limitations: z.array(boundedTextSchema).max(100),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
evidence: applicationGraphEvidenceSchema,
|
||||
});
|
||||
|
||||
@@ -337,7 +329,7 @@ const graphCoverageSchema = z.strictObject({
|
||||
omitted_relations: z.number().int().min(0).nullable(),
|
||||
limits: z.array(
|
||||
z.strictObject({
|
||||
name: z.string().min(1).max(128),
|
||||
name: z.string().min(1),
|
||||
value: z.number().int().min(0),
|
||||
unit: z.enum(["items", "bytes", "milliseconds", "depth", "other"]),
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { isJsonWithinLimits } from "./jsonLimits.js";
|
||||
import { isJsonWithinDepth, isJsonWithinLimits } from "./jsonLimits.js";
|
||||
|
||||
const limits = {
|
||||
maxDepth: 3,
|
||||
@@ -9,6 +9,18 @@ const limits = {
|
||||
};
|
||||
|
||||
describe("JSON limits", () => {
|
||||
it("checks depth without rejecting large keys, collections, or strings", () => {
|
||||
const properties = Object.fromEntries(
|
||||
Array.from({ length: 1_001 }, (_, index) => [
|
||||
`${"k".repeat(128)}${index}`,
|
||||
"v".repeat(4_097),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(isJsonWithinDepth(properties, 6)).toBe(true);
|
||||
expect(isJsonWithinDepth({ nested: { value: true } }, 1)).toBe(false);
|
||||
});
|
||||
|
||||
it("traverses nested object and array values", () => {
|
||||
expect(isJsonWithinLimits({ one: ["two", { three: 3 }] }, limits)).toBe(
|
||||
true,
|
||||
|
||||
@@ -5,6 +5,22 @@ export interface JsonLimits {
|
||||
readonly maxNodes: number;
|
||||
}
|
||||
|
||||
/** Return whether a JSON value fits a depth constraint without size quotas. */
|
||||
export const isJsonWithinDepth = (root: unknown, maxDepth: number): boolean => {
|
||||
const pending: Array<{ readonly value: unknown; readonly depth: number }> = [
|
||||
{ value: root, depth: 0 },
|
||||
];
|
||||
while (pending.length > 0) {
|
||||
const current = pending.pop();
|
||||
if (current === undefined) break;
|
||||
if (current.depth > maxDepth) return false;
|
||||
if (typeof current.value !== "object" || current.value === null) continue;
|
||||
for (const value of Object.values(current.value))
|
||||
pending.push({ value, depth: current.depth + 1 });
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/** Return whether every node, key, and string fits within the supplied limits. */
|
||||
export const isJsonWithinLimits = (
|
||||
root: unknown,
|
||||
|
||||
@@ -50,6 +50,12 @@ describe("managed member comparison", () => {
|
||||
expect(result.limitations).toContain(
|
||||
"Names are reported as observations but are not used as a matching basis.",
|
||||
);
|
||||
expect(
|
||||
managedMemberComparisonResultSchema.safeParse({
|
||||
...result,
|
||||
limitations: Array.from({ length: 101 }, () => "x".repeat(4_097)),
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("uses structural method shape when build-local token operands drift", () => {
|
||||
|
||||
@@ -21,7 +21,7 @@ import { keyMembers, sha256 } from "./managedMemberComparisonMatch.js";
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const tokenSchema = z.string().regex(/^0x[0-9a-f]{8}$/u);
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
|
||||
/** Two authenticated managed member observations. */
|
||||
export const compareManagedMembersInputSchema = z
|
||||
@@ -113,26 +113,24 @@ const comparisonItemSchema = <
|
||||
|
||||
const comparisonItemContextShape = {
|
||||
evidence_links: z.array(evidenceIdSchema).length(2),
|
||||
limitations: z.array(boundedTextSchema).max(100),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
};
|
||||
|
||||
const methodComparisonItemSchema = comparisonItemSchema(
|
||||
{
|
||||
...comparisonItemContextShape,
|
||||
item_id: z.string().regex(/^mmc_method_[a-f0-9]{64}$/u),
|
||||
dimensions: z
|
||||
.array(
|
||||
z.enum([
|
||||
"signature",
|
||||
"cil",
|
||||
"opcode-shape",
|
||||
"call-shape",
|
||||
"field-shape",
|
||||
"exception-shape",
|
||||
"availability",
|
||||
]),
|
||||
)
|
||||
.max(7),
|
||||
dimensions: z.array(
|
||||
z.enum([
|
||||
"signature",
|
||||
"cil",
|
||||
"opcode-shape",
|
||||
"call-shape",
|
||||
"field-shape",
|
||||
"exception-shape",
|
||||
"availability",
|
||||
]),
|
||||
),
|
||||
},
|
||||
memberIdentitySchema,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createEvidence } from "./evidence.js";
|
||||
import { managedReconstructionImportInputSchema } from "./managedReconstruction.js";
|
||||
|
||||
describe("managed reconstruction import input", () => {
|
||||
it("accepts more than the former 50-method and 100-note ceilings", () => {
|
||||
const evidence = createEvidence(
|
||||
undefined,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: {},
|
||||
},
|
||||
);
|
||||
const method = {
|
||||
token: "0x06000001",
|
||||
signature_sha256: "a".repeat(64),
|
||||
normalized_il_sha256: null,
|
||||
reconstruction: {
|
||||
kind: "semantic-pseudocode",
|
||||
language: "pseudocode",
|
||||
text: "return;",
|
||||
},
|
||||
};
|
||||
|
||||
const parsed = managedReconstructionImportInputSchema.parse({
|
||||
static_members: evidence,
|
||||
decompiler: {
|
||||
name: "Fixture decompiler",
|
||||
version: null,
|
||||
family: "other",
|
||||
executable_sha256: null,
|
||||
options: Array.from({ length: 51 }, (_, index) => `option-${index}`),
|
||||
},
|
||||
methods: Array.from({ length: 51 }, (_, index) => ({
|
||||
...method,
|
||||
token: `0x${(0x06000001 + index).toString(16).padStart(8, "0")}`,
|
||||
signature_sha256: index.toString(16).padStart(64, "0"),
|
||||
})),
|
||||
notes: Array.from({ length: 101 }, (_, index) => `note-${index}`),
|
||||
});
|
||||
|
||||
expect(parsed.methods).toHaveLength(51);
|
||||
expect(parsed.decompiler.options).toHaveLength(51);
|
||||
expect(parsed.notes).toHaveLength(101);
|
||||
});
|
||||
});
|
||||
@@ -22,7 +22,7 @@ const decompilerSchema = z.strictObject({
|
||||
version: z.string().min(1).max(128).nullable(),
|
||||
family: z.enum(["ilspy", "dnspy", "dnlib", "mono-cecil", "other"]),
|
||||
executable_sha256: digestSchema.nullable(),
|
||||
options: z.array(z.string().max(512)).max(50).default([]),
|
||||
options: z.array(z.string().max(512)).default([]),
|
||||
});
|
||||
|
||||
const managedReconstructionMethodInputSchema = z.strictObject({
|
||||
@@ -47,8 +47,8 @@ type ManagedReconstructionMethodInput = z.infer<
|
||||
export const managedReconstructionImportInputSchema = z.strictObject({
|
||||
static_members: evidenceSchema,
|
||||
decompiler: decompilerSchema,
|
||||
methods: z.array(managedReconstructionMethodInputSchema).min(1).max(50),
|
||||
notes: z.array(z.string().min(1).max(4_096)).max(100).default([]),
|
||||
methods: z.array(managedReconstructionMethodInputSchema).min(1),
|
||||
notes: z.array(z.string().min(1).max(4_096)).default([]),
|
||||
});
|
||||
|
||||
const importedMethodSchema = z.strictObject({
|
||||
@@ -95,16 +95,16 @@ export const managedReconstructionImportResultSchema = z.strictObject({
|
||||
options_sha256: digestSchema,
|
||||
}),
|
||||
summary: z.strictObject({
|
||||
imported_methods: z.number().int().min(1).max(50),
|
||||
decompiled_csharp_methods: z.number().int().min(0).max(50),
|
||||
decompiled_il_methods: z.number().int().min(0).max(50),
|
||||
pseudocode_methods: z.number().int().min(0).max(50),
|
||||
imported_methods: z.number().int().min(1),
|
||||
decompiled_csharp_methods: z.number().int().min(0),
|
||||
decompiled_il_methods: z.number().int().min(0),
|
||||
pseudocode_methods: z.number().int().min(0),
|
||||
total_text_bytes: z.number().int().min(1),
|
||||
}),
|
||||
methods: z.array(importedMethodSchema).min(1).max(50),
|
||||
notes: z.array(z.string().min(1).max(4_096)).max(100),
|
||||
methods: z.array(importedMethodSchema).min(1),
|
||||
notes: z.array(z.string().min(1).max(4_096)),
|
||||
evidence_links: z.array(evidenceIdSchema).length(1),
|
||||
limitations: z.array(z.string().min(1).max(4_096)).max(1_000),
|
||||
limitations: z.array(z.string().min(1).max(4_096)),
|
||||
});
|
||||
|
||||
export type ManagedReconstructionImportInput = z.infer<
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { JsonValue } from "./jsonValue.js";
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const tokenSchema = z.string().regex(/^0x[0-9a-f]{8}$/u);
|
||||
const boundedTextSchema = z.string().min(1).max(4_096);
|
||||
const boundedTextSchema = z.string().min(1);
|
||||
|
||||
const managedRuntimeEffectSchema = z.enum([
|
||||
"attach",
|
||||
@@ -30,9 +30,9 @@ const managedRuntimeHostSchema = z.strictObject({
|
||||
});
|
||||
|
||||
const managedRuntimeBoundsSchema = z.strictObject({
|
||||
timeout_ms: z.number().int().min(1).max(60_000).default(5_000),
|
||||
max_threads: z.number().int().min(1).max(256).default(32),
|
||||
max_output_bytes: z.number().int().min(0).max(1_048_576).default(65_536),
|
||||
timeout_ms: z.number().int().min(1).default(5_000),
|
||||
max_threads: z.number().int().min(1).default(32),
|
||||
max_output_bytes: z.number().int().min(0).default(65_536),
|
||||
allow_network: z.literal(false).default(false),
|
||||
allow_ui: z.literal(false).default(false),
|
||||
});
|
||||
@@ -109,7 +109,7 @@ export const managedRuntimeCorrelationResultSchema = z.strictObject({
|
||||
bounds: managedRuntimeBoundsSchema,
|
||||
unsupported_until_executor_exists: z.literal(true),
|
||||
evidence_links: z.array(evidenceIdSchema).length(1),
|
||||
limitations: z.array(boundedTextSchema).max(1_000),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
});
|
||||
|
||||
export type ManagedRuntimeCorrelationInput = z.infer<
|
||||
|
||||
@@ -24,7 +24,7 @@ const nodeRuntimeCharacterizationPlanSchema =
|
||||
|
||||
export const nodeCharacterizationPreparationInputSchema = z
|
||||
.strictObject({
|
||||
selected_alias: z.string().min(1).max(200),
|
||||
selected_alias: z.string().min(1),
|
||||
expected_effect: nodeCharacterizationExpectedEffectSchema,
|
||||
instrumentation: javascriptExportInstrumentationInputSchema,
|
||||
replay: controlledReplayPlanInputSchema,
|
||||
|
||||
@@ -453,10 +453,10 @@ const processCaptureShapeSchema: z.ZodType<UnverifiedProcessCapture> = z.object(
|
||||
z.object({
|
||||
sequence: z.number().int().nonnegative(),
|
||||
at_ms: z.number().int().nonnegative(),
|
||||
transition_id: z.string().min(1).max(64),
|
||||
state_before: z.string().min(1).max(64),
|
||||
state_after: z.string().min(1).max(64),
|
||||
sensitive_aliases: z.array(z.string().min(1).max(64)).max(32),
|
||||
transition_id: z.string().min(1),
|
||||
state_before: z.string().min(1),
|
||||
state_after: z.string().min(1),
|
||||
sensitive_aliases: z.array(z.string().min(1)),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
|
||||
@@ -14,8 +14,8 @@ const processReactiveOutcomeSchema = z.enum([
|
||||
|
||||
const processReactiveTransitionShape = {
|
||||
sequence: z.number().int().nonnegative(),
|
||||
transition_id: z.string().min(1).max(64),
|
||||
state_before: z.string().min(1).max(64),
|
||||
transition_id: z.string().min(1),
|
||||
state_before: z.string().min(1),
|
||||
trigger_event_ids: z.array(z.string().min(1)),
|
||||
action_event_ids: z.array(z.string().min(1)),
|
||||
action_types: z.array(
|
||||
@@ -32,7 +32,7 @@ const processReactiveTransitionShape = {
|
||||
const processReactiveTransitionSchema = z.union([
|
||||
z.object({
|
||||
...processReactiveTransitionShape,
|
||||
state_after: z.string().min(1).max(64),
|
||||
state_after: z.string().min(1),
|
||||
outcome: z.null(),
|
||||
}),
|
||||
z.object({
|
||||
@@ -43,7 +43,7 @@ const processReactiveTransitionSchema = z.union([
|
||||
]);
|
||||
|
||||
const processReactiveRunShape = {
|
||||
active_state: z.string().min(1).max(64),
|
||||
active_state: z.string().min(1),
|
||||
controls: z
|
||||
.array(
|
||||
z.object({
|
||||
|
||||
@@ -173,6 +173,22 @@ describe("process reactive runtime predicates", () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
it("matches caller supplied terminal literals longer than the former schema cap", () => {
|
||||
const literal = "Ready".repeat(2_001);
|
||||
const scenario = scenarioWith([
|
||||
finish("long_literal", terminalTrigger(literal)),
|
||||
]);
|
||||
const decision = offer(
|
||||
scenario,
|
||||
createProcessReactiveSnapshot(scenario),
|
||||
observation("terminal_raw", 0, { data: `prefix${literal}suffix` }),
|
||||
);
|
||||
|
||||
expect(decision).toMatchObject({
|
||||
kind: "transition",
|
||||
record: { transition_id: "long_literal" },
|
||||
});
|
||||
});
|
||||
it("evaluates ordered and repeated predicates without array-order arbitration", () => {
|
||||
const event = (name: string) => ({
|
||||
kind: "event" as const,
|
||||
|
||||
@@ -39,6 +39,56 @@ const baseScenario = () => ({
|
||||
],
|
||||
});
|
||||
|
||||
const buildLargeCallerScenario = () => {
|
||||
const states = Array.from({ length: 40 }, (_, index) => ({
|
||||
id: `state_${String(index)}`,
|
||||
max_visits: 300,
|
||||
deadline_ms: 30_000,
|
||||
on: [] as unknown[],
|
||||
}));
|
||||
const manyPredicates = {
|
||||
kind: "repeat",
|
||||
trigger: {
|
||||
kind: "all",
|
||||
triggers: Array.from({ length: 20 }, () => terminalTrigger()),
|
||||
},
|
||||
min: 1,
|
||||
max: 1_000,
|
||||
};
|
||||
const sendInputs = Array.from({ length: 300 }, () => ({
|
||||
type: "send_input",
|
||||
data: "x",
|
||||
sensitive: false,
|
||||
}));
|
||||
states[0]!.on = Array.from({ length: 130 }, (_, index) => ({
|
||||
id: `transition_${String(index)}`,
|
||||
priority: index,
|
||||
max_uses: 300,
|
||||
when: index === 0 ? manyPredicates : terminalTrigger(),
|
||||
actions: index === 0 ? sendInputs : [],
|
||||
target:
|
||||
index > 0 && index <= 39
|
||||
? { kind: "goto", state: `state_${String(index)}` }
|
||||
: { kind: "finish", outcome: "passed" },
|
||||
}));
|
||||
for (let index = 1; index < states.length; index += 1) {
|
||||
const state = states[index]!;
|
||||
state.on = [
|
||||
{
|
||||
...finishTransition(),
|
||||
id: `finish_${String(index)}`,
|
||||
max_uses: 300,
|
||||
actions: [{ type: "checkpoint", name: `ready_${String(index)}` }],
|
||||
},
|
||||
];
|
||||
}
|
||||
return processReactiveScenarioSchema.safeParse({
|
||||
initial_state: "state_0",
|
||||
deadline_ms: 30_000,
|
||||
states,
|
||||
});
|
||||
};
|
||||
|
||||
describe("process reactive scenario schema", () => {
|
||||
it("parses a terminal scenario", () => {
|
||||
expect(processReactiveScenarioSchema.parse(baseScenario())).toMatchObject({
|
||||
@@ -48,60 +98,49 @@ describe("process reactive scenario schema", () => {
|
||||
});
|
||||
|
||||
it("accepts caller-defined scenario sizes without count ceilings", () => {
|
||||
const states = Array.from({ length: 40 }, (_, index) => ({
|
||||
id: `state_${String(index)}`,
|
||||
max_visits: 300,
|
||||
deadline_ms: 30_000,
|
||||
on: [] as unknown[],
|
||||
}));
|
||||
const manyPredicates = {
|
||||
kind: "repeat",
|
||||
trigger: {
|
||||
kind: "all",
|
||||
triggers: Array.from({ length: 20 }, () => terminalTrigger()),
|
||||
},
|
||||
min: 1,
|
||||
max: 1_000,
|
||||
};
|
||||
const sendInputs = Array.from({ length: 300 }, () => ({
|
||||
type: "send_input",
|
||||
data: "x",
|
||||
sensitive: false,
|
||||
}));
|
||||
const transitions = Array.from({ length: 130 }, (_, index) => ({
|
||||
id: `transition_${String(index)}`,
|
||||
priority: index,
|
||||
max_uses: 300,
|
||||
when: index === 0 ? manyPredicates : terminalTrigger(),
|
||||
actions: index === 0 ? sendInputs : [],
|
||||
target:
|
||||
index > 0 && index <= 39
|
||||
? { kind: "goto", state: `state_${String(index)}` }
|
||||
: { kind: "finish", outcome: "passed" },
|
||||
}));
|
||||
states[0]!.on = transitions;
|
||||
for (let index = 1; index < states.length; index += 1) {
|
||||
const state = states[index]!;
|
||||
state.on = [
|
||||
{
|
||||
...finishTransition(),
|
||||
id: `finish_${String(index)}`,
|
||||
max_uses: 300,
|
||||
actions: [{ type: "checkpoint", name: `ready_${String(index)}` }],
|
||||
},
|
||||
];
|
||||
}
|
||||
const parsed = processReactiveScenarioSchema.safeParse({
|
||||
initial_state: "state_0",
|
||||
deadline_ms: 30_000,
|
||||
states,
|
||||
});
|
||||
const parsed = buildLargeCallerScenario();
|
||||
expect(
|
||||
parsed.success,
|
||||
parsed.success ? "" : JSON.stringify(parsed.error.issues),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts long caller supplied identifiers, terminal matchers, and input", () => {
|
||||
const identifier = `transition_${"x".repeat(128)}`;
|
||||
const checkpoint = `checkpoint_${"x".repeat(128)}`;
|
||||
const literal = "Ready".repeat(2_001);
|
||||
const data = "input".repeat(200_001);
|
||||
const parsed = processReactiveScenarioSchema.safeParse({
|
||||
initial_state: "starting",
|
||||
deadline_ms: 30_000,
|
||||
states: [
|
||||
{
|
||||
id: "starting",
|
||||
max_visits: 1,
|
||||
deadline_ms: 5_000,
|
||||
on: [
|
||||
{
|
||||
...finishTransition(),
|
||||
id: identifier,
|
||||
when: { ...terminalTrigger(), literal },
|
||||
actions: [
|
||||
{ type: "checkpoint", name: checkpoint },
|
||||
{ type: "send_input", data, sensitive: false },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(parsed.success).toBe(true);
|
||||
if (parsed.success) {
|
||||
expect(parsed.data.states[0]?.on[0]?.id).toBe(identifier);
|
||||
expect(parsed.data.states[0]?.on[0]?.when).toMatchObject({ literal });
|
||||
expect(parsed.data.states[0]?.on[0]?.actions[1]).toMatchObject({ data });
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
["unknown major version", { ...baseScenario(), version: 2 }],
|
||||
[
|
||||
|
||||
@@ -12,10 +12,8 @@ export const PROCESS_REACTIVE_LIMITS = {
|
||||
jsonDepth: 256,
|
||||
} as const;
|
||||
|
||||
const identifierSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]{0,63}$/u);
|
||||
const checkpointNameSchema = z
|
||||
.string()
|
||||
.regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/u);
|
||||
const identifierSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]*$/u);
|
||||
const checkpointNameSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]*$/u);
|
||||
const positiveRuntime = z.number().int().safe().positive();
|
||||
|
||||
const frontierSchema = z.discriminatedUnion("kind", [
|
||||
@@ -93,7 +91,6 @@ const processReactiveTriggerSchema: z.ZodType<ProcessReactiveTrigger> = z.lazy(
|
||||
exact: jsonValueSchema,
|
||||
ignore_fields: z
|
||||
.array(ignoredFieldSchema)
|
||||
.max(5)
|
||||
.refine((values) => new Set(values).size === values.length, {
|
||||
message: "ignored event fields must be unique",
|
||||
}),
|
||||
@@ -112,7 +109,7 @@ const processReactiveTriggerSchema: z.ZodType<ProcessReactiveTrigger> = z.lazy(
|
||||
kind: z.literal("terminal_text"),
|
||||
view: z.literal("decoded"),
|
||||
encoding: z.literal("utf8"),
|
||||
literal: z.string().min(1).max(10_000),
|
||||
literal: z.string().min(1),
|
||||
case_sensitive: z.literal(true),
|
||||
control_sequences: z.literal("include"),
|
||||
occurrence: z.number().int().safe().positive(),
|
||||
@@ -156,13 +153,13 @@ const signalTargetSchema = z.discriminatedUnion("kind", [
|
||||
const processReactiveActionSchema = z.discriminatedUnion("type", [
|
||||
z.strictObject({
|
||||
type: z.literal("send_input"),
|
||||
data: z.string().max(1_000_000),
|
||||
data: z.string(),
|
||||
sensitive: z.boolean(),
|
||||
}),
|
||||
z.strictObject({
|
||||
type: z.literal("resize"),
|
||||
columns: z.number().int().min(1).max(1_000),
|
||||
rows: z.number().int().min(1).max(1_000),
|
||||
columns: z.number().int().positive(),
|
||||
rows: z.number().int().positive(),
|
||||
}),
|
||||
z.strictObject({ type: z.literal("close_stdin") }),
|
||||
z.strictObject({
|
||||
|
||||
@@ -16,21 +16,52 @@ describe("process scenario collection inputs", () => {
|
||||
expect(scenario.checkpoints).toHaveLength(65);
|
||||
});
|
||||
|
||||
it("lets callers raise the output byte budget without a tool-side ceiling", () => {
|
||||
it("allows a zero-depth filesystem observation", () => {
|
||||
expect(
|
||||
processScenarioSchema.parse({
|
||||
executable: "/bin/echo",
|
||||
working_directory: "/tmp",
|
||||
limits: { filesystem_depth: 0 },
|
||||
}).limits.filesystem_depth,
|
||||
).toBe(0);
|
||||
});
|
||||
|
||||
it("accepts caller budgets above the former tool-side ceilings", () => {
|
||||
const scenario = processScenarioSchema.parse({
|
||||
executable: "/bin/echo",
|
||||
working_directory: "/tmp",
|
||||
limits: { output_bytes: 10_000_001 },
|
||||
timeout_ms: 600_000,
|
||||
idle_timeout_ms: 900_000,
|
||||
settle_ms: 20_000,
|
||||
limits: {
|
||||
output_bytes: 10_000_001,
|
||||
files: 100_001,
|
||||
file_bytes: 100_000_001,
|
||||
processes: 10_001,
|
||||
protocol_events: 100_001,
|
||||
protocol_body_bytes: 10_000_001,
|
||||
connections: 1_001,
|
||||
filesystem_depth: 100,
|
||||
},
|
||||
checkpoints: [
|
||||
{
|
||||
name: "later",
|
||||
trigger: { type: "time", at_ms: 600_000 },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(scenario.limits.output_bytes).toBe(10_000_001);
|
||||
expect(
|
||||
processScenarioSchema.safeParse({
|
||||
executable: "/bin/echo",
|
||||
working_directory: "/tmp",
|
||||
limits: { frames: 100_001 },
|
||||
}).success,
|
||||
).toBe(false);
|
||||
expect(scenario.limits.files).toBe(100_001);
|
||||
expect(scenario.limits.file_bytes).toBe(100_000_001);
|
||||
expect(scenario.limits.processes).toBe(10_001);
|
||||
expect(scenario.limits.protocol_events).toBe(100_001);
|
||||
expect(scenario.limits.protocol_body_bytes).toBe(10_000_001);
|
||||
expect(scenario.limits.connections).toBe(1_001);
|
||||
expect(scenario.limits.filesystem_depth).toBe(100);
|
||||
expect(scenario.timeout_ms).toBe(600_000);
|
||||
expect(scenario.idle_timeout_ms).toBe(900_000);
|
||||
expect(scenario.settle_ms).toBe(20_000);
|
||||
});
|
||||
|
||||
it("accepts large interaction and replay descriptions under the run budgets", () => {
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
} from "./processReactiveScenario.js";
|
||||
import { replayMachineSchema } from "./replayMachine.js";
|
||||
|
||||
const positiveBudget = z.number().int().positive();
|
||||
const positiveBudget = z.number().int().safe().positive();
|
||||
const maximumTimerDelay = 2_147_483_647;
|
||||
const timedEventBase = { at_ms: z.number().int().nonnegative() };
|
||||
const environmentName = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/u);
|
||||
const reservedEnvironment = new Set([
|
||||
@@ -23,11 +24,11 @@ export const normalizationSchema = z.object({
|
||||
paths: z.boolean(),
|
||||
pids: z.boolean(),
|
||||
ports: z.boolean(),
|
||||
time_bucket_ms: positiveBudget.max(60_000),
|
||||
time_bucket_ms: positiveBudget,
|
||||
patterns: z.array(
|
||||
z.object({
|
||||
pattern: z.string().max(500),
|
||||
replacement: z.string().max(100),
|
||||
pattern: z.string(),
|
||||
replacement: z.string(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
@@ -38,9 +39,9 @@ const commandNameSchema = z
|
||||
.string()
|
||||
.regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u);
|
||||
const outputChunkSchema = z.object({
|
||||
at_ms: z.number().int().nonnegative().max(300_000),
|
||||
at_ms: z.number().int().safe().nonnegative().max(maximumTimerDelay),
|
||||
stream: z.enum(["stdout", "stderr"]),
|
||||
data: z.string().max(1_000_000),
|
||||
data: z.string(),
|
||||
});
|
||||
|
||||
/** Compute a canonical SHA-256 commitment independent of object key order. */
|
||||
@@ -128,9 +129,9 @@ export const processScenarioSchema = z
|
||||
filesystem_roots: z.array(z.string().startsWith("/")).default([]),
|
||||
terminal: z
|
||||
.object({
|
||||
columns: z.number().int().min(1).max(1_000).default(80),
|
||||
rows: z.number().int().min(1).max(1_000).default(24),
|
||||
scrollback: z.number().int().min(0).max(10_000).default(1_000),
|
||||
columns: z.number().int().min(1).max(65_535).default(80),
|
||||
rows: z.number().int().min(1).max(65_535).default(24),
|
||||
scrollback: z.number().int().min(0).default(1_000),
|
||||
})
|
||||
.default({ columns: 80, rows: 24, scrollback: 1_000 }),
|
||||
checkpoints: z
|
||||
@@ -140,11 +141,16 @@ export const processScenarioSchema = z
|
||||
trigger: z.discriminatedUnion("type", [
|
||||
z.object({
|
||||
type: z.literal("time"),
|
||||
at_ms: z.number().int().nonnegative().max(300_000),
|
||||
at_ms: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.nonnegative()
|
||||
.max(maximumTimerDelay),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("terminal_literal"),
|
||||
value: z.string().min(1).max(10_000),
|
||||
value: z.string().min(1),
|
||||
occurrence: positiveBudget.default(1),
|
||||
}),
|
||||
z.object({ type: z.literal("root_exit") }),
|
||||
@@ -191,8 +197,8 @@ export const processScenarioSchema = z
|
||||
z.object({
|
||||
...timedEventBase,
|
||||
type: z.literal("resize"),
|
||||
columns: z.number().int().min(1).max(1_000),
|
||||
rows: z.number().int().min(1).max(1_000),
|
||||
columns: z.number().int().min(1).max(65_535),
|
||||
rows: z.number().int().min(1).max(65_535),
|
||||
}),
|
||||
z.object({
|
||||
...timedEventBase,
|
||||
@@ -202,19 +208,19 @@ export const processScenarioSchema = z
|
||||
]),
|
||||
)
|
||||
.default([]),
|
||||
timeout_ms: positiveBudget.max(300_000).default(30_000),
|
||||
idle_timeout_ms: positiveBudget.max(300_000).default(30_000),
|
||||
settle_ms: z.number().int().nonnegative().max(10_000).default(100),
|
||||
timeout_ms: positiveBudget.default(30_000),
|
||||
idle_timeout_ms: positiveBudget.default(30_000),
|
||||
settle_ms: z.number().int().safe().nonnegative().default(100),
|
||||
limits: z
|
||||
.object({
|
||||
output_bytes: positiveBudget.safe().default(1_000_000),
|
||||
files: positiveBudget.max(100_000).default(10_000),
|
||||
file_bytes: positiveBudget.max(100_000_000).default(10_000_000),
|
||||
processes: positiveBudget.max(10_000).default(1_000),
|
||||
protocol_events: positiveBudget.max(100_000).default(10_000),
|
||||
protocol_body_bytes: positiveBudget.max(10_000_000).default(1_000_000),
|
||||
connections: positiveBudget.max(1_000).default(100),
|
||||
filesystem_depth: z.number().int().min(1).max(64).default(16),
|
||||
output_bytes: positiveBudget.default(1_000_000),
|
||||
files: positiveBudget.default(10_000),
|
||||
file_bytes: positiveBudget.default(10_000_000),
|
||||
processes: positiveBudget.default(1_000),
|
||||
protocol_events: positiveBudget.default(10_000),
|
||||
protocol_body_bytes: positiveBudget.default(1_000_000),
|
||||
connections: positiveBudget.default(100),
|
||||
filesystem_depth: z.number().int().safe().nonnegative().default(16),
|
||||
})
|
||||
.strict()
|
||||
.default({
|
||||
@@ -232,15 +238,14 @@ export const processScenarioSchema = z
|
||||
paths: z.boolean().default(true),
|
||||
pids: z.boolean().default(true),
|
||||
ports: z.boolean().default(true),
|
||||
time_bucket_ms: positiveBudget.max(60_000).default(10),
|
||||
time_bucket_ms: positiveBudget.default(10),
|
||||
patterns: z
|
||||
.array(
|
||||
z.object({
|
||||
pattern: z.string().max(500),
|
||||
replacement: z.string().max(100),
|
||||
pattern: z.string(),
|
||||
replacement: z.string(),
|
||||
}),
|
||||
)
|
||||
.max(32)
|
||||
.default([]),
|
||||
})
|
||||
.default({
|
||||
@@ -256,31 +261,38 @@ export const processScenarioSchema = z
|
||||
http: z
|
||||
.array(
|
||||
z.object({
|
||||
method: z.string().max(16),
|
||||
method: z.string(),
|
||||
path: z.string().startsWith("/"),
|
||||
status: z.number().int().min(100).max(599),
|
||||
body: z.string().max(1_000_000),
|
||||
body: z.string(),
|
||||
request_headers: z.record(z.string(), z.string()).default({}),
|
||||
request_body: z.string().max(1_000_000).optional(),
|
||||
request_body: z.string().optional(),
|
||||
response_headers: z.record(z.string(), z.string()).default({}),
|
||||
delay_ms: z.number().int().nonnegative().max(30_000).default(0),
|
||||
delay_ms: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.nonnegative()
|
||||
.max(maximumTimerDelay)
|
||||
.default(0),
|
||||
disconnect: z.boolean().default(false),
|
||||
max_calls: positiveBudget.default(1),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
websocket_messages: z.array(z.string().max(1_000_000)).default([]),
|
||||
websocket_messages: z.array(z.string()).default([]),
|
||||
websocket_connections: z
|
||||
.array(
|
||||
z.object({
|
||||
messages: z.array(
|
||||
z.object({
|
||||
data: z.string().max(1_000_000),
|
||||
data: z.string(),
|
||||
delay_ms: z
|
||||
.number()
|
||||
.int()
|
||||
.safe()
|
||||
.nonnegative()
|
||||
.max(30_000)
|
||||
.max(maximumTimerDelay)
|
||||
.default(0),
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -74,6 +74,49 @@ const partialSpecification = (): ProcessTraceSpecification => ({
|
||||
},
|
||||
});
|
||||
describe("process trace specification", () => {
|
||||
it("accepts event sets and cardinalities beyond the former fixed ceilings", () => {
|
||||
const ids = Array.from({ length: 257 }, (_, index) => `event-${index}`);
|
||||
const events = ids.map((id) => ({
|
||||
id,
|
||||
source: "terminal_raw" as const,
|
||||
exact: { id },
|
||||
cardinality: { kind: "required" as const },
|
||||
}));
|
||||
const trace = processTraceSpecificationSchema.safeParse({
|
||||
events: [
|
||||
{
|
||||
id: "repeated",
|
||||
source: "terminal_raw",
|
||||
exact: "event",
|
||||
cardinality: { kind: "exact", count: 10_001 },
|
||||
},
|
||||
],
|
||||
language: {
|
||||
kind: "finite_traces",
|
||||
variants: [
|
||||
{
|
||||
id: "long-trace",
|
||||
trace: Array.from({ length: 10_001 }, () => "repeated"),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(trace.success).toBe(true);
|
||||
|
||||
const eventSet = processTraceSpecificationSchema.safeParse({
|
||||
events,
|
||||
language: {
|
||||
kind: "partial_order",
|
||||
happens_before: ids.slice(1).map((after, index) => ({
|
||||
before: ids[index] ?? "",
|
||||
after,
|
||||
})),
|
||||
prefix: Array.from({ length: 4_097 }, () => ids[0] ?? ""),
|
||||
},
|
||||
});
|
||||
expect(eventSet.success).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects cycles, implicit concurrency, overlap, and unsatisfiable variants", () => {
|
||||
const base = partialSpecification();
|
||||
expect(
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
type ProcessObservationSource,
|
||||
} from "./processObservation.js";
|
||||
|
||||
const identifierSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]{0,63}$/u);
|
||||
const identifierSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._-]*$/u);
|
||||
|
||||
/** Process observation families admitted by a declared trace specification. */
|
||||
export const processTraceSourceSchema = processObservationSourceSchema;
|
||||
@@ -19,13 +19,13 @@ const cardinalitySchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({ kind: z.literal("optional") }),
|
||||
z.strictObject({
|
||||
kind: z.literal("exact"),
|
||||
count: z.number().int().min(0).max(10_000),
|
||||
count: z.number().int().min(0),
|
||||
}),
|
||||
z
|
||||
.strictObject({
|
||||
kind: z.literal("range"),
|
||||
min: z.number().int().min(0).max(10_000),
|
||||
max: z.number().int().min(0).max(10_000),
|
||||
min: z.number().int().min(0),
|
||||
max: z.number().int().min(0),
|
||||
})
|
||||
.refine(({ min, max }) => min <= max, {
|
||||
message: "cardinality min must not exceed max",
|
||||
@@ -47,7 +47,6 @@ const eventDeclarationSchema = z.strictObject({
|
||||
"elapsed_ms",
|
||||
]),
|
||||
)
|
||||
.max(5)
|
||||
.refine((values) => new Set(values).size === values.length, {
|
||||
message: "ignored event fields must be unique",
|
||||
})
|
||||
@@ -64,7 +63,6 @@ const partialOrderLanguageSchema = z.strictObject({
|
||||
after: identifierSchema,
|
||||
}),
|
||||
)
|
||||
.max(4_096)
|
||||
.default([]),
|
||||
not_before: z
|
||||
.array(
|
||||
@@ -73,21 +71,17 @@ const partialOrderLanguageSchema = z.strictObject({
|
||||
anchor: identifierSchema,
|
||||
}),
|
||||
)
|
||||
.max(4_096)
|
||||
.default([]),
|
||||
unordered_groups: z
|
||||
.array(
|
||||
z.strictObject({ events: z.array(identifierSchema).min(2).max(256) }),
|
||||
)
|
||||
.max(256)
|
||||
.array(z.strictObject({ events: z.array(identifierSchema).min(2) }))
|
||||
.default([]),
|
||||
prefix: z.array(identifierSchema).max(4_096).default([]),
|
||||
suffix: z.array(identifierSchema).max(4_096).default([]),
|
||||
prefix: z.array(identifierSchema).default([]),
|
||||
suffix: z.array(identifierSchema).default([]),
|
||||
});
|
||||
|
||||
const finiteTraceTokenSchema = z.union([
|
||||
identifierSchema,
|
||||
z.strictObject({ unordered: z.array(identifierSchema).min(2).max(256) }),
|
||||
z.strictObject({ unordered: z.array(identifierSchema).min(2) }),
|
||||
]);
|
||||
|
||||
const finiteTraceLanguageSchema = z.strictObject({
|
||||
@@ -96,15 +90,14 @@ const finiteTraceLanguageSchema = z.strictObject({
|
||||
.array(
|
||||
z.strictObject({
|
||||
id: identifierSchema,
|
||||
trace: z.array(finiteTraceTokenSchema).max(4_096),
|
||||
trace: z.array(finiteTraceTokenSchema),
|
||||
}),
|
||||
)
|
||||
.min(1)
|
||||
.max(64),
|
||||
.min(1),
|
||||
});
|
||||
|
||||
const specificationShapeSchema = z.strictObject({
|
||||
events: z.array(eventDeclarationSchema).min(1).max(256),
|
||||
events: z.array(eventDeclarationSchema).min(1),
|
||||
language: z.discriminatedUnion("kind", [
|
||||
partialOrderLanguageSchema,
|
||||
finiteTraceLanguageSchema,
|
||||
|
||||
@@ -12,6 +12,32 @@ import {
|
||||
} from "./protocolCapture.js";
|
||||
|
||||
describe("protocol capture", () => {
|
||||
it("accepts every captured message", () => {
|
||||
const message: ProtocolMessage = {
|
||||
sequence: 0,
|
||||
at_ms: 0,
|
||||
family: "json-rpc",
|
||||
direction: "request",
|
||||
endpoint: null,
|
||||
content_type: null,
|
||||
raw_payload: null,
|
||||
decoded_fields: [],
|
||||
schema_hypotheses: [],
|
||||
truncated: false,
|
||||
credentials_redacted: false,
|
||||
};
|
||||
|
||||
expect(
|
||||
protocolCaptureSchema.parse({
|
||||
family: "json-rpc",
|
||||
messages: Array.from({ length: 10_001 }, (_, sequence) => ({
|
||||
...message,
|
||||
sequence,
|
||||
})),
|
||||
}).messages,
|
||||
).toHaveLength(10_001);
|
||||
});
|
||||
|
||||
it("classifies gRPC from content type", () => {
|
||||
expect(classifyProtocolFamily("application/grpc+proto", null)).toBe("grpc");
|
||||
});
|
||||
@@ -87,6 +113,12 @@ describe("JSON-RPC decoding", () => {
|
||||
});
|
||||
|
||||
describe("MessagePack decoding", () => {
|
||||
it("does not report unobserved payload bytes as truncation", () => {
|
||||
const result = decodeMessagePack(new Uint8Array(10_001).fill(0x82));
|
||||
|
||||
expect(result.truncated).toBe(false);
|
||||
});
|
||||
|
||||
it("detects map type", () => {
|
||||
const payload = new Uint8Array([0x82]);
|
||||
const result = decodeMessagePack(payload);
|
||||
|
||||
@@ -69,7 +69,7 @@ export const protocolCaptureSchema = z.strictObject({
|
||||
/** Protocol family for this capture. */
|
||||
family: protocolFamilySchema,
|
||||
/** Captured messages in order. */
|
||||
messages: z.array(protocolMessageSchema).min(0).max(10_000),
|
||||
messages: z.array(protocolMessageSchema).min(0),
|
||||
/** Aggregated schema hypotheses across all messages. */
|
||||
inferred_schema: z.array(schemaHypothesisSchema).default([]),
|
||||
/** Whether any message was truncated. */
|
||||
@@ -192,7 +192,7 @@ export function decodeMessagePack(rawPayload: Uint8Array): {
|
||||
}
|
||||
return {
|
||||
decoded_fields: fields,
|
||||
truncated: rawPayload.length > 10_000,
|
||||
truncated: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ export function decodeGrpcFrame(rawPayload: Uint8Array): {
|
||||
inferred: false,
|
||||
},
|
||||
],
|
||||
truncated: length > 10_000,
|
||||
truncated: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,29 @@ describe("reconstruction coverage closure", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns recommendations for every missing required surface", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const boundary = workspace.boundaries[0];
|
||||
if (boundary === undefined) throw new Error("Expected fixture boundary");
|
||||
const missingSurfaces = Array.from(
|
||||
{ length: 10_001 },
|
||||
(_, index) => `missing.surface.${index}`,
|
||||
);
|
||||
const incomplete = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
boundaries: [{ ...boundary, required_surface_ids: missingSurfaces }],
|
||||
});
|
||||
|
||||
const result = evaluateReconstructionClosure(
|
||||
incomplete,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
);
|
||||
|
||||
expect(result.reasons).toHaveLength(missingSurfaces.length);
|
||||
expect(result.recommended_probes).toHaveLength(missingSurfaces.length);
|
||||
});
|
||||
|
||||
it("invalidates stale verifier contracts and detected authority routing", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const owner = workspace.owners[0];
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const stableIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._:/-]{0,199}$/u);
|
||||
const boundedTextSchema = z.string().trim().min(1).max(4_096);
|
||||
const boundedTextSchema = z.string().trim().min(1);
|
||||
|
||||
const authoritySchema = z.enum([
|
||||
"observed",
|
||||
@@ -29,26 +29,26 @@ const authoritySchema = z.enum([
|
||||
const artifactSchema = z.strictObject({
|
||||
artifact_id: stableIdSchema,
|
||||
artifact_sha256: digestSchema,
|
||||
version: z.string().trim().min(1).max(500),
|
||||
version: z.string().trim().min(1),
|
||||
environment_sha256: digestSchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(1_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const surfaceSchema = z.strictObject({
|
||||
surface_id: stableIdSchema,
|
||||
family: z.string().trim().min(1).max(100),
|
||||
family: z.string().trim().min(1),
|
||||
artifact_id: stableIdSchema,
|
||||
occurrence_id: z.string().trim().min(1).max(500).nullable(),
|
||||
occurrence_id: z.string().trim().min(1).nullable(),
|
||||
location: boundedTextSchema,
|
||||
authority: authoritySchema,
|
||||
dependency_surface_ids: z.array(stableIdSchema).max(1_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(1_000),
|
||||
dependency_surface_ids: z.array(stableIdSchema),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const implementationOwnerSchema = z.strictObject({
|
||||
disposition: z.literal("implemented"),
|
||||
owner_path: boundedTextSchema,
|
||||
owner_export: z.string().trim().min(1).max(500).nullable(),
|
||||
owner_export: z.string().trim().min(1).nullable(),
|
||||
owner_sha256: digestSchema,
|
||||
path_state: z.enum(["present", "missing", "unknown"]),
|
||||
package_state: z.enum(["distributed", "missing", "unknown"]),
|
||||
@@ -70,10 +70,10 @@ const ownerSchema = z.strictObject({
|
||||
|
||||
const claimSchema = z.strictObject({
|
||||
claim_id: stableIdSchema,
|
||||
title: z.string().trim().min(1).max(500),
|
||||
kind: z.string().trim().min(1).max(100),
|
||||
surface_ids: z.array(stableIdSchema).min(1).max(1_000),
|
||||
required_dimensions: z.array(stableIdSchema).min(1).max(100),
|
||||
title: z.string().trim().min(1),
|
||||
kind: z.string().trim().min(1),
|
||||
surface_ids: z.array(stableIdSchema).min(1),
|
||||
required_dimensions: z.array(stableIdSchema).min(1),
|
||||
required_authority: z.enum([
|
||||
"shipped-artifact",
|
||||
"controlled-replay",
|
||||
@@ -84,16 +84,16 @@ const claimSchema = z.strictObject({
|
||||
|
||||
const verifierContractBaseSchema = z.strictObject({
|
||||
verifier_id: stableIdSchema,
|
||||
claim_ids: z.array(stableIdSchema).min(1).max(1_000),
|
||||
dimensions: z.array(stableIdSchema).min(1).max(100),
|
||||
claim_ids: z.array(stableIdSchema).min(1),
|
||||
dimensions: z.array(stableIdSchema).min(1),
|
||||
authority: z.enum([
|
||||
"shipped-artifact",
|
||||
"controlled-replay",
|
||||
"live-observation",
|
||||
"external",
|
||||
]),
|
||||
max_age_ms: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
||||
minimum_repeats: z.number().int().min(1).max(1_000),
|
||||
max_age_ms: z.number().int().min(1),
|
||||
minimum_repeats: z.number().int().min(1),
|
||||
normalization_sha256: digestSchema,
|
||||
normalization_removes_dimensions: z.literal(false),
|
||||
});
|
||||
@@ -114,21 +114,21 @@ const verifierResultSchema = z.strictObject({
|
||||
"truncated",
|
||||
"skipped",
|
||||
]),
|
||||
covered_claim_ids: z.array(stableIdSchema).min(1).max(1_000),
|
||||
covered_dimensions: z.array(stableIdSchema).min(1).max(100),
|
||||
artifact_sha256s: z.array(digestSchema).min(1).max(1_000),
|
||||
owner_sha256s: z.array(digestSchema).max(1_000),
|
||||
covered_claim_ids: z.array(stableIdSchema).min(1),
|
||||
covered_dimensions: z.array(stableIdSchema).min(1),
|
||||
artifact_sha256s: z.array(digestSchema).min(1),
|
||||
owner_sha256s: z.array(digestSchema),
|
||||
normalization_sha256: digestSchema,
|
||||
repeats: z.number().int().min(1).max(1_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(1_000),
|
||||
repeats: z.number().int().min(1),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const contradictionSchema = z.strictObject({
|
||||
contradiction_id: stableIdSchema,
|
||||
status: z.enum(["active", "resolved"]),
|
||||
surface_ids: z.array(stableIdSchema).max(1_000),
|
||||
claim_ids: z.array(stableIdSchema).max(1_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(2).max(1_000),
|
||||
surface_ids: z.array(stableIdSchema),
|
||||
claim_ids: z.array(stableIdSchema),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(2),
|
||||
});
|
||||
|
||||
const packageProofSchema = z.strictObject({
|
||||
@@ -141,35 +141,32 @@ const packageProofSchema = z.strictObject({
|
||||
"authority-independence",
|
||||
]),
|
||||
status: z.enum(["pass", "fail", "unknown", "unsupported", "skipped"]),
|
||||
artifact_sha256s: z.array(digestSchema).min(1).max(1_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(1_000),
|
||||
artifact_sha256s: z.array(digestSchema).min(1),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const boundarySchema = z.strictObject({
|
||||
boundary_id: stableIdSchema,
|
||||
title: z.string().trim().min(1).max(500),
|
||||
required_surface_ids: z.array(stableIdSchema).min(1).max(10_000),
|
||||
required_claim_ids: z.array(stableIdSchema).min(1).max(10_000),
|
||||
required_package_proof_kinds: z
|
||||
.array(packageProofSchema.shape.kind)
|
||||
.min(1)
|
||||
.max(5),
|
||||
allowed_dispositions: z.array(z.enum(["external", "non-goal"])).max(2),
|
||||
allowed_unknown_ids: z.array(stableIdSchema).max(1_000),
|
||||
title: z.string().trim().min(1),
|
||||
required_surface_ids: z.array(stableIdSchema).min(1),
|
||||
required_claim_ids: z.array(stableIdSchema).min(1),
|
||||
required_package_proof_kinds: z.array(packageProofSchema.shape.kind).min(1),
|
||||
allowed_dispositions: z.array(z.enum(["external", "non-goal"])),
|
||||
allowed_unknown_ids: z.array(stableIdSchema),
|
||||
});
|
||||
|
||||
export const reconstructionCoverageDataSchema = z.strictObject({
|
||||
evidence_bundle: evidenceBundleSchema,
|
||||
artifacts: z.array(artifactSchema).max(1_000),
|
||||
surfaces: z.array(surfaceSchema).max(10_000),
|
||||
owners: z.array(ownerSchema).max(10_000),
|
||||
claims: z.array(claimSchema).max(10_000),
|
||||
verifier_contracts: z.array(verifierContractSchema).max(10_000),
|
||||
verifier_results: z.array(verifierResultSchema).max(100_000),
|
||||
residual_unknown_ids: z.array(stableIdSchema).max(10_000),
|
||||
contradictions: z.array(contradictionSchema).max(10_000),
|
||||
package_proofs: z.array(packageProofSchema).max(10_000),
|
||||
boundaries: z.array(boundarySchema).max(1_000),
|
||||
artifacts: z.array(artifactSchema),
|
||||
surfaces: z.array(surfaceSchema),
|
||||
owners: z.array(ownerSchema),
|
||||
claims: z.array(claimSchema),
|
||||
verifier_contracts: z.array(verifierContractSchema),
|
||||
verifier_results: z.array(verifierResultSchema),
|
||||
residual_unknown_ids: z.array(stableIdSchema),
|
||||
contradictions: z.array(contradictionSchema),
|
||||
package_proofs: z.array(packageProofSchema),
|
||||
boundaries: z.array(boundarySchema),
|
||||
});
|
||||
|
||||
export type ReconstructionCoverageData = z.infer<
|
||||
@@ -227,17 +224,15 @@ export const reconstructionClosureResultSchema = z.strictObject({
|
||||
required_claims: z.number().int().min(0),
|
||||
reasons: z.number().int().min(0),
|
||||
}),
|
||||
reasons: z.array(closureReasonSchema).max(100_000),
|
||||
recommended_probes: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
operation: stableIdSchema,
|
||||
subject_id: stableIdSchema,
|
||||
rationale: boundedTextSchema,
|
||||
}),
|
||||
)
|
||||
.max(100_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100_000),
|
||||
reasons: z.array(closureReasonSchema),
|
||||
recommended_probes: z.array(
|
||||
z.strictObject({
|
||||
operation: stableIdSchema,
|
||||
subject_id: stableIdSchema,
|
||||
rationale: boundedTextSchema,
|
||||
}),
|
||||
),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
export type ReconstructionClosureResult = z.infer<
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
export const recommendedReconstructionProbes = (
|
||||
reasons: readonly ClosureReason[],
|
||||
): readonly { operation: string; subject_id: string; rationale: string }[] =>
|
||||
reasons.slice(0, 100).map((reason) => ({
|
||||
reasons.map((reason) => ({
|
||||
operation: probeOperation(reason.code),
|
||||
subject_id: reason.subject_id,
|
||||
rationale: reason.detail,
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
reconstructionObligationLedgerSchema,
|
||||
reconstructionObligationManifestSchema,
|
||||
} from "./reconstructionObligationLedgerSchemas.js";
|
||||
|
||||
const digest = "a".repeat(64);
|
||||
|
||||
describe("reconstruction obligation ledger schemas", () => {
|
||||
it("accepts manifests and ledgers above the former count ceilings", () => {
|
||||
const binding = {
|
||||
obligation_id: "obligation-1",
|
||||
owner: {
|
||||
module_path: "src/example.ts",
|
||||
symbol: "example",
|
||||
owner_sha256: digest,
|
||||
},
|
||||
parser_type: null,
|
||||
original_cases: [],
|
||||
fixtures: [],
|
||||
verifier: null,
|
||||
};
|
||||
const manifest = {
|
||||
bindings: Array.from({ length: 10_001 }, (_, index) => ({
|
||||
...binding,
|
||||
obligation_id: `obligation-${index}`,
|
||||
})),
|
||||
contradictions: [],
|
||||
};
|
||||
expect(
|
||||
reconstructionObligationManifestSchema.parse(manifest).bindings,
|
||||
).toHaveLength(10_001);
|
||||
|
||||
const ledger = {
|
||||
schema: "ReconstructionObligationLedger",
|
||||
ledger_id: `rol_${digest}`,
|
||||
closure_digest: digest,
|
||||
status: "ready",
|
||||
coverage: { status: "complete" },
|
||||
summary: {
|
||||
total: 0,
|
||||
required: 0,
|
||||
verified: 0,
|
||||
required_open: 0,
|
||||
by_status: [],
|
||||
by_application_layer: [],
|
||||
by_evidence_authority: [],
|
||||
},
|
||||
reports: {
|
||||
missing_owner_obligation_ids: [],
|
||||
missing_verifier_obligation_ids: [],
|
||||
contradicted_obligation_ids: [],
|
||||
residual_unknown_ids: [],
|
||||
},
|
||||
ownership_graph: [],
|
||||
dependency_graph: [],
|
||||
obligations: [],
|
||||
evidence_links: Array.from(
|
||||
{ length: 100_001 },
|
||||
(_, index) => `ev_${index.toString(16).padStart(64, "0")}`,
|
||||
),
|
||||
limitations: [],
|
||||
};
|
||||
|
||||
expect(
|
||||
reconstructionObligationLedgerSchema.parse(ledger).evidence_links,
|
||||
).toHaveLength(100_001);
|
||||
});
|
||||
});
|
||||
@@ -106,7 +106,7 @@ const fixtureBindingSchema = z.strictObject({
|
||||
fixture_id: stableIdSchema,
|
||||
case_kind: obligationCaseKindSchema,
|
||||
authority: obligationProofAuthoritySchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const nondeterminismSchema = z.strictObject({
|
||||
@@ -121,7 +121,7 @@ const verifierBindingSchema = z.strictObject({
|
||||
authority: obligationProofAuthoritySchema,
|
||||
status: z.enum(["pass", "fail", "unknown", "unsupported", "skipped"]),
|
||||
result_evidence_id: evidenceIdSchema,
|
||||
enumerated_obligation_ids: z.array(stableIdSchema).min(1).max(10_000),
|
||||
enumerated_obligation_ids: z.array(stableIdSchema).min(1),
|
||||
nondeterminism: nondeterminismSchema,
|
||||
});
|
||||
|
||||
@@ -129,21 +129,19 @@ export const reconstructionObligationManifestBindingSchema = z.strictObject({
|
||||
obligation_id: stableIdSchema,
|
||||
owner: ownerBindingSchema,
|
||||
parser_type: parserTypeBindingSchema.nullable(),
|
||||
original_cases: z.array(observedCaseSchema).max(100),
|
||||
fixtures: z.array(fixtureBindingSchema).max(100),
|
||||
original_cases: z.array(observedCaseSchema),
|
||||
fixtures: z.array(fixtureBindingSchema),
|
||||
verifier: verifierBindingSchema.nullable(),
|
||||
});
|
||||
|
||||
export const reconstructionObligationManifestSchema = z.strictObject({
|
||||
bindings: z.array(reconstructionObligationManifestBindingSchema).max(10_000),
|
||||
contradictions: z
|
||||
.array(
|
||||
z.strictObject({
|
||||
obligation_id: stableIdSchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(2).max(100),
|
||||
}),
|
||||
)
|
||||
.max(10_000),
|
||||
bindings: z.array(reconstructionObligationManifestBindingSchema),
|
||||
contradictions: z.array(
|
||||
z.strictObject({
|
||||
obligation_id: stableIdSchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(2),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export const reviewedReconstructionObligationSchema = z.strictObject({
|
||||
@@ -154,17 +152,17 @@ export const reviewedReconstructionObligationSchema = z.strictObject({
|
||||
family: z.string().trim().min(1).max(100),
|
||||
target: obligationTargetSchema,
|
||||
required: z.boolean(),
|
||||
required_case_kinds: z.array(obligationCaseKindSchema).min(1).max(5),
|
||||
required_case_kinds: z.array(obligationCaseKindSchema).min(1),
|
||||
required_original_authority: obligationOriginalAuthoritySchema,
|
||||
required_fixture_authority: obligationProofAuthoritySchema,
|
||||
required_verifier_authority: obligationProofAuthoritySchema,
|
||||
requires_parser_type: z.boolean(),
|
||||
dependency_obligation_ids: z.array(stableIdSchema).max(1_000),
|
||||
residual_unknown_ids: z.array(stableIdSchema).max(1_000),
|
||||
unavailable_authority: z.array(boundedTextSchema).max(100),
|
||||
required_next_evidence: z.array(boundedTextSchema).max(100),
|
||||
dependency_obligation_ids: z.array(stableIdSchema),
|
||||
residual_unknown_ids: z.array(stableIdSchema),
|
||||
unavailable_authority: z.array(boundedTextSchema),
|
||||
required_next_evidence: z.array(boundedTextSchema),
|
||||
disposition: z.enum(["active", "blocked", "out-of-scope"]),
|
||||
review_evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
review_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const diagnosticSchema = z.strictObject({
|
||||
@@ -203,22 +201,22 @@ export const reconstructionObligationSchema = z.strictObject({
|
||||
application_layer: obligationLayerSchema,
|
||||
family: z.string().trim().min(1).max(100),
|
||||
target: obligationTargetSchema,
|
||||
authority_references: z.array(authorityReferenceSchema).min(1).max(1_000),
|
||||
authority_references: z.array(authorityReferenceSchema).min(1),
|
||||
source_state: z.enum(["candidate", "observed", "reviewed", "unknown"]),
|
||||
observed_cases: z.array(observedCaseSchema).max(100),
|
||||
observed_cases: z.array(observedCaseSchema),
|
||||
required: z.boolean(),
|
||||
required_case_kinds: z.array(obligationCaseKindSchema).min(1).max(5),
|
||||
required_case_kinds: z.array(obligationCaseKindSchema).min(1),
|
||||
required_original_authority: obligationOriginalAuthoritySchema,
|
||||
required_fixture_authority: obligationProofAuthoritySchema,
|
||||
required_verifier_authority: obligationProofAuthoritySchema,
|
||||
requires_parser_type: z.boolean(),
|
||||
dependency_obligation_ids: z.array(stableIdSchema).max(1_000),
|
||||
residual_unknown_ids: z.array(stableIdSchema).max(1_000),
|
||||
unavailable_authority: z.array(boundedTextSchema).max(100),
|
||||
required_next_evidence: z.array(boundedTextSchema).max(100),
|
||||
dependency_obligation_ids: z.array(stableIdSchema),
|
||||
residual_unknown_ids: z.array(stableIdSchema),
|
||||
unavailable_authority: z.array(boundedTextSchema),
|
||||
required_next_evidence: z.array(boundedTextSchema),
|
||||
binding: reconstructionObligationManifestBindingSchema.nullable(),
|
||||
status: obligationStatusSchema,
|
||||
diagnostics: z.array(diagnosticSchema).max(1_000),
|
||||
diagnostics: z.array(diagnosticSchema),
|
||||
});
|
||||
|
||||
const countBySchema = <Schema extends z.ZodType>(
|
||||
@@ -274,9 +272,9 @@ export const reconstructionObligationLedgerSchema = z.strictObject({
|
||||
depends_on_obligation_id: stableIdSchema,
|
||||
}),
|
||||
),
|
||||
obligations: z.array(reconstructionObligationSchema).max(10_000),
|
||||
evidence_links: z.array(evidenceIdSchema).max(100_000),
|
||||
limitations: z.array(boundedTextSchema).max(1_000),
|
||||
obligations: z.array(reconstructionObligationSchema),
|
||||
evidence_links: z.array(evidenceIdSchema),
|
||||
limitations: z.array(boundedTextSchema),
|
||||
});
|
||||
|
||||
export const reconstructionObligationLedgerInputSchema = z.strictObject({
|
||||
|
||||
@@ -2,7 +2,10 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { RECONSTRUCTION_READINESS_EXAMPLE } from "../contracts/reconstructionReadinessExample.js";
|
||||
import { createReconstructionReadinessReport } from "./reconstructionReadiness.js";
|
||||
import type { ReconstructionReadinessInput } from "./reconstructionReadinessSchemas.js";
|
||||
import {
|
||||
reconstructionReadinessInputSchema,
|
||||
type ReconstructionReadinessInput,
|
||||
} from "./reconstructionReadinessSchemas.js";
|
||||
|
||||
const input = (
|
||||
overrides: Partial<ReconstructionReadinessInput> = {},
|
||||
@@ -12,6 +15,17 @@ const input = (
|
||||
});
|
||||
|
||||
describe("reconstruction readiness report", () => {
|
||||
it("accepts every caller supplied capability", () => {
|
||||
const capability = RECONSTRUCTION_READINESS_EXAMPLE.capabilities[0];
|
||||
if (capability === undefined) throw new TypeError("Missing capability");
|
||||
|
||||
const parsed = reconstructionReadinessInputSchema.parse(
|
||||
input({ capabilities: Array.from({ length: 1_001 }, () => capability) }),
|
||||
);
|
||||
|
||||
expect(parsed.capabilities).toHaveLength(1_001);
|
||||
});
|
||||
|
||||
it("passes the complete repository conformance journey deterministically", () => {
|
||||
const first = createReconstructionReadinessReport(input());
|
||||
const second = createReconstructionReadinessReport(input());
|
||||
|
||||
@@ -5,8 +5,8 @@ import { reconstructionObligationLedgerSchema } from "./reconstructionObligation
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const stableIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._:/-]{0,199}$/u);
|
||||
const boundedTextSchema = z.string().trim().min(1).max(4_096);
|
||||
const stableIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._:/-]*$/u);
|
||||
const boundedTextSchema = z.string().trim().min(1);
|
||||
|
||||
export const readinessStatusSchema = z.enum([
|
||||
"pass",
|
||||
@@ -62,8 +62,8 @@ const capabilitySchema = z.strictObject({
|
||||
"writes-workspace",
|
||||
"network-observation",
|
||||
]),
|
||||
authority_scopes: z.array(stableIdSchema).max(100),
|
||||
limits: z.array(limitSchema).max(100),
|
||||
authority_scopes: z.array(stableIdSchema),
|
||||
limits: z.array(limitSchema),
|
||||
unavailable_reason: boundedTextSchema.nullable(),
|
||||
});
|
||||
|
||||
@@ -78,7 +78,7 @@ const fixtureSchema = z.strictObject({
|
||||
]),
|
||||
artifact_sha256: digestSchema,
|
||||
environment_id: stableIdSchema,
|
||||
deliberate_faults: z.array(stableIdSchema).min(1).max(100),
|
||||
deliberate_faults: z.array(stableIdSchema).min(1),
|
||||
});
|
||||
|
||||
const workflowCandidateSchema = z.strictObject({
|
||||
@@ -96,7 +96,7 @@ const grantSchema = z.strictObject({
|
||||
scope: stableIdSchema,
|
||||
decision: z.enum(["granted", "denied", "cancelled", "restart-required"]),
|
||||
launched_process: z.boolean(),
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
const comparisonSchema = z.strictObject({
|
||||
@@ -108,9 +108,9 @@ const comparisonSchema = z.strictObject({
|
||||
unavailable_authority: z.boolean(),
|
||||
unstable: z.boolean(),
|
||||
deliberate_divergence_ref: boundedTextSchema.nullable(),
|
||||
divergence_refs: z.array(boundedTextSchema).max(100),
|
||||
contradiction_ids: z.array(stableIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(1_000),
|
||||
divergence_refs: z.array(boundedTextSchema),
|
||||
contradiction_ids: z.array(stableIdSchema),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const contradictionSchema = z.strictObject({
|
||||
@@ -118,8 +118,8 @@ const contradictionSchema = z.strictObject({
|
||||
declared_sha256: digestSchema,
|
||||
observed_sha256: digestSchema,
|
||||
policy: z.literal("record-and-continue"),
|
||||
affected_comparison_ids: z.array(stableIdSchema).min(1).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(2).max(100),
|
||||
affected_comparison_ids: z.array(stableIdSchema).min(1),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(2),
|
||||
});
|
||||
|
||||
const operationOutcomeSchema = z.strictObject({
|
||||
@@ -140,14 +140,14 @@ const operationOutcomeSchema = z.strictObject({
|
||||
mcp_status: z.enum(["success", "non-success"]).nullable(),
|
||||
error_code: stableIdSchema.nullable(),
|
||||
recovered: z.boolean(),
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
const cleanupSchema = z.strictObject({
|
||||
run_id: stableIdSchema,
|
||||
cancelled: z.boolean(),
|
||||
owned_resources_remaining: z.number().int().min(0),
|
||||
diagnostic_evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
diagnostic_evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
const closureObservationSchema = z.strictObject({
|
||||
@@ -155,21 +155,21 @@ const closureObservationSchema = z.strictObject({
|
||||
ledger_digest: digestSchema,
|
||||
status: z.enum(["ready", "open", "failed", "unknown"]),
|
||||
required_open: z.number().int().min(0),
|
||||
newly_verified_obligation_ids: z.array(stableIdSchema).max(10_000),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(1_000),
|
||||
newly_verified_obligation_ids: z.array(stableIdSchema),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const delegationCheckSchema = z.strictObject({
|
||||
candidate_id: stableIdSchema,
|
||||
delegates_to_authority: z.boolean(),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
const stageCheckSchema = z.strictObject({
|
||||
check_id: stableIdSchema,
|
||||
status: readinessStatusSchema,
|
||||
detail: boundedTextSchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
const stageSchema = z.strictObject({
|
||||
@@ -178,8 +178,8 @@ const stageSchema = z.strictObject({
|
||||
status: readinessStatusSchema,
|
||||
capability_issue: stableIdSchema.nullable(),
|
||||
next_action: boundedTextSchema.nullable(),
|
||||
evidence_ids: z.array(evidenceIdSchema).max(1_000),
|
||||
checks: z.array(stageCheckSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
checks: z.array(stageCheckSchema),
|
||||
});
|
||||
|
||||
const replaySchema = z.strictObject({
|
||||
@@ -187,7 +187,7 @@ const replaySchema = z.strictObject({
|
||||
deterministic: z.boolean(),
|
||||
tamper_detected: z.boolean(),
|
||||
stale_input_detected: z.boolean(),
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
export const reconstructionReadinessInputSchema = z.strictObject({
|
||||
@@ -196,26 +196,26 @@ export const reconstructionReadinessInputSchema = z.strictObject({
|
||||
server_version: boundedTextSchema,
|
||||
catalog_digest: digestSchema,
|
||||
skill_digest: digestSchema.nullable(),
|
||||
versions: z.array(versionObservationSchema).min(1).max(100),
|
||||
providers: z.array(providerIdentitySchema).max(100),
|
||||
versions: z.array(versionObservationSchema).min(1),
|
||||
providers: z.array(providerIdentitySchema),
|
||||
}),
|
||||
client: z.strictObject({
|
||||
name: boundedTextSchema,
|
||||
version: boundedTextSchema,
|
||||
negotiated_capabilities: z.array(stableIdSchema).max(100),
|
||||
negotiated_capabilities: z.array(stableIdSchema),
|
||||
}),
|
||||
capabilities: z.array(capabilitySchema).min(1).max(1_000),
|
||||
fixtures: z.array(fixtureSchema).min(1).max(100),
|
||||
workflow_candidates: z.array(workflowCandidateSchema).min(1).max(1_000),
|
||||
grants: z.array(grantSchema).max(1_000),
|
||||
capabilities: z.array(capabilitySchema).min(1),
|
||||
fixtures: z.array(fixtureSchema).min(1),
|
||||
workflow_candidates: z.array(workflowCandidateSchema).min(1),
|
||||
grants: z.array(grantSchema),
|
||||
evidence_bundle: evidenceBundleSchema,
|
||||
comparisons: z.array(comparisonSchema).max(1_000),
|
||||
contradictions: z.array(contradictionSchema).max(1_000),
|
||||
comparisons: z.array(comparisonSchema),
|
||||
contradictions: z.array(contradictionSchema),
|
||||
obligation_ledger: reconstructionObligationLedgerSchema,
|
||||
operation_outcomes: z.array(operationOutcomeSchema).max(10_000),
|
||||
cleanup: z.array(cleanupSchema).max(1_000),
|
||||
closure_history: z.array(closureObservationSchema).min(2).max(1_000),
|
||||
delegation_checks: z.array(delegationCheckSchema).min(1).max(1_000),
|
||||
operation_outcomes: z.array(operationOutcomeSchema),
|
||||
cleanup: z.array(cleanupSchema),
|
||||
closure_history: z.array(closureObservationSchema).min(2),
|
||||
delegation_checks: z.array(delegationCheckSchema).min(1),
|
||||
replay: replaySchema,
|
||||
stages: z
|
||||
.array(stageSchema)
|
||||
@@ -239,7 +239,7 @@ const findingSchema = z.strictObject({
|
||||
stage_id: readinessStageIdSchema,
|
||||
status: z.enum(["fail", "unknown"]),
|
||||
detail: boundedTextSchema,
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
});
|
||||
|
||||
export const reconstructionReadinessReportSchema = z.strictObject({
|
||||
@@ -283,8 +283,8 @@ export const reconstructionReadinessReportSchema = z.strictObject({
|
||||
seen.add(stage.stage_id);
|
||||
});
|
||||
}),
|
||||
findings: z.array(findingSchema).max(10_000),
|
||||
evidence_links: z.array(evidenceIdSchema).max(100_000),
|
||||
findings: z.array(findingSchema),
|
||||
evidence_links: z.array(evidenceIdSchema),
|
||||
snapshot: reconstructionReadinessInputSchema,
|
||||
});
|
||||
|
||||
|
||||
@@ -313,6 +313,47 @@ describe("reconstruction verification", () => {
|
||||
});
|
||||
|
||||
describe("reconstruction verification integrity", () => {
|
||||
it("accepts evidence closures larger than the former count ceilings", () => {
|
||||
const evidenceIds = Array.from(
|
||||
{ length: 20_101 },
|
||||
(_, index) => `ev_${index.toString(16).padStart(64, "0")}`,
|
||||
);
|
||||
const claimLinks = evidenceIds.slice(0, 202);
|
||||
const claim = {
|
||||
claim_id: "claim",
|
||||
kind: "structural-artifact",
|
||||
dimension: "overall",
|
||||
status: "pass",
|
||||
observed_status: "unchanged",
|
||||
comparison_evidence_id: claimLinks[0],
|
||||
left_evidence_ids: [claimLinks[1]],
|
||||
right_evidence_ids: [claimLinks[2]],
|
||||
evidence_links: claimLinks,
|
||||
unknown_ids: [],
|
||||
limitations: [],
|
||||
};
|
||||
const result = {
|
||||
status: "pass",
|
||||
specification_sha256: "a".repeat(64),
|
||||
summary: {
|
||||
total: 1,
|
||||
passed: 1,
|
||||
failed: 0,
|
||||
unknown: 0,
|
||||
behavioral: 0,
|
||||
structural: 1,
|
||||
},
|
||||
claims: { items: [claim] },
|
||||
recommended_probes: [],
|
||||
evidence_links: evidenceIds,
|
||||
limitations: [],
|
||||
};
|
||||
|
||||
expect(reconstructionVerificationResultSchema.parse(result)).toEqual(
|
||||
result,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects dangling or extra comparison closure", () => {
|
||||
const left = source("1", "controlled-replay");
|
||||
const right = source("2", "controlled-replay");
|
||||
|
||||
@@ -39,10 +39,6 @@ export {
|
||||
} from "./reconstructionVerificationSchemas.js";
|
||||
export type { ReconstructionVerificationResult } from "./reconstructionVerificationSchemas.js";
|
||||
|
||||
const MAX_BUNDLE_RECORDS = 20_100;
|
||||
const MAX_UNKNOWN_REVISIONS = 10_000;
|
||||
const MAX_CANONICAL_BYTES = 32 * 1024 * 1024;
|
||||
|
||||
const providers = {
|
||||
behavioral: {
|
||||
operation: "compare_process_captures",
|
||||
@@ -76,12 +72,7 @@ export const verifyReconstruction = (
|
||||
): ReconstructionVerificationResult => {
|
||||
const specification =
|
||||
reconstructionSpecificationSchema.parse(specificationInput);
|
||||
enforceInputSize(bundleInput);
|
||||
const bundle = parseEvidenceBundle(bundleInput);
|
||||
if (bundle.records.length > MAX_BUNDLE_RECORDS)
|
||||
throw new TypeError("Reconstruction Evidence record limit exceeded");
|
||||
if (bundle.unknowns.length > MAX_UNKNOWN_REVISIONS)
|
||||
throw new TypeError("Reconstruction unknown revision limit exceeded");
|
||||
const records = new Map(
|
||||
bundle.records.map((item) => [item.evidence_id, item]),
|
||||
);
|
||||
@@ -95,8 +86,6 @@ export const verifyReconstruction = (
|
||||
const evidenceLinks = uniqueSorted(
|
||||
results.flatMap(({ evidence_links: links }) => links),
|
||||
);
|
||||
if (evidenceLinks.length > 20_100)
|
||||
throw new TypeError("Reconstruction Evidence closure exceeds limit");
|
||||
const output = {
|
||||
status: failed > 0 ? "fail" : unresolved > 0 ? "unknown" : "pass",
|
||||
specification_sha256: digest({
|
||||
@@ -248,8 +237,8 @@ const sourceSides = (
|
||||
}
|
||||
const parsed = z
|
||||
.object({
|
||||
left_evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
right_evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
left_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
right_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
})
|
||||
.passthrough()
|
||||
.parse(parameters);
|
||||
@@ -374,15 +363,6 @@ const digest = (value: unknown): string => {
|
||||
return createHash("sha256").update(encoded).digest("hex");
|
||||
};
|
||||
|
||||
const enforceInputSize = (value: unknown): void => {
|
||||
const encoded = canonicalize(value);
|
||||
if (
|
||||
encoded === undefined ||
|
||||
Buffer.byteLength(encoded, "utf8") > MAX_CANONICAL_BYTES
|
||||
)
|
||||
throw new TypeError("Reconstruction Evidence bundle exceeds byte limit");
|
||||
};
|
||||
|
||||
const count = (
|
||||
items: readonly ClaimResult[],
|
||||
status: ClaimResult["status"],
|
||||
|
||||
@@ -96,7 +96,7 @@ export const reconstructionClaimResultSchema = z.object({
|
||||
comparison_evidence_id: evidenceIdSchema,
|
||||
left_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
right_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3).max(201),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3),
|
||||
unknown_ids: z.array(unknownIdSchema),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
@@ -125,7 +125,7 @@ export const reconstructionVerificationResultSchema = z
|
||||
unknown_ids: z.array(unknownIdSchema),
|
||||
}),
|
||||
),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3).max(20_100),
|
||||
evidence_links: z.array(evidenceIdSchema).min(3),
|
||||
limitations: z.array(z.string()),
|
||||
})
|
||||
.superRefine((result, context) => {
|
||||
|
||||
@@ -26,12 +26,12 @@ const resolutionSchema = z.discriminatedUnion("disposition", [
|
||||
z.object({
|
||||
disposition: z.literal("verified"),
|
||||
rationale: boundedText,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
}),
|
||||
z.object({
|
||||
disposition: z.enum(["withdrawn", "out-of-scope"]),
|
||||
rationale: boundedText,
|
||||
evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -58,8 +58,8 @@ const residualUnknownObjectSchema = z.object({
|
||||
]),
|
||||
severity: z.enum(["low", "medium", "high", "critical"]),
|
||||
domain: z.string().trim().min(1).max(100),
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema),
|
||||
required_authority: z
|
||||
.enum([
|
||||
"shipped-artifact",
|
||||
@@ -71,10 +71,10 @@ const residualUnknownObjectSchema = z.object({
|
||||
.nullable(),
|
||||
required_confidence: z.enum(["observed", "derived", "inferred"]),
|
||||
required_environment: environmentRequirementSchema.nullable(),
|
||||
recommended_probes: z.array(probeSchema).max(20),
|
||||
relationships: z.array(relationshipSchema).max(100),
|
||||
recommended_probes: z.array(probeSchema),
|
||||
relationships: z.array(relationshipSchema),
|
||||
resolution: resolutionSchema.nullable(),
|
||||
mutation_evidence_ids: z.array(evidenceIdSchema).min(1).max(100),
|
||||
mutation_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
});
|
||||
|
||||
export const residualUnknownSchema = residualUnknownObjectSchema.superRefine(
|
||||
@@ -126,10 +126,9 @@ export const residualUnknownSchema = residualUnknownObjectSchema.superRefine(
|
||||
code: "custom",
|
||||
message: "Evidence IDs must be unique",
|
||||
});
|
||||
const contradictingEvidence = new Set(value.contradicting_evidence_ids);
|
||||
if (
|
||||
value.supporting_evidence_ids.some((id) =>
|
||||
value.contradicting_evidence_ids.includes(id),
|
||||
)
|
||||
value.supporting_evidence_ids.some((id) => contradictingEvidence.has(id))
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -165,8 +164,8 @@ export const recordUnknownInputSchema = residualUnknownObjectSchema
|
||||
mutation_evidence_ids: true,
|
||||
})
|
||||
.extend({
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema).max(100).default([]),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema).max(100).default([]),
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema).default([]),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema).default([]),
|
||||
});
|
||||
|
||||
export type RecordUnknownInput = z.infer<typeof recordUnknownInputSchema>;
|
||||
@@ -177,13 +176,13 @@ export const updateUnknownInputSchema = z.object({
|
||||
expected_revision: z.number().int().min(1),
|
||||
status: residualUnknownObjectSchema.shape.status,
|
||||
severity: residualUnknownObjectSchema.shape.severity,
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema).max(100),
|
||||
supporting_evidence_ids: z.array(evidenceIdSchema),
|
||||
contradicting_evidence_ids: z.array(evidenceIdSchema),
|
||||
required_authority: residualUnknownObjectSchema.shape.required_authority,
|
||||
required_confidence: residualUnknownObjectSchema.shape.required_confidence,
|
||||
required_environment: environmentRequirementSchema.nullable(),
|
||||
recommended_probes: z.array(probeSchema).max(20),
|
||||
relationships: z.array(relationshipSchema).max(100),
|
||||
recommended_probes: z.array(probeSchema),
|
||||
relationships: z.array(relationshipSchema),
|
||||
resolution: resolutionSchema.nullable(),
|
||||
});
|
||||
|
||||
|
||||
@@ -4,19 +4,19 @@ import canonicalize from "canonicalize";
|
||||
import { z } from "zod";
|
||||
|
||||
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
||||
const stableIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._:/-]{0,199}$/u);
|
||||
const stableIdSchema = z.string().regex(/^[A-Za-z][A-Za-z0-9._:/-]*$/u);
|
||||
|
||||
const runtimeIdentitySchema = z.strictObject({
|
||||
family: z.string().trim().min(1).max(100),
|
||||
family: z.string().trim().min(1),
|
||||
provider_id: stableIdSchema,
|
||||
executable_path: z.string().min(1).max(4_096),
|
||||
executable_path: z.string().min(1),
|
||||
executable_sha256: digestSchema,
|
||||
version: z.string().trim().min(1).max(500),
|
||||
version: z.string().trim().min(1),
|
||||
profile_sha256: digestSchema,
|
||||
});
|
||||
|
||||
const artifactIdentitySchema = z.strictObject({
|
||||
path: z.string().min(1).max(4_096),
|
||||
path: z.string().min(1),
|
||||
sha256: digestSchema,
|
||||
byte_length: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
||||
});
|
||||
@@ -24,7 +24,7 @@ const artifactIdentitySchema = z.strictObject({
|
||||
const callableIdentitySchema = z.strictObject({
|
||||
callable_id: stableIdSchema,
|
||||
module_id: stableIdSchema,
|
||||
export_name: z.string().min(1).max(1_000),
|
||||
export_name: z.string().min(1),
|
||||
semantic_evidence_id: z
|
||||
.string()
|
||||
.regex(/^ev_[a-f0-9]{64}$/u)
|
||||
@@ -38,18 +38,18 @@ export const runtimeCharacterizationPlanSchema = z.strictObject({
|
||||
artifact: artifactIdentitySchema,
|
||||
runtime: runtimeIdentitySchema,
|
||||
callable: callableIdentitySchema,
|
||||
working_directory: z.string().min(1).max(4_096),
|
||||
isolated_home: z.string().min(1).max(4_096),
|
||||
working_directory: z.string().min(1),
|
||||
isolated_home: z.string().min(1),
|
||||
expected_effect: z.enum(["pure", "bounded-effects", "observation-only"]),
|
||||
allowed_boundaries: z.array(stableIdSchema).max(1_000),
|
||||
allowed_boundaries: z.array(stableIdSchema),
|
||||
limits: z.strictObject({
|
||||
max_calls: z.number().int().min(1).max(10_000),
|
||||
max_processes: z.number().int().min(0).max(1_000),
|
||||
max_files: z.number().int().min(0).max(100_000),
|
||||
max_calls: z.number().int().min(1),
|
||||
max_processes: z.number().int().min(0),
|
||||
max_files: z.number().int().min(0),
|
||||
max_bytes: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
||||
max_handles: z.number().int().min(0).max(100_000),
|
||||
timeout_ms: z.number().int().min(1).max(300_000),
|
||||
idle_timeout_ms: z.number().int().min(1).max(300_000),
|
||||
max_handles: z.number().int().min(0),
|
||||
timeout_ms: z.number().int().min(1),
|
||||
idle_timeout_ms: z.number().int().min(1),
|
||||
}),
|
||||
determinism: z.strictObject({
|
||||
clock: z.enum(["fixed", "real"]),
|
||||
|
||||
@@ -17,10 +17,10 @@ const runtimeFamilySchema = z.enum([
|
||||
"webassembly",
|
||||
]);
|
||||
const observationSchema = z.strictObject({
|
||||
path: z.string().min(1).max(4_096),
|
||||
path: z.string().min(1),
|
||||
artifact_id: z.string().regex(/^art_[a-f0-9]{64}$/u),
|
||||
sha256: digestSchema,
|
||||
format: z.string().min(1).max(100),
|
||||
format: z.string().min(1),
|
||||
});
|
||||
const runtimeObservationShape = {
|
||||
family: runtimeFamilySchema,
|
||||
@@ -30,20 +30,20 @@ const identifiedRuntimeSchema = z.discriminatedUnion("inspection", [
|
||||
z.strictObject({
|
||||
...runtimeObservationShape,
|
||||
inspection: z.literal("available"),
|
||||
provider_id: z.string().min(1).max(200),
|
||||
provider_id: z.string().min(1),
|
||||
reason: z.null(),
|
||||
}),
|
||||
z.strictObject({
|
||||
...runtimeObservationShape,
|
||||
inspection: z.literal("provider-missing"),
|
||||
provider_id: z.null(),
|
||||
reason: z.string().min(1).max(1_000),
|
||||
reason: z.string().min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
...runtimeObservationShape,
|
||||
inspection: z.literal("provider-selection-required"),
|
||||
provider_id: z.null(),
|
||||
reason: z.string().min(1).max(1_000),
|
||||
reason: z.string().min(1),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -56,14 +56,14 @@ const runtimeIdentificationInputSchema = z.strictObject({
|
||||
export const runtimeIdentificationResultSchema = z.strictObject({
|
||||
identification_id: z.string().regex(/^rid_[a-f0-9]{64}$/u),
|
||||
root_sha256: digestSchema,
|
||||
root_format: z.string().min(1).max(100),
|
||||
root_format: z.string().min(1),
|
||||
source_evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
runtimes: z.array(identifiedRuntimeSchema),
|
||||
coverage: z.strictObject({
|
||||
status: z.enum(["complete-within-inventory", "partial"]),
|
||||
inventory_complete: z.boolean(),
|
||||
}),
|
||||
limitations: z.array(z.string().min(1).max(4_096)).max(100),
|
||||
limitations: z.array(z.string().min(1)),
|
||||
});
|
||||
|
||||
export type RuntimeIdentificationInput = z.input<
|
||||
|
||||
@@ -82,12 +82,12 @@ const mappingSchema = z
|
||||
})
|
||||
.strict();
|
||||
|
||||
/** Strict bounded input for explicit static/runtime hypothesis correlation. */
|
||||
/** Strict input for explicit static/runtime hypothesis correlation. */
|
||||
export const staticRuntimeCorrelationInputSchema = z
|
||||
.object({
|
||||
static_comparisons: z.array(evidenceSchema).min(1).max(100),
|
||||
runtime_comparisons: z.array(evidenceSchema).min(1).max(100),
|
||||
mappings: z.array(mappingSchema).min(1).max(500),
|
||||
static_comparisons: z.array(evidenceSchema).min(1),
|
||||
runtime_comparisons: z.array(evidenceSchema).min(1),
|
||||
mappings: z.array(mappingSchema).min(1),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -115,7 +115,7 @@ const correlationItemSchema = z.object({
|
||||
}),
|
||||
observed_pattern: observedPatternSchema,
|
||||
classification: z.enum(["hypothesis", "contradiction", "unresolved_branch"]),
|
||||
evidence_links: z.array(evidenceIdSchema).min(2).max(20_100),
|
||||
evidence_links: z.array(evidenceIdSchema).min(2),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
@@ -130,7 +130,7 @@ export const staticRuntimeCorrelationResultSchema = z.object({
|
||||
correlations: z.object({
|
||||
items: z.array(correlationItemSchema),
|
||||
}),
|
||||
evidence_links: z.array(evidenceIdSchema).min(2).max(20_100),
|
||||
evidence_links: z.array(evidenceIdSchema).min(2),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
@@ -187,8 +187,6 @@ export const correlateStaticAndRuntime = (
|
||||
const links = uniqueSorted(
|
||||
correlations.flatMap(({ evidence_links: evidenceLinks }) => evidenceLinks),
|
||||
);
|
||||
if (links.length > 20_100)
|
||||
throw new TypeError("Static/runtime Evidence closure exceeds limit");
|
||||
const unresolved = correlations.filter(
|
||||
({ classification }) => classification === "unresolved_branch",
|
||||
);
|
||||
@@ -423,8 +421,8 @@ const comparisonParameterLinks = (evidence: Evidence): string[] => {
|
||||
.object({
|
||||
left_evidence_id: evidenceIdSchema.optional(),
|
||||
right_evidence_id: evidenceIdSchema.optional(),
|
||||
left_evidence_ids: z.array(evidenceIdSchema).min(1).max(100).optional(),
|
||||
right_evidence_ids: z.array(evidenceIdSchema).min(1).max(100).optional(),
|
||||
left_evidence_ids: z.array(evidenceIdSchema).min(1).optional(),
|
||||
right_evidence_ids: z.array(evidenceIdSchema).min(1).optional(),
|
||||
})
|
||||
.passthrough()
|
||||
.parse(evidence.parameters);
|
||||
@@ -441,10 +439,18 @@ const comparisonParameterLinks = (evidence: Evidence): string[] => {
|
||||
return [...left, ...right];
|
||||
};
|
||||
|
||||
const sameSet = (left: readonly string[], right: readonly string[]): boolean =>
|
||||
left.length === right.length &&
|
||||
new Set(left).size === left.length &&
|
||||
left.every((item) => right.includes(item));
|
||||
const sameSet = (
|
||||
left: readonly string[],
|
||||
right: readonly string[],
|
||||
): boolean => {
|
||||
if (left.length !== right.length) return false;
|
||||
const rightSet = new Set(right);
|
||||
return (
|
||||
rightSet.size === right.length &&
|
||||
new Set(left).size === left.length &&
|
||||
left.every((item) => rightSet.has(item))
|
||||
);
|
||||
};
|
||||
|
||||
const observedPattern = (
|
||||
staticStatus: ComparisonStatus,
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
FUNCTION_COMPARISON_EVIDENCE,
|
||||
INVESTIGATION_EXAMPLES,
|
||||
PROCESS_COMPARISON_EVIDENCE,
|
||||
} from "../contracts/investigationExamples.js";
|
||||
import {
|
||||
createResidualUnknown,
|
||||
recordUnknownInputSchema,
|
||||
residualUnknownSchema,
|
||||
updateResidualUnknown,
|
||||
updateUnknownInputSchema,
|
||||
} from "./residualUnknown.js";
|
||||
import {
|
||||
correlateStaticAndRuntime,
|
||||
staticRuntimeCorrelationInputSchema,
|
||||
staticRuntimeCorrelationResultSchema,
|
||||
} from "./staticRuntimeCorrelation.js";
|
||||
|
||||
const evidenceId = (index: number): string =>
|
||||
`ev_${index.toString(16).padStart(64, "0")}`;
|
||||
|
||||
const unknownId = (index: number): string =>
|
||||
`unk_${index.toString(16).padStart(64, "0")}`;
|
||||
|
||||
it("accepts complete residual unknown evidence, probe, and relationship lists", () => {
|
||||
const supportingEvidence = Array.from({ length: 101 }, (_, i) =>
|
||||
evidenceId(i + 1),
|
||||
);
|
||||
const contradictingEvidence = Array.from({ length: 101 }, (_, i) =>
|
||||
evidenceId(i + 102),
|
||||
);
|
||||
const relationships = Array.from({ length: 101 }, (_, i) => ({
|
||||
type: "related-to" as const,
|
||||
unknown_id: unknownId(i + 1),
|
||||
}));
|
||||
const recommendedProbes = Array.from({ length: 21 }, (_, i) => ({
|
||||
operation: `inspect_${i}`,
|
||||
rationale: `Inspect evidence path ${i}.`,
|
||||
}));
|
||||
const recordInput = recordUnknownInputSchema.parse({
|
||||
question: "Does this behavior depend on an external service?",
|
||||
severity: "medium",
|
||||
domain: "protocol",
|
||||
supporting_evidence_ids: supportingEvidence,
|
||||
contradicting_evidence_ids: contradictingEvidence,
|
||||
required_authority: "controlled-replay",
|
||||
required_confidence: "observed",
|
||||
required_environment: null,
|
||||
recommended_probes: recommendedProbes,
|
||||
relationships,
|
||||
});
|
||||
const created = createResidualUnknown(recordInput, evidenceId(500), null);
|
||||
|
||||
expect(created.supporting_evidence_ids).toHaveLength(101);
|
||||
expect(created.contradicting_evidence_ids).toHaveLength(101);
|
||||
expect(created.recommended_probes).toHaveLength(21);
|
||||
expect(created.relationships).toHaveLength(101);
|
||||
|
||||
const updateInput = updateUnknownInputSchema.parse({
|
||||
unknown_id: created.unknown_id,
|
||||
expected_revision: created.revision,
|
||||
status: "investigating",
|
||||
severity: created.severity,
|
||||
supporting_evidence_ids: supportingEvidence,
|
||||
contradicting_evidence_ids: contradictingEvidence,
|
||||
required_authority: created.required_authority,
|
||||
required_confidence: created.required_confidence,
|
||||
required_environment: created.required_environment,
|
||||
recommended_probes: recommendedProbes,
|
||||
relationships,
|
||||
resolution: null,
|
||||
});
|
||||
const updated = updateResidualUnknown(created, updateInput, evidenceId(501));
|
||||
|
||||
expect(residualUnknownSchema.parse(updated)).toMatchObject({
|
||||
revision: 2,
|
||||
mutation_evidence_ids: [evidenceId(500), evidenceId(501)],
|
||||
supporting_evidence_ids: supportingEvidence,
|
||||
contradicting_evidence_ids: contradictingEvidence,
|
||||
recommended_probes: recommendedProbes,
|
||||
relationships,
|
||||
});
|
||||
expect(() =>
|
||||
recordUnknownInputSchema.parse({
|
||||
...recordInput,
|
||||
supporting_evidence_ids: ["not-an-evidence-id"],
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("correlates every supplied mapping and accepts complete comparison lists", () => {
|
||||
const [mapping] =
|
||||
INVESTIGATION_EXAMPLES.correlate_static_and_runtime.mappings;
|
||||
if (mapping === undefined) throw new Error("missing correlation example");
|
||||
const mappings = Array.from({ length: 501 }, (_, i) => ({
|
||||
...mapping,
|
||||
hypothesis: {
|
||||
...mapping.hypothesis,
|
||||
statement: `Hypothesis ${i}`,
|
||||
},
|
||||
}));
|
||||
const input = {
|
||||
static_comparisons: Array.from(
|
||||
{ length: 101 },
|
||||
() => FUNCTION_COMPARISON_EVIDENCE,
|
||||
),
|
||||
runtime_comparisons: Array.from(
|
||||
{ length: 101 },
|
||||
() => PROCESS_COMPARISON_EVIDENCE,
|
||||
),
|
||||
mappings,
|
||||
};
|
||||
|
||||
expect(
|
||||
staticRuntimeCorrelationInputSchema.parse(input).mappings,
|
||||
).toHaveLength(501);
|
||||
const fullInput = {
|
||||
...input,
|
||||
static_comparisons: [FUNCTION_COMPARISON_EVIDENCE],
|
||||
runtime_comparisons: [PROCESS_COMPARISON_EVIDENCE],
|
||||
};
|
||||
const result = correlateStaticAndRuntime(fullInput);
|
||||
expect(result.correlations.items).toHaveLength(501);
|
||||
|
||||
expect(
|
||||
staticRuntimeCorrelationResultSchema.parse({
|
||||
...result,
|
||||
evidence_links: Array.from({ length: 20_101 }, (_, i) => evidenceId(i)),
|
||||
}).evidence_links,
|
||||
).toHaveLength(20_101);
|
||||
});
|
||||
@@ -94,6 +94,31 @@ describe("web bundle analyzer", () => {
|
||||
expect(result.completeness.status).toBe("complete");
|
||||
});
|
||||
|
||||
it("retains complete long chunk and WebMCP declaration text", () => {
|
||||
const specifier = `./${"chunk".repeat(1_000)}.js`;
|
||||
const name = "tool".repeat(100);
|
||||
const description = "untrusted declaration ".repeat(150);
|
||||
const propertyName = "property".repeat(100);
|
||||
const result = analyzeCapturedWebBundle(
|
||||
inspection(`
|
||||
import "${specifier}";
|
||||
document.modelContext.registerTool({
|
||||
name: "${name}",
|
||||
description: "${description}",
|
||||
inputSchema: { properties: { "${propertyName}": { type: "string" } } }
|
||||
});
|
||||
`),
|
||||
);
|
||||
|
||||
expect(result.observations.chunks.edges[0]?.specifier).toBe(specifier);
|
||||
expect(result.observations.webmcp_declarations[0]).toMatchObject({
|
||||
name,
|
||||
description,
|
||||
schema_property_names: [propertyName],
|
||||
trust: "page-declared-untrusted",
|
||||
});
|
||||
});
|
||||
|
||||
it("reports unavailable source maps as partial without dropping requested maps", () => {
|
||||
const analysis = analyzeCapturedWebBundle(inspection("export {};"), {
|
||||
status: "unavailable",
|
||||
|
||||
@@ -190,14 +190,13 @@ interface AddEdgeContext {
|
||||
}
|
||||
|
||||
const addEdge = (context: AddEdgeContext): void => {
|
||||
const bounded = context.specifier.slice(0, 4_096);
|
||||
const key = `edge\0${context.script.script_key}\0${context.kind}\0${bounded}`;
|
||||
const key = `edge\0${context.script.script_key}\0${context.kind}\0${context.specifier}`;
|
||||
addUnique(context.accumulator, key, () =>
|
||||
context.accumulator.edges.push({
|
||||
from_script_key: context.script.script_key,
|
||||
kind: context.kind,
|
||||
specifier: bounded,
|
||||
resolved_url: resolveSpecifier(bounded, context.script.url),
|
||||
specifier: context.specifier,
|
||||
resolved_url: resolveSpecifier(context.specifier, context.script.url),
|
||||
location: location(context.script.script_key, context.node),
|
||||
}),
|
||||
);
|
||||
@@ -252,11 +251,9 @@ const addWebMcpDeclaration = (
|
||||
const key = `webmcp\0${script.script_key}\0${name ?? ""}\0${schemaPropertyNames.join("\0")}`;
|
||||
addUnique(accumulator, key, () =>
|
||||
accumulator.webMcp.push({
|
||||
name: name?.slice(0, 256) ?? null,
|
||||
description: description?.slice(0, 2_048) ?? null,
|
||||
schema_property_names: [...new Set(schemaPropertyNames)]
|
||||
.sort()
|
||||
.slice(0, 256),
|
||||
name: name ?? null,
|
||||
description: description ?? null,
|
||||
schema_property_names: [...new Set(schemaPropertyNames)].sort(),
|
||||
trust: "page-declared-untrusted",
|
||||
location: location(script.script_key, node),
|
||||
}),
|
||||
|
||||
@@ -7,7 +7,7 @@ export const webTextArtifactSchema = z
|
||||
.object({
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
bytes: z.number().int().min(0),
|
||||
media_type: z.string().min(1).max(256),
|
||||
media_type: z.string().min(1),
|
||||
charset: z.literal("utf-8"),
|
||||
text: z.string(),
|
||||
})
|
||||
|
||||
@@ -28,6 +28,13 @@ describe("web content artifacts", () => {
|
||||
.success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("preserves provider media types longer than the former field ceiling", () => {
|
||||
const mediaType = `application/${"x".repeat(300)}`;
|
||||
const artifact = createWebTextArtifact("content", mediaType);
|
||||
|
||||
expect(webTextArtifactSchema.parse(artifact).media_type).toBe(mediaType);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stable web inventory", () => {
|
||||
|
||||
Reference in New Issue
Block a user