tui-model-selection.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. requestPermission: async () => {
  160. throw new Error("No permissions requested by model selection");
  161. },
  162. options: {
  163. submitPrompt: async (input, options) => {
  164. submitted = input;
  165. return command(input, options);
  166. },
  167. } as TuiOptions,
  168. setBusy: noop,
  169. setDraftAttachments: noop,
  170. setDraftValue: noop,
  171. setLastError: noop,
  172. setLiveModelText: noop,
  173. setMessages: noop,
  174. setSelection: noop,
  175. setSlashSelection: noop,
  176. setStatus: noop,
  177. setStatusDetails: noop,
  178. });
  179. assert.deepEqual(submitted, toPromptInput(text, [], option.ref));
  180. assert.deepEqual(f.writes, [{ ...option.ref, options: { reasoningLevel: "high" } }]);
  181. assert.deepEqual(f.defaultWrites, f.writes);
  182. });
  183. test("literal model ID wins before parsing a manual reasoning suffix", async () => {
  184. const f = fixture();
  185. await handleModelCommand("personal/vendor/model$literal:free", f.deps);
  186. assert.deepEqual(f.writes[0], { ...model().ref, options: { reasoningLevel: "high" } });
  187. f.setCatalog([model("personal", "plain")]);
  188. await handleModelCommand("personal/plain$low", f.deps);
  189. assert.deepEqual(f.writes[1], {
  190. providerId: "personal",
  191. modelId: "plain",
  192. options: { reasoningLevel: "low" },
  193. });
  194. });
  195. test("invalid reasoning and removed models fail before changing selection", async () => {
  196. const f = fixture();
  197. const invalid = await handleModelCommand("display", f.deps, {
  198. ...model().ref,
  199. options: { reasoningLevel: "invalid" },
  200. });
  201. assert.match(invalid.response, /Unable to switch model/);
  202. f.setCatalog([]);
  203. const removed = await handleModelCommand("display", f.deps, model().ref);
  204. assert.match(removed.response, /not available/);
  205. assert.equal(f.writes.length, 0);
  206. assert.equal(f.defaultWrites.length, 0);
  207. });
  208. test("effort changes persist the same literal model identity and its new reasoning level", async () => {
  209. const f = fixture({ ...model().ref, options: { reasoningLevel: "high" } });
  210. const command = createCommandCenter(f.deps);
  211. const options = { abortSignal: new AbortController().signal };
  212. await command("/effort list", options);
  213. assert.equal(f.defaultWrites.length, 0);
  214. await command("/effort low", options);
  215. assert.deepEqual(f.defaultWrites, [{ ...model().ref, options: { reasoningLevel: "low" } }]);
  216. await command("/variant high", options);
  217. assert.equal(f.defaultWrites.at(-1)?.options?.reasoningLevel, "high");
  218. const invalid = await command("/effort invalid", options);
  219. assert.match(invalid.response, /Unable to switch reasoning effort/);
  220. assert.equal(f.defaultWrites.length, 2);
  221. });
  222. test("preference write failures keep successful model and effort changes visible", async () => {
  223. const f = fixture();
  224. const command = createCommandCenter({
  225. ...f.deps,
  226. saveDefaultModelSelection: async () => {
  227. throw new Error("test configuration write failure");
  228. },
  229. });
  230. const options = { abortSignal: new AbortController().signal };
  231. const selected = await command({ text: "/model selected", modelSelection: model().ref }, options);
  232. assert.match(selected.response, /Model switched to personal\/vendor\/model\$literal:free/);
  233. assert.match(
  234. selected.response,
  235. /could not be saved as the default.*test configuration write failure/,
  236. );
  237. assert.doesNotMatch(selected.response, /Unable to switch model/);
  238. assert.equal(selected.thoughtLevel, "high");
  239. const effort = await command("/effort low", options);
  240. assert.match(effort.response, /Reasoning effort switched to low/);
  241. assert.match(effort.response, /could not be saved as the default/);
  242. assert.doesNotMatch(effort.response, /Unable to switch reasoning effort/);
  243. assert.equal(effort.thoughtLevel, "low");
  244. assert.equal(f.app.getThoughtLevel?.(), "low");
  245. });
  246. test("TUI persists defaults through the shared repository across new sessions and restarts", async (t) => {
  247. const dir = await mkdtemp(join(tmpdir(), "zcode-tui-model-selection-"));
  248. t.after(() => rm(dir, { recursive: true, force: true }));
  249. const filePath = join(dir, "provider_config.json");
  250. const seed = new NodePersonalProviderConfigRepository({ filePath, pollingIntervalMs: false });
  251. await seed.update((current) => ({ ...current, providerOrder: ["personal"] }));
  252. seed.dispose();
  253. const originalFile = JSON.parse(await readFile(filePath, "utf8"));
  254. const created: Array<{ options: ZCodeAppOptions; app: CommandCenterApp }> = [];
  255. const restoredSelection = { ...model().ref, options: { reasoningLevel: "high" } };
  256. let runtimeStarts = 0;
  257. const deps = {
  258. env: {},
  259. cwd: () => dir,
  260. skipUserConfig: true,
  261. loadDotenv: () => ({ keys: [], loaded: false, path: "" }),
  262. createZCodeApp: async (options: ZCodeAppOptions) => {
  263. const f = fixture(
  264. options.resume ? restoredSelection : options.configuredDefaultModelSelection,
  265. );
  266. f.app.resume = async () => ({
  267. appliedMessageCount: 0,
  268. directory: dir,
  269. interruptedToolCount: 0,
  270. messageCount: 0,
  271. partCount: 0,
  272. });
  273. f.app.forkFromCheckpoint = async () => ({ forkedSessionId: "forked", response: "Forked." });
  274. created.push({ options, app: f.app });
  275. return f.app;
  276. },
  277. startProcessProviderRegistryRuntime: async () => {
  278. runtimeStarts++;
  279. const personal = new NodePersonalProviderConfigRepository({
  280. filePath,
  281. pollingIntervalMs: false,
  282. });
  283. const repository = new NodeModelSelectionConfigRepository({ personalRepository: personal });
  284. return {
  285. runtime: { registryService: {} },
  286. modelSelectionConfigRepository: repository,
  287. configuredDefaultModelSelection: await repository.read(),
  288. dispose() {
  289. repository.dispose();
  290. personal.dispose();
  291. },
  292. };
  293. },
  294. } as unknown as RunDependencies;
  295. const options = { abortSignal: new AbortController().signal };
  296. const readFileConfig = async () => JSON.parse(await readFile(filePath, "utf8"));
  297. const handler = createTuiSubmitPrompt(deps, createCliModeState(), "test");
  298. try {
  299. await handler({ text: "/model selected", modelSelection: model().ref }, options);
  300. assert.deepEqual((await readFileConfig()).config.defaultModelSelection, restoredSelection);
  301. const activeTurnResult = await handler.sendInput!("/effort low", {});
  302. assert.equal(activeTurnResult.kind, "command_result");
  303. const expected = { ...model().ref, options: { reasoningLevel: "low" } };
  304. assert.deepEqual((await readFileConfig()).config.defaultModelSelection, expected);
  305. await handler("/new", options);
  306. assert.deepEqual(created.at(-1)?.options.configuredDefaultModelSelection, expected);
  307. assert.equal(created.at(-1)?.app.getThoughtLevel?.(), "low");
  308. assert.equal(
  309. runtimeStarts,
  310. 1,
  311. "new sessions reuse the process runtime and reread its repository",
  312. );
  313. await handler("/resume historical-session", options);
  314. assert.equal(created.at(-1)?.options.resume, true);
  315. assert.equal(created.at(-1)?.options.runtimeConfig?.modelSelection, undefined);
  316. assert.equal(created.at(-1)?.app.getThoughtLevel?.(), "high");
  317. await handler("/fork", options);
  318. assert.equal(created.at(-1)?.options.sessionId, "forked");
  319. assert.deepEqual((await readFileConfig()).config.defaultModelSelection, expected);
  320. const { defaultModelSelection: _selection, ...preservedConfig } = (await readFileConfig())
  321. .config;
  322. assert.deepEqual(preservedConfig, originalFile.config);
  323. } finally {
  324. await handler.close?.();
  325. }
  326. const restarted = createTuiSubmitPrompt(deps, createCliModeState(), "test");
  327. try {
  328. const metadata = await restarted.getSessionMetadata!();
  329. assert.equal(metadata.model, "personal/vendor/model$literal:free");
  330. assert.equal(metadata.thoughtLevel, "low");
  331. assert.equal(runtimeStarts, 2, "restart opens a new repository instance");
  332. } finally {
  333. await restarted.close?.();
  334. }
  335. });
  336. test("fresh metadata follows the registry without requiring Coding Plan credentials", async () => {
  337. const f = fixture();
  338. const hasModels = createTuiModelAvailabilityChecker(f.deps.getApp);
  339. assert.equal(await hasModels(), true);
  340. const ready = await readTuiSessionMetadata(f.app);
  341. assert.equal(ready.loginRequired, false);
  342. assert.equal(ready.modelOptions?.length, 1);
  343. f.setCatalog([]);
  344. assert.equal(await hasModels(), false);
  345. assert.deepEqual((await readTuiSessionMetadata(f.app)).modelOptions, []);
  346. });
  347. test("restoring incomplete reasoning does not fill a default or retain the previous effort", async () => {
  348. const f = fixture(model().ref);
  349. const metadata = await readTuiSessionMetadata(f.app);
  350. assert.equal(metadata.thoughtLevel, undefined);
  351. assert.equal(Object.hasOwn(metadata, "thoughtLevel"), true);
  352. assert.deepEqual(
  353. metadata.effortOptions?.map(({ id }) => id),
  354. ["low", "high"],
  355. );
  356. assert.equal(f.writes.length, 0);
  357. });
  358. test("personal providers can submit prompts without a Coding Plan login", async () => {
  359. const f = fixture();
  360. let submitted = false;
  361. f.app.submitPrompt = async () => {
  362. submitted = true;
  363. return { response: "ok" };
  364. };
  365. const result = await createCommandCenter(f.deps)("hello", {
  366. abortSignal: new AbortController().signal,
  367. });
  368. assert.equal(submitted, true);
  369. assert.equal(result.response, "ok");
  370. });
  371. test("active-turn model picks use the same configuration command instead of becoming model input", async () => {
  372. const f = fixture();
  373. let forwarded = false;
  374. f.app.sendInput = async () => {
  375. forwarded = true;
  376. throw new Error("Model command forwarded to Agent");
  377. };
  378. const deps = {
  379. env: {},
  380. cwd: () => process.cwd(),
  381. skipUserConfig: true,
  382. loadDotenv: () => ({ keys: [], loaded: false, path: "" }),
  383. createZCodeApp: async () => f.app,
  384. startProcessProviderRegistryRuntime: async () => ({
  385. runtime: { registryService: {} },
  386. modelSelectionConfigRepository: {
  387. read: async () => undefined,
  388. saveConfiguredDefault: f.deps.saveDefaultModelSelection,
  389. },
  390. dispose() {},
  391. }),
  392. } as unknown as RunDependencies;
  393. const handler = createTuiSubmitPrompt(deps, createCliModeState(), "test");
  394. try {
  395. const result = await handler.sendInput!(
  396. { text: "/model display", modelSelection: model().ref },
  397. {},
  398. );
  399. assert.equal(forwarded, false);
  400. assert.equal(result.kind, "command_result");
  401. assert.deepEqual(f.writes, [{ ...model().ref, options: { reasoningLevel: "high" } }]);
  402. assert.deepEqual(f.defaultWrites, f.writes);
  403. await handler.sendInput!("/effort low", {});
  404. assert.equal(forwarded, false);
  405. assert.equal(f.app.getThoughtLevel?.(), "low");
  406. assert.deepEqual(f.defaultWrites.at(-1), {
  407. ...model().ref,
  408. options: { reasoningLevel: "low" },
  409. });
  410. } finally {
  411. await handler.close?.();
  412. }
  413. });
  414. test("terminal picker refreshes an empty catalog and switches model and effort with keyboard input", async () => {
  415. const React = await import("react");
  416. const { createTestRenderer } = await import("@mbears/opentui-core/testing");
  417. const { createRoot } = await import("@mbears/opentui-react");
  418. const { TuiApp } = await import("../../tui/src/app.js");
  419. const reactEnvironment = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
  420. const previousActEnvironment = reactEnvironment.IS_REACT_ACT_ENVIRONMENT;
  421. reactEnvironment.IS_REACT_ACT_ENVIRONMENT = true;
  422. const f = fixture();
  423. const terminal = await createTestRenderer({
  424. width: 110,
  425. height: 32,
  426. targetFps: 30,
  427. screenMode: "alternate-screen",
  428. useThread: false,
  429. });
  430. const root = createRoot(terminal.renderer);
  431. let finishTurn: ((result: TuiSubmitPromptResult) => void) | undefined;
  432. const options: TuiOptions = {
  433. noColor: true,
  434. stdin: process.stdin,
  435. stdout: process.stdout,
  436. stderr: process.stderr,
  437. initialModel: "old/model",
  438. initialThoughtLevel: "low",
  439. locale: "en-US",
  440. modelOptions: [],
  441. listModelOptions: async () => f.app.listModels!(),
  442. submitPrompt: async (input, options) => {
  443. const text = typeof input === "string" ? input : input.text;
  444. if (text === "work")
  445. return new Promise((resolve) => {
  446. finishTurn = resolve;
  447. });
  448. if (text === "/resume incomplete") {
  449. return {
  450. ...(await readTuiSessionMetadata(fixture(model().ref).app)),
  451. response: "Restored incomplete session.",
  452. };
  453. }
  454. return createCommandCenter(f.deps)(input, options);
  455. },
  456. sendInput: async (input, options) => {
  457. const text = typeof input === "string" ? input : input.text;
  458. if (text.startsWith("/")) {
  459. return {
  460. kind: "command_result",
  461. result: await createCommandCenter(f.deps)(input, {
  462. ...options,
  463. abortSignal: options.abortSignal ?? new AbortController().signal,
  464. }),
  465. };
  466. }
  467. return {
  468. kind: "queued",
  469. pendingInputId: "queued-input",
  470. queueLength: 1,
  471. turnId: "test-turn" as TurnId,
  472. };
  473. },
  474. };
  475. const action = async (run: () => void | Promise<void>) => {
  476. await React.act(async () => {
  477. await run();
  478. });
  479. await terminal.renderOnce();
  480. };
  481. try {
  482. await action(() =>
  483. root.render(
  484. React.createElement(TuiApp, {
  485. options,
  486. onExit() {},
  487. hasCopyableSelection: () => false,
  488. copySelection: async () => ({ kind: "empty" as const }),
  489. }),
  490. ),
  491. );
  492. await action(() => terminal.mockInput.typeText("/model Personal Gateway"));
  493. assert.match(terminal.captureCharFrame(), /Reasoning Model/);
  494. assert.match(terminal.captureCharFrame(), /Personal Gateway/);
  495. await action(() => terminal.mockInput.pressEnter());
  496. assert.deepEqual(f.writes[0], { ...model().ref, options: { reasoningLevel: "high" } });
  497. assert.match(terminal.captureCharFrame(), /personal \| high/);
  498. await action(() => terminal.mockInput.typeText("/effort low"));
  499. await action(() => terminal.mockInput.pressEnter());
  500. assert.equal(f.app.getThoughtLevel?.(), "low");
  501. assert.match(terminal.captureCharFrame(), /personal \| low/);
  502. const replacement = {
  503. ...model("replacement", "next"),
  504. label: "Replacement Model",
  505. providerLabel: "Replacement Gateway",
  506. };
  507. f.setCatalog([replacement]);
  508. await action(() => terminal.mockInput.typeText("/model Replacement"));
  509. assert.match(terminal.captureCharFrame(), /Replacement Model/);
  510. await action(() => terminal.mockInput.pressTab());
  511. assert.match(terminal.captureCharFrame(), /\/model replacement\/next/);
  512. await action(() => terminal.mockInput.pressEnter());
  513. assert.deepEqual(f.writes[1], { ...replacement.ref, options: { reasoningLevel: "high" } });
  514. await action(() => terminal.mockInput.typeText("/resume incomplete"));
  515. await action(() => terminal.mockInput.pressEnter());
  516. assert.match(terminal.captureCharFrame(), /personal \| -/);
  517. await action(() => terminal.mockInput.typeText("work"));
  518. await action(() => terminal.mockInput.pressEnter());
  519. await action(() => terminal.mockInput.typeText("queued instruction"));
  520. await action(() => terminal.mockInput.pressEnter());
  521. assert.match(terminal.captureCharFrame(), /queued instruction/);
  522. await action(() => terminal.mockInput.typeText("/model Replacement"));
  523. await action(() => terminal.mockInput.pressEnter());
  524. assert.match(terminal.captureCharFrame(), /queued instruction/);
  525. assert.match(terminal.captureCharFrame(), /replacement \| high/);
  526. await action(() => terminal.mockInput.typeText("/effort low"));
  527. await action(() => terminal.mockInput.pressEnter());
  528. assert.match(terminal.captureCharFrame(), /queued instruction/);
  529. assert.match(terminal.captureCharFrame(), /replacement \| low/);
  530. await action(async () => {
  531. finishTurn?.({ response: "Work completed." });
  532. });
  533. } finally {
  534. await React.act(() => root.unmount());
  535. terminal.renderer.destroy();
  536. if (previousActEnvironment === undefined) delete reactEnvironment.IS_REACT_ACT_ENVIRONMENT;
  537. else reactEnvironment.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment;
  538. }
  539. });