import assert from "node:assert/strict"; import { test } from "node:test"; import { checkPRModel, missingDeclarations } from "./pr-model.mjs"; const declaration = "model: deepseek/deepseek-R1"; const opened = { action: "opened", pull_request: { number: 42, base: { ref: "main" } } }; const options = { apiUrl: "https://api.example.invalid", repository: "owner/repo", token: "test" }; test("requires visible model and agent declarations", () => { for (const agent of ["WorkBuddy", "豆包", "OpenAI Codex"]) { assert.deepEqual(missingDeclarations(`${declaration}\r\nagent: ${agent}`), []); } assert.deepEqual(missingDeclarations(declaration), ["agent"]); assert.deepEqual(missingDeclarations("agent: 豆包"), ["model"]); assert.deepEqual(missingDeclarations(`${declaration}\nagent: `), ["agent"]); assert.deepEqual(missingDeclarations(`${declaration}\n`), ["agent"]); assert.deepEqual(missingDeclarations("```\n" + declaration + "\nagent: 豆包\n```"), ["model", "agent"]); assert.deepEqual(missingDeclarations(null), ["model", "agent"]); }); test("closes a new PR when either declaration is missing from its current description", async () => { const cases = [ ["", ["model", "agent"]], [declaration, ["agent"]], ["agent: 豆包", ["model"]], [`${declaration}\nagent: WorkBuddy`, []], ]; for (const [body, missing] of cases) { const calls = []; const request = async (url, init) => { calls.push([url, init.method, init.body]); return { ok: true, json: async () => ({ state: "open", base: { ref: "main" }, body }) }; }; assert.deepEqual(await checkPRModel(opened, { ...options, request }), missing.length ? { status: "closed", missing } : "accepted"); assert.equal(calls.length, missing.length ? 2 : 1); if (missing.length) assert.deepEqual(calls[1], ["https://api.example.invalid/repos/owner/repo/pulls/42", "PATCH", JSON.stringify({ state: "closed" })]); } }); test("skips existing PR updates and other base branches", async () => { const request = () => assert.fail("The API must not be called"); for (const action of ["edited", "reopened", "synchronize", "ready_for_review"]) { assert.equal(await checkPRModel({ ...opened, action }, { ...options, request }), "skipped"); } const otherBase = { ...opened, pull_request: { ...opened.pull_request, base: { ref: "release" } } }; assert.equal(await checkPRModel(otherBase, { ...options, request }), "skipped"); });