refactor: extract gateway transcript append helper

This commit is contained in:
Peter Steinberger
2026-02-22 14:43:44 +00:00
parent 8e6b465fa8
commit 142c0a7f7d
5 changed files with 121 additions and 109 deletions

View File

@@ -224,14 +224,18 @@ describe("sanitizeChatSendMessageInput", () => {
});
describe("gateway chat transcript writes (guardrail)", () => {
it("does not append transcript messages via raw fs.appendFileSync(transcriptPath, ...)", () => {
it("routes transcript writes through helper and SessionManager parentId append", () => {
const chatTs = fileURLToPath(new URL("./chat.ts", import.meta.url));
const src = fs.readFileSync(chatTs, "utf-8");
const chatSrc = fs.readFileSync(chatTs, "utf-8");
const helperTs = fileURLToPath(new URL("./chat-transcript-inject.ts", import.meta.url));
const helperSrc = fs.readFileSync(helperTs, "utf-8");
expect(src.includes("fs.appendFileSync(transcriptPath")).toBe(false);
expect(chatSrc.includes("fs.appendFileSync(transcriptPath")).toBe(false);
expect(chatSrc).toContain("appendInjectedAssistantMessageToTranscript(");
expect(src).toContain("SessionManager.open(transcriptPath)");
expect(src).toContain("appendMessage(");
expect(helperSrc.includes("fs.appendFileSync(params.transcriptPath")).toBe(false);
expect(helperSrc).toContain("SessionManager.open(params.transcriptPath)");
expect(helperSrc).toContain("appendMessage(messageBody)");
});
});