// approved_db_forward_copy_test.go package main import ( "fmt" "os" "regexp" "strconv" "strings" "testing" ) // The copy gate of the db region forward plans (spec 2026-10-22 ยง10), the // region HA 2b gate over this record: // // - TestDBForwardCopyRecordIsComplete: the record names exactly // dbForwardCopyIDs; // - TestDBForwardCopyHasNoEmDash; // - TestDBForwardBuiltCopyIsApproved: an id in dbForwardCopyBuilt is an // approved row. No pending string reaches code or docs; // - TestDBForwardBuiltCopyIsApplied: a built row's text is in the file it // names. const dbForwardCopyRecordPath = "docs/superpowers/plans/2026-10-22-db-region-forward-copy.md" var dbForwardCopyIDPattern = regexp.MustCompile(`^DBF-[0-9]+$`) // dbForwardCopyIDs is the record's inventory, pinned: DBF-1 to DBF-20, // DBF-23 and DBF-24 (plan 3's pull rows among them), then DBF-21, DBF-22, // DBF-30, DBF-31 and DBF-32. var dbForwardCopyIDs = func() []string { ids := make([]string, 0, 27) for i := 1; i <= 24; i++ { if i == 21 || i == 22 { continue // appended below, in the record's order } ids = append(ids, "DBF-"+strconv.Itoa(i)) } return append(ids, "DBF-21", "DBF-22", "DBF-30", "DBF-31", "DBF-32") }() // dbForwardCopyBuilt is every id whose text the code or docs carry. The task // that writes a row's text adds its id here in the same commit, once Paul has // approved the row. var dbForwardCopyBuilt = []string{ "DBF-1", "DBF-2", "DBF-14", "DBF-9", "DBF-10", "DBF-21", "DBF-22", // the console "DBF-3", "DBF-4", "DBF-5", "DBF-6", "DBF-7", "DBF-8", "DBF-11", "DBF-12", "DBF-13", "DBF-15", "DBF-16", "DBF-32", // the CLI "DBF-19", "DBF-20", // the console's pull audit details (plan 3) "DBF-17", "DBF-18", "DBF-24", // the CLI's pull sentences (plan 3) "DBF-23", "DBF-31", // docs/site/cli.md (DBF-23 replaced DBF-30 there) } // dbForwardCopyWired is every id whose PENDING text the code already // carries, behind the console's CARLOS_DB_FORWARD switch, which is off // unless a deployment sets it (plan 2's build, ruling R1: Paul asked for the // feature to work first, and the copy review comes separately). This is the // moves record's D13 rule, a pending sentence only behind a switch that is // off by default, in list form: every DBF sentence in code is reached only // from a console that forwards, so none reaches a person on a deployment // that has not turned forwarding on. The copy review moves each id from here // to dbForwardCopyBuilt, applying Paul's edits in the same commit. Docs rows // are public the moment the site syncs, so they are never wired. Luna // approved every plan 2 row and every plan 3 pull row on 2026-10-23, so the // list is empty and every row is built. var dbForwardCopyWired = []string{} func mustParseDBForwardRecord(t *testing.T) []copyRow { t.Helper() raw, err := os.ReadFile(dbForwardCopyRecordPath) if err != nil { t.Fatal(err) } rows, err := parseCopyTable(string(raw), dbForwardCopyRecordPath, dbForwardCopyIDPattern, "a DBF-") if err != nil { t.Fatal(err) } return rows } func TestDBForwardCopyRecordIsComplete(t *testing.T) { reportAll(t, checkMovesInventory(mustParseDBForwardRecord(t), dbForwardCopyIDs)) } func TestDBForwardCopyHasNoEmDash(t *testing.T) { reportAll(t, checkMovesNoEmDash(mustParseDBForwardRecord(t))) } func TestDBForwardBuiltCopyIsApproved(t *testing.T) { reportAll(t, checkRunBuilt(mustParseDBForwardRecord(t), dbForwardCopyBuilt)) } func TestDBForwardBuiltCopyIsApplied(t *testing.T) { rows := builtRows(mustParseDBForwardRecord(t), dbForwardCopyBuilt) for i := range rows { rows[i].Text = strings.ReplaceAll(rows[i].Text, `\n`, "\n") } reportAll(t, checkRunApplied(rows, ".")) } // checkDBForwardWired: a wired id is a pending row the record has, named // once, not built as well, not a docs row, and its text is in the file it // names (so the review's edits must reach the code). func checkDBForwardWired(rows []copyRow, wired, built []string) []string { byID := map[string]copyRow{} for _, r := range rows { byID[r.ID] = r } isBuilt := map[string]bool{} for _, id := range built { isBuilt[id] = true } var out []string var apply []copyRow seen := map[string]bool{} for _, id := range wired { if seen[id] { out = append(out, fmt.Sprintf("dbForwardCopyWired names %s twice", id)) } seen[id] = true r, ok := byID[id] switch { case !ok: out = append(out, fmt.Sprintf("dbForwardCopyWired names %s, which the record has no row for", id)) continue case isBuilt[id]: out = append(out, fmt.Sprintf("%s is both wired and built: an approved row moves to dbForwardCopyBuilt", id)) case r.Status != "pending": out = append(out, fmt.Sprintf("%s is %s: an approved row moves from dbForwardCopyWired to dbForwardCopyBuilt", id, r.Status)) case strings.HasPrefix(r.Path(), "docs/"): out = append(out, fmt.Sprintf("%s is a docs row: pending docs text is never wired", id)) } r.Status = "approved" // checkMovesApplied reads approved rows only apply = append(apply, r) } return append(out, checkMovesApplied(apply, ".")...) } func TestDBForwardWiredCopyIsPendingAndApplied(t *testing.T) { rows := mustParseDBForwardRecord(t) for i := range rows { rows[i].Text = strings.ReplaceAll(rows[i].Text, `\n`, "\n") } reportAll(t, checkDBForwardWired(rows, dbForwardCopyWired, dbForwardCopyBuilt)) } // The gate bites: a wired row whose text is not in its file, an approved // row left wired, and a docs row wired are each refused. func TestDBForwardWiredGateRefuses(t *testing.T) { rows := []copyRow{ {"DBF-1", "internal/console/apidbforward.go", "nothing like this sentence is in the file.", "pending"}, {"DBF-2", "internal/console/apidbforward.go", "x", "approved"}, {"DBF-30", "docs/site/cli.md", "x", "pending"}, } got := checkDBForwardWired(rows, []string{"DBF-1", "DBF-2", "DBF-30"}, nil) for _, want := range []string{"does not contain the approved text", "DBF-2 is approved", "DBF-30 is a docs row"} { found := false for _, g := range got { found = found || strings.Contains(g, want) } if !found { t.Errorf("no problem saying %q in %q", want, got) } } }