fix(report): align code frames to terminal display columns

Merged
RU
9d ago
+67-3

Failure code-frame carets use UTF-16 character counts as terminal columns. A CJK identifier before the failing expression shifts the caret left, and wide source text can wrap despite the line being clipped.

  • Measure the sanitized source prefix with the existing terminal-width helper.
  • Clip source with the existing grapheme-aware column helper; omit the caret when its token is clipped away.
  • Cover ASCII, tabs, CJK, combining marks, emoji sequences, and clipped locations; document the behavior and add a patch changeset.

Verified

Ran it locally: yes.

Using Node 24.18.0 and the existing dependencies:

node node_modules/vitest/vitest.mjs run tests/unit --maxWorkers=1

2,548 runner unit tests pass (one skipped), plus runner and testbed typechecks, rebuild, lint, and diff checks. On main, five new width cases fail while the ASCII and tab controls pass; all seven pass after the fix.

Ran the real rebuilt public CLI in an 80-column PTY using a deterministic noop-engine fixture:

node node_modules/e2e/dist/cli/bin.js run wide.e2e.ts --config e2e.config.ts

Both deliberately failing tests exit 1. The saved source location remains line 2, column 53.

Actual CLI outputBeforeAfter
Caret terminal column after CJK identifier6162 (correct)
Maximum printed source-row width at 80 columns9579

Before:

      2| test('wide caret', async () => { const 界 = 1; throw new Error('wide c…
       |                                                     ^

After:

      2| test('wide caret', async () => { const 界 = 1; throw new Error('wide …
       |                                                      ^

The fixture config:

import { defineEngine } from 'e2e/engine';
export default { workers: 1, targets: [{ name: 'headless', platform: 'test',
  engine: defineEngine({ name: 'noop', version: '1', spiVersion: 1 }) }] };

Its tests/wide.e2e.ts:

import { test } from 'e2e';
test('wide caret', async () => { const 界 = 1; throw new Error('wide control'); });
test('wide clipping', async () => { throw new Error('界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界'); });

The baseline uses an existing built runner whose code-frame producer is byte-identical to main.

Also ran the unchanged testbed reporter stress suite with installed Chrome through the public CDP connector, using a fresh temporary profile and one worker. Its expected deliberate failure run exited 1: seven failures/timeouts, six successes including the flaky case, and two skips. The browser, temporary profile, and scratch config were cleaned up.

Repository-wide pnpm check and the complete mobile/browser integration gates were not rerun in this filtered dependency setup. The existing main download assertion discussed in #934 remains outside this change.

CI follow-up at 05badcf2e8bb6e55c81550ff0170385d5d84b213:

Transplanted the already merged upstream #934 fix: parse and validate the actual positive remaining download wait budget, capped at500ms, rather than assume the message always says500ms. Full web-platform integration:40 tests passed on each branch; core/web builds and focused lint pass. Controls reject invalid budgets, too-early trigger timing and malformed messages.

This addresses a shared baseline test defect without changing production behavior or adding expected-failure exemptions. GitHub CI on the updated head remains the final platform check.