console: placement guard is a caller census of every placement source
Astra scoped check of the R1 fix wave. The guard now lists every caller of Store.AppPlacement, appPlacementRow, LivePlacesNamed and the route folds (legacyFleetFromRoutes, fleetFromRoutes, firstFleetPlacement), each with its reason. A raw row read must itself call effectivePlacement, and a view's routeFleet may only be an argument to regionFactsFor. Restoring the old regionFactsFor body, a column read plus routeFleet, now fails it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+94
−27
internal/console/placement_census_test.go+94 −27
CI failed — run details
Intent
Attributed to this commit: 44.2 g CO₂e (5,691,770 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on g6-pool, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/placement_census_test.go b/internal/console/placement_census_test.go| index 411f7a7f4..b32140eff 100644 |
| --- a/internal/console/placement_census_test.go |
| +++ b/internal/console/placement_census_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "os" |
| "path/filepath" |
| "regexp" |
| + "slices" |
| "sort" |
| "strconv" |
| "strings" |
| @@ -15,26 +16,70 @@ import ( |
| // TestEffectivePlacementIsTheOnlyRouteFallback keeps "a born-HA app has no |
| // fleet placement" in one place (G6 branch review R1, stopping rule 2 |
| -// option 3): effectivePlacement. Two ways round it fail here. |
| +// option 3): effectivePlacement. It is a caller census over the package's |
| +// non-test files, and a new caller of any placement source fails here |
| +// before it can ship. |
| // |
| -// - A route fold (legacyFleetFromRoutes, fleetFromRoutes) whose answer |
| -// becomes an app's placement must run inside a func literal handed to |
| -// effectivePlacement, which never runs it for a born-HA row. The few |
| -// functions allowed to fold elsewhere are listed with the reason their |
| -// answer cannot place a born-HA app. |
| -// - A SQL statement that SELECTs the apps placement column must be one |
| -// of the listed reads: appPlacementRow and LivePlacesNamed return |
| -// ha_pool beside it for effectivePlacement; the others are named with |
| -// their reason. |
| +// - The route folds (legacyFleetFromRoutes, fleetFromRoutes and the loop |
| +// behind both, firstFleetPlacement) may run inside a func literal handed |
| +// to effectivePlacement, which never runs it for a born-HA row, or in a |
| +// listed function, with the reason its answer cannot place one. |
| +// - The raw row reads (appPlacementRow, LivePlacesNamed) return the |
| +// placement column beside ha_pool; every caller is listed, and each must |
| +// itself call effectivePlacement. |
| +// - Store.AppPlacement (the column with the rule applied) is listed |
| +// caller by caller: a column-only reader is safe, but one that then |
| +// substitutes a route fleet for the empty answer is the bypass this |
| +// census exists to stop. |
| +// - routeFleet, a route fold already made for a view, is read only as an |
| +// argument to regionFactsFor, which runs it through effectivePlacement. |
| +// - A SQL statement that SELECTs the apps placement column is one of the |
| +// listed reads. |
| // |
| -// A new reader fails here before it can ship. |
| +// A listed exception that no longer happens is stale and fails too. |
| func TestEffectivePlacementIsTheOnlyRouteFallback(t *testing.T) { |
| - folds := map[string]bool{"legacyFleetFromRoutes": true, "fleetFromRoutes": true} |
| - foldOK := map[string]string{ |
| - "sealkey.go:backfillAppPlacements": "picks backfill candidates; the write is SetAppPlacementIfContext, which never places a born-HA row", |
| - "sealkey.go:backfillApp": "the backfill's decision under its locks; same guarded write", |
| - "view.go:assembleViews": "routeFleet is display input; regionFactsFor runs it through effectivePlacement", |
| - "apitemporary.go:handleAPIAppList": "routeFleet for regionFactsFor, which runs it through effectivePlacement", |
| + const columnOnly = "column only, no route fallback: Store.AppPlacement applies effectivePlacement" |
| + const fedToFacts = "the fold is a view's routeFleet, handed to regionFactsFor, which runs it through effectivePlacement" |
| + census := map[string]map[string]string{ |
| + "legacyFleetFromRoutes": { |
| + "sealkey.go:backfillAppPlacements": "picks backfill candidates; the write is SetAppPlacementIfContext, which never places a born-HA row", |
| + "sealkey.go:backfillApp": "the backfill's decision under its locks; the same guarded write", |
| + }, |
| + "fleetFromRoutes": { |
| + "view.go:assembleViews": fedToFacts, |
| + "apitemporary.go:handleAPIAppList": fedToFacts, |
| + }, |
| + "firstFleetPlacement": { |
| + "regionfacts.go:legacyFleetFromRoutes": "the fold's own definition", |
| + "regionfacts.go:fleetFromRoutes": "the fold's own definition", |
| + }, |
| + "appPlacementRow": { |
| + "store.go:AppPlacement": "hands both columns to effectivePlacement (no fold)", |
| + "fleets.go:appPlacement": "hands both columns to effectivePlacement", |
| + "fleetsecretskey.go:fleetPlacedAppsIn": "hands both columns to effectivePlacement", |
| + "regionfacts.go:regionFactsFor": "hands both columns to effectivePlacement", |
| + }, |
| + "LivePlacesNamed": { |
| + "regionfacts.go:fleetAppRegions": "hands each row's columns to effectivePlacement", |
| + }, |
| + "AppPlacement": {}, |
| + } |
| + // Raw row reads: the caller must apply the rule itself. |
| + mustApply := map[string]bool{"appPlacementRow": true, "LivePlacesNamed": true} |
| + // Folds: a call inside an effectivePlacement func literal is the rule. |
| + foldInRule := map[string]bool{"legacyFleetFromRoutes": true, "fleetFromRoutes": true} |
| + for where, why := range map[string]string{ |
| + "appcopies.go:copiesRefusal": "a fleet test on the column", |
| + "claim_placement.go:Start": "the claim operation's recorded source", |
| + "plancaps.go:onOwnBoxes": "an empty column falls back through appPlacement", |
| + "replicafloor.go:replicaPolicyBarrier": "a fleet test on the column", |
| + "policysize.go:sizeAppPlacement": "a console with no registry has no route fallback", |
| + "replicaplacement.go:reconcileReplicaApp": "matches the column against a fleet target", |
| + "sealkey.go:sealPlacement": "a console with no registry has no route fallback", |
| + "sealkey.go:backfillAppPlacements": "picks candidates with an empty column; the write is guarded", |
| + "sealkey.go:backfillApp": "re-reads the column under its locks; the write is guarded", |
| + } { |
| + census["AppPlacement"][where] = columnOnly + "; " + why |
| } |
| selectOK := map[string]string{ |
| "store.go:appPlacementRow": "returns ha_pool beside placement for effectivePlacement", |
| @@ -69,10 +114,17 @@ func TestEffectivePlacementIsTheOnlyRouteFallback(t *testing.T) { |
| continue |
| } |
| where := name + ":" + fn.Name.Name |
| - // The func literals handed to effectivePlacement. |
| + // The func literals handed to effectivePlacement, and whether |
| + // the function applies the rule at all. |
| var inside []*ast.FuncLit |
| + var factsArgs []ast.Expr |
| + applies := false |
| ast.Inspect(fn.Body, func(n ast.Node) bool { |
| + if call, ok := n.(*ast.CallExpr); ok && calleeName(call) == "regionFactsFor" { |
| + factsArgs = append(factsArgs, call.Args...) |
| + } |
| if call, ok := n.(*ast.CallExpr); ok && calleeName(call) == "effectivePlacement" { |
| + applies = true |
| for _, arg := range call.Args { |
| if lit, ok := arg.(*ast.FuncLit); ok { |
| inside = append(inside, lit) |
| @@ -89,14 +141,28 @@ func TestEffectivePlacementIsTheOnlyRouteFallback(t *testing.T) { |
| } |
| return false |
| } |
| + use := func(helper string, pos token.Pos) { |
| + if foldInRule[helper] && within(pos) { |
| + return |
| + } |
| + if census[helper][where] == "" { |
| + bad = append(bad, fset.Position(pos).String()+": "+helper+" in "+where+", outside effectivePlacement and not in the census") |
| + return |
| + } |
| + if mustApply[helper] && !applies { |
| + bad = append(bad, fset.Position(pos).String()+": "+where+" reads "+helper+" but never calls effectivePlacement") |
| + } |
| + used[helper+" "+where] = true |
| + } |
| ast.Inspect(fn.Body, func(n ast.Node) bool { |
| switch x := n.(type) { |
| case *ast.CallExpr: |
| - if folds[calleeName(x)] && !within(x.Pos()) { |
| - if foldOK[where] == "" { |
| - bad = append(bad, fset.Position(x.Pos()).String()+": "+calleeName(x)+" outside effectivePlacement in "+where) |
| - } |
| - used["fold "+where] = true |
| + if c := calleeName(x); census[c] != nil { |
| + use(c, x.Pos()) |
| + } |
| + case *ast.SelectorExpr: |
| + if x.Sel.Name == "routeFleet" && !slices.Contains(factsArgs, ast.Expr(x)) { |
| + bad = append(bad, fset.Position(x.Pos()).String()+": routeFleet read in "+where+" other than as an argument to regionFactsFor") |
| } |
| case *ast.BasicLit: |
| if x.Kind != token.STRING { |
| @@ -117,10 +183,11 @@ func TestEffectivePlacementIsTheOnlyRouteFallback(t *testing.T) { |
| }) |
| } |
| } |
| - // A listed exception that no longer happens is stale: drop it. |
| - for where := range foldOK { |
| - if !used["fold "+where] { |
| - bad = append(bad, "stale fold exception "+where) |
| + for helper, callers := range census { |
| + for where := range callers { |
| + if !used[helper+" "+where] { |
| + bad = append(bad, "stale census entry: "+helper+" in "+where) |
| + } |
| } |
| } |
| for where := range selectOK { |