From f54a5fa720234f02078221afec6f39e56fc12b01 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Tue, 3 Nov 2026 11:45:37 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20fix(config):=20warn,=20repor?= =?UTF-8?q?t=20and=20optionally=20refuse=20when=20a=20seed=20boot=20drops?= =?UTF-8?q?=20a=20safety=20gate=20the=20previous=20runtime=20overlay=20car?= =?UTF-8?q?ried?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A spoke booting from the ConfigMap seed (runtime overlay moved aside, truncated or never written) silently lost review.require_labels, project.paused_repos, writeback.per_repo and project.issue_filter.require_labels. The boot now compares the effective config against the previous overlays still on the PVC (hive.yaml.runtime, hive.yaml.runtime.bak, hive.yaml.dashboard), logs one 'WARN safety gate dropped' per gate with the previous value, serves the list on /api/status as config.gate_regressions, shows a Settings banner, and with config.refuse_gate_regression: true refuses to start (exit 21). Fixes #16438 Signed-off-by: Andrew Anderson --- .../fixed-16438-gate-regression-guard.md | 1 + src/cmd/hive/boot_config_deps.go | 6 + src/cmd/hive/boot_config_deps_test.go | 61 +++++ src/cmd/hive/main.go | 23 ++ src/deploy/entrypoint.sh | 8 + .../api-reference/health-status-events.md | 2 +- src/docs/config-layering.md | 17 ++ src/docs/operator-reference/README.md | 1 + src/pkg/config/config.go | 8 + src/pkg/config/gate_regression.go | 247 ++++++++++++++++++ src/pkg/config/gate_regression_test.go | 199 ++++++++++++++ src/pkg/dashboard/server.go | 23 ++ .../dashboard/static-src/js/config-tabs.js | 14 +- src/pkg/dashboard/static/index.html | 14 +- 14 files changed, 621 insertions(+), 3 deletions(-) create mode 100644 changelog.d/fixed-16438-gate-regression-guard.md create mode 100644 src/pkg/config/gate_regression.go create mode 100644 src/pkg/config/gate_regression_test.go diff --git a/changelog.d/fixed-16438-gate-regression-guard.md b/changelog.d/fixed-16438-gate-regression-guard.md new file mode 100644 index 0000000000..af5e8d0d02 --- /dev/null +++ b/changelog.d/fixed-16438-gate-regression-guard.md @@ -0,0 +1 @@ +- A spoke that boots from the ConfigMap seed (runtime overlay moved aside or missing) no longer drops `review.require_labels`, `project.paused_repos`, `writeback.per_repo` or `project.issue_filter.require_labels` in silence: each gate a previous overlay on the PVC carried that the effective config lacks or loosens is logged as `WARN safety gate dropped` with its previous value, listed in `/api/status` as `config.gate_regressions`, and shown as a Settings banner; `config.refuse_gate_regression: true` refuses to start instead. diff --git a/src/cmd/hive/boot_config_deps.go b/src/cmd/hive/boot_config_deps.go index df6b0b6791..94faa8d482 100644 --- a/src/cmd/hive/boot_config_deps.go +++ b/src/cmd/hive/boot_config_deps.go @@ -56,6 +56,9 @@ type bootConfigDeps struct { runHub func(logger *slog.Logger, configPath string) // loadConfig is config.LoadWithDashboardOverlay. loadConfig func(path string) (*config.Config, error) + // gateRegressions compares the loaded config against the previous + // runtime overlays on the PVC (#16438); nil-returning in tests. + gateRegressions func(cfg *config.Config) []config.GateRegression // fileLogger builds the rolling-file logger from the loaded config. fileLogger func(cfg *config.Config) *slog.Logger // hiveID loads or generates the persistent hive identity. @@ -98,6 +101,9 @@ func defaultBootConfigDeps() bootConfigDeps { clearUpgradeMarker: func() error { return os.Remove(upgradeMarkerPath) }, runHub: runHub, loadConfig: config.LoadWithDashboardOverlay, + gateRegressions: func(cfg *config.Config) []config.GateRegression { + return config.DetectPriorOverlayGateRegressions(cfg, config.PriorOverlayPaths()) + }, fileLogger: func(cfg *config.Config) *slog.Logger { l := cfg.Governor.Logging return setupLogger(l.Dir, l.MaxSizeMB, l.MaxAgeDays, l.MaxBackups, l.Compress, l.Level) diff --git a/src/cmd/hive/boot_config_deps_test.go b/src/cmd/hive/boot_config_deps_test.go index 0abb9933bc..0b4a714343 100644 --- a/src/cmd/hive/boot_config_deps_test.go +++ b/src/cmd/hive/boot_config_deps_test.go @@ -82,6 +82,7 @@ func newBootConfigFake(t *testing.T) *bootConfigFake { cfg.Debug.PprofAddr = config.PprofAddrOff return cfg, nil }, + gateRegressions: func(*config.Config) []config.GateRegression { return nil }, // Every logger the phase installs is captured, including the stdout // bootstrap logger's replacement, so assertions see the whole boot. fileLogger: func(*config.Config) *slog.Logger { @@ -514,3 +515,63 @@ func TestBootConfigWith_HubModeNotGatedByProxyInjectGuard(t *testing.T) { t.Fatalf("returned=%v ok=%v code=%d hubRun=%v, want the hub started", returned, ok, code, f.hubRun) } } + +// #16438: a safety gate a previous runtime overlay carried that the effective +// config lacks is logged once per gate at WARN and kept on the config for +// /api/status; with config.refuse_gate_regression it is fatal, with its own +// exit code and the gates named in the log. +func TestBootConfigWith_GateRegressionWarnsOrRefuses(t *testing.T) { + regs := []config.GateRegression{ + {Gate: config.GateReviewRequireLabels, Previous: "[hive-review]", Effective: "none", Source: "/data/hive.yaml.runtime.bak"}, + {Gate: config.GatePausedRepos + "[acme/widgets]", Previous: "paused", Effective: "not paused", Source: "/data/hive.yaml.dashboard"}, + } + t.Run("warns and boots by default", func(t *testing.T) { + f := newBootConfigFake(t) + f.deps.gateRegressions = func(*config.Config) []config.GateRegression { return regs } + b := &boot{} + if returned, ok, code := runBootConfig(t, b, f.deps); !returned || !ok { + t.Fatalf("returned=%v ok=%v code=%d, want a normal boot", returned, ok, code) + } + log := f.log.String() + if n := strings.Count(log, "safety gate dropped"); n != len(regs) { + t.Fatalf("want %d 'safety gate dropped' lines, got %d:\n%s", len(regs), n, log) + } + for _, want := range []string{"review.require_labels", "[hive-review]", "acme/widgets", "level=WARN"} { + if !strings.Contains(log, want) { + t.Fatalf("gate warning lacks %q:\n%s", want, log) + } + } + if len(b.cfg.GateRegressions) != len(regs) { + t.Fatalf("cfg.GateRegressions = %v, want the detector's list", b.cfg.GateRegressions) + } + }) + t.Run("refuses when config.refuse_gate_regression is on", func(t *testing.T) { + f := newBootConfigFake(t) + load := f.deps.loadConfig + f.deps.loadConfig = func(p string) (*config.Config, error) { + cfg, err := load(p) + cfg.ConfigGuard.RefuseGateRegression = true + return cfg, err + } + f.deps.gateRegressions = func(*config.Config) []config.GateRegression { return regs } + returned, _, code := runBootConfig(t, &boot{}, f.deps) + if returned || code != gateRegressionExitCode { + t.Fatalf("returned=%v code=%d, want exit(%d)", returned, code, gateRegressionExitCode) + } + log := f.log.String() + for _, want := range []string{"refusing to start", "refuse_gate_regression", "review.require_labels", "acme/widgets"} { + if !strings.Contains(log, want) { + t.Fatalf("refusal log lacks %q:\n%s", want, log) + } + } + }) + t.Run("quiet when nothing regressed", func(t *testing.T) { + f := newBootConfigFake(t) + if returned, ok, code := runBootConfig(t, &boot{}, f.deps); !returned || !ok { + t.Fatalf("returned=%v ok=%v code=%d, want a normal boot", returned, ok, code) + } + if strings.Contains(f.log.String(), "safety gate dropped") { + t.Fatal("gate warning logged with no regressions") + } + }) +} diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 39a994c32b..16ecd5157a 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -444,6 +444,11 @@ const ( // HIVE_PROXY_ADVISORY_OK=true). Its own code so a refusing pod's // termination state says "fix the env", not "bug". proxyInjectConfigExitCode = 19 + // gateRegressionExitCode marks an exit caused by config.refuse_gate_regression + // (hivecommons/hive#16438): a previous runtime overlay carried a safety + // gate the effective config lacks. Its own code so the termination state + // says "restore the gate or the overlay", not "bug". + gateRegressionExitCode = 21 ) // singletonLockPath resolves where the process singleton lock lives. Every @@ -654,6 +659,24 @@ func (b *boot) bootConfigWith(deps bootConfigDeps) bool { "agents", b.cfg.RemovedAgents, ) + // Safety-gate regression check (#16438). A boot from the ConfigMap seed + // (runtime overlay moved aside, truncated, or never written) silently + // dropped review.require_labels on a live hive and the reviewer posted on + // unlabelled PRs for hours. Compare the effective config against whatever + // previous overlay is still on the PVC and say so, once per gate; refuse + // to start when the operator asked for that. + b.cfg.GateRegressions = deps.gateRegressions(b.cfg) + for _, g := range b.cfg.GateRegressions { + b.logger.Warn("safety gate dropped: "+g.String(), + "gate", g.Gate, "previous", g.Previous, "effective", g.Effective, "source", g.Source) + } + if len(b.cfg.GateRegressions) > 0 && b.cfg.ConfigGuard.RefuseGateRegression { + err := &config.GateRegressionError{Regressions: b.cfg.GateRegressions} + b.logger.Error("refusing to start: safety gate regression (config.refuse_gate_regression is on)", "error", err.Error()) + deps.exit(gateRegressionExitCode) + return false + } + // Surface config provenance: when the persisted runtime config exists, init // containers restore it over the ConfigMap seed on restart, so edits made // only to the seed (or only to the live file) silently lose to it. diff --git a/src/deploy/entrypoint.sh b/src/deploy/entrypoint.sh index ab9c357b83..661ffcf703 100644 --- a/src/deploy/entrypoint.sh +++ b/src/deploy/entrypoint.sh @@ -1143,6 +1143,14 @@ PYEOF fi # Write the (merged) config as the disaster-recovery snapshot. Always # under the new name; the legacy file is left untouched on the PVC. + # + # Reaching this branch on a hive that USED to have a runtime config means + # the safety gates it carried (review.require_labels, paused_repos, …) + # are now whatever the seed says — usually nothing (#16438). The Go + # binary compares the loaded config against hive.yaml.runtime.bak and + # hive.yaml.dashboard at boot and WARNs per dropped gate (fatal with + # config.refuse_gate_regression); an operator moving the runtime config + # aside should name the copy hive.yaml.runtime.bak so it is found. cp "$HIVE_CONFIG_PATH" "$HIVE_CONFIG_RUNTIME" 2>/dev/null || true hive_harden_runtime_config "$HIVE_CONFIG_RUNTIME" echo "[entrypoint] K8s mode — ConfigMap is the seed, runtime config written to $HIVE_CONFIG_RUNTIME" diff --git a/src/docs/api-reference/health-status-events.md b/src/docs/api-reference/health-status-events.md index 8c3676ea0f..5458c2d3fb 100644 --- a/src/docs/api-reference/health-status-events.md +++ b/src/docs/api-reference/health-status-events.md @@ -28,7 +28,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/health/deep` | Public | Deep health probe | `pkg/dashboard/server.go:1644` | | `GET` | `/api/livez` | Public | Kubernetes liveness probe | `pkg/dashboard/server.go:1645` | | `GET` | `/metrics` | Registered only when `HIVE_METRICS_ENABLED`; requires `Authorization: ****** (403 if the token is unset) | Prometheus metrics | `pkg/dashboard/server.go:1651` | -| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced, dayUSD, weekUSD, monthUSD, windowsPriced}` is the governor strip's rotating `running N · $X this hour / today / this week / this month` figure (#15614) — the hour is the rise since the top of the clock hour, the wider windows are the daily cost ledger summed from 00:00 UTC today, Monday 00:00 UTC (ISO week) and the 1st 00:00 UTC plus the rise since the ledger's last snapshot, `windowsPriced:false` when there is no ledger yet; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376); `ci_failure_signals` `{count, last, kicks, unmatched}` is the webhook CI-failure signal store — distinct red (repo, head, check) signals retained, the most recent one `{repo, number, head_sha, check, conclusion, details_url, agent, at}`, webhook-triggered kicks/nudges since boot, and failure deliveries whose head matched no open PR; `hotspots` `{count, actionable, filed}` is the merge-hotspot advisor's one-line summary (files at/above the thresholds, those with a split recommendation, those with a modularize issue filed), absent when the advisor is not wired — details on `GET /api/hotspots`; `writeback.dedupe` `{enabled, dedupe_same_item, dedupe_burst, rate_capped, hourly_cap, burst_items, burst_window_s, same_item_ttl_s}` is the write-back gate's content layer — the effective `writeback.dedupe.*` settings and the last-hour counts of writes held as `duplicate`, `burst` and `rate-capped` (each also listed under `GET /api/writeback/suppressed`) | `pkg/dashboard/server.go:1656` | +| `GET` | `/api/status` | Dashboard auth/session | Dashboard aggregate status; `labelPresets[]` (`{key,label,description,labels[],states[]}`) lists the built-in label-filter presets for the Projects cards, led by `needs-human` whose `labels[]` are the effective hard-suppress labels plus `needs-signal`, the hold labels, `stage/071-needs-author` and the reporter-trust awaiting label (#12172); accepts `?fields=a,b` for top-level selection and `?omit=repos` to drop heavy sections, and honors `Accept-Encoding: gzip`; `agents[]` includes busy-pane visibility fields (`kicksUndeliverable`, `busySince`, `lastTranscriptActivity`, `condition`, `conditionMessage`) when a Working pane cannot accept kicks; a working agent also carries `agents[].run` — the live per-run line (#14576): `{since, elapsedS, costUSD, tokens, priced, tests, filesChanged}`, the estimated spend/tokens since the kick was delivered (`lastKickAt`, falling back to `busySince`) (delta of the token collector's per-agent cumulative figure; `priced:false` when the agent has none yet), the last visible test-runner result (`pass`/`fail`/empty) and the last `N files changed` git summary (`-1` when none) parsed from the captured pane; top-level `fleetRun` `{running, hourUSD, hourPriced, dayUSD, weekUSD, monthUSD, windowsPriced}` is the governor strip's rotating `running N · $X this hour / today / this week / this month` figure (#15614) — the hour is the rise since the top of the clock hour, the wider windows are the daily cost ledger summed from 00:00 UTC today, Monday 00:00 UTC (ISO week) and the 1st 00:00 UTC plus the rise since the ledger's last snapshot, `windowsPriced:false` when there is no ledger yet; `sla` (fleet) and `repos[].sla` (per repo) carry the Delivery SLA block derived from the lifecycle timeline with no extra GitHub calls: `windows.{7d,30d}.{open_to_triage,triage_to_start,start_to_pr,pr_to_merge,open_to_merge}` as `{p50_h,p95_h,n}` (hours, nearest-rank), `history[]` of up to 30 daily buckets `{day,start_to_pr_p50,pr_to_merge_p50,open_to_merge_p50,n_started,n_pr,n_merged}` persisted under `/data/sla-history.json`, `stale_in_progress[]` (`{number,repo,started_at,age_h,agent}` — issues carrying `hive/in-progress` longer than the agent claim TTL with no linked PR), `stale_count`, `merged_7d`, `claim_ttl_s` and, on the fleet block, the effective `targets` (`start_to_pr_h`, `pr_to_merge_h`, `open_to_merge_h`); `staleSince` and `repos[].countsStale` / `countsStaleSince` mark totals served from last-good figures — the previous enumeration (#13382) or the ForgeState cache's last-good counts (#13376); `ci_failure_signals` `{count, last, kicks, unmatched}` is the webhook CI-failure signal store — distinct red (repo, head, check) signals retained, the most recent one `{repo, number, head_sha, check, conclusion, details_url, agent, at}`, webhook-triggered kicks/nudges since boot, and failure deliveries whose head matched no open PR; `hotspots` `{count, actionable, filed}` is the merge-hotspot advisor's one-line summary (files at/above the thresholds, those with a split recommendation, those with a modularize issue filed), absent when the advisor is not wired — details on `GET /api/hotspots`; `writeback.dedupe` `{enabled, dedupe_same_item, dedupe_burst, rate_capped, hourly_cap, burst_items, burst_window_s, same_item_ttl_s}` is the write-back gate's content layer — the effective `writeback.dedupe.*` settings and the last-hour counts of writes held as `duplicate`, `burst` and `rate-capped` (each also listed under `GET /api/writeback/suppressed`); `config.gate_regressions[]` `{gate, previous, effective, source}` is the boot-time safety-gate regression list (#16438) — gates a previous runtime overlay on the PVC carried that the running config lacks or loosens (`review.require_labels`, `project.issue_filter.require_labels`, `project.paused_repos[]`, `writeback.per_repo[].mode`), empty on a healthy boot | `pkg/dashboard/server.go:1656` | | `GET` | `/api/status/summary` | Dashboard auth/session | Compact agent/governor/budget status summary for pollers; honors `Accept-Encoding: gzip` | `pkg/dashboard/server.go:1657` | | `GET` | `/api/overview/issues.csv` | Dashboard auth/session | Cached Overview issue-band export as browser-compatible CSV; filters `band`, `repo`/`repos`, `stale`, and `held` are ANDed. | `pkg/dashboard/server.go:1658` | | `GET` | `/api/overview/issues.json` | Dashboard auth/session | Cached Overview issue-band export as typed JSON with `bands[]` metadata and row fields matching the CSV columns. | `pkg/dashboard/server.go:1659` | diff --git a/src/docs/config-layering.md b/src/docs/config-layering.md index ce6f70f7f2..0e68abda0e 100644 --- a/src/docs/config-layering.md +++ b/src/docs/config-layering.md @@ -189,6 +189,23 @@ Two consequences worth stating outright for a non-Kubernetes hive: the hive to whatever the seed was provisioned with, silently downgrading every hold-gated agent. Back up the volume, not just the seed file. +### Safety gates do not survive a seed boot — but the boot says so + +A boot from the ConfigMap seed (no runtime config on the PVC, or one moved +aside during a recovery) runs with whatever gates the *seed* has, which on a +long-lived hive is usually none: `review.require_labels`, +`project.paused_repos`, `writeback.per_repo` and +`project.issue_filter.require_labels` all live in the overlay. On the a1 spoke +that silently re-enabled reviews on every unlabelled PR for four hours +([#16438](https://github.com/hivecommons/hive/issues/16438)). The Go binary now +compares the loaded config against any previous overlay still on the PVC +(`hive.yaml.runtime`, `hive.yaml.runtime.bak`, `hive.yaml.dashboard`) and logs +`WARN safety gate dropped: …` once per gate with the previous value; the same +list is served as `config.gate_regressions` on `/api/status` and shown as a +banner at the top of Settings. `config.refuse_gate_regression: true` turns the +warning into a refusal to start. Nothing about how the gates are *enforced* +changes; the entrypoint's choice of boot source is unchanged too. + ### Migration The rename is **copy-forward, never destructive**. Writers emit diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index b769668ea0..467be2b382 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -251,6 +251,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through | `project.label_driven_trust_org_members` | `true` | Whether a public member of the repo's owning org who applies an approval label is trusted (Prow's own rule). Dashboard: Settings → Repos → "trust public org members". | | `project.label_driven_trusted_bots` | `["kubestellar-prow[bot]"]` | Bot logins whose label additions count as a trusted triager (Prow command bots relaying `/triage accepted`). `github-actions[bot]` is not in the default because it is the shared identity of every workflow in the repo, including ones triggered by untrusted events; operators whose Prow emulation runs as `github-actions[bot]` must add it explicitly per deployment. Dashboard: Settings → Repos → "Trusted bots". | | `project.label_driven_supersede_park_actors` | `[]` (off) | Automation logins (for example a lifecycle bot running as `github-actions[bot]`) whose park labels a later trusted acceptance supersedes on label-driven repos: Hive removes the label, says so in the release comment, and releases the issue ([#13605](https://github.com/hivecommons/hive/issues/13605)). Park labels added by people, by unlisted bots, or by a listed bot after the acceptance still block; `hold` is never superseded. Per-repo override: `project.repo_policies[].label_driven_supersede_park_actors`. | +| `config.refuse_gate_regression` | `false` | Safety-gate regression guard ([#16438](https://github.com/hivecommons/hive/issues/16438)). At boot the hive compares the effective config against any previous runtime overlay still on the PVC (`/data/hive.yaml.runtime`, an operator's `hive.yaml.runtime.bak`, `/data/hive.yaml.dashboard`) for `review.require_labels`, `project.issue_filter.require_labels`, `project.paused_repos` and `writeback.per_repo` modes. A gate the overlay carried that the effective config lacks or loosens — typically a boot from the ConfigMap seed after the overlay was moved aside — is logged once per gate as `WARN safety gate dropped: (was ) — effective config has `, listed in `/api/status` under `config.gate_regressions`, and shown as a banner at the top of Settings. `true` makes it fatal: the hive exits (code 21) with the gates named instead of running with weaker gates. Set it in the overlay itself; the ConfigMap seed is the file the regression usually comes from. Legacy `/data/hive.yaml.bak` is not consulted — it is frozen at the rename and would warn forever about gates removed on purpose. | | `auto_merge.allow_unprotected_base` | Deprecated no-op. | Accepted so older configs keep loading. `hive-merge` now merges into any protected or unprotected branch the App can write, subject to the CI-evidence gate and GitHub's own merge rules. | | `auto_merge.no_ci_ok` | Empty by default. | Explicit repo list whose zero-CI merge-request verdict may pass; failing or pending CI evidence is still enforced. | | `auto_merge.human_merge_pin_only` | Unset (off); enforced by the automerge sweep lanes and `/approve` (#16266), **not yet by the `hive-merge` relay** (#16265). | Per-repo schema for `enabled`, `paths`, `kinds` (`action-sha`, `image-digest`, `version-pin`) and `trusted_authors`. Enabled entries require all three lists. The sweep does not place a human-merge-path hold on a PR whose author is in `trusted_authors`, whose complete diff (every changed file, guarded or not) is pin replacements, whose every commit is authored by a `trusted_authors` login with a GitHub-verified signature, and whose every new action SHA resolves in its upstream action repository (the `# vN` tag points at it, or it is on the default branch; #16399); it never clears an existing hold. See [hive-merge.md](../hive-merge.md) for grammar, restrictions and outstanding integration/deployment requirements (#16242). | diff --git a/src/pkg/config/config.go b/src/pkg/config/config.go index bca9a76240..6c85fe185d 100644 --- a/src/pkg/config/config.go +++ b/src/pkg/config/config.go @@ -212,6 +212,9 @@ type Config struct { // `classification:` block (currently review_bots, hivecommons/hive#7360). // Default empty → the review-thread reconciler is off. Classification ClassificationConfig `yaml:"classification,omitempty" json:"classification,omitempty"` + // ConfigGuard is the `config:` block: how the config itself is loaded + // (hivecommons/hive#16438). See ConfigGuardConfig in gate_regression.go. + ConfigGuard ConfigGuardConfig `yaml:"config,omitempty" json:"config,omitempty"` // RemovedAgents are agent names an operator deliberately deleted. It is a // TOMBSTONE list, and it exists because deletion had no durable record // anywhere: the delete handlers dropped the agent from the in-memory map @@ -242,6 +245,11 @@ type Config struct { // dashboard can raise a banner for each. Runtime-only; see // DegradeContradictingLaunchCmds. LaunchCmdDegradations []LaunchCmdDegradation `yaml:"-" json:"-"` + // GateRegressions lists the safety gates a previous runtime overlay + // carried that this config lacks or weakens, as detected at boot + // (hivecommons/hive#16438). Runtime-only; served in /api/status as + // config.gate_regressions. See DetectPriorOverlayGateRegressions. + GateRegressions []GateRegression `yaml:"-" json:"-"` // ReviewerAutoscaleActive is the reviewer autoscaler's current target // replica count for the autoscaled lane (hivecommons/hive#14685). // Runtime-only: it is never persisted, is carried across config reloads diff --git a/src/pkg/config/gate_regression.go b/src/pkg/config/gate_regression.go new file mode 100644 index 0000000000..b1bc5ca9e1 --- /dev/null +++ b/src/pkg/config/gate_regression.go @@ -0,0 +1,247 @@ +package config + +import ( + "fmt" + "os" + "sort" + "strings" + + "github.com/hivecommons/hive/pkg/writeback" + "gopkg.in/yaml.v3" +) + +// ConfigGuardConfig is the `config:` block of hive.yaml: knobs about how the +// config itself is loaded, as opposed to what it says. +type ConfigGuardConfig struct { + // RefuseGateRegression makes a safety-gate regression at boot fatal + // (hivecommons/hive#16438). Off (the default) the hive logs one WARN per + // dropped gate and reports them in /api/status config.gate_regressions; + // on, it exits instead of starting with weaker gates than the previous + // runtime overlay carried. + RefuseGateRegression bool `yaml:"refuse_gate_regression,omitempty" json:"refuse_gate_regression,omitempty"` +} + +// Safety gate names as reported in logs, /api/status and the dashboard. +const ( + GateReviewRequireLabels = "review.require_labels" + GateIssueRequireLabels = "project.issue_filter.require_labels" + GatePausedRepos = "project.paused_repos" + GateWritebackPerRepo = "writeback.per_repo" +) + +// GateRegression is one safety gate that a previous runtime overlay carried +// and the effective config lacks or weakens. +type GateRegression struct { + // Gate is the config key, with the repo appended for per-repo gates + // (project.paused_repos[org/repo], writeback.per_repo[org/repo].mode). + Gate string `json:"gate"` + // Previous is the value the prior overlay had, rendered for a log line. + Previous string `json:"previous"` + // Effective is the value the running config has. + Effective string `json:"effective"` + // Source is the prior overlay file the previous value was read from. + Source string `json:"source,omitempty"` +} + +// String renders the regression the way the boot WARN line reports it. +func (g GateRegression) String() string { + s := fmt.Sprintf("%s (was %s) — effective config has %s", g.Gate, g.Previous, g.Effective) + if g.Source != "" { + s += " [from " + g.Source + "]" + } + return s +} + +// GateRegressionError is returned by RefuseGateRegressions when +// config.refuse_gate_regression is on and at least one gate regressed. +type GateRegressionError struct { + Regressions []GateRegression +} + +func (e *GateRegressionError) Error() string { + parts := make([]string, 0, len(e.Regressions)) + for _, g := range e.Regressions { + parts = append(parts, g.String()) + } + return fmt.Sprintf("refusing to start: config.refuse_gate_regression is on and %d safety gate(s) present in a previous runtime overlay are missing or weaker in the effective config: %s", + len(e.Regressions), strings.Join(parts, "; ")) +} + +// PriorOverlayPaths lists the files a previous boot may have left behind +// that carry the gates this hive used to run with, in the order they are +// consulted: the runtime config itself, an operator's `.bak` of it, and the +// dashboard overlay. The legacy /data/hive.yaml.bak is deliberately NOT in +// the list: it is frozen at the rename and goes stale on every later save, +// so comparing against it would warn forever about gates an operator +// removed on purpose. +func PriorOverlayPaths() []string { + return []string{RuntimeConfigFile, RuntimeConfigFile + ".bak", DashboardOverlayFile} +} + +// DetectPriorOverlayGateRegressions reads each prior overlay in paths that +// exists, is non-empty, parses, and is not the file effective was loaded +// from, and reports every safety gate it carries that effective lacks or +// weakens. The first overlay to report a given gate wins; later ones add +// only gates not yet seen. A missing or unparsable overlay contributes +// nothing — this is a boot-time warning, never a reason to fail the load. +func DetectPriorOverlayGateRegressions(effective *Config, paths []string) []GateRegression { + if effective == nil { + return nil + } + var out []GateRegression + seen := map[string]bool{} + for _, p := range paths { + if p == "" || sameConfigPath(p, effective.SourcePath) { + continue + } + data, err := os.ReadFile(p) + if err != nil || len(strings.TrimSpace(string(data))) == 0 { + continue + } + var prior Config + if err := yaml.Unmarshal([]byte(expandEnvVars(string(data))), &prior); err != nil { + continue + } + for _, g := range DetectGateRegressions(effective, &prior) { + if seen[g.Gate] { + continue + } + seen[g.Gate] = true + g.Source = p + out = append(out, g) + } + } + return out +} + +func sameConfigPath(a, b string) bool { + if a == "" || b == "" { + return false + } + if a == b { + return true + } + ai, errA := os.Stat(a) + bi, errB := os.Stat(b) + return errA == nil && errB == nil && os.SameFile(ai, bi) +} + +// DetectGateRegressions compares the safety gates of prior against +// effective and returns one entry per gate that effective has dropped or +// loosened. Tightenings and gates neither config sets are not reported. +func DetectGateRegressions(effective, prior *Config) []GateRegression { + if effective == nil || prior == nil { + return nil + } + var out []GateRegression + if g, ok := labelListRegression(GateReviewRequireLabels, prior.Review.RequireLabels, effective.Review.RequireLabels); ok { + out = append(out, g) + } + if g, ok := labelListRegression(GateIssueRequireLabels, prior.Project.IssueFilter.RequireLabels, effective.Project.IssueFilter.RequireLabels); ok { + out = append(out, g) + } + out = append(out, pausedRepoRegressions(effective, prior)...) + out = append(out, writebackPerRepoRegressions(effective, prior)...) + return out +} + +// labelListRegression reports a non-empty allow-list that became empty. +func labelListRegression(gate string, prior, effective []string) (GateRegression, bool) { + if len(nonBlank(prior)) == 0 || len(nonBlank(effective)) != 0 { + return GateRegression{}, false + } + return GateRegression{Gate: gate, Previous: formatList(prior), Effective: "none"}, true +} + +// pausedRepoRegressions reports each repo paused in prior that effective no +// longer pauses. Keys are org-qualified and case-folded the same way +// RepoPauseFor matches them, each config qualified with its own org. +func pausedRepoRegressions(effective, prior *Config) []GateRegression { + if len(prior.Project.PausedRepos) == 0 { + return nil + } + paused := effective.PausedRepoSet() + var out []GateRegression + for _, rp := range prior.Project.PausedRepos { + key := repoPauseKey(prior.Project.Org, rp.Repo) + if key == "" || paused[key] { + continue + } + out = append(out, GateRegression{ + Gate: fmt.Sprintf("%s[%s]", GatePausedRepos, key), + Previous: "paused", + Effective: "not paused", + }) + } + return out +} + +// repoModeStrictness orders writeback.per_repo modes from most to least +// restrictive. RepoModeDefault (no override, the kind matrix applies) sits +// between labels-only and full: dropping an off/issues-only/labels-only +// entry is a loosening, dropping a full entry is a tightening. +func repoModeStrictness(m writeback.RepoMode) int { + switch m { + case writeback.RepoModeOff: + return 0 + case writeback.RepoModeIssuesOnly: + return 1 + case writeback.RepoModeLabelsOnly: + return 2 + case writeback.RepoModeFull: + return 4 + default: + return 3 + } +} + +// writebackPerRepoRegressions reports each restrictive per-repo write-back +// mode in prior that effective resolves to a looser mode (or no override). +func writebackPerRepoRegressions(effective, prior *Config) []GateRegression { + if len(prior.Writeback.PerRepo) == 0 { + return nil + } + repos := make([]string, 0, len(prior.Writeback.PerRepo)) + for r := range prior.Writeback.PerRepo { + repos = append(repos, r) + } + sort.Strings(repos) + var out []GateRegression + for _, repo := range repos { + was := prior.Writeback.PerRepo[repo].Mode + if !was.Valid() || repoModeStrictness(was) >= repoModeStrictness(writeback.RepoModeDefault) { + continue + } + now := effective.Writeback.RepoModeFor(repo) + if repoModeStrictness(now) <= repoModeStrictness(was) { + continue + } + out = append(out, GateRegression{ + Gate: fmt.Sprintf("%s[%s].mode", GateWritebackPerRepo, strings.TrimSpace(repo)), + Previous: string(was), + Effective: formatRepoMode(now), + }) + } + return out +} + +func formatRepoMode(m writeback.RepoMode) string { + if m == writeback.RepoModeDefault { + return "no override (default matrix)" + } + return string(m) +} + +func nonBlank(in []string) []string { + var out []string + for _, s := range in { + if strings.TrimSpace(s) != "" { + out = append(out, strings.TrimSpace(s)) + } + } + return out +} + +func formatList(in []string) string { + return "[" + strings.Join(nonBlank(in), ", ") + "]" +} diff --git a/src/pkg/config/gate_regression_test.go b/src/pkg/config/gate_regression_test.go new file mode 100644 index 0000000000..a56a3a72fe --- /dev/null +++ b/src/pkg/config/gate_regression_test.go @@ -0,0 +1,199 @@ +package config + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/writeback" +) + +func gateCfg(org string, mutate func(c *Config)) *Config { + c := &Config{} + c.Project.Org = org + if mutate != nil { + mutate(c) + } + return c +} + +func gateNames(regs []GateRegression) []string { + out := make([]string, 0, len(regs)) + for _, g := range regs { + out = append(out, g.Gate) + } + return out +} + +func TestDetectGateRegressions(t *testing.T) { + full := func(c *Config) { + c.Review.RequireLabels = []string{"hive-review"} + c.Project.IssueFilter.RequireLabels = []string{"hive-ok"} + c.Project.PausedRepos = []RepoPause{{Repo: "Console"}} + c.Writeback.PerRepo = map[string]writeback.RepoOverride{ + "torch-spyre/spyre-inference": {Mode: writeback.RepoModeIssuesOnly}, + } + } + cases := []struct { + name string + prior *Config + effective *Config + want []string + wantPrev map[string]string + }{ + { + name: "unchanged", + prior: gateCfg("acme", full), + effective: gateCfg("acme", full), + }, + { + name: "no prior gates", + prior: gateCfg("acme", nil), + effective: gateCfg("acme", nil), + }, + { + name: "all dropped", + prior: gateCfg("acme", full), + effective: gateCfg("acme", func(c *Config) { + c.Review.RequireLabels = []string{" "} + }), + want: []string{ + GateReviewRequireLabels, + GateIssueRequireLabels, + GatePausedRepos + "[acme/console]", + GateWritebackPerRepo + "[torch-spyre/spyre-inference].mode", + }, + wantPrev: map[string]string{ + GateReviewRequireLabels: "[hive-review]", + GatePausedRepos + "[acme/console]": "paused", + GateWritebackPerRepo + "[torch-spyre/spyre-inference].mode": "issues-only", + }, + }, + { + name: "weakened per-repo writeback mode", + prior: gateCfg("acme", full), + effective: gateCfg("acme", func(c *Config) { + full(c) + c.Writeback.PerRepo["torch-spyre/spyre-inference"] = writeback.RepoOverride{Mode: writeback.RepoModeFull} + }), + want: []string{GateWritebackPerRepo + "[torch-spyre/spyre-inference].mode"}, + }, + { + name: "tightened per-repo writeback mode is not a regression", + prior: gateCfg("acme", full), + effective: gateCfg("acme", func(c *Config) { + full(c) + c.Writeback.PerRepo["torch-spyre/spyre-inference"] = writeback.RepoOverride{Mode: writeback.RepoModeOff} + }), + }, + { + name: "dropped full override is a tightening", + prior: gateCfg("acme", func(c *Config) { + c.Writeback.PerRepo = map[string]writeback.RepoOverride{"acme/x": {Mode: writeback.RepoModeFull}} + }), + effective: gateCfg("acme", nil), + }, + { + name: "label list changed but still non-empty", + prior: gateCfg("acme", full), + effective: gateCfg("acme", func(c *Config) { + full(c) + c.Review.RequireLabels = []string{"other-label"} + }), + }, + { + name: "pause matched across spellings", + prior: gateCfg("acme", func(c *Config) { c.Project.PausedRepos = []RepoPause{{Repo: "acme/Console"}} }), + effective: gateCfg("acme", func(c *Config) { + c.Project.PausedRepos = []RepoPause{{Repo: "console"}} + }), + }, + { + name: "nil configs", + prior: nil, + effective: gateCfg("acme", nil), + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := DetectGateRegressions(tc.effective, tc.prior) + if strings.Join(gateNames(got), ",") != strings.Join(tc.want, ",") { + t.Fatalf("gates = %v, want %v", gateNames(got), tc.want) + } + for _, g := range got { + if want, ok := tc.wantPrev[g.Gate]; ok && g.Previous != want { + t.Errorf("%s previous = %q, want %q", g.Gate, g.Previous, want) + } + if g.Effective == "" { + t.Errorf("%s has empty effective value", g.Gate) + } + } + }) + } +} + +func TestDetectPriorOverlayGateRegressions(t *testing.T) { + dir := t.TempDir() + write := func(name, body string) string { + p := filepath.Join(dir, name) + if err := os.WriteFile(p, []byte(body), 0o600); err != nil { + t.Fatal(err) + } + return p + } + effective := gateCfg("acme", nil) + effective.SourcePath = write("hive.yaml", "project:\n org: acme\n") + + t.Run("no prior overlay", func(t *testing.T) { + got := DetectPriorOverlayGateRegressions(effective, []string{filepath.Join(dir, "missing.yaml")}) + if len(got) != 0 { + t.Fatalf("got %v, want none", got) + } + }) + + t.Run("empty and malformed overlays are ignored", func(t *testing.T) { + empty := write("hive.yaml.runtime", "") + bad := write("hive.yaml.runtime.bak", "review: [not: a: map\n") + if got := DetectPriorOverlayGateRegressions(effective, []string{empty, bad}); len(got) != 0 { + t.Fatalf("got %v, want none", got) + } + }) + + t.Run("effective source path is skipped", func(t *testing.T) { + eff := gateCfg("acme", nil) + eff.SourcePath = write("gated.yaml", "project:\n org: acme\nreview:\n require_labels: [hive-review]\n") + if got := DetectPriorOverlayGateRegressions(eff, []string{eff.SourcePath}); len(got) != 0 { + t.Fatalf("got %v, want none", got) + } + }) + + t.Run("first overlay wins per gate, later overlays add new gates", func(t *testing.T) { + runtime := write("prior.runtime", "project:\n org: acme\nreview:\n require_labels: [hive-review]\n") + dash := write("prior.dashboard", "project:\n org: acme\n paused_repos:\n - repo: console\nreview:\n require_labels: [other]\n") + got := DetectPriorOverlayGateRegressions(effective, []string{runtime, dash}) + want := []string{GateReviewRequireLabels, GatePausedRepos + "[acme/console]"} + if strings.Join(gateNames(got), ",") != strings.Join(want, ",") { + t.Fatalf("gates = %v, want %v", gateNames(got), want) + } + if got[0].Previous != "[hive-review]" || got[0].Source != runtime { + t.Errorf("review gate = %+v, want previous from %s", got[0], runtime) + } + if got[1].Source != dash { + t.Errorf("pause gate source = %q, want %s", got[1].Source, dash) + } + }) +} + +func TestGateRegressionError_ListsEveryGate(t *testing.T) { + err := &GateRegressionError{Regressions: []GateRegression{ + {Gate: GateReviewRequireLabels, Previous: "[hive-review]", Effective: "none", Source: "/data/hive.yaml.runtime.bak"}, + {Gate: GatePausedRepos + "[acme/console]", Previous: "paused", Effective: "not paused"}, + }} + msg := err.Error() + for _, want := range []string{"refuse_gate_regression", "2 safety gate(s)", "review.require_labels (was [hive-review])", "acme/console", "/data/hive.yaml.runtime.bak"} { + if !strings.Contains(msg, want) { + t.Errorf("error %q lacks %q", msg, want) + } + } +} diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index 2ab315d0c7..1389c1e6e6 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -3735,9 +3735,28 @@ func (s *Server) handleStatus(w http.ResponseWriter, r *http.Request) { payload.UpgradeProgress = s.upgradeProgress(status, now) payload.Writeback = s.WritebackStatus() payload.Hotspots = s.HotspotStatusBlock() + payload.Config = s.configHealthStatus() statusJSONResponse(w, r, filterStatusPayload(&payload, r.URL.Query().Get("fields"), r.URL.Query().Get("omit"))) } +// ConfigHealthStatus is the `config` block of /api/status: what the boot +// found wrong with the loaded config itself, as opposed to what it says. +type ConfigHealthStatus struct { + // GateRegressions lists the safety gates a previous runtime overlay + // carried that the running config lacks or weakens (#16438). Always a + // list, empty on a healthy boot, so the dashboard banner needs no + // presence check. + GateRegressions []config.GateRegression `json:"gate_regressions"` +} + +func (s *Server) configHealthStatus() *ConfigHealthStatus { + out := &ConfigHealthStatus{GateRegressions: []config.GateRegression{}} + if s.deps != nil && s.deps.Config != nil && len(s.deps.Config.GateRegressions) > 0 { + out.GateRegressions = append(out.GateRegressions, s.deps.Config.GateRegressions...) + } + return out +} + // statusWithWebhooks adds the live webhook health block (#11177) and the // governor loop's pacing (evalMode, lastWakeReason) to the cached status // payload at serve time, so neither is a whole eval cycle stale. @@ -3765,6 +3784,10 @@ type statusWithWebhooks struct { // concurrent PRs in the window, how many warrant a split, how many have // a modularize issue filed. Absent when the advisor is not wired. Hotspots *HotspotStatus `json:"hotspots,omitempty"` + // Config reports boot-time findings about the loaded config itself: + // config.gate_regressions is the safety gates a previous runtime + // overlay carried that this boot dropped (#16438). + Config *ConfigHealthStatus `json:"config,omitempty"` } func (s *Server) handleStatusSummary(w http.ResponseWriter, r *http.Request) { diff --git a/src/pkg/dashboard/static-src/js/config-tabs.js b/src/pkg/dashboard/static-src/js/config-tabs.js index 117ed0a479..615f9dcea6 100644 --- a/src/pkg/dashboard/static-src/js/config-tabs.js +++ b/src/pkg/dashboard/static-src/js/config-tabs.js @@ -35,7 +35,7 @@ // agent's kick history over the selected time window. if (tabId === AGENT_PROMPTS_TAB) initAgentPromptHistory(); } else { - body.innerHTML = renderGovernorTab(tabId); + body.innerHTML = renderGateRegressionBanner() + renderGovernorTab(tabId); settingsAnnotateRows(body); if (tabId === 'Hub') { fetchQueueCount(); fetchAutoUpdateStatus(); } // The escalation breaker lives at the top level of hive.yaml, so the @@ -70,6 +70,18 @@ if (typeof syncRepoSaveGuard === 'function') syncRepoSaveGuard(); } + // Safety-gate regression banner (#16438): /api/status config.gate_regressions + // lists the gates (review.require_labels, project.paused_repos, …) a + // previous runtime overlay carried that this boot's config dropped or + // loosened. Shown at the top of every Settings tab until the operator + // restores the gate (or removes it on purpose) and the hive restarts. + function renderGateRegressionBanner() { + const regs = ((window._lastStatus || {}).config || {}).gate_regressions || []; + if (!regs.length) return ''; + const items = regs.map(g => `
  • ${esc(g.gate || '')} was ${esc(g.previous || '')}, now ${esc(g.effective || '')}${g.source ? ` (from ${esc(g.source)})` : ''}
  • `).join(''); + return ``; + } + function renderAgentImport() { var exampleURL = 'https://github.com/hivecommons/hive/blob/HEAD/src/examples/agents/customized-agent.yaml'; var rawURL = 'https://raw.githubusercontent.com/hivecommons/hive/HEAD/src/examples/agents/customized-agent.yaml'; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 80065e550f..96e9f2ecfc 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -52333,7 +52333,7 @@

    Configure LiteLLM

    // agent's kick history over the selected time window. if (tabId === AGENT_PROMPTS_TAB) initAgentPromptHistory(); } else { - body.innerHTML = renderGovernorTab(tabId); + body.innerHTML = renderGateRegressionBanner() + renderGovernorTab(tabId); settingsAnnotateRows(body); if (tabId === 'Hub') { fetchQueueCount(); fetchAutoUpdateStatus(); } // The escalation breaker lives at the top level of hive.yaml, so the @@ -52368,6 +52368,18 @@

    Configure LiteLLM

    if (typeof syncRepoSaveGuard === 'function') syncRepoSaveGuard(); } + // Safety-gate regression banner (#16438): /api/status config.gate_regressions + // lists the gates (review.require_labels, project.paused_repos, …) a + // previous runtime overlay carried that this boot's config dropped or + // loosened. Shown at the top of every Settings tab until the operator + // restores the gate (or removes it on purpose) and the hive restarts. + function renderGateRegressionBanner() { + const regs = ((window._lastStatus || {}).config || {}).gate_regressions || []; + if (!regs.length) return ''; + const items = regs.map(g => `
  • ${esc(g.gate || '')} was ${esc(g.previous || '')}, now ${esc(g.effective || '')}${g.source ? ` (from ${esc(g.source)})` : ''}
  • `).join(''); + return ``; + } + function renderAgentImport() { var exampleURL = 'https://github.com/hivecommons/hive/blob/HEAD/src/examples/agents/customized-agent.yaml'; var rawURL = 'https://raw.githubusercontent.com/hivecommons/hive/HEAD/src/examples/agents/customized-agent.yaml'; From 3b4c78cad27083e1e39b8e08460485d78102fdf4 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Tue, 3 Nov 2026 12:02:13 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20fix(config):=20rename=20gate?= =?UTF-8?q?-regression=20test=20helpers=20to=20avoid=20clashing=20with=20a?= =?UTF-8?q?gent=5Fsandbox=5Fgate=5Ftest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrew Anderson --- src/pkg/config/gate_regression_test.go | 50 +++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/pkg/config/gate_regression_test.go b/src/pkg/config/gate_regression_test.go index a56a3a72fe..32bbb9c1f5 100644 --- a/src/pkg/config/gate_regression_test.go +++ b/src/pkg/config/gate_regression_test.go @@ -9,7 +9,7 @@ import ( "github.com/hivecommons/hive/pkg/writeback" ) -func gateCfg(org string, mutate func(c *Config)) *Config { +func regCfg(org string, mutate func(c *Config)) *Config { c := &Config{} c.Project.Org = org if mutate != nil { @@ -18,7 +18,7 @@ func gateCfg(org string, mutate func(c *Config)) *Config { return c } -func gateNames(regs []GateRegression) []string { +func gateRegNames(regs []GateRegression) []string { out := make([]string, 0, len(regs)) for _, g := range regs { out = append(out, g.Gate) @@ -44,18 +44,18 @@ func TestDetectGateRegressions(t *testing.T) { }{ { name: "unchanged", - prior: gateCfg("acme", full), - effective: gateCfg("acme", full), + prior: regCfg("acme", full), + effective: regCfg("acme", full), }, { name: "no prior gates", - prior: gateCfg("acme", nil), - effective: gateCfg("acme", nil), + prior: regCfg("acme", nil), + effective: regCfg("acme", nil), }, { name: "all dropped", - prior: gateCfg("acme", full), - effective: gateCfg("acme", func(c *Config) { + prior: regCfg("acme", full), + effective: regCfg("acme", func(c *Config) { c.Review.RequireLabels = []string{" "} }), want: []string{ @@ -72,8 +72,8 @@ func TestDetectGateRegressions(t *testing.T) { }, { name: "weakened per-repo writeback mode", - prior: gateCfg("acme", full), - effective: gateCfg("acme", func(c *Config) { + prior: regCfg("acme", full), + effective: regCfg("acme", func(c *Config) { full(c) c.Writeback.PerRepo["torch-spyre/spyre-inference"] = writeback.RepoOverride{Mode: writeback.RepoModeFull} }), @@ -81,45 +81,45 @@ func TestDetectGateRegressions(t *testing.T) { }, { name: "tightened per-repo writeback mode is not a regression", - prior: gateCfg("acme", full), - effective: gateCfg("acme", func(c *Config) { + prior: regCfg("acme", full), + effective: regCfg("acme", func(c *Config) { full(c) c.Writeback.PerRepo["torch-spyre/spyre-inference"] = writeback.RepoOverride{Mode: writeback.RepoModeOff} }), }, { name: "dropped full override is a tightening", - prior: gateCfg("acme", func(c *Config) { + prior: regCfg("acme", func(c *Config) { c.Writeback.PerRepo = map[string]writeback.RepoOverride{"acme/x": {Mode: writeback.RepoModeFull}} }), - effective: gateCfg("acme", nil), + effective: regCfg("acme", nil), }, { name: "label list changed but still non-empty", - prior: gateCfg("acme", full), - effective: gateCfg("acme", func(c *Config) { + prior: regCfg("acme", full), + effective: regCfg("acme", func(c *Config) { full(c) c.Review.RequireLabels = []string{"other-label"} }), }, { name: "pause matched across spellings", - prior: gateCfg("acme", func(c *Config) { c.Project.PausedRepos = []RepoPause{{Repo: "acme/Console"}} }), - effective: gateCfg("acme", func(c *Config) { + prior: regCfg("acme", func(c *Config) { c.Project.PausedRepos = []RepoPause{{Repo: "acme/Console"}} }), + effective: regCfg("acme", func(c *Config) { c.Project.PausedRepos = []RepoPause{{Repo: "console"}} }), }, { name: "nil configs", prior: nil, - effective: gateCfg("acme", nil), + effective: regCfg("acme", nil), }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := DetectGateRegressions(tc.effective, tc.prior) - if strings.Join(gateNames(got), ",") != strings.Join(tc.want, ",") { - t.Fatalf("gates = %v, want %v", gateNames(got), tc.want) + if strings.Join(gateRegNames(got), ",") != strings.Join(tc.want, ",") { + t.Fatalf("gates = %v, want %v", gateRegNames(got), tc.want) } for _, g := range got { if want, ok := tc.wantPrev[g.Gate]; ok && g.Previous != want { @@ -142,7 +142,7 @@ func TestDetectPriorOverlayGateRegressions(t *testing.T) { } return p } - effective := gateCfg("acme", nil) + effective := regCfg("acme", nil) effective.SourcePath = write("hive.yaml", "project:\n org: acme\n") t.Run("no prior overlay", func(t *testing.T) { @@ -161,7 +161,7 @@ func TestDetectPriorOverlayGateRegressions(t *testing.T) { }) t.Run("effective source path is skipped", func(t *testing.T) { - eff := gateCfg("acme", nil) + eff := regCfg("acme", nil) eff.SourcePath = write("gated.yaml", "project:\n org: acme\nreview:\n require_labels: [hive-review]\n") if got := DetectPriorOverlayGateRegressions(eff, []string{eff.SourcePath}); len(got) != 0 { t.Fatalf("got %v, want none", got) @@ -173,8 +173,8 @@ func TestDetectPriorOverlayGateRegressions(t *testing.T) { dash := write("prior.dashboard", "project:\n org: acme\n paused_repos:\n - repo: console\nreview:\n require_labels: [other]\n") got := DetectPriorOverlayGateRegressions(effective, []string{runtime, dash}) want := []string{GateReviewRequireLabels, GatePausedRepos + "[acme/console]"} - if strings.Join(gateNames(got), ",") != strings.Join(want, ",") { - t.Fatalf("gates = %v, want %v", gateNames(got), want) + if strings.Join(gateRegNames(got), ",") != strings.Join(want, ",") { + t.Fatalf("gates = %v, want %v", gateRegNames(got), want) } if got[0].Previous != "[hive-review]" || got[0].Source != runtime { t.Errorf("review gate = %+v, want previous from %s", got[0], runtime) From 3c33f46dca6738c4ac68878c5cf7d90c75189778 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Tue, 3 Nov 2026 12:12:02 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20fix(config):=20pin=20config:?= =?UTF-8?q?=20block=20in=20agent-runtime=20golden=20and=20move=20gate=20ba?= =?UTF-8?q?nner=20margin=20into=20CSS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestAgentRuntimeConfigGolden saw the new config: block as an unexpected key; TestStyleRatchet counted the banner's inline style= attribute above baseline. Signed-off-by: Andrew Anderson --- src/pkg/config/testdata/agent_runtime_golden.json | 3 ++- src/pkg/dashboard/static-src/css/config-dialog.css | 1 + src/pkg/dashboard/static-src/js/config-tabs.js | 2 +- src/pkg/dashboard/static/index.html | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pkg/config/testdata/agent_runtime_golden.json b/src/pkg/config/testdata/agent_runtime_golden.json index 31797a5df0..9850c0d2d4 100644 --- a/src/pkg/config/testdata/agent_runtime_golden.json +++ b/src/pkg/config/testdata/agent_runtime_golden.json @@ -784,5 +784,6 @@ "forgestate": {}, "classification": { "review_bots": {} - } + }, + "config": {} } diff --git a/src/pkg/dashboard/static-src/css/config-dialog.css b/src/pkg/dashboard/static-src/css/config-dialog.css index 66f42f13b8..52c22bfa41 100644 --- a/src/pkg/dashboard/static-src/css/config-dialog.css +++ b/src/pkg/dashboard/static-src/css/config-dialog.css @@ -363,6 +363,7 @@ .cmp-banner { border: 1px solid color-mix(in srgb, var(--yellow) 45%, transparent); background: color-mix(in srgb, var(--yellow) 8%, transparent); border-radius: var(--r); padding: var(--sp-4) var(--sp-5); margin-bottom: var(--sp-6); font-size: var(--fs-sm); } .cmp-banner strong { color: var(--text); } .cmp-banner-detail { color: var(--muted); margin-top: var(--sp-2); } + ul.cmp-banner-detail { margin: var(--sp-2) 0 0 var(--sp-5); } .cmp-framework { display: flex; gap: var(--sp-4); align-items: flex-start; padding: var(--sp-3) var(--sp-0); cursor: pointer; } .cmp-framework input { width: auto; margin-top: var(--sp-1); } .cmp-framework-name { font-weight: 600; color: var(--text); } diff --git a/src/pkg/dashboard/static-src/js/config-tabs.js b/src/pkg/dashboard/static-src/js/config-tabs.js index 615f9dcea6..db3df650d0 100644 --- a/src/pkg/dashboard/static-src/js/config-tabs.js +++ b/src/pkg/dashboard/static-src/js/config-tabs.js @@ -79,7 +79,7 @@ const regs = ((window._lastStatus || {}).config || {}).gate_regressions || []; if (!regs.length) return ''; const items = regs.map(g => `
  • ${esc(g.gate || '')} was ${esc(g.previous || '')}, now ${esc(g.effective || '')}${g.source ? ` (from ${esc(g.source)})` : ''}
  • `).join(''); - return ``; + return ``; } function renderAgentImport() { diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 96e9f2ecfc..0a255cf420 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -4386,6 +4386,7 @@ .cmp-banner { border: 1px solid color-mix(in srgb, var(--yellow) 45%, transparent); background: color-mix(in srgb, var(--yellow) 8%, transparent); border-radius: var(--r); padding: var(--sp-4) var(--sp-5); margin-bottom: var(--sp-6); font-size: var(--fs-sm); } .cmp-banner strong { color: var(--text); } .cmp-banner-detail { color: var(--muted); margin-top: var(--sp-2); } + ul.cmp-banner-detail { margin: var(--sp-2) 0 0 var(--sp-5); } .cmp-framework { display: flex; gap: var(--sp-4); align-items: flex-start; padding: var(--sp-3) var(--sp-0); cursor: pointer; } .cmp-framework input { width: auto; margin-top: var(--sp-1); } .cmp-framework-name { font-weight: 600; color: var(--text); } @@ -52377,7 +52378,7 @@

    Configure LiteLLM

    const regs = ((window._lastStatus || {}).config || {}).gate_regressions || []; if (!regs.length) return ''; const items = regs.map(g => `
  • ${esc(g.gate || '')} was ${esc(g.previous || '')}, now ${esc(g.effective || '')}${g.source ? ` (from ${esc(g.source)})` : ''}
  • `).join(''); - return ``; + return ``; } function renderAgentImport() {