Skip to content

A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.

test(i18n): 断言中文措辞的测试固定语言,不再随系统语言和本机记下的语言变化

chipfighterf2a5761e25e6
diff --git a/docs/plan.md b/docs/plan.md
index 7db73e2..59e21bc 100644
--- a/docs/plan.md
+++ b/docs/plan.md
@@ -479,5 +479,6 @@ P1 通过后,再按用户的节奏一步步探索改写。
- 单元测试检查两种语言的条目一一对应、占位的 `{名字}` 也一致。
- **插件服务返回的文字**:报错和结果按面板带来的语言给出;改写失败的原因改成代码,由面板翻译;和用户设置冲突的报错带一个文字键,面板和命令行各按自己的语言显示。
- **面板认模型索要**:英文说明让模型回复“need IMG-004”,面板也认带引号的写法。
+- **测试**:环境变量 `CAM_LANG=zh|en` 可以固定语言(测试、开发用)。断言中文措辞的测试都固定成中文:第一次推到 CI 时,这些测试在英文系统上全部失败,而且在本机也会随记下的语言变化。
- **已知代价**:同一个任务中途切换 Codex 的语言,说明文字会变,模型那边缓存的上下文要重算一次。
- **验证**:`v01-placeholder-selftest.ts --lang en` 用同样的五轮对话检查英文说明:模型不收回之前的回答,被问到没说过的细节时回复“need IMG-xxx”。
diff --git a/plugin/src/language.ts b/plugin/src/language.ts
index cf83392..fe224cb 100644
--- a/plugin/src/language.ts
+++ b/plugin/src/language.ts
@@ -2,7 +2,7 @@
// v0.1; Chinese of any region gets Simplified Chinese, every other language gets English). The panel learns Codex's
// interface language and reports it with its calls; it is kept in the data directory, where the engine (the text for
// the model) and the plugin service (the tab's title) read it. Until a panel has reported one, the system language
-// counts; the command line always follows the system language.
+// counts; the command line always follows the system language. CAM_LANG=zh|en (tests, development) fixes the language.
// Input: language tags (BCP 47 or POSIX, e.g. "zh-CN", "zh_TW.UTF-8", "en-US"), the environment, the data directory.
// Output: "zh" | "en"; <data dir>/language.json = { "lang": "zh", "source": "codex" | "system", "at": "…" }.
@@ -24,6 +24,7 @@ export function langOf(tag: unknown): Lang | null {
// POSIX locale variables when set (macOS, Linux, some Windows shells), else what the runtime reports (Windows).
export function systemLang(env: NodeJS.ProcessEnv = process.env): Lang {
+ if (env.CAM_LANG === "zh" || env.CAM_LANG === "en") return env.CAM_LANG;
for (const name of ["LC_ALL", "LC_MESSAGES", "LANG"]) {
const lang = langOf(env[name]);
if (lang) return lang;
@@ -59,5 +60,7 @@ export function rememberLang(lang: Lang, source: LangSource, file = languageFile
}
export function currentLang(file = languageFileOf()): Lang {
+ const fixed = process.env.CAM_LANG;
+ if (fixed === "zh" || fixed === "en") return fixed;
return storedLang(file)?.lang ?? systemLang();
}
diff --git a/spike/src/install.test.ts b/spike/src/install.test.ts
index 6aed2a1..d4d0f84 100644
--- a/spike/src/install.test.ts
+++ b/spike/src/install.test.ts
@@ -9,6 +9,10 @@ import test from "node:test";
import { enableMcpServer } from "../../plugin/src/codexconfig.ts";
import { needsNoProxy, planInstall, planUninstall, pluginStatus, SERVER_NAME } from "../../plugin/src/install.ts";
+// These tests check the Chinese wording: the language is fixed, so neither the system's language nor one a panel
+// reported on this machine decides it (v0.1-14).
+process.env.CAM_LANG = "zh";
+
const CONFIG = 'model = "gpt-6-sol"\n\n[features]\nview_image = true\n\n[projects.\'d:\\\\work\']\ntrust_level = "trusted"\n';
const base = { port: 17891 };
const proxied = { httpProxy: "http://127.0.0.1:8888", noProxy: null };
diff --git a/spike/src/language.test.ts b/spike/src/language.test.ts
index 6e2cd44..8879d12 100644
--- a/spike/src/language.test.ts
+++ b/spike/src/language.test.ts
@@ -37,6 +37,8 @@ test("the language a panel reports is kept, with where it came from; without one
assert.equal(readFileSync(file, "utf8"), written, "unchanged: not written again");
rememberLang("zh", "system", file);
assert.deepEqual([currentLang(file), storedLang(file)?.source], ["zh", "system"]);
+ process.env.CAM_LANG = "en";
+ try { assert.deepEqual([currentLang(file), systemLang({ CAM_LANG: "en", LANG: "zh_CN.UTF-8" })], ["en", "en"], "CAM_LANG fixes it (tests, development)"); } finally { delete process.env.CAM_LANG; }
});
test("the plugin's texts exist in both languages with the same {values}", () => {
diff --git a/spike/src/plugin-server.test.ts b/spike/src/plugin-server.test.ts
index 5545b38..62762eb 100644
--- a/spike/src/plugin-server.test.ts
+++ b/spike/src/plugin-server.test.ts
@@ -12,6 +12,10 @@ import { fileURLToPath } from "node:url";
import { callTool, fromModel, PANEL_MIME, PANEL_URI, readResource, threadOf, TOOLS } from "../../plugin/src/plugin-server.ts";
import { line, red, sampleSessions, startThread, THREAD, turn, upload } from "./testfixtures.ts";
+// These tests check the Chinese wording: the language is fixed, so neither the system's language nor one a panel
+// reported on this machine decides it (v0.1-14).
+process.env.CAM_LANG = "zh";
+
const here = dirname(fileURLToPath(import.meta.url));
const modelMeta = { callId: "exec-1", "x-codex-turn-metadata": { thread_id: THREAD, turn_id: "t9" } };
const panelMeta = { thread_id: THREAD, threadId: THREAD, progressToken: 3 };
diff --git a/spike/src/proxy.test.ts b/spike/src/proxy.test.ts
index 481a0fb..6e10658 100644
--- a/spike/src/proxy.test.ts
+++ b/spike/src/proxy.test.ts
@@ -12,6 +12,10 @@ import { describeBody, hasUnchecked, hasUnsafeInteger, imageSizesOf, macProxy, o
import { writeSelection } from "../../plugin/src/selection.ts";
import { png } from "./testkit.ts";
+// These tests check the Chinese wording: the language is fixed, so neither the system's language nor one a panel
+// reported on this machine decides it (v0.1-14).
+process.env.CAM_LANG = "zh";
+
const none = () => null;
test("outbound proxy comes from the environment, then Windows settings", () => {
diff --git a/spike/src/setup.test.ts b/spike/src/setup.test.ts
index 0b9f135..c9c1d00 100644
--- a/spike/src/setup.test.ts
+++ b/spike/src/setup.test.ts
@@ -12,6 +12,10 @@ import { callTool, resetSetupBaseline } from "../../plugin/src/plugin-server.ts"
import { connectDirectly, pluginGone, useEngine, usesEngine } from "../../plugin/src/setup.ts";
import { sampleSessions, THREAD } from "./testfixtures.ts";
+// These tests check the Chinese wording: the language is fixed, so neither the system's language nor one a panel
+// reported on this machine decides it (v0.1-14).
+process.env.CAM_LANG = "zh";
+
const CONFIG = 'model = "gpt-6-sol"\n\n[features]\nview_image = true\n\n[plugins."codex-attachment-manager@codex-attachment-manager"]\nenabled = true\n';
function tempHome(t: TestContext): { home: string; data: string } {