Skip to content

Commit 110df38

Browse files
author
Raphael Lechner
committed
test(server): harden shadow test — assert home readFile is never called
Address CodeRabbit nitpick on #1405: `parseWorkflow` is globally mocked, so asserting `body.source === 'project'` alone cannot catch a regression that reads both files before deciding. Add a `spyOn(fs.readFile)` that fails if the home path was ever opened. Restores the spy in finally so other tests aren't affected.
1 parent 1d4869b commit 110df38

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/server/src/routes/api.workflows.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect, mock } from 'bun:test';
1+
import { describe, test, expect, mock, spyOn } from 'bun:test';
22
import { OpenAPIHono } from '@hono/zod-openapi';
33
import type { ConversationLockManager } from '@archon/core';
44
import type { WebAdapter } from '../adapters/web';
@@ -306,6 +306,12 @@ describe('GET /api/workflows/:name', () => {
306306
'name: shared\ndescription: home version\nnodes:\n - id: plan\n command: plan\n'
307307
);
308308

309+
// Spy on readFile to prove home-scope is not even attempted when project
310+
// hit succeeds. `parseWorkflow` is globally mocked, so asserting on
311+
// `body.source` alone can't catch a regression that opens both files.
312+
const fsPromises = await import('fs/promises');
313+
const readFileSpy = spyOn(fsPromises, 'readFile');
314+
309315
const prevArchonHome = process.env.ARCHON_HOME;
310316
process.env.ARCHON_HOME = tmpHome;
311317
try {
@@ -318,7 +324,12 @@ describe('GET /api/workflows/:name', () => {
318324
const body = (await response.json()) as { source: string };
319325
// Project must shadow home — home lookup should not even be attempted.
320326
expect(body.source).toBe('project');
327+
328+
const homePath = join(homeWorkflowsDir, 'shared.yaml');
329+
const homeWasRead = readFileSpy.mock.calls.some(args => String(args[0]) === homePath);
330+
expect(homeWasRead).toBe(false);
321331
} finally {
332+
readFileSpy.mockRestore();
322333
if (prevArchonHome === undefined) {
323334
delete process.env.ARCHON_HOME;
324335
} else {

0 commit comments

Comments
 (0)