fix(tests): align discord + queue changes

This commit is contained in:
Peter Steinberger
2025-12-26 14:32:57 +01:00
parent a678c3f53e
commit e33c09f8d4
4 changed files with 244 additions and 69 deletions

View File

@@ -392,84 +392,102 @@ describe("trigger handling", () => {
describe("group intro prompts", () => {
it("labels Discord groups using the surface metadata", async () => {
const commandSpy = vi
.spyOn(commandReply, "runCommandReply")
.mockResolvedValue({ payloads: [{ text: "ok" }], meta: { durationMs: 1 } });
await withTempHome(async (home) => {
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
payloads: [{ text: "ok" }],
meta: {
durationMs: 1,
agentMeta: { sessionId: "s", provider: "p", model: "m" },
},
});
await getReplyFromConfig(
{
Body: "status update",
From: "group:dev",
To: "+1888",
ChatType: "group",
GroupSubject: "Release Squad",
GroupMembers: "Alice, Bob",
Surface: "discord",
},
{},
baseCfg,
);
await getReplyFromConfig(
{
Body: "status update",
From: "group:dev",
To: "+1888",
ChatType: "group",
GroupSubject: "Release Squad",
GroupMembers: "Alice, Bob",
Surface: "discord",
},
{},
makeCfg(home),
);
expect(commandSpy).toHaveBeenCalledOnce();
const body =
commandSpy.mock.calls.at(-1)?.[0]?.templatingCtx.Body ?? "";
const intro = body.split("\n\n")[0];
expect(intro).toBe(
'You are replying inside the Discord group "Release Squad". Group members: Alice, Bob. Address the specific sender noted in the message context.',
);
expect(runEmbeddedPiAgent).toHaveBeenCalledOnce();
const extraSystemPrompt =
vi.mocked(runEmbeddedPiAgent).mock.calls.at(-1)?.[0]
?.extraSystemPrompt ?? "";
expect(extraSystemPrompt).toBe(
'You are replying inside the Discord group "Release Squad". Group members: Alice, Bob. Activation: trigger-only (you are invoked only when explicitly mentioned; recent context may be included). Address the specific sender noted in the message context.',
);
});
});
it("keeps WhatsApp labeling for WhatsApp group chats", async () => {
const commandSpy = vi
.spyOn(commandReply, "runCommandReply")
.mockResolvedValue({ payloads: [{ text: "ok" }], meta: { durationMs: 1 } });
await withTempHome(async (home) => {
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
payloads: [{ text: "ok" }],
meta: {
durationMs: 1,
agentMeta: { sessionId: "s", provider: "p", model: "m" },
},
});
await getReplyFromConfig(
{
Body: "ping",
From: "123@g.us",
To: "+1999",
ChatType: "group",
GroupSubject: "Ops",
Surface: "whatsapp",
},
{},
baseCfg,
);
await getReplyFromConfig(
{
Body: "ping",
From: "123@g.us",
To: "+1999",
ChatType: "group",
GroupSubject: "Ops",
Surface: "whatsapp",
},
{},
makeCfg(home),
);
expect(commandSpy).toHaveBeenCalledOnce();
const body =
commandSpy.mock.calls.at(-1)?.[0]?.templatingCtx.Body ?? "";
const intro = body.split("\n\n")[0];
expect(intro).toBe(
'You are replying inside the WhatsApp group "Ops". Address the specific sender noted in the message context.',
);
expect(runEmbeddedPiAgent).toHaveBeenCalledOnce();
const extraSystemPrompt =
vi.mocked(runEmbeddedPiAgent).mock.calls.at(-1)?.[0]
?.extraSystemPrompt ?? "";
expect(extraSystemPrompt).toBe(
'You are replying inside the WhatsApp group "Ops". Activation: trigger-only (you are invoked only when explicitly mentioned; recent context may be included). Address the specific sender noted in the message context.',
);
});
});
it("labels Telegram groups using their own surface", async () => {
const commandSpy = vi
.spyOn(commandReply, "runCommandReply")
.mockResolvedValue({ payloads: [{ text: "ok" }], meta: { durationMs: 1 } });
await withTempHome(async (home) => {
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
payloads: [{ text: "ok" }],
meta: {
durationMs: 1,
agentMeta: { sessionId: "s", provider: "p", model: "m" },
},
});
await getReplyFromConfig(
{
Body: "ping",
From: "group:tg",
To: "+1777",
ChatType: "group",
GroupSubject: "Dev Chat",
Surface: "telegram",
},
{},
baseCfg,
);
await getReplyFromConfig(
{
Body: "ping",
From: "group:tg",
To: "+1777",
ChatType: "group",
GroupSubject: "Dev Chat",
Surface: "telegram",
},
{},
makeCfg(home),
);
expect(commandSpy).toHaveBeenCalledOnce();
const body =
commandSpy.mock.calls.at(-1)?.[0]?.templatingCtx.Body ?? "";
const intro = body.split("\n\n")[0];
expect(intro).toBe(
'You are replying inside the Telegram group "Dev Chat". Address the specific sender noted in the message context.',
);
expect(runEmbeddedPiAgent).toHaveBeenCalledOnce();
const extraSystemPrompt =
vi.mocked(runEmbeddedPiAgent).mock.calls.at(-1)?.[0]
?.extraSystemPrompt ?? "";
expect(extraSystemPrompt).toBe(
'You are replying inside the Telegram group "Dev Chat". Activation: trigger-only (you are invoked only when explicitly mentioned; recent context may be included). Address the specific sender noted in the message context.',
);
});
});
});

View File

@@ -29,6 +29,7 @@ describe("healthCommand", () => {
connect: { ok: true, elapsedMs: 10 },
},
telegram: { configured: true, probe: { ok: true, elapsedMs: 1 } },
discord: { configured: false },
heartbeatSeconds: 60,
sessions: {
path: "/tmp/sessions.json",
@@ -54,6 +55,7 @@ describe("healthCommand", () => {
durationMs: 5,
web: { linked: false, authAgeMs: null },
telegram: { configured: false },
discord: { configured: false },
heartbeatSeconds: 60,
sessions: { path: "/tmp/sessions.json", count: 0, recent: [] },
} satisfies HealthSummary);

View File

@@ -13,14 +13,13 @@ export function isVerbose() {
}
export function logVerbose(message: string) {
// if (globalVerbose) {
if (!globalVerbose) return;
console.log(chalk.gray(message));
try {
getLogger().debug({ message }, "verbose");
} catch {
// ignore logger failures to avoid breaking verbose printing
}
// }
}
export function setYes(v: boolean) {