beads/cmd/bd/external_policy_direct_integration_test.go
Denis Redozubov 02f05340f6
fix(externaldeps): guard explicit claims and batch closes (#6738)
* fix(externaldeps): guard explicit claims and batch closes

Preserve external capability policy across lifecycle updates and batch close/claim-next operations, including direct, embedded, and proxied paths. Follow up on upstream PR #4753 and issue #4769.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Denis Redozubov

* test(externaldeps): include embedded regression in CI discovery

* test(serve): preserve external close policy when peeling hooks

Replace the raw batch-closer identity assertion with a behavioral policy check, retaining the no-hooks assertion. Document full-workspace claim filtering and batch lookup cost.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Denis Redozubov

* test(externaldeps): align the mixed-batch pin with #6648's partial-failure exit

Maintainer fixup applied while adopting PR #6738.

`exerciseExternalMutationPolicy`'s `mixed_batch_and_claim_next` subtest asserted
that a partially-refused `bd close` batch keeps the CLI's zero exit status. That
was true at this PR's original base, but #6740 (Beads #6648) landed on main in
the meantime and made a partial batch close exit 1 with an
`N of M issues failed to close` summary. The two changes are independently
correct and merge without a textual conflict, so the stale expectation only
surfaces as a red `cmd/bd` shard after the rebase.

The PR's substance is unchanged: the externally blocked issue is still refused
with its blocker named, the eligible item still closes, and `--claim-next` still
claims. Only the exit-status expectation moves onto the current contract, and
the summary line is now pinned so the interaction between the two features stays
covered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(dolt): check version scope on the transaction owner

withWriteTx and withRetryTx delegate transaction creation to commitWriteTx after #6719. Point the existing completeness guard at that owner so it still checks BeginTx and the versioned-history scope together.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Denis Redozubov

* fix(ci): register external policy files and isolate server cleanup

Include all six new Go files in Bazel targets. Run the direct-server fixture before parallel proxied tests because its cleanup purges dropped databases across their shared server; observed initialization failures coincide with that cleanup.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Denis Redozubov

* fix(externaldeps): scope close-only batch policy and drop the claim --force hint

Review-loop fixup for PR #6738 (iteration 1). The review approved with no
blocker or major findings; this takes its three minors and its nit, all in
code this PR introduces. Each minor lands with a test that a mutation of the
covered code turns red.

[minor] A refused proxied claim suggested an override that cannot work. The
external claim guard ignores --force but shares ErrCloseBlocked with the close
policy, so on the proxied route `bd update <id> --claim` against an externally
blocked issue printed "(use --force to override)". proxiedUpdateFailure now
reports a refused claim as the generic update failure, as the direct route
always has. claim_is_atomic asserts the refusal never mentions --force;
restoring the unconditional hint fails it on the proxied lane.

[minor] A close-only batch demanded policy support for unrelated blockers.
Without ClaimNext the batch closer still passed the workspace's whole
externally blocked set to BatchCloserWithPolicy, so one external blocker
anywhere made a backend lacking PolicyBatchCloserSource (such as one
registered through internal/storage/backends) refuse to close unblocked
issues. The policy is now scoped to the batch items unless the batch claims
next work, which still needs every blocker for FilterClaim. CheckClose looks
up exact ids, so no refusal changes. The NewBatchClosePolicy doc now says when
the whole set is required. TestBatchCloserScopesPolicyWithoutClaim covers an
unrelated blocker, a blocked item, and a next claim against such a backend.

[minor] The policy's fallback target read had no pin.
TestExecuteCloseBatchWithPolicyDefersToTheTargetRead drives it through
sqlmock: a missing target keeps the backend's not-found, and a failing status
read reports that failure, never ErrCloseBlocked. Refusing the missing target
or swallowing the read error each fails it.

[nit] DoltStore and EmbeddedDoltStore BatchCloserWithPolicy return
ErrUnsupported on a nil receiver, as NewBatchCloser does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
2026-10-01 01:35:54 -07:00

15 lines
547 B
Go

//go:build cgo && unix
package main
import "testing"
func TestProxiedServerExternalPolicyDirectParity(t *testing.T) {
requireSharedProxiedServer(t)
// This fixture drops its database and purges the shared server's dropped
// databases on cleanup. Finish before parallel proxied fixtures start so
// that server-wide cleanup cannot race their schema initialization.
bd := buildEmbeddedBD(t)
p := newDirectHistoryProject(t, bd, "xd")
exerciseExternalMutationPolicy(t, crossModeEnv{mode: "direct-server", bd: bd, dir: p.dir, env: p.env})
}