rony-chat-bot/internal/portfolio/chunker_test.go
Victor Hugo Vargas f33708534a feat: bootstrap rony-chat-bot Go module
Initial implementation of the bot:

- cmd/chat-bot: CLI entrypoint (serve, reindex, ask, version)
- internal/agent: LLM provider client + agent runner with RAG injection
- internal/config: YAML config loader (providers, RAG, persona, server)
- internal/i18n: response-language detection (EN/ES)
- internal/persona: persona system prompt assembly from YAML
- internal/portfolio: heading-based chunker + SQLite FTS5 indexer
- internal/server: chi router with /api/chat (SSE), /api/health, /api/info,
  /api/reindex, middleware (RequestID, Logging, CORS, RateLimit)
- internal/streaming: SSE protocol helpers (start, chunk, sources, done, error)
- web/: drop-in vanilla-JS chat widget (no build, no deps) + demo + README
- bench/: reproducible driver benchmark (modernc vs mattn SQLite)
- configs/portfolio-bot.yaml: llama.cpp default provider, SQLite RAG, canine persona
- docs/architecture.md / .es.md: aligned with SQLite FTS5 + llama.cpp decisions
- data/projects/README*.md: project data documentation
- README.md / .es.md: updated for current implementation

All tests pass (go test ./...). Bot is functional end-to-end with the
configured LLM provider.
2026-07-17 00:56:06 -07:00

111 lines
No EOL
1.8 KiB
Go

package portfolio
import (
"strings"
"testing"
)
func TestSplitMarkdownSections(t *testing.T) {
cases := []struct {
name string
input string
wantCount int
wantHeading []string
}{
{
name: "frontmatter only",
input: `---
title: "Foo"
tags: ["go"]
---
# Foo
Body of foo.`,
wantCount: 2,
wantHeading: []string{"frontmatter", "Foo"},
},
{
name: "no frontmatter, multiple H2s",
input: `# Title
intro paragraph
## Description
description body
## Tech stack
- Go
- SQLite`,
wantCount: 3,
wantHeading: []string{"Title", "Description", "Tech stack"},
},
{
name: "H3 stays under parent H2",
input: `# T
## Section
content
### H3 detail
H3 content stays here`,
wantCount: 1, // T has no body → dropped; H3 content folds into Section
wantHeading: []string{"Section"},
},
{
name: "drop empty section",
input: `## X
ok
## Empty
## Y
content`,
wantCount: 2,
wantHeading: []string{"X", "Y"},
},
{
name: "long H2 sub-splits",
input: "## Long\n" + strings.Repeat("a ", 800),
wantCount: 2, // 2 sub-splits of Long
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := SplitMarkdownSections(c.input, DefaultChunkerConfig())
if len(got) != c.wantCount {
t.Errorf("got %d chunks, want %d. Headings: %v", len(got), c.wantCount, headings(got))
}
if c.wantHeading != nil {
if !equalSlice(headings(got), c.wantHeading) {
t.Errorf("headings = %v, want %v", headings(got), c.wantHeading)
}
}
})
}
}
func headings(sections []section) []string {
out := make([]string, len(sections))
for i, s := range sections {
out[i] = s.Heading
}
return out
}
func equalSlice(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}