carlos / platform Public

console: pin the policy listings inside the console's 48 a day (#328, #329)

PF-8 (final review finding 4): count the re-sign pass's listings of
control/app-policy/ over simulated days, on the writer and on a console
refused the lease. The writer lists on none of a steady day's passes, so
plan 2's report (writer only, at most one per change-index backstop) can
take all 48; a console that is not the writer lists once a pass, twice a
day, and runs no report. A holding's first day lists up to once a pass,
the stated non-steady limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 60c33757485ac4dd864105e9789afba0466eced6 parent 9670a95
1 file changed, +85 −0
  • internal/console/apipolicy_resign_test.go +85 −0
diff --git a/internal/console/apipolicy_resign_test.go b/internal/console/apipolicy_resign_test.go
index a6a13eae9..c6e1923b0 100644
--- a/internal/console/apipolicy_resign_test.go
+++ b/internal/console/apipolicy_resign_test.go
@@ -612,3 +612,88 @@ func TestPolicyResignKeepsTheRequestBudget(t *testing.T) {
t.Fatalf("%d leaser calls, want 2", n)
}
}
+
+// PF-8 (final review finding 4): the console's listings for app policies fit
+// §3a's allowance of 48 LISTs a day per console, on the writer and on every
+// other console, counted through the real re-sign pass. The console's other
+// lister is plan 2's egress report: it runs only on the writer (plan 2 Task
+// 10, egressReportDue) and at most once per change-index backstop, so on the
+// writer it may take every one of the 48. The re-sign must then take none
+// there on a steady day; it lists on every pass only where it holds no
+// lease, where the report does not run. Stated limit: a holding's first day
+// (a console start or a takeover) lists up to once per pass, as plan 2's
+// report also runs a first pass in a new holding; §3a budgets steady state.
+// Fails if the re-sign lists on a steady writer's day, or more than once a
+// pass anywhere.
+func TestPolicyConsoleListingsFitTheDailyAllowance(t *testing.T) {
+ t.Parallel()
+ const allowance = 48 // §3a: LISTs per console per day
+ reportMax := int(24 * time.Hour / release.ChangeIndexBackstop)
+ passesPerDay := int(24 * time.Hour / doorKeyResignEvery)
+ if reportMax > allowance || passesPerDay > allowance {
+ t.Fatalf("report %d a day, re-sign passes %d a day: either alone exceeds the %d allowance", reportMax, passesPerDay, allowance)
+ }
+ ctx := context.Background()
+ day := func(fx *policyFx, cs *policyCountingStore) (lists, gets int) {
+ cs.reset()
+ for range passesPerDay {
+ fx.srv.resignAppPolicies(ctx)
+ }
+ l, le, g, _ := cs.counts()
+ return l + le, g
+ }
+ setup := func(t *testing.T, code string) (*policyFx, *fakePolicyLeaser, *policyCountingStore) {
+ fx := newPolicyFx(t, code)
+ f := fx.leased()
+ fx.addApps(t, "shop-c")
+ cs := newPolicyCountingStore(fx.rel)
+ fx.srv.cfg.Releases = cs
+ for _, app := range []string{"shop", "shop-b", "shop-c"} {
+ fx.mustPut(t, app, `{"egress_allow":["10.0.5.20"]}`, policyCreate)
+ }
+ // The holding the writes took ends: the next pass starts a new one,
+ // as after a console start or a takeover.
+ lastPolicyLease(t, f).set(errors.New("renewal lost"), time.Now().Add(10*time.Minute), nil)
+ return fx, f, cs
+ }
+
+ t.Run("the writer", func(t *testing.T) {
+ t.Parallel()
+ fx, f, cs := setup(t, "code-policy-lists-writer")
+ if lists, _ := day(fx, cs); lists > passesPerDay {
+ t.Fatalf("the holding's first day: %d listings, want at most one a pass (%d)", lists, passesPerDay)
+ }
+ for d := 2; d <= 3; d++ {
+ lists, gets := day(fx, cs)
+ if lists+reportMax > allowance {
+ t.Fatalf("day %d: %d re-sign listings plus the report's %d exceed %d", d, lists, reportMax, allowance)
+ }
+ if gets != 3*passesPerDay {
+ t.Fatalf("day %d: %d Gets, want %d (one per live policy per pass)", d, gets, 3*passesPerDay)
+ }
+ }
+ if n := f.callCount(); n != 2 {
+ t.Fatalf("%d leaser calls, want 2 (the writes' holding and one more)", n)
+ }
+ })
+
+ t.Run("a console that is not the writer", func(t *testing.T) {
+ t.Parallel()
+ fx, f, cs := setup(t, "code-policy-lists-other")
+ f.mu.Lock()
+ f.err = errors.New("acquire lease: held by console-b:4242")
+ f.mu.Unlock()
+ for d := 1; d <= 3; d++ {
+ lists, gets := day(fx, cs)
+ // The report does not run here: the re-sign's listings are the
+ // console's only ones.
+ if lists > passesPerDay || lists > allowance {
+ t.Fatalf("day %d: %d listings, want at most one a pass (%d)", d, lists, passesPerDay)
+ }
+ if gets != 0 {
+ t.Fatalf("day %d: %d Gets, want none without the lease", d, gets)
+ }
+ }
+ fx.logs.has(t, "console: app policies: not re-signing; ")
+ })
+}