Repository navigation
Expand file tree
/
Copy pathjavascriptExportShapeComparisonSchemas.test.ts
More file actions
105 lines (100 loc) · 2.65 KB
/
Copy pathjavascriptExportShapeComparisonSchemas.test.ts
File metadata and controls
105 lines (100 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { expect, it } from "vitest";
import {
javaScriptExportShapeComparisonChangeSchema,
projectedExportReturnShapesSchema,
} from "./javascriptExportShapeComparisonSchemas.js";
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);
});