mirror of
https://github.com/morluto/rea.git
synced 2026-10-26 17:35:11 +00:00
fix: preserve unknown JSON omission counts (#5905)
* fix: preserve unknown JSON omission counts * fix: preserve unknown counts for unselected JSON * fix: preserve unknown counts for uppercase JSON
This commit is contained in:
1 parent
37cbeff9f3
commit
c717c8a3ec
2 files changed
+134
-1
No files matched your search
@@ -612,7 +612,12 @@ const createFileTarget = (
|
||||
javascript?.parse_status ?? (skipped ? "skipped" : null),
|
||||
json_parse_status: json?.status ?? null,
|
||||
json_top_level_keys: json?.top_level_keys ?? [],
|
||||
omitted_json_top_level_keys: json?.omitted_top_level_keys ?? 0,
|
||||
omitted_json_top_level_keys:
|
||||
json === undefined
|
||||
? file.kind === "json" || file.kind === "package-json"
|
||||
? null
|
||||
: 0
|
||||
: json.omitted_top_level_keys,
|
||||
vendor_markers: javascript?.vendors ?? [],
|
||||
},
|
||||
evidence: artifactObservationEvidence({
|
||||
|
||||
@@ -124,3 +124,131 @@ it("uses the first structured observation when paths repeat", async () => {
|
||||
await reader.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves unknown omitted-key count for unavailable JSON", async () => {
|
||||
const root = await createTestTempDirectory("rea-unavailable-json-");
|
||||
await Promise.all([
|
||||
writeFile(join(root, "package.json"), JSON.stringify({ name: "fixture" })),
|
||||
writeFile(join(root, "config.json"), Buffer.from([0xff])),
|
||||
]);
|
||||
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
|
||||
try {
|
||||
const files = await readJavaScriptArtifactFiles(reader, snapshot);
|
||||
const analysis = analyzeJavaScriptArtifactFiles(files);
|
||||
const graph = buildJavaScriptArtifactGraph(snapshot, files, analysis);
|
||||
|
||||
const configFile = graph.nodes.find(({ observations }) =>
|
||||
observations.some(
|
||||
({ properties }) =>
|
||||
properties.path === "config.json" && properties.file_kind === "json",
|
||||
),
|
||||
);
|
||||
|
||||
const configObservation = configFile?.observations.find(
|
||||
({ properties }) =>
|
||||
properties.path === "config.json" && properties.file_kind === "json",
|
||||
);
|
||||
|
||||
expect(configObservation?.properties).toMatchObject({
|
||||
path: "config.json",
|
||||
text_status: "invalid-utf8",
|
||||
json_parse_status: "unavailable",
|
||||
omitted_json_top_level_keys: null,
|
||||
});
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves unknown omitted-key count for unselected JSON", async () => {
|
||||
const root = await createTestTempDirectory("rea-unselected-json-");
|
||||
|
||||
await Promise.all([
|
||||
writeFile(join(root, "package.json"), JSON.stringify({ name: "fixture" })),
|
||||
writeFile(join(root, "config.json"), JSON.stringify({ setting: true })),
|
||||
]);
|
||||
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
|
||||
try {
|
||||
const files = await readJavaScriptArtifactFiles(
|
||||
reader,
|
||||
snapshot,
|
||||
undefined,
|
||||
["package.json"],
|
||||
);
|
||||
|
||||
const analysis = analyzeJavaScriptArtifactFiles(files);
|
||||
const graph = buildJavaScriptArtifactGraph(snapshot, files, analysis);
|
||||
|
||||
const configFile = graph.nodes.find(({ observations }) =>
|
||||
observations.some(
|
||||
({ properties }) =>
|
||||
properties.path === "config.json" && properties.file_kind === "json",
|
||||
),
|
||||
);
|
||||
|
||||
const configObservation = configFile?.observations.find(
|
||||
({ properties }) =>
|
||||
properties.path === "config.json" && properties.file_kind === "json",
|
||||
);
|
||||
|
||||
expect(configObservation?.properties).toMatchObject({
|
||||
path: "config.json",
|
||||
text_status: "outside-analysis-scope",
|
||||
json_parse_status: null,
|
||||
omitted_json_top_level_keys: null,
|
||||
});
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves unknown omitted-key count for unselected uppercase JSON", async () => {
|
||||
const root = await createTestTempDirectory("rea-unselected-uppercase-json-");
|
||||
|
||||
await Promise.all([
|
||||
writeFile(join(root, "package.json"), JSON.stringify({ name: "fixture" })),
|
||||
writeFile(join(root, "config.JSON"), JSON.stringify({ setting: true })),
|
||||
]);
|
||||
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
|
||||
try {
|
||||
const files = await readJavaScriptArtifactFiles(
|
||||
reader,
|
||||
snapshot,
|
||||
undefined,
|
||||
["package.json"],
|
||||
);
|
||||
|
||||
const analysis = analyzeJavaScriptArtifactFiles(files);
|
||||
const graph = buildJavaScriptArtifactGraph(snapshot, files, analysis);
|
||||
|
||||
const configFile = graph.nodes.find(({ observations }) =>
|
||||
observations.some(
|
||||
({ properties }) =>
|
||||
properties.path === "config.JSON" && properties.file_kind === "json",
|
||||
),
|
||||
);
|
||||
|
||||
const configObservation = configFile?.observations.find(
|
||||
({ properties }) =>
|
||||
properties.path === "config.JSON" && properties.file_kind === "json",
|
||||
);
|
||||
|
||||
expect(configObservation?.properties).toMatchObject({
|
||||
path: "config.JSON",
|
||||
text_status: "outside-analysis-scope",
|
||||
json_parse_status: null,
|
||||
omitted_json_top_level_keys: null,
|
||||
});
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user