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 coding tool declarations", () => { for (const model of ["deepseek/deepseek-R1", "google/Gemini 4 Neon", "anthropic/Claude 4.5 Sonnet"]) { for (const tool of ["tool: Cursor", "tool: WorkBuddy", "tool: 豆包", "tool: OpenAI Codex", "agent: WorkBuddy"]) { assert.deepEqual(missingDeclarations(`model: ${model}\r\n${tool}`), []); } } assert.deepEqual(missingDeclarations(declaration), ["tool"]); assert.deepEqual(missingDeclarations("tool: 豆包"), ["model"]); assert.deepEqual(missingDeclarations("model: google/\ntool: Cursor"), ["model"]); assert.deepEqual(missingDeclarations("model: /gemini\ntool: Cursor"), ["model"]); assert.deepEqual(missingDeclarations("model: gemini\ntool: Cursor"), ["model"]); assert.deepEqual(missingDeclarations(`${declaration}\ntool: `), ["tool"]); assert.deepEqual(missingDeclarations(`${declaration}\n`), ["tool"]); assert.deepEqual(missingDeclarations("```\n" + declaration + "\ntool: 豆包\n```"), ["model", "tool"]); assert.deepEqual(missingDeclarations(null), ["model", "tool"]); }); test("closes a new PR when either declaration is missing from its current description", async () => { const cases = [ ["", ["model", "tool"]], [declaration, ["tool"]], ["tool: 豆包", ["model"]], [`${declaration}\ntool: WorkBuddy`, []], [`${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"); });