package digest // P5a task 07: a digest of a PDF cites pages. The page markers come from internal/pdfdoc; the // prompt tells the model to use them, and the prompt version moves so cached digests made with // the old prompt are not served. import ( "regexp" "strconv" "strings" "testing" ) func TestPromptCitesPages(t *testing.T) { if !strings.Contains(systemPrompt, "--- page N ---") || !strings.Contains(systemPrompt, "(p. N)") { t.Errorf("system prompt must tell the model to cite pages from --- page N --- markers:\n%s", systemPrompt) } if PromptVersion == "2" { t.Error("PromptVersion must change with the prompt (was \"2\")") } } // Page markers survive chunking whole: none is cut across two chunks. (This holds for today's // Split, whose paragraph boundaries fall around each marker; the test keeps it that way.) func TestSplitKeepsPageMarkers(t *testing.T) { var b strings.Builder for p := 1; p <= 40; p++ { b.WriteString("--- page " + strconv.Itoa(p) + " ---\n\n") b.WriteString(strings.Repeat("word ", 600)) b.WriteString("\n\n") } marker := regexp.MustCompile(`--- page \d+ ---`) n := 0 for _, c := range Split(b.String(), ChunkTokens) { n += len(marker.FindAllString(c, -1)) } if n != 40 { t.Errorf("%d whole page markers across the chunks, want 40", n) } }