@devries-cameron20 / t3code Mirror · read-only / commits / 8913a4a254
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 00:45 UTC

fix(web): keep typed unpublished variable rows across settings re-deliveries (#30115)

Co-authored-by: Justin <159104807+Justin24506@users.noreply.github.com>

Justin Jacob committed Nov 9, 2026 at 20:03 UTC 8913a4a25467b23804115205c4701865538198aa
2 files changed +136 -2
apps/web/src/components/settings/ProviderInstanceCard.environment.browser.test.tsx
+121
@@ -53,3 +53,124 @@ describe("ProviderEnvironmentSection saved secrets", () => {
53 expect(onChange).toHaveBeenLastCalledWith([]);
54 });
55 });
56 +
57 +describe("ProviderEnvironmentSection external settings writes", () => {
58 + it("keeps a typed unpublished row when an external write redelivers the environment", async () => {
59 + const onChange = vi.fn();
60 + await using screen = await render(
61 + <ProviderEnvironmentSection environment={[]} onChange={onChange} />,
62 + );
63 +
64 + await userEvent.click(screen.getByRole("button", { name: "Add variable" }));
65 + await userEvent.type(
66 + screen.getByRole("textbox", { name: "Environment variable name 1" }),
67 + "KEEP_ME_TYPED",
68 + );
69 + expect(onChange).not.toHaveBeenCalled();
70 +
71 + // A settings write from elsewhere on the instance redelivers a redacted, stored variable.
72 + await screen.rerender(
73 + <ProviderEnvironmentSection
74 + environment={[{ name: "OTHER_VAR", value: "", sensitive: true, valueRedacted: true }]}
75 + onChange={onChange}
76 + />,
77 + );
78 +
79 + await expect
80 + .element(screen.getByRole("textbox", { name: "Environment variable name 2" }))
81 + .toHaveValue("KEEP_ME_TYPED");
82 + });
83 +
84 + it("does not duplicate a redacted published row on the sibling reseed", async () => {
85 + const onChange = vi.fn();
86 + await using screen = await render(
87 + <ProviderEnvironmentSection environment={[]} onChange={onChange} />,
88 + );
89 +
90 + await userEvent.click(screen.getByRole("button", { name: "Add variable" }));
91 + await userEvent.fill(
92 + screen.getByRole("textbox", { name: "Environment variable name 1" }),
93 + "STORE_ME",
94 + );
95 + await userEvent.fill(screen.getByLabelText("Environment variable value 1"), "fake-secret");
96 + await userEvent.tab();
97 + expect(onChange).toHaveBeenLastCalledWith([
98 + { name: "STORE_ME", value: "fake-secret", sensitive: true, valueRedacted: false },
99 + ]);
100 +
101 + await userEvent.click(screen.getByRole("button", { name: "Add variable" }));
102 + await userEvent.type(
103 + screen.getByRole("textbox", { name: "Environment variable name 2" }),
104 + "UNPUBLISHED_ONE",
105 + );
106 +
107 + // The stored secret comes back redacted, so the rows reseed without matching the echo.
108 + await screen.rerender(
109 + <ProviderEnvironmentSection
110 + environment={[{ name: "STORE_ME", value: "", sensitive: true, valueRedacted: true }]}
111 + onChange={onChange}
112 + />,
113 + );
114 +
115 + await expect
116 + .element(screen.getByRole("textbox", { name: "Environment variable name 1" }))
117 + .toHaveValue("STORE_ME");
118 + await expect
119 + .element(screen.getByRole("textbox", { name: "Environment variable name 2" }))
120 + .toHaveValue("UNPUBLISHED_ONE");
121 + });
122 +
123 + it("keeps a committed but unpublishable row across an external write", async () => {
124 + const onChange = vi.fn();
125 + await using screen = await render(
126 + <ProviderEnvironmentSection environment={[]} onChange={onChange} />,
127 + );
128 +
129 + await userEvent.click(screen.getByRole("button", { name: "Add variable" }));
130 + await userEvent.fill(
131 + screen.getByRole("textbox", { name: "Environment variable name 1" }),
132 + "KEEP-ME",
133 + );
134 + await userEvent.tab();
135 + expect(onChange).not.toHaveBeenCalled();
136 +
137 + await screen.rerender(
138 + <ProviderEnvironmentSection
139 + environment={[{ name: "OTHER_VAR", value: "", sensitive: true, valueRedacted: true }]}
140 + onChange={onChange}
141 + />,
142 + );
143 + await expect
144 + .element(screen.getByRole("textbox", { name: "Environment variable name 2" }))
145 + .toHaveValue("KEEP-ME");
146 + });
147 +
148 + it("drops an acknowledged row when an external write removes it", async () => {
149 + const onChange = vi.fn();
150 + await using screen = await render(
151 + <ProviderEnvironmentSection environment={[]} onChange={onChange} />,
152 + );
153 +
154 + await userEvent.click(screen.getByRole("button", { name: "Add variable" }));
155 + await userEvent.fill(
156 + screen.getByRole("textbox", { name: "Environment variable name 1" }),
157 + "PUBLISH_ME",
158 + );
159 + await userEvent.tab();
160 + expect(onChange).toHaveBeenLastCalledWith([{ name: "PUBLISH_ME", value: "", sensitive: true }]);
161 +
162 + // The server echo acknowledges the publish and keeps the rows; nothing is republished.
163 + await screen.rerender(
164 + <ProviderEnvironmentSection
165 + environment={[{ name: "PUBLISH_ME", value: "", sensitive: true }]}
166 + onChange={onChange}
167 + />,
168 + );
169 + expect(onChange).toHaveBeenCalledTimes(1);
170 + const acknowledged = screen.getByRole("textbox", { name: "Environment variable name 1" });
171 +
172 + // Another client deletes the variable. The row must not come back.
173 + await screen.rerender(<ProviderEnvironmentSection environment={[]} onChange={onChange} />);
174 + await expect.element(acknowledged).not.toBeInTheDocument();
175 + });
176 +});
apps/web/src/components/settings/ProviderInstanceCard.tsx
+15 -2
@@ -97,7 +97,9 @@ function ProviderStatusDiagnostic({
97 }
98
99 let environmentVariableDraftId = 0;
100 -const nextEnvironmentVariableDraftId = () => `provider-env-${environmentVariableDraftId++}`;
100 +const DRAFT_ROW_ID_PREFIX = "provider-env-";
101 +const nextEnvironmentVariableDraftId = () =>
102 + `${DRAFT_ROW_ID_PREFIX}${environmentVariableDraftId++}`;
103
104 type EnvironmentDraftRow = {
105 readonly id: string;
@@ -346,12 +348,23 @@ export function ProviderEnvironmentSection(props: {
348 const [storedDraft, setDraft] = useState(() =>
349 seedRowsDraft(props.environment, toEnvironmentDraftRows),
350 );
349 - const draft = reconcileRowsDraft(
351 + let draft = reconcileRowsDraft(
352 storedDraft,
353 props.environment,
354 providerEnvironmentsEqual,
355 toEnvironmentDraftRows,
356 );
357 + if (draft.rows !== storedDraft.rows) {
358 + // Keep rows the server never acknowledged, even across an external reseed.
359 + const acknowledged = new Set(storedDraft.seen.map((variable) => variable.name));
360 + const unpublished = storedDraft.rows.filter(
361 + (row) =>
362 + row.id.startsWith(DRAFT_ROW_ID_PREFIX) &&
363 + !acknowledged.has(row.name) &&
364 + !draft.rows.some((incoming) => incoming.name === row.name),
365 + );
366 + if (unpublished.length > 0) draft = { ...draft, rows: [...draft.rows, ...unpublished] };
367 + }
368 if (draft !== storedDraft) setDraft(draft);
369 const rows = draft.rows;
370 const setRows = (nextRows: ReadonlyArray<EnvironmentDraftRow>) =>