+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
257 lines
8.7 KiB
TypeScript
257 lines
8.7 KiB
TypeScript
import { EnvironmentId, ProviderDriverKind, type AcpRegistrySearchAgent } from "@t3tools/contracts";
|
|
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
|
|
|
import { visitElements } from "../../test/reactElementTree";
|
|
import { reactHookHarness as hooks } from "../../test/reactHookHarness";
|
|
|
|
const settingsHooks = vi.hoisted(() => ({
|
|
read: vi.fn(() => ({ providerInstances: {} })),
|
|
mutate: vi.fn(),
|
|
useMutation: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("react", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("react")>();
|
|
const { reactHookHarness } = await import("../../test/reactHookHarness");
|
|
return {
|
|
...actual,
|
|
useMemo: reactHookHarness.useMemo,
|
|
useState: reactHookHarness.useState,
|
|
};
|
|
});
|
|
|
|
vi.mock("react/compiler-runtime", async () => {
|
|
const { reactHookHarness } = await import("../../test/reactHookHarness");
|
|
return { c: reactHookHarness.useMemoCache };
|
|
});
|
|
|
|
vi.mock("@t3tools/client-runtime/state/runtime", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("@t3tools/client-runtime/state/runtime")>()),
|
|
squashAtomCommandFailure: () => new Error("The settings update failed."),
|
|
}));
|
|
|
|
vi.mock("../../hooks/useSettings", () => ({
|
|
useEnvironmentSettings: settingsHooks.read,
|
|
usePersistEnvironmentProviderInstanceMutation: settingsHooks.useMutation,
|
|
}));
|
|
|
|
import { AddProviderInstanceDialog } from "./AddProviderInstanceDialog";
|
|
|
|
const remoteEnvironmentId = EnvironmentId.make("remote-device");
|
|
const preparedAgent: AcpRegistrySearchAgent = {
|
|
id: "kilo",
|
|
name: "Kilo Code",
|
|
version: "4.2.0",
|
|
description: "Kilo ACP agent",
|
|
authors: ["Kilo"],
|
|
license: "Apache-2.0",
|
|
website: null,
|
|
repository: null,
|
|
icon: "https://cdn.agentclientprotocol.com/registry/v1/latest/kilo.svg",
|
|
distribution: "binary",
|
|
integrity: "sha256",
|
|
};
|
|
|
|
function render(onOpenChange = vi.fn()) {
|
|
hooks.beginRender();
|
|
return AddProviderInstanceDialog({
|
|
open: true,
|
|
environmentId: remoteEnvironmentId,
|
|
environmentLabel: "Remote device",
|
|
onOpenChange,
|
|
});
|
|
}
|
|
|
|
function findByChildren(tree: ReturnType<typeof render>, children: string) {
|
|
const result = visitElements(tree, (element) => element.props.children === children);
|
|
expect(result).not.toBeNull();
|
|
return result!;
|
|
}
|
|
|
|
async function selectPreparedAcp() {
|
|
const searchStep = render();
|
|
const search = visitElements(
|
|
searchStep,
|
|
(element) =>
|
|
typeof element.type === "function" && element.type.name === "AcpRegistrySearchStep",
|
|
);
|
|
expect(search).not.toBeNull();
|
|
(search?.props.onPrepared as ((agent: AcpRegistrySearchAgent) => void) | undefined)?.(
|
|
preparedAgent,
|
|
);
|
|
}
|
|
|
|
describe("AddProviderInstanceDialog environment routing", () => {
|
|
beforeEach(() => {
|
|
hooks.reset();
|
|
settingsHooks.read.mockReset().mockReturnValue({ providerInstances: {} });
|
|
settingsHooks.mutate.mockReset().mockResolvedValue({ _tag: "Success", value: {} });
|
|
settingsHooks.useMutation.mockReset().mockReturnValue(settingsHooks.mutate);
|
|
});
|
|
|
|
it("creates a provider with its default identity without typing", async () => {
|
|
let tree = render();
|
|
const group = visitElements(
|
|
tree,
|
|
(element) => element.props["aria-labelledby"] === "add-instance-driver-label",
|
|
);
|
|
(group!.props.onValueChange as (value: string) => void)("grok");
|
|
tree = render();
|
|
(findByChildren(tree, "Next").props.onClick as () => void)();
|
|
tree = render();
|
|
(findByChildren(tree, "Next").props.onClick as () => void)();
|
|
tree = render();
|
|
(findByChildren(tree, "Add instance").props.onClick as () => void)();
|
|
await Promise.resolve();
|
|
expect(settingsHooks.mutate).toHaveBeenCalledWith({
|
|
operation: "create",
|
|
instanceId: "grok",
|
|
instance: { driver: "grok", enabled: true, displayName: "Grok" },
|
|
});
|
|
});
|
|
|
|
it("chooses an unused identity for another account without replacing configured instances", async () => {
|
|
settingsHooks.read.mockReturnValue({
|
|
providerInstances: {
|
|
codex_2: { driver: "codex", enabled: false },
|
|
},
|
|
});
|
|
let tree = render();
|
|
// Codex offers ChatGPT sign-in first; manual setup keeps the existing CLI flow.
|
|
(findByChildren(tree, "Configure manually").props.onClick as () => void)();
|
|
tree = render();
|
|
(findByChildren(tree, "Next").props.onClick as () => void)();
|
|
tree = render();
|
|
(findByChildren(tree, "Add instance").props.onClick as () => void)();
|
|
await Promise.resolve();
|
|
expect(settingsHooks.mutate).toHaveBeenCalledWith({
|
|
operation: "create",
|
|
instanceId: "codex_3",
|
|
instance: {
|
|
driver: "codex",
|
|
enabled: true,
|
|
displayName: "Codex",
|
|
config: { setupMode: "existing" },
|
|
},
|
|
});
|
|
});
|
|
|
|
it("reads and writes settings through the supplied environment", () => {
|
|
render();
|
|
|
|
expect(settingsHooks.read).toHaveBeenCalledWith(remoteEnvironmentId);
|
|
expect(settingsHooks.useMutation).toHaveBeenCalledWith(remoteEnvironmentId);
|
|
});
|
|
|
|
it("awaits an atomic create before closing and retains prepared ACP metadata", async () => {
|
|
const onOpenChange = vi.fn();
|
|
let resolveMutation!: (value: { readonly _tag: "Success"; readonly value: unknown }) => void;
|
|
settingsHooks.mutate.mockReturnValueOnce(
|
|
new Promise((resolve) => {
|
|
resolveMutation = resolve;
|
|
}),
|
|
);
|
|
await selectPreparedAcp();
|
|
|
|
const identityStep = render(onOpenChange);
|
|
expect(
|
|
visitElements(identityStep, (element) => {
|
|
const content = JSON.stringify(element.props.children);
|
|
return content?.includes("4.2.0") === true && content.includes("binary");
|
|
}),
|
|
).not.toBeNull();
|
|
(
|
|
findByChildren(identityStep, "Continue to sign-in").props.onClick as (() => void) | undefined
|
|
)?.();
|
|
expect(settingsHooks.mutate).toHaveBeenCalledWith({
|
|
operation: "create",
|
|
instanceId: "acpRegistry_kilo_code",
|
|
instance: {
|
|
driver: ProviderDriverKind.make("acpRegistry"),
|
|
enabled: true,
|
|
displayName: "Kilo Code",
|
|
config: {
|
|
agentId: "kilo",
|
|
distribution: "auto",
|
|
registryIconUrl: "https://cdn.agentclientprotocol.com/registry/v1/latest/kilo.svg",
|
|
},
|
|
},
|
|
});
|
|
expect(onOpenChange).not.toHaveBeenCalled();
|
|
|
|
resolveMutation({ _tag: "Success", value: {} });
|
|
await Promise.resolve();
|
|
await Promise.resolve();
|
|
expect(onOpenChange).not.toHaveBeenCalled();
|
|
const signInStep = render(onOpenChange);
|
|
const authentication = visitElements(
|
|
signInStep,
|
|
(element) =>
|
|
typeof element.type === "function" &&
|
|
element.type.name === "ProviderWizardAuthenticationStep",
|
|
);
|
|
expect(authentication?.props.instanceId).toBe("acpRegistry_kilo_code");
|
|
expect(authentication?.props.environmentId).toBe(remoteEnvironmentId);
|
|
expect(settingsHooks.mutate).toHaveBeenCalledTimes(1);
|
|
(authentication!.props.onFinish as () => void)();
|
|
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
});
|
|
|
|
it("configures a manually entered registry agent from the first provider screen", async () => {
|
|
let tree = render();
|
|
const search = visitElements(
|
|
tree,
|
|
(element) =>
|
|
typeof element.type === "function" && element.type.name === "AcpRegistrySearchStep",
|
|
);
|
|
(search!.props.onManualConfiguration as () => void)();
|
|
tree = render();
|
|
const configuration = visitElements(
|
|
tree,
|
|
(element) => element.props.idPrefix === "add-provider-acpRegistry-manual",
|
|
);
|
|
(configuration!.props.onChange as (value: Record<string, unknown>) => void)({
|
|
agentId: "devin",
|
|
});
|
|
tree = render();
|
|
(findByChildren(tree, "Next").props.onClick as () => void)();
|
|
tree = render();
|
|
(findByChildren(tree, "Continue to sign-in").props.onClick as () => void)();
|
|
await Promise.resolve();
|
|
await Promise.resolve();
|
|
expect(settingsHooks.mutate).toHaveBeenCalledWith({
|
|
operation: "create",
|
|
instanceId: "acpRegistry_custom",
|
|
instance: {
|
|
driver: "acpRegistry",
|
|
enabled: true,
|
|
config: { agentId: "devin" },
|
|
},
|
|
});
|
|
tree = render();
|
|
expect(
|
|
visitElements(
|
|
tree,
|
|
(element) =>
|
|
typeof element.type === "function" &&
|
|
element.type.name === "ProviderWizardAuthenticationStep",
|
|
),
|
|
).not.toBeNull();
|
|
});
|
|
|
|
it("keeps the dialog open when the atomic upsert fails", async () => {
|
|
settingsHooks.mutate.mockResolvedValueOnce({ _tag: "Failure", cause: new Error("Conflict") });
|
|
const onOpenChange = vi.fn();
|
|
await selectPreparedAcp();
|
|
|
|
const identityStep = render(onOpenChange);
|
|
(
|
|
findByChildren(identityStep, "Continue to sign-in").props.onClick as (() => void) | undefined
|
|
)?.();
|
|
await Promise.resolve();
|
|
await Promise.resolve();
|
|
|
|
expect(onOpenChange).not.toHaveBeenCalled();
|
|
});
|
|
});
|