Skip to content

Commit b746c8b

Browse files
committed
test(imessage): cover code-aware marker stripping
1 parent 63dae81 commit b746c8b

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

‎extensions/imessage/src/monitor/sanitize-outbound.test-support.ts‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,37 @@ describe("sanitizeOutboundText", () => {
6363
expect(sanitizeOutboundText(text)).toBe("Hello\n\nWorld");
6464
});
6565

66-
it("keeps a bare 'user:' mapping key inside a fenced code block", () => {
67-
const text =
68-
"```yaml\n- name: ensure account\n user:\n name: alice\n state: present\n```";
69-
// The role-turn stripper must not treat a YAML mapping key as a leaked turn
70-
// boundary; deleting `user:` silently reparents its children under the item.
71-
expect(sanitizeOutboundText(text)).toBe(text);
72-
});
73-
74-
it("keeps bare 'system:'/'assistant:' mapping keys inside a fenced code block", () => {
75-
const text = "```yaml\nsystem:\n role: primary\nassistant:\n role: helper\n```";
76-
expect(sanitizeOutboundText(text)).toBe(text);
77-
});
78-
79-
it("still strips a leaked role marker outside a code block while keeping the fenced one", () => {
80-
const text = "assistant:\n```yaml\nuser:\n name: alice\n```";
81-
const result = sanitizeOutboundText(text);
82-
// Leaked standalone marker in prose is removed; the fenced key survives.
83-
expect(result).not.toMatch(/^assistant:$/m);
84-
expect(result).toContain("```yaml\nuser:\n name: alice\n```");
66+
it.each([
67+
{
68+
name: "backtick fence preserves user while stripping prose user",
69+
input: "user:\n```yaml\nuser:\n name: alice\n```",
70+
expected: "```yaml\nuser:\n name: alice\n```",
71+
},
72+
{
73+
name: "tilde fence preserves system while stripping prose system",
74+
input: "system:\n~~~yaml\nsystem:\n enabled: true\n~~~",
75+
expected: "~~~yaml\nsystem:\n enabled: true\n~~~",
76+
},
77+
{
78+
name: "indented code preserves assistant while stripping prose assistant",
79+
input: "keep\n\nassistant:\n\n assistant:\n enabled: true",
80+
expected: "keep\n\n assistant:\n enabled: true",
81+
},
82+
{
83+
name: "unterminated fence preserves every marker family after offset shifts",
84+
input: [
85+
"#+#+#",
86+
"assistant to=final",
87+
"user:",
88+
"```text",
89+
"#+#+#",
90+
"assistant to=tool",
91+
"user:",
92+
].join("\n"),
93+
expected: ["```text", "#+#+#", "assistant to=tool", "user:"].join("\n"),
94+
},
95+
] as const)("$name", ({ input, expected }) => {
96+
expect(sanitizeOutboundText(input)).toBe(expected);
8597
});
8698

8799
it("handles combined internal markers in one message", () => {

0 commit comments

Comments
 (0)