fix: sender fallback for command auth (#755) (thanks @juanpablodlc)
This commit is contained in:
@@ -61,6 +61,7 @@
|
|||||||
- Agents: stop pre-creating session transcripts so first user messages persist in JSONL history.
|
- Agents: stop pre-creating session transcripts so first user messages persist in JSONL history.
|
||||||
- Auto-reply: align `/think` default display with model reasoning defaults. (#751) — thanks @gabriel-trigo.
|
- Auto-reply: align `/think` default display with model reasoning defaults. (#751) — thanks @gabriel-trigo.
|
||||||
- Auto-reply: flush block reply buffers on tool boundaries. (#750) — thanks @sebslight.
|
- Auto-reply: flush block reply buffers on tool boundaries. (#750) — thanks @sebslight.
|
||||||
|
- Auto-reply: allow sender fallback for command authorization when `SenderId` is empty (WhatsApp self-chat). (#755) — thanks @juanpablodlc.
|
||||||
- Heartbeat: refresh prompt text for updated defaults.
|
- Heartbeat: refresh prompt text for updated defaults.
|
||||||
- Agents/Tools: use PowerShell on Windows to capture system utility output. (#748) — thanks @myfunc.
|
- Agents/Tools: use PowerShell on Windows to capture system utility output. (#748) — thanks @myfunc.
|
||||||
- Docker: tolerate unset optional env vars in docker-setup.sh under strict mode. (#725) — thanks @petradonka.
|
- Docker: tolerate unset optional env vars in docker-setup.sh under strict mode. (#725) — thanks @petradonka.
|
||||||
|
|||||||
@@ -726,7 +726,8 @@ describe("runEmbeddedPiAgent", () => {
|
|||||||
const messages = await readSessionMessages(sessionFile);
|
const messages = await readSessionMessages(sessionFile);
|
||||||
const firstUserIndex = messages.findIndex(
|
const firstUserIndex = messages.findIndex(
|
||||||
(message) =>
|
(message) =>
|
||||||
message?.role === "user" && textFromContent(message.content) === "hello",
|
message?.role === "user" &&
|
||||||
|
textFromContent(message.content) === "hello",
|
||||||
);
|
);
|
||||||
const firstAssistantIndex = messages.findIndex(
|
const firstAssistantIndex = messages.findIndex(
|
||||||
(message) => message?.role === "assistant",
|
(message) => message?.role === "assistant",
|
||||||
@@ -836,7 +837,8 @@ describe("runEmbeddedPiAgent", () => {
|
|||||||
);
|
);
|
||||||
const newUserIndex = messages.findIndex(
|
const newUserIndex = messages.findIndex(
|
||||||
(message) =>
|
(message) =>
|
||||||
message?.role === "user" && textFromContent(message.content) === "hello",
|
message?.role === "user" &&
|
||||||
|
textFromContent(message.content) === "hello",
|
||||||
);
|
);
|
||||||
const newAssistantIndex = messages.findIndex(
|
const newAssistantIndex = messages.findIndex(
|
||||||
(message, index) => index > newUserIndex && message?.role === "assistant",
|
(message, index) => index > newUserIndex && message?.role === "assistant",
|
||||||
@@ -887,10 +889,12 @@ describe("runEmbeddedPiAgent", () => {
|
|||||||
const messages = await readSessionMessages(sessionFile);
|
const messages = await readSessionMessages(sessionFile);
|
||||||
const firstUserIndex = messages.findIndex(
|
const firstUserIndex = messages.findIndex(
|
||||||
(message) =>
|
(message) =>
|
||||||
message?.role === "user" && textFromContent(message.content) === "first",
|
message?.role === "user" &&
|
||||||
|
textFromContent(message.content) === "first",
|
||||||
);
|
);
|
||||||
const firstAssistantIndex = messages.findIndex(
|
const firstAssistantIndex = messages.findIndex(
|
||||||
(message, index) => index > firstUserIndex && message?.role === "assistant",
|
(message, index) =>
|
||||||
|
index > firstUserIndex && message?.role === "assistant",
|
||||||
);
|
);
|
||||||
const secondUserIndex = messages.findIndex(
|
const secondUserIndex = messages.findIndex(
|
||||||
(message) =>
|
(message) =>
|
||||||
|
|||||||
30
src/auto-reply/command-auth.test.ts
Normal file
30
src/auto-reply/command-auth.test.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
|
import { resolveCommandAuthorization } from "./command-auth.js";
|
||||||
|
import type { MsgContext } from "./templating.js";
|
||||||
|
|
||||||
|
describe("resolveCommandAuthorization", () => {
|
||||||
|
it("falls back from empty SenderId to SenderE164", () => {
|
||||||
|
const cfg = {
|
||||||
|
whatsapp: { allowFrom: ["+123"] },
|
||||||
|
} as ClawdbotConfig;
|
||||||
|
|
||||||
|
const ctx = {
|
||||||
|
Provider: "whatsapp",
|
||||||
|
Surface: "whatsapp",
|
||||||
|
From: "whatsapp:+999",
|
||||||
|
SenderId: "",
|
||||||
|
SenderE164: "+123",
|
||||||
|
} as MsgContext;
|
||||||
|
|
||||||
|
const auth = resolveCommandAuthorization({
|
||||||
|
ctx,
|
||||||
|
cfg,
|
||||||
|
commandAuthorized: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(auth.senderId).toBe("+123");
|
||||||
|
expect(auth.isAuthorizedSender).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -520,7 +520,7 @@ describe("trigger handling", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles inline /status and still runs the agent", async () => {
|
it("strips inline /status and still runs the agent", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||||
payloads: [{ text: "ok" }],
|
payloads: [{ text: "ok" }],
|
||||||
@@ -535,6 +535,9 @@ describe("trigger handling", () => {
|
|||||||
Body: "please /status now",
|
Body: "please /status now",
|
||||||
From: "+1002",
|
From: "+1002",
|
||||||
To: "+2000",
|
To: "+2000",
|
||||||
|
Provider: "whatsapp",
|
||||||
|
Surface: "whatsapp",
|
||||||
|
SenderE164: "+1002",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onBlockReply: async (payload) => {
|
onBlockReply: async (payload) => {
|
||||||
@@ -543,9 +546,11 @@ describe("trigger handling", () => {
|
|||||||
},
|
},
|
||||||
makeCfg(home),
|
makeCfg(home),
|
||||||
);
|
);
|
||||||
expect(blockReplies.length).toBe(1);
|
|
||||||
expect(blockReplies[0]?.text).toBeTruthy();
|
|
||||||
expect(runEmbeddedPiAgent).toHaveBeenCalled();
|
expect(runEmbeddedPiAgent).toHaveBeenCalled();
|
||||||
|
expect(blockReplies.length).toBe(0);
|
||||||
|
const prompt =
|
||||||
|
vi.mocked(runEmbeddedPiAgent).mock.calls[0]?.[0]?.prompt ?? "";
|
||||||
|
expect(prompt).not.toContain("/status");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -712,7 +717,7 @@ describe("trigger handling", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps inline /status for unauthorized senders", async () => {
|
it("strips inline /status for unauthorized senders", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||||
payloads: [{ text: "ok" }],
|
payloads: [{ text: "ok" }],
|
||||||
@@ -749,7 +754,7 @@ describe("trigger handling", () => {
|
|||||||
expect(runEmbeddedPiAgent).toHaveBeenCalled();
|
expect(runEmbeddedPiAgent).toHaveBeenCalled();
|
||||||
const prompt =
|
const prompt =
|
||||||
vi.mocked(runEmbeddedPiAgent).mock.calls[0]?.[0]?.prompt ?? "";
|
vi.mocked(runEmbeddedPiAgent).mock.calls[0]?.[0]?.prompt ?? "";
|
||||||
expect(prompt).toContain("/status");
|
expect(prompt).not.toContain("/status");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user