mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 10:07:19 +01:00
Users switch agents from the Control UI without typing quit commands in Zellij — click the agent chip on a project card, pick from Cmd+K palette, or accept the rate-limit banner's fallback suggestion. Detection lives in agent-resolution.ts (client-safe) + agent-process-scan.ts (server /proc walk); switch enqueues pending_commands type switch_agent which the Fleet Runner poller executes locally, quitting every running agent in the dir before launching the next. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
108 lines
3.1 KiB
TypeScript
108 lines
3.1 KiB
TypeScript
/**
|
|
* Inline self-tests for agent-resolution helpers.
|
|
* Run: npm run test:agent-resolution
|
|
*/
|
|
import {
|
|
inferAdapterFromTabName,
|
|
resolveDetectedAgentIds,
|
|
resolveOutgoingAgent,
|
|
hasAgentLabelMismatch,
|
|
detectCapacityIssueFromProject,
|
|
resolveNextFallbackAgent,
|
|
looksLikeAgentCapacityIssue,
|
|
} from "@/lib/agent-resolution";
|
|
import type { ProjectState } from "@/lib/control-types";
|
|
|
|
function stubProject(overrides: Partial<ProjectState> & Pick<ProjectState, "tab">): ProjectState {
|
|
return {
|
|
id: "1",
|
|
projectId: null,
|
|
liveTab: overrides.tab,
|
|
dir: "/tmp/proj",
|
|
agentPref: "claude",
|
|
modelPref: null,
|
|
session: null,
|
|
git: null,
|
|
sessionLifecycleSignals: true,
|
|
agentRunning: false,
|
|
activeAgents: [],
|
|
profile: null,
|
|
currentPrompt: null,
|
|
readyAt: null,
|
|
lockAt: null,
|
|
closingAt: null,
|
|
closedAt: null,
|
|
recentCustomPrompts: [],
|
|
recentInjections: [],
|
|
recentOutcomes: [],
|
|
latestOrchestrationRun: null,
|
|
autoInjectModeOverride: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function assert(condition: boolean, message: string): void {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
function runTests(): void {
|
|
let passed = 0;
|
|
const check = (label: string, fn: () => void) => {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ✓ ${label}`);
|
|
};
|
|
|
|
check("inferAdapterFromTabName suffix", () => {
|
|
assert(inferAdapterFromTabName("FleetCrown Codex") === "codex", "expected codex");
|
|
});
|
|
|
|
check("resolveDetectedAgentIds prefers activeAgents", () => {
|
|
const project = stubProject({ tab: "FleetCrown", activeAgents: ["codex"], agentPref: "claude" });
|
|
assert(resolveDetectedAgentIds(project)[0] === "codex", "expected live codex");
|
|
});
|
|
|
|
check("resolveOutgoingAgent uses live scan over preference", () => {
|
|
const project = stubProject({ tab: "FleetCrown", activeAgents: ["codex"], agentPref: "claude" });
|
|
assert(resolveOutgoingAgent(project, "claude") === "codex", "expected codex outgoing");
|
|
});
|
|
|
|
check("hasAgentLabelMismatch when pref disagrees with /proc", () => {
|
|
const project = stubProject({
|
|
tab: "FleetCrown",
|
|
agentRunning: true,
|
|
activeAgents: ["codex"],
|
|
agentPref: "claude",
|
|
});
|
|
assert(hasAgentLabelMismatch(project, "claude"), "expected mismatch");
|
|
});
|
|
|
|
check("detectCapacityIssueFromProject reads session text", () => {
|
|
const project = stubProject({
|
|
tab: "FleetCrown",
|
|
session: {
|
|
status: "working",
|
|
done: "rate limit exceeded",
|
|
next: "",
|
|
tests: "",
|
|
todos: "",
|
|
health: "good",
|
|
mtime: Date.now(),
|
|
},
|
|
});
|
|
assert(detectCapacityIssueFromProject(project), "expected capacity issue");
|
|
});
|
|
|
|
check("resolveNextFallbackAgent skips current", () => {
|
|
assert(resolveNextFallbackAgent("codex", ["claude", "cursor", "codex"]) === "cursor", "expected cursor");
|
|
});
|
|
|
|
check("looksLikeAgentCapacityIssue matches quota", () => {
|
|
assert(looksLikeAgentCapacityIssue("You have exceeded your quota"), "expected quota match");
|
|
});
|
|
|
|
console.log(`\n${passed} agent-resolution tests passed`);
|
|
}
|
|
|
|
runTests();
|