Files
sift/docs/plans/p5a/_files/internal/digest/pages_test.go
T
kyleandClaude Opus 5.5 cfde35397a P5a plan: PDF documents — seven Ornith tasks with acceptance tests first
docs/plans/p5a: 01 kind+fetch limits, 02 pdftext child + runner, 03 dcache PDF tables,
04 pdfpool, 05 pdfdoc render (map/pages/grep), 06 api, 07 digest citations, metrics, CLI,
skill, unit, README. Given tests compile against a panic-only skeleton and fail there for the
intended reasons; PDFs for tests are built by internal/pdftest (given), plus two qpdf-encrypted
fixtures.

Owner changes for the run: vendor go-pdfkit/extract v0.3.0 + reader v0.6.0 (pinned via
tools.go until task 02); AGENTS.md, tools/run-plan.sh (enforces a Co-Authored-By trailer for
the model), docs/implementer-log.md, `make gate`; gofmt (whitespace) on clean.go and guard;
TestUnsupportedType uses a zip now that PDFs are supported; requestDeadline 90→210 s and
writeTimeout 120→240 s for the PDF path's worst case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 20:47:38 -07:00

41 lines
1.3 KiB
Go

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)
}
}