test(insights): write the status goldens with sorted keys

The goldens held their fields in the order the code assigned them. They are now written with every object's keys sorted, so the text depends only on content and diffs and compresses well; the parsed content of every golden is unchanged. They carry no clock reading or generated id: the clock is pinned and the ids are fixed.
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 13:42:58 +02:00
1 parent 4794cdec88
commit 905d4b167c
11 files changed
+13715 -13695

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -503,7 +503,27 @@ async function record(arms: Record<string, Arm>): Promise<string> {
notes: await storedNotes(),
};
}
return `${JSON.stringify(out, null, 2)}\n`;
return `${JSON.stringify(sortedKeys(out), null, 2)}\n`;
}
/**
* A copy with every object's keys in sorted order, so a golden's text does
* not depend on the order code happened to assign fields in and compresses
* and diffs well. Arrays keep their order: that is content.
*/
function sortedKeys(value: unknown): unknown {
if (Array.isArray(value)) return value.map(sortedKeys);
if (value && typeof value === "object" && !(value instanceof Date)) {
return Object.fromEntries(
Object.keys(value as Record<string, unknown>)
.sort()
.map((key) => [
key,
sortedKeys((value as Record<string, unknown>)[key]),
]),
);
}
return value;
}
function compareGolden(name: string, actual: string): void {