rollbridge 0.1.77 → 0.1.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/daemon.js +22 -9
- package/test/owner-replacement.test.js +36 -1
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -38,7 +38,7 @@ const STATE_PERSIST_INTERVAL_MS = 5000
|
|
|
38
38
|
* @typedef {{configDigest: string, format: number, guardian: {pid?: number, socketPath: string, token: string}, reconnectGraceMs: number}} OwnerRecoveryMetadata
|
|
39
39
|
* @typedef {DaemonStatus & {recovery: OwnerRecoveryMetadata, serviceReleaseIds?: Record<string, string>, singletonReleaseIds?: Record<string, string>}} OwnerRecoverySnapshot
|
|
40
40
|
* @typedef {{authority: JsonValue, config: import("./config.js").RollbridgeConfig, listenerConnectionSources?: Record<string, Record<string, {http: number, websocket: number}>>, listenerSourceId?: string, recovery?: {command: JsonValue, reconnectGraceMs: number, startupTimeoutMs: number}, releaseConfigs?: Record<string, import("./config.js").RollbridgeConfig>, retiredListenerHandoff?: number, serviceReleaseIds?: Record<string, string>, singletonReleaseIds?: Record<string, string>, snapshot: OwnerRecoverySnapshot}} PrivateOwnerState
|
|
41
|
-
* @typedef {{boundaryCrossed: boolean, guardianVersion?: string, incumbentControl?: Awaited<ReturnType<typeof openControlSession>>, incumbentStartTime: string, legacyGuardian: GuardianClient, legacyInventory: {key: string, provenance: string}[], legacyPrepared?: {ownerState: JsonValue, replacementId: string}, legacySnapshot: OwnerRecoverySnapshot, prepared: {ownerState: JsonValue, replacementId: string}, protocol: GuardianHandoffProtocol, recoverySnapshot: OwnerRecoverySnapshot}} LegacyOwnerBridge
|
|
41
|
+
* @typedef {{boundaryCrossed: boolean, guardianVersion?: string, incumbentControl?: Awaited<ReturnType<typeof openControlSession>>, incumbentStartTime: string, legacyGuardian: GuardianClient, legacyInventory: {key: string, provenance: string, status: import("./managed-process.js").ManagedProcessStatus}[], legacyPrepared?: {ownerState: JsonValue, replacementId: string}, legacySnapshot: OwnerRecoverySnapshot, prepared: {ownerState: JsonValue, replacementId: string}, protocol: GuardianHandoffProtocol, recoverySnapshot: OwnerRecoverySnapshot}} LegacyOwnerBridge
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
export default class RollbridgeDaemon {
|
|
@@ -1134,7 +1134,7 @@ export default class RollbridgeDaemon {
|
|
|
1134
1134
|
}
|
|
1135
1135
|
const currentInventory = normalizeLegacyGuardianInventory(await bridge.legacyGuardian.inventory())
|
|
1136
1136
|
|
|
1137
|
-
if (!isDeepStrictEqual(currentInventory, bridge.legacyInventory)) {
|
|
1137
|
+
if (!isDeepStrictEqual(legacyInventoryIdentity(currentInventory), legacyInventoryIdentity(bridge.legacyInventory))) {
|
|
1138
1138
|
throw new Error("Legacy guardian process inventory changed before the disruptive boundary")
|
|
1139
1139
|
}
|
|
1140
1140
|
const candidateOwnerState = {
|
|
@@ -1146,7 +1146,11 @@ export default class RollbridgeDaemon {
|
|
|
1146
1146
|
snapshot: this.status()
|
|
1147
1147
|
}
|
|
1148
1148
|
|
|
1149
|
-
|
|
1149
|
+
// A legacy guardian keeps stopped registrations until its owner reconciles them. The
|
|
1150
|
+
// replacement intentionally does not reconstruct stopped releases; prove every live
|
|
1151
|
+
// registration exactly, while allowing only this known, non-running residue through the
|
|
1152
|
+
// disruptive boundary.
|
|
1153
|
+
assertLegacyGuardianInventoryMembership(currentInventory, candidateOwnerState, {allowStopped: true})
|
|
1150
1154
|
let legacyCommitted
|
|
1151
1155
|
|
|
1152
1156
|
if (bridge.legacyPrepared) {
|
|
@@ -3540,15 +3544,15 @@ function reconstructableOwnerSnapshotProcessKeys(snapshot, singletonReleaseIds =
|
|
|
3540
3544
|
|
|
3541
3545
|
/**
|
|
3542
3546
|
* Canonicalizes the authenticated guardian inventory without relying on map insertion order.
|
|
3543
|
-
* @param {{key: string, provenance: string}[]} inventory - Guardian inventory response.
|
|
3544
|
-
* @returns {{key: string, provenance: string}[]} Exact key/provenance fence.
|
|
3547
|
+
* @param {{key: string, provenance: string, status: import("./managed-process.js").ManagedProcessStatus}[]} inventory - Guardian inventory response.
|
|
3548
|
+
* @returns {{key: string, provenance: string, status: import("./managed-process.js").ManagedProcessStatus}[]} Exact key/provenance/status fence.
|
|
3545
3549
|
*/
|
|
3546
3550
|
function normalizeLegacyGuardianInventory(inventory) {
|
|
3547
3551
|
const normalized = inventory.map((entry) => {
|
|
3548
3552
|
if (!entry || typeof entry.key !== "string" || !entry.key || typeof entry.provenance !== "string" || !entry.provenance) {
|
|
3549
3553
|
throw new Error("Legacy guardian returned an invalid process inventory")
|
|
3550
3554
|
}
|
|
3551
|
-
return {key: entry.key, provenance: entry.provenance}
|
|
3555
|
+
return {key: entry.key, provenance: entry.provenance, status: entry.status}
|
|
3552
3556
|
}).sort((left, right) => left.key.localeCompare(right.key))
|
|
3553
3557
|
|
|
3554
3558
|
if (new Set(normalized.map(({key}) => key)).size !== normalized.length) {
|
|
@@ -3557,14 +3561,23 @@ function normalizeLegacyGuardianInventory(inventory) {
|
|
|
3557
3561
|
return normalized
|
|
3558
3562
|
}
|
|
3559
3563
|
|
|
3564
|
+
/**
|
|
3565
|
+
* @param {{key: string, provenance: string, status: import("./managed-process.js").ManagedProcessStatus}[]} inventory - Canonical guardian inventory.
|
|
3566
|
+
* @returns {{key: string, provenance: string}[]} Stable guardian inventory identity.
|
|
3567
|
+
*/
|
|
3568
|
+
function legacyInventoryIdentity(inventory) {
|
|
3569
|
+
return inventory.map(({key, provenance}) => ({key, provenance}))
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3560
3572
|
/**
|
|
3561
3573
|
* Requires every and only the process registrations serialized by committed private owner state.
|
|
3562
|
-
* @param {{key: string, provenance: string}[]} inventory - Canonical guardian inventory.
|
|
3574
|
+
* @param {{key: string, provenance: string, status: import("./managed-process.js").ManagedProcessStatus}[]} inventory - Canonical guardian inventory.
|
|
3563
3575
|
* @param {{snapshot: DaemonStatus, singletonReleaseIds?: Record<string, string>}} ownerState - Authenticated owner process snapshot.
|
|
3576
|
+
* @param {{allowStopped?: boolean}} [options] - Whether known stopped registrations may remain during legacy handoff.
|
|
3564
3577
|
*/
|
|
3565
|
-
function assertLegacyGuardianInventoryMembership(inventory, ownerState) {
|
|
3578
|
+
export function assertLegacyGuardianInventoryMembership(inventory, ownerState, {allowStopped = false} = {}) {
|
|
3566
3579
|
if (!ownerState?.snapshot) throw new Error("Legacy guardian owner state is missing its committed process snapshot")
|
|
3567
|
-
const inventoryKeys = inventory.map(({key}) => key)
|
|
3580
|
+
const inventoryKeys = inventory.filter(({status}) => !allowStopped || status.state !== "stopped").map(({key}) => key)
|
|
3568
3581
|
const snapshotKeys = ownerSnapshotProcessKeys(ownerState.snapshot, ownerState.singletonReleaseIds).sort((left, right) => left.localeCompare(right))
|
|
3569
3582
|
|
|
3570
3583
|
if (!isDeepStrictEqual(inventoryKeys, snapshotKeys)) {
|
|
@@ -10,13 +10,48 @@ import {describe, expect, test} from "@velocious/testing"
|
|
|
10
10
|
import {fileURLToPath} from "node:url"
|
|
11
11
|
import {normalizeConfig} from "../src/config.js"
|
|
12
12
|
import {openControlSession, sendControlCommand} from "../src/control-client.js"
|
|
13
|
-
import RollbridgeDaemon, {isLegacyGuardianPrepareDiagnostic, ownerConfigDigest, ownerReplacementTransitionAuthorityMatches} from "../src/daemon.js"
|
|
13
|
+
import RollbridgeDaemon, {assertLegacyGuardianInventoryMembership, isLegacyGuardianPrepareDiagnostic, ownerConfigDigest, ownerReplacementTransitionAuthorityMatches} from "../src/daemon.js"
|
|
14
14
|
import GuardianClient from "../src/guardian-client.js"
|
|
15
15
|
import {findAvailablePort} from "../src/port-allocator.js"
|
|
16
16
|
import {isProcessRunning, waitForProcessExit} from "./support/process.js"
|
|
17
17
|
|
|
18
18
|
describe("owner-replacement", () => {
|
|
19
19
|
|
|
20
|
+
test("legacy owner proof ignores only stopped registrations omitted by replacement reconstruction", () => {
|
|
21
|
+
const ownerState = /** @type {Parameters<typeof assertLegacyGuardianInventoryMembership>[1]} */ (/** @type {import("../src/json.js").JsonValue} */ ({
|
|
22
|
+
snapshot: {
|
|
23
|
+
activeReleaseId: "active",
|
|
24
|
+
releases: [
|
|
25
|
+
{releaseId: "stopped", processes: [{id: "web"}], state: "stopped"},
|
|
26
|
+
{releaseId: "active", processes: [{id: "web"}], state: "active"}
|
|
27
|
+
],
|
|
28
|
+
services: [],
|
|
29
|
+
singletons: []
|
|
30
|
+
}
|
|
31
|
+
}))
|
|
32
|
+
const inventory = /** @type {Parameters<typeof assertLegacyGuardianInventoryMembership>[0]} */ (/** @type {import("../src/json.js").JsonValue} */ ([
|
|
33
|
+
{key: "release:active:web", provenance: "active-provenance", status: {state: "running"}},
|
|
34
|
+
{key: "release:stopped:web", provenance: "stopped-provenance", status: {state: "stopped"}}
|
|
35
|
+
]))
|
|
36
|
+
const unexpectedStopped = /** @type {Parameters<typeof assertLegacyGuardianInventoryMembership>[0]} */ (/** @type {import("../src/json.js").JsonValue} */ ([
|
|
37
|
+
{key: "release:unexpected:web", provenance: "unexpected-provenance", status: {state: "stopped"}},
|
|
38
|
+
inventory[0]
|
|
39
|
+
]))
|
|
40
|
+
const unexpectedLive = /** @type {Parameters<typeof assertLegacyGuardianInventoryMembership>[0]} */ (/** @type {import("../src/json.js").JsonValue} */ ([
|
|
41
|
+
{key: "release:unexpected:web", provenance: "unexpected-provenance", status: {state: "running"}},
|
|
42
|
+
inventory[1]
|
|
43
|
+
]))
|
|
44
|
+
|
|
45
|
+
expect(() => assertLegacyGuardianInventoryMembership(inventory, ownerState)).not.toThrow()
|
|
46
|
+
expect(() => assertLegacyGuardianInventoryMembership(unexpectedStopped, ownerState, {allowStopped: true})).toThrow(/inventory does not match/)
|
|
47
|
+
expect(() => assertLegacyGuardianInventoryMembership(inventory, {
|
|
48
|
+
snapshot: {...ownerState.snapshot, releases: [ownerState.snapshot.releases[1]]}
|
|
49
|
+
}, {allowStopped: true})).not.toThrow()
|
|
50
|
+
expect(() => assertLegacyGuardianInventoryMembership(unexpectedLive, {
|
|
51
|
+
snapshot: {...ownerState.snapshot, releases: [ownerState.snapshot.releases[1]]}
|
|
52
|
+
}, {allowStopped: true})).toThrow(/inventory does not match/)
|
|
53
|
+
})
|
|
54
|
+
|
|
20
55
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
21
56
|
const binPath = path.join(repoRoot, "bin", "rollbridge")
|
|
22
57
|
const dummyAppPath = path.join(repoRoot, "test", "fixtures", "dummy-app.js")
|