MCPcopy
hub / github.com/coder/mux / selectModel

Function selectModel

tests/ui/agents/thinkingPersistence.test.ts:39–101  ·  view source on GitHub ↗
(
  container: HTMLElement,
  workspaceId: string,
  model: string
)

Source from the content-addressed store, hash-verified

37}
38
39async function selectModel(
40 container: HTMLElement,
41 workspaceId: string,
42 model: string
43): Promise<void> {
44 const input = await openModelSelector(container);
45
46 const user = userEvent.setup({ document: container.ownerDocument });
47 await user.clear(input);
48 await user.type(input, model);
49
50 const modelName = model.split(":")[1] ?? model;
51 const modelDisplayName = formatModelDisplayName(modelName);
52
53 const option = await waitFor(() => {
54 const match = within(container).getByText(modelDisplayName);
55 if (!match) {
56 throw new Error("Model option not found");
57 }
58 return match;
59 });
60
61 fireEvent.click(option);
62
63 await waitFor(() => {
64 const persisted = readPersistedState(getModelKey(workspaceId), "");
65 if (persisted !== model) {
66 throw new Error(`Expected model ${model} but got ${persisted}`);
67 }
68 });
69
70 // Wait for the UI to reflect the new model. This guards against race conditions
71 // where backend metadata updates can temporarily revert localStorage (and thus
72 // the displayed model) when switching models rapidly.
73 // Use the exact display name that the UI will show.
74 const expectedDisplayName = modelDisplayName.toLowerCase();
75 await waitFor(
76 () => {
77 const modelGroup = container.querySelector('[data-component="ModelSelectorGroup"]');
78 const displayedModel = (modelGroup?.textContent ?? "").toLowerCase();
79 if (!displayedModel.includes(expectedDisplayName)) {
80 throw new Error(
81 `Waiting for UI to show "${expectedDisplayName}", currently shows "${displayedModel}"`
82 );
83 }
84 },
85 { timeout: 3000 }
86 );
87
88 // Wait for UI to stabilize - ensure thinking controls are present and not in flux.
89 // Backend metadata updates can cause re-renders; waiting for a stable state
90 // prevents races when the test immediately interacts with thinking controls.
91 await waitFor(
92 () => {
93 const group = container.querySelector('[data-component="ThinkingSliderGroup"]');
94 const thinkingLabel = group?.querySelector("[data-thinking-label]");
95 if (!thinkingLabel?.textContent) {
96 throw new Error("Waiting for thinking controls to stabilize");

Callers 1

Calls 7

formatModelDisplayNameFunction · 0.90
readPersistedStateFunction · 0.90
getModelKeyFunction · 0.90
openModelSelectorFunction · 0.85
setupMethod · 0.80
waitForFunction · 0.50
clearMethod · 0.45

Tested by

no test coverage detected