Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

34 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { readFileSync, readdirSync } from "node:fs";
3import { DatabaseSync } from "node:sqlite";
4import { test } from "node:test";
5
6const dir = new URL("../migrations/", import.meta.url);
7const MIGRATION = "0008_work_item_cards.sql";
8
9test("cards kept about issues are about work items after the migration, run once or twice", () => {
10 const db = new DatabaseSync(":memory:");
11 for (const file of readdirSync(dir).sort()) {
12 if (file >= MIGRATION) break;
13 db.exec(readFileSync(new URL(file, dir), "utf8"));
14 }
15 db.exec("INSERT INTO channels (id, workspace_id, kind, name, created_by, created_at) VALUES ('chn_1', 'wsp_1', 'channel', 'general', 'g1t', 'now')");
16 const insert = db.prepare("INSERT INTO messages (id, channel_id, author, kind, body, card, created_at) VALUES (?, 'chn_1', 'g1t', ?, '', ?, 'now')");
17 insert.run("msg_1", "card", JSON.stringify({ kind: "issue", title: "Header", detail: null, state: "Open", href: null }));
18 insert.run("msg_2", "card", JSON.stringify({ kind: "draft_issue", title: "Draft", detail: null, state: "Draft", href: null }));
19 insert.run("msg_3", "card", JSON.stringify({ kind: "pull", title: "Fix", detail: null, state: null, href: null }));
20 insert.run("msg_4", "text", null);
21 const sql = readFileSync(new URL(MIGRATION, dir), "utf8");
22 db.exec(sql);
23 db.exec(sql);
24 const kinds = db.prepare("SELECT id, json_extract(card, '$.kind') AS kind, json_extract(card, '$.title') AS title FROM messages ORDER BY id").all();
25 assert.deepEqual(
26 kinds.map((row) => [row.id, row.kind, row.title]),
27 [
28 ["msg_1", "work_item", "Header"],
29 ["msg_2", "draft_work_item", "Draft"],
30 ["msg_3", "pull", "Fix"],
31 ["msg_4", null, null],
32 ],
33 );
34});