Skip to content

Commit 2a93356

Browse files
only21milclaudemaria-rcks
authored
fix(web): keep saved sensitive variables from losing their value (#23168)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 435cda9 commit 2a93356

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { userEvent } from "vite-plus/test/browser";
2+
import { describe, expect, it, vi } from "vite-plus/test";
3+
4+
import { render } from "../../../test/render";
5+
import { ProviderEnvironmentSection } from "./ProviderInstanceCard";
6+
7+
const savedSecret = {
8+
name: "FAKE_API_KEY",
9+
value: "",
10+
sensitive: true,
11+
valueRedacted: true,
12+
} as const;
13+
14+
describe("ProviderEnvironmentSection saved secrets", () => {
15+
it("requires a replacement before renaming or unlocking a stored secret", async () => {
16+
const onChange = vi.fn();
17+
await using screen = await render(
18+
<ProviderEnvironmentSection environment={[savedSecret]} onChange={onChange} />,
19+
);
20+
const name = screen.getByRole("textbox", { name: "Environment variable name 1" });
21+
const value = screen.getByLabelText("Environment variable value 1");
22+
const lock = screen.getByRole("button", {
23+
name: "Mark environment variable FAKE_API_KEY as sensitive",
24+
});
25+
26+
await expect.element(name).toBeDisabled();
27+
await expect.element(lock).toBeDisabled();
28+
await userEvent.fill(value, "unused-draft");
29+
await userEvent.clear(value);
30+
await userEvent.tab();
31+
expect(onChange).not.toHaveBeenCalled();
32+
await expect.element(name).toBeDisabled();
33+
await expect.element(lock).toBeDisabled();
34+
35+
await userEvent.fill(value, "fake-replacement");
36+
await userEvent.tab();
37+
expect(onChange).toHaveBeenLastCalledWith([
38+
{ ...savedSecret, value: "fake-replacement", valueRedacted: false },
39+
]);
40+
await expect.element(name).toBeEnabled();
41+
await expect.element(lock).toBeEnabled();
42+
await userEvent.fill(name, "RENAMED_KEY");
43+
await userEvent.tab();
44+
await userEvent.click(
45+
screen.getByRole("button", { name: "Mark environment variable RENAMED_KEY as sensitive" }),
46+
);
47+
expect(onChange).toHaveBeenLastCalledWith([
48+
{ name: "RENAMED_KEY", value: "fake-replacement", sensitive: false, valueRedacted: false },
49+
]);
50+
await userEvent.click(
51+
screen.getByRole("button", { name: "Remove environment variable RENAMED_KEY" }),
52+
);
53+
expect(onChange).toHaveBeenLastCalledWith([]);
54+
});
55+
});

‎apps/web/src/components/settings/ProviderInstanceCard.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ export function ProviderEnvironmentSection(props: {
453453
className="min-w-0 flex-1"
454454
value={variable.name}
455455
onCommit={(name) => updateVariable(variable.id, { name: name.trim() })}
456+
disabled={variable.valueRedacted === true}
456457
placeholder="VARIABLE_NAME"
457458
spellCheck={false}
458459
aria-label={`Environment variable name ${index + 1}`}
@@ -478,6 +479,7 @@ export function ProviderEnvironmentSection(props: {
478479
type="button"
479480
size="icon-micro"
480481
variant="ghost-muted"
482+
disabled={variable.valueRedacted === true}
481483
onClick={() => {
482484
const sensitive = !variable.sensitive;
483485
updateVariable(variable.id, {
@@ -558,6 +560,9 @@ export function ProviderEnvironmentSection(props: {
558560
})}
559561
<p className="text-xs text-muted-foreground">
560562
Sensitive values are stored separately and never returned to the app.
563+
{rows.some((row) => row.valueRedacted === true)
564+
? " Enter a new value to rename a saved one or make it plain text."
565+
: null}
561566
</p>
562567
</div>
563568
) : null}

0 commit comments

Comments
 (0)