Skip to content

fix(host-runtime): preserve UTF-8 filenames in workspace index - #1914

Merged
vastsa merged 2 commits into
vastsa:mainfrom
FuYukiH:fix/workspace-index-utf8
Oct 28, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
FuYukiH:fix/workspace-index-utf8

Conversation

@FuYukiH

@FuYukiH FuYukiH commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Git can split a UTF-8 filename between stdout chunks. The workspace index decoded each Buffer separately, replacing partial characters with �; file mentions and searches then received paths that did not exist.

Use Node's continuous UTF-8 stream decoder. Add deterministic tests for split 2-, 3-, and 4-byte characters through the index/search APIs, and exercise Unicode file selection in the real Composer renderer. Its hidden Windows fixture uses offscreen painting so the animation frames it awaits can advance.

A real Git listing of 2,500 CJK filenames reproduced two corrupted paths before the change. The fixed production index retained all 2,500, and search → reference resolution → file preview succeeded.

Validation on Windows x64, Node 24.14.0, Electron 43.6.0:

  • Focused host-runtime suites (fs-index-encoding, fs-index, workspace-files): 8 passed, 3 symlink tests skipped because Windows symlink privileges were unavailable. Used --testTimeout=30000 --hookTimeout=60000 for the large temporary trees.
  • Composer file-search and reference-display tests: 7 passed, including the real Electron Unicode selection flow.
  • node scripts/e2e-composer-autocomplete.mjs: all 4 layout scenarios passed.
  • pnpm build:js, Desktop typecheck, pnpm lint, pnpm docs:check, policy sync, and PR-base checks passed.

Candidate: 6e53a3c6fa9b5499a125cba03e4821363aaef5a0; base: 5aa253883c4e34fd65d31c434256d424c352bf0b. The IPC spec and E2E-102a expectations are updated.

Git stdout can split a filename in the middle of a UTF-8 character.
Decoding each Buffer independently corrupted those names in the cached
workspace index, so file mentions and searches could no longer find them.

Decode stdout as a continuous UTF-8 stream. Cover split two-, three-, and
four-byte characters through the index and search APIs, and document the
filename preservation contract.

Exercise Unicode file selection in the real renderer. Offscreen painting
lets its hidden Windows fixture advance the animation frames it awaits.

@muzimu217 muzimu217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the diff; the fix is right. String(chunk) decoded each Buffer independently, so a multi-byte character straddling a chunk boundary became U+FFFD; setEncoding("utf8") switches stdout to Node's continuous StringDecoder, which holds an incomplete sequence until the next chunk. The MAX_GIT_BUFFER comparison is unchanged in kind (string length before and after), so no accounting shift. The test is the right shape: deterministic chunk sizes 1/2/3/7 cover 2-, 3- and 4-byte sequences split at every position, and asserting both the index and searchWorkspaceFiles closes the loop through the second consumer.

One sibling site has the same defect, and it also handles raw UTF-8 paths: packages/host-runtime/src/workspace-diff.ts:59 accumulates String(d) from git status --porcelain=v1 -z (:241-242). With -z Git emits paths as raw bytes with no core.quotePath escaping, so a non-ASCII file name split across stdout chunks corrupts the same way — and there the mangled string becomes a status row path, which then fails to resolve against the index. Same one-line fix (child.stdout.setEncoding("utf8")), and the existing fs-index-encoding test shape can be reused with a mocked status child.

Not a blocker for this PR — the index corruption you fixed is the user-visible one — but it is the same class, so worth either folding in or filing as a follow-up before it is rediscovered through a diff view.

@vastsa
vastsa merged commit 605d413 into vastsa:main Oct 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants