@devries-cameron20 / t3code-1 / commits / 4cb8da6f2f
Fork 0

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

perf(relay): reconcile multiline env values without rescanning prefixes (#31196)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Hieu Le committed Nov 15, 2026 at 02:32 UTC 4cb8da6f2f23b03aad2b13e063bcf4313890e601
2 files changed +15 -2
infra/relay/src/clientConfig.test.ts
+9
@@ -37,10 +37,19 @@ describe("reconcileEnvFile", () => {
37 it("replaces a quoted multi-line value whole", () => {
38 expect(reconcileEnvFile('A="one\ntwo"\nKEEP=1\n', { A: "new" })).toBe("A=new\nKEEP=1\n");
39 expect(reconcileEnvFile("A='x'\nKEEP=1\n", { A: "new" })).toBe("A=new\nKEEP=1\n");
40 + expect(
41 + reconcileEnvFile(
42 + '# earlier "quote"\nA="first\nvalue"\nKEEP=1\nA=\'second\nvalue\'\nB=`third\nvalue`',
43 + { A: "new", B: "updated" },
44 + ),
45 + ).toBe('# earlier "quote"\nA=new\nKEEP=1\nB=updated\n');
46 });
47
48 it("keeps later lines when a quoted value never closes", () => {
49 expect(reconcileEnvFile('A="one\nKEEP=1\n', { A: "new" })).toBe("A=new\nKEEP=1\n");
50 + expect(
51 + reconcileEnvFile("A=\"one\nKEEP='two'\nB=`three\nKEEP=2", { A: "new", B: "updated" }),
52 + ).toBe("A=new\nKEEP='two'\nB=updated\nKEEP=2\n");
53 });
54
55 it("leaves a commented-out assignment alone", () => {
infra/relay/src/clientConfig.ts
+6 -2
@@ -73,8 +73,12 @@ export function reconcileEnvFile(
73 const rawValue = match[2] ?? "";
74 const quote = /^(['"`])/u.exec(rawValue)?.[1];
75 if (quote !== undefined && !closesQuote(rawValue, quote)) {
76 - const closing = lines.findIndex((candidate, at) => at > index && candidate.includes(quote));
77 - if (closing !== -1) index = closing;
76 + for (let closing = index + 1; closing < lines.length; closing += 1) {
77 + if (lines[closing]!.includes(quote)) {
78 + index = closing;
79 + break;
80 + }
81 + }
82 }
83 const value = pending.get(name);
84 if (value !== undefined) {