Address Greptile follow-up on sandbox core PR

This commit is contained in:
Devin Foley
2026-04-24 17:10:34 -07:00
parent 87dc7c2929
commit c855d5c72d
4 changed files with 146 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
import { collectSecretRefPaths } from "../services/json-schema-secret-refs.ts";
describe("collectSecretRefPaths", () => {
it("collects nested secret-ref paths from object properties", () => {
expect(Array.from(collectSecretRefPaths({
type: "object",
properties: {
credentials: {
type: "object",
properties: {
apiKey: { type: "string", format: "secret-ref" },
},
},
},
}))).toEqual(["credentials.apiKey"]);
});
it("collects secret-ref paths from JSON Schema composition keywords", () => {
expect(Array.from(collectSecretRefPaths({
type: "object",
allOf: [
{
properties: {
apiKey: { type: "string", format: "secret-ref" },
},
},
{
properties: {
nested: {
oneOf: [
{
properties: {
token: { type: "string", format: "secret-ref" },
},
},
],
},
},
},
],
})).sort()).toEqual(["apiKey", "nested.token"]);
});
});

View File

@@ -12,6 +12,15 @@ export function collectSecretRefPaths(
if (!schema || typeof schema !== "object") return paths;
function walk(node: Record<string, unknown>, prefix: string): void {
for (const keyword of ["allOf", "anyOf", "oneOf"] as const) {
const branches = node[keyword];
if (!Array.isArray(branches)) continue;
for (const branch of branches) {
if (!branch || typeof branch !== "object" || Array.isArray(branch)) continue;
walk(branch as Record<string, unknown>, prefix);
}
}
const properties = node.properties as Record<string, Record<string, unknown>> | undefined;
if (!properties || typeof properties !== "object") return;
for (const [key, propertySchema] of Object.entries(properties)) {
@@ -20,9 +29,7 @@ export function collectSecretRefPaths(
if (propertySchema.format === "secret-ref") {
paths.add(path);
}
if (propertySchema.type === "object") {
walk(propertySchema, path);
}
walk(propertySchema, path);
}
}

View File

@@ -164,4 +164,87 @@ describe("CompanySettings", () => {
root.unmount();
});
});
it("preserves sandbox config when re-selecting the same provider while editing", async () => {
const root = createRoot(container);
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
mockEnvironmentsApi.list.mockResolvedValue([
{
id: "env-1",
companyId: "company-1",
name: "Secure Sandbox",
description: null,
driver: "sandbox",
status: "active",
config: {
provider: "secure-plugin",
template: "saved-template",
},
metadata: null,
createdAt: new Date("2026-04-25T00:00:00.000Z"),
updatedAt: new Date("2026-04-25T00:00:00.000Z"),
},
]);
mockEnvironmentsApi.capabilities.mockResolvedValue(
getEnvironmentCapabilities(AGENT_ADAPTER_TYPES, {
sandboxProviders: {
"secure-plugin": {
status: "supported",
supportsSavedProbe: true,
supportsUnsavedProbe: true,
supportsRunExecution: true,
supportsReusableLeases: true,
displayName: "Secure Sandbox",
configSchema: {
type: "object",
properties: {
template: { type: "string", title: "Template" },
},
},
},
},
}),
);
await act(async () => {
root.render(
<QueryClientProvider client={queryClient}>
<TooltipProvider>
<CompanySettings />
</TooltipProvider>
</QueryClientProvider>,
);
});
await flushReact();
await flushReact();
const editButton = Array.from(container.querySelectorAll("button"))
.find((button) => button.textContent?.trim() === "Edit");
expect(editButton).toBeTruthy();
await act(async () => {
editButton?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
});
await flushReact();
const providerSelect = Array.from(container.querySelectorAll("select"))
.find((select) => Array.from(select.options).some((option) => option.value === "secure-plugin")) as HTMLSelectElement | undefined;
expect(providerSelect).toBeTruthy();
await act(async () => {
providerSelect!.value = "secure-plugin";
providerSelect!.dispatchEvent(new Event("change", { bubbles: true }));
});
await flushReact();
const templateInput = Array.from(container.querySelectorAll("input"))
.find((input) => (input as HTMLInputElement).value === "saved-template") as HTMLInputElement | undefined;
expect(templateInput?.value).toBe("saved-template");
await act(async () => {
root.unmount();
});
});
});

View File

@@ -1029,11 +1029,17 @@ export function CompanySettings() {
className="w-full rounded-md border border-border bg-transparent px-2.5 py-1.5 text-sm outline-none"
value={environmentForm.sandboxProvider}
onChange={(e) => {
const nextProvider = pluginSandboxProviders.find((provider) => provider.provider === e.target.value) ?? null;
const nextProviderKey = e.target.value;
const nextProvider = pluginSandboxProviders.find((provider) => provider.provider === nextProviderKey) ?? null;
setEnvironmentForm((current) => ({
...current,
sandboxProvider: e.target.value,
sandboxConfig: nextProvider?.configSchema ? getDefaultValues(nextProvider.configSchema as any) : {},
sandboxProvider: nextProviderKey,
sandboxConfig:
current.sandboxProvider === nextProviderKey
? current.sandboxConfig
: nextProvider?.configSchema
? getDefaultValues(nextProvider.configSchema as any)
: {},
}));
}}
>