fix: unify inbound sender labels

This commit is contained in:
Peter Steinberger
2026-01-17 05:21:02 +00:00
parent 572e04d5fb
commit f7089cde54
20 changed files with 587 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { formatAgentEnvelope } from "./envelope.js";
import { formatAgentEnvelope, formatInboundEnvelope } from "./envelope.js";
describe("formatAgentEnvelope", () => {
it("includes channel, from, ip, host, and timestamp", () => {
@@ -43,3 +43,38 @@ describe("formatAgentEnvelope", () => {
expect(body).toBe("[Telegram] hi");
});
});
describe("formatInboundEnvelope", () => {
it("prefixes sender for non-direct chats", () => {
const body = formatInboundEnvelope({
channel: "Discord",
from: "Guild #general",
body: "hi",
chatType: "channel",
senderLabel: "Alice",
});
expect(body).toBe("[Discord Guild #general] Alice: hi");
});
it("uses sender fields when senderLabel is missing", () => {
const body = formatInboundEnvelope({
channel: "Signal",
from: "Signal Group id:123",
body: "ping",
chatType: "group",
sender: { name: "Bob", id: "42" },
});
expect(body).toBe("[Signal Signal Group id:123] Bob (42): ping");
});
it("keeps direct messages unprefixed", () => {
const body = formatInboundEnvelope({
channel: "iMessage",
from: "+1555",
body: "hello",
chatType: "direct",
senderLabel: "Alice",
});
expect(body).toBe("[iMessage +1555] hello");
});
});