agenthub/tests/role-switch.test.ts
chahinebrini df698c9dff feat(agenthub): Rollenwechsel, agent-setup + Push-Channel
roleService haelt roles.*.preferredAgent (Routing-Autoritaet fuer asks,
Watchdog, start) und agents.*.role (Health/Board/MCP-Discovery) konsistent —
bisher konnte nur eine Seite gesetzt werden und der Roster lief auseinander.
Dazu agent-setup-Kommando, Push-Channel im MCP und Selbstheilung im
remoteClient.

Build clean, 304 Tests in 55 Dateien gruen.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0113SC5FkaMxcRzXHDBsHmdJ
2026-08-02 21:38:47 +02:00

58 lines
2.2 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { init } from '../src/cli/commands/init.js';
import { loadConfig, saveConfig } from '../src/core/config.js';
import { setPreferredAgent } from '../src/core/services/roleService.js';
import { getRoster } from '../src/core/services/rosterService.js';
describe('preferred role switching', () => {
let cwd: string;
beforeEach(() => {
cwd = mkdtempSync(join(tmpdir(), 'ah-role-switch-'));
init(cwd, { projectName: 'role-switch', yes: true });
const config = loadConfig(cwd);
config.agents = {
claude: { role: 'architect', dispatch: 'loop', aliases: [] },
codex: { role: 'implementer', dispatch: 'loop', aliases: [] },
kimi: { role: 'implementer', dispatch: 'loop', aliases: [] },
};
saveConfig(cwd, config);
});
afterEach(() => {
rmSync(cwd, { recursive: true, force: true });
});
it('promotes codex and moves claude to its remaining reviewer role', () => {
expect(setPreferredAgent(cwd, 'architect', 'codex')).toEqual({
role: 'architect',
agent: 'codex',
previousAgent: 'claude',
});
const config = loadConfig(cwd);
expect(config.roles.architect.preferredAgent).toBe('codex');
expect(config.agents?.codex.role).toBe('architect');
expect(config.agents?.claude.role).toBe('reviewer');
expect(getRoster(cwd).find((a) => a.name === 'codex')?.role).toBe('architect');
});
it('restores claude and returns codex to implementer', () => {
setPreferredAgent(cwd, 'architect', 'codex');
setPreferredAgent(cwd, 'architect', 'claude');
const config = loadConfig(cwd);
expect(config.agents?.claude.role).toBe('architect');
expect(config.agents?.codex.role).toBe('implementer');
expect(getRoster(cwd).find((a) => a.name === 'claude')?.role).toBe('architect');
});
it('rejects unknown agents without changing the config', () => {
expect(() => setPreferredAgent(cwd, 'architect', 'nobody')).toThrow('Unknown agent');
expect(loadConfig(cwd).roles.architect.preferredAgent).toBe('claude');
});
});