Files
rea/src/domain/javascript/javascriptExportShapeComparisonSchemas.test.ts
T
morluto b58adafa4f fix(javascript): align module lookup and source evidence
Preserve CommonJS literal paths and confined ESM URL semantics, including package main fallback, directory intent, Unicode identity, and present opaque modules. Parse extraction inputs at their AST/source owner, retain skipped HTML and source-map coverage, and distinguish endpoint candidates from proven receiver facts. Version structural fingerprints with computed literal contents and propagate them through worker contracts.

Reviewed fixes include #1810, #1840, #2642, #2700, #2702, #2714, #2803, #2960, #2968, #2986, #3035, and #3036.

Validation: 158 resolver tests passed; public CLI/MCP module lookup controls, package-main/Unicode workflows, and six builtin workflows passed in the current compiled lane. Worker schema/fingerprint regressions passed. Large public pdf.js completion and real Electron analysis remain unverified.
2026-10-14 08:46:50 +08:00

127 lines
3.2 KiB
TypeScript

import { expect, it } from "vitest";
import {
compareJavaScriptExportShapesInputSchema,
javaScriptExportShapeComparisonChangeSchema,
projectedExportReturnShapesSchema,
} from "./javascriptExportShapeComparisonSchemas.js";
it("accepts exact empty export names in selectors and projections", () => {
expect(
compareJavaScriptExportShapesInputSchema.shape.left_export_name.safeParse(
"",
).success,
).toBe(true);
expect(
projectedExportReturnShapesSchema.safeParse({
...projectionWithField({
path: "/kind",
presence: "present",
state: "literal",
value: "ok",
reason: null,
}),
exported_name: "",
}).success,
).toBe(true);
});
const projectionWithField = (field: unknown) => ({
semantic_role: "export-return-shapes",
module_path: "index.js",
exported_name: "render",
callable_id: "callable:render",
callable_kind: "function",
static_return_shapes: [
{
source_range: {
start: { line: 1, column: 0 },
end: { line: 1, column: 10 },
},
value_status: "unknown",
fields: [field],
property_coverage: [],
},
],
return_shape_coverage: {
status: "partial",
retained_return_sites: 1,
omitted_return_sites: null,
omitted_fields: 0,
omitted_property_coverage: 0,
projection_complete: true,
},
});
it("rejects a comparison change object missing presence", () => {
const digest = "a".repeat(64);
const change = {
change_id: `jesc_change_${digest}`,
status: "added",
path: "/total",
discriminant: { path: "/kind", value: "results" },
left: { availability: "absent" },
right: {
availability: "unknown",
reason: "Static field value is unknown.",
},
left_source_range: {
start: { line: 4, column: 9 },
end: { line: 4, column: 48 },
},
right_source_range: {
start: { line: 4, column: 9 },
end: { line: 4, column: 62 },
},
evidence_links: [`ev_${digest}`, `ev_${"b".repeat(64)}`],
limitations: [],
};
expect(
javaScriptExportShapeComparisonChangeSchema.safeParse(change).success,
).toBe(false);
expect(
javaScriptExportShapeComparisonChangeSchema.safeParse({
...change,
presence: { left: "absent", right: "present" },
}).success,
).toBe(true);
});
it("parses projected fields into literal, union, or unknown values", () => {
expect(
projectedExportReturnShapesSchema.safeParse(
projectionWithField({
path: "/kind",
presence: "present",
state: "unknown",
value: "invented",
reason: "Dynamic property",
}),
).success,
).toBe(false);
expect(
projectedExportReturnShapesSchema.safeParse(
projectionWithField({
path: "/kind",
presence: "present",
state: "union",
value: ["success", "failure"],
reason: null,
}),
).success,
).toBe(true);
});
it("rejects return fields that omit slot presence", () => {
expect(
projectedExportReturnShapesSchema.safeParse(
projectionWithField({
path: "/kind",
state: "literal",
value: "result",
reason: null,
}),
).success,
).toBe(false);
});