Skip to content

[Bug]: Test suites assert hardcoded English strings and fail on non-English locales #440

Description

@AndersHsueh

What happens

pnpm verify fails at test:capabilities on any machine whose locale is not English. The failures are not caused by the code under test: they are assertions that compare against hardcoded English strings while the product returns a localized string.

$ locale
LANG="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"

 Test Files  4 failed | 228 passed (232)
      Tests  29 failed | 5557 passed | 17 skipped (5603)

Affected suites

File Failing cases
packages/tui/test/unit/tui-app.test.ts 15
packages/tui/test/unit/tui-session-mutation-panels.test.ts 13
packages/tui/test/unit/tui-session-history-flow.test.ts 1
packages/tui/test/unit/update-application.test.ts 1
packages/tui/test/unit/tui-status-line-items.test.ts 1

The last one is worth separating out, because it is not caused by any local change — it reproduces on upstream main unmodified:

$ git checkout upstream/main
$ npx vitest run packages/tui/test/unit/tui-status-line-items.test.ts

AssertionError: expected '\n轻量模式 │ ~/repo │ ◇ Ship status line …' to contain 'Lightweight'
 Test Files  1 failed (1)
      Tests  1 failed | 94 passed (95)

The assertion expects Lightweight; the status line renders 轻量模式. This one arrived with #436 (opt-in lightweight context mode).

Why CI does not catch it

The Source verification workflow runs in an English locale, so every one of these assertions passes there. A contributor working in any other locale cannot get a green local pnpm verify, which makes it impossible to tell whether a change they made broke something.

Suggested direction

I am not certain of the intended fix, so I would rather report the symptom than guess. Two options that look reasonable:

  1. Assert on a locale-independent key (an i18n message id) instead of the rendered string.
  2. Pin the locale for the affected suites, so they test one language deliberately rather than inheriting the developer's.

Either is fine with me — I mainly wanted to flag that the current state makes local verification unusable outside English.

中文摘要

现象:任何非英文 locale 的机器上跑 pnpm verify 都会在 test:capabilities 失败。原因不是被测代码有问题,而是断言里硬编码了英文字符串,而产品返回的是本地化后的字符串。

影响范围:5 个测试文件共 31 例(tui-app 15、tui-session-mutation-panels 13、其余各 1)。

其中 tui-status-line-items.test.ts 值得单独说明:它不是任何本地改动引起的,在完全未修改的上游 main 上同样复现——断言期望 Lightweight,状态栏实际渲染 轻量模式。它随 #436(opt-in 轻量上下文模式)引入。

为什么 CI 看不见:Source verification workflow 跑在英文 locale 下,这些断言全部通过。结果是任何非英文环境的贡献者都拿不到本地绿的 pnpm verify,也就无法判断自己的改动是否真的弄坏了东西。

建议方向(我不确定哪种是本意,所以只报告症状不猜方案):一是对 i18n message id 而不是渲染后的字符串做断言;二是给受影响的测试套件固定 locale,让它们确定地只测一种语言。两者我都接受——主要是想指出当前状态让本地验证在英文环境之外不可用。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions