test(reference): cover failure normalization
This commit is contained in:
@@ -67,6 +67,27 @@ const deduplicateRelationships = (
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Sort parse failures deterministically while retaining distinct reasons. */
|
||||||
|
export const normalizeHistoricalSourceParseFailures = (
|
||||||
|
failures: HistoricalSourceGraphInput["parse_failures"],
|
||||||
|
): HistoricalSourceGraphInput["parse_failures"] =>
|
||||||
|
[...failures]
|
||||||
|
.sort((left, right) =>
|
||||||
|
byCodePoint(
|
||||||
|
historicalSourceParseFailureKey(left),
|
||||||
|
historicalSourceParseFailureKey(right),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.filter((value, index, array) => {
|
||||||
|
if (index === 0) return true;
|
||||||
|
const previous = array[index - 1];
|
||||||
|
return (
|
||||||
|
previous === undefined ||
|
||||||
|
historicalSourceParseFailureKey(value) !==
|
||||||
|
historicalSourceParseFailureKey(previous)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const buildProvenance = (
|
const buildProvenance = (
|
||||||
options: ReferenceSourceImportOptions,
|
options: ReferenceSourceImportOptions,
|
||||||
): HistoricalSourceGraphInput["provenance"] => ({
|
): HistoricalSourceGraphInput["provenance"] => ({
|
||||||
@@ -205,22 +226,7 @@ export const importReferenceSource = async (
|
|||||||
if (isAborted(options.signal)) return err(cancelled());
|
if (isAborted(options.signal)) return err(cancelled());
|
||||||
|
|
||||||
const uniqueRelationships = deduplicateRelationships(relationships);
|
const uniqueRelationships = deduplicateRelationships(relationships);
|
||||||
const uniqueFailures = [...parseFailures]
|
const uniqueFailures = normalizeHistoricalSourceParseFailures(parseFailures);
|
||||||
.sort((left, right) =>
|
|
||||||
byCodePoint(
|
|
||||||
historicalSourceParseFailureKey(left),
|
|
||||||
historicalSourceParseFailureKey(right),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.filter((value, index, array) => {
|
|
||||||
if (index === 0) return true;
|
|
||||||
const previous = array[index - 1];
|
|
||||||
if (previous === undefined) return true;
|
|
||||||
return (
|
|
||||||
historicalSourceParseFailureKey(value) !==
|
|
||||||
historicalSourceParseFailureKey(previous)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedEntries = [...entries].sort((left, right) =>
|
const sortedEntries = [...entries].sort((left, right) =>
|
||||||
byCodePoint(left.path, right.path),
|
byCodePoint(left.path, right.path),
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import { join } from "node:path";
|
|||||||
import { add, commit, init } from "isomorphic-git";
|
import { add, commit, init } from "isomorphic-git";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { importReferenceSource } from "../src/application/ReferenceSourceImport.js";
|
import {
|
||||||
|
importReferenceSource,
|
||||||
|
normalizeHistoricalSourceParseFailures,
|
||||||
|
} from "../src/application/ReferenceSourceImport.js";
|
||||||
import { projectReferenceSourceEntryFailure } from "../src/application/ReferenceSourceImportEntries.js";
|
import { projectReferenceSourceEntryFailure } from "../src/application/ReferenceSourceImportEntries.js";
|
||||||
import {
|
import {
|
||||||
projectReferenceSourceImportError,
|
projectReferenceSourceImportError,
|
||||||
@@ -52,6 +55,27 @@ const importTree = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("reference source import", () => {
|
describe("reference source import", () => {
|
||||||
|
it("deduplicates exact parse failures without collapsing distinct reasons", () => {
|
||||||
|
const malformed = {
|
||||||
|
path: "src/main.ts",
|
||||||
|
parser: "babel",
|
||||||
|
reason: "Malformed input",
|
||||||
|
};
|
||||||
|
const unexpected = {
|
||||||
|
path: "src/main.ts",
|
||||||
|
parser: "babel",
|
||||||
|
reason: "Unexpected token",
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(
|
||||||
|
normalizeHistoricalSourceParseFailures([
|
||||||
|
unexpected,
|
||||||
|
malformed,
|
||||||
|
unexpected,
|
||||||
|
]),
|
||||||
|
).toEqual([malformed, unexpected]);
|
||||||
|
});
|
||||||
|
|
||||||
it("projects entry failures without low-level reader diagnostics", () => {
|
it("projects entry failures without low-level reader diagnostics", () => {
|
||||||
for (const [kind, code] of [
|
for (const [kind, code] of [
|
||||||
["directory", "io"],
|
["directory", "io"],
|
||||||
|
|||||||
Reference in New Issue
Block a user