|
2 | 2 | import "@testing-library/jest-dom/vitest"; |
3 | 3 | import { useState } from "react"; |
4 | 4 | import { afterEach, expect, it, vi } from "vitest"; |
5 | | -import { cleanup, render, screen, waitFor } from "@testing-library/react"; |
| 5 | +import { act, cleanup, render, screen, waitFor } from "@testing-library/react"; |
6 | 6 | import userEvent from "@testing-library/user-event"; |
7 | 7 | import { AgentSettingsFields } from "./AgentSettingsFields"; |
8 | 8 | import { agentDraft, agentEdit, type AgentDraft } from "./agent-edit"; |
@@ -572,6 +572,93 @@ it("uses a masked OpenAI key for Goose model lookup and discards unsaved keys on |
572 | 572 | } |
573 | 573 | }); |
574 | 574 |
|
| 575 | +it("does not replay a failed Goose provider choice after a preset custom-path round trip", async () => { |
| 576 | + const fixture = controlFixture(); |
| 577 | + fixture.data.harnessOptions = [ |
| 578 | + { |
| 579 | + command: "/usr/local/bin/goose-acp", |
| 580 | + label: "Goose", |
| 581 | + defaultArgs: ["acp"], |
| 582 | + providers: [{ value: "anthropic", label: "Anthropic" }], |
| 583 | + configurationPolicy: { |
| 584 | + authentication: "harnessWithOverrides", |
| 585 | + provider: "selector", |
| 586 | + supportedModes: [], |
| 587 | + model: "optional", |
| 588 | + effortDiscovery: "unknown", |
| 589 | + selectorEnvironment: { |
| 590 | + model: "GOOSE_MODEL", |
| 591 | + provider: "GOOSE_PROVIDER", |
| 592 | + }, |
| 593 | + }, |
| 594 | + }, |
| 595 | + ]; |
| 596 | + const run = vi.fn(async () => { |
| 597 | + throw Error("Goose sign-in cancelled"); |
| 598 | + }); |
| 599 | + fixture.host.models = { begin: async () => 1, run, cancel: async () => {} }; |
| 600 | + const control = createAgentControl(fixture.host); |
| 601 | + const user = userEvent.setup(); |
| 602 | + function Editor() { |
| 603 | + const [draft, setDraft] = useState(() => ({ |
| 604 | + ...agentDraft(fixture.agent), |
| 605 | + command: "/custom/goose-acp", |
| 606 | + args: '["acp"]', |
| 607 | + provider: "", |
| 608 | + model: "", |
| 609 | + environment: {}, |
| 610 | + })); |
| 611 | + return ( |
| 612 | + <AgentSettingsFields |
| 613 | + draft={draft} |
| 614 | + control={control} |
| 615 | + state={{ |
| 616 | + status: "ready", |
| 617 | + data: fixture.data, |
| 618 | + busy: false, |
| 619 | + error: null, |
| 620 | + }} |
| 621 | + disabled={false} |
| 622 | + onChange={(patch) => setDraft((current) => ({ ...current, ...patch }))} |
| 623 | + /> |
| 624 | + ); |
| 625 | + } |
| 626 | + const view = render(<Editor />); |
| 627 | + try { |
| 628 | + await user.click(screen.getByRole("combobox", { name: "LLM Provider" })); |
| 629 | + await user.click(await screen.findByRole("option", { name: "Anthropic" })); |
| 630 | + await waitFor(() => expect(run).toHaveBeenCalledOnce()); |
| 631 | + await waitFor(() => |
| 632 | + expect( |
| 633 | + screen.getByRole("combobox", { name: "Model" }), |
| 634 | + ).not.toHaveAttribute("aria-busy", "true"), |
| 635 | + ); |
| 636 | + |
| 637 | + await user.click(screen.getByRole("combobox", { name: "Harness" })); |
| 638 | + await user.click( |
| 639 | + await screen.findByRole("option", { |
| 640 | + name: "Custom executable / current value", |
| 641 | + }), |
| 642 | + ); |
| 643 | + const executable = screen.getByRole("textbox", { name: "Executable" }); |
| 644 | + await user.clear(executable); |
| 645 | + await user.paste("/custom/hermes-acp"); |
| 646 | + expect(screen.queryByLabelText("Model")).toBeNull(); |
| 647 | + |
| 648 | + await user.clear(screen.getByRole("textbox", { name: "Executable" })); |
| 649 | + await user.paste("/custom/goose-acp"); |
| 650 | + await waitFor(() => |
| 651 | + expect(screen.getByRole("combobox", { name: "Model" })).toBeVisible(), |
| 652 | + ); |
| 653 | + expect(screen.getByLabelText("Anthropic API key")).toBeVisible(); |
| 654 | + await act(async () => {}); |
| 655 | + expect(run).toHaveBeenCalledOnce(); |
| 656 | + } finally { |
| 657 | + view.unmount(); |
| 658 | + control.dispose(); |
| 659 | + } |
| 660 | +}); |
| 661 | + |
575 | 662 | it("adds a Pi provider API key for lookup and drops it when the provider changes", async () => { |
576 | 663 | const fixture = controlFixture(); |
577 | 664 | fixture.data.harnessOptions = [ |
|
0 commit comments