refactor(tools): remove arbitrary workflow ceilings

This commit is contained in:
morluto
2026-09-29 17:36:26 +08:00
parent 6c68ff565f
commit 5f73cb061b
28 changed files with 184 additions and 195 deletions
+17 -6
View File
@@ -5,6 +5,7 @@ import {
analysisProfilesEqual,
createAnalysisProfile,
} from "./analysisProfile.js";
import type { JsonValue } from "./jsonValue.js";
const PROVIDER = {
id: "fixture",
@@ -58,15 +59,25 @@ describe("analysis profile commitments", () => {
expect(analysisProfileSchema.parse(profile)).toEqual(profile);
});
it("rejects digest tampering and structurally unsafe parameters", () => {
it("accepts deep, large, and long-string profile parameters", () => {
let nested: JsonValue = "leaf";
for (let index = 0; index < 24; index += 1)
nested = { [`level-${String(index)}`]: nested };
const parameters = {
nested,
entries: Array.from({ length: 5_000 }, (_, index) => index),
long_value: "x".repeat(20 * 1024),
};
const profile = createAnalysisProfile(PROVIDER, parameters);
expect(analysisProfileSchema.parse(profile)).toEqual(profile);
});
it("rejects digest tampering", () => {
const profile = createAnalysisProfile(PROVIDER, { loader: "default" });
expect(() =>
analysisProfileSchema.parse({ ...profile, digest: "0".repeat(64) }),
).toThrow(/digest/u);
expect(() =>
createAnalysisProfile(PROVIDER, {
oversized: "x".repeat(65 * 1024),
}),
).toThrow(/structural limits/u);
});
});
+1 -12
View File
@@ -3,14 +3,8 @@ import { createHash } from "node:crypto";
import canonicalize from "canonicalize";
import { z } from "zod";
import { isJsonWithinLimits } from "./jsonLimits.js";
import { jsonObjectSchema, type JsonValue } from "./jsonValue.js";
const PROFILE_JSON_LIMITS = Object.freeze({
maxDepth: 16,
maxStringLength: 16 * 1024,
maxNodes: 4_096,
});
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
/** Concrete provider identity committed by an analysis profile. */
@@ -20,14 +14,9 @@ export const committedProviderSchema = z.object({
version: z.string().min(1),
});
const boundedParametersSchema = jsonObjectSchema.refine(
(parameters) => isJsonWithinLimits(parameters, PROFILE_JSON_LIMITS),
{ message: "Analysis profile parameters exceed structural limits" },
);
const unsignedAnalysisProfileSchema = z.object({
provider: committedProviderSchema,
parameters: boundedParametersSchema,
parameters: jsonObjectSchema,
});
/** Canonical, provider-neutral commitment to analysis-affecting semantics. */
@@ -79,6 +79,53 @@ const createLargeNativeExportGraph = (): JavaScriptApplicationGraph => {
});
};
it("accepts deeply nested canonical application properties", () => {
let nested: unknown = "leaf";
for (let index = 0; index < 12; index += 1)
nested = { [`level-${String(index)}`]: nested };
const node = createJavaScriptApplicationNode({
kind: "native-export",
identity: {
strategy: "canonical-path",
stability: "artifact-version",
artifact_sha256: APPLICATION_GRAPH_DIGESTS.nativeAddon,
path: "native/deep-export",
},
observations: [
{
label: "deep export",
properties: { nested },
evidence: artifactEvidence(
APPLICATION_GRAPH_DIGESTS.nativeAddon,
"native/deep-export",
"native-analysis-provider",
),
},
],
});
const graph = createJavaScriptApplicationGraph({
schema: "JavaScriptApplicationGraph",
root_node_ids: [node.node_id],
nodes: [node],
edges: [],
coverage: {
status: "complete",
truncated: false,
omitted_count: 0,
limits: [],
},
limitations: [],
});
expect(graph.nodes[0]?.observations[0]?.properties).toEqual({ nested });
expect(
parseJavaScriptApplicationGraph(
JSON.parse(serializeJavaScriptApplicationGraph(graph)),
),
).toEqual(graph);
});
describe("JavaScript Application Graph", () => {
it("defines the complete provider-neutral node and relation vocabulary", () => {
expect(JAVASCRIPT_APPLICATION_NODE_KINDS).toEqual([
@@ -5,7 +5,6 @@ import {
applicationGraphEvidenceSchema,
applicationNodeIdentitySchema,
} from "./javascriptApplicationEvidenceSchemas.js";
import { isJsonWithinDepth } from "./jsonLimits.js";
import { jsonValueSchema } from "./jsonValue.js";
const boundedTextSchema = z.string().min(1);
@@ -70,15 +69,10 @@ export const JAVASCRIPT_APPLICATION_RELATIONS = [
/** Provider-neutral relation categories. */
const applicationRelationSchema = z.enum(JAVASCRIPT_APPLICATION_RELATIONS);
const applicationPropertiesSchema = z
.record(z.string().min(1), jsonValueSchema)
.superRefine((properties, context) => {
if (!isJsonWithinDepth(properties, 6))
context.addIssue({
code: "custom",
message: "Application graph properties exceed the supported depth",
});
});
const applicationPropertiesSchema = z.record(
z.string().min(1),
jsonValueSchema,
);
/** One node observation before its semantic identifier is derived. */
const applicationNodeObservationInputSchema = z.strictObject({
+1 -1
View File
@@ -9,7 +9,7 @@ const nodeIdSchema = z.string().regex(/^jag_node_[a-f0-9]{64}$/u);
const edgeIdSchema = z.string().regex(/^jag_edge_[a-f0-9]{64}$/u);
const boundedTextSchema = z.string().min(1);
/** Literal starting point for one bounded application trace. */
/** Literal starting point for one application feature trace. */
const applicationFeatureSeedSchema = z.strictObject({
kind: z.enum([
"node-id",
@@ -96,21 +96,23 @@ const node = (
kind: (typeof JAVASCRIPT_SEMANTIC_NODE_KINDS)[number],
role: string,
properties: Record<string, string | number | boolean | null> = {},
functionNodeId: string | null = null,
modulePath = "bundle.js",
options: {
readonly functionNodeId?: string | null;
readonly modulePath?: string;
} = {},
): JavaScriptSemanticGraphNode =>
createJavaScriptSemanticGraphNode({
kind,
identity: {
artifact_sha256: SHA,
module_path: modulePath,
module_path: options.modulePath ?? "bundle.js",
source_range: {
start: { line: 1, column: role.length },
end: { line: 1, column: role.length + 1 },
},
role_key: role,
},
function_node_id: functionNodeId,
function_node_id: options.functionNodeId ?? null,
application_node_ids: [],
label: role,
properties,
@@ -120,7 +122,7 @@ const node = (
it("accepts semantic module paths longer than the former schema ceiling", () => {
const modulePath = `${"segment/".repeat(600)}entry.js`;
expect(
node("module", "long-path", {}, null, modulePath).identity.module_path,
node("module", "long-path", {}, { modulePath }).identity.module_path,
).toBe(modulePath);
});
+1 -10
View File
@@ -1,7 +1,6 @@
import { z } from "zod";
import { applicationGraphEvidenceSchema } from "./javascriptApplicationEvidenceSchemas.js";
import { isJsonWithinDepth } from "./jsonLimits.js";
import { jsonValueSchema } from "./jsonValue.js";
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
@@ -190,15 +189,7 @@ const sourceRangeSchema = z
});
});
const semanticPropertiesSchema = z
.record(z.string().min(1), jsonValueSchema)
.superRefine((properties, context) => {
if (!isJsonWithinDepth(properties, 6))
context.addIssue({
code: "custom",
message: "Semantic properties exceed the supported depth",
});
});
const semanticPropertiesSchema = z.record(z.string().min(1), jsonValueSchema);
const semanticNodeIdentitySchema = z.strictObject({
artifact_sha256: digestSchema,
@@ -15,6 +15,7 @@ import {
type JavaScriptSemanticGraphNode,
} from "./javascriptSemanticGraph.js";
import { queryJavaScriptSemanticGraph } from "./javascriptSemanticQuery.js";
import type { JsonValue } from "./jsonValue.js";
const SHA = "a".repeat(64);
const JAG_ID = `jag_${"b".repeat(64)}`;
@@ -91,7 +92,7 @@ const unknownEvidence = (): ApplicationGraphEvidence => ({
const node = (
kind: (typeof JAVASCRIPT_SEMANTIC_NODE_KINDS)[number],
role: string,
properties: Record<string, string | number | boolean | null> = {},
properties: Record<string, JsonValue> = {},
functionNodeId: string | null = null,
): JavaScriptSemanticGraphNode =>
createJavaScriptSemanticGraphNode({
@@ -319,6 +320,16 @@ it("traverses paths beyond the former fixed depth ceiling", () => {
expect(result.nodes).toHaveLength(74);
});
it("accepts deeply nested semantic properties", () => {
let nested: JsonValue = "leaf";
for (let index = 0; index < 12; index += 1)
nested = { [`level-${String(index)}`]: nested };
const result = node("binding", "deep-properties", { nested });
expect(result.properties).toEqual({ nested });
});
it("keeps relevant dynamic frontiers unknown", () => {
const result = queryJavaScriptSemanticGraph(fixtureGraph(true), {
seed: { kind: "literal", value: "TOKEN" },
-48
View File
@@ -1,48 +0,0 @@
import { describe, expect, it } from "vitest";
import { isJsonWithinDepth, isJsonWithinLimits } from "./jsonLimits.js";
const limits = {
maxDepth: 3,
maxStringLength: 8,
maxNodes: 6,
};
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,
);
expect(
isJsonWithinLimits({ one: ["two", { three: "too-long-value" }] }, limits),
).toBe(false);
});
it("enforces depth, node, and object-key limits", () => {
expect(
isJsonWithinLimits(
{ one: { two: { three: null } } },
{
...limits,
maxDepth: 2,
},
),
).toBe(false);
expect(isJsonWithinLimits([1, 2, 3], { ...limits, maxNodes: 3 })).toBe(
false,
);
expect(isJsonWithinLimits({ "too-long-key": true }, limits)).toBe(false);
});
});
-51
View File
@@ -1,51 +0,0 @@
/** Structural limits applied while traversing an unknown JSON value. */
export interface JsonLimits {
readonly maxDepth: number;
readonly maxStringLength: number;
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,
limits: JsonLimits,
): boolean => {
const pending: Array<{ readonly value: unknown; readonly depth: number }> = [
{ value: root, depth: 0 },
];
let nodes = 0;
while (pending.length > 0) {
const current = pending.pop();
if (current === undefined) break;
nodes += 1;
if (nodes > limits.maxNodes || current.depth > limits.maxDepth)
return false;
if (
typeof current.value === "string" &&
current.value.length > limits.maxStringLength
)
return false;
if (typeof current.value !== "object" || current.value === null) continue;
for (const [key, value] of Object.entries(current.value)) {
if (key.length > limits.maxStringLength) return false;
pending.push({ value, depth: current.depth + 1 });
}
}
return true;
};