Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(agents): name an invalid env key, not its value, when bulk edit refuses (#10387)
xiaoke123456783fc659ae7361
diff --git a/packages/views/agents/components/tabs/env-file.test.ts b/packages/views/agents/components/tabs/env-file.test.tsindex fb576acc85..55b6390b88 100644--- a/packages/views/agents/components/tabs/env-file.test.ts+++ b/packages/views/agents/components/tabs/env-file.test.ts@@ -159,13 +159,18 @@ describe("formatEnvFile", () => {});});- it("refuses keys the parser could not read back", () => {- expect(formatEnvFile([{ key: "foo-bar", value: "x" }])).toEqual({- ok: false,- reason: "unrepresentable",- key: "foo-bar",- });- });+ // The API stores any key, but a line only reads back with a dotenv+ // identifier. Report it as the key's problem, not the value's (#10357).+ it.each(["foo-bar", "MY-TOOL_api_key", "1ST", "has space"])(+ "refuses key %j as an invalid name",+ (key) => {+ expect(formatEnvFile([{ key, value: "x" }])).toEqual({+ ok: false,+ reason: "invalid_key",+ key,+ });+ },+ );it("refuses duplicate keys, which no text could round-trip", () => {expect(diff --git a/packages/views/agents/components/tabs/env-file.ts b/packages/views/agents/components/tabs/env-file.tsindex 0f55b7f24e..e16c07395a 100644--- a/packages/views/agents/components/tabs/env-file.ts+++ b/packages/views/agents/components/tabs/env-file.ts@@ -128,7 +128,7 @@ export function parseEnvFile(text: string): EnvAssignment[] | null {export type EnvFormatResult =| { ok: true; text: string }- | { ok: false; reason: "unrepresentable" | "duplicate"; key: string };+ | { ok: false; reason: "invalid_key" | "unrepresentable" | "duplicate"; key: string };const KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;@@ -156,7 +156,10 @@ function encodeValue(key: string, value: string): string | null {/*** Serialize entries back into text `parseEnvFileResult` reads identically, or* name the first entry that cannot be represented so the caller can refuse to- * enter bulk editing without touching any data.+ * enter bulk editing without touching any data. A key outside the dotenv+ * identifier grammar (`invalid_key`) is reported apart from a value with no+ * text form (`unrepresentable`): the API stores both, and the user has to+ * know which field to change.** Success means the whole text round-trips, which is why duplicate keys are a* refusal rather than a formatting detail: two entries sharing a key can only@@ -168,7 +171,7 @@ export function formatEnvFile(assignments: EnvAssignment[]): EnvFormatResult {for (const { key, value } of assignments) {if (!KEY_PATTERN.test(key)) {- return { ok: false, reason: "unrepresentable", key };+ return { ok: false, reason: "invalid_key", key };}if (keys.has(key)) return { ok: false, reason: "duplicate", key };diff --git a/packages/views/agents/components/tabs/env-tab.test.tsx b/packages/views/agents/components/tabs/env-tab.test.tsxindex 9d29ac3524..0b3145660a 100644--- a/packages/views/agents/components/tabs/env-tab.test.tsx+++ b/packages/views/agents/components/tabs/env-tab.test.tsx@@ -391,6 +391,27 @@ describe("EnvTab values that bulk text cannot represent", () => {).toEqual(["PEM", "SAFE"]);});+ it("names the key, not the value, when a stored key has no bulk text form", async () => {+ getAgentEnv.mockResolvedValue({+ custom_env: { "MY-TOOL_api_key": "x", SAFE: "ok" },+ });+ const user = userEvent.setup();+ renderTab();++ await user.click(screen.getByRole("button", { name: /reveal & edit/i }));+ await user.click(screen.getByRole("button", { name: /bulk edit/i }));++ expect(toastError).toHaveBeenCalledWith(+ 'Bulk text only supports names like API_KEY — edit "MY-TOOL_api_key" as a row',+ );+ expect(+ screen.queryByRole("textbox", { name: /bulk edit/i }),+ ).not.toBeInTheDocument();+ expect(+ screen.getAllByPlaceholderText("KEY").map((i) => (i as HTMLInputElement).value),+ ).toEqual(["MY-TOOL_api_key", "SAFE"]);+ });+it("refuses bulk mode when two rows share a key", async () => {getAgentEnv.mockResolvedValue({ custom_env: { A: "1" } });const user = userEvent.setup();diff --git a/packages/views/agents/components/tabs/env-tab.tsx b/packages/views/agents/components/tabs/env-tab.tsxindex fe1659f737..dbfce69cb8 100644--- a/packages/views/agents/components/tabs/env-tab.tsx+++ b/packages/views/agents/components/tabs/env-tab.tsx@@ -231,9 +231,13 @@ export function EnvTab({toast.error(formatted.reason === "duplicate"? t(($) => $.tab_body.env.duplicate_keys_toast)- : t(($) => $.tab_body.env.bulk_unsupported_toast, {- key: formatted.key,- }),+ : formatted.reason === "invalid_key"+ ? t(($) => $.tab_body.env.bulk_invalid_key_toast, {+ key: formatted.key,+ })+ : t(($) => $.tab_body.env.bulk_unsupported_toast, {+ key: formatted.key,+ }),);return;}diff --git a/packages/views/locales/en/agents.json b/packages/views/locales/en/agents.jsonindex ec9d1b0195..1ee2f2f7f1 100644--- a/packages/views/locales/en/agents.json+++ b/packages/views/locales/en/agents.json@@ -547,6 +547,7 @@"bulk_placeholder": "API_KEY=value\nBASE_URL=https://example.com","bulk_plaintext_notice": "Values are shown in plain text while bulk editing.","bulk_unsupported_toast": "\"{{key}}\" can't be shown as text — edit it as a row",+ "bulk_invalid_key_toast": "Bulk text only supports names like API_KEY — edit \"{{key}}\" as a row","parse_error_malformed": "Line {{line}} isn't a KEY=value assignment","parse_error_duplicate": "Duplicate key \"{{key}}\" on line {{line}}","paste_invalid_toast": "Couldn't parse pasted environment variables",diff --git a/packages/views/locales/es/agents.json b/packages/views/locales/es/agents.jsonindex 18801e83ce..9bf38d21da 100644--- a/packages/views/locales/es/agents.json+++ b/packages/views/locales/es/agents.json@@ -529,6 +529,7 @@"bulk_placeholder": "API_KEY=value\nBASE_URL=https://example.com","bulk_plaintext_notice": "Los valores se muestran en texto plano durante la edición masiva.","bulk_unsupported_toast": "\"{{key}}\" no se puede mostrar como texto: edítala como fila",+ "bulk_invalid_key_toast": "La edición masiva solo admite nombres como API_KEY: edita \"{{key}}\" como fila","parse_error_malformed": "La línea {{line}} no es una asignación CLAVE=valor","parse_error_duplicate": "Clave duplicada \"{{key}}\" en la línea {{line}}","paste_invalid_toast": "No se han podido analizar las variables de entorno pegadas",diff --git a/packages/views/locales/fr/agents.json b/packages/views/locales/fr/agents.jsonindex 876a39c27b..75dee69299 100644--- a/packages/views/locales/fr/agents.json+++ b/packages/views/locales/fr/agents.json@@ -547,6 +547,7 @@"bulk_placeholder": "API_KEY=valeur\nBASE_URL=https://exemple.com","bulk_plaintext_notice": "Les valeurs sont affichées en clair pendant l'édition groupée.","bulk_unsupported_toast": "« {{key}} » ne peut pas être affiché en texte — modifiez-le en ligne",+ "bulk_invalid_key_toast": "L'édition groupée n'accepte que des noms comme API_KEY — modifiez « {{key}} » en ligne","parse_error_malformed": "La ligne {{line}} n'est pas une affectation CLÉ=valeur","parse_error_duplicate": "Clé « {{key}} » en double à la ligne {{line}}","paste_invalid_toast": "Impossible d'analyser les variables d'environnement collées",diff --git a/packages/views/locales/ja/agents.json b/packages/views/locales/ja/agents.jsonindex 37f909445e..8efac6eac9 100644--- a/packages/views/locales/ja/agents.json+++ b/packages/views/locales/ja/agents.json@@ -389,6 +389,7 @@"bulk_placeholder": "API_KEY=値\nBASE_URL=https://example.com","bulk_plaintext_notice": "一括編集中は値が平文で表示されます。","bulk_unsupported_toast": "\"{{key}}\" の値はテキストで表現できません。個別編集で変更してください",+ "bulk_invalid_key_toast": "一括編集では API_KEY のような変数名のみ使えます。\"{{key}}\" は個別編集で変更してください","parse_error_malformed": "{{line}} 行目が KEY=value 形式ではありません","parse_error_duplicate": "{{line}} 行目のキー \"{{key}}\" が重複しています","paste_invalid_toast": "貼り付けた環境変数を解析できませんでした",diff --git a/packages/views/locales/ko/agents.json b/packages/views/locales/ko/agents.jsonindex d975676ee3..0901d4b599 100644--- a/packages/views/locales/ko/agents.json+++ b/packages/views/locales/ko/agents.json@@ -389,6 +389,7 @@"bulk_placeholder": "API_KEY=값\nBASE_URL=https://example.com","bulk_plaintext_notice": "일괄 편집 중에는 값이 평문으로 표시됩니다.","bulk_unsupported_toast": "\"{{key}}\" 값은 텍스트로 표현할 수 없습니다. 개별 편집에서 수정하세요",+ "bulk_invalid_key_toast": "일괄 편집은 API_KEY 같은 변수 이름만 지원합니다. \"{{key}}\"은(는) 개별 편집에서 수정하세요","parse_error_malformed": "{{line}}번째 줄이 KEY=value 형식이 아닙니다","parse_error_duplicate": "{{line}}번째 줄의 키 \"{{key}}\"가 중복됩니다","paste_invalid_toast": "붙여넣은 환경 변수를 파싱할 수 없습니다",diff --git a/packages/views/locales/ru/agents.json b/packages/views/locales/ru/agents.jsonindex c5b016719e..db359632d0 100644--- a/packages/views/locales/ru/agents.json+++ b/packages/views/locales/ru/agents.json@@ -581,6 +581,7 @@"bulk_placeholder": "API_KEY=значение\nBASE_URL=https://example.com","bulk_plaintext_notice": "При массовом редактировании значения показываются открытым текстом.","bulk_unsupported_toast": "«{{key}}» нельзя показать как текст — отредактируйте как строку",+ "bulk_invalid_key_toast": "Массовое редактирование поддерживает только имена вида API_KEY — отредактируйте «{{key}}» как строку","parse_error_malformed": "Строка {{line}} не является присвоением вида KEY=value","parse_error_duplicate": "Повторяющийся ключ «{{key}}» в строке {{line}}","paste_invalid_toast": "Не удалось разобрать вставленные переменные окружения",diff --git a/packages/views/locales/zh-Hans/agents.json b/packages/views/locales/zh-Hans/agents.jsonindex 195cb27379..b4236155cc 100644--- a/packages/views/locales/zh-Hans/agents.json+++ b/packages/views/locales/zh-Hans/agents.json@@ -530,6 +530,7 @@"bulk_placeholder": "API_KEY=值\nBASE_URL=https://example.com","bulk_plaintext_notice": "批量编辑时,值以明文显示。","bulk_unsupported_toast": "\"{{key}}\" 的值无法用文本表示,请用逐条编辑修改",+ "bulk_invalid_key_toast": "批量编辑只支持 API_KEY 这类变量名,请用逐条编辑修改 \"{{key}}\"","parse_error_malformed": "第 {{line}} 行不是 KEY=value 格式","parse_error_duplicate": "第 {{line}} 行的 key \"{{key}}\" 重复","paste_invalid_toast": "无法解析粘贴的环境变量",diff --git a/packages/views/locales/zh-Hant/agents.json b/packages/views/locales/zh-Hant/agents.jsonindex b9827438fa..89f44ff2c0 100644--- a/packages/views/locales/zh-Hant/agents.json+++ b/packages/views/locales/zh-Hant/agents.json@@ -530,6 +530,7 @@"bulk_placeholder": "API_KEY=值\nBASE_URL=https://example.com","bulk_plaintext_notice": "批次編輯時,值以明文顯示。","bulk_unsupported_toast": "\"{{key}}\" 的值無法用文字表示,請用逐條編輯修改",+ "bulk_invalid_key_toast": "批次編輯只支援 API_KEY 這類變數名稱,請用逐條編輯修改 \"{{key}}\"","parse_error_malformed": "第 {{line}} 行不是 KEY=value 格式","parse_error_duplicate": "第 {{line}} 行的 key \"{{key}}\" 重複","paste_invalid_toast": "無法解析貼上的環境變數",