Skip to content

Commit 764bd13

Browse files
salman1993codex
andcommitted
Restore model browsing after connection tests
Update the Pi native IPC fixture for verified model selection and retain the rejected-key check. Co-authored-by: Codex <[email protected]> Signed-off-by: Salman Mohammed <[email protected]>
1 parent a7e6dff commit 764bd13

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎src-tauri/src/agents/tests.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,23 @@ fn pi_connection_test_prompts_the_draft_selection() {
22612261
std::fs::create_dir(&tools).unwrap();
22622262
for tool in ["pi", "node", "buzz-pi-acp"] {
22632263
let file = tools.join(tool);
2264-
std::fs::write(&file, "#!/bin/sh\nif [ \"$1\" = --version ]; then printf '0.99.1\\n'; exit 0; fi\nread request\ncase \"$*\" in *'--model model-a'*) stop=stop;; *) stop=error;; esac\nprintf '{\"type\":\"message_end\",\"message\":{\"role\":\"assistant\",\"stopReason\":\"%s\",\"errorMessage\":\"401\"}}\\n' \"$stop\"\n").unwrap();
2264+
std::fs::write(
2265+
&file,
2266+
r#"#!/bin/sh
2267+
if [ "$1" = --version ]; then printf '0.99.1\n'; exit 0; fi
2268+
case "$*" in
2269+
*'--model databricks/model-a'*) model=model-a; stop=stop; error='';;
2270+
*'--model databricks/model-b'*) model=model-b; stop=error; error=401;;
2271+
*) exit 1;;
2272+
esac
2273+
read request
2274+
case "$request" in *get_state*) ;; *) exit 1;; esac
2275+
printf '{"id":"selection","type":"response","command":"get_state","success":true,"data":{"model":{"provider":"databricks","id":"%s"}}}\n' "$model"
2276+
read request
2277+
case "$request" in *prompt*) ;; *) exit 1;; esac
2278+
printf '{"type":"message_end","message":{"role":"assistant","provider":"databricks","model":"%s","content":[{"type":"text","text":"OK"}],"stopReason":"%s","errorMessage":"%s"}}\n' "$model" "$stop" "$error"
2279+
"#,
2280+
).unwrap();
22652281
std::fs::set_permissions(file, std::fs::Permissions::from_mode(0o700)).unwrap();
22662282
}
22672283
let test = |model: &str| {
@@ -2278,7 +2294,9 @@ fn pi_connection_test_prompts_the_draft_selection() {
22782294
}}),
22792295
)
22802296
};
2281-
assert_eq!(test("model-a").unwrap()["models"], json!([]));
2297+
let result = test("model-a").unwrap();
2298+
assert_eq!(result["models"], json!([]));
2299+
assert_eq!(result["testedModel"], "databricks/model-a");
22822300
let error = test("model-b").unwrap_err();
22832301
assert!(
22842302
error.as_str().unwrap().contains("rejected the API key"),

‎src/bundled/agents/AgentModelPicker.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export function AgentModelPicker({
135135
if (!control.models || testing.current) return;
136136
pending.current?.abort();
137137
pending.current = null;
138+
attempted.current = null;
138139
setBusy(false);
139140
setStatus("");
140141
setOpen(false);

‎src/bundled/agents/AgentSettingsFields.test.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ it.each([
803803
["Pi", "/local/buzz-pi-acp"],
804804
["Goose", "/local/goose"],
805805
])(
806-
"tests a %s provider below its API key before choosing a model without changing the draft",
806+
"tests a %s provider before choosing a model and can browse again after cancelling lookup",
807807
async (label, command) => {
808808
const f = controlFixture();
809809
f.data.harnessOptions = [
@@ -816,7 +816,7 @@ it.each([
816816
];
817817
const catalog: ModelCatalog = {
818818
host: "",
819-
models: [],
819+
models: [{ id: "openai/gpt", name: "Test model" }],
820820
modelOverridden: false,
821821
disconnected: false,
822822
};
@@ -856,10 +856,8 @@ it.each([
856856
const button = screen.getByRole("button", { name: "Test connection" });
857857
const key = screen.getByLabelText("OpenAI API key");
858858
const model = screen.getByRole("combobox", { name: "Model" });
859-
if (label === "Goose")
860-
await userEvent
861-
.setup()
862-
.click(screen.getByRole("button", { name: "Browse models" }));
859+
const browse = screen.getByRole("button", { name: "Browse models" });
860+
if (label === "Goose") await userEvent.setup().click(browse);
863861
await waitFor(() => expect(run).toHaveBeenCalledTimes(1));
864862
expect(model).toHaveAttribute("aria-busy", "true");
865863
expect(button).toBeEnabled();
@@ -887,6 +885,17 @@ it.each([
887885
expect(model).toHaveValue("");
888886
expect(model).not.toHaveAttribute("aria-busy", "true");
889887
expect(onChange).not.toHaveBeenCalled();
888+
await userEvent.setup().click(browse);
889+
await waitFor(() => expect(run).toHaveBeenCalledTimes(3));
890+
expect(
891+
await screen.findByRole("option", { name: /Test model/ }),
892+
).toBeVisible();
893+
expect(run).toHaveBeenLastCalledWith(
894+
1,
895+
expect.objectContaining({ action: "connect" }),
896+
);
897+
expect(model).toHaveValue("");
898+
expect(onChange).not.toHaveBeenCalled();
890899
} finally {
891900
releaseLookup();
892901
view.unmount();

0 commit comments

Comments
 (0)