Files
davidandClaude Opus 5.5 fdfbcd3d3d Phase 7 part 5: add a section to an existing page
Sites → Sections and pages → Add a section, on any page built from
sections: choose one of the site's section types and where it goes; the
AI writes it from the page, its searches, the profile and the Inventory,
with the same rules as a new page. It's reviewed like a page (claims to
confirm, to-dos), and the pull request inserts it into the page's file as
text, so only that section is added; the build checks it. What to write
next suggests a FAQ for a section page found with questions, and a
comparison for one searched against something else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 07:25:19 -07:00

61 lines
2.1 KiB
Go

package sites
import (
"strings"
"testing"
)
const pageFile = `---
title: "FreeScout"
description: Help desk you own
sections:
- type: hero
heading: FreeScout, hosted
- type: text
body: |
Two lines
of text.
- type: final-cta
heading: Start now
menu: main
---
Body text.
`
func TestInsertSection(t *testing.T) {
yamlText, types, err := PageSections([]byte(pageFile))
if err != nil || strings.Join(types, ",") != "hero,text,final-cta" || !strings.Contains(yamlText, "FreeScout, hosted") {
t.Fatalf("sections: %v %q %v", types, yamlText, err)
}
faq := "- type: faq\n heading: Questions\n items:\n - q: Is it hosted?\n a: Yes.\n"
out, err := InsertSection([]byte(pageFile), faq, 2)
if err != nil {
t.Fatal(err)
}
got := string(out)
want := " of text.\n - type: faq\n heading: Questions\n items:\n - q: Is it hosted?\n a: Yes.\n - type: final-cta\n"
if !strings.Contains(got, want) || !strings.HasSuffix(got, "menu: main\n---\nBody text.\n") || !strings.HasPrefix(got, "---\ntitle: \"FreeScout\"\n") {
t.Errorf("inserted:\n%s", got)
}
if _, types, _ := PageSections(out); strings.Join(types, ",") != "hero,text,faq,final-cta" {
t.Errorf("types after: %v", types)
}
// At the end: before the next key.
out, err = InsertSection([]byte(pageFile), faq, 99)
if _, types, _ := PageSections(out); err != nil || strings.Join(types, ",") != "hero,text,final-cta,faq" || !strings.Contains(string(out), " a: Yes.\nmenu: main\n") {
t.Errorf("at the end: %v %v\n%s", types, err, out)
}
// Sections last in the front matter.
last := "---\ntitle: X\nsections:\n- type: hero\n heading: Hi\n---\n"
out, err = InsertSection([]byte(last), faq, 1)
if _, types, _ := PageSections(out); err != nil || strings.Join(types, ",") != "hero,faq" || !strings.HasSuffix(string(out), " a: Yes.\n---\n") {
t.Errorf("last: %v %v\n%s", types, err, out)
}
if _, err := InsertSection([]byte(pageFile), "- type: faq\n- type: text\n", 0); err == nil {
t.Error("took two sections")
}
if _, err := InsertSection([]byte("+++\ntitle = 'x'\n+++\n"), faq, 0); err == nil {
t.Error("took TOML")
}
}