Skip to content

fix(cli): preserve Unicode edge whitespace in Markdown tables - #8915

Merged
morluto merged 3 commits into
morluto:mainfrom
gongfpp:fix/markdown-unicode-edge-whitespace
Nov 6, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
gongfpp:fix/markdown-unicode-edge-whitespace

Conversation

@gongfpp

@gongfpp gongfpp commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8913. Preserve Unicode edge whitespace in rendered Markdown table headers and values instead of collapsing distinct caller-supplied facts.

Problem and expected behavior

"\u00a0name" and "name" previously both rendered as name; values with leading/trailing U+00A0, U+202F, or U+2003 also lost those characters. Rendered table text should retain the original spelling, just like existing ASCII-space/tab protections.

Change and scope

Use the shared table-cell encoder to protect edge whitespace with numeric entities after escaping literal input. Protect Unicode separators (\p{Z}) and BOM alongside the existing ASCII spaces/tabs. Leave other ASCII control characters unchanged rather than introducing character references the renderer may reject. Keep internal whitespace, literal entity strings, JSON output, and paragraph matching unchanged. Locate the two whitespace edges with one forward/backward scan after escaping, rather than retrying a trailing regular-expression match at every suffix. No new dependency or downstream repair path.

Contract and boundary impact

  • Owner: src/cli/cliOutputFormatter.ts; consumers are table headers/body cells, standalone reports, and validation-error field cells through the existing shared encoder.
  • Scope decision: not applicable; narrow fidelity fix within the existing CLI presentation boundary. No new provider, target execution, injection, mutation, or protection recovery.
  • CLI: only rendered Markdown table fidelity changes. MCP/tool schemas, saved Evidence/provenance, package/install metadata, authority and lifecycle behavior are unchanged.
  • Effects: presentation only; no additional target interaction, network access, or configuration changes.

Evidence and regression coverage

  • Extended existing compiled CLI → VitePress → parse5 regression: distinct Unicode/plain keys and values (NBSP, narrow NBSP, em space, line/paragraph separators, and BOM), all-whitespace cells, mixed whitespace, internal NBSP, literal  , and unchanged saved Evidence/JSON. The same test checks standalone reports.

  • Extended the shared validation-error/redaction regression with NBSP/tab/narrow-NBSP edges while preserving secret redaction and JSON values.

  • Before the production fix: compiled CLI selection had 1 failed / 8 passed, showing stripped Unicode and key/value collisions. The updated validation-error consumer separately failed on the unprotected NBSP/tab edge (1 failed / 3 passed).

  • Applicable boundary regressions: raw identity/normalization, empty and unusual source names, and public result/error projection. No lifecycle behavior changes.

  • Representative outcome: rendered "\u00a0name" now remains distinct from "name"; "\u202fvalue\u202f" retains both edge characters.

  • Added 10 shared-encoder cases for empty/all-whitespace input, internal spacing, emoji, escaped entity text, NUL/CRLF, and VT/FF barriers.

  • P1 performance follow-up: added a compiled CLI → VitePress → parse5 regression with 240,000 internal mixed NBSP/narrow-NBSP/em-space characters in both a header and a value. The parent process enforces a 20-second CLI deadline, so a synchronously blocked child cannot swallow the timeout. The previous head exceeded that deadline; the fixed regression passed in 610 ms locally, retaining the exact header/value and saved Evidence.

  • Local producer measurement on Node 24.22.1: an 80,000-NBSP internal run took 3,516 ms before and 0.046 ms after, with unchanged encoded output. These are individual local observations, not a portable timing guarantee or the test's performance threshold.

Validation performed

Node 24.22.1 / npm 11.16.0, macOS 26.6.2 arm64. Validated commit: f62a9ad7eddac21a2ba897e945bfa86463088ade (pre-commit hooks left the tested file contents unchanged).

  • npm run test:focused -- tests/boundary/cli/cliOutputFormatter.test.ts tests/boundary/cli/markdownLiteralCells.test.ts tests/boundary/cli/markdownArgumentErrors.test.ts tests/boundary/cli/markdownNestedFacts.test.ts tests/acceptance/markdownMissingSelectionWindow.test.ts — 34 passed, 5 files; builds the current runtime first.
  • npm run check — passed: typecheck, lint, formatting, Knip, metadata, architecture guards, production reachability report, and typed lint (no errors; repository warnings/advisories remain).
  • git diff --check — passed.

Compatibility, safety, and release

