tui-model-selection.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. import assert from "node:assert/strict";
  2. import { test } from "node:test";
  3. import { mkdtemp, readFile, rm } from "node:fs/promises";
  4. import { tmpdir } from "node:os";
  5. import { join } from "node:path";
  6. import type { TurnId } from "@zcode/contracts";
  7. import type { ZCodeAppOptions } from "@zcode/bootstrap";
  8. import {
  9. NodeModelSelectionConfigRepository,
  10. NodePersonalProviderConfigRepository,
  11. } from "@zcode/provider-node";
  12. import { modelSelectionSchema, type ModelSelection, type ZCodeModelOption } from "@zcode/shared";
  13. import { createCommandCenter, type CommandCenterApp } from "../src/command-center.js";
  14. import { handleModelCommand } from "../src/command-center/handlers/model.js";
  15. import { createTuiModelAvailabilityChecker } from "../src/tui-login-state.js";
  16. import { readTuiSessionMetadata } from "../src/tui-prompt-handler-queries.js";
  17. import { filterModelOptions, toPromptInput } from "../../tui/src/app-input.js";
  18. import { completeModelCommand } from "../../tui/src/app-keyboard-helpers.js";
  19. import { resolveComposerSubmittedText } from "../../tui/src/app-submit-resolver.js";
  20. import { submitIdleTurn } from "../../tui/src/app-submit.js";
  21. import type { TuiPromptInput, TuiOptions, TuiSubmitPromptResult } from "../../tui/src/types.js";
  22. import { createTuiSubmitPrompt } from "../src/tui-prompt-handler.js";
  23. import { createCliModeState } from "../src/tui-command-state.js";
  24. import type { RunDependencies } from "../src/cli-types.js";
  25. function model(providerId = "personal", modelId = "vendor/model$literal:free"): ZCodeModelOption {
  26. return {
  27. ref: { providerId, modelId },
  28. label: "Reasoning Model",
  29. providerLabel: "Personal Gateway",
  30. reasoning: {
  31. levels: [
  32. { value: "low", label: "Low" },
  33. { value: "high", label: "High" },
  34. ],
  35. defaultLevel: "high",
  36. },
  37. properties: {
  38. inputFormat: {
  39. supportsText: true,
  40. supportsImage: false,
  41. supportsVideo: false,
  42. supportsAudio: false,
  43. supportsPdf: false,
  44. },
  45. outputFormat: { supportsText: true },
  46. },
  47. };
  48. }
  49. function fixture(initial?: ModelSelection) {
  50. let current = initial;
  51. let catalog = [model()];
  52. const writes: ModelSelection[] = [];
  53. const defaultWrites: ModelSelection[] = [];
  54. const app: Pick<
  55. CommandCenterApp,
  56. | "sessionId"
  57. | "traceId"
  58. | "getModel"
  59. | "getCurrentModelOption"
  60. | "getThoughtLevel"
  61. | "getLocale"
  62. | "listModels"
  63. | "listThoughtLevels"
  64. | "setModel"
  65. | "setThoughtLevel"
  66. > = {
  67. sessionId: "test-session",
  68. traceId: "test-trace",
  69. getModel: () => (current ? `${current.providerId}/${current.modelId}` : ""),
  70. getCurrentModelOption: () =>
  71. catalog.find(
  72. ({ ref }) => ref.providerId === current?.providerId && ref.modelId === current?.modelId,
  73. ),
  74. getThoughtLevel: () => current?.options?.reasoningLevel,
  75. getLocale: () => "en-US",
  76. listModels: () => catalog,
  77. listThoughtLevels: () =>
  78. catalog
  79. .find(
  80. ({ ref }) => ref.providerId === current?.providerId && ref.modelId === current?.modelId,
  81. )
  82. ?.reasoning?.levels.map(({ value }) => value) ?? [],
  83. async setModel(value) {
  84. assert.notEqual(typeof value, "string", "TUI must submit the complete structured selection");
  85. const selection = modelSelectionSchema.parse(value);
  86. assert.ok(selection.options?.reasoningLevel);
  87. writes.push(selection);
  88. const previousModel = app.getModel!()!;
  89. current = selection;
  90. return {
  91. model: app.getModel!()!,
  92. previousModel,
  93. thoughtLevel: selection.options?.reasoningLevel,
  94. };
  95. },
  96. async setThoughtLevel(level) {
  97. assert.ok(current);
  98. assert.ok((await app.listThoughtLevels!()).includes(level), "Unsupported reasoning effort");
  99. current = { ...current, options: { reasoningLevel: level } };
  100. return { thoughtLevel: level };
  101. },
  102. };
  103. const getApp = async () => app as CommandCenterApp;
  104. const deps = {
  105. getApp,
  106. resumeApp: getApp,
  107. hasSelectableModels: createTuiModelAvailabilityChecker(getApp),
  108. saveDefaultModelSelection: async (selection: ModelSelection) => {
  109. defaultWrites.push(selection);
  110. },
  111. };
  112. return {
  113. app: app as CommandCenterApp,
  114. deps,
  115. writes,
  116. defaultWrites,
  117. setCatalog: (next: ZCodeModelOption[]) => {
  118. catalog = next;
  119. },
  120. };
  121. }
  122. test("registry refs support provider search and Tab completion without legacy IDs", () => {
  123. const option = model();
  124. assert.deepEqual(filterModelOptions("/model Personal Gateway", [option]), [option]);
  125. assert.deepEqual(filterModelOptions("/model list", [option]), []);
  126. let completed = "";
  127. completeModelCommand([option], { selectedIndex: 0 }, (value) => {
  128. completed = value;
  129. });
  130. assert.equal(completed, "/model personal/vendor/model$literal:free");
  131. });
  132. test("model list renders the current registry contract", async () => {
  133. const f = fixture();
  134. const result = await handleModelCommand("list", f.deps);
  135. assert.match(result.response, /personal\/vendor\/model\$literal:free/);
  136. assert.match(result.response, /Personal Gateway/);
  137. assert.doesNotMatch(result.response, /undefined|\/model lite/);
  138. assert.equal(result.modelOptions?.length, 1);
  139. assert.equal(f.defaultWrites.length, 0);
  140. });
  141. test("picker reference survives composer submission and selects the catalog reasoning default", async () => {
  142. const f = fixture();
  143. const option = model();
  144. const text = resolveComposerSubmittedText({
  145. modelOption: option,
  146. slashCommands: [],
  147. submittedValue: "/model Personal",
  148. });
  149. let submitted: TuiPromptInput | undefined;
  150. const command = createCommandCenter(f.deps);
  151. const noop = () => {};
  152. await submitIdleTurn({
  153. text,
  154. modelSelection: option.ref,
  155. draftAttachments: [],
  156. turnRef: { current: undefined },
  157. applyResult: noop,
  158. applySessionEvent: noop,
  159. options: {
  160. submitPrompt: async (input, options) => {
  161. submitted = input;
  162. return command(input, options);
  163. },
  164. } as TuiOptions,
  165. setBusy: noop,
  166. setDraftAttachments: noop,
  167. setDraftValue: noop,
  168. setLastError: noop,
  169. setLiveModelText: noop,
  170. setMessages: noop,
  171. setSelection: noop,
  172. setSlashSelection: noop,
  173. setStatus: noop,
  174. setStatusDetails: noop,
  175. });
  176. assert.deepEqual(submitted, toPromptInput(text, [], option.ref));
  177. assert.deepEqual(f.writes, [{ ...option.ref, options: { reasoningLevel: "high" } }]);
  178. assert.deepEqual(f.defaultWrites, f.writes);
  179. });
  180. test("literal model ID wins before parsing a manual reasoning suffix", async () => {
  181. const f = fixture();
  182. await handleModelCommand("personal/vendor/model$literal:free", f.deps);
  183. assert.deepEqual(f.writes[0], { ...model().ref, options: { reasoningLevel: "high" } });
  184. f.setCatalog([model("personal", "plain")]);
  185. await handleModelCommand("personal/plain$low", f.deps);
  186. assert.deepEqual(f.writes[1], {
  187. providerId: "personal",
  188. modelId: "plain",
  189. options: { reasoningLevel: "low" },
  190. });
  191. });
  192. test("invalid reasoning and removed models fail before changing selection", async () => {
  193. const f = fixture();
  194. const invalid = await handleModelCommand("display", f.deps, {
  195. ...model().ref,
  196. options: { reasoningLevel: "invalid" },
  197. });
  198. assert.match(invalid.response, /Unable to switch model/);
  199. f.setCatalog([]);
  200. const removed = await handleModelCommand("display", f.deps, model().ref);
  201. assert.match(removed.response, /not available/);
  202. assert.equal(f.writes.length, 0);
  203. assert.equal(f.defaultWrites.length, 0);
  204. });
  205. test("effort changes persist the same literal model identity and its new reasoning level", async () => {
  206. const f = fixture({ ...model().ref, options: { reasoningLevel: "high" } });
  207. const command = createCommandCenter(f.deps);
  208. const options = { abortSignal: new AbortController().signal };
  209. await command("/effort list", options);
  210. assert.equal(f.defaultWrites.length, 0);
  211. await command("/effort low", options);
  212. assert.deepEqual(f.defaultWrites, [{ ...model().ref, options: { reasoningLevel: "low" } }]);
  213. await command("/variant high", options);
  214. assert.equal(f.defaultWrites.at(-1)?.options?.reasoningLevel, "high");
  215. const invalid = await command("/effort invalid", options);
  216. assert.match(invalid.response, /Unable to switch reasoning effort/);
  217. assert.equal(f.defaultWrites.length, 2);
  218. });
  219. test("preference write failures keep successful model and effort changes visible", async () => {
  220. const f = fixture();
  221. const command = createCommandCenter({
  222. ...f.deps,
  223. saveDefaultModelSelection: async () => {
  224. throw new Error("test configuration write failure");
  225. },
  226. });
  227. const options = { abortSignal: new AbortController().signal };
  228. const selected = await command({ text: "/model selected", modelSelection: model().ref }, options);
  229. assert.match(selected.response, /Model switched to personal\/vendor\/model\$literal:free/);
  230. assert.match(
  231. selected.response,
  232. /could not be saved as the default.*test configuration write failure/,
  233. );
  234. assert.doesNotMatch(selected.response, /Unable to switch model/);
  235. assert.equal(selected.thoughtLevel, "high");
  236. const effort = await command("/effort low", options);
  237. assert.match(effort.response, /Reasoning effort switched to low/);
  238. assert.match(effort.response, /could not be saved as the default/);
  239. assert.doesNotMatch(effort.response, /Unable to switch reasoning effort/);
  240. assert.equal(effort.thoughtLevel, "low");
  241. assert.equal(f.app.getThoughtLevel?.(), "low");
  242. });
  243. test("TUI persists defaults through the shared repository across new sessions and restarts", async (t) => {
  244. const dir = await mkdtemp(join(tmpdir(), "zcode-tui-model-selection-"));
  245. t.after(() => rm(dir, { recursive: true, force: true }));
  246. const filePath = join(dir, "provider_config.json");
  247. const seed = new NodePersonalProviderConfigRepository({ filePath, pollingIntervalMs: false });
  248. await seed.update((current) => ({ ...current, providerOrder: ["personal"] }));
  249. seed.dispose();
  250. const originalFile = JSON.parse(await readFile(filePath, "utf8"));
  251. const created: Array<{ options: ZCodeAppOptions; app: CommandCenterApp }> = [];
  252. const restoredSelection = { ...model().ref, options: { reasoningLevel: "high" } };
  253. let runtimeStarts = 0;
  254. const deps = {
  255. env: {},
  256. cwd: () => dir,
  257. skipUserConfig: true,
  258. loadDotenv: () => ({ keys: [], loaded: false, path: "" }),
  259. createZCodeApp: async (options: ZCodeAppOptions) => {
  260. assert.equal(options.modelSelectionMode, "cli-default");
  261. const f = fixture(
  262. options.resume ? restoredSelection : options.configuredDefaultModelSelection,
  263. );
  264. f.app.resume = async () => ({
  265. appliedMessageCount: 0,
  266. directory: dir,
  267. interruptedToolCount: 0,
  268. messageCount: 0,
  269. partCount: 0,
  270. });
  271. f.app.forkFromCheckpoint = async () => ({ forkedSessionId: "forked", response: "Forked." });
  272. created.push({ options, app: f.app });
  273. return f.app;
  274. },
  275. startProcessProviderRegistryRuntime: async () => {
  276. runtimeStarts++;
  277. const personal = new NodePersonalProviderConfigRepository({
  278. filePath,
  279. pollingIntervalMs: false,
  280. });
  281. const repository = new NodeModelSelectionConfigRepository({ personalRepository: personal });
  282. return {
  283. runtime: { registryService: {} },
  284. modelSelectionConfigRepository: repository,
  285. configuredDefaultModelSelection: await repository.read(),
  286. dispose() {
  287. repository.dispose();
  288. personal.dispose();
  289. },
  290. };
  291. },
  292. } as unknown as RunDependencies;
  293. const options = { abortSignal: new AbortController().signal };
  294. const readFileConfig = async () => JSON.parse(await readFile(filePath, "utf8"));
  295. const handler = createTuiSubmitPrompt(deps, createCliModeState(), "test");
  296. try {
  297. await handler({ text: "/model selected", modelSelection: model().ref }, options);
  298. assert.deepEqual((await readFileConfig()).config.defaultModelSelection, restoredSelection);
  299. const activeTurnResult = await handler.sendInput!("/effort low", {});
  300. assert.equal(activeTurnResult.kind, "command_result");
  301. const expected = { ...model().ref, options: { reasoningLevel: "low" } };
  302. assert.deepEqual((await readFileConfig()).config.defaultModelSelection, expected);
  303. await handler("/new", options);
  304. assert.deepEqual(created.at(-1)?.options.configuredDefaultModelSelection, expected);
  305. assert.equal(created.at(-1)?.app.getThoughtLevel?.(), "low");
  306. assert.equal(
  307. runtimeStarts,
  308. 1,
  309. "new sessions reuse the process runtime and reread its repository",
  310. );
  311. await handler("/resume historical-session", options);
  312. assert.equal(created.at(-1)?.options.resume, true);
  313. assert.equal(created.at(-1)?.options.runtimeConfig?.modelSelection, undefined);
  314. assert.equal(created.at(-1)?.app.getThoughtLevel?.(), "high");
  315. await handler("/fork", options);
  316. assert.equal(created.at(-1)?.options.sessionId, "forked");
  317. assert.deepEqual((await readFileConfig()).config.defaultModelSelection, expected);
  318. const { defaultModelSelection: _selection, ...preservedConfig } = (await readFileConfig())
  319. .config;
  320. assert.deepEqual(preservedConfig, originalFile.config);
  321. } finally {
  322. await handler.close?.();
  323. }
  324. const restarted = createTuiSubmitPrompt(deps, createCliModeState(), "test");
  325. try {
  326. const metadata = await restarted.getSessionMetadata!();
  327. assert.equal(metadata.model, "personal/vendor/model$literal:free");
  328. assert.equal(metadata.thoughtLevel, "low");
  329. assert.equal(runtimeStarts, 2, "restart opens a new repository instance");
  330. } finally {
  331. await restarted.close?.();
  332. }
  333. });
  334. test("fresh metadata follows the registry without requiring Coding Plan credentials", async () => {
  335. const f = fixture();
  336. const hasModels = createTuiModelAvailabilityChecker(f.deps.getApp);
  337. assert.equal(await hasModels(), true);
  338. const ready = await readTuiSessionMetadata(f.app);
  339. assert.equal(ready.loginRequired, false);
  340. assert.equal(ready.modelOptions?.length, 1);
  341. f.setCatalog([]);
  342. assert.equal(await hasModels(), false);
  343. assert.deepEqual((await readTuiSessionMetadata(f.app)).modelOptions, []);
  344. });
  345. test("restoring incomplete reasoning does not fill a default or retain the previous effort", async () => {
  346. const f = fixture(model().ref);
  347. const metadata = await readTuiSessionMetadata(f.app);
  348. assert.equal(metadata.thoughtLevel, undefined);
  349. assert.equal(Object.hasOwn(metadata, "thoughtLevel"), true);
  350. assert.deepEqual(
  351. metadata.effortOptions?.map(({ id }) => id),
  352. ["low", "high"],
  353. );
  354. assert.equal(f.writes.length, 0);
  355. });
  356. test("personal providers can submit prompts without a Coding Plan login", async () => {
  357. const f = fixture();
  358. let submitted = false;
  359. f.app.submitPrompt = async () => {
  360. submitted = true;
  361. return { response: "ok" };
  362. };
  363. const result = await createCommandCenter(f.deps)("hello", {
  364. abortSignal: new AbortController().signal,
  365. });
  366. assert.equal(submitted, true);
  367. assert.equal(result.response, "ok");
  368. });
  369. test("active-turn model picks use the same configuration command instead of becoming model input", async () => {
  370. const f = fixture();
  371. let forwarded = false;
  372. f.app.sendInput = async () => {
  373. forwarded = true;
  374. throw new Error("Model command forwarded to Agent");
  375. };
  376. const deps = {
  377. env: {},
  378. cwd: () => process.cwd(),
  379. skipUserConfig: true,
  380. loadDotenv: () => ({ keys: [], loaded: false, path: "" }),
  381. createZCodeApp: async () => f.app,
  382. startProcessProviderRegistryRuntime: async () => ({
  383. runtime: { registryService: {} },
  384. modelSelectionConfigRepository: {
  385. read: async () => undefined,
  386. saveConfiguredDefault: f.deps.saveDefaultModelSelection,
  387. },
  388. dispose() {},
  389. }),
  390. } as unknown as RunDependencies;
  391. const handler = createTuiSubmitPrompt(deps, createCliModeState(), "test");
  392. try {
  393. const result = await handler.sendInput!(
  394. { text: "/model display", modelSelection: model().ref },
  395. {},
  396. );
  397. assert.equal(forwarded, false);
  398. assert.equal(result.kind, "command_result");
  399. assert.deepEqual(f.writes, [{ ...model().ref, options: { reasoningLevel: "high" } }]);
  400. assert.deepEqual(f.defaultWrites, f.writes);
  401. await handler.sendInput!("/effort low", {});
  402. assert.equal(forwarded, false);
  403. assert.equal(f.app.getThoughtLevel?.(), "low");
  404. assert.deepEqual(f.defaultWrites.at(-1), {
  405. ...model().ref,
  406. options: { reasoningLevel: "low" },
  407. });
  408. } finally {
  409. await handler.close?.();
  410. }
  411. });
  412. test("terminal picker refreshes an empty catalog and switches model and effort with keyboard input", async () => {
  413. const React = await import("react");
  414. const { createTestRenderer } = await import("@mbears/opentui-core/testing");
  415. const { createRoot } = await import("@mbears/opentui-react");
  416. const { TuiApp } = await import("../../tui/src/app.js");
  417. const reactEnvironment = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
  418. const previousActEnvironment = reactEnvironment.IS_REACT_ACT_ENVIRONMENT;
  419. reactEnvironment.IS_REACT_ACT_ENVIRONMENT = true;
  420. const f = fixture();
  421. const terminal = await createTestRenderer({
  422. width: 110,
  423. height: 32,
  424. targetFps: 30,
  425. screenMode: "alternate-screen",
  426. useThread: false,
  427. });
  428. const root = createRoot(terminal.renderer);
  429. let finishTurn: ((result: TuiSubmitPromptResult) => void) | undefined;
  430. const options: TuiOptions = {
  431. noColor: true,
  432. stdin: process.stdin,
  433. stdout: process.stdout,
  434. stderr: process.stderr,
  435. initialModel: "old/model",
  436. initialThoughtLevel: "low",
  437. locale: "en-US",
  438. modelOptions: [],
  439. listModelOptions: async () => f.app.listModels!(),
  440. submitPrompt: async (input, options) => {
  441. const text = typeof input === "string" ? input : input.text;
  442. if (text === "work")
  443. return new Promise((resolve) => {
  444. finishTurn = resolve;
  445. });
  446. if (text === "/resume incomplete") {
  447. return {
  448. ...(await readTuiSessionMetadata(fixture(model().ref).app)),
  449. response: "Restored incomplete session.",
  450. };
  451. }
  452. return createCommandCenter(f.deps)(input, options);
  453. },
  454. sendInput: async (input, options) => {
  455. const text = typeof input === "string" ? input : input.text;
  456. if (text.startsWith("/")) {
  457. return {
  458. kind: "command_result",
  459. result: await createCommandCenter(f.deps)(input, {
  460. ...options,
  461. abortSignal: options.abortSignal ?? new AbortController().signal,
  462. }),
  463. };
  464. }
  465. return {
  466. kind: "queued",
  467. pendingInputId: "queued-input",
  468. queueLength: 1,
  469. turnId: "test-turn" as TurnId,
  470. };
  471. },
  472. };
  473. const action = async (run: () => void | Promise<void>) => {
  474. await React.act(async () => {
  475. await run();
  476. });
  477. await terminal.renderOnce();
  478. };
  479. try {
  480. await action(() =>
  481. root.render(
  482. React.createElement(TuiApp, {
  483. options,
  484. onExit() {},
  485. hasCopyableSelection: () => false,
  486. copySelection: async () => ({ kind: "empty" as const }),
  487. }),
  488. ),
  489. );
  490. await action(() => terminal.mockInput.typeText("/model Personal Gateway"));
  491. assert.match(terminal.captureCharFrame(), /Reasoning Model/);
  492. assert.match(terminal.captureCharFrame(), /Personal Gateway/);
  493. await action(() => terminal.mockInput.pressEnter());
  494. assert.deepEqual(f.writes[0], { ...model().ref, options: { reasoningLevel: "high" } });
  495. assert.match(terminal.captureCharFrame(), /personal \| high/);
  496. await action(() => terminal.mockInput.typeText("/effort low"));
  497. await action(() => terminal.mockInput.pressEnter());
  498. assert.equal(f.app.getThoughtLevel?.(), "low");
  499. assert.match(terminal.captureCharFrame(), /personal \| low/);
  500. const replacement = {
  501. ...model("replacement", "next"),
  502. label: "Replacement Model",
  503. providerLabel: "Replacement Gateway",
  504. };
  505. f.setCatalog([replacement]);
  506. await action(() => terminal.mockInput.typeText("/model Replacement"));
  507. assert.match(terminal.captureCharFrame(), /Replacement Model/);
  508. await action(() => terminal.mockInput.pressTab());
  509. assert.match(terminal.captureCharFrame(), /\/model replacement\/next/);
  510. await action(() => terminal.mockInput.pressEnter());
  511. assert.deepEqual(f.writes[1], { ...replacement.ref, options: { reasoningLevel: "high" } });
  512. await action(() => terminal.mockInput.typeText("/resume incomplete"));
  513. await action(() => terminal.mockInput.pressEnter());
  514. assert.match(terminal.captureCharFrame(), /personal \| -/);
  515. await action(() => terminal.mockInput.typeText("work"));
  516. await action(() => terminal.mockInput.pressEnter());
  517. await action(() => terminal.mockInput.typeText("queued instruction"));
  518. await action(() => terminal.mockInput.pressEnter());
  519. assert.match(terminal.captureCharFrame(), /queued instruction/);
  520. await action(() => terminal.mockInput.typeText("/model Replacement"));
  521. await action(() => terminal.mockInput.pressEnter());
  522. assert.match(terminal.captureCharFrame(), /queued instruction/);
  523. assert.match(terminal.captureCharFrame(), /replacement \| high/);
  524. await action(() => terminal.mockInput.typeText("/effort low"));
  525. await action(() => terminal.mockInput.pressEnter());
  526. assert.match(terminal.captureCharFrame(), /queued instruction/);
  527. assert.match(terminal.captureCharFrame(), /replacement \| low/);
  528. await action(async () => {
  529. finishTurn?.({ response: "Work completed." });
  530. });
  531. } finally {
  532. await React.act(() => root.unmount());
  533. terminal.renderer.destroy();
  534. if (previousActEnvironment === undefined) delete reactEnvironment.IS_REACT_ACT_ENVIRONMENT;
  535. else reactEnvironment.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment;
  536. }
  537. });