refactor: rename container references to agent across codebase

- container-runner.ts → agent-runner.ts
- ContainerInput/Output → AgentInput/Output
- ContainerConfig → AgentConfig
- runContainerAgent → runAgentProcess
- CONTAINER_TIMEOUT → AGENT_TIMEOUT (with env fallback)
- MAX_CONCURRENT_CONTAINERS → MAX_CONCURRENT_AGENTS
- containerName → processName, isTaskContainer → isTaskProcess
- DB column container_config kept as-is (backwards compat)
This commit is contained in:
Eyejoker
2026-03-13 16:18:36 +09:00
parent 35277cea0a
commit bd7f4408ae
12 changed files with 144 additions and 133 deletions

View File

@@ -5,7 +5,7 @@ import { GroupQueue } from './group-queue.js';
// Mock config to control concurrency limit
vi.mock('./config.js', () => ({
DATA_DIR: '/tmp/nanoclaw-test-data',
MAX_CONCURRENT_CONTAINERS: 2,
MAX_CONCURRENT_AGENTS: 2,
}));
// Mock fs operations used by sendMessage/closeStdin
@@ -36,7 +36,7 @@ describe('GroupQueue', () => {
// --- Single group at a time ---
it('only runs one container per group at a time', async () => {
it('only runs one agent per group at a time', async () => {
let concurrentCount = 0;
let maxConcurrent = 0;
@@ -87,7 +87,7 @@ describe('GroupQueue', () => {
// Let promises settle
await vi.advanceTimersByTimeAsync(10);
// Only 2 should be active (MAX_CONCURRENT_CONTAINERS = 2)
// Only 2 should be active (MAX_CONCURRENT_AGENTS = 2)
expect(maxActive).toBe(2);
expect(activeCount).toBe(2);
@@ -280,7 +280,7 @@ describe('GroupQueue', () => {
// --- Idle preemption ---
it('does NOT preempt active container when not idle', async () => {
it('does NOT preempt active agent when not idle', async () => {
const fs = await import('fs');
let resolveProcess: () => void;
@@ -301,15 +301,15 @@ describe('GroupQueue', () => {
queue.registerProcess(
'group1@g.us',
{} as any,
'container-1',
'agent-1',
'test-group',
);
// Enqueue a task while container is active but NOT idle
// Enqueue a task while agent is active but NOT idle
const taskFn = vi.fn(async () => {});
queue.enqueueTask('group1@g.us', 'task-1', taskFn);
// _close should NOT have been written (container is working, not idle)
// _close should NOT have been written (agent is working, not idle)
const writeFileSync = vi.mocked(fs.default.writeFileSync);
const closeWrites = writeFileSync.mock.calls.filter(
(call) => typeof call[0] === 'string' && call[0].endsWith('_close'),
@@ -320,7 +320,7 @@ describe('GroupQueue', () => {
await vi.advanceTimersByTimeAsync(10);
});
it('preempts idle container when task is enqueued', async () => {
it('preempts idle agent when task is enqueued', async () => {
const fs = await import('fs');
let resolveProcess: () => void;
@@ -341,7 +341,7 @@ describe('GroupQueue', () => {
queue.registerProcess(
'group1@g.us',
{} as any,
'container-1',
'agent-1',
'test-group',
);
queue.notifyIdle('group1@g.us');
@@ -353,7 +353,7 @@ describe('GroupQueue', () => {
const taskFn = vi.fn(async () => {});
queue.enqueueTask('group1@g.us', 'task-1', taskFn);
// _close SHOULD have been written (container is idle)
// _close SHOULD have been written (agent is idle)
const closeWrites = writeFileSync.mock.calls.filter(
(call) => typeof call[0] === 'string' && call[0].endsWith('_close'),
);
@@ -380,11 +380,11 @@ describe('GroupQueue', () => {
queue.registerProcess(
'group1@g.us',
{} as any,
'container-1',
'agent-1',
'test-group',
);
// Container becomes idle
// Agent becomes idle
queue.notifyIdle('group1@g.us');
// A new user message arrives — resets idleWaiting
@@ -406,7 +406,7 @@ describe('GroupQueue', () => {
await vi.advanceTimersByTimeAsync(10);
});
it('sendMessage returns false for task containers so user messages queue up', async () => {
it('sendMessage returns false for task agents so user messages queue up', async () => {
let resolveTask: () => void;
const taskFn = vi.fn(async () => {
@@ -415,17 +415,17 @@ describe('GroupQueue', () => {
});
});
// Start a task (sets isTaskContainer = true)
// Start a task (sets isTaskProcess = true)
queue.enqueueTask('group1@g.us', 'task-1', taskFn);
await vi.advanceTimersByTimeAsync(10);
queue.registerProcess(
'group1@g.us',
{} as any,
'container-1',
'agent-1',
'test-group',
);
// sendMessage should return false — user messages must not go to task containers
// sendMessage should return false — user messages must not go to task agents
const result = queue.sendMessage('group1@g.us', 'hello');
expect(result).toBe(false);
@@ -454,7 +454,7 @@ describe('GroupQueue', () => {
queue.registerProcess(
'group1@g.us',
{} as any,
'container-1',
'agent-1',
'test-group',
);
@@ -469,7 +469,7 @@ describe('GroupQueue', () => {
);
expect(closeWrites).toHaveLength(0);
// Now container becomes idle — should preempt because task is pending
// Now agent becomes idle — should preempt because task is pending
writeFileSync.mockClear();
queue.notifyIdle('group1@g.us');