refactor(analysis): remove fixed result quotas

This commit is contained in:
morluto
2026-09-29 13:57:24 +08:00
parent 0e2738ffb6
commit 20152a9872
105 changed files with 605 additions and 1084 deletions
+10 -3
View File
@@ -121,9 +121,10 @@ match. An export is linked to a callable only through exact lexical/module
relationships recovered by the AST analysis.
Direct return expressions, including expression-bodied arrows, are evaluated
through a bounded execution-free value lattice. Literal object fields are
static observations. Calls, dynamic spreads, computed keys, parser recovery,
and exhausted value, property, or return-site limits remain partial or unknown.
through an execution-free value lattice. Literal object fields and direct
return sites are retained without count quotas. Calls, dynamic spreads,
computed keys, parser recovery, and the value-recursion depth guard remain
partial or unknown.
Nested callable returns are not assigned to their parent callable. Projected
graph observations carry source ranges but never source text.
@@ -176,3 +177,9 @@ Replay observations retain `controlled-replay` authority. They cannot
promote static inference into passive runtime observation or prove that the
original application, renderer, preload, main process, or remote service
behaved identically.
Module and explicit case lists have no fixed item-count ceiling. Planning checks
the complete request against the committed worker-protocol byte limit before
probing executables or reading modules; aggregate module-source and case-input
bytes have their own limits. Preset-generated cases remain capped at 64 because
REA expands that scalar request into case records before sandbox startup.
+1 -1
View File
@@ -11,7 +11,7 @@ The operation performs no filesystem, browser, or Electron I/O. It accepts only
semantically verified Evidence produced by `analyze_javascript_application`,
`inspect_web_page`, `inspect_electron_page`, or
`observe_javascript_runtime`; matching operation names alone
is insufficient. Provider identity, predicate version, subject digest, target
is insufficient. Provider identity, predicate type, subject digest, target
parameters, and normalized-result schemas are checked before reconciliation.
## Workflow
+15 -17
View File
@@ -106,23 +106,22 @@ EncBaseId because ECMA-335 metadata does not require those bit patterns.
- exact raw bytes or bounded value digest;
- raw CIL digest plus separately reported method-header, locals-token, and
exception-region observations where available;
- a deterministic v1 decoded-instruction-tuple digest for completely decoded
- a deterministic decoded-instruction-tuple digest for completely decoded
CIL, with the limitations below.
### Shipped decoded-CIL fingerprint v1
### Shipped decoded-CIL fingerprint
`inspect_managed_members` exposes two method CIL hashes with different byte
boundaries:
| Field | Shipped v1 input | Excluded from the digest |
| Field | Input | Excluded from the digest |
| ---------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `il_sha256` | The exact `il_size` raw CIL bytes after the tiny or fat method header | Method header, locals signature blob, alignment, and extra sections including exception clauses |
| `normalized_il_sha256` | UTF-8 `JSON.stringify` output for the instruction-order array of `[opcode, operand_kind, operand]` tuples | Instruction offsets except projected scalar branch targets, switch targets, resolved metadata/string identities, method header, locals, and exception regions |
The normalized field is available only when the entire CIL stream decodes with
status `present`. A partial, malformed, absent, or over-limit body reports
`null`. The tuple format is defined here and does not add a schema-version field
to the member result.
`null`. The tuple format is defined here.
Tuple operands use these exact projections:
@@ -134,17 +133,17 @@ Tuple operands use these exact projections:
- signed integer and variable operands: decimal strings; floating-point
operands: JavaScript's `String` representation of the decoded IEEE value.
Opcode names retain short/long forms and prefix opcodes. This makes v1 a
Opcode names retain short/long forms and prefix opcodes. This makes the value a
reproducible decoded-tuple fingerprint, not a canonical semantic CIL identity:
it does not resolve tokens across MVIDs, does not commit full control flow or
exception semantics, and does not replace the raw CIL digest. Cross-build
comparison uses the value only as one unique-only structural tier and reports
ambiguity when that evidence is insufficient. A future normalized-CIL v2 must
have an explicit algorithm version, canonical token/literal identities,
ambiguity when that evidence is insufficient. A future normalized-CIL
commitment would need canonical token/literal identities,
complete branch and switch targets, and explicit locals/exception semantics.
For example, a decoded `nop; ret` body serializes exactly as
`[["nop","none",null],["ret","none",null]]` and has v1 digest
`[["nop","none",null],["ret","none",null]]` and has digest
`5e5fad7741cb44bca3a4f045546b7449990da343f612f5f34c0ca30e9eee0636`.
This vector specifies the tuple order, `null` handling, absence of whitespace,
UTF-8 encoding, and lowercase hexadecimal output.
@@ -205,7 +204,7 @@ bounded set of observations needed to investigate a proposition:
- exact strings, numeric constants, enum-like values, and serialization keys;
- branch, switch, exception, loop, call, and field-flow shape;
- construction and generic-instantiation sites;
- raw CIL and decoded-tuple-v1 commitments, plus separate header, locals, and
- raw CIL and decoded-tuple commitments, plus separate header, locals, and
exception observations;
- callers, callees, shared fields, and competing candidates; and
- limitations from reflection, dynamic dispatch, generated code, protection,
@@ -218,12 +217,11 @@ turn that role into the method's durable identity.
Cross-version matching is two-stage:
1. Exact identity requires compatible artifact/module commitments and exact
raw CIL identity; v1 does not expose a standalone complete-method-body
digest.
2. Structural identity compares normalized signatures, the limited v1
raw CIL identity; no standalone complete-method-body digest is exposed.
2. Structural identity compares normalized signatures, the limited
decoded-CIL tuple fingerprint, constants, and bounded shape context. It
reports all candidates at the winning score and remains ambiguous when the
evidence does not distinguish them. The v1 digest does not itself remap
evidence does not distinguish them. The digest does not itself remap
metadata tokens.
Tokens are always remapped through observed structure. A caller cannot carry
@@ -374,8 +372,8 @@ manifest supplies those fields. It then pages each declared MethodDef token
directly by row, so selected methods do not need to appear in the first member
page of a large application. `il_length` remains accepted as a legacy alias for
`il_size`; optional `il_sha256` locks the exact raw CIL bytes in addition to
REA's member-result-v1 decoded-instruction-tuple digest. That normalized field
has the v1 limits documented above and is not a complete semantic CIL identity.
REA's decoded-instruction-tuple digest. That normalized field has the limits
documented above and is not a complete semantic CIL identity.
The optional `application_graph` block reuses those exact-build method
commitments. For each referenced MethodDef token, the verifier builds a bounded
@@ -424,7 +422,7 @@ The managed-code track advances as reviewable pull requests:
1. accepted evidence/provider boundary (this document and ADR);
2. read-only artifact triage and exact identity (shipped);
3. bounded metadata, signatures, method bodies, raw CIL hashes, and the limited
decoded-instruction-tuple fingerprint v1 (shipped; normalized-CIL v2
decoded-instruction-tuple fingerprint (shipped; complete normalized-CIL
semantics remain planned);
4. obfuscation-resistant slices and cross-version comparison (shipped for
static member observations);
+1 -1
View File
@@ -17,7 +17,7 @@ const completionClaim = ({
...new Set(targets.map(({ sha256: digest }) => digest)),
].sort();
const evidence = createEvidence(targets[0], COMPLETION_PROVIDER, {
predicateType: "rea.verification/v1",
predicateType: "rea.verification",
operation: "verify_managed_conformance",
parameters: {
scenario_id: scenarioId,
+1 -1
View File
@@ -19,7 +19,7 @@ export const projectAndroidApplicationEvidence = (
schema: androidApplicationProjectionInputSchema,
project: projectAndroidApplication,
operation: OPERATION,
predicateType: "rea.android-application-graph/v1",
predicateType: "rea.android-application-graph",
provider: ANDROID_APPLICATION_PROVIDER,
subjectFormat: () => "apk",
protocolError: "Android application projection produced an invalid result",
+1 -1
View File
@@ -19,7 +19,7 @@ export const projectAppleApplicationEvidence = (
schema: appleApplicationProjectionInputSchema,
project: projectAppleApplication,
operation: OPERATION,
predicateType: "rea.apple-application-graph/v1",
predicateType: "rea.apple-application-graph",
provider: APPLE_APPLICATION_PROVIDER,
subjectFormat: () => "ipa",
protocolError: "Apple application projection produced an invalid result",
@@ -34,11 +34,11 @@ const APPLICATION_GRAPH_IDENTITIES = [
},
{
operation: "reconcile_javascript_runtime",
predicate: "rea.javascript-runtime-reconciliation/v1",
predicate: "rea.javascript-runtime-reconciliation",
},
{
operation: "project_managed_application_graph",
predicate: "rea.managed-application-graph/v1",
predicate: "rea.managed-application-graph",
},
] as const satisfies readonly EvidenceSemanticIdentity[];
+3 -14
View File
@@ -1,4 +1,5 @@
import { projectPermissionFailure } from "./PermissionFailure.js";
import { artifactExtractionPermissionRequest } from "./ArtifactExtractionDestination.js";
import { parseConfig, type AppConfig } from "../config.js";
import type { JsonValue } from "../domain/jsonValue.js";
import { EnhancedTools } from "./EnhancedTools.js";
@@ -118,23 +119,11 @@ const authorizeAnalysis = async (
const requests = [];
if (tool === "extract_artifact" && typeof arguments_.output_root === "string")
requests.push({
capability: "artifact_extract" as const,
path: arguments_.output_root,
request: artifactExtractionPermissionRequest(),
access: "write" as const,
});
for (const request of requests) {
const result = await authority.authorize(
{
capability: request.capability,
roots: [request.path],
executables: [],
environment_names: [],
network: "none",
mount: false,
operation_identity: `${tool}:${request.capability}:${request.path}`,
},
request.access,
);
const result = await authority.authorize(request.request, request.access);
if (!result.ok) return err(projectPermissionFailure(result.error));
}
if (
@@ -39,13 +39,13 @@ export const parseApplicationGraphEvidence = (
return staticApplicationSource(evidence);
if (
evidence.operation === "reconcile_javascript_runtime" &&
evidence.predicate_type === "rea.javascript-runtime-reconciliation/v1" &&
evidence.predicate_type === "rea.javascript-runtime-reconciliation" &&
providerMatches(evidence, JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER)
)
return staticRuntimeSource(evidence);
if (
evidence.operation === "project_managed_application_graph" &&
evidence.predicate_type === "rea.managed-application-graph/v1" &&
evidence.predicate_type === "rea.managed-application-graph" &&
providerMatches(evidence, MANAGED_WORKFLOW_PROVIDER)
)
return managedApplicationSource(evidence);
@@ -17,7 +17,7 @@ export const createApplicationFeatureTraceEvidence = (
result: ApplicationFeatureTraceResult,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.application-feature-trace/v1",
predicateType: "rea.application-feature-trace",
operation: "trace_application_feature",
parameters,
result: jsonValueSchema.parse(result),
@@ -35,7 +35,7 @@ export const createJavaScriptSemanticTraceEvidence = (
result: JavaScriptSemanticTraceResult,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.javascript-semantic-trace/v1",
predicateType: "rea.javascript-semantic-trace",
operation: "trace_javascript_semantics",
parameters,
result: jsonValueSchema.parse(result),
@@ -53,7 +53,7 @@ export const createApplicationVersionComparisonEvidence = (
result: ApplicationVersionComparisonResult,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.application-version-comparison/v1",
predicateType: "rea.application-version-comparison",
operation: "compare_application_versions",
parameters,
result: jsonValueSchema.parse(result),
@@ -71,7 +71,7 @@ export const createSourceToBundleComparisonEvidence = (
result: SourceToBundleComparisonResult,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.source-to-bundle-comparison/v1",
predicateType: "rea.source-to-bundle-comparison",
operation: "compare_source_to_bundle",
parameters,
result: jsonValueSchema.parse(result),
@@ -89,7 +89,7 @@ export const createJavaScriptExportShapeComparisonEvidence = (
result: JavaScriptExportShapeComparisonResult,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.javascript-export-shape-comparison/v1",
predicateType: "rea.javascript-export-shape-comparison",
operation: "compare_javascript_export_shapes",
parameters,
result: jsonValueSchema.parse(result),
+13 -24
View File
@@ -124,21 +124,13 @@ const analyzeArtifactFile = (
parsed,
{
maxAstNodes: remainingNodes,
maxFindings: Number.MAX_SAFE_INTEGER,
maxModules: Number.MAX_SAFE_INTEGER,
deadline: context.deadline,
now: context.now,
},
);
const staticFindings = findingCount(analysis);
const semanticLimits: JavaScriptSemanticLimits = {
...DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS,
maxScopes: remainingNodes,
maxBindings: remainingNodes,
maxCallables: remainingNodes,
maxReferences: remainingNodes,
maxModuleLinks: remainingNodes,
};
const semanticLimits: JavaScriptSemanticLimits =
DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS;
const semantics =
analysis.parse_status === "complete" || analysis.parse_status === "partial"
? analyzeParsedJavaScriptSemantics(parsed, semanticLimits)
@@ -212,13 +204,13 @@ const parsePackage = (
path: file.path,
sha256: file.sha256,
status: "included",
name: boundedString(value.name),
version: boundedString(value.version),
main: boundedString(value.main),
name: optionalString(value.name),
version: optionalString(value.version),
main: optionalString(value.main),
renderer:
boundedString(value.renderer) ??
boundedString(value.browser) ??
boundedString(value.module),
optionalString(value.renderer) ??
optionalString(value.browser) ??
optionalString(value.module),
limitation: null,
};
};
@@ -253,7 +245,7 @@ const parseHtmlScripts = (
const baseHref = htmlBaseHref(text);
const pattern = /<script\b[^>]*\bsrc\s*=\s*(["'])([^"']+)\1[^>]*>/giu;
for (const match of text.matchAll(pattern)) {
const script = match[2]?.slice(0, 4_096);
const script = match[2];
if (script === undefined) continue;
const start = match.index;
scripts.push({
@@ -268,7 +260,7 @@ const parseHtmlScripts = (
const htmlBaseHref = (text: string): string | null => {
const match = /<base\b[^>]*\bhref\s*=\s*(["'])([^"']+)\1[^>]*>/iu.exec(text);
return match?.[2]?.slice(0, 4_096) ?? null;
return match?.[2] ?? null;
};
const parseSourceMap = (
@@ -297,7 +289,7 @@ const parseSourceMap = (
null,
"Parse deadline elapsed during source-map decoding.",
);
const maps = flattenSourceMaps(value, 10_000);
const maps = flattenSourceMaps(value);
if (maps === undefined)
return invalidSourceMap(file, "Source map is not a bounded version 3 map.");
return collectSourceMapOriginals(file, maps, context);
@@ -372,7 +364,6 @@ const unavailableSourceMap = (
const flattenSourceMaps = (
root: unknown,
maximum: number,
): Readonly<Record<string, unknown>>[] | undefined => {
if (!isRecord(root) || root.version !== 3) return undefined;
const maps: Readonly<Record<string, unknown>>[] = [];
@@ -381,8 +372,6 @@ const flattenSourceMaps = (
const map = pending.pop();
if (map === undefined || map.version !== 3) return undefined;
if (Array.isArray(map.sections)) {
if (pending.length + maps.length + map.sections.length > maximum)
return undefined;
for (const section of map.sections) {
if (!isRecord(section) || !isRecord(section.map)) return undefined;
pending.push(section.map);
@@ -454,8 +443,8 @@ const resolveSourceName = (root: string, source: string): string =>
4_096,
);
const boundedString = (value: unknown): string | null =>
typeof value === "string" && value.length > 0 ? value.slice(0, 4_096) : null;
const optionalString = (value: unknown): string | null =>
typeof value === "string" && value.length > 0 ? value : null;
const sha256 = (value: string): string =>
createHash("sha256").update(value).digest("hex");
@@ -81,15 +81,12 @@ const createBundlerChunkNode = (
bundler: registration.bundler,
runtime: registration.runtime,
chunk_keys: registration.chunk_keys,
omitted_chunk_keys: registration.omitted_chunk_keys,
unknown_chunk_keys: registration.unknown_chunk_keys,
runtime_require_name: registration.runtime_require_name,
runtime_module_cache_status: registration.runtime_module_cache_status,
entry_module_keys: registration.entry_module_keys,
omitted_entry_module_keys: registration.omitted_entry_module_keys,
unknown_entry_module_keys: registration.unknown_entry_module_keys,
async_chunk_keys: registration.async_chunk_keys,
omitted_async_chunk_keys: registration.omitted_async_chunk_keys,
unknown_async_chunk_keys: registration.unknown_async_chunk_keys,
module_count: registration.modules.length,
},
@@ -140,7 +137,6 @@ const addBundlerModuleNodes = (
structural_fingerprint_status:
moduleValue.structural_fingerprint_status,
exports: moduleValue.exports,
exports_truncated: moduleValue.exports_truncated,
},
evidence: astObservationEvidence({
sha256: file.sha256,
@@ -250,8 +250,6 @@ describe("contextual JavaScript module identity", () => {
`,
{
maxAstNodes: 10_000,
maxFindings: 100,
maxModules: 100,
deadline: Number.POSITIVE_INFINITY,
now: () => 0,
},
@@ -84,12 +84,23 @@ export interface JavaScriptReplayRunner {
) => Promise<ReplayExecutionResult>;
}
const assertReplayManifestWithinProtocolLimit = (
input: ControlledReplayInput,
): void => {
if (
new TextEncoder().encode(JSON.stringify(input)).byteLength >
input.limits.protocol_bytes
)
throw new RangeError("Replay plan input exceeds its protocol byte limit");
};
/** Read, normalize, and content-address every input to one replay experiment. */
export const prepareReplayPlan = async (
input: ControlledReplayInput,
policy: EnabledJavaScriptReplayPolicy,
host: JavaScriptReplayHost,
): Promise<PreparedReplayPlan> => {
assertReplayManifestWithinProtocolLimit(input);
const cases = replayCases(input).map((item) => ({
...item,
sha256: digestJson(item.arguments),
@@ -47,7 +47,7 @@ export const projectJavaScriptExportReturnShapes = (input: {
semanticOmitted === null ? null : semanticOmitted + projectionOmitted;
const coverage = complete
? input.baseCoverage
: callable.returnCoverage.status === "truncated" || projectionOmitted > 0
: projectionOmitted > 0
? truncatedApplicationCoverage(limits, omitted)
: partialApplicationCoverage(limits, omitted);
const limitations = [
@@ -26,8 +26,8 @@ export const createJavaScriptRuntimeObservationEvidence = (
createEvidence(undefined, provider, {
predicateType:
operation === "list_javascript_runtime_targets"
? "rea.javascript-runtime-target-list/v1"
: "rea.javascript-runtime-observation/v1",
? "rea.javascript-runtime-target-list"
: "rea.javascript-runtime-observation",
operation,
parameters: parameters(input),
result: jsonValueSchema.parse(result),
@@ -16,7 +16,7 @@ export const createJavaScriptRuntimeReconciliationEvidence = (
result: JavaScriptRuntimeReconciliationResult,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER, {
predicateType: "rea.javascript-runtime-reconciliation/v1",
predicateType: "rea.javascript-runtime-reconciliation",
operation: "reconcile_javascript_runtime",
parameters: parameters(input),
result: jsonValueSchema.parse(result),
@@ -173,10 +173,10 @@ it("connects caller results, direct returns, parameters, and captures", () => {
expect(capture?.evidence.location).not.toEqual(readOuter.evidence.location);
});
it("preserves semantic analyzer truncation in graph coverage", () => {
it("preserves the semantic value-depth guard in graph coverage", () => {
const graph = graphFor(
"const first = 1; const second = first; const third = second;",
{ maxReferences: 1 },
{ maxValueDepth: 1 },
);
expect(graph.coverage).toMatchObject({
status: "partial",
@@ -184,7 +184,7 @@ it("preserves semantic analyzer truncation in graph coverage", () => {
omitted_nodes: null,
omitted_relations: null,
limits: expect.arrayContaining([
{ name: "semantic.maxReferences", value: 1, unit: "items" },
{ name: "semantic.maxValueDepth", value: 1, unit: "depth" },
]),
});
expect(
@@ -75,7 +75,7 @@ interface FileContext extends SemanticFlowProjectionContext {
readonly callResolutions: ReadonlyMap<string, "candidate" | "resolved">;
}
/** Project bounded per-file semantic IR into an artifact-bound companion graph. */
/** Project per-file semantic IR into an artifact-bound companion graph. */
export const buildJavaScriptSemanticGraph = ({
rootArtifactSha256,
applicationGraph,
@@ -19,7 +19,7 @@ export const projectSemanticFunctionFingerprints = (
return [
createJavaScriptSemanticFingerprint({
function_node_id: callable.node_id,
algorithm: "rea.javascript-semantic-function/v1",
algorithm: "rea.javascript-semantic-function",
status: fingerprint.status,
components: {
parameter_arity: fingerprint.components.parameterArity,
@@ -281,13 +281,13 @@ export const projectSemanticFrontiers = (
}
};
/** Publish exact semantic analyzer limits reached by any admitted source file. */
/** Publish the semantic recursion guard when it caused incomplete recovery. */
export const semanticRecoveryLimits = (
analysis: JavaScriptArtifactAnalysis,
): {
readonly name: string;
readonly value: number;
readonly unit: "items";
readonly unit: "depth";
}[] => {
const limits = new Map<string, number>();
for (const { semantic } of analysis.files) {
@@ -297,5 +297,5 @@ export const semanticRecoveryLimits = (
}
return [...limits]
.sort(([left], [right]) => left.localeCompare(right))
.map(([name, value]) => ({ name, value, unit: "items" }));
.map(([name, value]) => ({ name, value, unit: "depth" }));
};
@@ -46,7 +46,7 @@ const createManagedApplicationGraphEvidence = (
result: ManagedApplicationGraphResult,
): Evidence =>
createEvidence(subjectTarget(input), MANAGED_WORKFLOW_PROVIDER, {
predicateType: "rea.managed-application-graph/v1",
predicateType: "rea.managed-application-graph",
operation: OPERATION,
parameters: {
managed_artifact_evidence_id: input.managed_artifact?.evidence_id ?? null,
@@ -156,7 +156,7 @@ const createManagedMemberComparisonEvidence = (
result: z.infer<typeof managedMemberComparisonResultSchema>,
): Evidence =>
createEvidence(undefined, MANAGED_WORKFLOW_PROVIDER, {
predicateType: "rea.managed-member-comparison/v1",
predicateType: "rea.managed-member-comparison",
operation: "compare_managed_members",
parameters: {
left_evidence_id: parameters.left.evidence_id,
@@ -45,7 +45,7 @@ const createManagedNativeVerificationEvidence = (
result: ManagedNativeVerificationResult,
): Evidence =>
createEvidence(undefined, MANAGED_WORKFLOW_PROVIDER, {
predicateType: "rea.managed-native-verification/v1",
predicateType: "rea.managed-native-verification",
operation: OPERATION,
parameters: {
managed_boundaries_evidence_id: input.managed_boundaries.evidence_id,
@@ -59,7 +59,7 @@ const createManagedReconstructionEvidence = (
},
MANAGED_WORKFLOW_PROVIDER,
{
predicateType: "rea.managed-reconstruction-import/v1",
predicateType: "rea.managed-reconstruction-import",
operation: OPERATION,
parameters: {
static_members_evidence_id: input.static_members.evidence_id,
@@ -115,7 +115,7 @@ export const planManagedRuntimeCorrelationEvidenceValidated = async (
},
MANAGED_WORKFLOW_PROVIDER,
{
predicateType: "rea.managed-runtime-correlation-plan/v1",
predicateType: "rea.managed-runtime-correlation-plan",
operation: OPERATION,
parameters: {
static_members_evidence_id: staticEvidence.evidence_id,
@@ -212,7 +212,7 @@ const createTransformationEvidence = (
},
PROVIDER,
{
predicateType: "rea.javascript-export-transformation/v1",
predicateType: "rea.javascript-export-transformation",
operation: PREPARE_OPERATION,
parameters: {
selected_alias: input.selected_alias,
@@ -249,7 +249,7 @@ const createCharacterizationEvidence = (
},
PROVIDER,
{
predicateType: "rea.runtime-characterization/v1",
predicateType: "rea.runtime-characterization",
operation: EXECUTE_OPERATION,
parameters: {
plan_sha256: prepared.plan.plan_sha256,
@@ -340,7 +340,7 @@ const digestPreparation = (
): string =>
createHash("sha256")
.update(
`rea.node-characterization-preparation/v1\0${instrumentedSha256}\0${replayPlanDigest}`,
`rea.node-characterization-preparation\0${instrumentedSha256}\0${replayPlanDigest}`,
)
.digest("hex");
@@ -69,7 +69,7 @@ export const evidenceAuthoritySupportsProof = (
if (
evidence.confidence !== "observed" ||
!proofEvidenceAuthorities[authority].includes(evidence.authority) ||
evidence.predicate_type !== "rea.reconstruction-proof/v1" ||
evidence.predicate_type !== "rea.reconstruction-proof" ||
evidence.operation !== "verify_reconstruction_obligations"
)
return false;
@@ -22,7 +22,7 @@ const proofEvidence = (id: string) =>
undefined,
{ id: `fixture-${id}`, name: "Fixture verifier", version: "1" },
{
predicateType: "rea.fixture-verification/v1",
predicateType: "rea.fixture-verification",
operation: "run_fixture_verifier",
parameters: { id },
result: { passed: true },
@@ -58,7 +58,7 @@ const boundProofEvidence = (
undefined,
{ id: `proof-${id}`, name: "Reconstruction proof", version: "1" },
{
predicateType: "rea.reconstruction-proof/v1",
predicateType: "rea.reconstruction-proof",
operation: "verify_reconstruction_obligations",
parameters: {},
result: {
@@ -248,7 +248,7 @@ describe("reconstruction obligation ledger fail-closed behavior", () => {
undefined,
{ id: "external", name: "External protocol observer", version: "1" },
{
predicateType: "rea.protocol-observation/v1",
predicateType: "rea.protocol-observation",
operation: "observe_protocol",
parameters: {},
result: { status: 200 },
@@ -23,7 +23,7 @@ const proofEvidence = (id: string) =>
undefined,
{ id: `fixture-${id}`, name: "Fixture verifier", version: "1" },
{
predicateType: "rea.fixture-verification/v1",
predicateType: "rea.fixture-verification",
operation: "run_fixture_verifier",
parameters: { id },
result: { passed: true },
@@ -59,7 +59,7 @@ const boundProofEvidence = (
undefined,
{ id: `proof-${id}`, name: "Reconstruction proof", version: "1" },
{
predicateType: "rea.reconstruction-proof/v1",
predicateType: "rea.reconstruction-proof",
operation: "verify_reconstruction_obligations",
parameters: {},
result: {
@@ -64,7 +64,7 @@ const createLedgerEvidence = (
): Evidence => {
const completeLedger = reconstructionObligationLedgerSchema.parse(ledger);
return createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.reconstruction-obligation-ledger/v1",
predicateType: "rea.reconstruction-obligation-ledger",
operation: OPERATION,
parameters: jsonObjectSchema.parse({
ledger_id: completeLedger.ledger_id,
+1 -1
View File
@@ -19,7 +19,7 @@ export const unknownMutationEvidence = (
input: RecordUnknownInput,
): Evidence =>
createEvidence(target, UNKNOWN_REGISTRY_PROVIDER, {
predicateType: "rea.residual-unknown-mutation/v1",
predicateType: "rea.residual-unknown-mutation",
operation: "record_unknown",
parameters: { domain: input.domain, severity: input.severity },
result: {
@@ -17,7 +17,7 @@ const reconciliationEvidence = createEvidence(
version: "1",
},
{
predicateType: "rea.javascript-runtime-reconciliation/v1",
predicateType: "rea.javascript-runtime-reconciliation",
operation: "reconcile_javascript_runtime",
parameters: {
static_layers:
@@ -185,7 +185,7 @@ const runtimeEvidence = createEvidence(
version: "1",
},
{
predicateType: "rea.electron-page-inspection/v1",
predicateType: "rea.electron-page-inspection",
operation: "inspect_electron_page",
parameters: {
cdp_endpoint: "http://127.0.0.1:9223",
+1 -1
View File
@@ -56,7 +56,7 @@ export const MANAGED_TOOL_CONTRACTS = [
name: "inspect_managed_members",
...toolContractMetadata("inspect_managed_members"),
description:
"Inspect PE/CLI metadata members, signatures, raw CIL hashes, member-result-v1 decoded-instruction-tuple hashes, separately reported exception regions, call edges, and field-access anchors without loading or executing target code. Metadata tokens are reported as build-local coordinates bound to the artifact SHA-256 and MVID; the v1 tuple hash does not resolve them or fully commit control flow.",
"Inspect PE/CLI metadata members, signatures, raw CIL hashes, decoded-instruction-tuple hashes, separately reported exception regions, call edges, and field-access anchors without loading or executing target code. Metadata tokens are reported as build-local coordinates bound to the artifact SHA-256 and MVID; the tuple hash does not resolve them or fully commit control flow.",
kind: "managed-provider",
inputSchema: managedMemberInputSchema,
outputSchema: memberOutputSchema,
@@ -143,7 +143,7 @@ export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
name: "compare_managed_members",
...toolContractMetadata("compare_managed_members"),
description:
"Compare two authenticated inspect_managed_members Evidence records using unique-only decoded-CIL-v1/signature and structural method-shape tiers. Names are reported as observations but are not used as a matching basis; metadata tokens remain build-local coordinates bound to each artifact SHA-256 and MVID, and the v1 tuple digest does not itself remap them.",
"Compare two authenticated inspect_managed_members Evidence records using unique-only decoded-CIL/signature and structural method-shape tiers. Names are reported as observations but are not used as a matching basis; metadata tokens remain build-local coordinates bound to each artifact SHA-256 and MVID, and the tuple digest does not itself remap them.",
kind: "application",
inputSchema: compareManagedMembersReferenceInputSchema,
outputSchema: comparisonOutputSchema,
@@ -184,7 +184,7 @@ export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
name: "import_managed_reconstruction",
...toolContractMetadata("import_managed_reconstruction"),
description:
"Import decompiler-produced managed reconstruction against authenticated inspect_managed_members Evidence. The workflow locks each method to artifact SHA-256, MVID, metadata token, signature hash, and the limited member-result-v1 decoded-IL tuple hash, records the decompiler identity and options, and marks C# or pseudocode as analyst inference rather than canonical byte observation.",
"Import decompiler-produced managed reconstruction against authenticated inspect_managed_members Evidence. The workflow locks each method to artifact SHA-256, MVID, metadata token, signature hash, and the limited decoded-IL tuple hash, records the decompiler identity and options, and marks C# or pseudocode as analyst inference rather than canonical byte observation.",
kind: "application",
inputSchema: managedReconstructionReferenceInputSchema,
outputSchema: reconstructionOutputSchema,
@@ -205,7 +205,7 @@ export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
name: "plan_managed_runtime_correlation",
...toolContractMetadata("plan_managed_runtime_correlation"),
description:
"Prepare a separately authorized managed runtime-correlation admission plan from authenticated inspect_managed_members Evidence. The operation is default-disabled, requires the managed_runtime permission ceiling and grant, locks the exact artifact SHA-256, MVID, method signature, and limited member-result-v1 decoded-IL tuple hash, distinguishes attach/load/debugger/reflection/instrumentation effects, and records that no target code was executed.",
"Prepare a separately authorized managed runtime-correlation admission plan from authenticated inspect_managed_members Evidence. The operation is default-disabled, requires the managed_runtime permission ceiling and grant, locks the exact artifact SHA-256, MVID, method signature, and limited decoded-IL tuple hash, distinguishes attach/load/debugger/reflection/instrumentation effects, and records that no target code was executed.",
kind: "application",
inputSchema: managedRuntimeCorrelationReferenceInputSchema,
outputSchema: runtimeOutputSchema,
@@ -16,7 +16,7 @@ const sourceEvidence = (variant: string) =>
version: "1",
},
{
predicateType: "rea.reconstruction-readiness-fixture/v1",
predicateType: "rea.reconstruction-readiness-fixture",
operation: "run_reconstruction_readiness_fixture",
parameters: { variant },
result: { passed: true, variant },
+1 -1
View File
@@ -144,7 +144,7 @@ export const snapshotTarget = (
architecture: target.architecture ?? null,
});
/** Build the immutable provider/profile binding used by snapshot v2. */
/** Build the immutable provider/profile binding used by a cached snapshot. */
export const snapshotBinding = (
profile: AnalysisProfileCommitment,
): AnalysisSnapshotBinding =>
+1 -1
View File
@@ -67,7 +67,7 @@ const artifactChangeSchema = z.object({
.string()
.regex(/^art_[a-f0-9]{64}$/u)
.nullable(),
evidence_links: z.array(evidenceIdSchema).min(2).max(200),
evidence_links: z.array(evidenceIdSchema).min(2),
});
/** Deterministic artifact comparison with every change returned inline. */
-13
View File
@@ -79,8 +79,6 @@ type RecordPair = z.infer<
typeof bundleComparisonInputSchema
>["record_pairs"][number];
const MAX_ENTITIES = 100_000;
/** Compare canonical bundle membership and only explicitly paired observations. */
export const compareBundles = (
leftInput: unknown,
@@ -89,7 +87,6 @@ export const compareBundles = (
): BundleComparisonResult => {
const left = parseEvidenceBundle(leftInput);
const right = parseEvidenceBundle(rightInput);
enforceBounds(left, right);
const leftDigest = bundleDigest(left);
const rightDigest = bundleDigest(right);
const recordResult = compareRecords(left, right, recordPairs);
@@ -303,16 +300,6 @@ const historyEvidenceIds = (history: readonly ResidualUnknown[]): string[] =>
),
].sort(ascii);
const enforceBounds = (left: EvidenceBundle, right: EvidenceBundle): void => {
const total =
left.records.length +
right.records.length +
left.unknowns.length +
right.unknowns.length;
if (total > MAX_ENTITIES)
throw new TypeError(`Bundle comparison exceeds ${MAX_ENTITIES} entities`);
};
const bundleDigest = (bundle: EvidenceBundle): string =>
createHash("sha256").update(serializeEvidenceBundle(bundle)).digest("hex");
+2 -2
View File
@@ -39,7 +39,7 @@ const comparison = (
{
predicateType: process
? "rea.process-comparison"
: "rea.artifact-comparison/v1",
: "rea.artifact-comparison",
operation,
parameters: {},
result,
@@ -230,7 +230,7 @@ describe("changed behavior", () => {
undefined,
{ id: "rea-bundle-comparison", name: "Bundle", version: "1" },
{
predicateType: "rea.bundle-comparison/v1",
predicateType: "rea.bundle-comparison",
operation: "compare_bundles",
parameters: {},
result: {},
+2 -2
View File
@@ -89,13 +89,13 @@ const EXPECTED_PROVIDERS = {
version: "3",
},
compare_artifacts: {
predicates: ["rea.artifact-comparison/v1"],
predicates: ["rea.artifact-comparison"],
id: "rea-artifact-comparison",
name: "REA artifact comparison",
version: "1",
},
compare_functions: {
predicates: ["rea.function-comparison/v1"],
predicates: ["rea.function-comparison"],
id: "rea-function-comparison",
name: "REA function comparison",
version: "1",
@@ -191,7 +191,7 @@ const applicationLimitSchema = z.strictObject({
});
/** Bounded collection coverage without treating omission as absence. */
const coverageLimitsSchema = z.array(applicationLimitSchema).max(32);
const coverageLimitsSchema = z.array(applicationLimitSchema);
const omittedCountSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
export const applicationCoverageSchema = z.union([
@@ -211,7 +211,7 @@ export const applicationCoverageSchema = z.union([
status: z.literal("partial"),
truncated: z.literal(true),
omitted_count: z.union([omittedCountSchema.positive(), z.null()]),
limits: z.array(applicationLimitSchema).min(1).max(32),
limits: z.array(applicationLimitSchema).min(1),
}),
z.strictObject({
status: z.enum(["unknown", "unavailable"]),
+13 -37
View File
@@ -8,10 +8,9 @@ export interface AstFingerprint {
readonly truncated: boolean;
}
/** Bounded static CommonJS export names. */
/** Static CommonJS export names. */
export interface StaticExports {
readonly values: readonly string[];
readonly truncated: boolean;
}
/** Derive a rename-resistant, bounded syntax fingerprint without code execution. */
@@ -41,31 +40,16 @@ export const fingerprintJavaScriptAst = (
};
/** Collect statically declared CommonJS/bundler export names from one factory. */
export const collectJavaScriptExports = (
node: t.Node,
maximumExports: number,
): StaticExports => {
export const collectJavaScriptExports = (node: t.Node): StaticExports => {
const exports = new Set<string>();
let truncated = false;
t.traverseFast(node, (current) => {
if (exports.size >= maximumExports) {
truncated = true;
return t.traverseFast.stop;
}
if (t.isAssignmentExpression(current))
collectAssignmentExports(
current.left,
current.right,
exports,
maximumExports,
);
if (t.isCallExpression(current))
collectCallExports(current, exports, maximumExports);
collectAssignmentExports(current.left, current.right, exports);
if (t.isCallExpression(current)) collectCallExports(current, exports);
return undefined;
});
return {
values: [...exports].sort(compareCodePoints),
truncated,
};
};
@@ -97,31 +81,29 @@ const collectAssignmentExports = (
left: t.LVal | t.OptionalMemberExpression,
right: t.Expression,
output: Set<string>,
maximum: number,
): void => {
const path = memberPath(left);
if (path === "exports" || path === "module.exports") {
if (t.isObjectExpression(right)) collectObjectKeys(right, output, maximum);
else addExport(output, "default", maximum);
if (t.isObjectExpression(right)) collectObjectKeys(right, output);
else addExport(output, "default");
return;
}
if (path.startsWith("exports."))
addExport(output, path.slice("exports.".length), maximum);
addExport(output, path.slice("exports.".length));
if (path.startsWith("module.exports."))
addExport(output, path.slice("module.exports.".length), maximum);
addExport(output, path.slice("module.exports.".length));
};
const collectCallExports = (
call: t.CallExpression,
output: Set<string>,
maximum: number,
): void => {
const callee = memberPath(call.callee);
if (callee === "Object.defineProperty") {
const target = memberPath(call.arguments[0]);
const name = stringValue(call.arguments[1]);
if ((target === "exports" || target === "module.exports") && name)
addExport(output, name, maximum);
addExport(output, name);
}
if (!callee.endsWith(".d")) return;
const target = memberPath(call.arguments[0]);
@@ -130,28 +112,22 @@ const collectCallExports = (
(target === "exports" || target === "module.exports") &&
t.isObjectExpression(declarations)
)
collectObjectKeys(declarations, output, maximum);
collectObjectKeys(declarations, output);
};
const collectObjectKeys = (
object: t.ObjectExpression,
output: Set<string>,
maximum: number,
): void => {
for (const property of object.properties) {
if (output.size >= maximum) return;
if (!t.isObjectProperty(property) && !t.isObjectMethod(property)) continue;
const name = propertyName(property.key);
if (name !== "") addExport(output, name, maximum);
if (name !== "") addExport(output, name);
}
};
const addExport = (
output: Set<string>,
name: string,
maximum: number,
): void => {
if (output.size < maximum) output.add(name.slice(0, 4_096));
const addExport = (output: Set<string>, name: string): void => {
output.add(name);
};
const memberPath = (node: t.Node | null | undefined, depth = 0): string => {
@@ -1,6 +1,9 @@
import { expect, it } from "vitest";
import { projectedExportReturnShapesSchema } from "./javascriptExportShapeComparisonSchemas.js";
import {
javaScriptExportShapeComparisonResultSchema,
projectedExportReturnShapesSchema,
} from "./javascriptExportShapeComparisonSchemas.js";
const projectionWithField = (field: unknown) => ({
semantic_role: "export-return-shapes",
@@ -51,3 +54,109 @@ it("parses projected fields into literal, union, or unknown values", () => {
).success,
).toBe(true);
});
it("accepts every projected return site and field without presentation caps", () => {
const fields = Array.from({ length: 65 }, (_, index) => ({
path: `/field-${String(index)}`,
state: "literal",
value: index,
reason: null,
}));
const propertyCoverage = fields.map(({ path }) => ({
path,
status: "complete",
omitted: 0,
}));
const shapes = Array.from({ length: 33 }, () => ({
source_range: {
start: { line: 1, column: 0 },
end: { line: 1, column: 10 },
},
value_status: "object",
fields,
property_coverage: propertyCoverage,
}));
expect(
projectedExportReturnShapesSchema.parse({
...projectionWithField(fields[0]),
static_return_shapes: shapes,
return_shape_coverage: {
status: "complete",
retained_return_sites: shapes.length,
omitted_return_sites: 0,
omitted_fields: 0,
omitted_property_coverage: 0,
projection_complete: true,
},
}).static_return_shapes,
).toHaveLength(33);
});
it("accepts complete candidate and change inventories without page ceilings", () => {
const evidenceId = `ev_${"a".repeat(64)}`;
const graphId = `jag_${"b".repeat(64)}`;
const selector = {
evidence_id: evidenceId,
graph_id: graphId,
requested_module_path: "index.js",
requested_export_name: "render",
candidates: Array.from({ length: 1_001 }, (_, index) => ({
node_id: `jag_node_${index.toString(16).padStart(64, "0")}`,
module_path: "index.js",
export_name: "render",
matches_requested_module: true,
matches_requested_export: true,
})),
omitted_candidates: 0,
status: "missing",
selected_node_id: null,
};
const changes = Array.from({ length: 10_001 }, (_, index) => ({
change_id: `jesc_change_${index.toString(16).padStart(64, "0")}`,
status: "unknown",
path: `/field-${String(index)}`,
discriminant: null,
left: { availability: "absent" },
right: { availability: "absent" },
left_source_range: null,
right_source_range: null,
evidence_links: [evidenceId, `ev_${"c".repeat(64)}`],
limitations: [],
}));
expect(
javaScriptExportShapeComparisonResultSchema.parse({
comparison_id: `jesc_${"d".repeat(64)}`,
left: selector,
right: { ...selector, graph_id: `jag_${"e".repeat(64)}` },
summary: { added: 0, removed: 0, changed: 0, unknown: changes.length },
changes,
coverage: {
status: "complete-within-inputs",
left_graph_status: "complete",
right_graph_status: "complete",
paired_variants: 0,
unpaired_left_variants: 0,
unpaired_right_variants: 0,
omitted_left_variants: 0,
omitted_right_variants: 0,
left_source_omitted_variants: 0,
right_source_omitted_variants: 0,
left_omitted_fields: 0,
right_omitted_fields: 0,
left_omitted_property_coverage: 0,
right_omitted_property_coverage: 0,
omitted_candidates: 0,
omitted_changes: 0,
},
evidence_links: [evidenceId, `ev_${"c".repeat(64)}`],
limitations: [],
runtime_validation: {
recommended_tool: "run_controlled_replay",
automatically_started: false,
required_for: "runtime-semantics",
},
}).changes,
).toHaveLength(10_001);
});
@@ -84,7 +84,7 @@ const projectedReturnFieldSchema = z.discriminatedUnion("state", [
z.strictObject({
...projectedReturnFieldShape,
state: z.literal("union"),
value: z.array(semanticPrimitiveSchema).min(1).max(32),
value: z.array(semanticPrimitiveSchema).min(1),
reason: z.null(),
}),
z.strictObject({
@@ -125,8 +125,8 @@ const projectedReturnShapeSchema = z
"cycle",
"limit-reached",
]),
fields: z.array(projectedReturnFieldSchema).max(64),
property_coverage: z.array(projectedPropertyCoverageSchema).max(64),
fields: z.array(projectedReturnFieldSchema),
property_coverage: z.array(projectedPropertyCoverageSchema),
})
.superRefine((shape, context) => {
const fieldPaths = shape.fields.map(({ path }) => path);
@@ -153,10 +153,10 @@ export const projectedExportReturnShapesSchema = z
exported_name: selectorTextSchema,
callable_id: boundedTextSchema,
callable_kind: z.enum(["function", "class", "method"]),
static_return_shapes: z.array(projectedReturnShapeSchema).max(32),
static_return_shapes: z.array(projectedReturnShapeSchema),
return_shape_coverage: z.strictObject({
status: z.enum(["complete", "partial", "truncated"]),
retained_return_sites: z.number().int().min(0).max(32),
retained_return_sites: z.number().int().min(0),
omitted_return_sites: z.number().int().min(0).nullable(),
omitted_fields: z.number().int().min(0),
omitted_property_coverage: z.number().int().min(0),
@@ -188,7 +188,7 @@ const selectorResultShape = {
graph_id: graphIdSchema,
requested_module_path: selectorTextSchema,
requested_export_name: selectorTextSchema,
candidates: z.array(exportCandidateSchema).max(1_000),
candidates: z.array(exportCandidateSchema),
omitted_candidates: z.number().int().min(0),
};
const selectorResultSchema = z.union([
@@ -217,7 +217,7 @@ const valueAvailabilitySchema = z.discriminatedUnion("availability", [
}),
z.strictObject({
availability: z.literal("union"),
values: z.array(semanticPrimitiveSchema).min(1).max(32),
values: z.array(semanticPrimitiveSchema).min(1),
}),
z.strictObject({
availability: z.literal("unknown"),
@@ -240,7 +240,7 @@ const comparisonChangeSchema = z.strictObject({
left_source_range: sourceRangeSchema.nullable(),
right_source_range: sourceRangeSchema.nullable(),
evidence_links: z.array(evidenceIdSchema).length(2),
limitations: z.array(boundedTextSchema).max(20),
limitations: z.array(boundedTextSchema),
});
/** Bounded static export-return comparison with explicit unknown semantics. */
@@ -254,7 +254,7 @@ export const javaScriptExportShapeComparisonResultSchema = z.strictObject({
changed: z.number().int().min(0),
unknown: z.number().int().min(0),
}),
changes: z.array(comparisonChangeSchema).max(10_000),
changes: z.array(comparisonChangeSchema),
coverage: z.strictObject({
status: z.enum(["complete-within-inputs", "partial", "truncated"]),
left_graph_status: z.enum([
@@ -284,7 +284,7 @@ export const javaScriptExportShapeComparisonResultSchema = z.strictObject({
omitted_changes: z.number().int().min(0),
}),
evidence_links: z.array(evidenceIdSchema).length(2),
limitations: z.array(boundedTextSchema).max(1_000),
limitations: z.array(boundedTextSchema),
runtime_validation: z.strictObject({
recommended_tool: z.literal("run_controlled_replay"),
automatically_started: z.literal(false),
@@ -55,7 +55,7 @@ const absolutePathSchema = z.string().min(1).max(16_384).refine(isAbsolute);
const assertIdentity = (evidence: Evidence): void => {
if (
evidence.operation !== "capture_electron_scenario" ||
evidence.predicate_type !== "rea.electron-active-scenario/v1" ||
evidence.predicate_type !== "rea.electron-active-scenario" ||
evidence.provider.id !== "rea-playwright-electron-active" ||
evidence.provider.name !==
"REA Playwright active Electron observation provider" ||
@@ -187,7 +187,7 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
if (evidence.operation === "inspect_web_page") {
assertEvidenceIdentity(evidence, {
operation: "inspect_web_page",
predicate: "rea.web-page-inspection/v2",
predicate: "rea.web-page-inspection",
providerId: "rea-cdp-browser",
providerName: "REA Chrome DevTools Protocol observation provider",
providerVersion: "2",
@@ -216,7 +216,7 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
if (evidence.operation === "inspect_electron_page") {
assertEvidenceIdentity(evidence, {
operation: "inspect_electron_page",
predicate: "rea.electron-page-inspection/v1",
predicate: "rea.electron-page-inspection",
providerId: "rea-cdp-electron",
providerName: "REA Electron file-page CDP observation provider",
providerVersion: "1",
@@ -244,7 +244,7 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
if (evidence.operation === "observe_javascript_runtime") {
assertEvidenceIdentity(evidence, {
operation: "observe_javascript_runtime",
predicate: "rea.javascript-runtime-observation/v1",
predicate: "rea.javascript-runtime-observation",
providerId: "rea-v8-inspector",
providerName: "REA passive Node/Electron V8 Inspector provider",
providerVersion: "1",
@@ -156,21 +156,17 @@ describe("JavaScript semantic analysis: calls 2", () => {
]);
});
it("bounds Promise recovery with an explicit frontier", () => {
it("retains every promise operation found in the finite source", () => {
const ir = analyzeJavaScriptSemantics(
`
Promise.resolve(1);
Promise.resolve(2);
Promise.resolve(3);
`,
{ maxPromiseOperations: 1 },
);
expect(ir.promiseOperations).toHaveLength(1);
expect(ir.coverage).toMatchObject({
status: "truncated",
limitsReached: ["maxPromiseOperations"],
});
expect(ir.promiseOperations).toHaveLength(3);
expect(ir.coverage.status).toBe("complete");
});
it("fingerprints formatting and local-name changes identically", () => {
@@ -48,7 +48,7 @@ describe("JavaScript semantic analysis: dataflow 1", () => {
]);
});
it("applies independent hard bounds to every new semantic fact family", () => {
it("retains all statically recovered call, flow, capture, and frontier facts", () => {
const ir = analyzeJavaScriptSemantics(
`
const captured = 1;
@@ -58,35 +58,24 @@ describe("JavaScript semantic analysis: dataflow 1", () => {
object[first];
object[second];
`,
{
maxCallSites: 1,
maxCallArguments: 1,
maxArgumentFlows: 0,
maxCallReturnFlows: 0,
maxClosureCaptures: 0,
maxFrontiers: 1,
},
);
expect(ir.callSites).toHaveLength(1);
expect(ir.callSites[0]?.arguments).toEqual([
expect.objectContaining({ index: 0, spread: false }),
expect(ir.callSites).toHaveLength(2);
expect(ir.callSites.map(({ arguments: args }) => args)).toEqual([
[
expect.objectContaining({ index: 0, spread: false }),
expect.objectContaining({ index: 1, spread: false }),
],
[
expect.objectContaining({ index: 0, spread: false }),
expect.objectContaining({ index: 1, spread: false }),
],
]);
expect(ir.argumentFlows).toEqual([]);
expect(ir.callReturnFlows).toEqual([]);
expect(ir.closureCaptures).toEqual([]);
expect(ir.frontiers).toHaveLength(1);
expect(ir.coverage).toMatchObject({
status: "truncated",
limitsReached: expect.arrayContaining([
"maxCallSites",
"maxCallArguments",
"maxArgumentFlows",
"maxCallReturnFlows",
"maxClosureCaptures",
"maxFrontiers",
]),
});
expect(ir.argumentFlows).toHaveLength(4);
expect(ir.callReturnFlows).toHaveLength(2);
expect(ir.closureCaptures).toHaveLength(1);
expect(ir.frontiers).toHaveLength(2);
expect(ir.coverage.status).toBe("complete");
});
it("recovers only direct return sites with literal and unknown object fields", () => {
@@ -137,7 +126,7 @@ describe("JavaScript semantic analysis: dataflow 1", () => {
});
describe("JavaScript semantic analysis: dataflow 2", () => {
it("retains partial property coverage, empty returns, and return limits", () => {
it("retains partial property coverage and empty returns", () => {
const partial = analyzeJavaScriptSemantics(`
const spread = () => ({ type: "spread", ...dynamic });
const computed = () => ({ type: "computed", [key]: 1 });
@@ -163,24 +152,9 @@ describe("JavaScript semantic analysis: dataflow 2", () => {
status: "unknown",
reason: "Return has no value.",
});
const limited = analyzeJavaScriptSemantics(
"function many(value) { if (value) return 1; return 2; }",
{ maxReturnSites: 1 },
);
expect(onlyCallable(limited, "many")).toMatchObject({
returnSites: [{ value: { status: "literal", value: 1 } }],
returnCoverage: {
status: "truncated",
retainedCount: 1,
omittedCount: 1,
limitsReached: ["maxReturnSites"],
},
});
expect(limited.coverage.limitsReached).toContain("maxReturnSites");
});
it("fails closed on assignment ambiguity, alias cycles, and lattice limits", () => {
it("fails closed on assignment ambiguity and alias cycles", () => {
const ambiguous = analyzeJavaScriptSemantics(`
let current = "first";
current = "second";
@@ -196,20 +170,6 @@ describe("JavaScript semantic analysis: dataflow 2", () => {
expect(topLevelBinding(ambiguous, "right").provenance).toMatchObject({
status: "cycle",
});
const limited = analyzeJavaScriptSemantics(
'const channel = enabled ? "one" : "two";',
{ maxUnionValues: 1 },
);
expect(topLevelBinding(limited, "channel").value).toEqual({
status: "limit-reached",
reason: "maxUnionValues reached.",
});
expect(limited.coverage).toMatchObject({
status: "truncated",
limitsReached: ["maxUnionValues"],
});
expect(limited.coverage.omittedCount).toBeGreaterThan(0);
});
it("does not invent exact module paths for dynamic property access", () => {
@@ -234,7 +194,7 @@ describe("JavaScript semantic analysis: dataflow 2", () => {
).toEqual([]);
});
it("bounds retained scopes and bindings without corrupting outer resolution", () => {
it("retains all scopes, bindings, and references without truncation", () => {
const ir = analyzeJavaScriptSemantics(
`
const retained = "yes";
@@ -242,23 +202,22 @@ describe("JavaScript semantic analysis: dataflow 2", () => {
retained;
function nested(value) { return retained + value; }
`,
{ maxBindings: 1, maxCallables: 0, maxScopes: 1 },
);
expect(ir.bindings.map(({ name }) => name)).toEqual(["retained"]);
expect(ir.callables).toEqual([]);
expect(ir.coverage.status).toBe("truncated");
expect(ir.coverage.limitsReached).toEqual(
expect.arrayContaining(["maxBindings", "maxCallables", "maxScopes"]),
);
expect(ir.references.filter(({ name }) => name === "retained")).toEqual(
expect.arrayContaining([
expect.objectContaining({
resolution: "resolved",
bindingId: topLevelBinding(ir, "retained").bindingId,
}),
expect.objectContaining({ resolution: "unknown", bindingId: null }),
]),
expect(ir.bindings.map(({ name }) => name)).toEqual(
expect.arrayContaining(["retained", "omitted", "value"]),
);
expect(ir.callables.map(({ name }) => name)).toContain("nested");
expect(ir.coverage.status).toBe("complete");
expect(ir.references.filter(({ name }) => name === "retained")).toEqual([
expect.objectContaining({
resolution: "resolved",
bindingId: topLevelBinding(ir, "retained").bindingId,
}),
expect.objectContaining({
resolution: "resolved",
bindingId: topLevelBinding(ir, "retained").bindingId,
}),
]);
});
});
@@ -8,31 +8,23 @@ import {
} from "./javascriptSemanticAnalysis.fixture.js";
describe("JavaScript semantic analysis: rejection 1", () => {
it("reports reference, module-link, depth, and object-property limits", () => {
const retained = analyzeJavaScriptSemantics(
`
const first = require("first");
const second = require("second");
first;
second;
`,
{ maxModuleLinks: 1, maxReferences: 1 },
it("retains complete finite facts and reports the recursive depth guard", () => {
const names = Array.from(
{ length: 280 },
(_, index) => `key${String(index)}`,
);
expect(retained.moduleLinks).toHaveLength(1);
expect(retained.references).toHaveLength(1);
expect(retained.coverage.limitsReached).toEqual(
expect.arrayContaining(["maxModuleLinks", "maxReferences"]),
);
const object = analyzeJavaScriptSemantics(
"const object = { first: 1, second: 2 };",
{ maxObjectProperties: 1 },
`const first = require("first"); const second = require("second"); first; second; const object = { ${names.map((name, index) => `${name}: ${String(index)}`).join(", ")} };`,
);
expect(object.moduleLinks).toHaveLength(2);
expect(object.references).toHaveLength(4);
expect(topLevelBinding(object, "object").value).toMatchObject({
status: "object",
unknownProperties: true,
unknownProperties: false,
properties: expect.arrayContaining([
expect.objectContaining({ name: "key279" }),
]),
});
expect(object.coverage.limitsReached).toContain("maxObjectProperties");
const depth = analyzeJavaScriptSemantics(
'const first = "value"; const second = first;',
@@ -104,15 +96,9 @@ describe("JavaScript semantic analysis: rejection 1", () => {
});
it.prop([fc.string({ maxLength: 512 })])(
"fails closed for arbitrary bounded source text",
"fails closed for arbitrary source text",
(source) => {
const ir = analyzeJavaScriptSemantics(source, {
maxBindings: 64,
maxCallables: 64,
maxModuleLinks: 64,
maxReferences: 256,
maxScopes: 64,
});
const ir = analyzeJavaScriptSemantics(source);
expect(ir.schema).toBe("JavaScriptSemanticIR");
expect(["complete", "partial", "truncated", "failed"]).toContain(
@@ -85,7 +85,7 @@ describe("JavaScript semantic analysis: runtime boundaries 1", () => {
expect(ir.timerOperations).toEqual([]);
});
it("bounds every added semantic effect family independently", () => {
it("retains every added semantic effect family", () => {
const ir = analyzeJavaScriptSemantics(
`
import { spawn } from "node:child_process";
@@ -99,31 +99,17 @@ describe("JavaScript semantic analysis: runtime boundaries 1", () => {
JSON.parse(raw);
open(path);
`,
{
maxPromiseOperations: 0,
maxEventOperations: 0,
maxTimerOperations: 0,
maxChildProcessOperations: 0,
maxConfigurationOperations: 0,
maxRequestOperations: 0,
maxBoundaryOperations: 0,
maxResourceOperations: 0,
maxObjectOperations: 0,
},
);
expect(ir.coverage.limitsReached).toEqual(
expect.arrayContaining([
"maxBoundaryOperations",
"maxChildProcessOperations",
"maxConfigurationOperations",
"maxEventOperations",
"maxPromiseOperations",
"maxRequestOperations",
"maxResourceOperations",
"maxTimerOperations",
"maxObjectOperations",
]),
);
expect(ir.coverage.status).toBe("complete");
expect(ir.promiseOperations).toHaveLength(1);
expect(ir.eventOperations).toHaveLength(1);
expect(ir.timerOperations).toHaveLength(1);
expect(ir.childProcessSpawns).toHaveLength(1);
expect(ir.configurationOperations).toHaveLength(1);
expect(ir.requestOperations).toHaveLength(1);
expect(ir.boundaryOperations).toHaveLength(1);
expect(ir.resourceOperations).toHaveLength(1);
expect(ir.objectOperations.length).toBeGreaterThan(0);
});
});
-17
View File
@@ -14,7 +14,6 @@ import {
collectSemanticReferences,
immutableSemanticBindings,
immutableSemanticScopes,
reachSemanticLimit,
semanticModuleOrigin,
semanticStaticPropertyName,
} from "./javascriptSemanticProjection.js";
@@ -249,17 +248,6 @@ const nestedScope = (
): JavaScriptSemanticScopeState | undefined => {
const kind = scopeKind(node, parent);
if (kind === undefined) return undefined;
if (state.scopes.length >= state.limits.maxScopes) {
reachSemanticLimit(state, "maxScopes");
return {
scopeId: `${semanticScopeId(kind, node)}:omitted`,
parentScopeId: parentScope.scopeId,
kind,
location: range(node),
bindingsComplete: false,
bindings: new Map(),
};
}
const scope: JavaScriptSemanticScopeState = {
scopeId: semanticScopeId(kind, node),
parentScopeId: parentScope.scopeId,
@@ -447,11 +435,6 @@ const addBinding = (input: AddBindingInput): void => {
state.omittedCount += 1;
return;
}
if (state.bindingsById.size >= state.limits.maxBindings) {
scope.bindingsComplete = false;
reachSemanticLimit(state, "maxBindings");
return;
}
binding = createBinding(scope, name, kind, mutable);
scope.bindings.set(name, binding);
state.bindingsById.set(binding.bindingId, binding);
@@ -6,7 +6,6 @@ import type {
JavaScriptSemanticTimerOperation,
} from "./javascriptSemanticIr.js";
import {
reachSemanticLimit,
semanticCallableIdForNode,
semanticStaticPropertyName,
} from "./javascriptSemanticProjection.js";
@@ -116,10 +115,6 @@ const collectEvent = (
);
if (method === undefined) return;
const kind = eventKind(method);
if (output.length >= state.limits.maxEventOperations) {
reachSemanticLimit(state, "maxEventOperations");
return;
}
const eventArgument = node.arguments[0];
const listenerArgument = node.arguments[1];
const emitter = emitterIdentity(member.object, state);
@@ -191,10 +186,6 @@ const collectTimer = (input: TimerCollectionInput): void => {
const { node, parent, ownerCallableId, state, output } = input;
const method = timerMethod(node.callee, state);
if (method === null) return;
if (output.length >= state.limits.maxTimerOperations) {
reachSemanticLimit(state, "maxTimerOperations");
return;
}
const kind = TIMER_SCHEDULE_METHODS.some((candidate) => candidate === method)
? "schedule"
: "cancel";
+3 -33
View File
@@ -10,7 +10,6 @@ import type {
JavaScriptSemanticFrontier,
} from "./javascriptSemanticIr.js";
import {
reachSemanticLimit,
semanticCallableIdForNode,
semanticReferenceRole,
semanticStaticPropertyName,
@@ -45,7 +44,6 @@ interface MutableCallAnalysis {
readonly callResultFlows: JavaScriptSemanticCallResultFlow[];
readonly closureCaptures: JavaScriptSemanticClosureCapture[];
readonly frontiers: JavaScriptSemanticFrontier[];
retainedArguments: number;
}
interface CallCollectionContext {
@@ -59,7 +57,7 @@ interface CallCollectionContext {
>;
}
/** Recover bounded direct-call and lexical-capture candidates from inert syntax. */
/** Recover direct-call and lexical-capture candidates from inert syntax. */
export const collectJavaScriptSemanticCalls = (
program: t.Program,
state: JavaScriptSemanticAnalysisState,
@@ -72,7 +70,6 @@ export const collectJavaScriptSemanticCalls = (
callResultFlows: [],
closureCaptures: [],
frontiers: [],
retainedArguments: 0,
};
const callableById = new Map(
callables.map((callable) => [callable.callableId, callable]),
@@ -127,10 +124,6 @@ const collectCallSite = (
context: CallCollectionContext,
): void => {
const { state, callableById, output } = context;
if (output.callSites.length >= state.limits.maxCallSites) {
reachSemanticLimit(state, "maxCallSites");
return;
}
const resolution = resolveLocalCallables({
node: node.callee,
state,
@@ -140,7 +133,7 @@ const collectCallSite = (
bindingCache: context.bindingResolutionCache,
});
const callSiteId = semanticCallSiteId(node);
const argumentsValue = retainedArguments(node.arguments, state, output);
const argumentsValue = retainedArguments(node.arguments);
const site: JavaScriptSemanticCallSite = {
callSiteId,
kind: t.isNewExpression(node) ? "construct" : "call",
@@ -219,16 +212,9 @@ const retainedArguments = (
| t.JSXNamespacedName
| t.ArgumentPlaceholder
)[],
state: JavaScriptSemanticAnalysisState,
output: MutableCallAnalysis,
): JavaScriptSemanticCallSite["arguments"] => {
const retained: JavaScriptSemanticCallSite["arguments"][number][] = [];
for (const [index, node] of nodes.entries()) {
if (output.retainedArguments >= state.limits.maxCallArguments) {
reachSemanticLimit(state, "maxCallArguments");
break;
}
output.retainedArguments += 1;
retained.push({
index,
location: range(node),
@@ -243,7 +229,7 @@ const collectArgumentFlows = (
node: t.CallExpression | t.OptionalCallExpression | t.NewExpression,
context: CallCollectionContext,
): void => {
const { state, callableById, output } = context;
const { callableById, output } = context;
const retainedIndexes = new Set(site.arguments.map(({ index }) => index));
let positionIsExact = true;
for (const [index, argument] of node.arguments.entries()) {
@@ -265,10 +251,6 @@ const collectArgumentFlows = (
index,
context,
)) {
if (output.argumentFlows.length >= state.limits.maxArgumentFlows) {
reachSemanticLimit(state, "maxArgumentFlows");
return;
}
const definition = parameter.definitions.find(
({ kind }) => kind === "parameter",
);
@@ -309,10 +291,6 @@ const collectReturnFlows = (
const callable = callableById.get(callableId);
if (callable === undefined) continue;
for (const returnSite of callable.returnSites) {
if (output.callReturnFlows.length >= state.limits.maxCallReturnFlows) {
reachSemanticLimit(state, "maxCallReturnFlows");
return;
}
output.callReturnFlows.push({
callSiteId: site.callSiteId,
callableId,
@@ -344,10 +322,6 @@ const collectCapture = (
bindingIsWithinCallable(binding, owner.bodyScopeId, state)
)
return;
if (output.closureCaptures.length >= state.limits.maxClosureCaptures) {
reachSemanticLimit(state, "maxClosureCaptures");
return;
}
output.closureCaptures.push({
callableId: owner.callableId,
bindingId: binding.bindingId,
@@ -397,10 +371,6 @@ const addFrontier = (
state: JavaScriptSemanticAnalysisState,
output: MutableCallAnalysis,
): void => {
if (output.frontiers.length >= state.limits.maxFrontiers) {
reachSemanticLimit(state, "maxFrontiers");
return;
}
output.frontiers.push(frontier);
};
@@ -6,7 +6,6 @@ import type {
JavaScriptSemanticChildProcessSpawn,
} from "./javascriptSemanticIr.js";
import {
reachSemanticLimit,
semanticCallableIdForNode,
semanticStaticPropertyName,
} from "./javascriptSemanticProjection.js";
@@ -83,7 +82,6 @@ const collectSpawns = (
return;
const method = childProcessMethod(node.callee, state);
if (method === null) return;
if (operationLimitReached(output.length, state)) return;
output.push({
node,
method,
@@ -151,7 +149,6 @@ const collectInteractions = (
context,
);
if (interaction === null) return;
if (operationLimitReached(spawns.length + output.length, state)) return;
output.push(interaction);
},
exit: (node) => popCallable(node, callableStack),
@@ -366,15 +363,6 @@ const literalString = (
return null;
};
const operationLimitReached = (
retained: number,
state: JavaScriptSemanticAnalysisState,
): boolean => {
if (retained < state.limits.maxChildProcessOperations) return false;
reachSemanticLimit(state, "maxChildProcessOperations");
return true;
};
const popCallable = (node: t.Node, stack: string[]): void => {
const callableId = semanticCallableIdForNode(node);
if (callableId !== null && stack.at(-1) === callableId) stack.pop();
+11 -32
View File
@@ -5,23 +5,11 @@ import { compareCodePoints } from "./javascriptStaticAnalysisHelpers.js";
/** Exact retention state for one callable's direct returns. */
export type JavaScriptSemanticReturnCoverage = {
readonly retainedCount: number;
} & (
| {
readonly status: "complete";
readonly omittedCount: 0;
readonly limitsReached: readonly [];
}
| {
readonly status: "partial";
readonly omittedCount: 0 | null;
readonly limitsReached: readonly [];
}
| {
readonly status: "truncated";
readonly omittedCount: number;
readonly limitsReached: readonly ["maxReturnSites"];
}
);
} & {
readonly status: "complete" | "partial";
readonly omittedCount: 0 | null;
readonly limitsReached: readonly [];
};
/** Coverage state for one bounded semantic recovery pass. */
export type JavaScriptSemanticCoverage =
@@ -69,19 +57,10 @@ export const semanticCoverage = (
/** Classify one callable's direct-return coverage. */
export const semanticReturnCoverage = (
retainedCount: number,
omittedCount: number,
parserPartial: boolean,
): JavaScriptSemanticReturnCoverage =>
omittedCount > 0
? {
status: "truncated",
retainedCount,
omittedCount,
limitsReached: ["maxReturnSites"],
}
: {
status: parserPartial ? "partial" : "complete",
retainedCount,
omittedCount: 0,
limitsReached: [],
};
): JavaScriptSemanticReturnCoverage => ({
status: parserPartial ? "partial" : "complete",
retainedCount,
omittedCount: 0,
limitsReached: [],
});
@@ -1,7 +1,6 @@
import * as t from "@babel/types";
import {
reachSemanticLimit,
semanticCallableIdForNode,
semanticStaticPropertyName,
} from "./javascriptSemanticProjection.js";
@@ -206,19 +205,3 @@ export const containsSemanticNode = (outer: t.Node, inner: t.Node): boolean =>
inner.end !== undefined &&
outer.start <= inner.start &&
outer.end >= inner.end;
/** Record one bounded data-effect frontier. */
export const dataEffectLimitReached = (
retained: number,
limit: number,
name:
| "maxConfigurationOperations"
| "maxRequestOperations"
| "maxBoundaryOperations"
| "maxResourceOperations",
state: JavaScriptSemanticAnalysisState,
): boolean => {
if (retained < limit) return false;
reachSemanticLimit(state, name);
return true;
};
@@ -16,7 +16,6 @@ import {
builtinDataEffectMethod as builtinMethod,
containsSemanticNode as containsNode,
dataEffectArgumentBindingId as argumentBindingId,
dataEffectLimitReached as limitReached,
dataEffectLiteralString as literalString,
dataEffectMemberCallee as memberCallee,
dataEffectMemberObject as memberObject,
@@ -83,15 +82,6 @@ const collectConfigurations = (
traverseWithContext(program, context, (node, parent) => {
const details = configurationDetails(node, parent, context);
if (details === null) return;
if (
limitReached(
output.length,
context.state.limits.maxConfigurationOperations,
"maxConfigurationOperations",
context.state,
)
)
return;
const operation: JavaScriptSemanticConfigurationOperation = {
configId: `config:${details.kind}:${String(node.start ?? -1)}:${String(node.end ?? -1)}`,
kind: details.kind,
@@ -178,15 +168,6 @@ const collectDefaults = (
containsNode(node.left, source),
);
if (sources.length !== 1 || sources[0] === undefined) return;
if (
limitReached(
configurations.length + output.length,
context.state.limits.maxConfigurationOperations,
"maxConfigurationOperations",
context.state,
)
)
return;
output.push({
configId: `config:default:${String(node.start ?? -1)}:${String(node.end ?? -1)}`,
kind: "default",
@@ -216,15 +197,6 @@ const collectRequests = (
return;
const method = requestMethod(node, context.state);
if (method === null) return;
if (
limitReached(
output.length,
context.state.limits.maxRequestOperations,
"maxRequestOperations",
context.state,
)
)
return;
const endpoint = requestEndpoint(node);
output.push({
node,
@@ -276,15 +248,6 @@ const collectResponseConsumers = (
? []
: (requestsByBinding.get(binding.bindingId) ?? []);
if (linked.length === 0) return;
if (
limitReached(
requests.length + output.length,
context.state.limits.maxRequestOperations,
"maxRequestOperations",
context.state,
)
)
return;
output.push({
requestId: `response:${String(node.start ?? -1)}:${String(node.end ?? -1)}`,
kind: "response-consumer",
@@ -312,15 +275,6 @@ const collectBoundaries = (
if (!t.isCallExpression(node) && !t.isOptionalCallExpression(node)) return;
const details = boundaryDetails(node, context.state);
if (details === null) return;
if (
limitReached(
output.length,
context.state.limits.maxBoundaryOperations,
"maxBoundaryOperations",
context.state,
)
)
return;
output.push({
boundaryId: `boundary:${details.kind}:${String(node.start ?? -1)}:${String(node.end ?? -1)}`,
kind: details.kind,
@@ -181,7 +181,7 @@ const fixtureGraph = (withUnknown = false): JavaScriptSemanticGraph => {
);
const fingerprint = createJavaScriptSemanticFingerprint({
function_node_id: callable.node_id,
algorithm: "rea.javascript-semantic-function/v1",
algorithm: "rea.javascript-semantic-function",
status: "complete",
components: {
parameter_arity: 0,
+9 -16
View File
@@ -194,11 +194,6 @@ const sourceRangeSchema = z
const semanticPropertiesSchema = z
.record(z.string().min(1).max(128), jsonValueSchema)
.superRefine((properties, context) => {
if (Object.keys(properties).length > 64)
context.addIssue({
code: "custom",
message: "Semantic properties exceed 64 keys",
});
if (
!isJsonWithinLimits(properties, {
maxDepth: 6,
@@ -313,7 +308,7 @@ const fingerprintComponentsSchema = z.strictObject({
/** One bounded rename-resistant function fingerprint. */
export const javaScriptSemanticFingerprintInputSchema = z.strictObject({
function_node_id: semanticNodeIdSchema,
algorithm: z.literal("rea.javascript-semantic-function/v1"),
algorithm: z.literal("rea.javascript-semantic-function"),
status: z.enum(["complete", "partial", "unavailable"]),
components: fingerprintComponentsSchema,
limitations: z.array(boundedTextSchema).max(100),
@@ -340,15 +335,13 @@ const graphCoverageSchema = z.strictObject({
truncated: z.boolean(),
omitted_nodes: z.number().int().min(0).nullable(),
omitted_relations: z.number().int().min(0).nullable(),
limits: z
.array(
z.strictObject({
name: z.string().min(1).max(128),
value: z.number().int().min(0),
unit: z.enum(["items", "bytes", "milliseconds", "depth", "other"]),
}),
)
.max(32),
limits: z.array(
z.strictObject({
name: z.string().min(1).max(128),
value: z.number().int().min(0),
unit: z.enum(["items", "bytes", "milliseconds", "depth", "other"]),
}),
),
families: z.array(familyCoverageSchema).length(12),
});
@@ -363,7 +356,7 @@ export const javaScriptSemanticGraphInputSchema = z.strictObject({
fingerprints: z.array(javaScriptSemanticFingerprintSchema),
unknowns: z.array(javaScriptSemanticUnknownSchema),
coverage: graphCoverageSchema,
limitations: z.array(boundedTextSchema).max(1_000),
limitations: z.array(boundedTextSchema),
});
/** Stored JavaScript Semantic Relation Graph. */
@@ -177,7 +177,7 @@ const fixtureGraph = (withUnknown = false): JavaScriptSemanticGraph => {
);
const fingerprint = createJavaScriptSemanticFingerprint({
function_node_id: callable.node_id,
algorithm: "rea.javascript-semantic-function/v1",
algorithm: "rea.javascript-semantic-function",
status: "complete",
components: {
parameter_arity: 0,
+3 -49
View File
@@ -13,58 +13,12 @@ export type {
/** Hard bounds for one execution-free JavaScript semantic analysis. */
export interface JavaScriptSemanticLimits {
readonly maxScopes: number;
readonly maxBindings: number;
readonly maxCallables: number;
readonly maxReferences: number;
readonly maxModuleLinks: number;
readonly maxReturnSites: number;
readonly maxCallSites: number;
readonly maxCallArguments: number;
readonly maxArgumentFlows: number;
readonly maxCallReturnFlows: number;
readonly maxClosureCaptures: number;
readonly maxPromiseOperations: number;
readonly maxEventOperations: number;
readonly maxTimerOperations: number;
readonly maxChildProcessOperations: number;
readonly maxConfigurationOperations: number;
readonly maxRequestOperations: number;
readonly maxBoundaryOperations: number;
readonly maxResourceOperations: number;
readonly maxObjectOperations: number;
readonly maxFrontiers: number;
readonly maxValueDepth: number;
readonly maxUnionValues: number;
readonly maxObjectProperties: number;
}
/** Conservative defaults for one source file. */
/** Stack guard for recursive value and provenance recovery. */
export const DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS: JavaScriptSemanticLimits = {
maxScopes: 4_096,
maxBindings: 20_000,
maxCallables: 20_000,
maxReferences: 100_000,
maxModuleLinks: 20_000,
maxReturnSites: 20_000,
maxCallSites: 20_000,
maxCallArguments: 100_000,
maxArgumentFlows: 100_000,
maxCallReturnFlows: 100_000,
maxClosureCaptures: 100_000,
maxPromiseOperations: 100_000,
maxEventOperations: 100_000,
maxTimerOperations: 100_000,
maxChildProcessOperations: 100_000,
maxConfigurationOperations: 100_000,
maxRequestOperations: 100_000,
maxBoundaryOperations: 100_000,
maxResourceOperations: 100_000,
maxObjectOperations: 100_000,
maxFrontiers: 20_000,
maxValueDepth: 16,
maxUnionValues: 32,
maxObjectProperties: 256,
};
/** One exact module origin followed through imports, requires, or aliases. */
@@ -211,7 +165,7 @@ export interface JavaScriptSemanticClosureCapture {
readonly referenceLocation: JavaScriptSourceRange;
}
/** One bounded promise/task operation recovered from explicit syntax. */
/** One promise/task operation recovered from explicit syntax. */
export interface JavaScriptSemanticPromiseOperation {
readonly promiseId: string;
readonly kind:
@@ -293,7 +247,7 @@ export interface JavaScriptSemanticEventOperation {
readonly resolution: "complete" | "partial" | "unresolved";
}
/** One bounded timer scheduling or cancellation candidate. */
/** One timer scheduling or cancellation candidate. */
export interface JavaScriptSemanticTimerOperation {
readonly timerId: string;
readonly kind: "schedule" | "cancel";
-5
View File
@@ -5,7 +5,6 @@ import type {
JavaScriptSemanticObjectOperation,
} from "./javascriptSemanticIr.js";
import {
reachSemanticLimit,
semanticCallableIdForNode,
semanticStaticPropertyName,
} from "./javascriptSemanticProjection.js";
@@ -140,10 +139,6 @@ const addObjectOperation = (
state: JavaScriptSemanticAnalysisState,
output: JavaScriptSemanticObjectOperation[],
): void => {
if (output.length >= state.limits.maxObjectOperations) {
reachSemanticLimit(state, "maxObjectOperations");
return;
}
output.push({
objectOperationId: `object:${input.kind}:${String(input.node.start ?? -1)}:${String(input.node.end ?? -1)}`,
kind: input.kind,
+1 -13
View File
@@ -4,17 +4,12 @@ import type {
JavaScriptSemanticPrimitive,
JavaScriptSemanticValue,
} from "./javascriptSemanticIr.js";
import type { JavaScriptSemanticAnalysisState } from "./javascriptSemanticState.js";
import {
reachSemanticValueLimit,
semanticPrimitiveKey,
} from "./javascriptSemanticProvenance.js";
import { semanticPrimitiveKey } from "./javascriptSemanticProvenance.js";
import { compareCodePoints } from "./javascriptStaticAnalysisHelpers.js";
/** Normalize one bounded collection of possible primitive values. */
export const semanticPrimitiveSet = (
values: readonly JavaScriptSemanticPrimitive[],
state: JavaScriptSemanticAnalysisState,
): JavaScriptSemanticValue => {
const unique = [
...new Map(
@@ -23,13 +18,6 @@ export const semanticPrimitiveSet = (
].sort((left, right) =>
compareCodePoints(semanticPrimitiveKey(left), semanticPrimitiveKey(right)),
);
if (unique.length > state.limits.maxUnionValues) {
reachSemanticValueLimit(state, "maxUnionValues");
return {
status: "limit-reached",
reason: "maxUnionValues reached.",
};
}
const only = unique[0];
return unique.length === 1 && only !== undefined
? { status: "literal", value: only }
@@ -38,10 +38,6 @@ export const collectSemanticCallable = (input: CollectCallableInput): void => {
const { node, parent, containerScope, bodyScope, state } = input;
const kind = callableKind(node);
if (kind === undefined) return;
if (state.callables.length >= state.limits.maxCallables) {
reachSemanticLimit(state, "maxCallables");
return;
}
const callableId =
semanticCallableIdForNode(node) ?? "callable:unknown:-1:-1";
state.callables.push({
@@ -110,10 +106,6 @@ export const collectSemanticReferences = (
const key = `${String(node.start)}:${role}:${node.name}`;
if (seen.has(key)) return;
seen.add(key);
if (output.length >= state.limits.maxReferences) {
reachSemanticLimit(state, "maxReferences");
return;
}
const binding = resolveSemanticBindingState(state, node, node.name);
const blocked =
binding === undefined &&
@@ -372,10 +364,6 @@ const addModuleLink = (
readonly callableId?: string | null;
},
): void => {
if (state.moduleLinks.length >= state.limits.maxModuleLinks) {
reachSemanticLimit(state, "maxModuleLinks");
return;
}
state.moduleLinks.push({ ...link, callableId: link.callableId ?? null });
};
+7 -11
View File
@@ -5,7 +5,6 @@ import type {
JavaScriptSemanticPromiseOperation,
} from "./javascriptSemanticIr.js";
import {
reachSemanticLimit,
semanticCallableIdForNode,
semanticStaticPropertyName,
} from "./javascriptSemanticProjection.js";
@@ -110,16 +109,13 @@ const collectCandidates = (
callableStack.push(callableId);
const details = promiseCandidateDetails(node, state);
if (details !== null) {
if (output.length >= state.limits.maxPromiseOperations)
reachSemanticLimit(state, "maxPromiseOperations");
else
output.push({
node,
...details,
promiseId: semanticPromiseId(details.kind, node),
ownerCallableId: callableStack.at(-1) ?? null,
ancestors: [...ancestors],
});
output.push({
node,
...details,
promiseId: semanticPromiseId(details.kind, node),
ownerCallableId: callableStack.at(-1) ?? null,
ancestors: [...ancestors],
});
}
ancestors.push(node);
},
+3 -6
View File
@@ -19,20 +19,17 @@ export const semanticUnresolvedProvenance = (
reason: string,
): JavaScriptBindingProvenance => ({ status, origins: [], reason });
/** Construct ambiguous provenance while retaining every bounded origin. */
/** Construct ambiguous provenance while retaining every origin. */
export const semanticAmbiguousProvenance = (
origins: readonly JavaScriptModuleOrigin[],
reason: string,
): JavaScriptBindingProvenance => ({ status: "ambiguous", origins, reason });
/** Normalize bounded exact module origins into one provenance classification. */
/** Normalize exact module origins into one provenance classification. */
export const semanticOriginsProvenance = (
origins: readonly JavaScriptModuleOrigin[],
state: JavaScriptSemanticAnalysisState,
): JavaScriptBindingProvenance => {
const unique = uniqueSemanticOrigins(origins);
if (unique.length > state.limits.maxUnionValues)
return semanticLimitProvenance(state, "maxUnionValues");
const origin = unique[0];
return unique.length === 1 && origin !== undefined
? { status: "module", origins: [origin], reason: null }
@@ -54,7 +51,7 @@ export const uniqueSemanticOrigins = (
/** Mark and return an explicit provenance-limit value. */
export const semanticLimitProvenance = (
state: JavaScriptSemanticAnalysisState,
limit: "maxValueDepth" | "maxUnionValues",
limit: "maxValueDepth",
): JavaScriptBindingProvenance => {
reachSemanticValueLimit(state, limit);
return semanticUnresolvedProvenance("limit-reached", `${limit} reached.`);
-17
View File
@@ -11,7 +11,6 @@ import {
type JavaScriptSemanticBindingState,
} from "./javascriptSemanticState.js";
import {
dataEffectLimitReached,
outerDataEffectBinding,
traverseDataEffects,
type DataEffectTraversalContext,
@@ -63,7 +62,6 @@ const collectAcquisitions = (
if (!t.isCallExpression(node) && !t.isOptionalCallExpression(node)) return;
const method = acquisitionMethod(node.callee, context.state);
if (method === null) return;
if (resourceLimitReached(output.length, context.state)) return;
output.push({
node,
method,
@@ -105,10 +103,6 @@ const collectReleases = (
const linked =
binding === undefined ? [] : (byBinding.get(binding.bindingId) ?? []);
if (linked.length === 0) return;
if (
resourceLimitReached(acquisitions.length + output.length, context.state)
)
return;
output.push({
resourceId: `resource:release:${String(node.start ?? -1)}:${String(node.end ?? -1)}`,
kind: "release",
@@ -193,17 +187,6 @@ const resourceModule = (specifier: string): boolean =>
"tls",
].includes(specifier);
const resourceLimitReached = (
retained: number,
state: JavaScriptSemanticAnalysisState,
): boolean =>
dataEffectLimitReached(
retained,
state.limits.maxResourceOperations,
"maxResourceOperations",
state,
);
const resourceCandidateId = (candidate: ResourceCandidate): string =>
`resource:acquire:${String(candidate.node.start ?? -1)}:${String(candidate.node.end ?? -1)}`;
+3 -18
View File
@@ -10,10 +10,7 @@ import type {
ProjectedPropertyCoverage,
ProjectedReturnField,
} from "./javascriptExportShapeComparisonSchemas.js";
import {
reachSemanticLimit,
semanticCallableIdForNode,
} from "./javascriptSemanticProjection.js";
import { semanticCallableIdForNode } from "./javascriptSemanticProjection.js";
import {
resolveSemanticBindingState,
type JavaScriptSemanticAnalysisState,
@@ -29,14 +26,13 @@ interface ReturnExpression {
readonly location: JavaScriptSemanticReturnSite["location"];
}
/** Evaluate bounded direct returns while excluding every nested callable. */
/** Evaluate direct returns while excluding every nested callable. */
export const collectSemanticReturns = (
program: t.Program,
state: JavaScriptSemanticAnalysisState,
parserPartial: boolean,
): JavaScriptSemanticCallable[] => {
const nodes = callableNodes(program);
let retained = 0;
return state.callables.map((callable) => {
const node = nodes.get(callable.callableId);
if (node === undefined)
@@ -51,14 +47,7 @@ export const collectSemanticReturns = (
};
const expressions = directReturnExpressions(node);
const sites: JavaScriptSemanticReturnSite[] = [];
let omitted = 0;
for (const expression of expressions) {
if (retained >= state.limits.maxReturnSites) {
omitted += 1;
reachSemanticLimit(state, "maxReturnSites");
continue;
}
retained += 1;
sites.push({
returnSiteId: semanticReturnSiteId(
callable.callableId,
@@ -78,11 +67,7 @@ export const collectSemanticReturns = (
return {
...callable,
returnSites: sites,
returnCoverage: semanticReturnCoverage(
sites.length,
omitted,
parserPartial,
),
returnCoverage: semanticReturnCoverage(sites.length, parserPartial),
};
});
};
+17 -50
View File
@@ -102,21 +102,15 @@ const evaluateExpression = (
}
if (t.isTemplateLiteral(node)) return evaluateTemplate(node, context);
if (t.isConditionalExpression(node))
return mergeValues(
[
evaluateExpression(node.consequent, nestedContext(context)),
evaluateExpression(node.alternate, nestedContext(context)),
],
context.state,
);
return mergeValues([
evaluateExpression(node.consequent, nestedContext(context)),
evaluateExpression(node.alternate, nestedContext(context)),
]);
if (t.isLogicalExpression(node))
return mergeValues(
[
evaluateExpression(node.left, nestedContext(context)),
evaluateExpression(node.right, nestedContext(context)),
],
context.state,
);
return mergeValues([
evaluateExpression(node.left, nestedContext(context)),
evaluateExpression(node.right, nestedContext(context)),
]);
if (t.isObjectExpression(node)) return evaluateObject(node, context);
if (t.isArrayExpression(node)) return evaluateArray(node, context);
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
@@ -156,10 +150,8 @@ const evaluateTemplate = (
candidates = candidates.flatMap((prefix) =>
values.map((value) => `${prefix}${String(value)}`),
);
if (candidates.length > context.state.limits.maxUnionValues)
return limitValue(context.state, "maxUnionValues");
}
return primitiveSet(candidates, context.state);
return primitiveSet(candidates);
};
const evaluateObject = (
@@ -186,12 +178,6 @@ const evaluateObject = (
if (omittedProperties !== null) omittedProperties += 1;
continue;
}
if (properties.length >= context.state.limits.maxObjectProperties) {
reachSemanticValueLimit(context.state, "maxObjectProperties");
unknownProperties = true;
if (omittedProperties !== null) omittedProperties += 1;
continue;
}
properties.push({
name,
value: evaluateExpression(property.value, nestedContext(context)),
@@ -231,12 +217,6 @@ const evaluateArray = (
if (omittedItems !== null) omittedItems += 1;
continue;
}
if (items.length >= context.state.limits.maxObjectProperties) {
reachSemanticValueLimit(context.state, "maxObjectProperties");
unknownItems = true;
if (omittedItems !== null) omittedItems += 1;
continue;
}
items.push(evaluateExpression(element, nestedContext(context)));
}
return unknownItems
@@ -277,7 +257,7 @@ const evaluateAddition = (
: `${String(leftValue)}${String(rightValue)}`,
),
);
return primitiveSet(values, context.state);
return primitiveSet(values);
};
const evaluateUnary = (
@@ -290,20 +270,11 @@ const evaluateUnary = (
if (argument === null)
return { status: "unknown", reason: "Non-primitive unary operand." };
if (node.operator === "!")
return primitiveSet(
argument.map((value) => !value),
context.state,
);
return primitiveSet(argument.map((value) => !value));
if (node.operator === "+")
return primitiveSet(
argument.map((value) => Number(value)),
context.state,
);
return primitiveSet(argument.map((value) => Number(value)));
if (node.operator === "-")
return primitiveSet(
argument.map((value) => -Number(value)),
context.state,
);
return primitiveSet(argument.map((value) => -Number(value)));
return { status: "unknown", reason: `Unsupported unary ${node.operator}.` };
};
@@ -355,7 +326,7 @@ const provenanceForBinding = (
if (context.depth >= context.state.limits.maxValueDepth)
return semanticLimitProvenance(context.state, "maxValueDepth");
if (binding.directOrigins.length > 0)
return semanticOriginsProvenance(binding.directOrigins, context.state);
return semanticOriginsProvenance(binding.directOrigins);
if (binding.initializers.length === 0) return semanticLocalProvenance();
if (binding.initializers.length > 1)
return semanticAmbiguousProvenance(
@@ -387,7 +358,6 @@ const provenanceForBinding = (
...initializer.projection.map((segment) => String(segment)),
],
})),
context.state,
);
};
@@ -396,8 +366,7 @@ const provenanceForExpression = (
context: EvaluationContext,
): JavaScriptBindingProvenance => {
const required = requireOrigin(node);
if (required !== undefined)
return semanticOriginsProvenance([required], context.state);
if (required !== undefined) return semanticOriginsProvenance([required]);
if (t.isIdentifier(node)) {
const binding = resolveSemanticBindingState(context.state, node, node.name);
return binding === undefined
@@ -427,7 +396,6 @@ const provenanceForExpression = (
...origin,
importedPath: [...origin.importedPath, member],
})),
context.state,
);
}
if (t.isConditionalExpression(node) || t.isLogicalExpression(node)) {
@@ -471,7 +439,6 @@ const requireOrigin = (node: t.Node): JavaScriptModuleOrigin | undefined => {
const mergeValues = (
values: readonly JavaScriptSemanticValue[],
state: JavaScriptSemanticAnalysisState,
): JavaScriptSemanticValue => {
const primitives = values.flatMap(
(value) => primitiveCandidates(value) ?? [],
@@ -480,7 +447,7 @@ const mergeValues = (
values.every(
(value) => value.status === "union" || value.status === "literal",
)
? primitiveSet(primitives, state)
? primitiveSet(primitives)
: { status: "ambiguous", reason: "Branches have incompatible values." };
};
@@ -495,7 +462,7 @@ const memberKey = (
const limitValue = (
state: JavaScriptSemanticAnalysisState,
limit: "maxValueDepth" | "maxUnionValues",
limit: "maxValueDepth",
): JavaScriptSemanticValue => {
reachSemanticValueLimit(state, limit);
return { status: "limit-reached", reason: `${limit} reached.` };
@@ -0,0 +1,32 @@
import { describe, expect, it } from "vitest";
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
describe("JavaScript static analysis findings", () => {
it("retains every static reference and Electron property in large literals", () => {
const names = Array.from({ length: 300 }, (_, index) => `key${index}`);
const source = [
...names.map(
(name, index) => `import value${index} from "./${name}.js";`,
),
`new BrowserWindow({ webPreferences: { ${names.map((name) => `${name}: true`).join(", ")} } });`,
`contextBridge.exposeInMainWorld("api", { ${names.map((name) => `${name}: () => true`).join(", ")} });`,
`const { ${names.join(", ")} } = require("./addon.node");`,
].join("\n");
const analysis = analyzeJavaScriptStaticSource(source, {
maxAstNodes: 100_000,
deadline: Number.POSITIVE_INFINITY,
now: () => 0,
});
expect(analysis.parse_status).toBe("complete");
expect(analysis.references).toHaveLength(301);
expect(analysis.electron.browser_windows[0]?.web_preferences).toHaveLength(
300,
);
expect(analysis.electron.context_bridge_apis[0]?.members).toHaveLength(300);
expect(analysis.electron.native_addon_bindings[0]?.members).toHaveLength(
300,
);
});
});
+6 -15
View File
@@ -52,7 +52,7 @@ export const analyzeParsedJavaScriptStaticSource = (
): JavaScriptStaticAnalysis => {
const accumulator = createJavaScriptAnalysisAccumulator();
traverseStaticSource(source, file, accumulator, limits);
addSourceMapDirectives(source, accumulator, limits.maxFindings);
addSourceMapDirectives(source, accumulator);
return finalizeStaticAnalysis(source, file, accumulator, limits);
};
@@ -95,12 +95,6 @@ const finalizeStaticAnalysis = (
...(accumulator.truncated
? ["AST analysis stopped at the configured node or time bound."]
: []),
...(accumulator.droppedFindings === 0
? []
: ["Static findings were truncated at the configured finding bound."]),
...(accumulator.structuralTruncation
? ["Bundler metadata reached a per-record structural bound."]
: []),
...(accumulator.unknownFindings === 0
? []
: [
@@ -109,15 +103,13 @@ const finalizeStaticAnalysis = (
"JavaScript syntax was parsed as data and was never evaluated.",
];
return {
parse_status:
accumulator.truncated || accumulator.droppedFindings > 0
? "truncated"
: parserErrors > 0 || accumulator.unknownFindings > 0
? "partial"
: "complete",
parse_status: accumulator.truncated
? "truncated"
: parserErrors > 0 || accumulator.unknownFindings > 0
? "partial"
: "complete",
parse_error_count: parserErrors,
visited_ast_nodes: Math.min(accumulator.visitedNodes, limits.maxAstNodes),
dropped_findings: accumulator.droppedFindings,
references: finalizeLocatedFindings(
accumulator.references,
accumulator.modules,
@@ -170,7 +162,6 @@ const inspectNode = (
const findings = {
source,
accumulator,
maximum: limits.maxFindings,
};
inspectElectronStaticNode(node, findings);
if (t.isCallExpression(node)) {
+26 -112
View File
@@ -4,7 +4,7 @@ import {
collectJavaScriptExports,
fingerprintJavaScriptAst,
} from "./javascriptAstFingerprint.js";
import { addBoundedFinding } from "./javascriptStaticAnalysisFindings.js";
import { addFindingOnce } from "./javascriptStaticAnalysisFindings.js";
import {
argumentValue,
calleeName,
@@ -38,59 +38,31 @@ export const inspectBundlerRegistration = (
if (runtime === undefined || !t.isArrayExpression(entry)) return;
const chunkIds = entry.elements[0];
const table = entry.elements[1];
const runtimeValue = runtimeMetadata(entry.elements[2], limits.maxFindings);
const runtimeValue = runtimeMetadata(entry.elements[2]);
if (!t.isArrayExpression(chunkIds) || !t.isObjectExpression(table)) return;
const recovered = recoverBundlerModules(source, table, accumulator, limits);
const chunkKeys = staticArrayValues(
chunkIds,
Math.min(256, limits.maxFindings),
);
if (chunkKeys.omitted > 0) {
accumulator.droppedFindings += chunkKeys.omitted;
accumulator.structuralTruncation = true;
}
const chunkKeys = staticArrayValues(chunkIds);
accumulator.unknownFindings += chunkKeys.unknown;
if (
runtimeValue.omittedEntryModuleKeys > 0 ||
runtimeValue.omittedAsyncChunkKeys > 0 ||
recovered.omittedAsyncChunkKeys > 0
) {
accumulator.droppedFindings +=
runtimeValue.omittedEntryModuleKeys +
runtimeValue.omittedAsyncChunkKeys +
recovered.omittedAsyncChunkKeys;
accumulator.structuralTruncation = true;
}
accumulator.unknownFindings +=
runtimeValue.unknownEntryModuleKeys +
runtimeValue.unknownAsyncChunkKeys +
recovered.unknownAsyncChunkKeys;
const asyncChunkKeys = boundedUniqueValues(
[...runtimeValue.asyncChunkKeys, ...recovered.asyncChunkKeys],
Math.min(256, limits.maxFindings),
);
if (asyncChunkKeys.omitted > 0) {
accumulator.droppedFindings += asyncChunkKeys.omitted;
accumulator.structuralTruncation = true;
}
const asyncChunkKeys = uniqueValues([
...runtimeValue.asyncChunkKeys,
...recovered.asyncChunkKeys,
]);
const registration = {
bundler: runtime.toLowerCase().includes("rspack")
? ("rspack" as const)
: ("webpack" as const),
runtime,
chunk_keys: chunkKeys.values,
omitted_chunk_keys: chunkKeys.omitted,
unknown_chunk_keys: chunkKeys.unknown,
runtime_require_name: runtimeValue.requireName,
runtime_module_cache_status: bundlerModuleCacheStatus(source),
entry_module_keys: runtimeValue.entryModuleKeys,
omitted_entry_module_keys: runtimeValue.omittedEntryModuleKeys,
unknown_entry_module_keys: runtimeValue.unknownEntryModuleKeys,
async_chunk_keys: asyncChunkKeys.values,
omitted_async_chunk_keys:
runtimeValue.omittedAsyncChunkKeys +
recovered.omittedAsyncChunkKeys +
asyncChunkKeys.omitted,
unknown_async_chunk_keys:
runtimeValue.unknownAsyncChunkKeys + recovered.unknownAsyncChunkKeys,
modules: recovered.modules.sort((left, right) =>
@@ -98,10 +70,9 @@ export const inspectBundlerRegistration = (
),
location: range(call),
};
addBoundedFinding(
addFindingOnce(
accumulator,
`registration\0${registrationKey(registration)}`,
limits.maxFindings,
() => accumulator.registrations.push(registration),
);
};
@@ -124,34 +95,26 @@ export const inspectEsbuildWrapper = (
if (wrapperKind === null || !t.isObjectExpression(table)) return;
const recovered = recoverBundlerModules(source, table, accumulator, limits);
if (recovered.modules.length === 0) return;
if (recovered.omittedAsyncChunkKeys > 0) {
accumulator.droppedFindings += recovered.omittedAsyncChunkKeys;
accumulator.structuralTruncation = true;
}
accumulator.unknownFindings += recovered.unknownAsyncChunkKeys;
const registration: JavaScriptBundlerRegistration = {
bundler: "esbuild",
runtime: `esbuild-${wrapperKind}`,
chunk_keys: [`${wrapperKind}@${String(call.start ?? 0)}`],
omitted_chunk_keys: 0,
unknown_chunk_keys: 0,
runtime_require_name: null,
runtime_module_cache_status: "not-observed",
entry_module_keys: [],
omitted_entry_module_keys: 0,
unknown_entry_module_keys: 0,
async_chunk_keys: recovered.asyncChunkKeys,
omitted_async_chunk_keys: recovered.omittedAsyncChunkKeys,
unknown_async_chunk_keys: recovered.unknownAsyncChunkKeys,
modules: recovered.modules.sort((left, right) =>
compareCodePoints(left.module_key, right.module_key),
),
location: range(call),
};
addBoundedFinding(
addFindingOnce(
accumulator,
`registration\0${registrationKey(registration)}`,
limits.maxFindings,
() => accumulator.registrations.push(registration),
);
};
@@ -159,7 +122,6 @@ export const inspectEsbuildWrapper = (
interface RecoveredBundlerModules {
readonly modules: JavaScriptBundlerModule[];
readonly asyncChunkKeys: readonly string[];
readonly omittedAsyncChunkKeys: number;
readonly unknownAsyncChunkKeys: number;
}
@@ -171,7 +133,6 @@ const recoverBundlerModules = (
): RecoveredBundlerModules => {
const modules: JavaScriptBundlerModule[] = [];
const asyncChunkKeys: string[] = [];
let omittedAsyncChunkKeys = 0;
let unknownAsyncChunkKeys = 0;
for (const property of table.properties) {
const recovered = recoverBundlerModule(
@@ -183,13 +144,11 @@ const recoverBundlerModules = (
if (recovered === null) continue;
modules.push(recovered.module);
asyncChunkKeys.push(...recovered.asyncChunkKeys);
omittedAsyncChunkKeys += recovered.omittedAsyncChunkKeys;
unknownAsyncChunkKeys += recovered.unknownAsyncChunkKeys;
}
return {
modules,
asyncChunkKeys,
omittedAsyncChunkKeys,
unknownAsyncChunkKeys,
};
};
@@ -202,34 +161,17 @@ const recoverBundlerModule = (
): {
readonly module: JavaScriptBundlerModule;
readonly asyncChunkKeys: readonly string[];
readonly omittedAsyncChunkKeys: number;
readonly unknownAsyncChunkKeys: number;
} | null => {
const factory = moduleFactory(property);
if (factory === undefined) return null;
if (accumulator.moduleCount >= limits.maxModules) {
accumulator.droppedFindings += 1;
return null;
}
accumulator.moduleCount += 1;
const key = modulePropertyName(property);
if (key.startsWith("[computed@") || key.startsWith("[unknown@"))
accumulator.unknownFindings += 1;
const fingerprint = fingerprintJavaScriptAst(
factory,
Math.min(limits.maxAstNodes, 100_000),
);
const exportsValue = collectJavaScriptExports(factory, 256);
const fingerprint = fingerprintJavaScriptAst(factory, limits.maxAstNodes);
const exportsValue = collectJavaScriptExports(factory);
const requireName = factoryRequireName(factory);
const asyncChunks = collectBundlerAsyncChunkKeys(
factory,
requireName,
limits.maxFindings,
);
if (fingerprint.truncated || exportsValue.truncated) {
accumulator.droppedFindings += 1;
accumulator.structuralTruncation = true;
}
const asyncChunks = collectBundlerAsyncChunkKeys(factory, requireName);
if (typeof factory.start === "number" && typeof factory.end === "number")
accumulator.modules.push({
start: factory.start,
@@ -255,11 +197,9 @@ const recoverBundlerModule = (
source_sha256: sha256Text(sourceSlice(source, factory)),
...structuralFingerprint,
exports: exportsValue.values,
exports_truncated: exportsValue.truncated,
location: range(factory),
},
asyncChunkKeys: asyncChunks.values,
omittedAsyncChunkKeys: asyncChunks.omitted,
unknownAsyncChunkKeys: asyncChunks.unknown,
};
};
@@ -267,16 +207,13 @@ const recoverBundlerModule = (
interface RuntimeMetadata {
readonly requireName: string | null;
readonly entryModuleKeys: readonly string[];
readonly omittedEntryModuleKeys: number;
readonly unknownEntryModuleKeys: number;
readonly asyncChunkKeys: readonly string[];
readonly omittedAsyncChunkKeys: number;
readonly unknownAsyncChunkKeys: number;
}
interface BoundedValues {
interface StaticValues {
readonly values: readonly string[];
readonly omitted: number;
readonly unknown: number;
}
@@ -285,43 +222,32 @@ type BundlerFunction =
| t.ArrowFunctionExpression
| t.ObjectMethod;
const runtimeMetadata = (
node: t.Node | null | undefined,
maximum: number,
): RuntimeMetadata => {
const runtimeMetadata = (node: t.Node | null | undefined): RuntimeMetadata => {
if (!isBundlerFunction(node))
return {
requireName: null,
entryModuleKeys: [],
omittedEntryModuleKeys: 0,
unknownEntryModuleKeys: node === null || node === undefined ? 0 : 1,
asyncChunkKeys: [],
omittedAsyncChunkKeys: 0,
unknownAsyncChunkKeys: 0,
};
const parameter = node.params[0];
const requireName = t.isIdentifier(parameter)
? parameter.name.slice(0, 4_096)
: null;
const requireName = t.isIdentifier(parameter) ? parameter.name : null;
if (requireName === null)
return {
requireName,
entryModuleKeys: [],
omittedEntryModuleKeys: 0,
unknownEntryModuleKeys: 1,
asyncChunkKeys: [],
omittedAsyncChunkKeys: 0,
unknownAsyncChunkKeys: 0,
};
const entries = collectBundlerEntryModuleKeys(node, requireName, maximum);
const asyncChunks = collectBundlerAsyncChunkKeys(node, requireName, maximum);
const entries = collectBundlerEntryModuleKeys(node, requireName);
const asyncChunks = collectBundlerAsyncChunkKeys(node, requireName);
return {
requireName,
entryModuleKeys: entries.values,
omittedEntryModuleKeys: entries.omitted,
unknownEntryModuleKeys: entries.unknown,
asyncChunkKeys: asyncChunks.values,
omittedAsyncChunkKeys: asyncChunks.omitted,
unknownAsyncChunkKeys: asyncChunks.unknown,
};
};
@@ -329,24 +255,20 @@ const runtimeMetadata = (
const collectBundlerEntryModuleKeys = (
factory: BundlerFunction,
requireName: string,
maximum: number,
): BoundedValues =>
collectBundlerCallArgumentValues(factory, requireName, maximum);
): StaticValues => collectBundlerCallArgumentValues(factory, requireName);
const collectBundlerAsyncChunkKeys = (
factory: BundlerFunction,
requireName: string | null,
maximum: number,
): BoundedValues =>
): StaticValues =>
requireName === null
? { values: [], omitted: 0, unknown: 0 }
: collectBundlerCallArgumentValues(factory, `${requireName}.e`, maximum);
? { values: [], unknown: 0 }
: collectBundlerCallArgumentValues(factory, `${requireName}.e`);
const collectBundlerCallArgumentValues = (
factory: BundlerFunction,
callee: string,
maximum: number,
): BoundedValues => {
): StaticValues => {
const values: string[] = [];
let unknown = 0;
t.traverseFast(factory, (node) => {
@@ -357,7 +279,7 @@ const collectBundlerCallArgumentValues = (
else values.push(value);
return undefined;
});
return boundedUniqueValues(values, Math.min(256, maximum), unknown);
return uniqueValues(values, unknown);
};
const isBundlerFunction = (
@@ -367,18 +289,10 @@ const isBundlerFunction = (
t.isArrowFunctionExpression(node) ||
t.isObjectMethod(node);
const boundedUniqueValues = (
values: readonly string[],
maximum: number,
unknown = 0,
): BoundedValues => {
const bounded = [
...new Set(values.map((value) => value.slice(0, 4_096))),
].sort(compareCodePoints);
const retained = bounded.slice(0, Math.max(0, maximum));
const uniqueValues = (values: readonly string[], unknown = 0): StaticValues => {
const unique = [...new Set(values)].sort(compareCodePoints);
return {
values: retained,
omitted: Math.max(0, bounded.length - retained.length),
values: unique,
unknown,
};
};
+8 -11
View File
@@ -2,7 +2,7 @@ import * as t from "@babel/types";
import { sanitizeEndpointCandidate } from "./browserObservation.js";
import {
addBoundedFinding,
addFindingOnce,
addLocatedFinding,
moduleAtOffset,
} from "./javascriptStaticAnalysisFindings.js";
@@ -143,9 +143,7 @@ const vitePreloadDependencyTable = (source: string): readonly string[] => {
if (body === undefined) return [];
return [
...body.matchAll(/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'/gu),
]
.map((literal) => (literal[1] ?? literal[2] ?? "").slice(0, 4_096))
.slice(0, 256);
].map((literal) => literal[1] ?? literal[2] ?? "");
};
const inspectEndpointCall = (
@@ -236,14 +234,14 @@ export const addReference = (
context: FindingContext,
input: ReferenceInput,
): void => {
const boundedSpecifier = input.specifier?.slice(0, 4_096) ?? null;
const specifier = input.specifier ?? null;
const reference =
boundedSpecifier === null
specifier === null
? {
specifier: null,
expression: sourceSlice(context.source, input.node).slice(0, 4_096),
expression: sourceSlice(context.source, input.node),
}
: { specifier: boundedSpecifier, expression: null };
: { specifier, expression: null };
addLocatedFinding(context, {
collection: context.accumulator.references,
key: `reference\0${input.kind}\0${reference.specifier ?? reference.expression}`,
@@ -274,16 +272,15 @@ const addEndpoint = (context: FindingContext, input: EndpointInput): void =>
export const addSourceMapDirectives = (
source: string,
accumulator: AnalysisAccumulator,
maximum: number,
): void => {
for (const match of source.matchAll(
/\/\/[#@]\s*sourceMappingURL\s*=\s*([^\s]+)/gu,
)) {
const declared = match[1]?.slice(0, 4_096);
const declared = match[1];
if (declared === undefined) continue;
const start = match.index;
const location = rangeForOffsets(source, start, start + match[0].length);
addBoundedFinding(accumulator, `source-map\0${declared}`, maximum, () =>
addFindingOnce(accumulator, `source-map\0${declared}`, () =>
accumulator.sourceMaps.push({ declared_url: declared, location }),
);
}
+3 -25
View File
@@ -6,17 +6,16 @@ import type {
LocatedJavaScriptFindingInput,
} from "./javascriptStaticAnalysisState.js";
/** Add one module-attributable finding under the shared global finding bound. */
/** Add one module-attributable finding once per source location. */
export const addLocatedFinding = <
Value extends { readonly module_key: string | null },
>(
context: JavaScriptFindingContext,
input: LocatedJavaScriptFindingInput<Value>,
): void =>
addBoundedFinding(
addFindingOnce(
context.accumulator,
`${input.key}\0${String(input.node.start)}`,
context.maximum,
() =>
input.collection.push({
offset: input.node.start ?? -1,
@@ -25,17 +24,12 @@ export const addLocatedFinding = <
);
/** Reserve one deterministic finding key before mutating an accumulator. */
export const addBoundedFinding = (
export const addFindingOnce = (
accumulator: JavaScriptAnalysisAccumulator,
key: string,
maximum: number,
add: () => void,
): void => {
if (accumulator.seen.has(key)) return;
if (accumulatedFindingCount(accumulator) >= maximum) {
accumulator.droppedFindings += 1;
return;
}
accumulator.seen.add(key);
add();
};
@@ -60,19 +54,3 @@ export const moduleAtOffset = (
if (offset === null || offset === undefined) return undefined;
return modules.find(({ start, end }) => offset >= start && offset <= end);
};
const accumulatedFindingCount = (
accumulator: JavaScriptAnalysisAccumulator,
): number =>
accumulator.references.length +
accumulator.endpoints.length +
accumulator.storage.length +
accumulator.roles.length +
accumulator.sourceMaps.length +
accumulator.registrations.length +
accumulator.browserWindows.length +
accumulator.contextBridgeApis.length +
accumulator.ipc.length +
accumulator.senderValidations.length +
accumulator.utilityProcesses.length +
accumulator.nativeAddonBindings.length;
+23 -29
View File
@@ -16,7 +16,6 @@ export const failedJavaScriptStaticAnalysis = (): JavaScriptStaticAnalysis => ({
parse_status: "failed",
parse_error_count: 1,
visited_ast_nodes: 0,
dropped_findings: 0,
references: [],
endpoints: [],
storage: [],
@@ -50,7 +49,7 @@ export const argumentNode = (
): t.Node | undefined =>
argument !== null && t.isNode(argument) ? argument : undefined;
/** Recognize the bounded runtime name for a Webpack/Rspack push call. */
/** Recognize the runtime name for a Webpack/Rspack push call. */
export const chunkRuntime = (call: t.CallExpression): string | undefined => {
if (
!t.isMemberExpression(call.callee) &&
@@ -64,11 +63,10 @@ export const chunkRuntime = (call: t.CallExpression): string | undefined => {
const findChunkRuntime = (node: t.Node, depth: number): string | undefined => {
if (depth >= 128) return undefined;
if (t.isIdentifier(node) && /(?:webpack|rspack)Chunk/iu.test(node.name))
return node.name.slice(0, 4_096);
return node.name;
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
const property = propertyName(node.property);
if (/(?:webpack|rspack)Chunk/iu.test(property))
return property.slice(0, 4_096);
if (/(?:webpack|rspack)Chunk/iu.test(property)) return property;
return t.isNode(node.object)
? findChunkRuntime(node.object, depth + 1)
: undefined;
@@ -106,7 +104,7 @@ export const moduleFactory = (
return undefined;
};
/** Derive a bounded literal or explicitly computed module key. */
/** Derive a literal or explicitly computed module key. */
export const modulePropertyName = (
property: t.ObjectMethod | t.ObjectProperty | t.SpreadElement,
): string =>
@@ -115,7 +113,7 @@ export const modulePropertyName = (
!t.isStringLiteral(property.key) &&
!t.isNumericLiteral(property.key)
? `[computed@${String(property.start ?? -1)}]`
: propertyName(property.key).slice(0, 4_096) ||
: propertyName(property.key) ||
`[unknown@${String(property.start ?? -1)}]`
: `[unknown@${String(property.start ?? -1)}]`;
@@ -124,31 +122,28 @@ export const factoryRequireName = (
factory: t.FunctionExpression | t.ArrowFunctionExpression | t.ObjectMethod,
): string | null => {
const parameter = factory.params[2];
return t.isIdentifier(parameter) ? parameter.name.slice(0, 4_096) : null;
return t.isIdentifier(parameter) ? parameter.name : null;
};
/** Collect bounded unique literal values and explicit omissions from an array. */
/** Collect all unique static literal values from an array. */
export const staticArrayValues = (
array: t.ArrayExpression,
maximum: number,
): {
readonly values: readonly string[];
readonly omitted: number;
readonly unknown: number;
} => {
const staticValues = array.elements.flatMap((element) => {
const value = argumentValue(element);
return value === undefined ? [] : [value.slice(0, 4_096)];
return value === undefined ? [] : [value];
});
const values = [...new Set(staticValues)].sort(compareCodePoints);
return {
values: values.slice(0, maximum),
omitted: Math.max(0, values.length - maximum),
values,
unknown: array.elements.length - staticValues.length,
};
};
/** Resolve a bounded path composed only from inert literal syntax. */
/** Resolve a path composed only from inert literal syntax. */
export const staticPath = (node: t.Node): string | undefined =>
staticPathAt(node, 0);
@@ -162,17 +157,17 @@ export const staticPathResolutionContext = (
const staticPathAt = (node: t.Node, depth: number): string | undefined => {
if (depth >= 128) return undefined;
if (t.isStringLiteral(node)) return node.value.slice(0, 4_096);
if (t.isStringLiteral(node)) return node.value;
if (t.isTemplateLiteral(node) && node.expressions.length === 0) {
const value = node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw;
return value?.slice(0, 4_096);
return value;
}
if (t.isBinaryExpression(node, { operator: "+" })) {
const left = staticPathAt(node.left, depth + 1);
const right = staticPathAt(node.right, depth + 1);
return left === undefined || right === undefined
? undefined
: `${left}${right}`.slice(0, 4_096);
: `${left}${right}`;
}
if (t.isCallExpression(node) || t.isNewExpression(node))
return staticCallPath(node, depth);
@@ -210,7 +205,7 @@ const staticCallPath = (
if (value === undefined) return undefined;
parts.push(value);
}
return parts.length === 0 ? undefined : posix.join(...parts).slice(0, 4_096);
return parts.length === 0 ? undefined : posix.join(...parts);
};
const isFilesystemPathExpression = (node: t.Node, depth: number): boolean => {
@@ -310,43 +305,42 @@ export const storageKind = (
return undefined;
};
/** Produce a dotted bounded callee name from member syntax. */
/** Produce a dotted callee name from member syntax. */
export const calleeName = (node: t.Node): string => calleeNameAt(node, 0);
const calleeNameAt = (node: t.Node, depth: number): string => {
if (depth >= 128) return "[deep]";
if (t.isIdentifier(node)) return node.name.slice(0, 4_096);
if (t.isIdentifier(node)) return node.name;
if (t.isImport(node)) return "import";
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
const object = t.isNode(node.object)
? calleeNameAt(node.object, depth + 1)
: "";
const property = propertyName(node.property);
return (object === "" ? property : `${object}.${property}`).slice(0, 4_096);
return object === "" ? property : `${object}.${property}`;
}
return "";
};
/** Read a literal property name without evaluating computed syntax. */
export const propertyName = (node: t.Node): string => {
if (t.isIdentifier(node)) return node.name.slice(0, 4_096);
if (t.isIdentifier(node)) return node.name;
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
return String(node.value).slice(0, 4_096);
return String(node.value);
return "";
};
/** Return a string literal value without evaluating an expression. */
export const stringValue = (
node: t.Node | null | undefined,
): string | undefined =>
t.isStringLiteral(node) ? node.value.slice(0, 4_096) : undefined;
): string | undefined => (t.isStringLiteral(node) ? node.value : undefined);
/** Return a string or numeric argument literal. */
export const argumentValue = (
node: t.Node | null | undefined,
): string | undefined => {
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
return String(node.value).slice(0, 4_096);
return String(node.value);
return undefined;
};
@@ -359,7 +353,7 @@ export const prefixedArgument = (
return value === undefined ? undefined : `${prefix}${value}`;
};
/** Retain the exact bounded source span represented by an AST node. */
/** Retain the exact source span represented by an AST node. */
export const sourceSlice = (source: string, node: t.Node): string =>
typeof node.start !== "number" || typeof node.end !== "number"
? ""
@@ -414,7 +408,7 @@ export const detectVendors = (source: string): string[] =>
export const registrationKey = (
registration: JavaScriptBundlerRegistration,
): string =>
`${registration.runtime}\0${registration.chunk_keys.join("\0")}\0${String(registration.omitted_chunk_keys)}\0${String(registration.unknown_chunk_keys)}\0${registration.modules.map(({ module_key: key, source_sha256: digest }) => `${key}:${digest}`).join("\0")}`;
`${registration.runtime}\0${registration.chunk_keys.join("\0")}\0${String(registration.unknown_chunk_keys)}\0${registration.modules.map(({ module_key: key, source_sha256: digest }) => `${key}:${digest}`).join("\0")}`;
/** Sort values by a deterministic unique semantic key. */
export const sortedUnique = <Value>(
+3 -10
View File
@@ -31,7 +31,7 @@ export interface LocatedJavaScriptFinding<Value> {
readonly value: Value;
}
/** Mutable bounded collections used during one inert AST traversal. */
/** Mutable collections used during one inert AST traversal. */
export interface JavaScriptAnalysisAccumulator {
readonly references: LocatedJavaScriptFinding<JavaScriptStaticReference>[];
readonly endpoints: LocatedJavaScriptFinding<JavaScriptStaticEndpoint>[];
@@ -48,18 +48,14 @@ export interface JavaScriptAnalysisAccumulator {
readonly modules: JavaScriptModuleRange[];
readonly seen: Set<string>;
visitedNodes: number;
droppedFindings: number;
moduleCount: number;
unknownFindings: number;
structuralTruncation: boolean;
truncated: boolean;
}
/** Shared source, accumulator, and finding bound for helper inspections. */
/** Shared source and accumulator for helper inspections. */
export interface JavaScriptFindingContext {
readonly source: string;
readonly accumulator: JavaScriptAnalysisAccumulator;
readonly maximum: number;
}
/** Candidate import, require, worker, or service-worker reference. */
@@ -87,7 +83,7 @@ export interface LocatedJavaScriptFindingInput<
readonly value: Value;
}
/** Create isolated mutable state for one bounded source analysis. */
/** Create isolated mutable state for one source analysis. */
export const createJavaScriptAnalysisAccumulator =
(): JavaScriptAnalysisAccumulator => ({
references: [],
@@ -105,9 +101,6 @@ export const createJavaScriptAnalysisAccumulator =
modules: [],
seen: new Set(),
visitedNodes: 0,
droppedFindings: 0,
moduleCount: 0,
unknownFindings: 0,
structuralTruncation: false,
truncated: false,
});
+1 -8
View File
@@ -63,7 +63,6 @@ interface JavaScriptBundlerModuleState {
readonly factory_require_name: string | null;
readonly source_sha256: string;
readonly exports: readonly string[];
readonly exports_truncated: boolean;
readonly location: JavaScriptSourceRange;
}
@@ -87,15 +86,12 @@ export interface JavaScriptBundlerRegistration {
readonly bundler: "webpack" | "rspack" | "esbuild";
readonly runtime: string;
readonly chunk_keys: readonly string[];
readonly omitted_chunk_keys: number;
readonly unknown_chunk_keys: number;
readonly runtime_require_name: string | null;
readonly runtime_module_cache_status: "observed" | "not-observed";
readonly entry_module_keys: readonly string[];
readonly omitted_entry_module_keys: number;
readonly unknown_entry_module_keys: number;
readonly async_chunk_keys: readonly string[];
readonly omitted_async_chunk_keys: number;
readonly unknown_async_chunk_keys: number;
readonly modules: readonly JavaScriptBundlerModule[];
readonly location: JavaScriptSourceRange;
@@ -111,12 +107,11 @@ export interface JavaScriptRolePath {
readonly location: JavaScriptSourceRange;
}
/** Bounded, deterministic AST-only analysis of one JavaScript source file. */
/** Deterministic AST-only analysis of one JavaScript source file. */
export interface JavaScriptStaticAnalysis {
readonly parse_status: "complete" | "partial" | "failed" | "truncated";
readonly parse_error_count: number;
readonly visited_ast_nodes: number;
readonly dropped_findings: number;
readonly references: readonly JavaScriptStaticReference[];
readonly endpoints: readonly JavaScriptStaticEndpoint[];
readonly storage: readonly JavaScriptStaticStorage[];
@@ -134,8 +129,6 @@ export interface JavaScriptStaticAnalysis {
/** Hard bounds applied to one AST-only JavaScript analysis. */
export interface JavaScriptStaticAnalysisLimits {
readonly maxAstNodes: number;
readonly maxFindings: number;
readonly maxModules: number;
readonly deadline: number;
readonly now: () => number;
}
-2
View File
@@ -150,7 +150,6 @@ export const managedMemberComparisonResultSchema = z.strictObject({
comparison_id: z.string().regex(/^mmc_[a-f0-9]{64}$/u),
algorithm: z.strictObject({
name: z.literal("rea-managed-member-comparison"),
version: z.literal(1),
token_identity: z.literal("build-local"),
name_matching: z.literal("not-used"),
}),
@@ -247,7 +246,6 @@ export const compareManagedMembers = (
})}`,
algorithm: {
name: "rea-managed-member-comparison" as const,
version: 1 as const,
token_identity: "build-local" as const,
name_matching: "not-used" as const,
},
@@ -344,7 +344,6 @@ export const buildVerificationResult = ({
return {
algorithm: {
name: "rea-managed-native-verification" as const,
version: 1 as const,
token_identity: "build-local" as const,
token_to_address_mapping: "not-inferred" as const,
},
@@ -128,7 +128,6 @@ export const managedNativeVerificationResultSchema = z
verification_id: z.string().regex(/^mnv_[a-f0-9]{64}$/u),
algorithm: z.strictObject({
name: z.literal("rea-managed-native-verification"),
version: z.literal(1),
token_identity: z.literal("build-local"),
token_to_address_mapping: z.literal("not-inferred"),
}),
+1 -1
View File
@@ -12,7 +12,7 @@ const EVIDENCE_RECORDS = ["1", "2", "3", "4", "5"].map((character) =>
undefined,
{ id: "fixture", name: "Fixture", version: "1" },
{
predicateType: "rea.coverage-fixture/v1",
predicateType: "rea.coverage-fixture",
operation: `fixture-${character}`,
parameters: {},
result: { character },
@@ -34,7 +34,7 @@ const source = (
predicateType:
authority === "controlled-replay"
? "rea.process-capture"
: "rea.analysis/v2",
: "rea.analysis",
operation:
authority === "controlled-replay"
? "capture_process_scenario"
@@ -162,7 +162,7 @@ const artifactComparison = (
version: "1",
},
{
predicateType: "rea.artifact-comparison/v1",
predicateType: "rea.artifact-comparison",
operation: "compare_artifacts",
parameters: {
left_evidence_ids: [left.evidence_id],
@@ -370,7 +370,7 @@ describe("reconstruction verification integrity", () => {
undefined,
{ id: "fixture", name: "Fixture", version: "1" },
{
predicateType: "rea.residual-unknown-mutation/v1",
predicateType: "rea.residual-unknown-mutation",
operation: "record_unknown",
parameters: { index },
result: { action: "record" },
+4 -4
View File
@@ -52,13 +52,13 @@ const providers = {
},
"structural-function": {
operation: "compare_functions",
predicates: ["rea.function-comparison/v1"],
predicates: ["rea.function-comparison"],
id: "rea-function-comparison",
name: "REA function comparison",
},
"structural-artifact": {
operation: "compare_artifacts",
predicates: ["rea.artifact-comparison/v1"],
predicates: ["rea.artifact-comparison"],
id: "rea-artifact-comparison",
name: "REA artifact comparison",
},
@@ -191,8 +191,8 @@ const validateSourceKinds = (
claim.kind === "behavioral"
? ["capture_process_scenario", "rea.process-capture"]
: claim.kind === "structural-function"
? ["analyze_function", "rea.analysis/v2"]
: ["inventory_artifact", "rea.analysis/v2"];
? ["analyze_function", "rea.analysis"]
: ["inventory_artifact", "rea.analysis"];
if (
sources.some(
(source) =>
+1 -8
View File
@@ -6,10 +6,7 @@ import {
} from "./javascriptApplicationGraph.js";
import { createHistoricalSourceGraph } from "./referenceSourceGraph.js";
import { compareSourceToBundle } from "./sourceToBundleComparison.js";
import {
compareSourceToBundleInputSchema,
sourceToBundleComparisonResultSchema,
} from "./sourceToBundleComparisonSchemas.js";
import { sourceToBundleComparisonResultSchema } from "./sourceToBundleComparisonSchemas.js";
import { artifactEvidence } from "./javascriptApplicationGraph.fixture.js";
const HASH = {
@@ -149,10 +146,6 @@ describe("historical source to bundle comparison", () => {
candidate_evaluations: 2,
});
});
it("does not expose caller-selected comparison limits", () => {
expect(compareSourceToBundleInputSchema.shape).not.toHaveProperty("limits");
});
});
const historicalGraph = (
+1 -1
View File
@@ -166,7 +166,7 @@ const comparisonCoverage = (
});
const scoringModel = (): SourceToBundleComparisonResult["scoring"] => ({
algorithm: "rea-source-to-bundle-signals/v1",
algorithm: "rea-source-to-bundle-signals",
minimum_candidate_score: 20,
weights: SOURCE_TO_BUNDLE_SIGNAL_WEIGHTS.map(([signal, weight]) => ({
signal,
@@ -81,7 +81,7 @@ export const sourceToBundleComparisonResultSchema = z.strictObject({
root_artifact_sha256: digestSchema,
}),
scoring: z.strictObject({
algorithm: z.literal("rea-source-to-bundle-signals/v1"),
algorithm: z.literal("rea-source-to-bundle-signals"),
minimum_candidate_score: z.literal(20),
weights: z.array(
z.strictObject({
+2 -2
View File
@@ -145,12 +145,12 @@ type ComparisonIdentity = readonly [string | readonly string[], string, string];
const EXPECTED: Readonly<Record<string, ComparisonIdentity>> = {
compare_artifacts: [
"rea.artifact-comparison/v1",
"rea.artifact-comparison",
"rea-artifact-comparison",
"REA artifact comparison",
],
compare_functions: [
"rea.function-comparison/v1",
"rea.function-comparison",
"rea-function-comparison",
"REA function comparison",
],
+16 -56
View File
@@ -1,38 +1,15 @@
import { z } from "zod";
import {
DEFAULT_BROWSER_INSPECTION_LIMITS,
inspectWebPageWithSourceInputSchema,
} from "./browserObservation.js";
import { inspectWebPageWithSourceInputSchema } from "./browserObservation.js";
import { webTextArtifactSchema } from "./webContentArtifact.js";
/** Provider-owned parser and network safety bounds, never caller settings. */
export const WEB_BUNDLE_ANALYSIS_LIMITS = {
max_ast_nodes: 250_000,
max_source_maps: 100,
max_source_map_bytes: 4 * 1_024 * 1_024,
max_total_source_map_bytes: 16 * 1_024 * 1_024,
max_source_map_mappings: 10_000,
} as const;
/** Capture-and-analyze input with optional source-map fetching. */
export const analyzeWebBundleToolInputSchema =
inspectWebPageWithSourceInputSchema.safeExtend({
fetch_source_maps: z.boolean().default(false),
});
export const analyzeWebBundleInputSchema =
analyzeWebBundleToolInputSchema.transform((input) => ({
...input,
limits: DEFAULT_BROWSER_INSPECTION_LIMITS,
analysis_limits: WEB_BUNDLE_ANALYSIS_LIMITS,
})) as z.ZodType<AnalyzeWebBundleInput>;
export type AnalyzeWebBundleInput = z.infer<
typeof inspectWebPageWithSourceInputSchema
> & {
readonly limits: typeof DEFAULT_BROWSER_INSPECTION_LIMITS;
readonly fetch_source_maps: boolean;
readonly analysis_limits: typeof WEB_BUNDLE_ANALYSIS_LIMITS;
};
export const analyzeWebBundleInputSchema = analyzeWebBundleToolInputSchema;
export type AnalyzeWebBundleInput = z.infer<typeof analyzeWebBundleInputSchema>;
const sourceLocationSchema = z.object({
script_key: z.string(),
@@ -93,12 +70,7 @@ const sourceMapSchema = z.union([
z.object({
...sourceMapContextShape,
...parsedSourceMapShape,
status: z.literal("truncated"),
limitation: z.string(),
}),
z.object({
...sourceMapContextShape,
status: z.enum(["fetch_failed", "invalid", "policy_filtered", "truncated"]),
status: z.enum(["fetch_failed", "invalid", "policy_filtered"]),
artifact: z.null(),
original_sources: z.tuple([]),
original_module_edges: z.tuple([]),
@@ -117,24 +89,15 @@ const webTextArtifactSummarySchema = z.object({
export const webSourceMapsSchema = z
.object({
status: z.enum([
"not_requested",
"included",
"partial",
"unavailable",
"truncated",
]),
status: z.enum(["not_requested", "included", "partial", "unavailable"]),
requested: z.number().int().min(0),
processed: z.number().int().min(0),
dropped: z.number().int().min(0),
dropped_script_keys: z.array(z.string()),
items: z.array(sourceMapSchema),
})
.superRefine((sourceMaps, context) => {
if (
sourceMaps.requested !== sourceMaps.processed + sourceMaps.dropped ||
sourceMaps.processed !== sourceMaps.items.length ||
sourceMaps.dropped !== sourceMaps.dropped_script_keys.length
sourceMaps.requested !== sourceMaps.processed ||
sourceMaps.processed !== sourceMaps.items.length
)
context.addIssue({
code: "custom",
@@ -142,17 +105,14 @@ export const webSourceMapsSchema = z
});
const statuses = sourceMaps.items.map(({ status }) => status);
const included = statuses.filter((status) => status === "included").length;
const hasTruncated = statuses.includes("truncated");
const allowedStatuses =
sourceMaps.dropped > 0 || hasTruncated
? ["truncated"]
: sourceMaps.items.length === 0
? ["not_requested", "unavailable"]
: included === sourceMaps.items.length
? ["included"]
: included > 0
? ["partial"]
: ["unavailable"];
sourceMaps.items.length === 0
? ["not_requested", "unavailable"]
: included === sourceMaps.items.length
? ["included"]
: included > 0
? ["partial"]
: ["unavailable"];
if (!allowedStatuses.includes(sourceMaps.status))
context.addIssue({
code: "custom",
@@ -164,7 +124,7 @@ export const webSourceMapsSchema = z
export type WebSourceMapItem = z.infer<typeof sourceMapSchema>;
export type WebSourceMaps = z.infer<typeof webSourceMapsSchema>;
/** Provider-neutral result of bounded JavaScript bundle reverse engineering. */
/** Provider-neutral result of JavaScript bundle reverse engineering. */
export const webBundleAnalysisSchema = z.object({
capture: z.object({
target_url: z.string(),
@@ -226,7 +186,7 @@ export const webBundleAnalysisSchema = z.object({
}),
),
completeness: z.object({
status: z.enum(["complete_within_limits", "truncated", "partial"]),
status: z.enum(["complete", "partial"]),
parsed_scripts: z.number().int().min(0),
parse_failures: z.number().int().min(0),
visited_ast_nodes: z.number().int().min(0),
+41 -54
View File
@@ -1,20 +1,14 @@
import { describe, expect, it } from "vitest";
import {
inspectWebPageToolInputSchema,
webPageInspectionSchema,
} from "./browserObservation.js";
import { webPageInspectionSchema } from "./browserObservation.js";
import { analyzeCapturedWebBundle } from "./webBundleAnalyzer.js";
import {
analyzeWebBundleInputSchema,
webBundleAnalysisSchema,
} from "./webBundleAnalysis.js";
import { webBundleAnalysisSchema } from "./webBundleAnalysis.js";
import { createWebTextArtifact } from "./webContentArtifact.js";
const origin = "https://app.example.test";
describe("web bundle analyzer", () => {
it("extracts bounded graph, route, endpoint, vendor, and WebMCP evidence", () => {
it("extracts graph, route, endpoint, vendor, and WebMCP evidence", () => {
const source = `
import { createApp } from "./chunk.js?token=secret";
const lazy = import("./lazy.js");
@@ -33,7 +27,7 @@ describe("web bundle analyzer", () => {
});
const __webpack_require__ = () => createApp(routes, lazy);
`;
const result = analyzeCapturedWebBundle(inspection(source), input());
const result = analyzeCapturedWebBundle(inspection(source));
expect(result.observations.chunks.edges).toEqual(
expect.arrayContaining([
@@ -70,12 +64,12 @@ describe("web bundle analyzer", () => {
]),
);
expect(JSON.stringify(result)).not.toContain("authorization=secret");
expect(result.completeness.status).toBe("complete_within_limits");
expect(result.completeness.status).toBe("complete");
});
it("reports parser gaps without imposing a finding cap", () => {
const malformed = inspection("function broken( {");
const failed = analyzeCapturedWebBundle(malformed, input());
const failed = analyzeCapturedWebBundle(malformed);
expect(failed.completeness).toMatchObject({
status: "partial",
parse_failures: 1,
@@ -84,47 +78,52 @@ describe("web bundle analyzer", () => {
const analyzed = analyzeCapturedWebBundle(
inspection("fetch('/one'); fetch('/two'); fetch('/three');"),
input(),
);
expect(analyzed.observations.endpoints).toHaveLength(3);
expect(analyzed.completeness.status).toBe("complete_within_limits");
expect(analyzed.completeness.status).toBe("complete");
});
it("propagates source-map truncation into completeness and unknowns", () => {
const analysis = analyzeCapturedWebBundle(
inspection("export {};"),
input(),
{
status: "truncated",
requested: 2,
processed: 1,
dropped: 1,
dropped_script_keys: [`scr_${"2".repeat(64)}`],
items: [
{
script_key: `scr_${"1".repeat(64)}`,
declared_url: "https://app.example.test/app.js.map",
status: "truncated",
artifact: null,
original_sources: [],
original_module_edges: [],
mappings: [],
limitation: "Source-map response exceeded the byte budget.",
},
],
},
);
it("analyzes AST nodes after the former fixed node ceiling", () => {
const source = `${";".repeat(250_001)}fetch('/last');`;
const result = analyzeCapturedWebBundle(inspection(source));
expect(analysis.completeness.status).toBe("truncated");
expect(result.observations.endpoints).toContainEqual(
expect.objectContaining({ value: "/last" }),
);
expect(result.completeness.visited_ast_nodes).toBeGreaterThan(250_000);
expect(result.completeness.status).toBe("complete");
});
it("reports unavailable source maps as partial without dropping requested maps", () => {
const analysis = analyzeCapturedWebBundle(inspection("export {};"), {
status: "unavailable",
requested: 1,
processed: 1,
items: [
{
script_key: `scr_${"1".repeat(64)}`,
declared_url: "https://app.example.test/app.js.map",
status: "fetch_failed",
artifact: null,
original_sources: [],
original_module_edges: [],
mappings: [],
limitation: "Source-map fetch failed.",
},
],
});
expect(analysis.completeness.status).toBe("partial");
expect(analysis.unknowns).toContainEqual({
dimension: "source_maps",
reason: "Source-map evidence was truncated by provider safety limits",
affected_script_keys: [`scr_${"1".repeat(64)}`, `scr_${"2".repeat(64)}`],
reason:
"One or more requested source maps were unavailable or incomplete",
affected_script_keys: [`scr_${"1".repeat(64)}`],
});
});
it("rejects inconsistent source-map coverage counts", () => {
const result = analyzeCapturedWebBundle(inspection("export {};"), input());
const result = analyzeCapturedWebBundle(inspection("export {};"));
expect(
webBundleAnalysisSchema.safeParse({
...result,
@@ -140,17 +139,6 @@ describe("web bundle analyzer", () => {
});
});
const input = (overrides: Record<string, unknown> = {}) =>
analyzeWebBundleInputSchema.parse({
...inspectWebPageToolInputSchema.parse({
cdp_endpoint: "http://127.0.0.1:9222",
allowed_origins: [origin],
target_id: "page-1",
include_script_sources: true,
}),
...overrides,
});
const inspection = (source: string) =>
webPageInspectionSchema.parse({
browser: {
@@ -200,7 +188,6 @@ const inspection = (source: string) =>
status: "not_approved",
retained_bytes: 0,
excluded_fields: 0,
truncated_fields: 0,
},
nodes: [],
},
+2 -8
View File
@@ -5,27 +5,21 @@ import {
isIncludedScript,
} from "./webBundleAnalyzerInspection.js";
import { buildWebBundleAnalysis } from "./webBundleAnalyzerResult.js";
import type {
AnalyzeWebBundleInput,
WebBundleAnalysis,
} from "./webBundleAnalysis.js";
import type { WebBundleAnalysis } from "./webBundleAnalysis.js";
/** Analyze captured, explicitly approved JavaScript source without execution. */
export const analyzeCapturedWebBundle = (
inspection: WebPageInspection,
input: AnalyzeWebBundleInput,
sourceMaps: WebBundleAnalysis["observations"]["source_maps"] = {
status: "not_requested",
requested: 0,
processed: 0,
dropped: 0,
dropped_script_keys: [],
items: [],
},
): WebBundleAnalysis => {
const accumulator = emptyAccumulator();
const sourceScripts = inspection.scripts.items.filter(isIncludedScript);
for (const script of sourceScripts) analyzeScript(script, input, accumulator);
for (const script of sourceScripts) analyzeScript(script, accumulator);
return buildWebBundleAnalysis(
inspection,
sourceScripts,
+1 -11
View File
@@ -3,10 +3,7 @@ import * as t from "@babel/types";
import { sanitizeEndpointCandidate } from "./browserObservation.js";
import type { WebPageInspection } from "./browserObservation.js";
import type {
AnalyzeWebBundleInput,
WebBundleAnalysis,
} from "./webBundleAnalysis.js";
import type { WebBundleAnalysis } from "./webBundleAnalysis.js";
import {
calleeName,
endpointArgument,
@@ -40,12 +37,10 @@ export interface AnalysisAccumulator {
visitedNodes: number;
parsedScripts: number;
parseFailures: number;
astLimitReached: boolean;
}
export const analyzeScript = (
script: IncludedScript,
input: AnalyzeWebBundleInput,
accumulator: AnalysisAccumulator,
): void => {
let file: ReturnType<typeof parse>;
@@ -63,10 +58,6 @@ export const analyzeScript = (
detectVendorFingerprints(script, accumulator);
t.traverseFast(file, (node) => {
accumulator.visitedNodes += 1;
if (accumulator.visitedNodes > input.analysis_limits.max_ast_nodes) {
accumulator.astLimitReached = true;
return t.traverseFast.stop;
}
inspectNode(script, node, accumulator);
return undefined;
});
@@ -348,7 +339,6 @@ export const emptyAccumulator = (): AnalysisAccumulator => ({
visitedNodes: 0,
parsedScripts: 0,
parseFailures: 0,
astLimitReached: false,
});
export const isIncludedScript = (
+6 -20
View File
@@ -23,8 +23,6 @@ export const buildWebBundleAnalysis = (
accumulator.parseFailures > 0 ||
unavailable.length > 0 ||
sourceMapIncomplete;
const truncated =
accumulator.astLimitReached || sourceMaps.status === "truncated";
return webBundleAnalysisSchema.parse({
capture: buildCaptureObservation(inspection, sourceScripts),
observations: {
@@ -45,7 +43,6 @@ export const buildWebBundleAnalysis = (
sourceMaps,
}),
completeness: buildCompleteness({
truncated,
partial,
parsedScripts: accumulator.parsedScripts,
parseFailures: accumulator.parseFailures,
@@ -116,23 +113,16 @@ const buildUnknowns = (input: UnknownsInput): WebBundleAnalysis["unknowns"] => [
{
dimension: "source_maps" as const,
reason:
input.sourceMaps.status === "truncated"
? "Source-map evidence was truncated by provider safety limits"
: "One or more requested source maps were unavailable or incomplete",
affected_script_keys: [
...new Set([
...input.sourceMaps.items
.filter(({ status }) => status !== "included")
.map(({ script_key }) => script_key),
...input.sourceMaps.dropped_script_keys,
]),
].sort(),
"One or more requested source maps were unavailable or incomplete",
affected_script_keys: input.sourceMaps.items
.filter(({ status }) => status !== "included")
.map(({ script_key }) => script_key)
.sort(),
},
]),
];
interface CompletenessInput {
readonly truncated: boolean;
readonly partial: boolean;
readonly parsedScripts: number;
readonly parseFailures: number;
@@ -142,11 +132,7 @@ interface CompletenessInput {
const buildCompleteness = (
input: CompletenessInput,
): WebBundleAnalysis["completeness"] => ({
status: input.truncated
? "truncated"
: input.partial
? "partial"
: "complete_within_limits",
status: input.partial ? "partial" : "complete",
parsed_scripts: input.parsedScripts,
parse_failures: input.parseFailures,
visited_ast_nodes: input.visitedNodes,
+2 -2
View File
@@ -25,7 +25,7 @@ export const registerArtifactComparisonTool = (
async (input, context) => {
const expected = {
operation: ["inspect_artifact", "inventory_artifact"],
predicate: "rea.analysis/v2",
predicate: "rea.analysis",
};
const left = resolveSessionEvidenceIds(
session,
@@ -47,7 +47,7 @@ export const registerArtifactComparisonTool = (
const leftEvidenceIds = [input.left_evidence_id];
const rightEvidenceIds = [input.right_evidence_id];
const evidence = createEvidence(undefined, ARTIFACT_COMPARISON_PROVIDER, {
predicateType: "rea.artifact-comparison/v1",
predicateType: "rea.artifact-comparison",
operation: contract.name,
parameters: {
left_evidence_ids: leftEvidenceIds,
+1 -1
View File
@@ -36,7 +36,7 @@ export const registerBundleComparisonTool = (
if (!computed.ok) return toCallToolResult(computed, contract);
const comparison = computed.value;
const evidence = createEvidence(undefined, BUNDLE_COMPARISON_PROVIDER, {
predicateType: "rea.bundle-comparison/v1",
predicateType: "rea.bundle-comparison",
operation: contract.name,
parameters: {
left_bundle_sha256: comparison.left_bundle_sha256,
+2 -2
View File
@@ -25,7 +25,7 @@ export const registerFunctionComparisonTool = (
async (input, context) => {
const expected = {
operation: "analyze_function",
predicate: "rea.analysis/v2",
predicate: "rea.analysis",
};
const left = resolveSessionEvidenceIds(
session,
@@ -51,7 +51,7 @@ export const registerFunctionComparisonTool = (
if (!computed.ok) return toCallToolResult(computed, contract);
const comparison = computed.value;
const evidence = createEvidence(undefined, FUNCTION_COMPARISON_PROVIDER, {
predicateType: "rea.function-comparison/v1",
predicateType: "rea.function-comparison",
operation: contract.name,
parameters: {
left_evidence_id: leftEvidence.evidence_id,
@@ -75,7 +75,7 @@ export const registerJavaScriptRuntimeObservationTools = (
[
{
operation: "list_javascript_runtime_targets",
predicate: "rea.javascript-runtime-target-list/v1",
predicate: "rea.javascript-runtime-target-list",
},
],
);
@@ -10,7 +10,7 @@ export const resolveManagedEvidence = (
): Result<Evidence[], EvidenceIntegrityError> =>
resolveSessionEvidenceIds(session, evidenceIds, {
operation: "inspect_managed_members",
predicate: "rea.analysis/v2",
predicate: "rea.analysis",
});
export const resolveManagedArtifactEvidence = (
@@ -19,7 +19,7 @@ export const resolveManagedArtifactEvidence = (
): Result<Evidence[], EvidenceIntegrityError> =>
resolveSessionEvidenceIds(session, [evidenceId], {
operation: "inspect_managed_artifact",
predicate: "rea.analysis/v2",
predicate: "rea.analysis",
});
export const resolveManagedBoundaryEvidence = (
@@ -28,7 +28,7 @@ export const resolveManagedBoundaryEvidence = (
): Result<Evidence[], EvidenceIntegrityError> =>
resolveSessionEvidenceIds(session, [evidenceId], {
operation: "inspect_managed_native_boundaries",
predicate: "rea.analysis/v2",
predicate: "rea.analysis",
});
export const resolveNativeEvidence = (
@@ -44,7 +44,7 @@ export const resolveNativeEvidence = (
: "inspect_macho or analyze_function";
const resolved = resolveSessionEvidenceIds(session, [evidenceId], {
operation: expectedOperation,
predicate: "rea.analysis/v2",
predicate: "rea.analysis",
});
if (!resolved.ok) return resolved;
records.push(...resolved.value);
@@ -75,7 +75,7 @@ describe("application workflow MCP parity", () => {
expect.arrayContaining([
expect.objectContaining({
operation: "compare_javascript_export_shapes",
predicate_type: "rea.javascript-export-shape-comparison/v1",
predicate_type: "rea.javascript-export-shape-comparison",
}),
]),
);

Some files were not shown because too many files have changed in this diff Show More