Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

repair-flywheel.test.ts

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

repair-flywheel.test.tsBlame101 lines · 1 contributor
e6bad81Claude1/**
2 * Tests for the deterministic parts of the flywheel: failure normalisation
3 * and fingerprinting. The DB-touching functions are exercised in higher-
4 * level integration tests against a live Postgres.
5 *
6 * Goal: prove that failures with the same root cause but different variable
7 * bits (line numbers, paths, timestamps, hashes) collapse to the same
8 * signature. That's the property that makes the cache work.
9 */
10import { describe, expect, it } from "bun:test";
11import { fingerprint, normaliseFailure } from "../lib/repair-flywheel";
12
13describe("normaliseFailure", () => {
14 it("strips line + column numbers", () => {
15 const a = normaliseFailure("Error at /opt/app/src/foo.ts:42:13");
16 const b = normaliseFailure("Error at /opt/app/src/foo.ts:1099:7");
17 expect(a).toBe(b);
18 });
19
20 it("strips ISO-8601 timestamps", () => {
21 const a = normaliseFailure("Failed at 2026-05-08T22:14:15.123Z");
22 const b = normaliseFailure("Failed at 2025-01-01T00:00:00Z");
23 expect(a).toBe(b);
24 });
25
26 it("strips full SHA-1 commit hashes", () => {
27 const a = normaliseFailure("revert b0a3ba2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f80");
28 const b = normaliseFailure("revert deadbeefcafebabedeadbeefcafebabedeadbeef");
29 expect(a).toBe(b);
30 });
31
32 it("strips UUIDs", () => {
33 const a = normaliseFailure(
34 "request-id 550e8400-e29b-41d4-a716-446655440000 failed",
35 );
36 const b = normaliseFailure(
37 "request-id 6ba7b810-9dad-11d1-80b4-00c04fd430c8 failed",
38 );
39 expect(a).toBe(b);
40 });
41
42 it("strips absolute paths on linux + windows", () => {
43 const a = normaliseFailure("ENOENT /home/runner/work/foo/bar.ts");
44 const b = normaliseFailure("ENOENT /tmp/runner/zzz/bar.ts");
45 const c = normaliseFailure("ENOENT C:\\Users\\runner\\bar.ts");
46 expect(a).toBe(b);
47 expect(a).toBe(c);
48 });
49
50 it("strips ANSI colour codes", () => {
51 const a = normaliseFailure("\x1b[31merror:\x1b[0m lockfile mismatch");
52 const b = normaliseFailure("error: lockfile mismatch");
53 expect(a).toBe(b);
54 });
55
56 it("strips quoted strings (often contain user data)", () => {
57 const a = normaliseFailure(`expected 'alice@example.com' to match pattern`);
58 const b = normaliseFailure(`expected 'bob@other.com' to match pattern`);
59 expect(a).toBe(b);
60 });
61
62 it("collapses whitespace + lowercases", () => {
63 const a = normaliseFailure("ERROR: Lockfile out of sync");
64 const b = normaliseFailure("error: lockfile out of sync");
65 expect(a).toBe(b);
66 });
67
68 it("does NOT collapse genuinely different errors", () => {
69 const a = normaliseFailure("error: lockfile is out of sync");
70 const b = normaliseFailure("TypeError: cannot read property of undefined");
71 expect(a).not.toBe(b);
72 });
73});
74
75describe("fingerprint", () => {
76 it("produces a 32-char hex string", () => {
77 const sig = fingerprint("any failure text");
78 expect(sig).toMatch(/^[0-9a-f]{32}$/);
79 });
80
81 it("is stable across calls", () => {
82 const text = "error: bun install failed: lockfile mismatch at line 42";
83 expect(fingerprint(text)).toBe(fingerprint(text));
84 });
85
86 it("collapses semantically-identical failures to one signature", () => {
87 const a = fingerprint(
88 "TypeError at /home/runner/work/proj/src/foo.ts:42:13 in commit b0a3ba2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f80",
89 );
90 const b = fingerprint(
91 "TypeError at /tmp/build/x/src/foo.ts:9999:1 in commit deadbeefcafebabedeadbeefcafebabedeadbeef",
92 );
93 expect(a).toBe(b);
94 });
95
96 it("differs for genuinely different failures", () => {
97 const a = fingerprint("error: lockfile is out of sync");
98 const b = fingerprint("TypeError: cannot read property of undefined");
99 expect(a).not.toBe(b);
100 });
101});