wip(k1): checkpoint connection recovery rewrite
Capture the current unreleased K1 connection, recovery, lifecycle, viewer, and test work as a single known-bad baseline for subsequent fixes.
This commit is contained in:
@@ -42,6 +42,113 @@ function snapshot(revision, generation, phase = "streaming", sessionId = "device
|
||||
};
|
||||
}
|
||||
|
||||
function stampedSnapshot({
|
||||
runtimeStartedAt = "2026-08-06T10:00:00Z",
|
||||
runtimeStartedMonotonicNs = "1000000",
|
||||
runtimeId = "runtime-a",
|
||||
snapshotRevision = 1,
|
||||
cameraRevision = snapshotRevision,
|
||||
generation = 1,
|
||||
} = {}) {
|
||||
return {
|
||||
...snapshot(cameraRevision, generation),
|
||||
snapshot_runtime_started_at_utc: runtimeStartedAt,
|
||||
snapshot_runtime_started_monotonic_ns: runtimeStartedMonotonicNs,
|
||||
snapshot_runtime_id: runtimeId,
|
||||
snapshot_revision: snapshotRevision,
|
||||
};
|
||||
}
|
||||
|
||||
test("uses the process snapshot revision before camera-local counters", () => {
|
||||
const current = stampedSnapshot({ snapshotRevision: 8, cameraRevision: 2 });
|
||||
const stale = stampedSnapshot({ snapshotRevision: 7, cameraRevision: 99 });
|
||||
const newer = stampedSnapshot({ snapshotRevision: 9, cameraRevision: 1 });
|
||||
|
||||
assert.equal(selectMonotonicXgridsState(current, stale), current);
|
||||
assert.equal(selectMonotonicXgridsState(current, newer), newer);
|
||||
});
|
||||
|
||||
test("accepts a newer runtime and rejects a delayed snapshot from the old runtime", () => {
|
||||
const oldRuntime = stampedSnapshot({
|
||||
runtimeStartedAt: "2026-08-06T10:00:00Z",
|
||||
runtimeStartedMonotonicNs: "1000000",
|
||||
runtimeId: "runtime-old",
|
||||
snapshotRevision: 300,
|
||||
});
|
||||
const newRuntime = stampedSnapshot({
|
||||
runtimeStartedAt: "2026-08-06T10:05:00Z",
|
||||
runtimeStartedMonotonicNs: "2000000",
|
||||
runtimeId: "runtime-new",
|
||||
snapshotRevision: 1,
|
||||
});
|
||||
const delayedOldRuntime = stampedSnapshot({
|
||||
runtimeStartedAt: "2026-08-06T10:00:00Z",
|
||||
runtimeStartedMonotonicNs: "1000000",
|
||||
runtimeId: "runtime-old",
|
||||
snapshotRevision: 301,
|
||||
});
|
||||
|
||||
assert.equal(selectMonotonicXgridsState(oldRuntime, newRuntime), newRuntime);
|
||||
assert.equal(
|
||||
selectMonotonicXgridsState(newRuntime, delayedOldRuntime),
|
||||
newRuntime,
|
||||
);
|
||||
});
|
||||
|
||||
test("orders restarts by monotonic time even when UTC moves backwards", () => {
|
||||
const oldRuntime = stampedSnapshot({
|
||||
runtimeStartedAt: "2026-08-06T10:05:00Z",
|
||||
runtimeStartedMonotonicNs: "2000000",
|
||||
runtimeId: "runtime-old",
|
||||
snapshotRevision: 900,
|
||||
});
|
||||
const newRuntime = stampedSnapshot({
|
||||
runtimeStartedAt: "2026-08-06T09:55:00Z",
|
||||
runtimeStartedMonotonicNs: "3000000",
|
||||
runtimeId: "runtime-new",
|
||||
snapshotRevision: 1,
|
||||
});
|
||||
|
||||
assert.equal(selectMonotonicXgridsState(oldRuntime, newRuntime), newRuntime);
|
||||
assert.equal(selectMonotonicXgridsState(newRuntime, oldRuntime), newRuntime);
|
||||
});
|
||||
|
||||
test("orders two runtimes sharing the same UTC millisecond", () => {
|
||||
const first = stampedSnapshot({
|
||||
runtimeStartedMonotonicNs: "4000000",
|
||||
runtimeId: "runtime-first",
|
||||
});
|
||||
const second = stampedSnapshot({
|
||||
runtimeStartedMonotonicNs: "4000001",
|
||||
runtimeId: "runtime-second",
|
||||
});
|
||||
|
||||
assert.equal(selectMonotonicXgridsState(first, second), second);
|
||||
});
|
||||
|
||||
test("a malformed monotonic stamp cannot replace valid runtime authority", () => {
|
||||
const current = stampedSnapshot({
|
||||
runtimeStartedMonotonicNs: "5000000",
|
||||
runtimeId: "runtime-current",
|
||||
});
|
||||
const malformed = stampedSnapshot({
|
||||
runtimeStartedAt: "2026-08-06T11:00:00Z",
|
||||
runtimeStartedMonotonicNs: "not-a-number",
|
||||
runtimeId: "runtime-malformed",
|
||||
snapshotRevision: 9999,
|
||||
});
|
||||
|
||||
assert.equal(selectMonotonicXgridsState(current, malformed), current);
|
||||
});
|
||||
|
||||
test("does not let an unstamped legacy response replace stamped authority", () => {
|
||||
const current = stampedSnapshot({ snapshotRevision: 8 });
|
||||
const legacy = snapshot(99, 99);
|
||||
|
||||
assert.equal(selectMonotonicXgridsState(current, legacy), current);
|
||||
assert.equal(selectMonotonicXgridsState(legacy, current), current);
|
||||
});
|
||||
|
||||
test("accepts the first camera preview snapshot", () => {
|
||||
const incoming = snapshot(1, 1);
|
||||
assert.equal(selectMonotonicXgridsState(null, incoming), incoming);
|
||||
|
||||
Reference in New Issue
Block a user