fix: strip envelopes in chat history

This commit is contained in:
Peter Steinberger
2026-01-19 22:48:47 +00:00
parent 4bac76e66d
commit 44c61a77c5
4 changed files with 136 additions and 1 deletions

View File

@@ -303,6 +303,47 @@ describe("gateway server chat", () => {
await server.close();
});
test("chat.history strips inbound envelopes for user messages", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gw-"));
testState.sessionStorePath = path.join(dir, "sessions.json");
await writeSessionStore({
entries: {
main: {
sessionId: "sess-main",
updatedAt: Date.now(),
},
},
});
const enveloped = "[WebChat agent:main:main +2m 2026-01-19 09:29 UTC] hello world";
await fs.writeFile(
path.join(dir, "sess-main.jsonl"),
JSON.stringify({
message: {
role: "user",
content: [{ type: "text", text: enveloped }],
timestamp: Date.now(),
},
}),
"utf-8",
);
const { server, ws } = await startServerWithClient();
await connectOk(ws);
const res = await rpcReq<{ messages?: unknown[] }>(ws, "chat.history", {
sessionKey: "main",
});
expect(res.ok).toBe(true);
const message = (res.payload?.messages ?? [])[0] as
| { content?: Array<{ text?: string }> }
| undefined;
expect(message?.content?.[0]?.text).toBe("hello world");
ws.close();
await server.close();
});
test("chat.history prefers sessionFile when set", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-gw-"));
testState.sessionStorePath = path.join(dir, "sessions.json");