No room has room_settings.is_main = 1, so every main-only path was dead, and admin work is done from the host shell. Each room's agent may now only act on its own room: - IPC: messages/inbound injection only to the source room; schedule, update, pause, resume and cancel only for the source room's tasks; drop the assign_room and refresh_groups IPC tasks and the deps they needed (assignRoom/syncGroups/getAvailableGroups/writeGroupsSnapshot) - DB/host evidence is always scoped to the source group folder - runner MCP server: drop the assign_room tool, the target_group_jid parameters and the isMain flag; list_tasks shows only the room's tasks - drop EJCLAW_IS_MAIN, RunnerInput.isMain and AgentInput.isMain; the global CLAUDE.md memory is now included for every room - drop the available_groups.json snapshot (available-groups.ts), the inferred restart announcement that only went to the main room, and the unused Channel.syncGroups hook - setup register: drop --is-main; deregister-room: drop the main-room refusal and --force, and fix its unknown[] binding type error - remove the groups/main/ template The room_settings.is_main column and migrations are untouched; new rows get the column default (0) and nothing reads it anymore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
162 lines
4.2 KiB
TypeScript
162 lines
4.2 KiB
TypeScript
import fs from 'fs';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
const {
|
|
assignRoomMock,
|
|
initDatabaseMock,
|
|
emitStatusMock,
|
|
loggerInfoMock,
|
|
isValidGroupFolderMock,
|
|
} = vi.hoisted(() => ({
|
|
assignRoomMock: vi.fn(),
|
|
initDatabaseMock: vi.fn(),
|
|
emitStatusMock: vi.fn(),
|
|
loggerInfoMock: vi.fn(),
|
|
isValidGroupFolderMock: vi.fn(() => true),
|
|
}));
|
|
|
|
vi.mock('../src/config.js', () => ({
|
|
GROUPS_DIR: '/tmp/ejclaw-groups',
|
|
}));
|
|
|
|
vi.mock('../src/db.js', () => ({
|
|
assignRoom: assignRoomMock,
|
|
initDatabase: initDatabaseMock,
|
|
}));
|
|
|
|
vi.mock('../src/group-folder.js', () => ({
|
|
isValidGroupFolder: isValidGroupFolderMock,
|
|
}));
|
|
|
|
// Registration now provisions the paired workspace (which shells out to git)
|
|
// and hot-reloads the running service. Stub both so the unit test stays hermetic
|
|
// and only verifies the registration delegation, not workspace/git side effects.
|
|
vi.mock('../src/paired-workspace-manager.js', () => ({
|
|
ensurePairedWorkspaceProvisioned: vi.fn(
|
|
() => '/tmp/ejclaw-groups/test-room/owner',
|
|
),
|
|
}));
|
|
|
|
vi.mock('../src/runtime-reload-signal.js', () => ({
|
|
signalEjclawReload: vi.fn(() => false),
|
|
}));
|
|
|
|
vi.mock('../src/logger.js', () => ({
|
|
logger: {
|
|
info: loggerInfoMock,
|
|
},
|
|
}));
|
|
|
|
vi.mock('./status.js', () => ({
|
|
emitStatus: emitStatusMock,
|
|
}));
|
|
|
|
import { run } from './register.js';
|
|
|
|
describe('register step', () => {
|
|
afterEach(() => {
|
|
assignRoomMock.mockReset();
|
|
initDatabaseMock.mockReset();
|
|
emitStatusMock.mockReset();
|
|
loggerInfoMock.mockReset();
|
|
isValidGroupFolderMock.mockReset();
|
|
isValidGroupFolderMock.mockReturnValue(true);
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it('delegates room assignment to the canonical service without editing env or prompts', async () => {
|
|
const mkdirSpy = vi
|
|
.spyOn(fs, 'mkdirSync')
|
|
.mockImplementation(() => undefined);
|
|
const readSpy = vi.spyOn(fs, 'readFileSync');
|
|
const writeSpy = vi.spyOn(fs, 'writeFileSync');
|
|
|
|
await run([
|
|
'--jid',
|
|
'dc:test-room',
|
|
'--name',
|
|
'Test Room',
|
|
'--folder',
|
|
'test-room',
|
|
]);
|
|
|
|
expect(initDatabaseMock).toHaveBeenCalledTimes(1);
|
|
expect(assignRoomMock).toHaveBeenCalledWith('dc:test-room', {
|
|
name: 'Test Room',
|
|
folder: 'test-room',
|
|
});
|
|
expect(mkdirSpy).toHaveBeenCalledWith('/tmp/ejclaw-groups/test-room/logs', {
|
|
recursive: true,
|
|
});
|
|
expect(readSpy).not.toHaveBeenCalled();
|
|
expect(writeSpy).not.toHaveBeenCalled();
|
|
expect(emitStatusMock).toHaveBeenCalledWith('REGISTER_CHANNEL', {
|
|
JID: 'dc:test-room',
|
|
NAME: 'Test Room',
|
|
FOLDER: 'test-room',
|
|
CHANNEL: 'discord',
|
|
STATUS: 'success',
|
|
RELOADED: 'no',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
});
|
|
|
|
it('fails fast when deprecated assistant-name is passed', async () => {
|
|
const exitSpy = vi
|
|
.spyOn(process, 'exit')
|
|
.mockImplementation((code?: string | number | null | undefined) => {
|
|
throw new Error(`process.exit:${code}`);
|
|
});
|
|
|
|
await expect(
|
|
run([
|
|
'--jid',
|
|
'dc:test-room',
|
|
'--name',
|
|
'Test Room',
|
|
'--folder',
|
|
'test-room',
|
|
'--assistant-name',
|
|
'Nova',
|
|
]),
|
|
).rejects.toThrow('process.exit:4');
|
|
|
|
expect(initDatabaseMock).not.toHaveBeenCalled();
|
|
expect(assignRoomMock).not.toHaveBeenCalled();
|
|
expect(emitStatusMock).toHaveBeenCalledWith('REGISTER_CHANNEL', {
|
|
STATUS: 'failed',
|
|
ERROR: 'assistant_name_option_removed',
|
|
NEXT_STEP:
|
|
'Use a dedicated assistant identity configuration command instead',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
|
|
exitSpy.mockRestore();
|
|
});
|
|
|
|
it('never writes prompt or env files during registration', async () => {
|
|
const mkdirSpy = vi
|
|
.spyOn(fs, 'mkdirSync')
|
|
.mockImplementation(() => undefined);
|
|
const readSpy = vi.spyOn(fs, 'readFileSync');
|
|
const writeSpy = vi.spyOn(fs, 'writeFileSync');
|
|
|
|
await run([
|
|
'--jid',
|
|
'dc:main-room',
|
|
'--name',
|
|
'Main Room',
|
|
'--folder',
|
|
'main-room',
|
|
]);
|
|
|
|
expect(assignRoomMock).toHaveBeenCalledWith('dc:main-room', {
|
|
name: 'Main Room',
|
|
folder: 'main-room',
|
|
});
|
|
expect(mkdirSpy).toHaveBeenCalledTimes(1);
|
|
expect(readSpy).not.toHaveBeenCalled();
|
|
expect(writeSpy).not.toHaveBeenCalled();
|
|
});
|
|
});
|