From 2feab191bb77342d0a53efcb4c663ade02eea59e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 2 May 2026 10:17:54 +0000 Subject: [PATCH] test(types): regression test that ContextHeader is hidden from JSON Locks in two invariants exposed during the integration audit: - ContextHeader on types.Chunk must never leak into the JSON representation served to API clients (json:"-" + gorm:"-"). - types.ParsedChunk.EmbeddingContent prepends ContextHeader with a blank line separator and falls back to plain Content when the header is unset. https://claude.ai/code/session_01XADhx6mtu2ZYW3DE9Lun6k --- internal/types/chunk_contextheader_test.go | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 internal/types/chunk_contextheader_test.go diff --git a/internal/types/chunk_contextheader_test.go b/internal/types/chunk_contextheader_test.go new file mode 100644 index 00000000..cb85c7b2 --- /dev/null +++ b/internal/types/chunk_contextheader_test.go @@ -0,0 +1,35 @@ +package types + +import ( + "encoding/json" + "strings" + "testing" +) + +func TestChunkContextHeaderHiddenInJSON(t *testing.T) { + c := Chunk{ + ID: "test", + Content: "body", + ContextHeader: "# Heading", + } + b, err := json.Marshal(c) + if err != nil { + t.Fatal(err) + } + if strings.Contains(string(b), "Heading") || strings.Contains(string(b), "context_header") { + t.Errorf("ContextHeader leaked into JSON: %s", string(b)) + } +} + +func TestParsedChunkEmbeddingContent(t *testing.T) { + pc := ParsedChunk{Content: "body", ContextHeader: "# H"} + got := pc.EmbeddingContent() + want := "# H\n\nbody" + if got != want { + t.Errorf("EmbeddingContent mismatch: got %q, want %q", got, want) + } + pc2 := ParsedChunk{Content: "only body"} + if pc2.EmbeddingContent() != "only body" { + t.Errorf("EmbeddingContent without header should equal Content") + } +}