refactor(javascript): remove analysis ceilings
This commit is contained in:
@@ -2,10 +2,6 @@ import { createHash } from "node:crypto";
|
||||
|
||||
import { analyzeParsedJavaScriptStaticSource } from "../domain/javascriptStaticAnalysis.js";
|
||||
import { analyzeParsedJavaScriptSemantics } from "../domain/javascriptSemanticAnalysis.js";
|
||||
import {
|
||||
DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS,
|
||||
type JavaScriptSemanticLimits,
|
||||
} from "../domain/javascriptSemanticIr.js";
|
||||
import { parseJavaScriptSource } from "../domain/javascriptSourceParser.js";
|
||||
import type {
|
||||
JavaScriptSourceRange,
|
||||
@@ -58,10 +54,7 @@ export const analyzeJavaScriptArtifactFiles = (
|
||||
const finalizeArtifactAnalysis = (
|
||||
state: MutableArtifactAnalysis,
|
||||
): JavaScriptArtifactAnalysis => {
|
||||
const sourceMapTruncations = state.sourceMaps.filter(
|
||||
({ status }) => status === "truncated",
|
||||
).length;
|
||||
const truncatedScopes = state.truncatedScopes + sourceMapTruncations;
|
||||
const truncatedScopes = state.truncatedScopes;
|
||||
return {
|
||||
files: state.files,
|
||||
packages: state.packages,
|
||||
@@ -103,27 +96,16 @@ const analyzeArtifactFile = (
|
||||
state.parseFailures += 1;
|
||||
return;
|
||||
}
|
||||
const analysis = analyzeParsedJavaScriptStaticSource(
|
||||
file.text.value,
|
||||
parsed,
|
||||
{
|
||||
maxAstNodes: Number.POSITIVE_INFINITY,
|
||||
deadline: Number.POSITIVE_INFINITY,
|
||||
now: () => 0,
|
||||
},
|
||||
);
|
||||
const analysis = analyzeParsedJavaScriptStaticSource(file.text.value, parsed);
|
||||
const staticFindings = findingCount(analysis);
|
||||
const semanticLimits: JavaScriptSemanticLimits =
|
||||
DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS;
|
||||
const semantics =
|
||||
analysis.parse_status === "complete" || analysis.parse_status === "partial"
|
||||
? analyzeParsedJavaScriptSemantics(parsed, semanticLimits)
|
||||
? analyzeParsedJavaScriptSemantics(parsed)
|
||||
: null;
|
||||
state.files.push({
|
||||
file,
|
||||
javascript: analysis,
|
||||
semantic:
|
||||
semantics === null ? null : { ir: semantics, limits: semanticLimits },
|
||||
semantic: semantics === null ? null : { ir: semantics },
|
||||
});
|
||||
state.visitedNodes += analysis.visited_ast_nodes;
|
||||
state.findings += staticFindings + (semantics?.moduleLinks.length ?? 0);
|
||||
@@ -132,8 +114,6 @@ const analyzeArtifactFile = (
|
||||
0,
|
||||
);
|
||||
if (analysis.parse_status === "failed") state.parseFailures += 1;
|
||||
if (analysis.parse_status === "truncated") state.truncatedScopes += 1;
|
||||
if (semantics?.coverage.status === "truncated") state.truncatedScopes += 1;
|
||||
};
|
||||
|
||||
const addSourceMap = (
|
||||
@@ -293,7 +273,6 @@ const collectSourceMapOriginals = (
|
||||
sha256: file.sha256,
|
||||
status: "included",
|
||||
sources,
|
||||
omitted_sources: 0,
|
||||
limitation: null,
|
||||
};
|
||||
};
|
||||
@@ -308,7 +287,6 @@ const unavailableSourceMap = (
|
||||
sha256: file.sha256,
|
||||
status: "invalid",
|
||||
sources: [],
|
||||
omitted_sources: 0,
|
||||
limitation: "Source-map text could not be decoded as UTF-8.",
|
||||
};
|
||||
};
|
||||
@@ -340,7 +318,6 @@ const invalidSourceMap = (
|
||||
sha256: file.sha256,
|
||||
status: "invalid",
|
||||
sources: [],
|
||||
omitted_sources: 0,
|
||||
limitation,
|
||||
});
|
||||
|
||||
@@ -376,10 +353,7 @@ const pointForOffset = (
|
||||
};
|
||||
|
||||
const resolveSourceName = (root: string, source: string): string =>
|
||||
`${root}${root !== "" && !root.endsWith("/") ? "/" : ""}${source}`.slice(
|
||||
0,
|
||||
4_096,
|
||||
);
|
||||
`${root}${root !== "" && !root.endsWith("/") ? "/" : ""}${source}`;
|
||||
|
||||
const optionalString = (value: unknown): string | null =>
|
||||
typeof value === "string" && value.length > 0 ? value : null;
|
||||
|
||||
@@ -2,10 +2,7 @@ import type {
|
||||
JavaScriptSourceRange,
|
||||
JavaScriptStaticAnalysis,
|
||||
} from "../domain/javascriptStaticAnalysisTypes.js";
|
||||
import type {
|
||||
JavaScriptSemanticIr,
|
||||
JavaScriptSemanticLimits,
|
||||
} from "../domain/javascriptSemanticIr.js";
|
||||
import type { JavaScriptSemanticIr } from "../domain/javascriptSemanticIr.js";
|
||||
import type { JavaScriptArtifactFile } from "./JavaScriptArtifactFiles.js";
|
||||
|
||||
interface JavaScriptStructuredObservation {
|
||||
@@ -52,30 +49,22 @@ export interface JavaScriptSourceMapOriginal {
|
||||
readonly content_sha256: string | null;
|
||||
}
|
||||
|
||||
/** Bounded local source-map parse result. */
|
||||
/** Local source-map parse result. */
|
||||
export type JavaScriptSourceMapObservation = JavaScriptStructuredObservation &
|
||||
(
|
||||
| {
|
||||
readonly status: "included";
|
||||
readonly sources: readonly JavaScriptSourceMapOriginal[];
|
||||
readonly omitted_sources: 0;
|
||||
readonly limitation: null;
|
||||
}
|
||||
| {
|
||||
readonly status: "truncated";
|
||||
readonly sources: readonly JavaScriptSourceMapOriginal[];
|
||||
readonly omitted_sources: number | null;
|
||||
readonly limitation: string;
|
||||
}
|
||||
| {
|
||||
readonly status: "invalid";
|
||||
readonly sources: readonly [];
|
||||
readonly omitted_sources: 0;
|
||||
readonly limitation: string;
|
||||
}
|
||||
);
|
||||
|
||||
/** Bounded parse status for one inventoried JSON module. */
|
||||
/** Parse status for one inventoried JSON module. */
|
||||
export type JavaScriptJsonModuleObservation = JavaScriptStructuredObservation &
|
||||
(
|
||||
| {
|
||||
@@ -104,11 +93,10 @@ export interface AnalyzedJavaScriptArtifactFile {
|
||||
readonly javascript: JavaScriptStaticAnalysis | null;
|
||||
readonly semantic: {
|
||||
readonly ir: JavaScriptSemanticIr;
|
||||
readonly limits: JavaScriptSemanticLimits;
|
||||
} | null;
|
||||
}
|
||||
|
||||
/** Complete bounded static-analysis projection before graph construction. */
|
||||
/** Complete static-analysis projection before graph construction. */
|
||||
export interface JavaScriptArtifactAnalysis {
|
||||
readonly files: readonly AnalyzedJavaScriptArtifactFile[];
|
||||
readonly packages: readonly JavaScriptPackageObservation[];
|
||||
|
||||
@@ -134,8 +134,6 @@ const addBundlerModuleNodes = (
|
||||
moduleValue.structural_fingerprint_sha256,
|
||||
structural_fingerprint_algorithm:
|
||||
moduleValue.structural_fingerprint_algorithm,
|
||||
structural_fingerprint_status:
|
||||
moduleValue.structural_fingerprint_status,
|
||||
exports: moduleValue.exports,
|
||||
},
|
||||
evidence: astObservationEvidence({
|
||||
|
||||
@@ -6,10 +6,7 @@ import {
|
||||
type JavaScriptArtifactGraphContext,
|
||||
} from "./JavaScriptArtifactGraphContext.js";
|
||||
import { artifactObservationEvidence } from "./JavaScriptArtifactGraphEvidence.js";
|
||||
import {
|
||||
completeApplicationCoverage,
|
||||
partialApplicationCoverage,
|
||||
} from "../domain/javascriptApplicationEvidenceSchemas.js";
|
||||
import { completeApplicationCoverage } from "../domain/javascriptApplicationEvidenceSchemas.js";
|
||||
import { resolveArtifactPathByContext } from "./JavaScriptArtifactPathResolution.js";
|
||||
|
||||
/** Project HTML renderer entrypoints and their local script assets. */
|
||||
@@ -91,10 +88,7 @@ export const addJavaScriptSourceMapOriginals = (
|
||||
const mapFile = context.filesByPath.get(sourceMap.path);
|
||||
const mapNode = context.fileNodes.get(sourceMap.path);
|
||||
if (mapFile === undefined || mapNode === undefined) continue;
|
||||
const coverage =
|
||||
sourceMap.status === "truncated"
|
||||
? partialApplicationCoverage([], null)
|
||||
: completeApplicationCoverage();
|
||||
const coverage = completeApplicationCoverage();
|
||||
for (const original of sourceMap.sources) {
|
||||
const node = context.accumulator.addNode({
|
||||
kind: "source-module",
|
||||
|
||||
@@ -159,9 +159,81 @@ describe("contextual JavaScript artifact path resolution", () => {
|
||||
}),
|
||||
).toMatchObject({ resolution_status: "not-found", resolved_path: null });
|
||||
});
|
||||
|
||||
it("resolves inventoried paths longer than the former character ceiling", () => {
|
||||
const declaredPath = `./${"a".repeat(5_000)}.js`;
|
||||
const expectedPath = `app/${declaredPath.slice(2)}`;
|
||||
const files = fileMap([
|
||||
file("app/consumer.js", "root"),
|
||||
file(expectedPath, "root"),
|
||||
]);
|
||||
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath,
|
||||
sourcePath: "app/consumer.js",
|
||||
context: "module-specifier",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: expectedPath,
|
||||
limitations: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("contextual JavaScript package path resolution", () => {
|
||||
it("follows package entrypoints beyond the former recursion ceiling", () => {
|
||||
const files = fileMap([
|
||||
file("app/consumer.js", "root"),
|
||||
file(
|
||||
"app/node_modules/pkg-1/package.json",
|
||||
"root",
|
||||
'{"main":"../pkg-2"}',
|
||||
),
|
||||
file(
|
||||
"app/node_modules/pkg-2/package.json",
|
||||
"root",
|
||||
'{"main":"../pkg-3"}',
|
||||
),
|
||||
file(
|
||||
"app/node_modules/pkg-3/package.json",
|
||||
"root",
|
||||
'{"main":"../pkg-4"}',
|
||||
),
|
||||
file(
|
||||
"app/node_modules/pkg-4/package.json",
|
||||
"root",
|
||||
'{"main":"../pkg-5"}',
|
||||
),
|
||||
file(
|
||||
"app/node_modules/pkg-5/package.json",
|
||||
"root",
|
||||
'{"main":"../pkg-6"}',
|
||||
),
|
||||
file(
|
||||
"app/node_modules/pkg-6/package.json",
|
||||
"root",
|
||||
'{"main":"entry.js"}',
|
||||
),
|
||||
file("app/node_modules/pkg-6/entry.js", "root"),
|
||||
]);
|
||||
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "pkg-1",
|
||||
sourcePath: "app/consumer.js",
|
||||
context: "module-specifier",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "app/node_modules/pkg-6/entry.js",
|
||||
limitations: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps an inventoried but unreadable directory package unavailable", () => {
|
||||
const files = fileMap([
|
||||
file("app/package.json", "root"),
|
||||
@@ -272,11 +344,6 @@ describe("contextual JavaScript module identity", () => {
|
||||
}});
|
||||
window.loadURL("file:///renderer/index.html");
|
||||
`,
|
||||
{
|
||||
maxAstNodes: Number.POSITIVE_INFINITY,
|
||||
deadline: Number.POSITIVE_INFINITY,
|
||||
now: () => 0,
|
||||
},
|
||||
);
|
||||
|
||||
expect(analysis.role_paths).toEqual(
|
||||
|
||||
@@ -21,7 +21,7 @@ interface ArtifactPathResolutionBase {
|
||||
readonly limitations: readonly string[];
|
||||
}
|
||||
|
||||
/** Explicit outcome of bounded, artifact-confined path resolution. */
|
||||
/** Explicit outcome of artifact-confined path resolution. */
|
||||
export type ArtifactPathResolution = ArtifactPathResolutionBase &
|
||||
(
|
||||
| {
|
||||
@@ -54,7 +54,6 @@ const EXTENSIONS = [
|
||||
".html",
|
||||
".node",
|
||||
];
|
||||
const MAX_PACKAGE_DEPTH = 4;
|
||||
const NODE_BUILTINS = new Set(
|
||||
builtinModules.map((name) => name.replace(/^node:/u, "")),
|
||||
);
|
||||
@@ -74,11 +73,11 @@ type CandidateResolution =
|
||||
/** Resolve one declaration under its exact syntax/metadata context. */
|
||||
export const resolveArtifactPathByContext = (
|
||||
input: ResolveArtifactPathInput,
|
||||
): ArtifactPathResolution => resolveAtDepth(input, 0);
|
||||
): ArtifactPathResolution => resolvePackagePath(input, new Set());
|
||||
|
||||
const resolveAtDepth = (
|
||||
const resolvePackagePath = (
|
||||
input: ResolveArtifactPathInput,
|
||||
packageDepth: number,
|
||||
packageChain: ReadonlySet<string>,
|
||||
): ArtifactPathResolution => {
|
||||
const rejected = rejectDeclaration(input);
|
||||
if (rejected !== null) return rejected;
|
||||
@@ -86,7 +85,7 @@ const resolveAtDepth = (
|
||||
if (typeof candidate !== "string") return candidate;
|
||||
const confined = confineCandidate(input, candidate);
|
||||
if (typeof confined !== "string") return confined;
|
||||
const resolved = resolveCandidate(input, confined, packageDepth);
|
||||
const resolved = resolveCandidate(input, confined, packageChain);
|
||||
return outcome(input, resolved);
|
||||
};
|
||||
|
||||
@@ -98,10 +97,6 @@ const rejectDeclaration = (
|
||||
return unresolvedOutcome(input, "rejected", [
|
||||
"The declared path is empty.",
|
||||
]);
|
||||
if (declared.length > 4_096)
|
||||
return unresolvedOutcome(input, "rejected", [
|
||||
"The declared path exceeds the 4096-character resolution bound.",
|
||||
]);
|
||||
if (declared.includes("\0") || declared.includes("\\"))
|
||||
return unresolvedOutcome(input, "rejected", [
|
||||
"NUL and backslash path syntax are not admitted for canonical artifact paths.",
|
||||
@@ -239,7 +234,7 @@ const confineCandidate = (
|
||||
const resolveCandidate = (
|
||||
input: ResolveArtifactPathInput,
|
||||
candidate: string,
|
||||
packageDepth: number,
|
||||
packageChain: ReadonlySet<string>,
|
||||
): CandidateResolution => {
|
||||
const source = input.files.get(input.sourcePath);
|
||||
for (const path of directCandidates(candidate)) {
|
||||
@@ -251,14 +246,6 @@ const resolveCandidate = (
|
||||
)
|
||||
return { resolvedPath: path, status: "resolved", limitations: [] };
|
||||
}
|
||||
if (packageDepth >= MAX_PACKAGE_DEPTH)
|
||||
return {
|
||||
resolvedPath: null,
|
||||
status: "unavailable",
|
||||
limitations: [
|
||||
`Directory package resolution exceeded its ${String(MAX_PACKAGE_DEPTH)}-package recursion bound.`,
|
||||
],
|
||||
};
|
||||
const packagePath = posix.join(candidate, "package.json");
|
||||
const packageFile = input.files.get(packagePath);
|
||||
if (
|
||||
@@ -275,24 +262,32 @@ const resolveCandidate = (
|
||||
`Directory package metadata ${packagePath} was inventoried but its text is unavailable: ${packageFile.text.reason}.`,
|
||||
],
|
||||
};
|
||||
if (packageChain.has(packagePath))
|
||||
return {
|
||||
resolvedPath: null,
|
||||
status: "unavailable",
|
||||
limitations: [
|
||||
`Directory package entrypoint cycle includes ${packagePath}.`,
|
||||
],
|
||||
};
|
||||
const main = packageEntry(packageFile.text.value, input.moduleKind);
|
||||
if (main.status === "invalid")
|
||||
return {
|
||||
resolvedPath: null,
|
||||
status: "unavailable",
|
||||
limitations: [
|
||||
`Directory package metadata ${packagePath} is not valid bounded package JSON.`,
|
||||
`Directory package metadata ${packagePath} is not valid package JSON.`,
|
||||
],
|
||||
};
|
||||
if (main.status === "missing") return notFoundCandidate();
|
||||
const nested = resolveAtDepth(
|
||||
const nested = resolvePackagePath(
|
||||
{
|
||||
declaredPath: main.value,
|
||||
sourcePath: packagePath,
|
||||
context: "package-entrypoint",
|
||||
files: input.files,
|
||||
},
|
||||
packageDepth + 1,
|
||||
new Set([...packageChain, packagePath]),
|
||||
);
|
||||
return nested.resolution_status === "resolved"
|
||||
? {
|
||||
@@ -332,7 +327,7 @@ const packageEntry = (
|
||||
: [Reflect.get(value, "main"), Reflect.get(value, "module")];
|
||||
const entry = preferred.find((candidate) => candidate !== undefined);
|
||||
if (entry === undefined) return { status: "missing" };
|
||||
return boundedPackagePath(entry);
|
||||
return packagePathValue(entry);
|
||||
} catch {
|
||||
return { status: "invalid" };
|
||||
}
|
||||
@@ -344,24 +339,24 @@ const packageExport = (
|
||||
):
|
||||
| { readonly status: "value"; readonly value: string }
|
||||
| { readonly status: "invalid" } => {
|
||||
if (typeof value === "string") return boundedPackagePath(value);
|
||||
if (typeof value === "string") return packagePathValue(value);
|
||||
if (typeof value !== "object" || value === null || Array.isArray(value))
|
||||
return { status: "invalid" };
|
||||
const root = Reflect.get(value, ".") ?? value;
|
||||
if (typeof root === "string") return boundedPackagePath(root);
|
||||
if (typeof root === "string") return packagePathValue(root);
|
||||
if (typeof root !== "object" || root === null || Array.isArray(root))
|
||||
return { status: "invalid" };
|
||||
const condition =
|
||||
Reflect.get(root, moduleKind ?? "default") ?? Reflect.get(root, "default");
|
||||
return boundedPackagePath(condition);
|
||||
return packagePathValue(condition);
|
||||
};
|
||||
|
||||
const boundedPackagePath = (
|
||||
const packagePathValue = (
|
||||
value: unknown,
|
||||
):
|
||||
| { readonly status: "value"; readonly value: string }
|
||||
| { readonly status: "invalid" } =>
|
||||
typeof value === "string" && value.length > 0 && value.length <= 4_096
|
||||
typeof value === "string" && value.length > 0
|
||||
? { status: "value", value }
|
||||
: { status: "invalid" };
|
||||
|
||||
@@ -369,7 +364,7 @@ const notFoundCandidate = (): CandidateResolution => ({
|
||||
resolvedPath: null,
|
||||
status: "not-found",
|
||||
limitations: [
|
||||
"No bounded extension, directory package, or index candidate exists in the inventoried artifact container.",
|
||||
"No extension, directory package, or index candidate exists in the inventoried artifact container.",
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ import type { ApplicationNode } from "../domain/javascriptApplicationGraph.js";
|
||||
import {
|
||||
completeApplicationCoverage,
|
||||
partialApplicationCoverage,
|
||||
truncatedApplicationCoverage,
|
||||
} from "../domain/javascriptApplicationEvidenceSchemas.js";
|
||||
import type {
|
||||
JavaScriptModuleOrigin,
|
||||
JavaScriptSemanticIr,
|
||||
JavaScriptSemanticLimits,
|
||||
JavaScriptSemanticModuleLink,
|
||||
} from "../domain/javascriptSemanticIr.js";
|
||||
import type { JavaScriptArtifactFile } from "./JavaScriptArtifactFiles.js";
|
||||
@@ -31,7 +29,6 @@ import { projectJavaScriptExportReturnShapes } from "./JavaScriptReturnShapeProj
|
||||
|
||||
interface SemanticAnalysis {
|
||||
readonly ir: JavaScriptSemanticIr;
|
||||
readonly limits: JavaScriptSemanticLimits;
|
||||
}
|
||||
|
||||
interface RelationshipInput {
|
||||
@@ -369,16 +366,9 @@ const relationshipEvidence = (
|
||||
const semanticCoverage = (
|
||||
semantic: SemanticAnalysis,
|
||||
): JavaScriptArtifactGraphCoverage => {
|
||||
const limits = Object.entries(semantic.limits).map(([name, value]) => ({
|
||||
name: `semantic-${camelToKebab(name)}`,
|
||||
value,
|
||||
unit: "items" as const,
|
||||
}));
|
||||
if (semantic.ir.coverage.status === "complete")
|
||||
return completeApplicationCoverage(limits);
|
||||
return semantic.ir.coverage.status === "truncated"
|
||||
? truncatedApplicationCoverage(limits, semantic.ir.coverage.omittedCount)
|
||||
: partialApplicationCoverage(limits, semantic.ir.coverage.omittedCount);
|
||||
return completeApplicationCoverage();
|
||||
return partialApplicationCoverage([], semantic.ir.coverage.omittedCount);
|
||||
};
|
||||
|
||||
const moduleFormat = (
|
||||
@@ -420,8 +410,5 @@ const isExportLink = (link: JavaScriptSemanticModuleLink): boolean =>
|
||||
link.kind === "re-export" ||
|
||||
link.kind === "commonjs-export";
|
||||
|
||||
const camelToKebab = (value: string): string =>
|
||||
value.replaceAll(/([a-z])([A-Z])/gu, "$1-$2").toLowerCase();
|
||||
|
||||
const compareCodePoints = (left: string, right: string): number =>
|
||||
left < right ? -1 : left > right ? 1 : 0;
|
||||
|
||||
@@ -5,10 +5,6 @@ import type { JavaScriptArtifactAnalysis } from "./JavaScriptArtifactAnalysisTyp
|
||||
import type { JavaScriptArtifactFile } from "./JavaScriptArtifactFiles.js";
|
||||
import { queryJavaScriptSemanticGraph } from "../domain/javascriptSemanticQuery.js";
|
||||
import { analyzeJavaScriptSemantics } from "../domain/javascriptSemanticAnalysis.js";
|
||||
import {
|
||||
DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS,
|
||||
type JavaScriptSemanticLimits,
|
||||
} from "../domain/javascriptSemanticIr.js";
|
||||
|
||||
const SHA256 = "a".repeat(64);
|
||||
const GRAPH_ID = `jag_${"b".repeat(64)}`;
|
||||
@@ -173,25 +169,19 @@ it("connects caller results, direct returns, parameters, and captures", () => {
|
||||
expect(capture?.evidence.location).not.toEqual(readOuter.evidence.location);
|
||||
});
|
||||
|
||||
it("preserves the semantic value-depth guard in graph coverage", () => {
|
||||
const graph = graphFor(
|
||||
"const first = 1; const second = first; const third = second;",
|
||||
{ maxValueDepth: 1 },
|
||||
);
|
||||
it("reports complete graph coverage for deeply nested static values", () => {
|
||||
const nesting = 40;
|
||||
const nestedValue =
|
||||
Array.from({ length: nesting }, () => "{ next: ").join("") +
|
||||
'"value"' +
|
||||
" }".repeat(nesting);
|
||||
const graph = graphFor(`const nested = ${nestedValue};`);
|
||||
expect(graph.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
truncated: true,
|
||||
omitted_nodes: null,
|
||||
omitted_relations: null,
|
||||
limits: expect.arrayContaining([
|
||||
{ name: "semantic.maxValueDepth", value: 1, unit: "depth" },
|
||||
]),
|
||||
truncated: false,
|
||||
omitted_nodes: 0,
|
||||
omitted_relations: 0,
|
||||
limits: [],
|
||||
});
|
||||
expect(
|
||||
graph.coverage.families.find(
|
||||
({ family }) => family === "promise-ownership",
|
||||
),
|
||||
).toMatchObject({ status: "unknown", retained_relations: 0 });
|
||||
});
|
||||
|
||||
it("projects bounded Promise ownership and unresolved sources", () => {
|
||||
@@ -259,10 +249,7 @@ it("keeps duplicate function fingerprints ambiguous", () => {
|
||||
expect(query.summary.total_seed_matches).toBe(2);
|
||||
});
|
||||
|
||||
const graphFor = (
|
||||
source: string,
|
||||
inputLimits: Partial<JavaScriptSemanticLimits> = {},
|
||||
) => {
|
||||
const graphFor = (source: string) => {
|
||||
const file: JavaScriptArtifactFile = {
|
||||
path: "app.js",
|
||||
container_sha256: SHA256,
|
||||
@@ -273,18 +260,13 @@ const graphFor = (
|
||||
unpacked: false,
|
||||
text: { included: true, value: source },
|
||||
};
|
||||
const semanticLimits = {
|
||||
...DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS,
|
||||
...inputLimits,
|
||||
};
|
||||
const analysis: JavaScriptArtifactAnalysis = {
|
||||
files: [
|
||||
{
|
||||
file,
|
||||
javascript: null,
|
||||
semantic: {
|
||||
ir: analyzeJavaScriptSemantics(source, inputLimits),
|
||||
limits: semanticLimits,
|
||||
ir: analyzeJavaScriptSemantics(source),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
projectSemanticFrontiers,
|
||||
projectSemanticPromises,
|
||||
projectSemanticReturnValues,
|
||||
semanticRecoveryLimits,
|
||||
type SemanticFlowProjectionContext,
|
||||
} from "./JavaScriptSemanticGraphFlowProjection.js";
|
||||
import {
|
||||
@@ -90,10 +89,7 @@ export const buildJavaScriptSemanticGraph = ({
|
||||
);
|
||||
}
|
||||
if (state.roots.size === 0) addFallbackRoot(rootArtifactSha256, state);
|
||||
const semanticTruncated = analysis.files.some(
|
||||
({ semantic }) => semantic?.ir.coverage.status === "truncated",
|
||||
);
|
||||
const truncated = semanticTruncated;
|
||||
const truncated = false;
|
||||
const unknowns = [...state.unknowns.values()];
|
||||
return createJavaScriptSemanticGraph({
|
||||
schema: "JavaScriptSemanticRelationGraph",
|
||||
@@ -109,7 +105,7 @@ export const buildJavaScriptSemanticGraph = ({
|
||||
truncated,
|
||||
omitted_nodes: truncated ? null : 0,
|
||||
omitted_relations: truncated ? null : 0,
|
||||
limits: [...semanticRecoveryLimits(analysis)],
|
||||
limits: [],
|
||||
families: JAVASCRIPT_SEMANTIC_RELATION_FAMILIES.map((family) => ({
|
||||
family,
|
||||
status: semanticFamilyStatus(family, analysis, truncated),
|
||||
|
||||
@@ -3,7 +3,6 @@ import type { JavaScriptSemanticGraphNode } from "../domain/javascriptSemanticGr
|
||||
import type { JavaScriptSemanticIr } from "../domain/javascriptSemanticIr.js";
|
||||
import { sourceRangesEqual } from "../domain/javascriptStaticAnalysisHelpers.js";
|
||||
import type { JavaScriptSourceRange } from "../domain/javascriptStaticAnalysisTypes.js";
|
||||
import type { JavaScriptArtifactAnalysis } from "./JavaScriptArtifactAnalysisTypes.js";
|
||||
import type { JavaScriptArtifactFile } from "./JavaScriptArtifactFiles.js";
|
||||
import {
|
||||
addSemanticGraphNode,
|
||||
@@ -280,22 +279,3 @@ export const projectSemanticFrontiers = (
|
||||
addSemanticGraphUnknown(context.state, unknown);
|
||||
}
|
||||
};
|
||||
|
||||
/** Publish the semantic recursion guard when it caused incomplete recovery. */
|
||||
export const semanticRecoveryLimits = (
|
||||
analysis: JavaScriptArtifactAnalysis,
|
||||
): {
|
||||
readonly name: string;
|
||||
readonly value: number;
|
||||
readonly unit: "depth";
|
||||
}[] => {
|
||||
const limits = new Map<string, number>();
|
||||
for (const { semantic } of analysis.files) {
|
||||
if (semantic === null) continue;
|
||||
for (const name of semantic.ir.coverage.limitsReached)
|
||||
limits.set(`semantic.${name}`, semantic.limits[name]);
|
||||
}
|
||||
return [...limits]
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
.map(([name, value]) => ({ name, value, unit: "depth" }));
|
||||
};
|
||||
|
||||
@@ -5,10 +5,6 @@ import type { JavaScriptArtifactAnalysis } from "./JavaScriptArtifactAnalysisTyp
|
||||
import type { JavaScriptArtifactFile } from "./JavaScriptArtifactFiles.js";
|
||||
import { queryJavaScriptSemanticGraph } from "../domain/javascriptSemanticQuery.js";
|
||||
import { analyzeJavaScriptSemantics } from "../domain/javascriptSemanticAnalysis.js";
|
||||
import {
|
||||
DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS,
|
||||
type JavaScriptSemanticLimits,
|
||||
} from "../domain/javascriptSemanticIr.js";
|
||||
|
||||
const SHA256 = "a".repeat(64);
|
||||
const GRAPH_ID = `jag_${"b".repeat(64)}`;
|
||||
@@ -270,10 +266,7 @@ const emptyAnalysis = (): JavaScriptArtifactAnalysis => ({
|
||||
limitations: [],
|
||||
});
|
||||
|
||||
const graphFor = (
|
||||
source: string,
|
||||
inputLimits: Partial<JavaScriptSemanticLimits> = {},
|
||||
) => {
|
||||
const graphFor = (source: string) => {
|
||||
const file: JavaScriptArtifactFile = {
|
||||
path: "app.js",
|
||||
container_sha256: SHA256,
|
||||
@@ -284,18 +277,13 @@ const graphFor = (
|
||||
unpacked: false,
|
||||
text: { included: true, value: source },
|
||||
};
|
||||
const semanticLimits = {
|
||||
...DEFAULT_JAVASCRIPT_SEMANTIC_LIMITS,
|
||||
...inputLimits,
|
||||
};
|
||||
const analysis: JavaScriptArtifactAnalysis = {
|
||||
files: [
|
||||
{
|
||||
file,
|
||||
javascript: null,
|
||||
semantic: {
|
||||
ir: analyzeJavaScriptSemantics(source, inputLimits),
|
||||
limits: semanticLimits,
|
||||
ir: analyzeJavaScriptSemantics(source),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user