Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

test(types): regression test that ContextHeader is hidden from JSON

Claude2feab191bb77
diff --git a/internal/types/chunk_contextheader_test.go b/internal/types/chunk_contextheader_test.go
new file mode 100644
index 000000000..cb85c7b2d
--- /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")
+ }
+}