refactor: land approved runtime cleanup and room binding cutover

This commit is contained in:
ejclaw
2026-04-10 21:04:23 +09:00
parent ce3854745d
commit 4e05f60400
45 changed files with 636 additions and 637 deletions

View File

@@ -1,27 +1,14 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { RegisteredGroup } from './types.js';
const { handleSessionCommandMock, hasAllowedTriggerMock, loggerInfoMock } =
vi.hoisted(() => ({
handleSessionCommandMock: vi.fn(),
hasAllowedTriggerMock: vi.fn(),
loggerInfoMock: vi.fn(),
}));
const { handleSessionCommandMock } = vi.hoisted(() => ({
handleSessionCommandMock: vi.fn(),
}));
vi.mock('./session-commands.js', () => ({
handleSessionCommand: handleSessionCommandMock,
}));
vi.mock('./message-runtime-rules.js', () => ({
hasAllowedTrigger: hasAllowedTriggerMock,
}));
vi.mock('./logger.js', () => ({
logger: {
info: loggerInfoMock,
},
}));
import { handleQueuedRunGates } from './message-runtime-gating.js';
describe('message-runtime-gating', () => {
@@ -44,8 +31,6 @@ describe('message-runtime-gating', () => {
beforeEach(() => {
handleSessionCommandMock.mockReset();
hasAllowedTriggerMock.mockReset();
loggerInfoMock.mockReset();
});
it('returns session-command results directly when a command is handled', async () => {
@@ -57,29 +42,13 @@ describe('message-runtime-gating', () => {
const result = await handleQueuedRunGates(baseArgs);
expect(result).toEqual({ handled: true, success: false });
expect(hasAllowedTriggerMock).not.toHaveBeenCalled();
});
it('treats missing triggers as a handled no-op', async () => {
it('falls through when no session command is handled', async () => {
handleSessionCommandMock.mockResolvedValue({ handled: false });
hasAllowedTriggerMock.mockReturnValue(false);
const result = await handleQueuedRunGates(baseArgs);
expect(result).toEqual({ handled: true, success: true });
expect(loggerInfoMock).toHaveBeenCalledWith(
{ chatJid: 'room-1', group: 'room', runId: 'run-1' },
'Skipping queued run because no allowed trigger was found',
);
});
it('falls through when no session command is handled and the trigger is allowed', async () => {
handleSessionCommandMock.mockResolvedValue({ handled: false });
hasAllowedTriggerMock.mockReturnValue(true);
const result = await handleQueuedRunGates(baseArgs);
expect(result).toEqual({ handled: false });
expect(loggerInfoMock).not.toHaveBeenCalled();
});
});