Files
2026-11-16 17:26:44 -08:00

87 lines
4.5 KiB
TypeScript

import "./setup_env";
import { describe, expect, test } from "bun:test";
import type { Task } from "../src/types";
import { enrichTaskLite, enrichTasksLite, enrichSecurityLite } from "../src/enrich";
// Empty watcher lists keep the enrichers off the database (both lookups return
// early on an empty key set), so these run against the closed test port.
const DRAWER_ONLY = [
// LIST_OMIT
"executionPlan", "description", "reproSteps", "remark", "regenContext", "reviewHistory",
"reviewFeedback", "attachments", "trackingImpact", "methodCoverage",
// BOARD_OMIT
"criticVerdict", "logPath", "evalLogPath", "beforeEvidencePath", "afterEvidencePath",
"workspacePath", "productProfile", "psms", "codeSidecars", "createdViaKeyId",
"commitAuthor",
];
function fullTask(over: Partial<Task> = {}): Task {
return {
id: "t1", meegoId: "123", meegoUrl: "https://meego/123", title: "a bug", status: "manual_review",
platform: "android", priorityKey: 1, pinned: 0, createdAt: 1, watchers: [], clusters: [],
mrState: null, mergedIntoBaseAt: null, readableReportGeneratedAt: 42, readableReportRound: 2,
description: "long…", executionPlan: "plan…", reproSteps: "steps…", remark: "r", regenContext: null,
reviewFeedback: null, attachments: null, methodCoverage: null,
reviewHistory: [
{ at: 1, source: "human", round: 1, text: "redo" },
{ at: 2, source: "critic", round: 1, text: "auto" },
{ at: 3, source: "human", round: 2, text: "again" },
],
trackingImpact: { verdict: "changed", files: [], removed: 0, added: 1, nearby: 0, eventKeys: [] },
criticVerdict: "PASS", logPath: "/l", evalLogPath: "/e", beforeEvidencePath: "/b", afterEvidencePath: "/a",
workspacePath: "/w", productProfile: null, psms: ["x"], codeSidecars: [],
createdViaKeyId: null, createdViaSource: null, externalId: null,
...over,
} as unknown as Task;
}
describe("board projection (lists + WS pushes)", () => {
test("a WS push carries no drawer-only field, and derives the card scalars from the full row", async () => {
const lean = await enrichTaskLite(fullTask()) as unknown as Record<string, unknown>;
for (const k of DRAWER_ONLY) expect(k in lean ? k : null).toBeNull();
expect(lean.humanRejects).toBe(2);
expect(lean.trackingVerdict).toBe("changed");
// surface fields the board and the report-freshness check rely on survive
expect(lean.status).toBe("manual_review");
expect(lean.readableReportGeneratedAt).toBe(42);
expect(lean.watcherLabels).toEqual({});
});
test("a list row uses the SQL-precomputed scalars instead of the (absent) JSON", async () => {
// What listTasksLite hands the enricher: no review/tracking JSON (rowToTask
// defaults them to []/null), scalars computed by the query.
const row = { ...fullTask(), reviewHistory: [], trackingImpact: null, humanRejects: 5, trackingVerdict: null } as unknown as Task;
const [lean] = await enrichTasksLite([row]) as unknown as Record<string, unknown>[];
expect(lean!.humanRejects).toBe(5);
expect(lean!.trackingVerdict).toBeNull();
for (const k of DRAWER_ONLY) expect(k in lean! ? k : null).toBeNull();
});
test("list row and WS push have the same key set", async () => {
const push = await enrichTaskLite(fullTask()) as unknown as Record<string, unknown>;
const [row] = await enrichTasksLite([{ ...fullTask(), humanRejects: 2, trackingVerdict: "changed" } as unknown as Task]);
expect(Object.keys(row as object).sort()).toEqual(Object.keys(push).sort());
});
test("the open-platform origin rides on the board: source + external id, not the key id", async () => {
// keyId null keeps the label lookup off the database; the label is null then.
const t = fullTask({ createdViaSource: "jira-crm", externalId: "CRM-1001" } as Partial<Task>);
const push = await enrichTaskLite(t) as unknown as Record<string, unknown>;
const [row] = await enrichTasksLite([t]) as unknown as Record<string, unknown>[];
for (const lean of [push, row!]) {
expect(lean.createdViaSource).toBe("jira-crm");
expect(lean.externalId).toBe("CRM-1001");
expect(lean.createdViaLabel).toBeNull();
expect(lean.createdViaOwner).toBeNull();
expect("createdViaKeyId" in lean).toBe(false);
}
});
test("security push keeps the list's trackingVerdict: null", async () => {
const lean = await enrichSecurityLite(fullTask() as never) as unknown as Record<string, unknown>;
expect(lean.trackingVerdict).toBeNull();
expect("workspacePath" in lean).toBe(false);
});
});