Release Healer Man 0.1.43

This commit is contained in:
phenom committed 2026-09-14 13:20:20 -04:00
1 parent c7e8163790
commit ccc01396cd
86 files changed
+2951 -198

No files matched your search

+43 -3
View File
@@ -19,11 +19,22 @@ export function createDungeonReportRepository(database, { isGameMaster, ErrorTyp
revision INTEGER NOT NULL DEFAULT 0
) STRICT;
CREATE INDEX IF NOT EXISTS dungeon_reports_dungeon_status_idx ON dungeon_reports(dungeon_id, status);
CREATE TABLE IF NOT EXISTS boss_testing_reviews (
boss_key TEXT PRIMARY KEY,
dungeon_id TEXT NOT NULL,
boss_name TEXT NOT NULL,
status TEXT NOT NULL CHECK (status IN ('ready', 'needs-testing', 'not-ready')),
reviewed_by TEXT NOT NULL,
reviewed_at INTEGER NOT NULL
) STRICT;
`);
const columns = new Set(database.prepare("PRAGMA table_info(dungeon_reports)").all().map((column) => column.name));
if (!columns.has("boss_key")) database.exec("ALTER TABLE dungeon_reports ADD COLUMN boss_key TEXT");
if (!columns.has("boss_name")) database.exec("ALTER TABLE dungeon_reports ADD COLUMN boss_name TEXT");
const insert = database.prepare(`
INSERT INTO dungeon_reports (
id, dungeon_id, comment, status, submitted_by_account_id, submitted_by_username, created_at, updated_at
) VALUES (?, ?, ?, 'Submitted', ?, ?, ?, ?)
id, dungeon_id, comment, status, submitted_by_account_id, submitted_by_username, created_at, updated_at, boss_key, boss_name
) VALUES (?, ?, ?, 'Submitted', ?, ?, ?, ?, ?, ?)
`);
const byId = database.prepare("SELECT * FROM dungeon_reports WHERE id = ?");
const list = database.prepare(`
@@ -45,6 +56,14 @@ export function createDungeonReportRepository(database, { isGameMaster, ErrorTyp
function validateStatus(status) {
if (!policy.statuses.includes(status)) throw new ErrorType("Choose a valid report status.", 400, "invalid_report_status");
}
function validateBoss(input) {
validateDungeon(input?.dungeonId);
if (typeof input.bossKey !== "string" || !input.bossKey.startsWith(`${input.dungeonId}/`)
|| input.bossKey.length <= input.dungeonId.length + 1 || input.bossKey.length > 256
|| typeof input.bossName !== "string" || !input.bossName.trim() || input.bossName.length > 128) {
throw new ErrorType("Choose a valid boss.", 400, "invalid_boss");
}
}
function publicReport(row) {
return {
id: row.id,
@@ -56,10 +75,30 @@ export function createDungeonReportRepository(database, { isGameMaster, ErrorTyp
updatedAt: Number(row.updated_at),
updatedBy: row.updated_by_username,
revision: Number(row.revision),
...(row.boss_key ? { bossKey: row.boss_key, bossName: row.boss_name } : {}),
};
}
return {
listBossTestingReviews() {
return { reviews: database.prepare("SELECT * FROM boss_testing_reviews ORDER BY boss_key").all().map((row) => ({
bossKey: row.boss_key, dungeonId: row.dungeon_id, bossName: row.boss_name,
status: row.status, reviewedBy: row.reviewed_by, reviewedAt: Number(row.reviewed_at),
})) };
},
saveBossTestingReview(account, input) {
validateBoss(input);
if (!["ready", "needs-testing", "not-ready"].includes(input.status)) {
throw new ErrorType("Choose a valid boss readiness status.", 400, "invalid_boss_status");
}
const review = { bossKey: input.bossKey, dungeonId: input.dungeonId, bossName: input.bossName.trim(),
status: input.status, reviewedBy: account?.username ?? "Guest player", reviewedAt: Date.now() };
database.prepare(`INSERT INTO boss_testing_reviews VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(boss_key) DO UPDATE SET boss_name = excluded.boss_name, status = excluded.status,
reviewed_by = excluded.reviewed_by, reviewed_at = excluded.reviewed_at`).run(
review.bossKey, review.dungeonId, review.bossName, review.status, review.reviewedBy, review.reviewedAt);
return review;
},
listDungeonReports({ status = null, dungeonId = null } = {}) {
if (status !== null) validateStatus(status);
if (dungeonId !== null) validateDungeon(dungeonId);
@@ -70,13 +109,14 @@ export function createDungeonReportRepository(database, { isGameMaster, ErrorTyp
},
submitDungeonReport(account, input) {
validateDungeon(input?.dungeonId);
if (input?.bossKey !== undefined || input?.bossName !== undefined) validateBoss(input);
if (typeof input?.comment !== "string" || !input.comment.trim() || input.comment.length > policy.commentMaxLength) {
throw new ErrorType("Describe the issue in 1-500 characters.", 400, "invalid_report_comment");
}
const id = randomUUID();
const now = Date.now();
insert.run(id, input.dungeonId, input.comment.replace(/\r\n?/g, "\n").trim(), account?.id ?? null,
account?.username ?? "Guest player", now, now);
account?.username ?? "Guest player", now, now, input.bossKey ?? null, input.bossName?.trim() ?? null);
return publicReport(byId.get(id));
},
updateDungeonReport(account, id, input) {
+29
View File
@@ -69,6 +69,30 @@ test("persists reports and status changes across database restarts", async () =>
} finally { database?.close(); rmSync(directory, { recursive: true, force: true }); }
});
test("persists boss readiness and structured boss reports without changing ordinary reports", async () => {
const directory = mkdtempSync(path.join(os.tmpdir(), "healer-man-boss-feedback-"));
let database;
try {
database = openGameDatabase({ dataDir: directory });
const boss = { dungeonId: "wailing-caverns", bossKey: "wailing-caverns/lady-anacondra", bossName: "Lady Anacondra" };
for (const status of ["ready", "needs-testing", "not-ready"]) {
assert.equal(database.saveBossTestingReview(null, { ...boss, status }).status, status);
}
assert.throws(() => database.saveBossTestingReview(null, { ...boss, status: "Closed" }), { code: "invalid_boss_status" });
assert.throws(() => database.saveBossTestingReview(null, { ...boss, bossKey: "other/boss", status: "ready" }), { code: "invalid_boss" });
const report = database.submitDungeonReport(null, { ...boss, comment: "x".repeat(500) });
assert.equal(report.bossKey, boss.bossKey);
assert.equal(report.bossName, boss.bossName);
const reviews = database.listBossTestingReviews();
database.close();
database = openGameDatabase({ dataDir: directory });
assert.deepEqual(database.listBossTestingReviews(), reviews);
assert.deepEqual(database.listDungeonReports().reports, [report]);
const ordinary = database.submitDungeonReport(null, { dungeonId: boss.dungeonId, comment: "Door issue" });
assert.equal(ordinary.bossKey, undefined);
} finally { database?.close(); rmSync(directory, { recursive: true, force: true }); }
});
test("serves public reports and GM-only status API with shelved modes disabled", async () => {
const directory = mkdtempSync(path.join(os.tmpdir(), "healer-man-report-api-"));
const runtime = createGameServer({ dataDir: directory, enableShelvedModes: false });
@@ -80,6 +104,11 @@ test("serves public reports and GM-only status API with shelved modes disabled",
});
try {
const player = await runtime.database.register("ApiPlayer", "report-player");
const boss = { dungeonId: "wailing-caverns", bossKey: "wailing-caverns/lady-anacondra", bossName: "Lady Anacondra", status: "ready" };
const saved = await fetch(`${origin}/api/boss-testing/reviews`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(boss) });
assert.equal(saved.status, 200);
const labels = await (await fetch(`${origin}/api/boss-testing/reviews`)).json();
assert.equal(labels.reviews[0].status, "ready");
const gm = await runtime.database.register("Phenom", "report-admin");
const created = await request("", "POST", { dungeonId: "stormwind-stockade", comment: "Issue via API" }, player.token);
assert.equal(created.status, 201);
+13
View File
@@ -261,6 +261,19 @@ export function createGameServer(options = {}) {
json(response, 200, gameDatabase.getDungeonRun(dungeonRunMatch[1]));
return;
}
if (url.pathname === "/api/boss-testing/reviews" && request.method === "GET") {
json(response, 200, gameDatabase.listBossTestingReviews());
return;
}
if (url.pathname === "/api/boss-testing/reviews" && request.method === "POST") {
const token = bearerToken(request);
const account = token ? gameDatabase.authenticate(token) : null;
if (!allowReportRequest(account?.id ?? request.socket.remoteAddress)) {
throw new GameDatabaseError("Too many updates. Please wait a minute and try again.", 429, "rate_limited");
}
json(response, 200, { review: gameDatabase.saveBossTestingReview(account, await readJson(request, 8 * 1024)) });
return;
}
if (url.pathname === "/api/dungeon-reports" && request.method === "GET") {
json(response, 200, gameDatabase.listDungeonReports({
status: url.searchParams.get("status"),