Public: anyone can read this; the crew can change it.
Full suite red: test/flow-alarm-drift.test.ts #12852
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12839-full-suite-red-test-flow-alarm-drift-tes → main 1 commit fork
1 file
changed +15
−7
test/flow-alarm-drift.test.ts +15 −7
| @@ -51,6 +51,17 @@ test("by hours: past 6 h fires; says the three most behind", () => { | ||
| 51 | 51 | expect(driftAlarm([], NOW)).toEqual({ fired: false, says: "No open pull is drifting from main." }); |
| 52 | 52 | }); |
| 53 | 53 | |
| 54 | /** Land n commits on main in one git process; the same as n pushes for what drift reads. */ | |
| 55 | async function landMany(dir: string, n: number, tag: string): Promise<void> { | |
| 56 | let input = ""; | |
| 57 | for (let i = 0; i < n; i++) { | |
| 58 | const body = "x\n"; | |
| 59 | input += `commit refs/heads/main\ncommitter t <t@t> ${Math.floor(Date.now() / 1000)} +0000\ndata ${tag.length + String(i).length}\n${tag}${i}\n${i === 0 ? "from refs/heads/main^0\n" : ""}M 100644 inline ${tag}${i}.txt\ndata ${body.length}\n${body}\n`; | |
| 60 | } | |
| 61 | const p = Bun.spawn(["git", "fast-import", "--quiet"], { cwd: dir, stdin: new Blob([input]), stdout: "ignore", stderr: "pipe" }); | |
| 62 | if ((await p.exited) !== 0) throw new Error(await new Response(p.stderr).text()); | |
| 63 | } | |
| 64 | ||
| 54 | 65 | let dataDir: string; |
| 55 | 66 | let app: App; |
| 56 | 67 | |
| @@ -69,10 +80,9 @@ test("read from git: landings past a pull's base, open pulls only", async () => | ||
| 69 | 80 | const repo = ok(await createRepo(app.db, app.reposRoot, { ownerId: ada.id, name: "svc", visibility: "public" })); |
| 70 | 81 | const dir = repoDir(app.reposRoot, ada.username, repo.name); |
| 71 | 82 | const land = async (n: number) => { |
| 72 | for (let i = 0; i < n; i++) | |
| 73 | ok(await commitToBranch(app, ada, repo, { message: `m${i}`, files: [{ path: `f${Math.random()}.txt`, content: "x\n" }] })); | |
| 83 | await landMany(dir, n, `m${Math.random().toString(36).slice(2)}`); | |
| 74 | 84 | }; |
| 75 | await land(1); | |
| 85 | ok(await commitToBranch(app, ada, repo, { message: "seed", files: [{ path: "seed.txt", content: "x\n" }] })); | |
| 76 | 86 | const branch = (b: string) => |
| 77 | 87 | commitToBranch(app, ada, repo, { message: b, branch: b, files: [{ path: `${b}.txt`, content: "x\n" }] } as any); |
| 78 | 88 | ok(await branch("one")); |
| @@ -122,8 +132,7 @@ test("a rebased head stops counting; a merged pull never counts", async () => { | ||
| 122 | 132 | ok(await commitToBranch(app, ada, repo, { message: "seed", files: [{ path: "a.txt", content: "a\n" }] })); |
| 123 | 133 | ok(await commitToBranch(app, ada, repo, { message: "w", branch: "work", files: [{ path: "w.txt", content: "w\n" }] } as any)); |
| 124 | 134 | const pull = ok(await createPull(app.db, dir, { repoId: repo.id, authorId: ada.id, title: "w", baseBranch: "main", headBranch: "work" })); |
| 125 | for (let i = 0; i < 26; i++) | |
| 126 | ok(await commitToBranch(app, ada, repo, { message: `m${i}`, files: [{ path: `g${i}.txt`, content: "x\n" }] })); | |
| 135 | await landMany(dir, 26, "g"); | |
| 127 | 136 | expect((await alarmDrift(app, new Date())).fired).toBe(true); |
| 128 | 137 | // Merge main into the head and tell the pull, as a push does. |
| 129 | 138 | const merged = await git("commit-tree", "main^{tree}", "-p", "work", "-p", "main", "-m", "merge main"); |
| @@ -132,8 +141,7 @@ test("a rebased head stops counting; a merged pull never counts", async () => { | ||
| 132 | 141 | app.db.query("UPDATE pull SET head_oid = ?1 WHERE issue_id = ?2").run(merged, pull.id); |
| 133 | 142 | expect((await alarmDrift(app, new Date())).fired).toBe(false); |
| 134 | 143 | // Behind again, but merged: never counts. |
| 135 | for (let i = 0; i < 26; i++) | |
| 136 | ok(await commitToBranch(app, ada, repo, { message: `n${i}`, files: [{ path: `h${i}.txt`, content: "x\n" }] })); | |
| 144 | await landMany(dir, 26, "h"); | |
| 137 | 145 | expect((await alarmDrift(app, new Date())).fired).toBe(true); |
| 138 | 146 | app.db.query("UPDATE pull SET merged_at = ?1 WHERE issue_id = ?2").run(new Date().toISOString(), pull.id); |
| 139 | 147 | expect((await alarmDrift(app, new Date())).fired).toBe(false); |
new above
offline