carlos / platform Public

test: every approved nearest-region string is applied, and the record lists the whole inventory (nearest-region Task 25)

TestApprovedCopyIsApplied reads the approved copy record and checks that
each entry's text is in the file it names. It also pins the plan's copy
inventory (121 ids) as a literal, so a record that drops an entry, repeats
one or adds one fails. A short text (under 25 bytes) in a Go file must be
a whole string literal, in Go-quoted or backtick form, so a word like
"Region" cannot pass by appearing in a comment. The usage fragments U1 to
U3 are checked against string literal values. Docs and scripts match raw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e34f5964a0491894afcc513bbe4c45885ffe7d20 parent 6bb6860
1 file changed, +162 −0
  • approved_copy_test.go +162 −0
diff --git a/approved_copy_test.go b/approved_copy_test.go
new file mode 100644
index 000000000..90dd14401
--- /dev/null
+++ b/approved_copy_test.go
@@ -0,0 +1,162 @@
+// approved_copy_test.go
+package main
+
+import (
+ "bytes"
+ "encoding/json"
+ "go/scanner"
+ "go/token"
+ "os"
+ "path/filepath"
+ "sort"
+ "strconv"
+ "strings"
+ "testing"
+)
+
+// approvedCopyIDs is the copy inventory of the nearest-region plan, Task 0
+// Step 1, pinned as a literal: C1 to C31, R-*, O1 to O20, U, S, G, the 34
+// C23 place names, D1 to D10 and F1. The record must name every one of them,
+// once, and nothing else. A record that loses an entry fails here even though
+// every entry left in it is applied.
+var approvedCopyIDs = []string{
+ "C1", "C2", "C3", "C5", "C7", "C8", "C21", "C24", "R-absent",
+ "R-not-hosting", "R-no-secrets-key", "R-not-eligible", "C16",
+ "C17", "C18", "C19", "C16b", "C17b", "C18b", "C19b", "C20", "C26",
+ "C27", "C28", "C29", "C31", "O1", "O2", "O3", "O4", "O5", "O6",
+ "O7", "O8", "O9", "O10", "O11", "O12", "O13", "O14", "O15", "O16",
+ "O17", "O18", "O19", "O20", "C9", "C10", "C11", "C12", "C13a",
+ "C13b", "C14", "C15", "C15b", "C15c", "C25", "C30", "C30b", "C30c",
+ "C22a", "C22b", "C22c", "C22d", "U1", "U2", "U3", "S1", "S2",
+ "S3", "G1", "G2", "G3", "G4", "G5", "G6", "C23-us-east-1", "C23-us-east-2",
+ "C23-us-west-1", "C23-us-west-2", "C23-ca-central-1", "C23-ca-west-1",
+ "C23-mx-central-1", "C23-sa-east-1", "C23-eu-west-1", "C23-eu-west-2",
+ "C23-eu-west-3", "C23-eu-central-1", "C23-eu-central-2", "C23-eu-south-1",
+ "C23-eu-south-2", "C23-eu-north-1", "C23-il-central-1", "C23-me-south-1",
+ "C23-me-central-1", "C23-af-south-1", "C23-ap-south-1", "C23-ap-south-2",
+ "C23-ap-east-1", "C23-ap-east-2", "C23-ap-southeast-1", "C23-ap-southeast-2",
+ "C23-ap-southeast-3", "C23-ap-southeast-4", "C23-ap-southeast-5",
+ "C23-ap-southeast-6", "C23-ap-southeast-7", "C23-ap-northeast-1",
+ "C23-ap-northeast-2", "C23-ap-northeast-3", "D1", "D2", "D3",
+ "D4", "D5", "D6", "D7", "D8", "D9", "D10", "F1",
+}
+
+// approvedCopyFragments are record entries whose text is a piece of a larger
+// string literal (a flag inside a usage line), so no Go-quoted form of the
+// text alone can appear in the file. They are checked against the values of
+// the file's string literals instead of its raw bytes.
+var approvedCopyFragments = map[string]bool{"U1": true, "U2": true, "U3": true}
+
+// shortCopyBytes is the length under which a text is a word or a flag name.
+// A short text could appear by accident (the word "Region" in a comment), so
+// in a Go file it must appear as a whole string literal, in its Go-quoted
+// form or its backtick form.
+const shortCopyBytes = 25
+
+// Every string Paul approved in the nearest-region copy review is present,
+// byte for byte, in the file the record names (codex plan-R1 13). A string
+// edited after review, or never applied, fails here, and so does an approved
+// string the record no longer lists.
+func TestApprovedCopyIsApplied(t *testing.T) {
+ raw, err := os.ReadFile("docs/superpowers/plans/2026-10-02-nearest-region-copy.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ checkApprovedCopy(t, raw, ".")
+}
+
+// checkApprovedCopy checks a record against the files under root.
+func checkApprovedCopy(t *testing.T, raw []byte, root string) {
+ t.Helper()
+ var rec struct {
+ ApprovedBy string `json:"approved_by"`
+ ApprovedOn string `json:"approved_on"`
+ Entries []struct{ ID, File, Text string }
+ }
+ if err := json.Unmarshal(raw, &rec); err != nil {
+ t.Fatal(err)
+ }
+ if rec.ApprovedBy == "" || rec.ApprovedOn == "" || len(rec.Entries) == 0 {
+ t.Fatalf("the record has no approval: %+v", rec)
+ }
+
+ seen := map[string]int{}
+ for _, e := range rec.Entries {
+ seen[e.ID]++
+ }
+ want := map[string]bool{}
+ for _, id := range approvedCopyIDs {
+ want[id] = true
+ if seen[id] == 0 {
+ t.Errorf("the record has no entry %s, which the plan's copy inventory names", id)
+ }
+ }
+ var extra []string
+ for id, n := range seen {
+ if n > 1 {
+ t.Errorf("the record names %s %d times", id, n)
+ }
+ if !want[id] {
+ extra = append(extra, id)
+ }
+ }
+ sort.Strings(extra)
+ for _, id := range extra {
+ t.Errorf("the record has entry %s, which the pinned inventory does not name (add it to approvedCopyIDs)", id)
+ }
+
+ for _, e := range rec.Entries {
+ if e.Text == "" {
+ t.Errorf("%s: the approved text is empty", e.ID)
+ continue
+ }
+ body, err := os.ReadFile(filepath.Join(root, e.File))
+ if err != nil {
+ t.Errorf("%s: %v", e.ID, err)
+ continue
+ }
+ if !copyApplied(e.ID, e.File, e.Text, body) {
+ t.Errorf("%s: %s does not contain the approved text %q", e.ID, e.File, e.Text)
+ }
+ }
+}
+
+// copyApplied reports whether body holds the approved text. Docs, scripts and
+// long Go texts match raw. A short text in a Go file must be a whole string
+// literal, so a word cannot pass by appearing elsewhere in the file.
+func copyApplied(id, file, text string, body []byte) bool {
+ if !strings.HasSuffix(file, ".go") {
+ return bytes.Contains(body, []byte(text))
+ }
+ if approvedCopyFragments[id] {
+ return goLiteralContains(body, text)
+ }
+ if len(text) >= shortCopyBytes {
+ return bytes.Contains(body, []byte(text))
+ }
+ if bytes.Contains(body, []byte(strconv.Quote(text))) {
+ return true
+ }
+ return !strings.Contains(text, "`") && bytes.Contains(body, []byte("`"+text+"`"))
+}
+
+// goLiteralContains reports whether the value of any string literal in the Go
+// source contains text.
+func goLiteralContains(src []byte, text string) bool {
+ fset := token.NewFileSet()
+ file := fset.AddFile("", fset.Base(), len(src))
+ var s scanner.Scanner
+ s.Init(file, src, nil, 0)
+ for {
+ _, tok, lit := s.Scan()
+ if tok == token.EOF {
+ return false
+ }
+ if tok != token.STRING {
+ continue
+ }
+ if v, err := strconv.Unquote(lit); err == nil && strings.Contains(v, text) {
+ return true
+ }
+ }
+}