Add context packs impact analysis and message validation

This commit is contained in:
2026-05-07 10:17:24 +08:00
parent f2d0a83705
commit 0c5254eb1b
18 changed files with 780 additions and 13 deletions

View File

@@ -91,6 +91,25 @@ context: Base lottery page.
if !foundTitle {
t.Fatalf("expected canvas node text to include title, got %+v", canvas.Nodes)
}
pack := project.PackFor("page.lottery.main", "implement", "implement", -1, 0, Filter{})
if pack.Summary.UnitCount != 4 {
t.Fatalf("pack unit count = %d", pack.Summary.UnitCount)
}
if !strings.Contains(pack.Markdown(), "GSP Context Pack") {
t.Fatal("expected pack markdown")
}
impact := project.Impact("feedback.positive", -1)
if impact.Summary.DirectCount != 1 {
t.Fatalf("impact direct count = %d", impact.Summary.DirectCount)
}
if impact.Direct[0].ID != "page.lottery.main" {
t.Fatalf("impact direct = %+v", impact.Direct)
}
if !strings.Contains(impact.Markdown(), "GSP Impact") {
t.Fatal("expected impact markdown")
}
}
func TestValidateMissingReference(t *testing.T) {
@@ -263,6 +282,40 @@ func TestInitAIUsageRequiresManifest(t *testing.T) {
}
}
func TestValidateMessage(t *testing.T) {
root := t.TempDir()
if _, err := InitProject(root, InitOptions{
Entry: "page.sample.main",
}); err != nil {
t.Fatal(err)
}
writeTestFile(t, root, "message.gspmsg", `gspMessageVersion: 0.1
id: msg.sample
from: planner
to: implementer
intent: implement
entry: page.sample.main
stage: implement
requires:
- page.sample.main
contextPack:
mode: implement
depth: -1
`)
project, err := LoadProject(root)
if err != nil {
t.Fatal(err)
}
message, err := ReadMessage(project.Root, "message.gspmsg")
if err != nil {
t.Fatal(err)
}
report := project.ValidateMessage(message)
if !report.OK {
t.Fatalf("expected valid message, got %+v", report.Errors)
}
}
func writeTestFile(t *testing.T, root, name, content string) {
t.Helper()
path := filepath.Join(root, name)