Fix handle_noop_message tests failing due to unmocked loadAgentOutput#14587
Fix handle_noop_message tests failing due to unmocked loadAgentOutput#14587
Conversation
…t output Instead of mocking loadAgentOutput with vi.mock(), create temporary files with actual agent output JSON data that the real loadAgentOutput function can read. This approach: 1. Tests the full integration flow (real file I/O + parsing) 2. Works with dynamic imports that bypass module mocks 3. Matches the pattern used in load_agent_output.test.cjs 4. Properly cleans up temp files in afterEach Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Remove trailing whitespace - Format multiline JSON.stringify calls for better readability Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the handle_noop_message Vitest suite to avoid vi.mock() being bypassed by cache-busted dynamic imports, by supplying real agent-output JSON via GH_AW_AGENT_OUTPUT temp files (matching the repo’s established pattern for env-based file loaders).
Changes:
- Removes the module-level
vi.mock("./load_agent_output.cjs")approach in favor of writing real JSON fixtures to temp files. - Sets
process.env.GH_AW_AGENT_OUTPUTto those temp files per test case to exercise the actual file I/O path. - Cleans up temporary directories in
afterEach().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Create agent output file with noop + other outputs | ||
| const outputFile = path.join(tempDir, "agent_output.json"); | ||
| fs.writeFileSync( | ||
| outputFile, | ||
| JSON.stringify({ | ||
| items: [ | ||
| { type: "noop", message: "No action needed" }, | ||
| { type: "create_issue", title: "Some issue" }, | ||
| ], | ||
| }) | ||
| ); | ||
| process.env.GH_AW_AGENT_OUTPUT = outputFile; |
There was a problem hiding this comment.
The same agent-output fixture setup (compute outputFile path, write JSON, set GH_AW_AGENT_OUTPUT) is duplicated across many test cases in this file. Consider extracting a small helper (e.g., writeAgentOutput(items) returning the file path and setting the env var) to reduce repetition and make future test additions less error-prone.
Tests used
vi.mock()at module level but importedhandle_noop_message.cjswith cache-busting timestamps (?t=+ Date.now()), bypassing the mock. RealloadAgentOutputexecuted withoutGH_AW_AGENT_OUTPUTset, returning early and failing assertions.Changes
vi.mock()with temporary file creation in testsGH_AW_AGENT_OUTPUTto temp files containing actual JSON dataafterEach()Before/After
Before:
After:
This matches the pattern in
load_agent_output.test.cjsand tests the full file I/O flow.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.