sessions-index-projection.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. // SessionsIndexProjection / SessionsIndexPublisher 黄金测试(M5 ①,14-sessions-index):
  2. // 多会话 ConversationSnapshot → SessionSummary 派生 + upsert/remove delta + conflation + 帧记账。
  3. import { describe, expect, it } from "vitest";
  4. import type {
  5. EventId,
  6. SessionEvent,
  7. SessionEventType as SessionEventTypeUnion,
  8. SessionId,
  9. TraceId,
  10. TurnId,
  11. } from "@zcode/contracts";
  12. import { SessionEventType } from "@zcode/contracts";
  13. import {
  14. sessionsIndexSnapshotSchema,
  15. sessionsIndexTopicFrameSchema,
  16. } from "@zcode/shared/zcode-protocol-v4";
  17. import { ProductProjection } from "../src/zcode-protocol-v4/index.js";
  18. import {
  19. SessionsIndexProjection,
  20. deriveSessionSummary,
  21. } from "../src/zcode-protocol-v4/sessions-index-projection.js";
  22. import { SessionsIndexPublisher } from "../src/zcode-protocol-v4/sessions-index-publisher.js";
  23. function buildEvents(
  24. sessionId: string,
  25. build: (push: (type: SessionEventTypeUnion, payload: unknown, turnId?: string) => void) => void,
  26. ): SessionEvent[] {
  27. const events: SessionEvent[] = [];
  28. let seq = 0;
  29. build((type, payload, turnId) => {
  30. seq += 1;
  31. events.push({
  32. id: `event-${sessionId}-${seq}` as EventId,
  33. sessionId: sessionId as SessionId,
  34. turnId: turnId as TurnId | undefined,
  35. type,
  36. timestamp: new Date(1_700_000_000_000 + seq * 1000),
  37. traceId: "trace-1" as TraceId,
  38. sequenceNumber: seq,
  39. payload,
  40. });
  41. });
  42. return events;
  43. }
  44. function projectionFor(sessionId: string, events: SessionEvent[]): ProductProjection {
  45. const projection = new ProductProjection(sessionId, "epoch-1");
  46. for (const event of events) projection.applyEvent(event);
  47. return projection;
  48. }
  49. describe("SessionsIndexProjection 黄金测试(L1)", () => {
  50. it("派生:title/phase/goal/hasBackgroundWork/preview 从会话快照取值", () => {
  51. const events = buildEvents("s1", (push) => {
  52. push(SessionEventType.SessionCreated, {
  53. mode: "default",
  54. contextWindow: 200_000,
  55. });
  56. push(SessionEventType.SessionTitleUpdated, {
  57. previousTitle: "",
  58. source: "custom",
  59. title: "我的会话",
  60. });
  61. push(SessionEventType.TurnStarted, { turnNumber: 1, input: "hi", inputId: "query-1" }, "t1");
  62. push(
  63. SessionEventType.ModelStreaming,
  64. { kind: "text_start", delta: "", done: false, assistantMessageId: "m1" },
  65. "t1",
  66. );
  67. push(
  68. SessionEventType.ModelStreaming,
  69. {
  70. kind: "text_delta",
  71. delta: "你好世界",
  72. done: false,
  73. assistantMessageId: "m1",
  74. },
  75. "t1",
  76. );
  77. push(SessionEventType.ModelStreaming, { kind: "text_end", delta: "", done: false }, "t1");
  78. push(
  79. SessionEventType.TurnComplete,
  80. {
  81. response: "",
  82. tokenCount: 0,
  83. toolCallCount: 0,
  84. duration: 0,
  85. resultType: "success",
  86. historyRoundCount: 2,
  87. },
  88. "t1",
  89. );
  90. });
  91. const snapshot = projectionFor("s1", events).getSnapshot();
  92. const summary = deriveSessionSummary(snapshot, {
  93. workspaceId: "ws-1",
  94. createdAt: 1000,
  95. lastActivityAt: 2000,
  96. });
  97. expect(summary.sessionId).toBe("s1");
  98. expect(summary.workspaceId).toBe("ws-1");
  99. expect(summary.title).toBe("我的会话");
  100. expect(summary.titleSource).toBe("custom");
  101. expect(summary.phase).toBe("completedSuccess");
  102. // control.sessionEnded 由 onTurnComplete 置为 phase!=="error"(M2 既有语义,summary 忠实透传)。
  103. expect(summary.sessionEnded).toBe(true);
  104. expect(summary.hasBackgroundWork).toBe(false);
  105. expect(summary.lastAssistantPreview).toContain("你好世界");
  106. expect(summary.createdAt).toBe(1000);
  107. expect(summary.lastActivityAt).toBe(2000);
  108. });
  109. it("hasBackgroundWork:有 running 后台任务时为 true", () => {
  110. const events = buildEvents("s2", (push) => {
  111. push(SessionEventType.SessionCreated, {
  112. mode: "default",
  113. contextWindow: 200_000,
  114. });
  115. push(SessionEventType.BackgroundTaskStarted, {
  116. taskId: "bg-1",
  117. toolName: "Bash",
  118. command: "sleep 100",
  119. status: "running",
  120. });
  121. });
  122. const snapshot = projectionFor("s2", events).getSnapshot();
  123. const summary = deriveSessionSummary(snapshot, {
  124. workspaceId: "ws-1",
  125. createdAt: 1,
  126. lastActivityAt: 2,
  127. });
  128. expect(summary.hasBackgroundWork).toBe(true);
  129. });
  130. it("workflowActivity:从 workflowRuns + workflow 后台工作派生;活动时间不变时只改 node 的事件判等,phase 翻转必产帧", () => {
  131. const runProgress = (
  132. push: (type: SessionEventTypeUnion, payload: unknown) => void,
  133. sequence: number,
  134. eventType: string,
  135. payload: Record<string, unknown>,
  136. ) =>
  137. push(SessionEventType.DynamicWorkflowRunProgress, {
  138. runId: "run-1",
  139. toolCallId: "tool-1",
  140. sequence,
  141. eventType,
  142. payload,
  143. });
  144. const events = buildEvents("s-wf", (push) => {
  145. push(SessionEventType.SessionCreated, { mode: "default", contextWindow: 200_000 });
  146. push(SessionEventType.BackgroundTaskStarted, {
  147. taskId: "run-1",
  148. toolName: "CreateWorkflow",
  149. taskKind: "workflow",
  150. description: "Deep research",
  151. status: "running",
  152. });
  153. runProgress(push, 0, "run-started", { runId: "run-1", caps: { maxConcurrency: 4 } });
  154. runProgress(push, 1, "run-launched", {
  155. inputId: "in-1",
  156. phaseNames: ["Research", "Write"],
  157. // 进入 Write 时 Research 的 strand 还在跑:侧栏据此把两站之间画成双线段。
  158. phaseAlongside: [[], [0]],
  159. });
  160. runProgress(push, 2, "phase-entered", { name: "Research", ordinal: 1 });
  161. runProgress(push, 3, "actor-created", {
  162. actor: { siteId: "actor#1", ordinal: 1 },
  163. name: "Scout",
  164. });
  165. runProgress(push, 4, "node-queued", {
  166. instance: { siteId: "ask#1", ordinal: 1 },
  167. kind: "ask",
  168. actor: { siteId: "actor#1", ordinal: 1 },
  169. });
  170. runProgress(push, 5, "node-executing", { instance: { siteId: "ask#1", ordinal: 1 } });
  171. });
  172. const projection = projectionFor("s-wf", events);
  173. const summary = deriveSessionSummary(projection.getSnapshot(), {
  174. workspaceId: "ws-1",
  175. createdAt: 1,
  176. lastActivityAt: 2,
  177. });
  178. expect(summary.hasBackgroundWork).toBe(true);
  179. expect(summary.workflowActivity).toEqual({
  180. runs: [
  181. {
  182. runId: "run-1",
  183. toolCallId: "tool-1",
  184. name: "Deep research",
  185. status: "running",
  186. startedAt: expect.any(Number),
  187. phases: [
  188. { name: "Research", status: "running" },
  189. { name: "Write", status: "pending", alongside: [0] },
  190. ],
  191. currentPhase: "Research",
  192. agentsWorking: 1,
  193. },
  194. ],
  195. });
  196. // 同一 run 再来只改 node / 用量、不改 phase / status / 子代理数的事件:摘要判等,不产侧栏帧。
  197. const index = new SessionsIndexProjection("ws-1", "epoch-1");
  198. expect(
  199. index.upsertFromConversation(projection.getSnapshot(), { createdAt: 1, lastActivityAt: 2 }),
  200. ).toHaveLength(1);
  201. const nodeOnly = buildEvents("s-wf", (push) => {
  202. runProgress(push, 6, "node-queued", {
  203. instance: { siteId: "ask#2", ordinal: 1 },
  204. kind: "ask",
  205. actor: { siteId: "actor#1", ordinal: 1 },
  206. });
  207. runProgress(push, 7, "usage-updated", { spentTokens: 120 });
  208. });
  209. for (const event of nodeOnly) projection.applyEvent(event);
  210. expect(
  211. index.upsertFromConversation(projection.getSnapshot(), { createdAt: 1, lastActivityAt: 2 }),
  212. ).toEqual([]);
  213. // 进入下一个 phase 则产 delta,且站点灯随之翻转。
  214. const [phase] = buildEvents("s-wf", (push) =>
  215. runProgress(push, 8, "phase-entered", { name: "Write", ordinal: 1 }),
  216. );
  217. projection.applyEvent(phase!);
  218. const deltas = index.upsertFromConversation(projection.getSnapshot(), {
  219. createdAt: 1,
  220. lastActivityAt: 2,
  221. });
  222. expect(deltas).toHaveLength(1);
  223. const delta = deltas[0]!;
  224. if (delta.op !== "session.upserted") throw new Error("expected upsert");
  225. expect(delta.session.workflowActivity?.runs[0]?.phases.map((p) => p.status)).toEqual([
  226. "done",
  227. "running",
  228. ]);
  229. });
  230. it("projects the head interaction auto-resolution state into the lightweight summary", () => {
  231. const events = buildEvents("s-ask", (push) => {
  232. push(SessionEventType.SessionCreated, {
  233. mode: "default",
  234. contextWindow: 200_000,
  235. });
  236. push(SessionEventType.PermissionRequested, {
  237. requestId: "ask-1",
  238. toolCallId: "tool-1",
  239. toolName: "AskUserQuestion",
  240. riskLevel: "low",
  241. reason: "Need input",
  242. input: {
  243. questions: [
  244. {
  245. header: "Choice",
  246. question: "Choose?",
  247. options: [
  248. { label: "A", description: "a" },
  249. { label: "B", description: "b" },
  250. ],
  251. },
  252. ],
  253. },
  254. });
  255. push(SessionEventType.UserInputAutoResolutionUpdated, {
  256. interactionId: "ask-1",
  257. toolCallId: "tool-1",
  258. autoResolution: {
  259. state: "visibleCountdown",
  260. startedAt: 1_000,
  261. visibleAt: 61_000,
  262. deadlineAt: 301_000,
  263. },
  264. });
  265. });
  266. const summary = deriveSessionSummary(projectionFor("s-ask", events).getSnapshot(), {
  267. workspaceId: "ws-1",
  268. createdAt: 1,
  269. lastActivityAt: 2,
  270. });
  271. expect(summary.pendingInteraction).toEqual({
  272. interactionId: "ask-1",
  273. kind: "userInput",
  274. toolName: "AskUserQuestion",
  275. autoResolution: {
  276. state: "visibleCountdown",
  277. startedAt: 1_000,
  278. visibleAt: 61_000,
  279. deadlineAt: 301_000,
  280. },
  281. });
  282. });
  283. it("只投影 pending interaction 的 kind/count,不下发 payload", () => {
  284. const events = buildEvents("s-interactions", (push) => {
  285. push(SessionEventType.SessionCreated, {
  286. mode: "default",
  287. contextWindow: 200_000,
  288. });
  289. });
  290. const baseSnapshot = projectionFor("s-interactions", events).getSnapshot();
  291. const summary = deriveSessionSummary(
  292. {
  293. ...baseSnapshot,
  294. pendingInteractions: [
  295. { kind: "permission" } as never,
  296. { kind: "permission" } as never,
  297. { kind: "userInput" } as never,
  298. ],
  299. },
  300. {
  301. workspaceId: "ws-1",
  302. createdAt: 1,
  303. lastActivityAt: 2,
  304. },
  305. );
  306. expect(summary.pendingInteractionSummary).toEqual({
  307. permissionCount: 2,
  308. userInputCount: 1,
  309. });
  310. expect(summary).not.toHaveProperty("pendingInteractions");
  311. });
  312. it("不把 workspace Hook review 降级成 permission/userInput 侧栏状态", () => {
  313. const events = buildEvents("s-workspace-review", (push) => {
  314. push(SessionEventType.SessionCreated, {
  315. mode: "default",
  316. contextWindow: 200_000,
  317. });
  318. });
  319. const baseSnapshot = projectionFor("s-workspace-review", events).getSnapshot();
  320. const summary = deriveSessionSummary(
  321. {
  322. ...baseSnapshot,
  323. pendingInteractions: [
  324. {
  325. interactionId: "workspace-review-1",
  326. kind: "workspaceHookReview",
  327. payload: { kind: "workspaceHookReview" },
  328. } as never,
  329. ],
  330. },
  331. {
  332. workspaceId: "ws-1",
  333. createdAt: 1,
  334. lastActivityAt: 2,
  335. },
  336. );
  337. expect(summary).not.toHaveProperty("pendingInteraction");
  338. expect(summary).not.toHaveProperty("pendingInteractionSummary");
  339. });
  340. it("index:upsert 变化才产 delta(conflation),remove 命中产 delta", () => {
  341. const index = new SessionsIndexProjection("ws-1", "list-epoch-1");
  342. const events = buildEvents("s1", (push) => {
  343. push(SessionEventType.SessionCreated, {
  344. mode: "default",
  345. contextWindow: 200_000,
  346. });
  347. });
  348. const snapshot = projectionFor("s1", events).getSnapshot();
  349. const extra = { createdAt: 1, lastActivityAt: 2 };
  350. // 首次 upsert 产 delta
  351. const d1 = index.upsertFromConversation(snapshot, extra);
  352. expect(d1).toHaveLength(1);
  353. expect(d1[0]).toMatchObject({ op: "session.upserted" });
  354. // 相同 snapshot + extra → 幂等无 delta
  355. const d2 = index.upsertFromConversation(snapshot, extra);
  356. expect(d2).toHaveLength(0);
  357. // lastActivityAt 变化 → 再产 upsert
  358. const d3 = index.upsertFromConversation(snapshot, {
  359. createdAt: 1,
  360. lastActivityAt: 3,
  361. });
  362. expect(d3).toHaveLength(1);
  363. // 快照含该会话
  364. expect(index.getSnapshot().sessions.map((s) => s.sessionId)).toEqual(["s1"]);
  365. // remove 命中产 delta,再 remove 幂等
  366. expect(index.remove("s1")).toHaveLength(1);
  367. expect(index.remove("s1")).toHaveLength(0);
  368. expect(index.getSnapshot().sessions).toHaveLength(0);
  369. });
  370. it("index:stored→live 降级防御——live 空标题/新时间不得覆盖 store 种子", () => {
  371. const index = new SessionsIndexProjection("ws-1", "list-epoch-1");
  372. // store 种子:带标题与原始时间(模拟侧栏冷启动)。
  373. index.seed({
  374. sessionId: "s1",
  375. workspaceId: "ws-1",
  376. title: "项目分析与优化",
  377. phase: "completedSuccess",
  378. sessionEnded: true,
  379. hasBackgroundWork: false,
  380. lastActivityAt: 100,
  381. lastAssistantPreview: "旧预览",
  382. createdAt: 10,
  383. });
  384. // 冷恢复的 live 投影:hydration 前 meta.title 为空、record 时间被 resume 重置为"现在"。
  385. const events = buildEvents("s1", (push) => {
  386. push(SessionEventType.SessionCreated, {
  387. mode: "default",
  388. contextWindow: 200_000,
  389. });
  390. });
  391. const snapshot = projectionFor("s1", events).getSnapshot();
  392. index.upsertFromConversation(snapshot, {
  393. createdAt: 9_999,
  394. lastActivityAt: 9_999,
  395. });
  396. const merged = index.getSnapshot().sessions.find((s) => s.sessionId === "s1");
  397. expect(merged?.title).toBe("项目分析与优化");
  398. expect(merged?.createdAt).toBe(10);
  399. expect(merged?.lastAssistantPreview).toBe("旧预览");
  400. // Bugfix 断言:hydration 前的 live 投影 phase 是初始 draft,不得把终态基线降级。
  401. expect(merged?.phase).toBe("completedSuccess");
  402. expect(merged?.sessionEnded).toBe(true);
  403. });
  404. it("index:冷恢复 draft 窗口快照与基线等价时不产 delta(打开历史任务不刷列表)", () => {
  405. const index = new SessionsIndexProjection("ws-1", "list-epoch-1");
  406. index.seed({
  407. sessionId: "s1",
  408. workspaceId: "ws-1",
  409. title: "项目分析与优化",
  410. phase: "completedSuccess",
  411. sessionEnded: true,
  412. hasBackgroundWork: false,
  413. lastActivityAt: 100,
  414. lastAssistantPreview: "旧预览",
  415. createdAt: 10,
  416. });
  417. // 冷恢复 live 投影(hydration 未完成):phase=draft、无标题/预览;
  418. // record 时间已由 resume 路径回填 store 真实时间(lastActivityAt 一致)。
  419. const events = buildEvents("s1", (push) => {
  420. push(SessionEventType.SessionCreated, {
  421. mode: "default",
  422. contextWindow: 200_000,
  423. });
  424. });
  425. const snapshot = projectionFor("s1", events).getSnapshot();
  426. const deltas = index.upsertFromConversation(snapshot, {
  427. createdAt: 10,
  428. lastActivityAt: 100,
  429. });
  430. // 所有字段被降级防御保住 → summariesEqual → 零 delta,UI 列表不动。
  431. expect(deltas).toHaveLength(0);
  432. });
  433. it("index:多会话快照 schema 合法 + 无序聚合", () => {
  434. const index = new SessionsIndexProjection("ws-1", "list-epoch-1");
  435. for (const sid of ["a", "b", "c"]) {
  436. const events = buildEvents(sid, (push) => {
  437. push(SessionEventType.SessionCreated, {
  438. mode: "default",
  439. contextWindow: 200_000,
  440. });
  441. });
  442. index.upsertFromConversation(projectionFor(sid, events).getSnapshot(), {
  443. createdAt: 1,
  444. lastActivityAt: 2,
  445. });
  446. }
  447. const snap = index.getSnapshot();
  448. expect(snap.sessions).toHaveLength(3);
  449. expect(new Set(snap.sessions.map((s) => s.sessionId))).toEqual(new Set(["a", "b", "c"]));
  450. // 帧 schema 合法性
  451. expect(() => sessionsIndexSnapshotSchema.parse(snap)).not.toThrow();
  452. });
  453. it("fork:parentSessionId 透传", () => {
  454. const events = buildEvents("child", (push) => {
  455. push(SessionEventType.SessionCreated, {
  456. mode: "default",
  457. contextWindow: 200_000,
  458. });
  459. });
  460. const snapshot = projectionFor("child", events).getSnapshot();
  461. const summary = deriveSessionSummary(snapshot, {
  462. workspaceId: "ws-1",
  463. createdAt: 1,
  464. lastActivityAt: 2,
  465. parentSessionId: "parent",
  466. });
  467. expect(summary.parentSessionId).toBe("parent");
  468. });
  469. });
  470. describe("SessionsIndexPublisher 单测(帧记账)", () => {
  471. let clock = 1000;
  472. const now = () => (clock += 1);
  473. function snap(sessionId: string): ReturnType<ProductProjection["getSnapshot"]> {
  474. const events = buildEvents(sessionId, (push) => {
  475. push(SessionEventType.SessionCreated, {
  476. mode: "default",
  477. contextWindow: 200_000,
  478. });
  479. });
  480. return projectionFor(sessionId, events).getSnapshot();
  481. }
  482. it("subscribe → snapshot 帧(fromSeq=0),帧 schema 合法", () => {
  483. const pub = new SessionsIndexPublisher("ws-1", "epoch-1", now);
  484. pub.ingestConversation(snap("a"), { createdAt: 1, lastActivityAt: 2 });
  485. const res = pub.subscribe("conn-1");
  486. expect(res.mode).toBe("snapshot");
  487. expect(res.frame?.payload.kind).toBe("snapshot");
  488. expect(res.frame?.fromSeq).toBe(0);
  489. expect(() => sessionsIndexTopicFrameSchema.parse(res.frame)).not.toThrow();
  490. });
  491. it("订阅后 ingest → flush 出增量帧((fromSeq, toSeq])", () => {
  492. const pub = new SessionsIndexPublisher("ws-1", "epoch-1", now);
  493. const res = pub.subscribe("conn-1");
  494. const baseSeq = res.frame?.toSeq ?? 0;
  495. // 新会话进入 → 有变化
  496. expect(pub.ingestConversation(snap("a"), { createdAt: 1, lastActivityAt: 2 })).toBe(true);
  497. const frame = pub.flush(res.subscriptionId);
  498. expect(frame?.payload.kind).toBe("deltas");
  499. expect(frame?.fromSeq).toBe(baseSeq);
  500. expect(frame?.toSeq).toBe(pub.seq);
  501. if (frame?.payload.kind === "deltas") {
  502. expect(frame.payload.deltas[0]).toMatchObject({ op: "session.upserted" });
  503. }
  504. // 已排空 → 再 flush 为 null
  505. expect(pub.flush(res.subscriptionId)).toBeNull();
  506. });
  507. it("幂等 ingest 不产帧;resume base=当前 seq → frame null", () => {
  508. const pub = new SessionsIndexPublisher("ws-1", "epoch-1", now);
  509. pub.ingestConversation(snap("a"), { createdAt: 1, lastActivityAt: 2 });
  510. // 同快照再进 → 无变化
  511. expect(pub.ingestConversation(snap("a"), { createdAt: 1, lastActivityAt: 2 })).toBe(false);
  512. const res = pub.subscribe("conn-1", { logEpoch: "epoch-1", seq: pub.seq });
  513. expect(res.mode).toBe("resume");
  514. expect(res.frame).toBeNull();
  515. });
  516. it("removeSession → remove delta 帧", () => {
  517. const pub = new SessionsIndexPublisher("ws-1", "epoch-1", now);
  518. pub.ingestConversation(snap("a"), { createdAt: 1, lastActivityAt: 2 });
  519. const res = pub.subscribe("conn-1");
  520. expect(pub.removeSession("a")).toBe(true);
  521. const frame = pub.flush(res.subscriptionId);
  522. if (frame?.payload.kind === "deltas") {
  523. expect(frame.payload.deltas[0]).toMatchObject({
  524. op: "session.removed",
  525. sessionId: "a",
  526. });
  527. } else {
  528. throw new Error("expected deltas frame");
  529. }
  530. });
  531. it("异代际 base → 退化 snapshot;重订阅替换旧代际(同 connection 新 subscriptionId)", () => {
  532. const pub = new SessionsIndexPublisher("ws-1", "epoch-1", now);
  533. pub.ingestConversation(snap("a"), { createdAt: 1, lastActivityAt: 2 });
  534. const stale = pub.subscribe("conn-1", { logEpoch: "other-epoch", seq: 1 });
  535. expect(stale.mode).toBe("snapshot");
  536. expect(stale.frame?.payload.kind).toBe("snapshot");
  537. const replaced = pub.subscribe("conn-1");
  538. expect(replaced.subscriptionId).not.toBe(stale.subscriptionId);
  539. expect(pub.subscriptionIds()).toEqual([replaced.subscriptionId]);
  540. });
  541. });