zcodeAgentService.providerRegistry.test.ts 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. import { describe, expect, it, vi } from "vitest";
  2. import {
  3. ProviderConfig,
  4. ProviderConfigMap,
  5. ZhipuAccountAccessConfig,
  6. type AccountProviderConfigSnapshot,
  7. type ModelSelectionView,
  8. } from "@zcode/provider";
  9. import { zcodeProtocolMethods } from "@zcode/shared";
  10. import { V4_METHODS } from "@zcode/shared/zcode-protocol-v4";
  11. import { createAccountProviderConfig } from "./providerConfigFixtures.js";
  12. const START_PLAN_PROVIDER_ID = "account:zai-start-plan";
  13. const BIGMODEL_CODING_PLAN_PROVIDER_ID = "account:bigmodel-individual-coding-plan";
  14. const protocolModelProperties = {
  15. inputFormat: {
  16. supportsText: true,
  17. supportsImage: false,
  18. supportsVideo: false,
  19. supportsAudio: false,
  20. supportsPdf: false,
  21. },
  22. outputFormat: { supportsText: true },
  23. };
  24. type RegistryFixture = {
  25. generatedAt: number;
  26. revision: string;
  27. providers: Array<{
  28. providerId: string;
  29. apiFormat?: "anthropic-messages" | "openai-responses" | "openai-chat-completions";
  30. baseURL?: string;
  31. models: Array<{ modelId: string }>;
  32. }>;
  33. };
  34. class MockProcessManagerBase {
  35. // Bug 原因:service 现在订阅 runtime unavailable 生命周期来清理旧 client;这些 provider
  36. // 用例只验证 registry/model 语义,mock 必须提供同形状的空订阅,避免在业务断言前失败。
  37. onRuntimeLifecycle() {
  38. return { dispose() {} };
  39. }
  40. onRuntimeRestarted() {
  41. return { dispose() {} };
  42. }
  43. // Bug 根因:service 在 provider/model 门禁通过后会标记 runtime ready;共享 mock
  44. // 缺少该生命周期方法会让所有进入模型执行路径的用例在业务断言前统一失败。
  45. markReady() {}
  46. }
  47. function createSessionSnapshot(params: {
  48. model: { providerId: string; modelId: string };
  49. thoughtLevel?: string;
  50. }) {
  51. return {
  52. protocol: { name: "ZCode Protocol", version: 1 },
  53. session: {
  54. sessionId: "sess_1",
  55. workspace: {
  56. workspacePath: "/workspace/app",
  57. workspaceKey: "/workspace/app",
  58. },
  59. sessionKind: "interactive",
  60. title: "Runtime model test",
  61. mode: "build",
  62. status: "idle",
  63. createdAt: 1,
  64. updatedAt: 1,
  65. },
  66. settings: {
  67. model: {
  68. current: params.model,
  69. available: [
  70. {
  71. ref: params.model,
  72. label: params.model.modelId,
  73. properties: protocolModelProperties,
  74. },
  75. ],
  76. },
  77. thoughtLevel: {
  78. enabled: params.thoughtLevel !== undefined,
  79. current: params.thoughtLevel,
  80. available: params.thoughtLevel
  81. ? [{ value: params.thoughtLevel, label: params.thoughtLevel }]
  82. : [],
  83. },
  84. mode: { current: "build" },
  85. },
  86. projection: {
  87. sessionId: "sess_1",
  88. status: "idle",
  89. mode: "build",
  90. turnCount: 0,
  91. totalTokenCount: 0,
  92. contextUsed: 0,
  93. pendingPermissions: [],
  94. },
  95. runtime: { eventSeq: 0, stateRevision: 1, pendingRequestIds: [] },
  96. messages: [],
  97. };
  98. }
  99. function createStartPlanRegistry(params?: {
  100. glm52Levels?: string[];
  101. revision?: string;
  102. }): RegistryFixture {
  103. const glm52Levels = params?.glm52Levels ?? ["max", "off"];
  104. return {
  105. generatedAt: 2,
  106. providers: [
  107. {
  108. providerId: START_PLAN_PROVIDER_ID,
  109. apiKeyRequired: false,
  110. kind: "openai-compatible",
  111. baseURL: "https://zcode.z.ai/api/v1/zcode-plan",
  112. models: [
  113. {
  114. modelId: "GLM-5.2",
  115. reasoning: {
  116. enabled: true,
  117. ...(glm52Levels[0] ? { defaultLevel: glm52Levels[0] } : {}),
  118. levels: glm52Levels.map((level) => ({ value: level, label: level })),
  119. },
  120. },
  121. {
  122. modelId: "GLM-5.1",
  123. reasoning: {
  124. enabled: true,
  125. defaultLevel: "enabled",
  126. levels: [
  127. { value: "enabled", label: "enabled" },
  128. { value: "off", label: "off" },
  129. ],
  130. },
  131. },
  132. ],
  133. },
  134. ],
  135. revision: params?.revision ?? "sha256:start-plan-registry-1",
  136. };
  137. }
  138. function createBigModelCodingPlanRegistry(params?: { revision?: string }): RegistryFixture {
  139. return {
  140. generatedAt: 2,
  141. providers: [
  142. {
  143. providerId: BIGMODEL_CODING_PLAN_PROVIDER_ID,
  144. apiKeyRequired: false,
  145. kind: "anthropic",
  146. baseURL: "https://open.bigmodel.cn/api/anthropic",
  147. models: [{ modelId: "GLM-5.2" }],
  148. },
  149. ],
  150. revision: params?.revision ?? "sha256:bigmodel-coding-plan-registry-1",
  151. };
  152. }
  153. function createAccountProviderConfigChangeSource(initial: AccountProviderConfigSnapshot) {
  154. let snapshot = initial;
  155. let listener: ((reason: string) => void) | undefined;
  156. return {
  157. source: {
  158. async read() {
  159. return snapshot;
  160. },
  161. onDidChange(callback: (reason: string) => void) {
  162. listener = callback;
  163. return () => {
  164. if (listener === callback) listener = undefined;
  165. };
  166. },
  167. },
  168. emit(reason: string, next: AccountProviderConfigSnapshot) {
  169. snapshot = next;
  170. listener?.(reason);
  171. },
  172. };
  173. }
  174. function createModelSelectionChangeSource(initial: ModelSelectionView) {
  175. let view = initial;
  176. let listener: ((next: ModelSelectionView) => void) | undefined;
  177. return {
  178. source: {
  179. async getView() {
  180. return view;
  181. },
  182. onDidChange(callback: (next: ModelSelectionView) => void) {
  183. listener = callback;
  184. return {
  185. dispose() {
  186. if (listener === callback) listener = undefined;
  187. },
  188. };
  189. },
  190. },
  191. emit(next: ModelSelectionView) {
  192. view = next;
  193. listener?.(next);
  194. },
  195. };
  196. }
  197. function createModelSelectionViewFromRegistry(snapshot: RegistryFixture): ModelSelectionView {
  198. return {
  199. revision: snapshot.generatedAt,
  200. providers: snapshot.providers.map((provider) => ({
  201. providerId: provider.providerId,
  202. config: {
  203. kind: "api" as const,
  204. api: {
  205. type: provider.apiFormat ?? "openai-chat-completions",
  206. baseUrl: provider.baseURL,
  207. },
  208. models: provider.models.map((model) => model.modelId),
  209. },
  210. models: provider.models.map((model) => ({ modelId: model.modelId, config: {} })),
  211. })),
  212. };
  213. }
  214. function createReadyModelSelectionSource() {
  215. return createModelSelectionChangeSource(
  216. createModelSelectionViewFromRegistry(createStartPlanRegistry()),
  217. ).source;
  218. }
  219. describe("createZCodeAgentService provider registry", () => {
  220. it("uses the process model selection view for local startup without sending runtimeModel", async () => {
  221. const selectionSource = createModelSelectionChangeSource({
  222. revision: 1,
  223. providers: [
  224. {
  225. providerId: "custom-openai",
  226. config: {
  227. kind: "api",
  228. apiFormat: "openai-chat-completions",
  229. baseURL: "https://api.example.com/v1",
  230. models: ["agent-model"],
  231. },
  232. models: [{ modelId: "agent-model", config: {} }],
  233. },
  234. ],
  235. });
  236. const request = vi.fn(async (method: string, params?: unknown) => {
  237. if (method === zcodeProtocolMethods.sessionCreate) {
  238. const model = (params as { model: { providerId: string; modelId: string } }).model;
  239. return createSessionSnapshot({ model, thoughtLevel: "high" });
  240. }
  241. throw new Error(`Unexpected method ${method}`);
  242. });
  243. vi.resetModules();
  244. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  245. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  246. async getClient() {
  247. return {
  248. request,
  249. transportKind: "stdio",
  250. onNotification: () => ({ dispose() {} }),
  251. onRequest: () => ({ dispose() {} }),
  252. onClose: () => ({ dispose() {} }),
  253. };
  254. }
  255. disposeAll() {}
  256. },
  257. }));
  258. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  259. const service = createZCodeAgentService({
  260. modelSelectionReadinessSource: selectionSource.source,
  261. });
  262. await service.createSession({
  263. workspacePath: "/workspace/app",
  264. model: { providerId: "custom-openai", modelId: "agent-model" },
  265. thoughtLevel: "high",
  266. });
  267. const createCall = request.mock.calls.find(
  268. ([method]) => method === zcodeProtocolMethods.sessionCreate,
  269. );
  270. expect(createCall?.[1]).toMatchObject({
  271. model: { providerId: "custom-openai", modelId: "agent-model" },
  272. thoughtLevel: "high",
  273. });
  274. expect(
  275. (createCall?.[1] as { runtimeModel?: unknown } | undefined)?.runtimeModel,
  276. ).toBeUndefined();
  277. service.disposeAll();
  278. });
  279. it("starts a waiting local worker after the process model selection view becomes ready", async () => {
  280. const selectionSource = createModelSelectionChangeSource({
  281. revision: 1,
  282. providers: [],
  283. });
  284. const getClient = vi.fn(async () => ({
  285. request: vi.fn(async () => {
  286. throw new Error("Unexpected request");
  287. }),
  288. transportKind: "stdio" as const,
  289. onNotification: () => ({ dispose() {} }),
  290. onRequest: () => ({ dispose() {} }),
  291. onClose: () => ({ dispose() {} }),
  292. }));
  293. vi.resetModules();
  294. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  295. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  296. getClient = getClient;
  297. disposeAll() {}
  298. },
  299. }));
  300. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  301. const service = createZCodeAgentService({
  302. modelSelectionReadinessSource: selectionSource.source,
  303. });
  304. await expect(service.initialize({ workspacePath: "/workspace/app" })).resolves.toMatchObject({
  305. available: false,
  306. });
  307. expect(getClient).not.toHaveBeenCalled();
  308. selectionSource.emit({
  309. revision: 2,
  310. providers: [
  311. {
  312. providerId: "custom-openai",
  313. config: {
  314. kind: "api",
  315. apiFormat: "openai-chat-completions",
  316. baseURL: "https://api.example.com/v1",
  317. models: ["agent-model"],
  318. },
  319. models: [{ modelId: "agent-model", config: {} }],
  320. },
  321. ],
  322. });
  323. await vi.waitFor(() => expect(getClient).toHaveBeenCalledTimes(1));
  324. await expect(service.initialize({ workspacePath: "/workspace/app" })).resolves.toMatchObject({
  325. available: true,
  326. });
  327. service.disposeAll();
  328. });
  329. it("resolves account provider request auth without a renderer round trip", async () => {
  330. let requestListener: ((request: unknown) => void) | undefined;
  331. const respond = vi.fn(async () => {});
  332. const resolveCurrent = vi.fn(async () => ({ apiKey: "team-runtime-key" }));
  333. vi.resetModules();
  334. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  335. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  336. async getClient() {
  337. return {
  338. request: vi.fn(async (method: string) => {
  339. if (method === zcodeProtocolMethods.initialize) {
  340. return {
  341. available: true,
  342. protocolName: "ZCode Protocol",
  343. protocolVersion: 1,
  344. workspaceKey: "/workspace/app",
  345. };
  346. }
  347. throw new Error(`Unexpected method ${method}`);
  348. }),
  349. respond,
  350. respondError: vi.fn(async () => {}),
  351. transportKind: "stdio",
  352. onNotification: () => ({ dispose() {} }),
  353. onRequest: (listener: (request: unknown) => void) => {
  354. requestListener = listener;
  355. return { dispose() {} };
  356. },
  357. onClose: () => ({ dispose() {} }),
  358. };
  359. }
  360. disposeAll() {}
  361. },
  362. }));
  363. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  364. const service = createZCodeAgentService({
  365. accountRequestAuthService: { resolveCurrent },
  366. modelSelectionReadinessSource: createModelSelectionChangeSource(
  367. createModelSelectionViewFromRegistry(createBigModelCodingPlanRegistry()),
  368. ).source,
  369. });
  370. await service.initialize({ workspacePath: "/workspace/app" });
  371. requestListener?.({
  372. id: "agent-request-team-auth",
  373. method: zcodeProtocolMethods.interactionRequestProviderRuntimeHeaders,
  374. params: {
  375. requestId: "team-auth-1",
  376. sessionId: "sess_1",
  377. workspace: {
  378. workspacePath: "/workspace/app",
  379. workspaceKey: "/workspace/app",
  380. },
  381. modelSelection: {
  382. providerId: BIGMODEL_CODING_PLAN_PROVIDER_ID,
  383. modelId: "GLM-5.2",
  384. },
  385. providerId: BIGMODEL_CODING_PLAN_PROVIDER_ID,
  386. accountAccess: {
  387. type: "zhipu-account",
  388. accountType: "bigmodel",
  389. mode: "team-coding-plan",
  390. entitled: true,
  391. },
  392. reason: "model-request",
  393. },
  394. });
  395. await vi.waitFor(() => {
  396. expect(respond).toHaveBeenCalledWith("agent-request-team-auth", {
  397. headersApplied: true,
  398. requestAuth: { apiKey: "team-runtime-key" },
  399. });
  400. });
  401. expect(resolveCurrent).toHaveBeenCalledWith({
  402. providerId: BIGMODEL_CODING_PLAN_PROVIDER_ID,
  403. modelId: "GLM-5.2",
  404. accountAccess: {
  405. type: "zhipu-account",
  406. accountType: "bigmodel",
  407. mode: "team-coding-plan",
  408. entitled: true,
  409. },
  410. reason: "model-request",
  411. });
  412. service.disposeAll();
  413. });
  414. it("keeps initialize waiting without creating a client when provider/model is unavailable", async () => {
  415. const getClient = vi.fn();
  416. vi.resetModules();
  417. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  418. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  419. getClient = getClient;
  420. disposeAll() {}
  421. },
  422. }));
  423. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  424. const service = createZCodeAgentService({
  425. modelSelectionReadinessSource: createModelSelectionChangeSource({
  426. revision: 1,
  427. providers: [],
  428. }).source,
  429. });
  430. await expect(
  431. Promise.all([
  432. service.initialize({ workspacePath: "/workspace/app" }),
  433. service.initialize({ workspacePath: "/workspace/app" }),
  434. ]),
  435. ).resolves.toEqual([
  436. expect.objectContaining({ available: false, reasonCode: "provider_not_ready" }),
  437. expect.objectContaining({ available: false, reasonCode: "provider_not_ready" }),
  438. ]);
  439. expect(getClient).not.toHaveBeenCalled();
  440. service.disposeAll();
  441. });
  442. it("keeps concurrent callers on the same ready startup generation available", async () => {
  443. const getClient = vi.fn(async () => ({
  444. request: vi.fn(),
  445. transportKind: "stdio" as const,
  446. onNotification: () => ({ dispose() {} }),
  447. onRequest: () => ({ dispose() {} }),
  448. onClose: () => ({ dispose() {} }),
  449. }));
  450. vi.resetModules();
  451. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  452. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  453. getClient = getClient;
  454. disposeAll() {}
  455. },
  456. }));
  457. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  458. const service = createZCodeAgentService({
  459. modelSelectionReadinessSource: createModelSelectionChangeSource(
  460. createModelSelectionViewFromRegistry(
  461. createStartPlanRegistry({ revision: "sha256:ready-concurrent" }),
  462. ),
  463. ).source,
  464. });
  465. const workspace = { workspacePath: "/workspace/concurrent-ready" };
  466. await expect(
  467. Promise.all([service.initialize(workspace), service.initialize(workspace)]),
  468. ).resolves.toEqual([
  469. expect.objectContaining({ available: true }),
  470. expect.objectContaining({ available: true }),
  471. ]);
  472. service.disposeAll();
  473. });
  474. it.each(["desktop-continuous", "web-remote-replayable"] as const)(
  475. "并发预热完成不能让迟到的首条命令误判 runtime 已释放:%s",
  476. async (clientMode) => {
  477. const ready = createModelSelectionViewFromRegistry(createStartPlanRegistry());
  478. let finishLateRead!: (view: ModelSelectionView) => void;
  479. const lateRead = new Promise<ModelSelectionView>((resolve) => {
  480. finishLateRead = resolve;
  481. });
  482. const getView = vi.fn().mockResolvedValueOnce(ready).mockReturnValue(lateRead);
  483. const request = vi.fn(async () => ({
  484. commandId: "first-input",
  485. status: "accepted" as const,
  486. revisionAtDecision: 1,
  487. }));
  488. const getClient = vi.fn(async () => ({
  489. request,
  490. transportKind: "stdio" as const,
  491. onNotification: () => ({ dispose() {} }),
  492. onRequest: () => ({ dispose() {} }),
  493. onClose: () => ({ dispose() {} }),
  494. }));
  495. vi.resetModules();
  496. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  497. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  498. getClient = getClient;
  499. disposeAll() {}
  500. },
  501. }));
  502. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  503. const service = createZCodeAgentService({ modelSelectionReadinessSource: { getView } });
  504. const workspace = {
  505. workspacePath: "/workspace/concurrent-first-input",
  506. ...(clientMode === "web-remote-replayable"
  507. ? { workspaceIdentity: "remote:ssh:first:/workspace/concurrent-first-input" }
  508. : {}),
  509. };
  510. try {
  511. const warmup = service.initialize(workspace);
  512. const command = service.sendConversationCommandV4({
  513. ...workspace,
  514. clientMode,
  515. envelope: {
  516. commandId: "first-input",
  517. clientId: clientMode,
  518. sessionId: "sess_1",
  519. type: "sendText",
  520. payload: { text: "first input" },
  521. issuedAt: 1,
  522. },
  523. });
  524. // 旧实现会分别读取 readiness;预热先完成并删掉等待记录,再让首条输入的读取返回。
  525. await expect(warmup).resolves.toMatchObject({ available: true });
  526. finishLateRead(ready);
  527. await expect(command).resolves.toMatchObject({ status: "accepted" });
  528. expect(getView).toHaveBeenCalledTimes(1);
  529. expect(getClient).toHaveBeenCalledTimes(1);
  530. expect(request).toHaveBeenCalledExactlyOnceWith(
  531. V4_METHODS.command,
  532. expect.objectContaining({ commandId: "first-input", type: "sendText" }),
  533. expect.anything(),
  534. );
  535. } finally {
  536. finishLateRead(ready);
  537. service.disposeAll();
  538. }
  539. },
  540. );
  541. it("释放并重新打开 workspace 后,旧 readiness 回调不能借用新 runtime", async () => {
  542. const ready = createModelSelectionViewFromRegistry(createStartPlanRegistry());
  543. let finishOldRead!: (view: ModelSelectionView) => void;
  544. const oldRead = new Promise<ModelSelectionView>((resolve) => {
  545. finishOldRead = resolve;
  546. });
  547. const getView = vi.fn().mockReturnValueOnce(oldRead).mockResolvedValue(ready);
  548. const getClient = vi.fn(async () => ({
  549. request: vi.fn(),
  550. transportKind: "stdio" as const,
  551. onNotification: () => ({ dispose() {} }),
  552. onRequest: () => ({ dispose() {} }),
  553. onClose: () => ({ dispose() {} }),
  554. }));
  555. vi.resetModules();
  556. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  557. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  558. getClient = getClient;
  559. async disposeWorkspace() {}
  560. disposeAll() {}
  561. },
  562. }));
  563. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  564. const service = createZCodeAgentService({ modelSelectionReadinessSource: { getView } });
  565. const workspace = { workspacePath: "/workspace/reopen-during-readiness" };
  566. try {
  567. const oldStartup = service.initialize(workspace);
  568. await service.disposeWorkspace(workspace);
  569. await expect(service.initialize(workspace)).resolves.toMatchObject({ available: true });
  570. finishOldRead(ready);
  571. await expect(oldStartup).resolves.toMatchObject({ available: false });
  572. expect(getClient).toHaveBeenCalledTimes(1);
  573. } finally {
  574. finishOldRead(ready);
  575. service.disposeAll();
  576. }
  577. });
  578. it("starts each waiting workspace identity once when provider/model becomes ready", async () => {
  579. const clients: Array<{
  580. request: ReturnType<typeof vi.fn>;
  581. transportKind: "stdio";
  582. onNotification: () => { dispose(): void };
  583. onRequest: () => { dispose(): void };
  584. onClose: () => { dispose(): void };
  585. }> = [];
  586. const getClient = vi.fn(async () => {
  587. const request = vi.fn(async (method: string) => {
  588. throw new Error(`Unexpected method ${method}`);
  589. });
  590. const client = {
  591. request,
  592. transportKind: "stdio" as const,
  593. onNotification: () => ({ dispose() {} }),
  594. onRequest: () => ({ dispose() {} }),
  595. onClose: () => ({ dispose() {} }),
  596. };
  597. clients.push(client);
  598. return client;
  599. });
  600. vi.resetModules();
  601. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  602. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  603. getClient = getClient;
  604. disposeAll() {}
  605. },
  606. }));
  607. const selectionSource = createModelSelectionChangeSource({
  608. revision: 1,
  609. providers: [],
  610. });
  611. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  612. const service = createZCodeAgentService({
  613. modelSelectionReadinessSource: selectionSource.source,
  614. });
  615. const firstIdentity = "remote:ssh:first:/workspace/app";
  616. const secondIdentity = "remote:ssh:second:/workspace/app";
  617. await service.initialize({
  618. workspacePath: "/workspace/app",
  619. workspaceIdentity: firstIdentity,
  620. });
  621. await service.initialize({
  622. workspacePath: "/workspace/app",
  623. workspaceIdentity: secondIdentity,
  624. });
  625. expect(getClient).not.toHaveBeenCalled();
  626. const ready = createStartPlanRegistry({ revision: "sha256:ready" });
  627. selectionSource.emit(createModelSelectionViewFromRegistry(ready));
  628. await vi.waitFor(() => expect(getClient).toHaveBeenCalledTimes(2));
  629. expect(getClient).toHaveBeenCalledWith(
  630. expect.objectContaining({ workspaceIdentity: firstIdentity }),
  631. );
  632. expect(getClient).toHaveBeenCalledWith(
  633. expect.objectContaining({ workspaceIdentity: secondIdentity }),
  634. );
  635. expect(clients.every((client) => client.request.mock.calls.length === 0)).toBe(true);
  636. selectionSource.emit(
  637. createModelSelectionViewFromRegistry({
  638. ...ready,
  639. generatedAt: ready.generatedAt + 1,
  640. }),
  641. );
  642. await new Promise((resolve) => setTimeout(resolve, 0));
  643. expect(getClient).toHaveBeenCalledTimes(2);
  644. service.disposeAll();
  645. });
  646. it("readiness 读取中到达 ready 事件时,失败的旧启动不能吞掉新事件", async () => {
  647. const getClient = vi.fn(async () => ({
  648. request: vi.fn(),
  649. transportKind: "stdio" as const,
  650. onNotification: () => ({ dispose() {} }),
  651. onRequest: () => ({ dispose() {} }),
  652. onClose: () => ({ dispose() {} }),
  653. }));
  654. vi.resetModules();
  655. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  656. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  657. getClient = getClient;
  658. disposeAll() {}
  659. },
  660. }));
  661. const selectionSource = createModelSelectionChangeSource({ revision: 1, providers: [] });
  662. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  663. const service = createZCodeAgentService({
  664. modelSelectionReadinessSource: selectionSource.source,
  665. });
  666. try {
  667. const initial = service.initialize({ workspacePath: "/workspace/ready-during-startup" });
  668. // getView 已取到空列表,但 await continuation 尚未恢复;此时仅发出一次 ready。
  669. selectionSource.emit(createModelSelectionViewFromRegistry(createStartPlanRegistry()));
  670. await expect(initial).resolves.toMatchObject({ available: false });
  671. await vi.waitFor(() => expect(getClient).toHaveBeenCalledTimes(1));
  672. } finally {
  673. service.disposeAll();
  674. }
  675. });
  676. it("does not restart a released workspace from an already queued provider-ready event", async () => {
  677. const getClient = vi.fn(async () => ({
  678. request: vi.fn(),
  679. transportKind: "stdio" as const,
  680. onNotification: () => ({ dispose() {} }),
  681. onRequest: () => ({ dispose() {} }),
  682. onClose: () => ({ dispose() {} }),
  683. }));
  684. const disposeWorkspace = vi.fn(async () => {});
  685. vi.resetModules();
  686. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  687. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  688. getClient = getClient;
  689. disposeWorkspace = disposeWorkspace;
  690. disposeAll() {}
  691. },
  692. }));
  693. const selectionSource = createModelSelectionChangeSource({
  694. revision: 1,
  695. providers: [],
  696. });
  697. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  698. const service = createZCodeAgentService({
  699. modelSelectionReadinessSource: selectionSource.source,
  700. });
  701. const workspace = { workspacePath: "/workspace/released-before-ready" };
  702. await expect(service.initialize(workspace)).resolves.toMatchObject({
  703. available: false,
  704. reasonCode: "provider_not_ready",
  705. });
  706. selectionSource.emit(
  707. createModelSelectionViewFromRegistry(
  708. createStartPlanRegistry({ revision: "sha256:ready-after-release" }),
  709. ),
  710. );
  711. await service.disposeWorkspace(workspace);
  712. await new Promise((resolve) => setTimeout(resolve, 0));
  713. expect(disposeWorkspace).toHaveBeenCalledWith(workspace);
  714. expect(getClient).not.toHaveBeenCalled();
  715. service.disposeAll();
  716. });
  717. it("reuses a read-only sessions-index client when provider/model becomes ready", async () => {
  718. const request = vi.fn(async (method: string) => {
  719. if (method === "v4/conversation/subscribe") {
  720. return {
  721. ack: {
  722. subscriptionId: "sub-readonly",
  723. mode: "snapshot" as const,
  724. logEpoch: "epoch-readonly",
  725. },
  726. };
  727. }
  728. throw new Error(`Unexpected method ${method}`);
  729. });
  730. const getClient = vi.fn(async () => ({
  731. request,
  732. transportKind: "stdio" as const,
  733. onNotification: () => ({ dispose() {} }),
  734. onRequest: () => ({ dispose() {} }),
  735. onClose: () => ({ dispose() {} }),
  736. }));
  737. vi.resetModules();
  738. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  739. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  740. getClient = getClient;
  741. disposeAll() {}
  742. },
  743. }));
  744. const selectionSource = createModelSelectionChangeSource({
  745. revision: 1,
  746. providers: [],
  747. });
  748. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  749. const service = createZCodeAgentService({
  750. modelSelectionReadinessSource: selectionSource.source,
  751. });
  752. const workspacePath = "/workspace/read-only-then-ready";
  753. await service.subscribeSessionsIndexV4({ workspacePath });
  754. await expect(service.initialize({ workspacePath })).resolves.toMatchObject({
  755. available: false,
  756. reasonCode: "provider_not_ready",
  757. });
  758. expect(getClient).toHaveBeenCalledTimes(1);
  759. selectionSource.emit(
  760. createModelSelectionViewFromRegistry(
  761. createStartPlanRegistry({ revision: "sha256:ready-after-readonly" }),
  762. ),
  763. );
  764. await expect(service.initialize({ workspacePath })).resolves.toMatchObject({
  765. available: true,
  766. });
  767. expect(getClient).toHaveBeenCalledTimes(1);
  768. expect(request).not.toHaveBeenCalledWith(
  769. "workspace/updateProviderRegistry",
  770. expect.anything(),
  771. expect.anything(),
  772. );
  773. service.disposeAll();
  774. });
  775. it("syncs the current Environment Account Config before remote session/create", async () => {
  776. const calls: string[] = [];
  777. const request = vi.fn(async (method: string) => {
  778. calls.push(method);
  779. if (method === zcodeProtocolMethods.providerUpdateAccountConfig) {
  780. return {
  781. receivedRevision: "account-1",
  782. status: "received" as const,
  783. providerCount: 1,
  784. };
  785. }
  786. if (method === zcodeProtocolMethods.sessionCreate) {
  787. return createSessionSnapshot({
  788. model: { providerId: "e2e-primary", modelId: "deepseek-v4-flash" },
  789. });
  790. }
  791. throw new Error(`Unexpected method ${method}`);
  792. });
  793. vi.resetModules();
  794. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  795. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  796. async getClient() {
  797. return {
  798. request,
  799. transportKind: "stdio",
  800. onNotification: () => ({ dispose() {} }),
  801. onRequest: () => ({ dispose() {} }),
  802. onClose: () => ({ dispose() {} }),
  803. };
  804. }
  805. disposeAll() {}
  806. },
  807. }));
  808. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  809. const accountSnapshot: AccountProviderConfigSnapshot = {
  810. revision: "account-1",
  811. basedOnZCodeBuiltinRevision: "zcode-builtin:1",
  812. states: {
  813. "account:zai-individual-coding-plan": {
  814. availability: "available",
  815. entitled: true,
  816. current: false,
  817. },
  818. },
  819. providers: new ProviderConfigMap([
  820. [
  821. "account:zai-individual-coding-plan",
  822. new ProviderConfig({
  823. access: new ZhipuAccountAccessConfig({ entitled: true }),
  824. builtinModelIds: ["GLM-5.2"],
  825. }),
  826. ],
  827. ]),
  828. };
  829. const service = createZCodeAgentService({
  830. modelSelectionReadinessSource: createReadyModelSelectionSource(),
  831. accountProviderConfigSource: {
  832. async read() {
  833. return accountSnapshot;
  834. },
  835. onDidChange() {
  836. return () => {};
  837. },
  838. },
  839. });
  840. await service.createSession({
  841. workspacePath: "/workspace/app",
  842. workspaceIdentity: "remote:ssh:dev:/workspace/app",
  843. model: { providerId: "e2e-primary", modelId: "deepseek-v4-flash" },
  844. });
  845. expect(calls).toEqual([
  846. zcodeProtocolMethods.providerUpdateAccountConfig,
  847. zcodeProtocolMethods.sessionCreate,
  848. ]);
  849. expect(request).toHaveBeenNthCalledWith(
  850. 1,
  851. zcodeProtocolMethods.providerUpdateAccountConfig,
  852. {
  853. revision: "account-1",
  854. basedOnZCodeBuiltinRevision: "zcode-builtin:1",
  855. states: accountSnapshot.states,
  856. providers: {
  857. "account:zai-individual-coding-plan": {
  858. access: {
  859. type: "zhipu-account",
  860. entitled: true,
  861. },
  862. builtinModelIds: ["GLM-5.2"],
  863. },
  864. },
  865. },
  866. expect.any(Object),
  867. );
  868. expect(request).not.toHaveBeenCalledWith(
  869. "workspace/updateProviderRegistry",
  870. expect.anything(),
  871. expect.anything(),
  872. );
  873. service.disposeAll();
  874. });
  875. it("pushes changed Account Config without rebuilding the Workspace Snapshot", async () => {
  876. const accountSource = createAccountProviderConfigChangeSource({
  877. revision: "account-1",
  878. basedOnZCodeBuiltinRevision: "zcode-builtin:1",
  879. providers: new ProviderConfigMap([
  880. [
  881. "account:zai-individual-coding-plan",
  882. createAccountProviderConfig({
  883. models: ["GLM-5.2"],
  884. }),
  885. ],
  886. ]),
  887. });
  888. const request = vi.fn(async (method: string, params?: unknown) => {
  889. if (method === zcodeProtocolMethods.providerUpdateAccountConfig) {
  890. const revision = (params as { revision: string }).revision;
  891. return { receivedRevision: revision, providerCount: 1, status: "received" as const };
  892. }
  893. if (method === zcodeProtocolMethods.sessionCreate) {
  894. return createSessionSnapshot({
  895. model: { providerId: "e2e-primary", modelId: "model-a" },
  896. });
  897. }
  898. throw new Error(`Unexpected method ${method}`);
  899. });
  900. vi.resetModules();
  901. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  902. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  903. async getClient() {
  904. return {
  905. request,
  906. transportKind: "stdio",
  907. onNotification: () => ({ dispose() {} }),
  908. onRequest: () => ({ dispose() {} }),
  909. onClose: () => ({ dispose() {} }),
  910. };
  911. }
  912. disposeAll() {}
  913. },
  914. }));
  915. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  916. const service = createZCodeAgentService({
  917. modelSelectionReadinessSource: createReadyModelSelectionSource(),
  918. accountProviderConfigSource: accountSource.source,
  919. });
  920. await service.createSession({
  921. workspacePath: "/workspace/app",
  922. model: { providerId: "e2e-primary", modelId: "model-a" },
  923. });
  924. request.mockClear();
  925. accountSource.emit("team-plan-selected", {
  926. revision: "account-2",
  927. basedOnZCodeBuiltinRevision: "zcode-builtin:1",
  928. providers: new ProviderConfigMap([
  929. [
  930. "account:zai-individual-coding-plan",
  931. createAccountProviderConfig({
  932. models: ["GLM-5.2"],
  933. }),
  934. ],
  935. ]),
  936. });
  937. await vi.waitFor(() => {
  938. expect(request).toHaveBeenCalledWith(
  939. zcodeProtocolMethods.providerUpdateAccountConfig,
  940. expect.objectContaining({ revision: "account-2" }),
  941. expect.any(Object),
  942. );
  943. });
  944. expect(request).not.toHaveBeenCalledWith(
  945. "workspace/updateProviderRegistry",
  946. expect.anything(),
  947. expect.anything(),
  948. );
  949. // Source 读取也必须串行;否则旧 read 晚返回会把旧快照排在新快照之后。
  950. const latest = await accountSource.source.read();
  951. let releaseOldRead!: (value: AccountProviderConfigSnapshot) => void;
  952. const read = vi.spyOn(accountSource.source, "read").mockImplementationOnce(
  953. () =>
  954. new Promise((resolve) => {
  955. releaseOldRead = resolve;
  956. }),
  957. );
  958. request.mockClear();
  959. accountSource.emit("slow-account-query", { ...latest, revision: "account-3" });
  960. await vi.waitFor(() => expect(read).toHaveBeenCalledTimes(1));
  961. accountSource.emit("new-account-query", { ...latest, revision: "account-4" });
  962. await Promise.resolve();
  963. await Promise.resolve();
  964. const readsBeforeRelease = read.mock.calls.length;
  965. releaseOldRead({ ...latest, revision: "account-3" });
  966. await vi.waitFor(() => {
  967. expect(
  968. request.mock.calls.filter(
  969. ([method]) => method === zcodeProtocolMethods.providerUpdateAccountConfig,
  970. ),
  971. ).toHaveLength(2);
  972. });
  973. const delivered = request.mock.calls
  974. .filter(([method]) => method === zcodeProtocolMethods.providerUpdateAccountConfig)
  975. .map(([, params]) => (params as { revision: string }).revision);
  976. service.disposeAll();
  977. expect(readsBeforeRelease).toBe(1);
  978. expect(delivered).toEqual(["account-3", "account-4"]);
  979. });
  980. it("does not push the full local registry before a V4 draft createSession command", async () => {
  981. const calls: string[] = [];
  982. const request = vi.fn(async (method: string, params?: unknown) => {
  983. calls.push(method);
  984. if (method === V4_METHODS.command) {
  985. const envelope = params as { commandId: string };
  986. return {
  987. commandId: envelope.commandId,
  988. status: "accepted" as const,
  989. revisionAtDecision: 1,
  990. result: { type: "createSession" as const, sessionId: "sess_v4_draft" },
  991. };
  992. }
  993. throw new Error(`Unexpected method ${method}`);
  994. });
  995. vi.resetModules();
  996. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  997. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  998. async getClient() {
  999. return {
  1000. request,
  1001. transportKind: "stdio",
  1002. onNotification: () => ({ dispose() {} }),
  1003. onRequest: () => ({ dispose() {} }),
  1004. onClose: () => ({ dispose() {} }),
  1005. };
  1006. }
  1007. disposeAll() {}
  1008. },
  1009. }));
  1010. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  1011. const service = createZCodeAgentService({
  1012. modelSelectionReadinessSource: createReadyModelSelectionSource(),
  1013. });
  1014. const createPromise = service.sendConversationCommandV4({
  1015. workspacePath: "/workspace/app",
  1016. envelope: {
  1017. commandId: "cmd-v4-draft-custom-model",
  1018. clientId: "client-v4-draft",
  1019. sessionId: null,
  1020. type: "createSession",
  1021. payload: {
  1022. workspaceId: "/workspace/app",
  1023. config: {
  1024. provider: "custom:glm",
  1025. model: "glm-5.2",
  1026. thought: "max",
  1027. },
  1028. },
  1029. issuedAt: 1,
  1030. },
  1031. });
  1032. await expect(createPromise).resolves.toMatchObject({
  1033. status: "accepted",
  1034. result: { type: "createSession", sessionId: "sess_v4_draft" },
  1035. });
  1036. expect(calls).toEqual([V4_METHODS.command]);
  1037. expect(request).toHaveBeenNthCalledWith(
  1038. 1,
  1039. V4_METHODS.command,
  1040. expect.objectContaining({
  1041. type: "createSession",
  1042. payload: expect.objectContaining({
  1043. config: expect.objectContaining({
  1044. provider: "custom:glm",
  1045. model: "glm-5.2",
  1046. }),
  1047. }),
  1048. }),
  1049. expect.any(Object),
  1050. );
  1051. service.disposeAll();
  1052. });
  1053. it("workspace presentation does not attach Host-derived model facts", async () => {
  1054. const request = vi.fn(async () => ({
  1055. workspace: {
  1056. workspacePath: "/workspace/app",
  1057. workspaceKey: "/workspace/app",
  1058. },
  1059. mode: "build",
  1060. slashCommands: [],
  1061. }));
  1062. vi.resetModules();
  1063. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  1064. ZCodeAgentProcessManager: class extends MockProcessManagerBase {
  1065. async getClient() {
  1066. return {
  1067. request,
  1068. transportKind: "stdio",
  1069. onNotification: () => ({ dispose() {} }),
  1070. onRequest: () => ({ dispose() {} }),
  1071. onClose: () => ({ dispose() {} }),
  1072. };
  1073. }
  1074. disposeAll() {}
  1075. },
  1076. }));
  1077. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  1078. const service = createZCodeAgentService({
  1079. modelSelectionReadinessSource: createReadyModelSelectionSource(),
  1080. });
  1081. await service.readWorkspacePresentation({ workspacePath: "/workspace/app" });
  1082. const readPresentationCall = request.mock.calls.find(
  1083. ([method]) => method === zcodeProtocolMethods.workspaceReadPresentation,
  1084. );
  1085. expect(readPresentationCall?.[1]).toMatchObject({
  1086. workspace: {
  1087. workspacePath: "/workspace/app",
  1088. workspaceKey: "/workspace/app",
  1089. },
  1090. });
  1091. expect(readPresentationCall?.[1]).not.toHaveProperty("model");
  1092. });
  1093. it("workspace presentation 在 stdio 关闭竞态下重新获取 client 并重试一次", async () => {
  1094. const workspacePresentation = {
  1095. workspace: {
  1096. workspacePath: "/workspace/app",
  1097. workspaceKey: "/workspace/app",
  1098. },
  1099. mode: "build",
  1100. slashCommands: [],
  1101. };
  1102. const firstRequest = vi.fn(async (method: string) => {
  1103. if (method === zcodeProtocolMethods.workspaceReadPresentation) {
  1104. throw new Error("ZCode agent stdio transport is closed");
  1105. }
  1106. return {
  1107. workspace: workspacePresentation.workspace,
  1108. status: "applied",
  1109. providerCount: 1,
  1110. };
  1111. });
  1112. const secondRequest = vi.fn(async (method: string) => {
  1113. if (method === zcodeProtocolMethods.workspaceReadPresentation) {
  1114. return workspacePresentation;
  1115. }
  1116. return {
  1117. workspace: workspacePresentation.workspace,
  1118. status: "applied",
  1119. providerCount: 1,
  1120. };
  1121. });
  1122. const getClient = vi
  1123. .fn()
  1124. .mockResolvedValueOnce({
  1125. request: firstRequest,
  1126. transportKind: "stdio",
  1127. onNotification: () => ({ dispose() {} }),
  1128. onRequest: () => ({ dispose() {} }),
  1129. onClose: () => ({ dispose() {} }),
  1130. })
  1131. .mockResolvedValue({
  1132. request: secondRequest,
  1133. transportKind: "stdio",
  1134. onNotification: () => ({ dispose() {} }),
  1135. onRequest: () => ({ dispose() {} }),
  1136. onClose: () => ({ dispose() {} }),
  1137. });
  1138. vi.resetModules();
  1139. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  1140. ZCodeAgentProcessManager: class {
  1141. getClient = getClient;
  1142. // Bug 原因同共享 mock:service 构造期新增 runtime 生命周期订阅;本用例只驱动
  1143. // stdio 重试,因此用空 disposable 补齐局部测试桩契约。
  1144. onRuntimeLifecycle() {
  1145. return { dispose() {} };
  1146. }
  1147. // Bugfix: rebase 后 service 会在构造期订阅 runtime restart;局部 process manager 测试桩
  1148. // 必须保留该接口,否则尚未进入 stdio 重试断言就会因 mock 合约不完整失败。
  1149. onRuntimeRestarted() {
  1150. return { dispose() {} };
  1151. }
  1152. disposeAll() {}
  1153. },
  1154. }));
  1155. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  1156. const service = createZCodeAgentService({
  1157. modelSelectionReadinessSource: createReadyModelSelectionSource(),
  1158. });
  1159. await expect(
  1160. service.readWorkspacePresentation({ workspacePath: "/workspace/app" }),
  1161. ).resolves.toMatchObject(workspacePresentation);
  1162. expect(getClient).toHaveBeenCalledTimes(2);
  1163. expect(firstRequest).toHaveBeenCalledWith(
  1164. zcodeProtocolMethods.workspaceReadPresentation,
  1165. expect.anything(),
  1166. expect.anything(),
  1167. );
  1168. expect(secondRequest).toHaveBeenCalledWith(
  1169. zcodeProtocolMethods.workspaceReadPresentation,
  1170. expect.anything(),
  1171. expect.anything(),
  1172. );
  1173. });
  1174. });