Repository navigation
refactor(registrar): shared snapshot-version parser; give the in-flight-publication watch test teeth - #1274
Merged
Conversation
…#1272) The agent's versionContentHash (registry/internal/registrar) duplicated the registrar server's parser (registrar/internal/server/snapshot.go), and #1266's emptyResend cache-clear depends on the two agreeing on "renamed". Move the version format -- its documentation, Format, ContentHash and a Compare (Same / Renamed / Different) -- into common/snapshotversion, a stdlib-only leaf package, and use it on both sides: the server's resumeLocked and the agent's emptyResend now classify with the same function. Table tests cover every form (<rev>.<hash>, <rev>+<hash>, hash:<hash>, legacy counter, empty, garbage) and the mixed-form comparisons both sides make. Pure refactor: s.version is always rendered from s.contentHash, so comparing a token to the version's hash is comparing it to the content hash. Existing tests pass unchanged (publish_order_test only follows the helper's new name). Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
#1271) Since publications are serialized (#1266), batch C can no longer overtake an in-flight batch B, so TestWatchEndpoints_PreSnapshotBatchCannotRegressTheToken passed even with SubscribeWith no longer excluding publications: B's duplicate broadcast now carries the snapshot's own version, so the token and cache assertions cannot see it. Assert the rule SubscribeWith actually enforces: each batch is in the watch's snapshot or on its channel, never both -- B's and C's endpoints reach the stream exactly once. With publishMu dropped from SubscribeWith (local mutation, not committed) the test fails 10/10 on B delivered twice; the original assertions pass under the same mutation. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1272
Closes #1271
Test and refactor only. No behaviour change, no proto change. Based on
mainafter #1266/#1267.#1272: one parser for agent and server
New leaf package
common/snapshotversion(stdlib only:strconv,strings). It now holds the version format documentation (moved out ofregistrar/internal/server/snapshot.go), plus:Format(revision, dirty, hash): was the server'sformatVersion.ContentHash(version): wasversionContentHash, which existed on both sides.Compare(token, current) Relation: returnsSame(identical),Renamed(same embedded hash) orDifferent. Empty tokens get no special meaning here; each caller keeps its own "no token means resend" check.HashLen(wascontentHashLen) and the separator constants.Both sides now classify with the same function:
Snapshot.resumeLocked:Compare(token, s.version). This is equivalent to the oldhash(token) == s.contentHashcheck becauses.versionis always rendered froms.contentHash(NewSnapshot/refreshLocked).emptyResend:Compare(lastVersion, marker.Version) == Different. This is the oldversion equal → false; else !ok || !markerOK || hashes differlogic.Table tests cover every form:
<rev>.<hash>,<rev>+<hash>,hash:<hash>, a legacy counter, empty, empty hash parts, and garbage. The garbage cases pin today's "everything after the first separator" behaviour, so a stricter parser has to be a deliberate change made on both sides. Other tests:Renamed); different hash, legacy counter, empty (allDifferent); identical (Same).Existing tests of both packages pass unchanged. The only edit is in
publish_order_test.go, which follows the helper to its new name.Dependency footprint:
bazel query --noimplicit_deps 'kind(go_library, deps(//common/snapshotversion))'returns only the package itself. Its reverse deps are//registrar/internal/serverand//registry/internal/registrar. The agent already links the second throughregistry/registrarclient.somepathfrom every guarded binary (agent-ready, identity-ready, mesh-dns, mesh-dns-ready, proxy-ready, proxy-supervisor, uds-csi, cni, plus prober and controller) to the package is empty.#1271:
TestWatchEndpoints_PreSnapshotBatchCannotRegressTheTokenhas teeth againProblem. Since publications are serialized, batch C cannot overtake an in-flight batch B. If
SubscribeWithstopped excluding publications, the watch would still receive B twice: once in its snapshot and once on its channel after the marker. But that duplicate now carries the snapshot's own version, so the old token and cache assertions could not see it.Fix. The test keeps its scenario: B is applied but not yet broadcast, C is queued behind it, and a watch starts in between. It keeps the token and cache assertions and adds the rule
SubscribeWithenforces: each batch is in the watch's snapshot or on its channel, never both. B's and C's endpoints must reach the stream exactly once (new helper:endpointDeliveries). The doc comment now says what the test proves and why the exactly-once assertion is the one that matters.Mutation evidence. I removed
b.publishMu.Lock()/Unlock()fromSubscribeWithlocally (not committed) and ran--runs_per_test=10:TestWatchEndpoints_*test passed under the mutation (this confirms test(registrar): TestWatchEndpoints_PreSnapshotBatchCannotRegressTheToken no longer guards anything after publish serialization #1271);the in-flight batch must be in the watch's snapshot or on its channel, never both(expected 1, actual 2).I re-ran this on the post-merge
mainbasis with the same result.TestWatchEndpoints_ChangeDuringInitialExchangeIsDeliveredcovers the lost-batch rule but not the duplicate, so this test is not redundant.Proof
bazel testpasses for//common/snapshotversion:all,//registrar/internal/server:all,//registry/internal/registrar:all,//agent/internal/cmd:all,//registrar/internal/cmd:all,//registrar/internal/services:all, and all 8deps_testguards.bazel test --config=race --runs_per_test=5passes forsnapshotversion_test,server_testandregistrar_test.make gazelleleaves the tree clean, andmake format-checkpasses.bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...passes.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr