ci: add pull request quality gates
CI / install-and-build (pull_request) Successful in 1m29s
CI / format (pull_request) Successful in 51s
CI / typecheck-source (pull_request) Successful in 41s
CI / typecheck-tests (pull_request) Successful in 39s
CI / test (pull_request) Successful in 51s
CI / lint (pull_request) Successful in 21s

Co-Authored-By: gpt-5.6-terra <noreply@openai.com>
This commit was merged in pull request #12.
This commit is contained in:
2026-07-22 21:50:29 +00:00
co-authored by Codex
parent b9fa79ff1f
commit 31d4636dde
80 changed files with 2007 additions and 398 deletions
+27 -12
View File
@@ -1,12 +1,15 @@
import { describe, it, before, after } from "node:test";
import assert from "node:assert/strict";
import type { DbInterface } from "../../src/db/types/DbInterface.js";
import { NotFoundAbodeError, InvalidAbodeError } from "../../src/db/types/errors.js";
import {
NotFoundAbodeError,
InvalidAbodeError,
} from "../../src/db/types/errors.js";
import { hashPassword } from "../../src/util/hash.js";
export function runAbodeTests(
name: string,
getDb: () => Promise<{ db: DbInterface; close(): void }>
getDb: () => Promise<{ db: DbInterface; close(): void }>,
): void {
describe(`${name}: abodes`, async () => {
let db: DbInterface;
@@ -28,7 +31,10 @@ export function runAbodeTests(
after(() => close());
it("createAbode returns an Abode with expected fields", async () => {
const abode = await db.createAbode({ name: "Test Abode" }, { uid: ctxUid });
const abode = await db.createAbode(
{ name: "Test Abode" },
{ uid: ctxUid },
);
assert.ok(abode.aid, "has aid");
assert.equal(abode.name, "Test Abode");
assert.ok(abode.created_at);
@@ -36,7 +42,10 @@ export function runAbodeTests(
});
it("getAbodeById returns the created abode", async () => {
const created = await db.createAbode({ name: "ById Abode" }, { uid: ctxUid });
const created = await db.createAbode(
{ name: "ById Abode" },
{ uid: ctxUid },
);
const found = await db.getAbodeById(created.aid);
assert.equal(found.aid, created.aid);
assert.equal(found.name, "ById Abode");
@@ -48,14 +57,14 @@ export function runAbodeTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
it("listAbodes includes the created abode", async () => {
const created = await db.createAbode(
{ name: `Listed Abode ${Date.now()}` },
{ uid: ctxUid }
{ uid: ctxUid },
);
const abodes = await db.listAbodes();
assert.ok(Array.isArray(abodes));
@@ -67,32 +76,38 @@ export function runAbodeTests(
const created = await db.createAbode({ name: "Before" }, { uid: ctxUid });
const updated = await db.updateAbode(
{ aid: created.aid, name: "After" },
{ uid: ctxUid }
{ uid: ctxUid },
);
assert.equal(updated.aid, created.aid);
assert.equal(updated.name, "After");
});
it("updateAbode with no fields throws InvalidAbodeError", async () => {
const created = await db.createAbode({ name: "No Update" }, { uid: ctxUid });
const created = await db.createAbode(
{ name: "No Update" },
{ uid: ctxUid },
);
await assert.rejects(
() => db.updateAbode({ aid: created.aid }, { uid: ctxUid }),
(err) => {
assert.ok(err instanceof InvalidAbodeError);
return true;
}
},
);
});
it("deleteAbodeById removes the abode", async () => {
const created = await db.createAbode({ name: "To Delete" }, { uid: ctxUid });
const created = await db.createAbode(
{ name: "To Delete" },
{ uid: ctxUid },
);
await db.deleteAbodeById(created.aid);
await assert.rejects(
() => db.getAbodeById(created.aid),
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -102,7 +117,7 @@ export function runAbodeTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
});
+4 -4
View File
@@ -6,7 +6,7 @@ import { hashPassword } from "../../src/util/hash.js";
export function runApikeyTests(
name: string,
getDb: () => Promise<{ db: DbInterface; close(): void }>
getDb: () => Promise<{ db: DbInterface; close(): void }>,
): void {
describe(`${name}: apikeys`, async () => {
let db: DbInterface;
@@ -69,7 +69,7 @@ export function runApikeyTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -85,7 +85,7 @@ export function runApikeyTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -95,7 +95,7 @@ export function runApikeyTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
});
+15 -7
View File
@@ -11,7 +11,10 @@ import { hashPassword } from "../../src/util/hash.js";
export function runAuthTests(
name: string,
getDb: () => Promise<{ db: BackendDbInterface; close(): void }>,
createExpiredApikey?: (db: BackendDbInterface, uid: string) => Promise<`at_${string}`>
createExpiredApikey?: (
db: BackendDbInterface,
uid: string,
) => Promise<`at_${string}`>,
): void {
describe(`${name}: auth`, async () => {
let db: BackendDbInterface;
@@ -23,7 +26,12 @@ export function runAuthTests(
({ db, close } = await getDb());
email = `auth-user-${Date.now()}@test.example`;
const pw = await hashPassword(password);
await db.createUser({ email, name: "Auth User", password: pw, flags: {} });
await db.createUser({
email,
name: "Auth User",
password: pw,
flags: {},
});
});
after(() => close());
@@ -40,7 +48,7 @@ export function runAuthTests(
(err) => {
assert.ok(err instanceof NotAuthorizedAbodeError);
return true;
}
},
);
});
@@ -54,7 +62,7 @@ export function runAuthTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -71,7 +79,7 @@ export function runAuthTests(
(err) => {
assert.ok(err instanceof ConflictAbodeError);
return true;
}
},
);
});
});
@@ -118,7 +126,7 @@ export function runAuthTests(
(err) => {
assert.ok(err instanceof NotAuthorizedAbodeError);
return true;
}
},
);
});
@@ -129,7 +137,7 @@ export function runAuthTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
});
+21 -12
View File
@@ -1,12 +1,15 @@
import { describe, it, before, after } from "node:test";
import assert from "node:assert/strict";
import type { DbInterface } from "../../src/db/types/DbInterface.js";
import { NotFoundAbodeError, InvalidAbodeError } from "../../src/db/types/errors.js";
import {
NotFoundAbodeError,
InvalidAbodeError,
} from "../../src/db/types/errors.js";
import { hashPassword } from "../../src/util/hash.js";
export function runResidentTests(
name: string,
getDb: () => Promise<{ db: DbInterface; close(): void }>
getDb: () => Promise<{ db: DbInterface; close(): void }>,
): void {
describe(`${name}: residents`, async () => {
let db: DbInterface;
@@ -36,7 +39,7 @@ export function runResidentTests(
uid = resUser.uid;
const abode = await db.createAbode(
{ name: `Resident Abode ${Date.now()}` },
{ uid: ctxUid }
{ uid: ctxUid },
);
aid = abode.aid;
await db.createResident({ uid, aid, flags: {} }, { uid: ctxUid });
@@ -56,12 +59,12 @@ export function runResidentTests(
() =>
db.getResidentById(
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000001"
"00000000-0000-0000-0000-000000000001",
),
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -101,7 +104,7 @@ export function runResidentTests(
it("updateResident updates flags", async () => {
const updated = await db.updateResident(
{ uid, aid, flags: { admin: true } },
{ uid: ctxUid }
{ uid: ctxUid },
);
assert.equal(updated.uid, uid);
assert.deepEqual(updated.flags, { admin: true });
@@ -113,7 +116,7 @@ export function runResidentTests(
(err) => {
assert.ok(err instanceof InvalidAbodeError);
return true;
}
},
);
});
@@ -125,15 +128,21 @@ export function runResidentTests(
password: pw,
flags: {},
});
const abode2 = await db.createAbode({ name: "Del Abode" }, { uid: ctxUid });
await db.createResident({ uid: user2.uid, aid: abode2.aid, flags: {} }, { uid: ctxUid });
const abode2 = await db.createAbode(
{ name: "Del Abode" },
{ uid: ctxUid },
);
await db.createResident(
{ uid: user2.uid, aid: abode2.aid, flags: {} },
{ uid: ctxUid },
);
await db.deleteResidentById(user2.uid, abode2.aid);
await assert.rejects(
() => db.getResidentById(user2.uid, abode2.aid),
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -142,12 +151,12 @@ export function runResidentTests(
() =>
db.deleteResidentById(
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
"00000000-0000-0000-0000-000000000003",
),
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
});
+3 -3
View File
@@ -6,7 +6,7 @@ import { hashPassword } from "../../src/util/hash.js";
export function runSessionTests(
name: string,
getDb: () => Promise<{ db: BackendDbInterface; close(): void }>
getDb: () => Promise<{ db: BackendDbInterface; close(): void }>,
): void {
describe(`${name}: sessions`, async () => {
let db: BackendDbInterface;
@@ -46,7 +46,7 @@ export function runSessionTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -58,7 +58,7 @@ export function runSessionTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
});
+17 -9
View File
@@ -11,7 +11,7 @@ import { hashPassword } from "../../src/util/hash.js";
export function runUserTests(
name: string,
getDb: () => Promise<{ db: DbInterface; close(): void }>,
getReadonlyDb?: () => Promise<{ db: DbInterface; close(): void }>
getReadonlyDb?: () => Promise<{ db: DbInterface; close(): void }>,
): void {
describe(`${name}: users`, async () => {
let db: DbInterface;
@@ -57,13 +57,18 @@ export function runUserTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
it("getUserByEmail returns the created user", async () => {
const email = `user-byemail-${Date.now()}@test.example`;
await db.createUser({ email, name: "ByEmail User", password: hashedPw, flags: {} });
await db.createUser({
email,
name: "ByEmail User",
password: hashedPw,
flags: {},
});
const found = await db.getUserByEmail(email);
assert.ok("email" in found, "result includes email");
assert.equal(found.email, email);
@@ -75,7 +80,7 @@ export function runUserTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -100,7 +105,10 @@ export function runUserTests(
password: hashedPw,
flags: {},
});
const updated = await db.updateUser({ uid: created.uid, name: "After Update" });
const updated = await db.updateUser({
uid: created.uid,
name: "After Update",
});
assert.equal(updated.uid, created.uid);
assert.equal(updated.name, "After Update");
});
@@ -117,7 +125,7 @@ export function runUserTests(
(err) => {
assert.ok(err instanceof InvalidAbodeError);
return true;
}
},
);
});
@@ -134,7 +142,7 @@ export function runUserTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
@@ -144,7 +152,7 @@ export function runUserTests(
(err) => {
assert.ok(err instanceof NotFoundAbodeError);
return true;
}
},
);
});
});
@@ -178,7 +186,7 @@ export function runUserTests(
(err) => {
assert.ok(err instanceof ReadonlyAbodeError);
return true;
}
},
);
});
});