/// import assert from "node:assert/strict"; import { test } from "node:test"; import { type CloseDeps, caseNumberFromTitle, closeDevilIssueIfDone, DEVIL_AGENT_IDS, } from "./devil-closer.ts"; const CMPA = "8639e837-4c9d-47fa-a76b-95788d651896"; const DEVIL = DEVIL_AGENT_IDS[CMPA]; const TITLE = "[ערר 8165-11-25] שטן-מליץ — red-team על הניתוח"; function deps(over: Partial = {}) { const closed: string[] = []; const d: CloseDeps = { getIssue: async (id) => ({ id, title: TITLE, status: "in_progress", assigneeAgentId: DEVIL, createdAt: "2026-10-14T12:45:58Z", }), statCritique: async () => ({ size: 39261, mtimeMs: Date.parse("2026-10-14T13:29:50Z"), }), closeIssue: async (id) => { closed.push(id); }, log: () => {}, ...over, }; return { d, closed }; } const RUN = { agentId: DEVIL, issueId: "i1", status: "succeeded" }; test("caseNumberFromTitle", () => { assert.equal(caseNumberFromTitle(TITLE), "8165-11-25"); assert.equal(caseNumberFromTitle("[ערר 8027/25] x"), "8027/25"); assert.equal(caseNumberFromTitle("בלי מספר"), null); }); test("סוגר כשהכול תקין", async () => { const { d, closed } = deps(); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "closed"); assert.deepEqual(closed, ["i1"]); }); test("לא סוכן שטן → לא נוגע", async () => { const { d, closed } = deps(); assert.equal( await closeDevilIssueIfDone(CMPA, { ...RUN, agentId: "other" }, d), "not_devil_run", ); assert.equal(closed.length, 0); }); test("חברה לא מוכרת → לא נוגע", async () => { const { d } = deps(); assert.equal(await closeDevilIssueIfDone("nope", RUN, d), "not_devil_run"); }); test("ריצה שלא הצליחה → לא סוגר", async () => { const { d, closed } = deps(); assert.equal( await closeDevilIssueIfDone(CMPA, { ...RUN, status: "failed" }, d), "not_devil_run", ); assert.equal(closed.length, 0); }); test("issue שאינו של שטן (כותרת אחרת) → לא סוגר", async () => { const { d, closed } = deps({ getIssue: async (id) => ({ id, title: "[ערר 1-1-1] ניתוח משפטי", status: "in_progress", assigneeAgentId: DEVIL, }), }); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "not_devil_issue"); assert.equal(closed.length, 0); }); test("כבר סגור → לא סוגר שוב", async () => { const { d, closed } = deps({ getIssue: async (id) => ({ id, title: TITLE, status: "done", assigneeAgentId: DEVIL, }), }); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "already_closed"); assert.equal(closed.length, 0); }); test("אין קובץ מזכר → נשאר פתוח", async () => { const { d, closed } = deps({ statCritique: async () => null }); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "no_deliverable"); assert.equal(closed.length, 0); }); test("קובץ ישן מלפני יצירת ה-issue → נשאר פתוח", async () => { const { d, closed } = deps({ statCritique: async () => ({ size: 39261, mtimeMs: Date.parse("2026-10-01T00:00:00Z"), }), }); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "no_deliverable"); assert.equal(closed.length, 0); }); test("קובץ קצר מדי → נשאר פתוח", async () => { const { d, closed } = deps({ statCritique: async () => ({ size: 300, mtimeMs: Date.parse("2026-10-14T13:29:50Z"), }), }); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "no_deliverable"); assert.equal(closed.length, 0); }); test("כשל גישה לקובץ → נשאר פתוח (fail-safe)", async () => { const { d, closed } = deps({ statCritique: async () => { throw new Error("EACCES"); }, }); assert.equal(await closeDevilIssueIfDone(CMPA, RUN, d), "stat_failed"); assert.equal(closed.length, 0); });