|
1 | 1 | import assert from "node:assert/strict"; |
2 | 2 | import test from "node:test"; |
3 | 3 | import { MINIMUM_SUPPORTED_PATCHLOOM_VERSION } from "../../src/binary/patchloom.js"; |
4 | | -import { classifyAgentsFile } from "../../src/commands/initializeProject.js"; |
| 4 | +import { classifyAgentsFile, generateAgentRules } from "../../src/commands/initializeProject.js"; |
5 | 5 | import { buildStatusDetails, preferredStatusAction } from "../../src/commands/showStatus.js"; |
6 | 6 | import { buildPatchloomMcpEntry, configureMcpTargets, inspectMcpTargets } from "../../src/mcp/config.js"; |
| 7 | +import { setPatchloomLog } from "../../src/logging/outputChannel.js"; |
7 | 8 | import { formatCliOutput, formatError } from "../../src/util.js"; |
8 | 9 |
|
9 | 10 | test("formatError extracts message from Error instances", () => { |
@@ -334,3 +335,32 @@ test("configureMcpTargets creates or updates only the selected target kinds", as |
334 | 335 | assert.match(writes.get(cursorPath) ?? "", /mcp-server/); |
335 | 336 | assert.match(writes.get(cursorPath) ?? "", /other/); |
336 | 337 | }); |
| 338 | + |
| 339 | +test("generateAgentRules logs error to output channel on CLI failure", async () => { |
| 340 | + const logged: { exitCode: number; stdout: string; stderr: string }[] = []; |
| 341 | + const commands: { binary: string; args: readonly string[]; cwd: string }[] = []; |
| 342 | + setPatchloomLog({ |
| 343 | + log() {}, |
| 344 | + logCommand(binary, args, cwd) { commands.push({ binary, args, cwd }); }, |
| 345 | + logResult(exitCode, stdout, stderr) { logged.push({ exitCode, stdout, stderr }); }, |
| 346 | + show() {}, |
| 347 | + dispose() {} |
| 348 | + }); |
| 349 | + try { |
| 350 | + await assert.rejects( |
| 351 | + () => generateAgentRules("/nonexistent/patchloom", "/tmp"), |
| 352 | + (err: Error) => { |
| 353 | + assert.match(err.message, /ENOENT|not found|No such file/i); |
| 354 | + return true; |
| 355 | + } |
| 356 | + ); |
| 357 | + assert.equal(commands.length, 1, "logCommand should be called once"); |
| 358 | + assert.equal(commands[0].binary, "/nonexistent/patchloom"); |
| 359 | + assert.deepEqual(commands[0].args, ["agent-rules"]); |
| 360 | + assert.equal(commands[0].cwd, "/tmp"); |
| 361 | + assert.equal(logged.length, 1, "logResult should be called once on failure"); |
| 362 | + assert.equal(logged[0].exitCode, 1); |
| 363 | + } finally { |
| 364 | + setPatchloomLog(undefined); |
| 365 | + } |
| 366 | +}); |
0 commit comments