返回 DeepSeek-Reasonix
session-identity.test.ts
根目录 / desktop / frontend / src / __tests__ / session-identity.test.ts
1 import assert from "node:assert/strict";
2 import { sessionIdentityKey } from "../app-runtime/sessionTarget";
3 import { hasSessionGeneration, sameSessionIdentity, sessionIdentityStableKey } from "../lib/sessionIdentity";
4
5 const a = { session: { hostId: "local", sessionId: "canonical-a" }, sessionPath: "", sessionGeneration: 1 };
6 const b = { session: { hostId: "local", sessionId: "canonical-b" }, sessionPath: "", sessionGeneration: 1 };
7
8 assert.equal(hasSessionGeneration(0), true, "a newly bound host session starts at zero");
9 assert.equal(hasSessionGeneration(1), true);
10 for (const invalid of [undefined, null, -1, 0.5, NaN, Infinity, "0", Number.MAX_SAFE_INTEGER + 1]) {
11 assert.equal(hasSessionGeneration(invalid), false, `invalid generation ${String(invalid)}`);
12 }
13
14 assert.notEqual(sessionIdentityStableKey(a), sessionIdentityStableKey(b), "empty-path canonical sessions own different cache keys");
15 assert.equal(sameSessionIdentity(a, { ...a }), true, "the same SessionRef is stable across snapshots");
16 assert.equal(sameSessionIdentity(a, b), false, "SessionRef prevents canonical transcript cross-wiring");
17 assert.equal(
18 sessionIdentityKey({ ...a, tabId: "reused-tab", scope: "project", workspaceRoot: "/repo", topicId: "legacy-topic" }),
19 sessionIdentityStableKey(a),
20 "canonical SessionRef outranks reused tab, topic and compatibility-path identities",
21 );
22
23 console.log("session identity: canonical SessionRef owns caches, navigation and hydration fences");
24
24 lines TYPESCRIPT