evOo-local/apps/web/src/lib/bot-persona.test.ts
Cursor Agent 0c9e6d7c58
fix(security): GitHub broker, drop sudo, DE awareness i18n, CI image tools
Route git push and gh pr through the sandbox supervisor broker so project
computers never receive GITHUB_TOKEN/GH_TOKEN. Remove NOPASSWD sudo from the
computer image. Localize awareness strip copy via Lingui and wire
computer-image-tools.test.sh into the validate-computer-image job.

Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
2026-10-07 21:41:56 +00:00

134 lines
3.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
extractVoiceAwareness,
narrateGroupSpark,
personaTextPose,
resolveBotPersona,
resolvePersonaArchetype,
resolveTextStagePhase,
} from "./bot-persona";
describe("resolvePersonaArchetype", () => {
it("detects Steve Jobs CTO template alignment", () => {
expect(
resolvePersonaArchetype({
name: "Steve Jobs - Autonomous CTO",
title: "Executive CTO",
description: "Full system access",
}),
).toBe("cto-executive");
});
it("detects fixer / chief operator", () => {
expect(
resolvePersonaArchetype({
name: "Fixer",
title: "Chief of Staff",
description: "",
}),
).toBe("chief-operator");
});
it("falls back to specialist when no archetype rule matches", () => {
expect(
resolvePersonaArchetype({
name: "Maya",
title: "Compliance Review",
description: "Focused specialist",
}),
).toBe("specialist");
});
});
describe("resolveBotPersona", () => {
it("uses title as role line when present", () => {
const profile = resolveBotPersona({
name: "Apex Quant",
title: "Portfolio Lead",
description: "alpha signals",
});
expect(profile.archetype).toBe("quant");
expect(profile.roleLine).toBe("Portfolio Lead");
expect(profile.cadence).toBe("urgent");
});
});
describe("extractVoiceAwareness", () => {
it("surfaces active subagent collaboration", () => {
const event = extractVoiceAwareness(
{
threadId: "t1",
botId: "b1",
messages: [
{
id: "m1",
role: "bot",
runId: "r1",
createdAt: "",
blocks: [
{
kind: "subagent",
agentId: "a1",
name: "Code Architect",
task: "Refactor auth module",
status: "running",
},
],
},
],
run: { id: "r1", status: "running" },
} as never,
"Steve Jobs",
);
expect(event?.kind).toBe("subagent");
expect(event?.targetName).toBe("Code Architect");
});
});
describe("narrateGroupSpark", () => {
it("uses playful peer-reply language for builder archetype", () => {
const line = narrateGroupSpark(
{
kind: "peer-reply",
actorName: "Eggbot",
actorBotId: "b2",
detail: "That API shape is wrong.",
},
"builder",
);
expect(line.toLowerCase()).toContain("geeked");
expect(line).toContain("Eggbot");
});
});
describe("resolveTextStagePhase", () => {
it("maps running work to working phase", () => {
expect(
resolveTextStagePhase({
running: true,
hasMessages: true,
}),
).toBe("working");
});
it("uses idle for empty threads", () => {
expect(
resolveTextStagePhase({
running: false,
hasMessages: false,
}),
).toBe("idle");
});
});
describe("personaTextPose", () => {
it("returns working pose while agent runs", () => {
const profile = resolveBotPersona({
name: "Apex Quant",
title: "Quant",
description: "",
});
expect(personaTextPose(profile, "working")).toBe("working");
});
});