mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
test(reference): cover failure normalization
This commit is contained in:
@@ -67,6 +67,27 @@ const deduplicateRelationships = (
|
||||
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 = (
|
||||
options: ReferenceSourceImportOptions,
|
||||
): HistoricalSourceGraphInput["provenance"] => ({
|
||||
@@ -205,22 +226,7 @@ export const importReferenceSource = async (
|
||||
if (isAborted(options.signal)) return err(cancelled());
|
||||
|
||||
const uniqueRelationships = deduplicateRelationships(relationships);
|
||||
const uniqueFailures = [...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 uniqueFailures = normalizeHistoricalSourceParseFailures(parseFailures);
|
||||
|
||||
const sortedEntries = [...entries].sort((left, right) =>
|
||||
byCodePoint(left.path, right.path),
|
||||
|
||||
@@ -6,7 +6,10 @@ import { join } from "node:path";
|
||||
import { add, commit, init } from "isomorphic-git";
|
||||
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 {
|
||||
projectReferenceSourceImportError,
|
||||
@@ -52,6 +55,27 @@ const importTree = (
|
||||
});
|
||||
|
||||
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", () => {
|
||||
for (const [kind, code] of [
|
||||
["directory", "io"],
|
||||
|
||||
Reference in New Issue
Block a user