session-model-selection-restore.test.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // 会话常驻 Selection 的恢复回归。
  2. // Bug 现场:旧版分叉把分叉点的加速卡选型写进 child 的 runtime/model_selection entry,
  3. // 这类会话恢复后常驻在隐藏的 `account:*-highspeed-card` 上,UI 模型选择器一片空白。
  4. import { describe, expect, it } from "vitest";
  5. import {
  6. SESSION_ENTRY_MODEL_SELECTION,
  7. type SessionEntryInfo,
  8. type SessionId,
  9. type SessionStorePort,
  10. } from "@zcode/contracts";
  11. import { HIGHSPEED_PROVIDER_IDS } from "@zcode/shared";
  12. import { readSessionModelSelection } from "../src/app/session-store.js";
  13. const SESSION_ID = "sess_restore" as SessionId;
  14. function storeWithEntryData(data: unknown): Pick<SessionStorePort, "sessionEntries"> {
  15. const entry = {
  16. id: `${SESSION_ID}:runtime-model-selection`,
  17. sessionID: SESSION_ID,
  18. type: SESSION_ENTRY_MODEL_SELECTION,
  19. time: { created: 1, updated: 1 },
  20. data,
  21. } as SessionEntryInfo;
  22. return { sessionEntries: async () => [entry] } as Pick<SessionStorePort, "sessionEntries">;
  23. }
  24. describe("恢复会话常驻 Selection", () => {
  25. it("丢弃持久化的加速卡选型,让会话回到未绑定", async () => {
  26. for (const providerId of Object.values(HIGHSPEED_PROVIDER_IDS)) {
  27. await expect(
  28. readSessionModelSelection(
  29. storeWithEntryData({
  30. providerId,
  31. modelId: "GLM-5.3",
  32. options: { reasoningLevel: "max" },
  33. }),
  34. SESSION_ID,
  35. ),
  36. ).resolves.toBeUndefined();
  37. }
  38. });
  39. it("普通选型原样恢复", async () => {
  40. await expect(
  41. readSessionModelSelection(
  42. storeWithEntryData({
  43. providerId: "account:bigmodel-team-coding-plan",
  44. modelId: "GLM-5.3",
  45. options: { reasoningLevel: "max" },
  46. }),
  47. SESSION_ID,
  48. ),
  49. ).resolves.toEqual({
  50. providerId: "account:bigmodel-team-coding-plan",
  51. modelId: "GLM-5.3",
  52. options: { reasoningLevel: "max" },
  53. });
  54. });
  55. it("档位非法走模型身份兜底时同样过滤加速卡", async () => {
  56. // 兜底分支只捞 providerId/modelId,加速 Provider 不能借这条路径复活。
  57. await expect(
  58. readSessionModelSelection(
  59. storeWithEntryData({
  60. providerId: HIGHSPEED_PROVIDER_IDS.bigmodel,
  61. modelId: "GLM-5.3",
  62. options: { reasoningLevel: 3 },
  63. }),
  64. SESSION_ID,
  65. ),
  66. ).resolves.toBeUndefined();
  67. await expect(
  68. readSessionModelSelection(
  69. storeWithEntryData({
  70. providerId: "account:bigmodel-team-coding-plan",
  71. modelId: "GLM-5.3",
  72. options: { reasoningLevel: 3 },
  73. }),
  74. SESSION_ID,
  75. ),
  76. ).resolves.toEqual({ providerId: "account:bigmodel-team-coding-plan", modelId: "GLM-5.3" });
  77. });
  78. it("没有 entry 时返回空", async () => {
  79. await expect(
  80. readSessionModelSelection({ sessionEntries: async () => [] }, SESSION_ID),
  81. ).resolves.toBeUndefined();
  82. await expect(readSessionModelSelection({}, SESSION_ID)).resolves.toBeUndefined();
  83. });
  84. });