fix(proxy): unsplit bd ready --gated, and stop policing a flag bd list lacks (#6697)
* fix(proxy): unsplit `bd ready --gated`, and stop policing a flag `bd list` lacks
Post-merge review of #6293 (landed as 6f8d15341) found two majors. Both are
incomplete-fix defects in that PR's own work, not regressions: each is a claim
the PR made that its code does not support.
1. `bd ready --gated` still inherited the max-rows refusal that `bd mol ready
--gated` was freed from. The two spellings are documented as the same
gate-resume scan, and on the proxied route they literally are one:
`runReadyProxiedGated` discards its `readyInput` and calls the same
`findGateReadyMolecules` as `runMolReadyGatedProxiedServer`. Neither threads
a row cap. But the new front door keys on `path == "ready"`, which fires for
every `bd ready` invocation, so with `BEADS_MAX_ROWS` exported only the
`mol` spelling worked. #6293 moved the refusal off the shared cobra leaf
name and onto the command; the arm is the level it actually belongs at.
Both refusal sites are exempted, because exempting one only moves the split:
`ready.go`'s in-RunE backstop calls `AssertProxyCapability` with an empty
command, so it always resolves the mode-wide refusal and cannot honor a
command-specific allow. `readyGatedArm` is the single predicate they share.
`--claim` stays refused, including `--claim --gated`. That pair is a usage
error (`gatherReadyInput`), not a gated run, so the mutating arm keeps its
refusal on every path into it and this exemption cannot reopen it.
2. `list`'s `ProxyCapRepo` row was flipped from `notApplicable()` to
`repoRefusal`, promising a typed refusal for `bd list --repo` — but `--repo`
is registered only on `createCmd` (create.go:940), so cobra rejects
`bd list --repo` as an unknown flag before any of this runs. The row, the
comment above `repoRefusal`, the CHANGELOG contract and the test that
"proved" it all described a command line that cannot exist. The policy table
is the audit source of truth this PR argues for; a row refusing a flag the
command does not have is worse than the N/A row it replaced.
Restored to `notApplicable()` and the CHANGELOG retargeted at
`bd create --repo`, which exists and is gated. `runListProxiedServer`'s
defensive branch goes back to the mode-wide assert: keyed on the `list` row
it would now resolve to "allowed" and let a repo override through, which is
the opposite of what the branch is for.
Tests: both fixes are pinned by tests that fail without them, checked by
reverting each guard in place.
- `bd ready --gated` under `BEADS_MAX_ROWS=5` joins the front-door allow matrix
against the real command tree, and the e2e allow matrix beside its `mol`
twin. `--claim` and `--claim --gated` are pinned as still-refused, so
widening the exemption to a bare `--gated` check does not pass.
- The RunE backstop gets its own unit pin rather than being left to the
env-gated proxied e2e lane; it asserts two-sidedly, since a guard that
swallowed the error would pass a "no refusal" check alone.
- `TestProxyCapabilityRowsNameFlagsTheCommandRegisters` is the drift guard the
review asked for: the existing one pins paths, which is why it could not see
a row naming a real command and a flag that does not exist. It runs both
directions — a refused/honored row must name a flag the command registers, an
N/A row must name one it does not.
- The two `list --repo` tests #6293 added both asserted the false premise, not
just the one the review named; both are retargeted at the reachable
`bd create --repo` site and at the corrected row.
Deliberately out of scope: the four non-gating minors and the nit from the same
review are left for separate follow-ups against main.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* docs(changelog): record the `bd ready --gated` proxied row-cap fix
The behavior change in the previous commit is user-visible -- a command line
that exited 1 under a cap now runs -- so it gets its own [Unreleased] bullet
rather than riding along under #6293's entry, which describes the refusal as
it shipped.
Notes the ignored-cap consequence explicitly: `--gated` alongside a cap is now
dropped rather than refused, which is what the direct route has always done.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
e677d90d88
commit
c507f3b4c9
7 changed files with 350 additions and 39 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
|
@ -183,12 +183,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
text. Exit statuses are unchanged; this applies on every topology.
|
||||
|
||||
- **Proxied `--repo` and row-cap refusals are typed again**
|
||||
([#6293](https://github.com/gastownhall/beads/pull/6293)). `bd list --repo`
|
||||
([#6293](https://github.com/gastownhall/beads/pull/6293)). `bd create --repo`
|
||||
under `--proxied-server` answers `--json` with the stable
|
||||
`{"code": "proxy.repo.unsupported", …, "mutates": false}` on stdout rather
|
||||
than prose on stderr, and `bd ready --claim --max-rows N` refuses with the
|
||||
same `proxy.max_rows.unsupported` shape as `bd ready --max-rows N`: `--claim`
|
||||
does not exempt a row cap the proxied route cannot enforce either way.
|
||||
`bd create` is the only command that registers `--repo`, so it is the only
|
||||
command this refusal applies to.
|
||||
- **`bd ready --gated` runs under `--proxied-server` with a row cap set**
|
||||
([#6697](https://github.com/gastownhall/beads/pull/6697)). It was refused
|
||||
whenever `--max-rows` or `BEADS_MAX_ROWS` resolved to a positive cap, while
|
||||
`bd mol ready --gated` — the documented alias for the same gate-resume scan —
|
||||
was not, so one command line behaved differently under its two spellings. The
|
||||
gated arm lists molecules whose gate closed rather than ready rows and threads
|
||||
no cap on either route, so it no longer consults one; a cap passed alongside
|
||||
`--gated` is ignored, matching what the direct route has always done. Every
|
||||
other `bd ready` arm still refuses an active cap, `--claim` included.
|
||||
- **The proxied `bd admin compact` refusal names the command it means**
|
||||
([#6293](https://github.com/gastownhall/beads/pull/6293)). The message is now
|
||||
"only 'bd admin compact --dolt' is supported in proxied-server mode"; it read
|
||||
|
|
|
|||
|
|
@ -154,6 +154,11 @@ func TestHistoryRemoteAllowPathFrontDoorMatrix(t *testing.T) {
|
|||
capRefused bool
|
||||
}{
|
||||
{name: "mol ready --gated", args: []string{"mol", "ready", "--gated"}},
|
||||
// The documented alias for the row above, running the identical
|
||||
// gate-resume scan. It belongs beside it: keying the cap refusal on
|
||||
// `bd ready` rather than on the arm left this spelling refused while
|
||||
// the `mol` one worked, which is the same split one level down.
|
||||
{name: "ready --gated", args: []string{"ready", "--gated"}},
|
||||
{name: "ready", args: []string{"ready"}, capRefused: true},
|
||||
{name: "list", args: []string{"list"}},
|
||||
{name: "dep tree", args: []string{"dep", "tree", sentinel.ID}},
|
||||
|
|
|
|||
|
|
@ -22,11 +22,16 @@ import (
|
|||
|
||||
func runListProxiedServer(cmd *cobra.Command, ctx context.Context, out io.Writer, in listInput) error {
|
||||
if in.repoOverrideSet {
|
||||
// The one live (non-shadowed) --repo refusal: the pre-provider gate
|
||||
// covers `create` only, so this is the site the contract is read from.
|
||||
// Typed, so the proxyCommandCapabilities["list"] row is the single
|
||||
// source of the message and --json still gets code/mutates on stdout.
|
||||
return HandleProxyCapabilityError(AssertProxyCommandCapability("list", ProxyModeProxied, ProxyCapRepo))
|
||||
// Unreachable from the CLI: listCmd registers no --repo flag, so
|
||||
// gatherListInput's Changed("repo") is always false. Kept as a
|
||||
// defensive guard for the day one is added, and deliberately NOT keyed
|
||||
// on proxyCommandCapabilities["list"] -- that row reads
|
||||
// notApplicable() precisely because the flag is absent, so a
|
||||
// command-keyed assert would resolve it to "allowed" and let a repo
|
||||
// override through. The mode-wide rule is the one that still means
|
||||
// something here, and it renders the same typed code/mutates on stdout
|
||||
// under --json.
|
||||
return HandleProxyCapabilityError(AssertProxyCapability(ProxyModeProxied, ProxyCapRepo))
|
||||
}
|
||||
switch {
|
||||
case in.watchMode:
|
||||
|
|
|
|||
|
|
@ -171,9 +171,10 @@ var (
|
|||
// nothing else has been wired to it.
|
||||
watchRefusal = refused("proxy.watch.unsupported", "watch mode not supported in proxied-server mode", ProxyReasonUnimplemented, trackLongTail)
|
||||
// --repo routes to another workspace, bypassing the proxied root entirely,
|
||||
// which is why it is design rather than a gap. `bd list` honors a repo
|
||||
// override and refuses it at runtime, so its row specializes this rule
|
||||
// instead of claiming the flag is absent.
|
||||
// which is why it is design rather than a gap. `bd create` is the only
|
||||
// command that registers the flag, so it is the only command this rule can
|
||||
// actually refuse; every other row for it must be notApplicable(), which is
|
||||
// what TestProxyCapabilityRowsNameFlagsTheCommandRegisters enforces.
|
||||
repoRefusal = refused("proxy.repo.unsupported", "--repo is not supported with --proxied-server", ProxyReasonDesign, "")
|
||||
)
|
||||
|
||||
|
|
@ -210,9 +211,16 @@ var proxyCapabilityMatrix = map[ProxyMode]map[ProxyCapability]proxyCapabilityRul
|
|||
// "ready", and the row records that the command has no --max-rows flag to
|
||||
// refuse. TestProxyCapabilityPolicyKeysResolveInRealCommandTree keeps the pin
|
||||
// honest by failing if the path it names stops existing.
|
||||
//
|
||||
// A row must describe a flag the command actually registers. `list`'s
|
||||
// ProxyCapRepo is notApplicable() for that reason and not as a hedge: listCmd
|
||||
// has no --repo flag (create.go:940 registers the only one), so `bd list --repo`
|
||||
// dies in cobra as an unknown flag and a refusal row here would be policy no
|
||||
// command line can reach. TestProxyCapabilityRowsNameFlagsTheCommandRegisters
|
||||
// enforces both directions of that rule.
|
||||
var proxyCommandCapabilities = map[string]map[ProxyMode]map[ProxyCapability]proxyCapabilityRule{
|
||||
"show": {ProxyModeProxied: {ProxyCapWatch: watchRefusal}},
|
||||
"list": {ProxyModeProxied: {ProxyCapWatch: honored(), ProxyCapMaxRows: honored(), ProxyCapRepo: repoRefusal}},
|
||||
"list": {ProxyModeProxied: {ProxyCapWatch: honored(), ProxyCapMaxRows: honored(), ProxyCapRepo: notApplicable()}},
|
||||
"dep tree": {ProxyModeProxied: {ProxyCapMaxRows: honored()}},
|
||||
"ready": {ProxyModeProxied: {ProxyCapMaxRows: maxRowsRefusal}},
|
||||
"mol ready": {ProxyModeProxied: {ProxyCapMaxRows: notApplicable()}},
|
||||
|
|
@ -345,7 +353,7 @@ func validateProxyCapabilitiesBeforeProvider(cmd *cobra.Command) error {
|
|||
return HandleProxyCapabilityError(AssertProxyCommandCapability(path, ProxyModeProxied, ProxyCapWatch))
|
||||
}
|
||||
}
|
||||
if path == "ready" {
|
||||
if path == "ready" && !readyGatedArm(cmd) {
|
||||
// --claim is NOT exempt. The proxied ready role cannot enforce a row
|
||||
// cap on either arm, and ready.go refuses a positive cap on both (see
|
||||
// its comment above rejectMaxRowsUnderProxiedServer) — so exempting
|
||||
|
|
@ -353,6 +361,12 @@ func validateProxyCapabilitiesBeforeProvider(cmd *cobra.Command) error {
|
|||
// same refusal to an untyped one raised after the provider opened.
|
||||
// A malformed or negative value is still rejected here, before any
|
||||
// provider work, which is what the claim path gained.
|
||||
//
|
||||
// --gated IS exempt, and the guard sits on the branch rather than
|
||||
// inside it so the arm skips the resolver too: the direct route never
|
||||
// resolves a cap before dispatching --gated, so resolving one here
|
||||
// would make a malformed or negative value fail on the proxied route
|
||||
// alone. See readyGatedArm for why the arm takes no cap at all.
|
||||
maxRows, err := resolveMaxRowsQuiet(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"maps"
|
||||
"os"
|
||||
"slices"
|
||||
|
|
@ -99,6 +97,96 @@ func TestProxyCapabilityPolicyKeysResolveInRealCommandTree(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// proxyCapabilityFlagNames records the command-line flag each capability
|
||||
// governs. They happen to be the same strings as the capability constants, and
|
||||
// this map exists so that stays a checked fact rather than a coincidence: a
|
||||
// capability renamed away from its flag would turn the guard below into a
|
||||
// no-op that still passes.
|
||||
var proxyCapabilityFlagNames = map[ProxyCapability]string{
|
||||
ProxyCapReadonly: "readonly",
|
||||
ProxyCapMaxRows: "max-rows",
|
||||
ProxyCapWatch: "watch",
|
||||
ProxyCapRepo: "repo",
|
||||
}
|
||||
|
||||
// commandAcceptsFlag reports whether this command would accept --name on a real
|
||||
// command line, counting flags inherited from parents (--readonly is a root
|
||||
// persistent flag) as well as locally registered ones.
|
||||
func commandAcceptsFlag(cmd *cobra.Command, name string) bool {
|
||||
if cmd.Flags().Lookup(name) != nil {
|
||||
return true
|
||||
}
|
||||
return cmd.InheritedFlags().Lookup(name) != nil
|
||||
}
|
||||
|
||||
// TestProxyCapabilityRowsNameFlagsTheCommandRegisters is the flag-level half of
|
||||
// the policy drift guard, and the sibling above is the reason it is needed: that
|
||||
// one pins PATHS, so a row can name a command that genuinely exists and still
|
||||
// describe a flag the command has never had. `bd list` carried a
|
||||
// ProxyCapRepo: repoRefusal row promising a typed refusal for `bd list --repo`,
|
||||
// which cobra rejects at parse time as an unknown flag — a policy row no command
|
||||
// line could reach, plus a changelog contract no wrapper could observe. The path
|
||||
// guard could not see it.
|
||||
//
|
||||
// The rule runs in both directions, because each direction is a different lie:
|
||||
//
|
||||
// - a refused/honored row says the command handles the flag, so the command
|
||||
// must register it — otherwise the row is unreachable policy;
|
||||
// - a notApplicable() row says the command has no such flag, so the command
|
||||
// must NOT register it — otherwise a live flag is silently unpoliced, and
|
||||
// the front door's command-keyed assert resolves it to "allowed".
|
||||
func TestProxyCapabilityRowsNameFlagsTheCommandRegisters(t *testing.T) {
|
||||
// Vacuity guard: a flag name that no command registers would let every
|
||||
// "must not register" assertion below pass for the wrong reason.
|
||||
registrars := map[string]int{}
|
||||
var walk func(*cobra.Command)
|
||||
walk = func(c *cobra.Command) {
|
||||
for _, name := range proxyCapabilityFlagNames {
|
||||
if c.Flags().Lookup(name) != nil {
|
||||
registrars[name]++
|
||||
}
|
||||
}
|
||||
for _, child := range c.Commands() {
|
||||
walk(child)
|
||||
}
|
||||
}
|
||||
walk(rootCmd)
|
||||
for capability, name := range proxyCapabilityFlagNames {
|
||||
if capability == ProxyCapReadonly {
|
||||
continue // root persistent flag; no command registers it locally
|
||||
}
|
||||
if registrars[name] == 0 {
|
||||
t.Errorf("no command in the real tree registers --%s (capability %q); the flag name is stale", name, capability)
|
||||
}
|
||||
}
|
||||
|
||||
for _, path := range slices.Sorted(maps.Keys(proxyCommandCapabilities)) {
|
||||
cmd := realCommandAtPath(t, path)
|
||||
for mode, capabilities := range proxyCommandCapabilities[path] {
|
||||
for capability, rule := range capabilities {
|
||||
name, ok := proxyCapabilityFlagNames[capability]
|
||||
if !ok {
|
||||
t.Errorf("proxyCommandCapabilities[%q][%s] uses capability %q with no recorded flag name; add one so this guard keeps covering it",
|
||||
path, mode, capability)
|
||||
continue
|
||||
}
|
||||
registered := commandAcceptsFlag(cmd, name)
|
||||
if rule.Outcome == ProxyOutcomeNA {
|
||||
if registered {
|
||||
t.Errorf("proxyCommandCapabilities[%q][%s][%s] is notApplicable(), but `bd %s` accepts --%s; the row denies a flag the command has",
|
||||
path, mode, capability, path, name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !registered {
|
||||
t.Errorf("proxyCommandCapabilities[%q][%s][%s] is %q, but `bd %s` accepts no --%s; no command line can reach this row",
|
||||
path, mode, capability, rule.Outcome, path, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestProxyFrontDoorBranchesUseRealCommandPaths pins the command paths the
|
||||
// three front-door branches key on by hand: the two validators, plus the
|
||||
// skipsStoreInit route into validateProxyRegistryBeforeProvider in main.go.
|
||||
|
|
@ -125,6 +213,7 @@ func TestProxyCapabilityFrontDoorAllowsSupportedCommands(t *testing.T) {
|
|||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
for _, tc := range []struct {
|
||||
path string
|
||||
flags []string
|
||||
cappedEnv bool
|
||||
wantRefuse bool
|
||||
}{
|
||||
|
|
@ -139,11 +228,26 @@ func TestProxyCapabilityFrontDoorAllowsSupportedCommands(t *testing.T) {
|
|||
{path: "dep tree", cappedEnv: true},
|
||||
{path: "compact"},
|
||||
{path: "compact", cappedEnv: true},
|
||||
// `bd ready --gated` is the documented alias for the row above and runs
|
||||
// the identical gate-resume scan, so a cap that leaves `bd mol ready
|
||||
// --gated` alone must leave this spelling alone too. Keying the refusal
|
||||
// on the command rather than the arm split one command line in half.
|
||||
{path: "ready", flags: []string{"gated"}},
|
||||
{path: "ready", flags: []string{"gated"}, cappedEnv: true},
|
||||
// `bd ready` is the command the max-rows refusal was written for, so
|
||||
// it must still refuse an active cap.
|
||||
{path: "ready", cappedEnv: true, wantRefuse: true},
|
||||
// ...on every arm that actually lists ready rows. --claim is not
|
||||
// exempt, and neither is --gated in combination with it: that pair is a
|
||||
// usage error rather than a gated run, so the claim arm keeps its
|
||||
// refusal on every path into it.
|
||||
{path: "ready", flags: []string{"claim"}, cappedEnv: true, wantRefuse: true},
|
||||
{path: "ready", flags: []string{"claim", "gated"}, cappedEnv: true, wantRefuse: true},
|
||||
} {
|
||||
name := tc.path
|
||||
for _, flag := range tc.flags {
|
||||
name += " --" + flag
|
||||
}
|
||||
if tc.cappedEnv {
|
||||
name += " with " + maxRowsEnvVar
|
||||
}
|
||||
|
|
@ -154,6 +258,23 @@ func TestProxyCapabilityFrontDoorAllowsSupportedCommands(t *testing.T) {
|
|||
t.Setenv(maxRowsEnvVar, "")
|
||||
}
|
||||
cmd := realCommandAtPath(t, tc.path)
|
||||
// These are the real commands off rootCmd, so a flag set here
|
||||
// outlives the subtest unless it is put back.
|
||||
for _, flagName := range tc.flags {
|
||||
flag := cmd.Flags().Lookup(flagName)
|
||||
if flag == nil {
|
||||
t.Fatalf("bd %s has no --%s flag to set", tc.path, flagName)
|
||||
}
|
||||
if err := cmd.Flags().Set(flagName, "true"); err != nil {
|
||||
t.Fatalf("set --%s on bd %s: %v", flagName, tc.path, err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := flag.Value.Set(flag.DefValue); err != nil {
|
||||
t.Errorf("restore --%s on bd %s: %v", flagName, tc.path, err)
|
||||
}
|
||||
flag.Changed = false
|
||||
})
|
||||
}
|
||||
var err error
|
||||
stderr := captureStderr(t, func() {
|
||||
err = validateProxyCapabilitiesBeforeProvider(cmd)
|
||||
|
|
@ -218,57 +339,88 @@ func TestProxyCapabilityRulesAlwaysCarryAMessage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestListRepoRowMatchesShippedBehavior pins the row against the runtime
|
||||
// refusal it is supposed to describe. The table documents itself as the
|
||||
// deterministic audit source of truth, so a row that disagrees with the
|
||||
// command is worse than an absent one.
|
||||
func TestListRepoRowMatchesShippedBehavior(t *testing.T) {
|
||||
err := AssertProxyCommandCapability("list", ProxyModeProxied, ProxyCapRepo)
|
||||
// TestRepoRowsMatchShippedBehavior pins the --repo rows against the commands
|
||||
// they describe, in both directions. The table documents itself as the
|
||||
// deterministic audit source of truth, so a row that disagrees with the command
|
||||
// is worse than an absent one — and that cuts the same way whether the
|
||||
// disagreement over- or under-states the refusal.
|
||||
func TestRepoRowsMatchShippedBehavior(t *testing.T) {
|
||||
// `bd create --repo` is the reachable site: create.go registers the flag and
|
||||
// the pre-provider gate asserts the mode-wide rule for it, so that rule must
|
||||
// carry the documented message.
|
||||
err := AssertProxyCapability(ProxyModeProxied, ProxyCapRepo)
|
||||
if err == nil {
|
||||
t.Fatal("list --repo asserted nil; bd list --repo is refused under --proxied-server")
|
||||
t.Fatal("--repo asserted nil; bd create --repo is refused under --proxied-server")
|
||||
}
|
||||
if got, want := err.Error(), "--repo is not supported with --proxied-server"; got != want {
|
||||
t.Fatalf("list --repo refusal = %q, want %q", got, want)
|
||||
t.Fatalf("--repo refusal = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
// `bd list --repo` is NOT a reachable site: listCmd registers no --repo, so
|
||||
// the row reads notApplicable() and a command-keyed assert must come back
|
||||
// allowed. An earlier version of this test asserted the opposite — that the
|
||||
// list row refuses — which pinned a promise no command line could collect,
|
||||
// since cobra rejects `bd list --repo` as an unknown flag before any of this
|
||||
// runs.
|
||||
if err := AssertProxyCommandCapability("list", ProxyModeProxied, ProxyCapRepo); err != nil {
|
||||
t.Fatalf("list --repo asserted %v; bd list has no --repo flag, so its row must be notApplicable()", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestListRepoProxiedRefusalIsStrictJSON pins the refusal's SHAPE, where the
|
||||
// test above pins only its text. `bd list --repo` is the one --repo refusal
|
||||
// the pre-provider gate does not shadow (it covers `create` only), so this
|
||||
// call site is where the contract is actually observed — and a message-only
|
||||
// assertion is exactly what let the site go untyped while the row still
|
||||
// promised a code. A wrapper parsing --json must get the stable code and the
|
||||
// mutates flag on stdout, and the error must still carry exit 1.
|
||||
func TestListRepoProxiedRefusalIsStrictJSON(t *testing.T) {
|
||||
// TestRepoProxiedRefusalIsStrictJSON pins the --repo refusal's SHAPE, where the
|
||||
// test above pins only its text: a wrapper parsing --json must get the stable
|
||||
// code and the mutates flag on stdout, and the error must still carry exit 1.
|
||||
//
|
||||
// It drives `bd create --repo` through the REAL command tree, and that is the
|
||||
// whole point of the test. `bd create` is the only command that registers
|
||||
// --repo (create.go), so its pre-provider gate is the only site a user can
|
||||
// actually reach this refusal from. An earlier version of this test called
|
||||
// runListProxiedServer directly with a hand-built listInput{repoOverrideSet:
|
||||
// true} — which cannot happen, because listCmd has no --repo flag for cobra to
|
||||
// mark Changed, and `bd list --repo` dies at parse time as an unknown flag. A
|
||||
// direct-call assertion looks like coverage while proving nothing about any
|
||||
// command line.
|
||||
func TestRepoProxiedRefusalIsStrictJSON(t *testing.T) {
|
||||
oldJSON := jsonOutput
|
||||
jsonOutput = true
|
||||
t.Cleanup(func() { jsonOutput = oldJSON })
|
||||
|
||||
root := &cobra.Command{Use: "bd"}
|
||||
cmd := &cobra.Command{Use: "list"}
|
||||
root.AddCommand(cmd)
|
||||
cmd := realCommandAtPath(t, "create")
|
||||
flag := cmd.Flags().Lookup("repo")
|
||||
if flag == nil {
|
||||
t.Fatal("bd create no longer registers --repo; the refusal has no reachable site")
|
||||
}
|
||||
if err := cmd.Flags().Set("repo", "/somewhere/else"); err != nil {
|
||||
t.Fatalf("set --repo on bd create: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := flag.Value.Set(flag.DefValue); err != nil {
|
||||
t.Errorf("restore --repo on bd create: %v", err)
|
||||
}
|
||||
flag.Changed = false
|
||||
})
|
||||
|
||||
var gotErr error
|
||||
out := captureStdout(t, func() error {
|
||||
gotErr = runListProxiedServer(cmd, context.Background(), io.Discard, listInput{repoOverrideSet: true})
|
||||
gotErr = validateProxyCapabilitiesBeforeProvider(cmd)
|
||||
return nil
|
||||
})
|
||||
|
||||
if code, ok := exitCodeFromError(gotErr); !ok || code != 1 {
|
||||
t.Fatalf("list --repo refusal exit = %v (typed=%v), want 1", code, ok)
|
||||
t.Fatalf("create --repo refusal exit = %v (typed=%v), want 1", code, ok)
|
||||
}
|
||||
var got map[string]any
|
||||
if err := json.Unmarshal([]byte(out), &got); err != nil {
|
||||
t.Fatalf("list --repo refusal is not JSON on stdout: %q (%v)", out, err)
|
||||
t.Fatalf("create --repo refusal is not JSON on stdout: %q (%v)", out, err)
|
||||
}
|
||||
if got["code"] != "proxy.repo.unsupported" {
|
||||
t.Fatalf("list --repo refusal code = %v, want proxy.repo.unsupported (out=%q)", got["code"], out)
|
||||
t.Fatalf("create --repo refusal code = %v, want proxy.repo.unsupported (out=%q)", got["code"], out)
|
||||
}
|
||||
if got["error"] != "--repo is not supported with --proxied-server" {
|
||||
t.Fatalf("list --repo refusal error = %v", got["error"])
|
||||
t.Fatalf("create --repo refusal error = %v", got["error"])
|
||||
}
|
||||
if got["mutates"] != false {
|
||||
t.Fatalf("list --repo refusal mutates = %v, want false", got["mutates"])
|
||||
t.Fatalf("create --repo refusal mutates = %v, want false", got["mutates"])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,15 @@ This is useful for agents executing molecules to see which steps can run next.`,
|
|||
// this safety limit; malformed values remain usage errors. The
|
||||
// pre-provider front door refuses the same cap first, so this is
|
||||
// its backstop — both raise proxy.max_rows.unsupported.
|
||||
if err := rejectMaxRowsUnderProxiedServer(cmd); err != nil {
|
||||
//
|
||||
// --gated is skipped here as well as at the front door, and it has
|
||||
// to be skipped in both places: this backstop calls
|
||||
// AssertProxyCapability with an empty command, so it always
|
||||
// resolves the mode-wide refusal and cannot honor the
|
||||
// command-specific allow the front door's path-keyed assert reads.
|
||||
// Exempting only the front door would move the split from one
|
||||
// refusal site to the other, not close it.
|
||||
if err := rejectReadyMaxRowsUnderProxiedServer(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
return runReadyProxiedServer(cmd, rootCtx)
|
||||
|
|
@ -271,6 +279,50 @@ This is useful for agents executing molecules to see which steps can run next.`,
|
|||
},
|
||||
}
|
||||
|
||||
// readyGatedArm reports whether this `bd ready` invocation dispatches to the
|
||||
// gate-resume arm — the same scan `bd mol ready --gated` runs, and the reason
|
||||
// the row cap does not apply to it. Both proxied refusal sites call this, so
|
||||
// the exemption cannot land on one and miss the other.
|
||||
//
|
||||
// The arm lists molecules whose gate closed, never ready rows: on the direct
|
||||
// route --gated reaches runMolReadyGatedCore above any cap resolution, and on
|
||||
// the proxied route runReadyProxiedGated discards its readyInput and calls the
|
||||
// same findGateReadyMolecules as runMolReadyGatedProxiedServer. `mol ready`,
|
||||
// the documented alias, carries a notApplicable() cap row for exactly that
|
||||
// reason; keying the refusal on `bd ready` alone split one documented command
|
||||
// line across its two spellings.
|
||||
//
|
||||
// --claim is excluded deliberately. `--claim --gated` is a usage error
|
||||
// (gatherReadyInput), not a gated run, so the claim arm keeps the refusal it is
|
||||
// owed on every code path and this exemption cannot reopen it.
|
||||
func readyGatedArm(cmd *cobra.Command) bool {
|
||||
if cmd == nil {
|
||||
return false
|
||||
}
|
||||
if gated, _ := cmd.Flags().GetBool("gated"); !gated {
|
||||
return false
|
||||
}
|
||||
claim, _ := cmd.Flags().GetBool("claim")
|
||||
return !claim
|
||||
}
|
||||
|
||||
// rejectReadyMaxRowsUnderProxiedServer is `bd ready`'s in-RunE backstop for the
|
||||
// row cap the proxied ready role cannot enforce. It exists as a named function
|
||||
// rather than an inline `if` so the exemption is reachable from a unit test:
|
||||
// the front door's half runs against the real command tree in
|
||||
// TestProxyCapabilityFrontDoorAllowsSupportedCommands, but this half sits
|
||||
// behind usesProxiedServer() and would otherwise be pinned only by the
|
||||
// env-gated proxied e2e lane.
|
||||
//
|
||||
// Call it in place of rejectMaxRowsUnderProxiedServer on this command; every
|
||||
// other capped command wants the unconditional form.
|
||||
func rejectReadyMaxRowsUnderProxiedServer(cmd *cobra.Command) error {
|
||||
if readyGatedArm(cmd) {
|
||||
return nil
|
||||
}
|
||||
return rejectMaxRowsUnderProxiedServer(cmd)
|
||||
}
|
||||
|
||||
// blockedFilterFromFlags builds the blocked-issue filter from blockedCmd's
|
||||
// flags. Both the direct and the proxied-server path call it, so the two
|
||||
// cannot drift as filtering flags are added.
|
||||
|
|
|
|||
|
|
@ -76,6 +76,78 @@ func TestReadyRefusesMaxRowsUnderProxiedServerOnClaim(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestReadyGatedSkipsMaxRowsRefusalUnderProxiedServer pins the third arm.
|
||||
// `bd ready --gated` and `bd mol ready --gated` are documented as the same
|
||||
// gate-resume scan, and on the proxied route they literally are one:
|
||||
// runReadyProxiedGated discards its readyInput and calls the same
|
||||
// findGateReadyMolecules as runMolReadyGatedProxiedServer. Neither threads a
|
||||
// row cap, so a cap must not refuse either spelling -- refusing only the
|
||||
// `bd ready` one split a single documented command line in half for anyone
|
||||
// with BEADS_MAX_ROWS exported.
|
||||
//
|
||||
// This goes through RunE rather than calling the helper, because RunE is where
|
||||
// the second refusal site lives: the pre-provider front door is pinned
|
||||
// separately against the real command tree in
|
||||
// TestProxyCapabilityFrontDoorAllowsSupportedCommands, and exempting one site
|
||||
// without the other just moves the refusal rather than removing it.
|
||||
//
|
||||
// The assertion is two-sided on purpose. A guard that swallowed the error
|
||||
// entirely would pass a "no refusal" check alone, so the test also requires
|
||||
// RunE to have reached the proxied dispatch -- uowProvider is nil here, so
|
||||
// runReadyProxiedServer's own message is the proof it got that far.
|
||||
func TestReadyGatedSkipsMaxRowsRefusalUnderProxiedServer(t *testing.T) {
|
||||
pinProxiedServerMode(t)
|
||||
pinJSONOutput(t, false)
|
||||
|
||||
if uowProvider != nil {
|
||||
t.Fatal("precondition: uowProvider must be nil so the dispatch cannot open a real proxied connection")
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
env string
|
||||
}{
|
||||
{name: "flag", args: []string{"--gated", "--max-rows", "5"}},
|
||||
{name: "env", args: []string{"--gated"}, env: "5"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Setenv(maxRowsEnvVar, tc.env)
|
||||
cmd := newReadyFlagsCommand(t, tc.args...)
|
||||
|
||||
var err error
|
||||
stderr := captureStderr(t, func() { err = readyCmd.RunE(cmd, nil) })
|
||||
|
||||
if strings.Contains(stderr, "--max-rows / BEADS_MAX_ROWS is not supported in proxied-server mode") {
|
||||
t.Fatalf("proxied `bd ready %s` was refused for a cap the gated arm never uses: %q",
|
||||
strings.Join(tc.args, " "), stderr)
|
||||
}
|
||||
if !strings.Contains(stderr, "proxied-server UOW provider not initialized") {
|
||||
t.Fatalf("proxied `bd ready %s` did not reach the proxied dispatch: err=%v stderr=%q",
|
||||
strings.Join(tc.args, " "), err, stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestReadyClaimGatedKeepsMaxRowsRefusalUnderProxiedServer is the boundary of
|
||||
// the exemption above. `--claim --gated` is a usage error rather than a gated
|
||||
// run, so it must not pick up the gated arm's pass: the claim arm is the one
|
||||
// invocation that mutates on the far side of this guard, and it keeps the
|
||||
// refusal on every path into it. Without this, widening the exemption to a bare
|
||||
// `--gated` check would look correct.
|
||||
func TestReadyClaimGatedKeepsMaxRowsRefusalUnderProxiedServer(t *testing.T) {
|
||||
pinProxiedServerMode(t)
|
||||
pinJSONOutput(t, false)
|
||||
t.Setenv(maxRowsEnvVar, "5")
|
||||
|
||||
err := rejectReadyMaxRowsUnderProxiedServer(newReadyFlagsCommand(t, "--claim", "--gated"))
|
||||
if err == nil {
|
||||
t.Fatal("proxied `bd ready --claim --gated` under a live cap was allowed; want the refusal the claim arm is owed")
|
||||
}
|
||||
assertExitCode(t, err, 1)
|
||||
}
|
||||
|
||||
// TestReadyClaimWithoutLiveCapIsNotRefusedUnderProxiedServer is the other half:
|
||||
// the refusal is conditioned on a live cap, not on --claim. Without it, a guard
|
||||
// that rejected every proxied --claim would pass the test above.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue