Canonicalize source checkout line endings

This commit is contained in:
Meta Vens 2026-08-30 23:21:47 +02:00
commit b8e377278a
2 changed files with 9 additions and 5 deletions

View file

@ -433,11 +433,15 @@ function comparableFields(document: ArchivedSourceDocumentRecord): Record<string
path: document.path,
language: document.language,
title: document.title,
content: document.content,
content: canonicalizeLineEndings(document.content),
metadata: document.metadata ?? {},
};
}
function canonicalizeLineEndings(content: string): string {
return content.replace(/\r\n?/g, "\n");
}
function compareDocuments(
left: ArchivedSourceDocumentRecord,
right: ArchivedSourceDocumentRecord,

View file

@ -25,16 +25,16 @@ async function main(): Promise<void> {
try {
const archive = new FileSourceDocumentArchiveRepository(archivePath);
const original = document("original body", "2026-06-03T00:00:00.000Z");
const original = document("original\r\nbody", "2026-06-03T00:00:00.000Z");
const updated = document("updated body", "2026-08-30T00:00:00.000Z");
await archive.syncRepoDocuments("Fixture", [original]);
const timestampOnlyPlan = await archive.planRepoDocuments(
"Fixture",
[document("original body", "2026-08-30T00:00:00.000Z")],
[document("original\nbody", "2026-08-30T00:00:00.000Z")],
);
assertEqual(timestampOnlyPlan.changedSourceIds.length, 0, "checkout timestamp changed document identity");
assertEqual(timestampOnlyPlan.unchanged, 1, "checkout timestamp did not remain observational");
assertEqual(timestampOnlyPlan.changedSourceIds.length, 0, "checkout metadata changed document identity");
assertEqual(timestampOnlyPlan.unchanged, 1, "checkout timestamp and line endings did not remain observational");
const failingPipeline = new SourceRagPipeline(
archive,