* test(conformance): author R7.1 as-of-read conformance contract Adds a new Phase 0 conformance contract for R7.1 (as-of reads, gastownhall/beads#6136, design doc #5898 rev 9) -- no fixture existed for this anywhere in backend/conformance/, so this is authored from scratch, not un-skipped. AsOfReadFixture supplies three hooks: Resolve (the read under test), MintAt (seeds a version at a controlled accept-time), and MakeUnanswerable (arranges a Gone/Unknown refusal independently of RetentionFixture/EpochFixture's own removal machinery, since R7.1's refusal is a sibling contract to R17/R20, not a dependent of them). Five Run* functions cover the bead's five required-coverage points verbatim: - selector accepts either an instant or a version address, and both name the same answer when they resolve to the same version; - resolution returns the latest version at-or-before T, with a version accepted after T strictly excluded even when close by; - a served result reports the exact address it served; - an unanswerable read refuses as a typed Gone*/Unknown outcome with a reason, and never substitutes a neighboring version, the nearest surviving version, or current state -- asserted directly by requiring Address == "" on every refusal; - local completeness only (TC3): a lineage minted into one of two stores resolves there and refuses Unknown (FR-06) on the store that never received it, asserting nothing about agreement between the two. The file's doc comment states the Memory-plane-consumer-policy non-goal explicitly (closed-before-T boundary, sibling exclusion, supersession exclusion are consumer policy per #5877, not part of this primitive) so the gap reads as deliberate scope, not an oversight. Wired onto all three storage legs (dolt, embeddeddolt, uow) with unconditional "not implemented" stubs rather than partial-real hooks, so every case fails via MintAt on its first fixture call -- deterministic RED with no risk of an accidental pass, per the precedent set by be-x5jqd.1. Sentinel error messages reference be-x5jqd.5, the implementation child this suite is written ahead of. TestEveryLegWiresEveryRoleContract requires zero waivers: all 5 new entrypoints are fully wired (not nil) on all three legs. Branch cut from the rebased be-2h167 head (5fdfb92fe5). Verified via go build ./..., go vet ./..., gofmt -l, and go test -tags cgo across all three legs: all 5 new subtests (8 counting the 4-way Gone/Unknown table) FAIL for the documented reason, TestEveryLegWiresEveryRoleContract passes cleanly on all three legs, and TestVersionedHistoryPhase0RunsInFullSkipMode is unaffected. Bead: be-x5jqd.2 * fix(history): refuse metadata integers binary64 cannot hold exactly (refs be-wdlod, #6358 follow-up) canonicalDurableState canonicalizes numbers per RFC 8785 (JCS), which renders every number as an IEEE-754 binary64 double regardless of magnitude. An integer-valued metadata literal past 2^53-1 therefore rounds to a DIFFERENT VALUE on the way into durable_state -- not a formatting change, a value change -- which can collapse two distinct issue states onto one durable_state and therefore one content token. refuseUnrepresentableIntegers is the fix: an admission gate, one layer above the JCS step, that parses each JSON number literal exactly with math/big (never float64 -- float64 rounding is the exact thing being guarded against) and refuses whenever the literal's VALUE, not its spelling, is an integer whose magnitude exceeds 2^53-1. Value-not-form matters because the first cut of this gate skipped any literal containing '.', 'e', or 'E' outright, reasoning that non-integer forms round-trip losslessly -- true for genuinely fractional literals, but not for an integer VALUE spelled in decimal or exponential form: QA found that 9007199254740993.0 and 9.007199254740993e15 walked straight past that first gate and canonicalized to the same colliding target as the bare literal. The predicate now inspects the value via big.Rat.SetString/.IsInt, so all three spellings are refused alike. 1e300 is refused too, no notation carve-out: it denotes the integer 10^300, and binary64 spacing near that magnitude is roughly 2^248 -- vastly wider than the collision window at the 2^53 boundary this gate exists to close. Admitting that spelling while refusing 9007199254740993 would be the same defect with a bigger window (mayor's ruling, citing this collision-window argument as decisive). Non-integer values stay admissible past the bound (1.5e300 is fine): ES6 shortest-round-trip formatting is a bijection on doubles, so two non-integer literals collide only if they already denoted the same double before this gate ever ran, and a fractional literal never carried a promise of exact decimal storage the way an integer -- an id, a count, a timestamp -- carries a promise of exactness that silent rounding would corrupt. jcsCanonicalize is canonicalDurableState's RFC 8785 step pulled out on its own, below the gate rather than behind it, because refusing 1e300 puts the admission policy at odds with one of this store's own spec- conformance fixtures: testdata/jcs/input/values.json, one of the 10 official RFC 8785 vectors shipped verbatim from the spec's reference suite (not authored here), itself contains 1E30. RFC 8785 conformance is a claim about the canonicalizer, not about this store's admission policy, so TestCanonicalDurableStateIsJCS now runs all 10 shipped vectors -- values.json included, still asserting 1E30 folds to 1e+30 per spec -- through the ungated jcsCanonicalize, while its two local ad hoc cases keep exercising the full gated canonicalDurableState, since neither conflicts and both are more faithful to production traffic that way. The gate's own refusal of that magnitude is pinned separately, on its own terms, in version_history_integer_admission_test.go. Severity is MINOR, not MAJOR: Dolt's JSON column type already renormalizes metadata to float64 on every read regardless of this gate (measured on dolt 2.2.3: 9007199254740993 reads back as 9007199254740992, 1e300 as 1e+300), which converges two distinct in-memory states to one stored state before any version row is minted. The collision this gate closes is therefore unreachable through normal bd update traffic on this backend; it stays real for off-path writes -- bd sql, a hand-written JSONL import, or a TEXT-column backend -- which is why this landed as a follow-up rather than gating Phase 2 itself. Verified clean: a full module compile; static analysis over the storage tree; the complete issueops package suite (260 subtests); the schema package suite; and the broader storage tree, apart from one dolt-package test that fails identically against the pre-this-diff baseline (a Dolt server port collision with a concurrent session's process on this host) -- confirmed pre-existing and environmental, not caused by this change. * feat(issueops): implement R7.1 as-of read's store-layer primitive (be-x5jqd.5) Turns backend/conformance/versioned_read_contract.go (authored RED in 6aefdce60, gastownhall/beads#5898 rev 9, #6136) towards GREEN. This commit lands the shared production seam; wiring the three per-leg fixtures (dolt, embeddeddolt, uow) onto it is a follow-up commit. asof_read.go (new): AsOfReadInTx resolves an AsOfSelector (an instant or a previously-served version address) to one issue_versions row -- the latest version accepted at or before T, everything later strictly excluded -- and reports either its state and address, or a typed refusal (gone-retention/gone-erasure/gone-reorganization/unknown) with a reason. storeID is accepted only for signature parity with the fixture hook shape (Design D: the conformance suite's own ad hoc dispatch string selects among per-leg isolated test stores; issue_versions carries no store_id column, matching CurrentEpochInTx's precedent). AsOfRestriction is string-backed, unlike R20's int-backed EpochRestriction, because it round-trips directly through the new removed_restriction column with a plain cast. Migration 0069 adds issue_versions.removed_restriction VARCHAR(30), nullable (NULL = live, never a stored value). Sits alongside removed_at/ removed_reason (migration 0067, virgin until this slice); AsOfReadInTx only READS all three -- a future R17 is the real writer via hold/remove/ erase primitives, no collision. Guarded PREPARE + CLI direct-DDL override + schema_test.go hygiene entries, all modeled on 0068's pattern; TestLatestVersionIncludesMigration0068 is superseded per the one-pin-at-a-time convention. version_history.go: splits RecordVersionInTx into a versionedHistoryEnabled- gated wrapper and a new exported RecordVersionAtInTx, both delegating to a shared recordVersionAtInTx(..., at time.Time) body. RecordVersionAtInTx is test-support only -- ungated, caller-chosen timestamp -- so an as-of- read fixture's MintAt hook can mint version rows dated in the past without flipping a store's history-enabled flag. No behavior change for existing RecordVersionInTx callers. The new/moved code shifted which function each completeness guard sees as the enclosing write site, so all three needed updating, not bypassing: - row_lock_guard_test.go's funcNameExemptions key moves from RecordVersionInTx to recordVersionAtInTx (the write's new actual enclosing function), reasoning extended to cover both callers. - journal_completeness_test.go's beadDMLExemptions and version_completeness_test.go's versionExemptions each gain a RecordVersionAtInTx entry mirroring RecordVersionInTx's own (test- support twin, no production caller, no mutation of its own to journal/mint beyond the seam itself). Also fixed a latent test-helper gotcha found while writing the 0069 Dolt-CLI test: queryDoltCSV trims the whole `dolt sql -r csv` output before parsing, so a row whose ONLY selected column is NULL renders as a bare blank line that strings.TrimSpace silently swallows when it's the trailing line, collapsing "one row, NULL value" into "zero rows". Fixed by selecting a non-NULL anchor column (issue_id) alongside the column under test. Verification performed: full module compile and static analysis, gofmt clean; the complete internal/storage/schema suite with the real-Dolt-CLI lane enabled; and the complete internal/storage/issueops suite, including every completeness/row-lock structural guard -- all clean. * feat(issueops): wire dolt, embeddeddolt, and uow onto R7.1 as-of read (be-x5jqd.5) Turns backend/conformance/versioned_read_contract.go fully GREEN (authored RED in 6aefdce60, gastownhall/beads#5898 rev 9, #6136): this follows up on 4da98a9a8's shared production seam by wiring all three storage legs' AsOfReadFixture (Resolve/MintAt/MakeUnanswerable) onto issueops.AsOfReadInTx, per that commit's own stated plan. Each leg's asOfReadHarness is Design D's dispatch table: the conformance suite invents storeID strings to select among N isolated stores, and isolating them is entirely the harness's job -- AsOfReadInTx itself stays storeID-oblivious. The three legs differ only in how they get that isolation cheaply: - dolt: one shared testcontainer, N randomly-named databases - embeddeddolt: N fully independent on-disk databases - uow: one shared dolt sql-server subprocess (NewDoltServerUOWProvider's adoption semantics collapse repeat calls against the same root dir onto the same process), N randomly-named databases All three harnesses are Fatalf/Skip-free below their own TestAsOfReadContract body: AsOfReadFixture's hooks carry no *testing.T of their own and run from inside t.Run subtest closures (sometimes nested two deep), where FailNow/SkipNow would panic with "subtest may have called FailNow on a parent test". Failures instead flow back as a plain error into conformance.RunAsOfReadXXX, which Fatalfs correctly on the subtest's own goroutine. Two small companion fixes surfaced while wiring the legs on: - issueops.asOfVersionAddress -> AsOfVersionAddress (exported): each leg's MintAt needs to build the exact token its own RecordVersionAtInTx write will resolve against, from a different package than issueops. - recordVersionAtInTx now truncates `at` to whole seconds before writing it to issue_versions.change_at (DATETIME, migration 0067). Measured on dolt 2.2.3: the column ROUNDS a sub-second value rather than truncating it, so a change_at of 13:32:04.77 lands at 13:32:05 -- strictly later than the instant it was meant to record. That breaks resolveAsOfRevisionInTx's "at or before T" comparison (asof_read.go) for any T between the true instant and the rounded- up one. This is a production correctness fix, not test-only: RecordVersionInTx hits the identical hazard on every real time.Now().UTC() call whose nanosecond component rounds up. Verification performed: - uow: TestAsOfReadContract green standalone (5 subtests, 4 nested restriction variants) and the full uow package green in isolation (673s, includes pre-existing TestReleaserContract and everything else). A `go test ./internal/storage/...` full-tree sweep flagged uow FAIL via a 600s hang inside TestReleaserContract's migration lock -- traced to cross-package parallel resource contention from running the whole storage tree's dolt-sql-server-spinning suites concurrently, not a regression: the same test is clean when the package runs alone. - embeddeddolt: TestAsOfReadContract green (22.89s, all subtests and all 4 restriction variants). - dolt: skipped on this host -- no Docker for the leg's testcontainer, the same pre-existing skipIfNoDolt gate the whole dolt package already runs under, unrelated to this change. - TestEveryLegWiresEveryRoleContract and TestEveryContractImporterInTheStorageTreeIsRegistered both pass for all three legs. - gofmt clean; whole-module build and vet clean. Bead: be-x5jqd.5 * feat(versions): bd versions + a config switch for versioned history (refs be-hs42e.6.2) Versioned history has been buildable but not usable: migrations 0067+ create issue_versions, and the Phase 2 writer fills it, but SetVersionedHistoryEnabled was a Go method nothing in cmd/bd ever called. There was no supported way for a person to turn the feature on, and no way at all to read it back without raw Dolt SQL. This adds the switch and a reader. - versioned-history.enabled (env BD_VERSIONED_HISTORY_ENABLED), default off, applied at the top of wireStorageDecorators. It MUST run on the raw store: the capability is a type assertion and no decorator forwards it, so applying it after a wrap would silently leave history off while the config said it was on. TestVersionedHistoryConfigAppliesToTheRawStore pins the ordering, and fails rather than skips if a decorator ever starts forwarding. - storage.VersionLister + issueops.ListVersionsInTx over issue_versions, on the dolt and embeddeddolt legs. A narrow capability rather than a Storage method, following ExternalRefHistoryQuerier: a backend that cannot know must be able to say so instead of answering "none". - bd versions <id>, with three distinguishable outcomes rather than two. Off, unsupported, and empty are different answers with different fixes; an empty list is a claim about the bead, and returning it for the other two would be a wrong answer rather than an empty one. The four removal restrictions render as four sentences, and unknown (no lineage knowledge here) is not gone. - REV is printed as a local ordinal with a footer saying so. It is deliberately NOT presented as a citable address: AsOfVersionAddress mints over the ordinal, two clones can both hold revision 8 of the same bead, and the durable version_id primary key has not landed. An address printed now would break every citation once it does. - bd version <id> now points at bd versions <id> instead of printing bd's own build and looking like the bead has no history. Bare bd version is unchanged. No migration: 0067/0068/0069 already carry every column this reads. Verified on a scratch store: create + 2 updates + close with the flag on lists 4 attributed versions; with the flag off, 0 rows in issue_versions and the command refuses naming the key. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(versions): emit local_revision, not revision, in --json (bee's #5898 consumer read) types.Issue already ships `json:"revision"` (types.go:1206) and it is the row-lock CAS token — an unrelated value, and a string where this one is an int64. Emitting "revision" from the versions payload would put two meanings and two types on one key in the place machines read: the `bd version` collision again, with worse consequences, since a script that learned one shape gets the other and cannot tell. local_revision also carries the non-citability with the value rather than only in a footer no script parses, and needs no rename when version_id lands beside it. Raised by @bee-ghosttrack's consumer read on #5898, who reported a couple of hundred script files parsing `bd … --json` — this is the part of the surface they would actually touch. Pinned by TestVersionsJSONDoesNotCollideWithIssueRevision. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(versions): make the advertised switch actually switch it on (#6661 review) @bee-ghosttrack's blocking finding: the help text and the off-refusal both told the user to run `bd config set versioned-history.enabled true`, and that command did not turn the feature on. The key is not yaml-only, so `bd config set` routed it to the workspace DATABASE; both readers called config.GetBool, which is viper (yaml + env) only. The user ran exactly what they were told, was told it was set, and recording stayed off — configured on, actually off, one layer up from the decorator-ordering hazard this command already guards. Takes bee's option (b): read the switch from the store's own config, where `bd config set` already writes it. That also makes recording a property of the STORE rather than of whoever is calling, which is what closes finding 2 — two clients of one sql-server can no longer disagree about whether a write is recorded. The two planes are OR'd rather than ranked. The hazard is a write that fails to record, never one that records when it needn't, so either saying yes is enough and neither can silently switch the other off. BD_VERSIONED_HISTORY_ENABLED still works for a one-off run. A store with no settings plane (proxied, no-db) falls back to viper instead of failing the command. Also from that review: - finding 3: the read no longer refuses just because recording is off. A store that recorded for a month and was switched off HAS versions; refusing made a claim about the store from a fact about this invocation's config, which VersionLister's own doc says are independent. Rows are listed either way, with a note when recording is currently off; refuse-with-remedy only when off AND empty. - finding 4: an unresolved id with no versions is "no such bead", not "none yet". Falling through on an unresolved id stays right — a deleted bead can still have versions — but only until the answer is empty. - finding 5: the ordering test's escape hatch is t.Fatal, not t.Skip; a skip returned before the assertion that actually guards the ordering. The storage_chain.go doc cited a test name that never existed. version_lister.go promised a list of compile-time assertions that was not there; the assertions now exist in each leg's own package, where they can compile. - `versioned-history.` is a recognized config prefix, so the set no longer prints "not a recognized config key" immediately before confirming the set. Test: TestVersionedHistorySwitchRoundTrip_Embedded drives the real `bd config set` through to a real `bd versions` against a real store, with BD_VERSIONED_HISTORY_ENABLED cleared so a pass proves the store setting carried it alone. This is the round trip bee asked for, and it is the only shape that could have caught the original defect — a fake-backed unit test cannot see a disagreement between two real planes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs(versions): name what the OR'd switch planes cost (#6661 review) @bee-ghosttrack, round 2: with the two planes OR'd rather than ranked, the consequence worth naming is that once the store setting says on, BD_VERSIONED_HISTORY_ENABLED=0 cannot countermand it for a single run. The help now says so, and says where to turn it off instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(versions): gate the wiring store read on the capability, not a recover (#6661 review) @bee-ghosttrack's round-3 blocking finding. wireStorageDecorators reads the versioned-history switch off the raw store on every bd invocation, and did so before anything established that the store could use the answer. cmd/bd's own fakeProbingDoltStore embeds a nil storage.DoltStorage, so the promoted WorkspaceConfig SIGSEGV'd at wiring time -- and a panic takes the whole test binary down, which is why one unguarded read showed up as two red CI steps (Test (macos-latest), PR Core (wrapper timing)) rather than one failed test. Takes the fix bee prescribed: assert storage.VersionedHistoryConfigurer first and read the store plane only when the store could act on the answer. The previous round fixed this with a recover plus a WorkspaceConfig on the fake, and left a comment arguing that no capability assertion could work. That argument was wrong, and wrong in a specific way worth recording: it reasoned about asserting WorkspaceConfig, which IS declared on storage.DoltStorage and so matches every store including the nil-embedding fake. bee proposed asserting VersionedHistoryConfigurer, which is a different interface -- SetVersionedHistoryEnabled is NOT part of DoltStorage, so the fake does not promote it and does not satisfy it. The comment rebutted a fix that had not been proposed. It now states what is actually true. So the fake goes back to byte-identical with the pushed head: the wiring fix fixes that test without touching it, as bee said it would, and the fake keeps the "only the methods below may be called" constraint its own doc asserts. The recover stays, as a backstop rather than the guard. It covers what the assertion does not: versionedHistoryEnabled is also called from `bd versions`, where the read is the point and no capability gate precedes it, and a store that DOES implement the capability can still have a half-built settings plane. The viper plane is still read first and unconditionally, so a set-but-unsupported store still reaches applyVersionedHistoryConfig and still gets its warning. Only the store-plane read is gated. The one case that loses a warning is a store whose own settings plane says true but which lacks the capability -- and `bd config set` could not have written that plane on such a store to begin with. Tests, split so each layer fails for its own reason: - TestWireStorageDecoratorsSkipsTheStoreReadForANonConfigurer asserts calls == 0, not merely that it survived. "It survived" is what the recover delivers too, which is how this regressed the first time. - TestWireStorageDecoratorsSurvivesAStoreThatCannotAnswer keeps the recover's case, now on a store that IS a configurer so the guard lets it through. - TestVersionedHistoryEnabledForWiringReadsTheStoreWhenItCanRecord pins that the guard did not stop reading the plane finding 1 existed to start reading. Mutation-verified both ways: removing the guard fails the first test on calls=1/want=0 while everything still "passes" by surviving; removing the recover leaves the first test green and fails only the second. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(versions): name the embedded round-trip so CI selects it (#6661 review) @bee-ghosttrack's round-3 finding 2. The round-trip test that proves the two config planes agree ran only on the author's machine. .github/scripts/embedded-test-shard.sh discovers what to run with `grep -rh '^func TestEmbedded' cmd/bd/*_embedded_test.go` and validates manifest entries against ^TestEmbedded[A-Za-z0-9_]+$. TestVersionedHistorySwitchRoundTrip_Embedded matched neither, so the only lane that sets BEADS_TEST_EMBEDDED_DOLT=1 for cmd/bd never selected it; the generic Test jobs run without that env, where the test's own guard skipped it. Skipped and passed look alike from outside, which is what made it invisible. Renaming is the whole fix -- a test absent from the shard manifest still gets a shard from the fallback distribution. Verified by running the script's own selector over the tree and confirming the new name is discovered. The rationale is now a comment on the test, because the old name reads more naturally and nothing else in the file explains why the prefix is load-bearing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(versions): drop the dead fixture, name the empty arm (#6661 review) @bee-ghosttrack's round-3 finding 3. TestVersionsRefusesWhenFlagOff built a backend holding one recorded version, handed it to nothing, and ended in `_ = backend`. The fixture was load-bearing for the assertion the test was named after -- that the read was refused BEFORE the backend was consulted. Finding 3 removed that behaviour on purpose, so the assertion went with it; the fixture stayed behind, unused, under a name still promising the old contract. Renamed to TestVersionsOffAndEmptyRefusesWithRemedy for what it actually pins, moved beside TestVersionsOffButRecordedStillLists so the two read as the pair they are -- recording off decides the FOOTER, never whether to read; off with rows lists them, off and empty is the one case that refuses -- and the dead fixture is gone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(proxy): give bd versions a capability row, a typed refusal (#6661) main's proxied-server capability registry (#6582) requires every command path to carry a row, and TestProxyCapabilityRegistryCoversCommandTree fails for `bd versions`, which this PR adds. It is refused, reason unimplemented, rather than permitted. It is a pure read (issueops.ListVersionsInTx in one read transaction), so nothing about it is unsafe on a shared backend and "design" would be wrong. But it reaches the backend only through the optional storage.VersionLister, which the dolt and embedded stores implement and the uow provider does not. Permitting it would open the proxied provider in the root pre-run (starting the proxy and dolt) and then fail untyped at errVersionsUnsupported. The row refuses with proxy.versions.unsupported before any side effect, and its tracking names the missing piece: a VersionLister over the proxied uow provider (tracker #6132). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(uow): register verified shutdown cleanup in TestAsOfReadContract (#6661) main's TestEveryServerFixtureRegistersVerifiedCleanup (#6441) requires every server fixture to use verifiedShutdownCleanup(t, storeRootDir) instead of calling proxy.Shutdown directly, so a shutdown that refuses cannot leave a live dolt sql-server behind a green run. TestAsOfReadContract still had its own proxy.Shutdown cleanup that only logged the error. The cleanup is registered at the same point, so the LIFO ordering the harness relies on (every provider closed before the shared server stops) is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * style(schema): gofmt cli_migrations.go after the 0070 renumber The rebase onto upstream's 0069_widen_issue_versions_datetime_precision (#6675) joined its const and the renumbered 0070 comment without the separating blank line, which make fmt-check rejects. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(history): stop flooring change_at now that 0069 widened it (refs be-hs42e.10) recordVersionAtInTx carried `at = at.Truncate(time.Second)`. That was correct while 0067's plain DATETIME was in force: Dolt's datetime(0) does not truncate sub-second input, it ROUNDS half-up, so a change_at could be stored strictly LATER than the instant it recorded and break AsOfReadInTx's "latest version accepted at or before T". Flooring first left nothing to round. Migration 0069 widened change_at and removed_at to DATETIME(6), which removes the rounding entirely and makes the floor actively harmful — it threw away the microseconds the widening exists to keep. Two versions minted in the same second collapsed onto one stored value and stopped being distinguishable by change_at, which defeats --at, the only PORTABLE selector the read surface offers while revision stays a per-store ordinal and no durable version address has shipped. This was measured, not inferred. On a store carrying both the widening and the floor, four versions minted inside one second all read back 15:40:38.000000: the column could hold microseconds and the writer refused to supply them. Two correct fixes cancelling each other, and only the second one was visible. removed_at needs no matching change: MarkLatestVersionRemovedInTx already passes time.Now().UTC() straight through and was never floored. Audited rather than assumed. Pinned by TestRecordVersionKeepsSubSecondChangeAt (embeddeddolt), which mints two versions 500ms apart inside one second and asserts both that the fractional part survives and that the two differ. Verified it FAILS with the floor restored — reporting exactly the 11:04:07.000000 collapse — and passes without it, so it is a real guard rather than a test that passes either way. The column's own half of the contract stays pinned by TestMigration0069ChangeAtSurvivesSubSecondPrecisionThroughDoltCLI. Also drops this branch's own tx-minting guard commit, which upstream landed independently as #6833. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(feat): red — Activate versioned history in every store and provider factory, each store reading its own #6661 switch (stacked on #6661) (refs be-qxq70) Tests first, all failing on the right reasons at fb6e219d6a (#6661's head): - D1: on real embedded stores a routed update, a routed close and `bd create --repo` into a rig whose OWN row is on each gain 0 issue_versions rows, want 1; the control (a write inside the rig) gains 1. - D3: BD_VERSIONED_HISTORY_ENABLED=1 records into no routed store, and =0 is shown not to switch off a store whose row is on. - D4: TestEveryStoreConstructionActivatesVersionedHistory flags all 9 store and provider factories, and its mutation probe reports "probed 0 of 9". - wiring: wireStorageDecorators still reads the store's row (1 read) and switches it on; activation belongs to the factories. - internal/versionedhistory (does not exist yet) and the doctor repair opener: the resolver, the provider read (K1), the error-vs-absent diagnostics and the shared-activation requirement. * feat: green — Activate versioned history in every store and provider factory, each store reading its own #6661 switch (stacked on #6661) (refs be-qxq70) Stacked on #6661 (fb6e219d6a). #6661's plane and approved commits are unchanged: the switch stays a row of the store's own config table, OR'd with viper, and `bd config set versioned-history.enabled true` still writes that row and not config.yaml. The defect: applyVersionedHistoryConfig ran only from wireStorageDecorators, so the one store a command opens for its own workspace was activated and every store built by newDoltStoreFromConfig (prefix-routed update/close, `bd create --repo`, the direct-mode open) was not. With the switch on they recorded no issue_versions row while the command reported success. - Activation moves to where a store or unit-of-work provider is constructed (the store_factory.go/_nocgo.go twins, uow_factory.go's two provider constructors, the personal-migration planning store, and bd doctor's repair opener), on the raw store, before anything can wrap it. wireStorageDecorators no longer activates, so each store's row is read once per open. - One resolver, in internal/versionedhistory, reachable from doctor/fix which cannot import package main. #6661's semantics are preserved: one key spelling, viper first, then the capability check, then the row read, with the recover backstop. The behavior-preserving refactor of #6661's versioned_history_switch.go / storage_chain.go is the only edit to files #6661 introduced; the resolver tests moved with the code, assertions unchanged. - K1: a provider has no DoltStorage, so its row is read through a unit of work (NewUOW + ConfigUseCase().GetConfig) at construction: a pooled connection, one SELECT, rolled back. The constructors have already run initSchema, so this starts no server and creates nothing. It does not fall back to viper alone. - A row read that errors resolves to off but is reported under BD_DEBUG; an absent row stays silent. - Docs (configuration.md), a CHANGELOG entry, and a hint at `bd config set ... true` time that the setting replicates and is single-writer only. The bazel-sync run also wanted unrelated BUILD entries for files that already exist at #6661's head (versions.go, versioned_read_contract.go, ...); they are not part of this change and are left out. * test(feat): green — a served mutation records from the provider's own row, on a real server (refs be-qxq70) K1 is the one place the resolver cannot ask a DoltStorage: `bd serve` against a server-mode workspace writes through a unit-of-work provider, so its flag is read through NewUOW + ConfigUseCase().GetConfig at construction. The fakes in internal/versionedhistory prove the read; this proves it WORKS against a real Dolt server at that moment (pool open, database selected, schema migrated). Two server-mode workspaces on the shared test container: the one whose own row says on records a served HTTP mutation (+1 issue_versions row), the one with no row records none. Measured both ways: passes with the provider activation in place, and fails ("added 0 issue_versions row(s), want 1") with it deleted from both provider constructors in uow_factory.go. Proxied lane only (BEADS_TEST_PROXIED_SERVER=1 BEADS_TEST_ENV_RUN_DOLT=1 TESTCONTAINERS_RYUK_DISABLED=true), like TestServeActivatesTheEventsJournal, so it skips in a plain make test. * test(feat): red — #6661 review round, small items: findings 2, 4, 5, 6 and 8 Tests for the small findings in the second review round on #6661. - 2: `bd versions` must decide "recording" from the store's own setting. BD_VERSIONED_HISTORY_ENABLED=1 with the store's row unset and nothing recorded must refuse, not answer "none yet"; the help text must not offer the variable as a per-run switch for a read. - 4: `bd versions --json` is one object, {"versions": [...], "recording": bool}, with [] rather than null when nothing is recorded. - 5: AsOfReadInTx reports any stored removed_restriction outside its four values, "live" included, as unknown. - 6: the 0070 header spells the restriction vocabulary with the underscore spellings the code stores and compares. - 8: `bd version <arg>` exits 1 and points at `bd versions <arg>`. This one pins behaviour the branch already has, so it passes at red; it was shown to fail with the guard removed. Item 7 is a comment-only fix and has no test. * feat: green — #6661 review round, small items: findings 2, 4, 5, 6 and 7 - 2: `bd versions` reports the store's own setting. It read the environment and config.yaml as well, so BD_VERSIONED_HISTORY_ENABLED=1 made a store that never recorded answer "No versions recorded yet" instead of refusing with the remedy. It only reads, so those planes cannot make the store record. The "for one run" hint is dropped from the help and the refusal, since it could only ever produce the wrong answer. - 4: `bd versions --json` is always {"versions": [...], "recording": bool}, with [] rather than null when nothing is recorded. Previously a bare array, or null, and no recording flag. - 5: AsOfReadInTx reports a stored removed_restriction outside its four values, "live" included, as unknown instead of passing it through. - 6: the 0070 header and its test use the underscore spellings the code stores and compares. 0070 is unreleased, and this changes its content hash. - 7: comment only. DATETIME(6) still rounds to the microsecond; the comment said 0069 removed the rounding entirely. * test(fix): red — #6661 number admission: fractions past the bound, exponent cost, pre-enable scan Tests for the review round on the number-admission gate, written before the change: - a fraction whose nearest double is at or past 2^53 is refused (9007199254740993.5, 9007199254740994.5, 9007199254740991.5), and the gate is closed under its own canonicalization, checked as a property over a corpus - classification depends on magnitude, not on the size of an exponent: 1e100000000 and -1e400 are refusals, 1e-100000000 and 1e-400 are admitted, and allocation does not grow with the exponent - the sentinel's text names the I-JSON exact-integer range - CheckMetadataVersionable agrees with the mint, and FindUnversionableMetadata finds what the mint would refuse and skips what it never versions - bd config set versioned-history.enabled true refuses, writing nothing, over rows the mint would refuse, and false never scans Guards that pass before and after by design: the verdict on every literal as the store returns it, the mint's refusal writing nothing, and, on the server and embedded legs, the store-level property that no two literals reading back as different numbers share a canonical form. Those store tests also log what each Dolt holds for a number outside the range when history is off, and pin that a later write to such a row is refused once history is on. * fix: green — #6661 number admission: the nearest-double rule, ParseFloat classification, a pre-enable scan at the switch The admission gate now refuses a JSON number literal if and only if the binary64 nearest to it has magnitude above 2^53-1, or it overflows, whatever the literal's spelling: - a fraction that rounds to or past 2^53 (9007199254740993.5, 9007199254740994.5, 9007199254740991.5) is refused, so the gate is closed under its own canonicalization - literals are classified with strconv.ParseFloat, linear in their length, so 1e1000000 no longer builds a million-digit integer inside the writer's transaction; an overflow is the sentinel and a magnitude too small for binary64 is admitted; math/big is gone - the sentinel reads "number is outside the I-JSON exact-integer range (magnitude above 2^53-1)"; ErrIntegerNotRepresentable keeps its name, with a comment saying why - ordinary fractions such as 0.1 stay admitted; no verdict on a value the store hands back changes The header now says what the mint's refusal is: an integrity backstop inside the writer's transaction, not an admission policy for metadata. bd config set versioned-history.enabled true now checks the store first. It reads every issue the mint would version, runs the mint's own function over each one's metadata (issueops.CheckMetadataVersionable, through issueops.FindUnversionableMetadata), and refuses, writing nothing, while any is refused, printing the count, the ids and the fix. There is no override; setting it false never scans. The environment and config.yaml planes do not pass through the command and rely on the refusal at write time. Also: docs and a CHANGELOG entry, and comments in the existing admission tests that described the old rule. * test(fix): keep the exponent-cost allocation test stable under the race detector TestNumberAdmissionAllocationsDoNotGrowWithTheExponent compared two independently averaged allocation counts with a strict >. Under -race sync.Pool drops one Put in four at random, and the refusal's fmt.Errorf takes its printer from a pool, so a call now and then allocates one more than it would. The test failed on most runs of `go test -race -short`, the flag set of the required lane, and never without -race. That noise only ever adds allocations, so compare the fewest allocations over many single-call samples instead. The comparison stays strict, and it still fails on the exact big.Rat gate this test exists to keep out (49 allocations for 1e1000000 against 36 for 1e400). The doc comment no longer claims the count is deterministic under -race. * test(fix): red — set-many skips the pre-enable scan; pin what the scan reads bd config set-many versioned-history.enabled=true switches versioned history on with no pre-enable scan: only bd config set makes it. With a row holding a number outside the I-JSON exact-integer range the setting is turned on and the next write to that row fails. The new embedded test drives the real verb over such a row and expects the whole batch to be refused, writing nothing. The scan's own embedded test only used open issues, so deleting AllFlag or IncludeAllTypes, or replacing the unlimited Limit, left it green. It now adds a closed, a pinned and a gate offender, and a second test imports more rows than one default page and expects every one of them counted. * fix: green — bd config set-many runs the pre-enable scan for versioned-history.enabled bd config set refuses to turn versioned history on while an issue holds metadata a version could not record. bd config set-many writes the same setting through a validation loop of its own and made no such check, so it switched history on over a row whose next write then failed. It now runs the same check for that one key inside its validation loop, before any pair of the batch is written, so a refusal stores nothing. The check reads through the accessor it already used on both routes: the store the command has opened on the direct route, the provider on the proxied one. * chore: strip internal tracker ids from the comments and tests across #6661's range Comment and test-text changes only; no behaviour changes. Across every commit from the merge-base with upstream main to here, the comments and tests named internal tracker ids (one bead id in eleven comments and in one test failure message, an example id in the `bd version` guard's comment, and an internal decision's attribution in the huge-exponent admission test). They now cite gastownhall/beads#5898 and #6136 only, which is what a reader of the public branch can follow. The 0070 migration's header comment is one of the edits. That migration is new on this branch (it does not exist on upstream main), so the change is not an edit to a shipped migration, but it does change the file's content hash; the schema tests that compute hashes are self-consistent. Text that already exists on upstream main is left as it is, even where it mentions an id: this commit does not rewrite lines the range did not add. * chore(bazel): bazel-sync (gazelle) for the #6661 range * fix(bazel): give fix_test the store.go its activation guard parses TestVersionedHistoryDoctorRepairOpenerUsesTheSharedActivation parses store.go from its working directory. `go test` runs in the package directory, so the file is there. A Bazel test only sees its declared runfiles, so the test failed with parse store.go: open store.go: no such file or directory in //cmd/bd/doctor/fix:fix_test (--config=ci) and in shard 1 of //cmd/bd/doctor/fix:fix_dolt_test (--config=doltserver), which runs the same binary through data = [":fix_test"]. Declare store.go as data on fix_test. * test(fix): red — the pre-enable scan must check the whole issue, as the mint does bd config set versioned-history.enabled true runs a check over every issue before it turns history on. The check looked at each issue's metadata alone, while the mint canonicalizes the whole issue. A gate's timeout is a time.Duration that a version holds as nanoseconds, so a gate whose timeout is past 2^53-1 ns (about 104.25 days) holds a number outside the I-JSON exact-integer range: the mint refuses every write to it, the scan never looked, and the switch could be turned on over it. - The agreement test's domain widens from metadata documents to whole issues: the metadata corpus, plus timeouts at 2500h (admitted), 2600h, 8760h and -2600h (refused), exactly 2^53-1 ns (admitted) and 2^53 ns (refused). - The scan test covers a gate over 105 days and expects the verdict to name the field, "timeout". - The mint-level refusal test covers the same gate and expects the refusal to name the field as well as the literal, for a number in metadata too. - An end-to-end test on the direct route and one on the proxied route create gates with bd gate create --timeout, expect the enable to refuse and name them, and expect the issues the scan names to be exactly the issues whose next write the mint refuses. - Three guards keep the scan's lite read from hiding a number: every column it leaves out is a string or a list of strings, nothing the mint adds and the scan does not load can hold a number, and no exported check over part of an issue exists beside the one the mint runs. Each guard is also run against shapes it must refuse, so it cannot pass by finding nothing. The new symbols (CheckIssueVersionable, FindUnversionable and the Field of UnversionableIssue) do not exist yet, so the issueops tests do not build. * fix: green — the pre-enable scan runs the mint's own check over the whole issue The check behind bd config set versioned-history.enabled true looked at each issue's metadata alone. The mint canonicalizes the whole issue, and a gate's timeout, a time.Duration held as nanoseconds, is a number outside the I-JSON exact-integer range once it is past 2^53-1 ns (about 104.25 days). The mint refuses every write to such a gate, the scan cleared the switch over it, and the first write after that failed. CheckIssueVersionable is now exactly canonicalDurableState's refusal over the whole issue, and FindUnversionable runs it over every issue the mint would version. It replaces FindUnversionableMetadata, and CheckMetadataVersionable is gone, so no check over part of an issue is exported beside the one the mint runs. A refusal names the top-level field it found the value in ("metadata", "timeout") as well as the literal, on the mint and on the scan; the field is located only after a refusal, so a write that is admitted still reads the document once. A gate timeout above 2^53-1 ns is unrecordable by policy: it is refused at the write, named by field and documented, not re-encoded. The refusal at the switch gives the fix for each field. For a number in metadata that is bd update --metadata or --unset-metadata, which works with history on or off because a version is recorded from the state after the write. For a gate timeout, which bd update cannot change, it is removing the gate with bd delete, or setting the timeout_ns column with bd sql while history is off; bd sql needs a server-backed store, and the text says so. It also says the check runs once, now: a writer that does not record (an older bd, bd sql, a pull from a clone that had history off) can add such a row afterwards, and the first write to it then fails with the same refusal. Making the check and the write of the setting one transaction would narrow that window, not close it. Corrected in the comments, the docs and the changelog as well: an import is not a path that skips the mint, since it goes through the same batch create; and Dolt's JSON column collapses duplicate keys when it stores a document, so on a Dolt store neither the scan nor the mint can see one, and the duplicate-key refusal is a defence for a backend that keeps them. * test(fix): red — the listing must answer as the as-of read does; the SDK opens must be accounted for Three review findings on the versioned-history change and one wording fix, tests first. - A removed version's restriction. AsOfReadInTx answers a stored value outside the four-value vocabulary (a NULL or empty column, "live", a hyphenated or arbitrary string) as unknown, but ListVersionsInTx hands the column back as stored, for every row, and the label bd versions prints passes such a string through. A table test runs the listing and the as-of read on the same stored value, for a version that was removed and one that was not, and expects the same answer, and none for a version that was never removed. The label gets the same out-of-vocabulary values and is expected to render what unknown renders. - The SDK's store opens. The shared construction guard now scans the repository root as well, so the Go SDK's five opens (Open, OpenFromConfig and OpenGated, and OpenBestAvailable in each build-tag twin) are noticed. Nothing accounts for them yet, so both guards fail on exactly those five sites. - A bytes bound beside the allocation-count bound on the number admission gate. A classifier that builds the number it is asked about makes one allocation whatever the exponent, so the count bound passes it, and the bytes grow. The fewest bytes one call allocates for a literal with a huge exponent must be no more than for a small one plus a margin. It passes today, because the gate never builds the number; it fails for a gate that does. - The refusal at the switch names the gate remedy as bd delete <id> --force, says that without --force bd only previews, and says that removing the gate unblocks anything it was blocking. The embedded and proxied end-to-end tests expect all three. * fix: green — the listing answers as the as-of read does; the SDK opens are accounted for Three review findings on the versioned-history change and one wording fix. A removed version's restriction. A stored removed_restriction is a free string, and only the four values of the vocabulary are answers. The as-of read already reported anything else (a NULL or empty column, "live", a hyphenated or arbitrary string) as unknown, but the listing handed the column back as stored, for every row, and the label bd versions prints passed it through. NormalizeRemovedRestriction is now the one place that decision is made. AsOfReadInTx calls it; ListVersionsInTx calls it for a version that was removed and gives a version that was not removed no restriction; and restrictionLabel renders through it. The listing, its JSON and the label now say what the as-of read says for the same row. The SDK's store opens. The Go SDK's five opens (Open, OpenFromConfig and OpenGated, and OpenBestAvailable in each build-tag twin) apply neither per-store switch, the events journal's or versioned history's, and they still do not. Applying them would change the library's behavior for every embedder, so that is a separate change; this one declares the boundary. The shared construction guard now accounts for the five with one exemption reason that is true of both switches, so a new SDK open is noticed rather than missed, and its staleness check keeps the exemptions honest. The docs gain one bullet saying that writers built on the SDK do not apply the switch. The bytes bound on the number admission gate needs no production change: the gate never builds the number, which is what the bound pins. The refusal at the switch now names the gate remedy as bd delete <id> --force, says that without --force bd only previews, and says that removing the gate also unblocks anything it was blocking. The docs line says the same. For a gate that blocks an issue, bd delete without --force prints a preview and exits 1, and with --force the gate is removed and what it blocked is ready again. * test(bazel): declare the root package's Go source as data for //cmd/bd:bd_test The shared store-construction scan now reads the repository root, where the Go SDK's opens live, but //cmd/bd:bd_test declared none of the root package's source. Under bazel test the scan therefore saw an empty directory, reported the five SDK exemptions as no longer matching a store construction site, and failed the events-journal guard, while go test, which sees the whole checkout, passed. List the root in tools/bazel/go_srcs.py so the generator emits its managed go_srcs filegroup there, and add that filegroup to bd_test's data. The new block is the generator's own output and nothing else changes. * ci: list the switch scan's proxied gate-timeout test in the 30-shard manifest Upstream main (#7129) moved the proxied-server tier to 30 duration-balanced shards, and TestProxiedShardManifestGeneratorNotStale requires every TestProxiedServer*/TestServerMode* test exactly once in that block. This branch adds TestProxiedServerVersionedHistorySwitchRefusesAnUnrecordableGateTimeout (cmd/bd/versioned_history_switch_scan_proxied_integration_test.go), so the block needs its line. Written by the generator itself: python3 scripts/ci/gen_proxied_shard_manifest.py 30 --weights=duration --write (one line, shard 8); --check exits 0 afterwards. Rebase note (maintainer): regenerated on current main, whose proxied-server tier uses 34 shards; the generator's incremental output (gen_proxied_shard_manifest.py 34 --weights=duration --write) placed this test at shard 6 of the 34-shard block. * ci: list the PR's embedded versioned-history tests in the embedded shard manifests #7156 made the embedded-Dolt tier's shard manifests exact-once (50 cmd shards, 15 storage shards), so every embedded test must be listed. This PR adds five embedded cmd tests and three embedded storage tests; this commit is exactly what the generators write for them: python3 scripts/ci/gen_embedded_cmd_shard_manifest.py 50 --weights=duration --write python3 scripts/ci/gen_embedded_storage_shard_manifest.py 15 --weights=duration --write Incremental: 8 lines added, none moved. Rebase note (maintainer): regenerated on current main, whose embedded manifests use 100 cmd shards and 40 storage shards; the generator's incremental output placed these tests at cmd shards 55 (TestEmbeddedVersionedHistorySwitchScansEveryRowNotOnePage), 56 (...SwitchRoundTrip), 57 (...SwitchRefusesUnversionableMetadata), 58 (...SwitchRefusesAnUnrecordableGateTimeout) and 59 (...SetManyRefusesUnversionableMetadata) of the 100-shard block, and at storage shards 5 (TestRecordVersionKeepsSubSecondChangeAt), 6 (TestVersionedHistoryKeepsNumbersTheStoreDistinguishesApart) and 23 (TestAsOfReadContract) of the 40-shard block. * test: exempt OpenBestAvailableWith, where #7188 moved the SDK's store construction Upstream #7188 split beads.OpenBestAvailable: it now delegates to the new OpenBestAvailableWith, which builds the store. This PR's two construction guards (TestEveryStoreConstructionActivatesTheEventsJournal and TestEveryStoreConstructionActivatesVersionedHistory) share one exemption list keyed by function, so after merging main they flagged OpenBestAvailableWith as an unexempted construction site and reported the OpenBestAvailable entries as stale. The two build-tag twins' keys now name OpenBestAvailableWith. The reason is unchanged: it is the SDK's library surface for embedders, and no code in the bd binary calls it. gofmt realigned the three neighbouring entries. * chore(schema): renumber removed_restriction to 0071 after #6943's 0070 Migrations are numbered by landing order. #6943 (participation_generation, the versioned-history write fence) lands first and owns main-plane 0070 and ignored/0028, so this PR's removed_restriction migration moves to the next free slot, 0071. The rename is done here, as one maintainer commit, rather than inside the replayed commits, so the history shows exactly what changed relative to the PR as reviewed; the intermediate commits of the rebase carry a duplicate 0070 and are not expected to build. - migrations/0070_add_removed_restriction.{up,down}.sql become 0071_*, with their header comments updated (the SQL itself is unchanged). Neither file exists on main or on #6943, so this is not an edit to a shipped migration. - cli_migrations.go: the CLI-bundle override is keyed to the new file name and renamed cliMigration0071AddRemovedRestriction, and its const now sits after 0070's. - migration_0070_add_removed_restriction_test.go becomes migration_0071_add_removed_restriction_test.go; its tests and messages say 0071, and it now owns the one LatestVersion pin (71). TestLatestVersionIncludesMigration0070 in #6943's participation_generation test is superseded by it and replaced by the usual pointer comment, and 0069's pointer comment now names the 0070 file that superseded it. - schema_test.go hygiene comments, BUILD.bazel embedsrcs/srcs, and the asof_read.go comment that cited the migration number. Checked: go test ./internal/storage/schema/... (with the dolt CLI lane, including TestAllMigrationsSQLAppliesThroughDoltCLIAndRecordsLatestVersion) and scripts/check-migration-hygiene.sh against origin/main and against #6943's tip. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(versions): reconcile #6661's tests and docs with #6943's write fence #6943's write fence (design §16.2b) makes an update-shaped write to a legacy record -- one whose participation_generation is NULL because it was created while versioned history was off -- a skip, not a refusal: the fence returns before the snapshot is canonicalized, so nothing is versioned and the mint's admission gate never runs. Several of #6661's tests seed rows with history off and then expect a later write to them to be versioned or refused, and several comments say every later write to an offending row fails. On a tree that carries both PRs those tests fail and those comments are wrong. This ports, without changing their substance, the fence-integration commits Jim Wordelman wrote for the donnabox integration fork, where both PRs were already folded together: - eff898db80 / 5d2e5a2ac4 (issueops, dolt, embeddeddolt): the mocked mint sequence scripts the fence's participation_generation read; the number fidelity test splits phase 2 into 2a (a legacy row is written, not versioned, not refused, stays NULL) and 2b (a participating row is refused and left untouched); TestRecordVersionInTxSkipsALegacyRowBefore- TheAdmissionGate pins the fence's order against the gate. - e0ad9d1e3c / 1528022dfa (cmd/bd): the switch round trip and the routing/env end-to-end tests build the rows they expect a version for after the setting is on, and assert that the pre-setting seeds gain nothing. - 18b9015bf5 (cmd/bd): the embedded and proxied gate-timeout scan tests assert the whole scan-vs-mint truth table (legacy offenders are named by the scan but not refused by the mint; participating offenders are both). - 5929ebd50c / 8ce872be03 (comments, CHANGELOG, configuration reference): the mint's refusal binds rows that participate in history; the pre-enable scan cannot see participation, so it over-approximates in the safe direction. Left out on purpose: the fork's mintSkipsRow helper and defer-wake sweep change, and its bd doctor "Versionable Issues" check and the docs that point at it; none of those are part of #6661 or #6943. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Jim Wordelman <jim@wordelman.name> * test(versions): adapt #6661's guards to what main changed under it Three test-side adjustments for code that landed on main after #6661's last merge of it; no production code changes. - internal/storage/leg_contract_wiring_test.go: main gained an HTTP storage leg, and TestEveryLegWiresEveryRoleContract requires every leg to name or waive every role contract. The five R7.1 as-of read contracts this PR adds are a storage capability the HTTP client does not serve (internal/httpclient answers AsOf with an explicit unsupported error, and the wire has no instant/address selector or gone/unknown refusal), so they are waived on the http leg with that reason, as the donnabox integration fork does. - cmd/bd/versioned_history_construction_test.go: main split newDoltStoreFromConfig into two thin wrappers over openDoltStoreFromConfig, which is where the activation defer now lives (this rebase's resolution of the activation commit), so the factory guard keys on that body. - cmd/bd/versioned_history_serve_e2e_test.go: main's TestProxiedGatedTestsRunInTheProxiedLane requires a test that skips unless BEADS_TEST_PROXIED_SERVER=1 to be one the proxied lane selects, so TestVersionedHistoryServeActivatesTheProviderFromItsOwnRow becomes TestProxiedServerVersionedHistoryServeActivatesTheProviderFromItsOwnRow, and the 34-shard proxied manifest gains its line (written by gen_proxied_shard_manifest.py 34 --weights=duration --write, incremental; --check passes). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore(bazel): emit go_srcs.py's managed blocks for internal/versionedhistory Main's tools/bazel/go_srcs.py now manages a repo_files filegroup block in every package BUILD file, lists those filegroups in the root BUILD.bazel's aggregates, and lists every go_library in tools/bazel's release_cross_build target. internal/versionedhistory is a package this PR adds, so after the rebase those managed blocks were stale and TestBazelGoSrcsBlocksCurrent (go test ./scripts/...) failed. This is the generator's own output (python3 tools/bazel/go_srcs.py) and nothing else; --check passes afterwards. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(versions): don't publish change_agent in bd versions --json `bd versions <id> --json` prints storage.IssueVersion as-is, so every JSON tag on that struct is part of a public contract. Provenance V2 (gastownhall/beads#7510, as ruled by the maintainer) removes the ad hoc agent field in favour of an actor chain; shipping a "change_agent" key now would make a public contract out of a field that is on its way out. IssueVersion.ChangeAgent is now tagged json:"-". Nothing else changes: the issue_versions.change_agent column (migration 0067) stays, ListVersionsInTx still reads it, change_actor and change_message are still published, and the human listing never showed the agent. No doc or golden named the key. TestVersionsJSONDoesNotPublishChangeAgent pins the absence with a non-empty value, so an omitempty-style regression would still fail, and pins that change_actor and change_message are still there. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(issueops): pin what the unfenced test-support mint does on #6943's new paths #6943's two fixes to the shared mint body -- (a) no issues row means no mint and no error, and (b) a create-shaped call on a new issues-table row flagged no-history stamps participation_generation without minting -- were written for its two kinds. This PR's shared body has a third, mintUnfenced, behind RecordVersionAtInTx (the R7.1 as-of fixtures' controlled-timestamp mint). The rebase resolution decided what (a) and (b) mean for it; this pins that decision: - (a) applies. It is the plane rule (FR-8: the table that holds the row decides its plane), not the fence, and the unfenced kind already honoured the flag-based form of the same rule (IsWisp). Without it, an unfenced mint for an unflagged wisps-table row would insert a version row that no issues row points at. The shared body's issues-table read now runs for all three kinds; only the update kind acts on the value it reads. - (b) does not apply. The unfenced mint never declares participation, so a flagged row returns right after the snapshot, as before: no read, no stamp. - The fence still does not apply: a legacy row is minted, and the closing UPDATE advances current_revision alone. TestRecordVersionAtInTxKeepsThePlaneRuleButNotTheFence scripts each of those three sequences exactly with sqlmock. TestTestSupportMintsStayOutsideTheShapeSplit places RecordVersionAtInTx outside #6943's create / dual-shape / update classification explicitly (it is the seam's exempt twin, not a mutation entry point or mint site): it must be in none of the shape lists, stay in versionExemptions, and reach neither RecordVersionForCreateInTx (it never stamps) nor RecordVersionInTx (whose gate and fence would stop the as-of fixtures minting history-off rows). The row-lock guard's exemption comment for recordVersionAtInTx already names the stamp-only UPDATE: #6943's own wording of it (all three UPDATE issues statements) was carried into that exemption when the as-of read commit was replayed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(storage): say exactly why the as-of read contracts stay waived on http #6943 now runs most of its participation-generation contracts over the served wire (internal/httpclient/served_participation_generation_test.go): their subject is a create or an update, which the client can send, and the fixture reads the reference store's raw columns. This checked whether the five R7.1 as-of read contracts can be wired the same way. They cannot, cheaply or otherwise, without a new wire operation: - their subject is the read itself (AsOfReadFixture.Resolve), and R7.1's read, issueops.AsOfReadInTx, is reached by no publicops role and served by no wire operation; - the wire carries neither selector (an instant or a served version address) nor the gone/unknown refusal the read answers with; - the client's only point-in-time read, DoltStorage.AsOf, is a Dolt commit-ref read, not R7.1, and is on the client's D8 unsupported allowlist. Binding Resolve to the reference store behind the served env would pass, but as a property of that store, which the store legs already pin, never of the client. So the waiver stays; its comment and reason string now say the above instead of the earlier shorthand ("HTTP AsOf is explicitly unsupported"), which conflated the client's commit-ref AsOf with R7.1. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(versions): describe what the write fence does to beads that predate recording With #6943's write fence (design §16.2b) a bead that existed before versioned history was turned on (participation_generation NULL) is legacy: an update-shaped write to it is skipped, so it is never versioned however often it is edited. Several user-facing strings from #6661 still described the behaviour before the fence, and an independent review reproduced each with a built bd (a legacy bead edited twice after enabling still lists no versions; a legacy bead the switch refuses over is written without refusal under BD_VERSIONED_HISTORY_ENABLED=1). Text only; no behaviour changes. - bd versions help: only beads created while recording is on are versioned; a bead that already existed is legacy and editing it records nothing; no backfill. (Was: "a bead edited yesterday shows nothing until it is edited again".) - bd versions empty listing: drops "yet" and says why the list is empty -- a bead created while recording is on always has its create version, so an empty list means the bead predates recording (or was made by a writer that was not recording), or is no-history or a wisp. The line still starts "No versions recorded for <id>", which the switch round-trip test pins. - bd versions with recording off: only beads created after it is turned on are versioned. - bd config set versioned-history.enabled true refusal: Jim's scan stays as conservative as he made it -- it cannot see participation, and a legacy row can still be minted create-shaped if it re-enters the issues plane -- but the text now says a listed issue's writes are refused only if it participates (created while history was on, or entered the issues plane while it was on), and that legacy issues are listed because the check cannot tell. The closing line says the same of a value a non-recording writer adds later. - docs/reference/configuration.md: the section opener says every accepted change to an issue created while history is on is snapshotted, and that a pre-existing issue is legacy; the "participates" parenthetical drops "or written" (a write never stamps participation; only a create-shaped mint does) and names entering the issues plane, matching the refusal text. CHANGELOG already says "if it participates in history" and is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(versions): keep updated_at across update-shaped version mints The update-shaped mint ended with UPDATE issues SET current_revision = ? WHERE id = ?. current_revision always changes there, so the column's ON UPDATE CURRENT_TIMESTAMP clause fired: with versioned history on, every label, dependency or import write moved issues.updated_at to the session's wall clock (local time, read back as UTC). An import with RejectStaleUpserts then stored the wall clock instead of the source's updated_at, and the source's next genuine edit was rejected as stale. The statement now assigns updated_at to itself, the rule #4298, blocked_state.go's mark/unmark templates and the create-shaped mint statements already follow, so history on leaves updated_at exactly where history off does. It is the one statement every production update-shaped mint ends with. Tests: - TestEmbeddedMintLeavesUpdatedAtWhereHistoryOffDoes (embeddeddolt) ages a bead, adds and removes a label and a dependency, and runs two RejectStaleUpserts imports, with history off first as the control. With the fix reverted, history on fails all six arms (updated_at reads the wall clock, and the later source edit is rejected as stale); history off passes either way. - RunParticipationGenerationFlagOffSkipsUpdateOnParticipatingRecord, wired on the dolt, embeddeddolt, uow and http legs: a record created with the flag on and updated with it off mints nothing and keeps its current_revision. Every other flag-off case uses a legacy record, which the fence stops first, so with RecordVersionInTx's gate removed this is the only case that fails, on all four legs. That gate is the single entry for every production update-shaped mint, so the one update arm covers label and close writes too. - The sqlmock pin of the statement (version_history_preenable_scan_test.go) and the journal-completeness exemption comment follow the new SQL. - The createbatchequiv issues_updated_at goldens of small, depadd, import458 and import458-reject-stale are re-recorded. They pinned the wall-clock bump, so each row minted a second time (eq-n2; eq-db1 and eq-dl; eq-b3 and eq-b250) had dropped out of the compared set; CI's embedded and server legs both printed the new digests. Recorded on embedded Dolt, the fix-reverted tree reproduces every committed golden byte for byte, HEAD moves only these four digests, and its rows equal the history-off rows in every scenario. GoldenDirEnv's comment lists it as the goldens' third deliberate change. - The new embedded test has its line in the storage shard manifest (gen_embedded_storage_shard_manifest.py 40 --weights=duration --write), so TestStorageEmbeddedShardManifestGeneratorNotStale stays green. It sits after TestEmbeddedEveryAcceptedLifecycleMutationMintsOneVersion rather than at the end of the file, where #7646 appends its own test, so the two PRs still merge without a conflict in that file. Docs: - CHANGELOG: the feature's two entries under ### Fixed described fixes to a switch no released bd has. One ### Added entry replaces them, covering bd versions, the versioned-history.enabled switch and its per-store semantics, the pre-enable check, the single-writer caveat, migration 0071 and the bd version <arg> refusal. - The bd versions help, its recording-off refusal and empty-listing note, and the opening paragraph of the configuration doc's Versioned Issue History section now state the rule the pre-enable refusal prints: a bead participates if it was created, or entered the issues plane (a wisp promoted or made persistent), while recording was on. bd version: the "did you mean bd versions" refusal now runs after the command's metrics event is created, like the other in-RunE argument refusals, so a mistyped bd version <id> is counted as a version invocation instead of going uncounted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen --------- Co-authored-by: Jim Wordelman <mayor@quad341.uk> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com> Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com>
703 lines
37 KiB
Go
703 lines
37 KiB
Go
package main
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
// The proxied-server capability registry: one table for every command path.
|
|
//
|
|
// Before this file the policy lived in three separate tables — a maintenance
|
|
// refusal map, a history classification map, and a transform row list — each
|
|
// with its own lookup and its own front-door validator. Nothing forced a new
|
|
// command to appear in any of them, so an unclassified command sailed past the
|
|
// gate and died deep in the store factory with an untyped error. The fix is not
|
|
// a fourth table: it is one table plus a test that fails when a command is
|
|
// missing from it (TestProxyCapabilityRegistryCoversCommandTree).
|
|
//
|
|
// WHAT A ROW MEANS. Outcome describes what the PRE-PROVIDER GATE does with the
|
|
// path on a proxied-server workspace, nothing more:
|
|
//
|
|
// ProxyOutcomeRefused the gate refuses with a typed ProxyCapabilityError
|
|
// before any workspace side effect
|
|
// ProxyOutcomeRefusedInRunE the gate lets the path through and the command
|
|
// refuses inside its own RunE with an untyped
|
|
// string; recorded here so the untyped surface is
|
|
// inventoried rather than invisible. Not enforced.
|
|
// ProxyOutcomeHonored the gate lets the path through. It does NOT
|
|
// promise a proxied route exists: a permitted
|
|
// command with no route still fails at the store
|
|
// factory with proxy.store.unrouted.
|
|
//
|
|
// Permitting a path also COSTS something, and the cost is invisible from this
|
|
// table: unless the command is on one of main.go's store-init skip lists, the
|
|
// root pre-run opens the proxied provider before RunE runs — which starts the
|
|
// proxy and its dolt child, creates the database and migrates the schema. For a
|
|
// command that genuinely uses the store that is the point. For a store-free one
|
|
// it is pure side effect, and on a workspace whose topology cannot be resolved
|
|
// it turns a clean typed refusal into a provider-open error. So "this command
|
|
// touches no store" is an argument for permitting it only once the command is
|
|
// also off the store-init path; see the `migrate hooks` row. Nothing here
|
|
// asserts that, and TestProxyCapabilityRegistryCoversCommandTree cannot see it.
|
|
//
|
|
// REASON is the load-bearing field. "design" means refusing is correct and is
|
|
// expected to stay that way — the semantics are undefined or unsafe against a
|
|
// backend that may be shared. "unimplemented" means the refusal is a capability
|
|
// gap with a named slice that closes it, and Tracking says which. Every later
|
|
// slice measures itself by turning "unimplemented" rows into honored ones; the
|
|
// count of remaining "unimplemented" rows is the completion signal for the whole
|
|
// proxied-parity effort. Assign the field row by row, from the command's actual
|
|
// semantics — a bulk assignment would destroy the only information it carries.
|
|
//
|
|
// The reason also renders in the refusal JSON, additive to the frozen
|
|
// {code, error, mutates} contract (see buildJSONCapabilityError). Codes are
|
|
// frozen; messages are informative-only.
|
|
|
|
// ProxyRefusalReason distinguishes a deliberate policy refusal from a
|
|
// not-yet-built one.
|
|
type ProxyRefusalReason string
|
|
|
|
const (
|
|
// ProxyReasonDesign: the command is refused on purpose and is expected to
|
|
// stay refused. Lifting it would need a semantic decision, not plumbing.
|
|
ProxyReasonDesign ProxyRefusalReason = "design"
|
|
// ProxyReasonUnimplemented: the command could work over the proxied
|
|
// provider; nobody has routed it yet. Tracking names the work item.
|
|
ProxyReasonUnimplemented ProxyRefusalReason = "unimplemented"
|
|
)
|
|
|
|
// Tracking values name the plan-of-record work item for an unimplemented
|
|
// refusal. These are the slices of the proxied-parity plan; a row gets a GitHub
|
|
// issue or bead ID instead once one is filed for it.
|
|
// S3 has no entry: it landed, and its rows carry Reason=design rather than a
|
|
// tracking item.
|
|
const (
|
|
trackVersionCtl = "proxied-parity S4 (dolt commit/push/pull/remote)"
|
|
trackSync = "proxied-parity S5 (bd sync)"
|
|
trackDegradation = "proxied-parity S6 (doctor, config show, degradations)"
|
|
trackLongTail = "proxied-parity S7 (long-tail policy pass)"
|
|
// Versioned history (gastownhall/beads#6132) is not a proxied-parity slice:
|
|
// its reads need a storage.VersionLister over the proxied uow provider.
|
|
trackVersionedHistory = "versioned history: VersionLister over the proxied uow provider (gastownhall/beads#6132)"
|
|
)
|
|
|
|
// capabilityRow is one command-path policy row. ArgSet is the sorted set of
|
|
// execution-altering flags that were set (for example "--auto-merge --dry-run"),
|
|
// empty for the bare path; a row keyed on an ArgSet wins over the bare row, which
|
|
// is how `duplicates --auto-merge --dry-run` stays honored while
|
|
// `duplicates --auto-merge` is refused.
|
|
//
|
|
// Topology overrides Rule on the proxied shapes named in it and is empty for
|
|
// every row whose answer is the same everywhere — which is all of them but the
|
|
// backup family. See honoredOn.
|
|
type capabilityRow struct {
|
|
Path string
|
|
ArgSet string
|
|
Rule proxyCapabilityRule
|
|
Topology map[ProxyTopology]proxyCapabilityRule
|
|
History HistoryCapabilityClass
|
|
Note string
|
|
}
|
|
|
|
// ruleFor resolves the row's policy on one proxied topology.
|
|
func (r capabilityRow) ruleFor(topology ProxyTopology) proxyCapabilityRule {
|
|
if rule, ok := r.Topology[topology]; ok {
|
|
return rule
|
|
}
|
|
return r.Rule
|
|
}
|
|
|
|
// honoredOn narrows a refusal to the shapes where it is actually true: the row
|
|
// goes on refusing everywhere except the topologies named here.
|
|
//
|
|
// The direction is deliberate. A row states its refusal first and then lists
|
|
// the exceptions, so a shape nobody thought about — a new transport, or the
|
|
// unknown a corrupt sidecar produces — inherits the refusal rather than the
|
|
// exemption.
|
|
func (r capabilityRow) honoredOn(topologies ...ProxyTopology) capabilityRow {
|
|
r.Topology = make(map[ProxyTopology]proxyCapabilityRule, len(topologies))
|
|
for _, topology := range topologies {
|
|
r.Topology[topology] = proxyCapabilityRule{Outcome: ProxyOutcomeHonored}
|
|
}
|
|
return r
|
|
}
|
|
|
|
// display renders the row's key the way its refusal message names it.
|
|
func (r capabilityRow) display() string {
|
|
if r.ArgSet == "" {
|
|
return r.Path
|
|
}
|
|
return r.Path + " " + r.ArgSet
|
|
}
|
|
|
|
func (r capabilityRow) withHistory(class HistoryCapabilityClass) capabilityRow {
|
|
r.History = class
|
|
return r
|
|
}
|
|
|
|
// asParentGroup marks a row whose path is a command GROUP. Cobra answers a
|
|
// non-runnable parent with its help text before PersistentPreRunE, so the gate
|
|
// never sees it; the row is kept because it is the parent every child row
|
|
// inherits its code from, and because a parent that later gains a Run must not
|
|
// silently become permitted.
|
|
func (r capabilityRow) asParentGroup() capabilityRow {
|
|
r.Note = "parent group: cobra shows help instead of reaching the gate"
|
|
return r
|
|
}
|
|
|
|
func (r capabilityRow) withMessage(message string) capabilityRow {
|
|
r.Rule.Message = message
|
|
return r
|
|
}
|
|
|
|
// refusedPath builds a typed front-door refusal for a bare command path.
|
|
func refusedPath(path, code string, reason ProxyRefusalReason, tracking string) capabilityRow {
|
|
return refusedArgs(path, "", code, reason, tracking)
|
|
}
|
|
|
|
// refusedArgs builds a typed front-door refusal keyed on a flag set.
|
|
func refusedArgs(path, argSet, code string, reason ProxyRefusalReason, tracking string) capabilityRow {
|
|
row := capabilityRow{Path: path, ArgSet: argSet}
|
|
row.Rule = proxyCapabilityRule{
|
|
Outcome: ProxyOutcomeRefused,
|
|
Code: code,
|
|
Message: row.display() + " is not supported in proxied-server mode",
|
|
ExitCode: 1,
|
|
Reason: reason,
|
|
Tracking: tracking,
|
|
}
|
|
return row
|
|
}
|
|
|
|
// refusedInRunE records a command that the gate permits and that then refuses
|
|
// itself with an untyped string from RunE. The row carries no message: the
|
|
// string lives in the command, and duplicating it here would rot. The scan in
|
|
// TestProxyCapabilityRegistryCoversInlineRefusals keeps the two in step.
|
|
//
|
|
// The reason is always "unimplemented" and the owner is always the long-tail
|
|
// slice, because an untyped string inside RunE is not a considered policy
|
|
// statement: a refusal decided on purpose belongs in the gate, typed, where a
|
|
// consumer can read it. Anything here is a family nobody has routed yet.
|
|
func refusedInRunE(path, site string) capabilityRow {
|
|
return capabilityRow{
|
|
Path: path,
|
|
Rule: proxyCapabilityRule{
|
|
Outcome: ProxyOutcomeRefusedInRunE, ExitCode: 1,
|
|
Reason: ProxyReasonUnimplemented, Tracking: trackLongTail,
|
|
},
|
|
Note: "untyped refusal in " + site,
|
|
}
|
|
}
|
|
|
|
// permitted records that the gate lets a path through. See the header: this is
|
|
// a statement about the gate, not a promise that a proxied route exists.
|
|
func permitted(path string) capabilityRow {
|
|
return capabilityRow{Path: path, Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}}
|
|
}
|
|
|
|
// backupRefusal builds one backup-family row: honored where bd owns the Dolt
|
|
// server, refused by design everywhere else. The code stays
|
|
// proxy.backup.unsupported — consumers have been keying on it since 1.3.0 and
|
|
// the refusal it names has not changed, only its reason and its scope — and the
|
|
// message keeps the frozen "<path> is not supported in proxied-server mode"
|
|
// prefix, with the reason appended.
|
|
//
|
|
// The message leads with SERVER-GLOBAL STATE rather than with the filesystem,
|
|
// because only the filesystem half is scheme-specific. `bd backup init` accepts
|
|
// https/aws/gs as well as file:// (resolveDoltBackupURL) and the help text
|
|
// recommends DoltHub; for those a server-side push over the network with the
|
|
// server's own credentials is a coherent thing to ask for, and "the destination
|
|
// is on the server's disk" says nothing about it. What is true of every scheme
|
|
// is that `CALL DOLT_BACKUP('add', …)` registers the remote ON THE SERVER,
|
|
// where it is global to every client of that server — one workspace's backup
|
|
// decision silently becomes everyone's, which is the shape of the auto-backup
|
|
// storm this command's own help text warns about.
|
|
//
|
|
// backupRemoteSchemeTracking is why these rows carry a Tracking item despite
|
|
// being Reason=design: the outcome is settled, the remote-scheme CASE is not.
|
|
func backupRefusal(path string) capabilityRow {
|
|
return refusedPath(path, "proxy.backup.unsupported", ProxyReasonDesign, backupRemoteSchemeTracking).
|
|
withMessage(path + " is not supported in proxied-server mode against a Dolt server bd does not own: " +
|
|
"the backup remote is registered on the server, where it is global to every client, " +
|
|
"and a file:// destination names a filesystem this client cannot see").
|
|
honoredOn(ProxyTopologyManagedLocal)
|
|
}
|
|
|
|
// backupRemoteSchemeTracking records the one part of the backup refusal that is
|
|
// a question rather than a verdict, so refusing the family off-host does not
|
|
// silently foreclose it. A remote-scheme destination (DoltHub, aws://, gs://)
|
|
// needs no filesystem bd can see — the server pushes it over the network from
|
|
// its own environment, which is exactly the credential story S4 has to settle
|
|
// for `dolt push` on these same topologies. Whether a per-client backup remote
|
|
// on a shared server is ever acceptable is the open part; the plumbing is not.
|
|
//
|
|
// Note also that the DoltHub story is already half-built in DIRECT mode:
|
|
// `bd backup init https://…` and `bd backup sync` work, but
|
|
// `bd backup restore https://…` does not, because validateBackupRestoreDir
|
|
// os.Stats its argument and rejects anything that is not an existing directory
|
|
// on every topology. Pre-existing, not something this slice changed.
|
|
const backupRemoteSchemeTracking = "open question, not a verdict: remote-scheme (DoltHub/aws/gs) backup on a server " +
|
|
"bd does not own — revisit with S4, which settles the same server-env credential question for dolt push"
|
|
|
|
// proxyCapabilityRegistry is the whole path-keyed policy. Rows for permitted
|
|
// paths are appended from proxyPermittedPaths by init.
|
|
var proxyCapabilityRegistry = []capabilityRow{
|
|
// --- doctor -------------------------------------------------------------
|
|
// Diagnosis needs no version-control surface; the checks simply have no
|
|
// proxied dual yet. S6 splits them into client-local and store-backed.
|
|
refusedPath("doctor", "proxy.doctor.unsupported", ProxyReasonUnimplemented, trackDegradation),
|
|
|
|
// --- backup / restore ---------------------------------------------------
|
|
// CALL DOLT_BACKUP(...) is pure SQL over a connection proxied mode already
|
|
// owns, so routing this family needed no proxy work at all — see
|
|
// backup_proxied_server.go.
|
|
//
|
|
// What it did need is the ownership policy, which is the first genuinely
|
|
// topology-differentiated rule in this table. A backup remote belongs to the
|
|
// SERVER, not to the client that asked for it: `CALL DOLT_BACKUP('add', …)`
|
|
// registers it in the server's own configuration, where it is global to
|
|
// every client connected to that server. On managed-local "every client" is
|
|
// this workspace, because bd spawned the child itself. Anywhere else one
|
|
// operator's backup decision silently becomes everyone's — the same shape as
|
|
// the auto-backup storm this command's help text already warns about, and
|
|
// the reason team-server is the sharpest case: bts owns the store.
|
|
//
|
|
// A file:// destination adds a second, scheme-specific problem on top: it
|
|
// names a path on the machine running dolt, so off-host the command either
|
|
// fails at the point of use or, far worse, reports success having written
|
|
// the backup somewhere the operator will never look for it.
|
|
//
|
|
// Hence: honored on managed-local, refused by design everywhere else. The
|
|
// OUTCOME is design — server-global state is not something plumbing on this
|
|
// side can make per-client, and a backup story for those shapes belongs to
|
|
// whoever runs the server. The remote-scheme case (DoltHub, aws://, gs://,
|
|
// which resolveDoltBackupURL accepts and backup.go recommends) is the part
|
|
// that is a question rather than a verdict, and it is not silently
|
|
// foreclosed: see backupRemoteSchemeTracking, which every row below carries.
|
|
backupRefusal("backup").asParentGroup(),
|
|
backupRefusal("backup init"),
|
|
backupRefusal("backup sync"),
|
|
backupRefusal("backup remove"),
|
|
backupRefusal("backup status"),
|
|
backupRefusal("backup restore"),
|
|
|
|
// --- version control over a shared history ------------------------------
|
|
// Refused by design: these mutate or traverse a history that several
|
|
// clients share through one connection, and the per-client semantics
|
|
// (whose working set? whose branch head?) are undefined. `diff` is the one
|
|
// plausible 1.4 candidate, via the dolt_diff system tables.
|
|
refusedPath("branch", "proxy.branch.unsupported", ProxyReasonDesign, "").
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("diff", "proxy.diff.unsupported", ProxyReasonDesign, "1.4 candidate: dolt_diff system tables"),
|
|
refusedPath("flatten", "proxy.flatten.unsupported", ProxyReasonDesign, "").
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("conflicts", "proxy.conflicts.unsupported", ProxyReasonDesign, "").
|
|
withHistory(HistoryDirectOnly).
|
|
asParentGroup(),
|
|
refusedPath("conflicts list", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("conflicts show", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("conflicts resolve", "proxy.conflicts.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("vc", "proxy.vc.unsupported", ProxyReasonDesign, "").
|
|
withHistory(HistoryDirectOnly).
|
|
asParentGroup(),
|
|
refusedPath("vc merge", "proxy.vc.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("vc commit", "proxy.vc.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("vc status", "proxy.vc.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("federation", "proxy.federation.unsupported", ProxyReasonDesign, "").
|
|
withHistory(HistoryDirectOnly).
|
|
asParentGroup(),
|
|
refusedPath("federation sync", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("federation status", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("federation add-peer", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("federation remove-peer", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("federation list-peers", "proxy.federation.unsupported", ProxyReasonDesign, ""),
|
|
|
|
// --- multi-repo routing -------------------------------------------------
|
|
// Routing to another workspace bypasses the proxied root entirely, which is
|
|
// the same reason --repo is N/A mode-wide.
|
|
refusedPath("repo", "proxy.repo.unsupported", ProxyReasonDesign, "").
|
|
withHistory(HistoryDirectOnly).
|
|
asParentGroup(),
|
|
refusedPath("repo add", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("repo remove", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("repo list", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("repo sync", "proxy.repo.unsupported", ProxyReasonDesign, ""),
|
|
|
|
// --- dolt version-control verbs -----------------------------------------
|
|
// CALL DOLT_PUSH/DOLT_PULL are SQL procedures and the generic repository
|
|
// that wraps them is already written; these need a use case and a route,
|
|
// not proxy work. `dolt remote remove` is already routed, which is the
|
|
// precedent — and `dolt commit` has now followed it: GH#4995 supplied the
|
|
// use case (it is the flush point dolt.auto-commit=batch/off defers to) and
|
|
// runDoltCommitProxiedServer supplied the route, so its row moved to the
|
|
// routed-history block below.
|
|
refusedPath("dolt push", "proxy.dolt_push.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("dolt pull", "proxy.dolt_pull.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("dolt remote", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
|
withHistory(HistoryDirectOnly).
|
|
asParentGroup(),
|
|
refusedPath("dolt remote add", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("dolt remote list", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("dolt remote reset-data", "proxy.dolt_remote.unsupported", ProxyReasonUnimplemented, trackVersionCtl).
|
|
withHistory(HistoryDirectOnly),
|
|
refusedPath("sync", "proxy.sync.unsupported", ProxyReasonUnimplemented, trackSync).
|
|
withHistory(HistoryDirectOnly),
|
|
|
|
// --- migration and workspace surgery ------------------------------------
|
|
// Storage-format and workspace surgery against a store other clients may be
|
|
// holding open. `migrate schema` is the exception and is already routed:
|
|
// the provider open runs it under the migration gate.
|
|
//
|
|
// S7 MUST RE-EXAMINE THE ROWS BELOW PER TOPOLOGY. "A store other clients may
|
|
// be holding open" describes external and team-server workspaces; it does
|
|
// not describe managed-local, which is 1:1 and bd-owned — bd spawned the
|
|
// dolt child itself. A row cannot yet say "refused, except on managed-local"
|
|
// (S3's backup locality policy is the slice that adds per-topology rules),
|
|
// so the blanket refusal is the only thing this table can express today.
|
|
// These rows keep it because nobody has done the semantic work to narrow
|
|
// them, not because the work has been done and come out this way.
|
|
refusedPath("migrate", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("migrate sync", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
|
// `migrate hooks` is the one row in this block the surgery rationale never
|
|
// described: it plans and applies GIT HOOK FILE migration (migrate_hooks.go
|
|
// -> doctor.PlanHookMigration) on the local filesystem and opens no store at
|
|
// all. It is refused for a structural reason instead — the command is wired
|
|
// into the store-opening path it does not need. It is on none of main.go's
|
|
// store-init skip lists, so permitting it makes the root pre-run open the
|
|
// proxied provider before RunE ever runs. Measured, not assumed: with this
|
|
// row flipped to permitted, `bd migrate hooks --dry-run` on a managed-local
|
|
// workspace started the proxy AND its dolt child (both pidfiles present) to
|
|
// print a hook plan, and on a workspace with an unreadable sidecar it exited
|
|
// 1 with "failed to open uow provider: corrupt proxied-server sidecar ..."
|
|
// where it had cleanly refused before. Trading a typed refusal for a
|
|
// connection error is not a lift. The honest fix is to take the command off
|
|
// the store path first, which is S7's job, not this slice's.
|
|
refusedPath("migrate hooks", "proxy.migrate.unsupported", ProxyReasonUnimplemented,
|
|
trackLongTail+" (specifically: put `migrate hooks` on main.go's store-init skip list, then permit it)"),
|
|
refusedPath("migrate issues", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("migrate-issues", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("migrate-personal", "proxy.migrate.unsupported", ProxyReasonDesign, ""),
|
|
|
|
// --- destructive admin --------------------------------------------------
|
|
// Same topology-blind rationale as the migrate block above, and the same
|
|
// instruction to S7: "destructive against a possibly-shared store" is a
|
|
// claim about external and team-server shapes. On managed-local the store is
|
|
// this workspace's alone, and `bd admin reset` there is no more shared than
|
|
// it is in embedded mode, where it is honored. Re-examine per topology.
|
|
refusedPath("admin cleanup", "proxy.admin.unsupported", ProxyReasonDesign, ""),
|
|
refusedPath("admin reset", "proxy.admin.unsupported", ProxyReasonDesign, ""),
|
|
// --- issue compaction ---------------------------------------------------
|
|
// `bd admin compact` without --dolt is the description-rewriting pass; only
|
|
// the --dolt arm has a proxied route (runCompactDoltProxiedServer). The
|
|
// --dolt arm is decided by flag VALUE, so the gate keeps a value-aware
|
|
// branch for it and lands here when the flag is off.
|
|
// The wording names the real command path. "compact --dolt" reads as the
|
|
// root `bd compact`, a different command with no --dolt flag and its own
|
|
// proxied route; compact.go's RunE fallback carries the same corrected
|
|
// string so the gate and the fallback cannot drift apart.
|
|
refusedPath("admin compact", "proxy.compact.unsupported", ProxyReasonUnimplemented, trackLongTail).
|
|
withMessage("only 'bd admin compact --dolt' is supported in proxied-server mode"),
|
|
// `bd restore` recovers a COMPACTED ISSUE's original text, not a backup —
|
|
// the backup verb is `bd backup restore`. Its snapshot read is ordinary
|
|
// CRUD; only its fallback path (reconstructing from Dolt history when no
|
|
// snapshot was archived) touches version control.
|
|
refusedPath("restore", "proxy.restore.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
|
|
// --- gates, formulas, swarm, merge slots --------------------------------
|
|
// Ordinary CRUD over a store with no version-control surface. They stay
|
|
// refused because nothing downstream has asked for them, which is this
|
|
// codebase's standing rule for lifting a refusal — not because the proxied
|
|
// topology makes them wrong.
|
|
refusedPath("gate discover", "proxy.gate.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("cook", "proxy.formula.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("ship", "proxy.formula.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("swarm create", "proxy.swarm.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("swarm list", "proxy.swarm.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("merge-slot create", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("merge-slot check", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("merge-slot acquire", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("merge-slot release", "proxy.merge_slot.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
|
|
// --- transforms ---------------------------------------------------------
|
|
// ID rewrites walk every reference in the store. They need a routed
|
|
// multi-statement transaction, which the UOW can express; nobody has
|
|
// written it. The arg-set rows are what let the read-only preview of a
|
|
// duplicate merge stay honored while the merge itself is refused.
|
|
refusedPath("rename", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("rename-prefix", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedArgs("rename-prefix", "--dry-run", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedArgs("rename-prefix", "--repair", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedArgs("rename-prefix", "--dry-run --repair", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("duplicate", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedArgs("duplicate", "--of", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedPath("supersede", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedArgs("supersede", "--with", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
refusedArgs("duplicates", "--auto-merge", "proxy.transform.unsupported", ProxyReasonUnimplemented, trackLongTail),
|
|
// The dry run reports what the merge WOULD do without writing anything, so
|
|
// it rides the read path plain `duplicates` already uses.
|
|
{Path: "duplicates", ArgSet: "--auto-merge --dry-run", Rule: proxyCapabilityRule{Outcome: ProxyOutcomeHonored}},
|
|
|
|
// --- routed history -----------------------------------------------------
|
|
// The paths that already have a proxied route, recorded so the class is
|
|
// asserted rather than remembered.
|
|
permitted("history").withHistory(HistoryProxySupported),
|
|
permitted("dolt remote remove").withHistory(HistoryProxySupported),
|
|
// `dolt commit` is routed by runDoltCommitProxiedServer. It is also the
|
|
// flush point dolt.auto-commit=batch/off defers to (GH#4995), so refusing it
|
|
// at the front door would leave those modes with no way to flush.
|
|
permitted("dolt commit").withHistory(HistoryProxySupported),
|
|
|
|
// --- versioned history ----------------------------------------------------
|
|
// `bd versions` is a pure read (issueops.ListVersionsInTx in one read
|
|
// transaction), so nothing about it is unsafe on a shared backend. It is
|
|
// refused only because no proxied route exists yet: it reaches the backend
|
|
// through the optional storage.VersionLister, which the dolt and embedded
|
|
// stores implement and the uow provider does not. Permitting it would open
|
|
// the proxied provider in the root pre-run and then fail untyped at
|
|
// errVersionsUnsupported, so it is refused here, before any side effect.
|
|
refusedPath("versions", "proxy.versions.unsupported", ProxyReasonUnimplemented, trackVersionedHistory),
|
|
|
|
// --- untyped refusals inside RunE ---------------------------------------
|
|
// The gate permits these paths and the command refuses itself with a bare
|
|
// string, so a JSON consumer gets no code and no mutates flag. They are
|
|
// listed to inventory that surface, not to enforce it: converting them to
|
|
// typed refusals changes observable output and belongs to the slice that
|
|
// owns each family. Tracker verbs are ordinary store reads plus a network
|
|
// call; nothing about the proxied topology makes them wrong.
|
|
refusedInRunE("ado status", "ado.go"),
|
|
refusedInRunE("ado projects", "ado.go"),
|
|
refusedInRunE("ado sync", "ado.go"),
|
|
refusedInRunE("github status", "github.go"),
|
|
refusedInRunE("github repos", "github.go"),
|
|
refusedInRunE("github sync", "github.go"),
|
|
refusedInRunE("gitlab status", "gitlab.go"),
|
|
refusedInRunE("gitlab projects", "gitlab.go"),
|
|
refusedInRunE("gitlab sync", "gitlab.go"),
|
|
refusedInRunE("notion status", "notion.go"),
|
|
refusedInRunE("notion init", "notion.go"),
|
|
refusedInRunE("notion connect", "notion.go"),
|
|
refusedInRunE("notion sync", "notion.go"),
|
|
refusedInRunE("create-form", "create_form.go"),
|
|
}
|
|
|
|
// proxyPermittedPaths lists every command path the proxied front door lets
|
|
// through. It exists so that a command added without a policy decision fails
|
|
// TestProxyCapabilityRegistryCoversCommandTree instead of shipping — the whole
|
|
// point of the registry. Being listed here says the GATE permits the path; a
|
|
// permitted command with no proxied route still fails at the store factory with
|
|
// proxy.store.unrouted.
|
|
var proxyPermittedPaths = []string{
|
|
// issue CRUD and queries
|
|
"assign", "batch", "blocked", "children", "close", "comment", "count", "create",
|
|
"defer", "delete", "duplicates", "edit", "export", "find-duplicates", "forget",
|
|
"gc", "graph", "graph check", "heartbeat", "import", "info", "lint", "link",
|
|
"list", "note", "orphans", "priority", "promote", "prune", "purge", "q", "query",
|
|
"ready", "recompute-blocked", "reclaim", "reopen", "search", "set-state", "show",
|
|
"stale", "status", "statuses", "tag", "types", "unclaim", "undefer", "update",
|
|
|
|
// comments, dependencies, labels, key-value
|
|
"comments", "comments add", "comments list",
|
|
"dep", "dep add", "dep cycles", "dep list", "dep relate", "dep remove", "dep tree", "dep unrelate",
|
|
"kv clear", "kv get", "kv list", "kv set",
|
|
"label add", "label list", "label list-all", "label propagate", "label remove", "label rename",
|
|
|
|
// molecules, epics, todos, state
|
|
"epic close-eligible", "epic status",
|
|
"mol bond", "mol burn", "mol current", "mol distill", "mol last-activity", "mol pour",
|
|
"mol progress", "mol ready", "mol seed", "mol show", "mol squash", "mol stale",
|
|
"mol wisp", "mol wisp create", "mol wisp gc", "mol wisp list",
|
|
"state", "state list", "todo", "todo add", "todo done", "todo list",
|
|
|
|
// gates, rules, provenance, audit, upgrade review
|
|
"audit label", "audit record",
|
|
"gate add-waiter", "gate check", "gate create", "gate list", "gate resolve", "gate show",
|
|
"provenance by-ref", "provenance log", "provenance record",
|
|
"rules audit", "rules compact",
|
|
"upgrade ack", "upgrade review", "upgrade status",
|
|
|
|
// workspace lifecycle and configuration
|
|
"bootstrap", "config apply", "config drift", "config get", "config list", "config set",
|
|
"config set-many", "config show", "config unset", "config validate", "connect", "context",
|
|
"init", "init-safety", "onboard", "preflight", "quickstart", "schema", "setup", "where",
|
|
"version", "worktree create", "worktree info", "worktree list", "worktree remove",
|
|
|
|
// storage, history and migration paths that are already routed or store-free
|
|
"compact", "events export", "events prune", "events tail",
|
|
"dolt clean-databases", "dolt killall", "dolt set", "dolt show", "dolt status",
|
|
"dolt start", "dolt stop", "dolt test",
|
|
"migrate from-proxied-server-to-server", "migrate from-proxied-server-to-shared-server",
|
|
"migrate from-server-to-proxied-server", "migrate from-shared-server-to-proxied-server",
|
|
"migrate legacy-sqlite", "migrate schema",
|
|
|
|
// formulas (parser-only), agent memory, swarm reads
|
|
"formula convert", "formula list", "formula schema", "formula show",
|
|
"mail", "memories", "ping", "prime", "recall", "remember",
|
|
"swarm status", "swarm validate",
|
|
|
|
// human-in-the-loop queue
|
|
"human", "human dismiss", "human list", "human respond", "human stats",
|
|
|
|
// trackers: the verbs with no proxied refusal of any kind
|
|
"ado pull", "ado push", "github pull", "github push", "gitlab pull", "gitlab push",
|
|
"jira pull", "jira push", "jira status", "jira sync",
|
|
"linear pull", "linear push", "linear status", "linear sync", "linear teams",
|
|
"notion pull", "notion push",
|
|
|
|
// hooks, metrics, serving and internal entry points
|
|
"hooks install", "hooks list", "hooks run", "hooks uninstall",
|
|
"metrics", "metrics example", "metrics off", "metrics on",
|
|
"serve", "sql",
|
|
"codex-hook", "cursor-hook", "db-proxy-child", "send-metrics",
|
|
}
|
|
|
|
func init() {
|
|
for _, path := range proxyPermittedPaths {
|
|
proxyCapabilityRegistry = append(proxyCapabilityRegistry, permitted(path))
|
|
}
|
|
proxyCapabilityIndex = make(map[string]capabilityRow, len(proxyCapabilityRegistry))
|
|
for _, row := range proxyCapabilityRegistry {
|
|
proxyCapabilityIndex[capabilityKey(row.Path, row.ArgSet)] = row
|
|
}
|
|
}
|
|
|
|
// proxyCapabilityIndex is proxyCapabilityRegistry keyed for lookup. Duplicate
|
|
// keys are rejected by TestProxyCapabilityRegistryHasNoDuplicateRows rather
|
|
// than by a panic here: a typo must fail the build, not every bd invocation.
|
|
var proxyCapabilityIndex map[string]capabilityRow
|
|
|
|
func capabilityKey(path, argSet string) string { return path + "\x00" + argSet }
|
|
|
|
// LookupCapabilityRow returns the row for an exact path/arg-set key.
|
|
func LookupCapabilityRow(path, argSet string) (capabilityRow, bool) {
|
|
row, ok := proxyCapabilityIndex[capabilityKey(path, argSet)]
|
|
return row, ok
|
|
}
|
|
|
|
// capabilityRowFor resolves a command to its row, preferring the row keyed on
|
|
// the flags the invocation actually set over the bare path.
|
|
//
|
|
// The fallback to the bare row is what lets one table serve both halves of the
|
|
// old policy: a path row refuses whatever flags were passed unless a more
|
|
// specific row says otherwise, so `backup sync --dry-run` is still refused by
|
|
// the `backup sync` row. The predecessor of the arg-set half matched exactly or
|
|
// not at all, which meant an unlisted flag combination on a refused path
|
|
// slipped through; no such combination exists among the commands that carry
|
|
// these flags, so nothing changes today, and the fallback is why none can
|
|
// appear later.
|
|
func capabilityRowFor(cmd *cobra.Command) (capabilityRow, bool) {
|
|
path := commandRegistryPath(cmd)
|
|
if argSet := commandPolicyArgSet(cmd); argSet != "" {
|
|
if row, ok := LookupCapabilityRow(path, argSet); ok {
|
|
return row, true
|
|
}
|
|
}
|
|
return LookupCapabilityRow(path, "")
|
|
}
|
|
|
|
// commandRegistryPath is the registry key for a command: its full path with the
|
|
// root name removed, for example "dolt remote add", "ready" for `bd ready`, and
|
|
// "" for the bare root.
|
|
//
|
|
// Both halves of the front door key on this rather than on cobra's Name(),
|
|
// which is only the leaf: two commands in different subtrees can share one, and
|
|
// `bd ready` and `bd mol ready --gated` do. A Name()-keyed rule silently applies
|
|
// to both, so a refusal written for one command lands on an unrelated command
|
|
// that no policy row authorizes.
|
|
func commandRegistryPath(cmd *cobra.Command) string {
|
|
if cmd == nil {
|
|
return ""
|
|
}
|
|
return strings.TrimSpace(strings.TrimPrefix(cmd.CommandPath(), cmd.Root().Name()))
|
|
}
|
|
|
|
// proxyPolicyArgFlags are the flags that take part in a capability key. Only
|
|
// flags that alter a command's execution belong here: output, tracing and other
|
|
// inherited root flags must never bypass a refusal by changing the key.
|
|
var proxyPolicyArgFlags = map[string]bool{
|
|
"auto-merge": true, "dry-run": true, "repair": true, "of": true, "with": true,
|
|
}
|
|
|
|
// commandPolicyArgSet renders the set flags that take part in the key, sorted so
|
|
// the key does not depend on the order the user typed them.
|
|
func commandPolicyArgSet(cmd *cobra.Command) string {
|
|
var args []string
|
|
cmd.Flags().Visit(func(f *pflag.Flag) {
|
|
if proxyPolicyArgFlags[f.Name] {
|
|
args = append(args, "--"+f.Name)
|
|
}
|
|
})
|
|
sort.Strings(args)
|
|
return strings.Join(args, " ")
|
|
}
|
|
|
|
// validateProxyRegistryBeforeProvider is the path-keyed half of the proxied
|
|
// front door: it rejects direct-only commands before migrations, auto-start or
|
|
// provider construction, so a refusal leaves the workspace untouched. The
|
|
// flag-keyed half is validateProxyCapabilitiesBeforeProvider.
|
|
//
|
|
// topology is the workspace's proxied shape (resolveProxiedTopology). It is a
|
|
// parameter rather than a lookup inside so the gate can be exercised for every
|
|
// shape without a workspace on disk.
|
|
func validateProxyRegistryBeforeProvider(cmd *cobra.Command, topology ProxyTopology) error {
|
|
if cmd == nil {
|
|
return nil
|
|
}
|
|
// `compact` is the one rule that a flag VALUE decides rather than a flag's
|
|
// presence, so it cannot be expressed as an arg-set row. `bd compact` and
|
|
// `bd rules compact` have no --dolt flag at all and are never refused here;
|
|
// `bd admin compact --dolt` has a proxied route and falls through to it.
|
|
if cmd.Name() == "compact" {
|
|
if cmd.Flags().Lookup("dolt") == nil {
|
|
return nil
|
|
}
|
|
if dolt, _ := cmd.Flags().GetBool("dolt"); dolt {
|
|
return nil
|
|
}
|
|
}
|
|
row, ok := capabilityRowFor(cmd)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
rule := row.ruleFor(topology)
|
|
if rule.Outcome != ProxyOutcomeRefused {
|
|
return nil
|
|
}
|
|
return HandleProxyCapabilityError(proxyCapabilityErrorFor(rule))
|
|
}
|
|
|
|
func proxyCapabilityErrorFor(rule proxyCapabilityRule) *ProxyCapabilityError {
|
|
return &ProxyCapabilityError{
|
|
Code: rule.Code,
|
|
Message: rule.Message,
|
|
ExitCode: rule.ExitCode,
|
|
Mutates: rule.Mutates,
|
|
Reason: rule.Reason,
|
|
}
|
|
}
|
|
|
|
// HistoryCapabilityClass classifies history/version-control commands on the
|
|
// proxied topology without coupling them to a particular backend engine.
|
|
type HistoryCapabilityClass string
|
|
|
|
const (
|
|
HistoryProxySupported HistoryCapabilityClass = "proxy-supported"
|
|
HistoryDirectOnly HistoryCapabilityClass = "direct-only"
|
|
)
|
|
|
|
// LookupHistoryCapability classifies an exact command path. Paths with no
|
|
// history classification are intentionally absent so callers cannot
|
|
// accidentally advertise support.
|
|
func LookupHistoryCapability(commandPath string) (HistoryCapabilityClass, bool) {
|
|
row, ok := LookupCapabilityRow(commandPath, "")
|
|
if !ok || row.History == "" {
|
|
return "", false
|
|
}
|
|
return row.History, true
|
|
}
|