package service import ( "github.com/Tencent/WeKnora/internal/types" "testing" ) func TestProcessTextChunksIncludesUnparentedText(t *testing.T) { parent := &types.Chunk{ID: "parent", ChunkType: types.ChunkTypeParentText} child := &types.Chunk{ID: "child", ChunkType: types.ChunkTypeText, ParentChunkID: "parent"} standalone := &types.Chunk{ID: "standalone", ChunkType: types.ChunkTypeText} got := processTextChunks([]*types.Chunk{parent, child, standalone}, true) if len(got) != 2 { t.Fatalf("indexed text count = %d, want 2; unparented text must not disappear in parent-child mode", len(got)) } if got[0] != child || got[1] != standalone { t.Fatal("must preserve text identity/order and exclude parent_text") } if child.NextChunkID != "" || standalone.PreChunkID != "" { t.Fatal("parent-child mode must not create flat adjacency links") } } func TestProcessTextChunksFlatLinks(t *testing.T) { first := &types.Chunk{ID: "first", ChunkType: types.ChunkTypeText} second := &types.Chunk{ID: "second", ChunkType: types.ChunkTypeText} got := processTextChunks([]*types.Chunk{first, {ID: "summary", ChunkType: types.ChunkTypeSummary}, second}, false) if len(got) != 2 || got[0] != first || got[1] != second { t.Fatal("flat text identity/order changed") } if first.NextChunkID != "second" || second.PreChunkID != "first" { t.Fatal("flat adjacency links missing") } } func TestProcessTextChunksParentsOnly(t *testing.T) { if got := processTextChunks([]*types.Chunk{{ID: "parent", ChunkType: types.ChunkTypeParentText}}, true); len(got) != 0 { t.Fatal("parent_text must remain stored-only") } if got := processTextChunks(nil, false); len(got) != 0 { t.Fatal("empty input must remain empty") } }