Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import {
MigrationCoordinator,
type MigrationDestination,
type SnapshotSerializer,
StateTransferProtocol,
} from "../../src/index.js";
describe("migration end-to-end", () => {
it("packs, transmits, and drains", async () => {
const received: Uint8Array[] = [];
const destination: MigrationDestination = {
accept: async () => true,
receive: async (b) => {
received.push(b);
},
};
const serializer: SnapshotSerializer = {
serialize: (s) => new TextEncoder().encode(JSON.stringify(s)),
deserialize: (b) => JSON.parse(new TextDecoder().decode(b)),
};
const coordinator = new MigrationCoordinator({
localPeerId: "alice",
localMeshId: "mesh-A",
stateTransfer: new StateTransferProtocol({ serializer }),
destination,
forwarder: async () => {},
captureSnapshot: async () => ({
peerId: "alice",
schemaVersion: 1,
state: { sessionId: "x", counter: 42 },
capturedAt: 0,
}),
});
const result = await coordinator.initiateMigration({
peerId: "alice",
fromMeshId: "mesh-A",
toMeshId: "mesh-B",
reason: "test",
priority: "graceful",
});
expect(result.success).toBe(true);
expect(received).toHaveLength(1);
const decoded = await new StateTransferProtocol({
serializer,
}).unpack(received[0]!);
expect((decoded.state as { counter: number }).counter).toBe(42);
});
});