No API/schema migration, generated metadata, dependency, or release-version change. No external reverse-engineering provider is involved. Windows/Linux and the full repository test suite were not run locally; CI remains authoritative for those lanes. AI assistance was used. The human owner has completed the review and author readiness declaration; no maintainer approval is claimed.

Author readiness

Human owner: @gongfpp

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no new actionable issue was found.

Summary

Preserves Unicode whitespace at Markdown table edges through the shared cell encoder.

  • CLI Markdown tables keep Unicode whitespace at cell edges.

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

Comment thread src/cli/cliOutputFormatter.ts Resolved
@gongfpp
gongfpp marked this pull request as ready for review November 4, 2026 15:15
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-04T15:15:18.550192Z
We couldn’t complete this review. Comment @codex review to try again.
eeca6cc Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gongfpp

gongfpp commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

CI triage for f62a9ad7e, run 41865059965:

  • Portable tests failed on exactly one test: tests/acceptance/process/processFinalization.test.ts > captures a cooperative finalizer through the compiled CLI workflow, Test timed out in 20000ms. The job reported 36398 passed, 1 failed, 183 skipped over a 4193s run.
  • The same parameterized case has an MCP variant in the same file that passed at 18.98s against the same 20s limit, which points at runner load rather than the change under test.
  • This diff only touches src/cli/cliOutputFormatter.ts and its tests: Markdown table cell encoding. Process finalization does not go through it.
  • CI required failed together with Portable tests, and shards 5/8 and 6/8 were cancelled by the same run; those shards were not evaluated and are not counted as passing here.

I cannot re-run the failed jobs from this account (rerun-failed-jobs returns 403 Must have admin rights to Repository), so a maintainer re-run is needed to confirm the timeout is environmental.

@gongfpp

gongfpp commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed onto 808491685 (plain merge, no conflicts — upstream has not touched any of the three files this PR changes since 89317a39f).

On the red at f62a9ad7e: the only failing lane was Test shard (8/8) → tests/acceptance/process/processFinalization.test.ts > captures a cooperative finalizer through the compiled CLI workflow, Test timed out in 20000ms. That is a compiled-CLI acceptance test this PR does not touch, and Source tests / Static checks were green in the same run (job 126700584948). Portable tests and CI required fail only because they aggregate that shard.

Local check after the merge (Windows 11 x64, Node 22.22.2, dist/ rebuilt from this head):

npx vitest run tests/boundary/cli/markdownLiteralCells.test.ts \
  tests/boundary/cli/markdownArgumentErrors.test.ts \
  tests/boundary/cli/cliOutputFormatter.test.ts
Test Files  3 passed (3)
     Tests  29 passed (29)

@gongfpp

gongfpp commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Checked that this is still needed against current main, since three Markdown-related fixes landed in cliOutputFormatter.ts after this branch was cut (e416ce198 validation error cells, 1dc9e8774 marker-only paragraphs, 675d4076d oracle cleanup).

Method: clean worktree on upstream/main at a7574d427, put only this PR's three test files on top of the unmodified main source, run them.

$ git checkout -B local/probe-8915-on-main upstream/main   # a7574d427
$ git checkout bef1a43c3 -- \
    tests/boundary/cli/markdownLiteralCells.test.ts \
    tests/boundary/cli/cliOutputFormatter.test.ts \
    tests/boundary/cli/markdownArgumentErrors.test.ts
$ ./node_modules/.bin/vitest run tests/boundary/cli/markdownLiteralCells.test.ts \
    tests/boundary/cli/cliOutputFormatter.test.ts \
    tests/boundary/cli/markdownArgumentErrors.test.ts

 Test Files  3 failed (3)
      Tests  7 failed | 22 passed (29)

The seven failures are exactly the ones this PR adds or tightens — five parameterised edge-spacing cases in cliOutputFormatter.test.ts (" \t ", " 🙂", " \t name ", " \u0000 ", " \r\n "), plus one added assertion each in markdownArgumentErrors.test.ts (retains upstream Markdown literal-cell protections after redaction) and markdownLiteralCells.test.ts (preserves literal Evidence keys and values when Markdown tables are rendered). Without the cliOutputFormatter.ts change, those are red on main; with it, all 29 pass.

So the other two fixes touch different paths and the gap this PR closes is still open on main.

CI on the current head is green after the refresh to 808491685 (Static checks, Source tests, CI required, Portable tests).

@morluto
morluto merged commit 08bc521 into morluto:main Nov 6, 2026
45 checks passed
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Markdown tables lose Unicode edge whitespace and collapse distinct keys

2 participants