fix: isolate watcher task runtimes

This commit is contained in:
Eyejoker
2026-03-23 07:16:07 +09:00
parent 867a6a80ef
commit 9def49f7fb
14 changed files with 407 additions and 61 deletions

View File

@@ -299,6 +299,68 @@ describe('agent-runner timeout behavior', () => {
);
});
it('isolates IPC and session directories for isolated scheduled tasks', async () => {
vi.useRealTimers();
fakeProc = createFakeProcess();
const resultPromise = runAgentProcess(
testGroup,
{
...testInput,
isScheduledTask: true,
runtimeTaskId: 'task-123',
useTaskScopedSession: true,
},
() => {},
async () => {},
);
fakeProc.emit('close', 0);
const result = await resultPromise;
expect(result.status).toBe('success');
const spawnEnv = vi.mocked(spawn).mock.calls.at(-1)?.[2]?.env as
| Record<string, string>
| undefined;
expect(spawnEnv?.NANOCLAW_IPC_DIR).toBe(
'/tmp/nanoclaw-test-data/ipc/test-group/tasks/task-123',
);
expect(spawnEnv?.CLAUDE_CONFIG_DIR).toBe(
'/tmp/nanoclaw-test-data/sessions/test-group/tasks/task-123/.claude',
);
});
it('keeps shared session history for group-context task runtimes while isolating IPC', async () => {
vi.useRealTimers();
fakeProc = createFakeProcess();
const resultPromise = runAgentProcess(
testGroup,
{
...testInput,
isScheduledTask: true,
runtimeTaskId: 'task-watch-group',
useTaskScopedSession: false,
},
() => {},
async () => {},
);
fakeProc.emit('close', 0);
const result = await resultPromise;
expect(result.status).toBe('success');
const spawnEnv = vi.mocked(spawn).mock.calls.at(-1)?.[2]?.env as
| Record<string, string>
| undefined;
expect(spawnEnv?.NANOCLAW_IPC_DIR).toBe(
'/tmp/nanoclaw-test-data/ipc/test-group/tasks/task-watch-group',
);
expect(spawnEnv?.CLAUDE_CONFIG_DIR).toBe(
'/tmp/nanoclaw-test-data/sessions/test-group/.claude',
);
});
it('merges a per-group codex config overlay before injecting managed MCP servers', async () => {
vi.useRealTimers();
fakeProc = createFakeProcess();