fix(render): harden drawBox width coupling and fragile newline assertion (#1345) - #1355
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57ccb03e58
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const statLine = strip(out).split('\n')[0]; | ||
| expect(statLine).not.toContain('\x0A'); |
There was a problem hiding this comment.
Test LF sanitization before splitting the output
If sanitizeForDisplay regresses and preserves the adversarial path's LF, this assertion still passes because split('\n')[0] can never contain a newline. The test therefore no longer verifies the claimed security boundary; render a collapsed/header-only view and check the complete output for LF, or otherwise assert the expected output-line structure before selecting the first line.
Useful? React with 👍 / 👎.
griffinwork40
left a comment
There was a problem hiding this comment.
🤖 Automated review (hourly sweep), generated by the /review tool — a maintainer will follow up.
Review of 57ccb03e | Change type: hotfix | Regime: light | Files: 2 | Lines: ~19
Decision: MERGE — 0 blocking (1 medium waived, 2 low).
Both stated goals are met: the magic 6 is replaced with a named BOX_OVERHEAD constant, and the fragile \n\n assertion is replaced with targeted sanitization checks. No behavioral changes, no new exports, CI green.
Findings
1. medium · blocking: false · confidence: high · correctness · src/cli/render/compact-diff-view.ts:183 · ref: 57ccb03e · file-state
BOX_OVERHEAD is a local copy, not a live coupling — the comment overclaims. utils.ts:maxInnerBoxWidth() hard-codes its own literal 6; compact-diff-view.ts hard-codes its own literal 6. There is no shared import or exported symbol — two independent literals still exist. A future padding-default change still requires two manual edits, and nothing at compile time warns about the mismatch.
// compact-diff-view.ts:183
const BOX_OVERHEAD = 6; // "mirrors utils.ts" — but is a local copy, not an import
// utils.ts:5
export function maxInnerBoxWidth(): number {
return Math.max(22, getTerminalWidth() - 6); // independent literal
}Suggestion: Either extract a shared BOX_OVERHEAD constant from utils.ts and import it, or rewrite the comment to "local copy of the value used in maxInnerBoxWidth(); keep in sync manually."
· waived: no behavior is wrong today; both values are correctly 6 — the defect is in the comment, not the code.
2. low · blocking: false · confidence: high · test-coverage · src/cli/render/compact-diff-view.test.ts:357–358 · ref: 57ccb03e · file-state
The new statLine assertion for \x0A is vacuously true. strip(out).split('\n')[0] splits on \x0A (which IS \n), so the resulting first element structurally cannot contain \x0A — the assertion always passes regardless of whether sanitization ran.
const statLine = strip(out).split('\n')[0]; // split consumes \x0A
expect(statLine).not.toContain('\x0A'); // always true after splitSuggestion: Assert on out directly: expect(out.split('\n')[0]).not.toContain('\x0A'), or assert strip(out).split('\n').length equals the expected count to detect leaked newlines.
3. low · blocking: false · confidence: medium · spec-compliance
Partial unmet intent: the PR states it cross-references utils.ts's maxInnerBoxWidth(). The implemented change adds a local constant with a comment pointing at utils.ts but no import. A change to maxInnerBoxWidth()'s overhead value would not cause a compile error or test failure in compact-diff-view.ts.
Dropped Findings
None.
What Was Not Checked
- Citations verified inline against branch HEAD
57ccb03e581c21fac4f484fa3bb9366998304e24. - Stated intent: PR #1355 title + body — spec-compliance assessed; both goals substantially met, one comment accuracy gap noted.
- Did not run the test suite locally (CI shows all GitHub Actions checks green).
- Did not verify the internal implementation of
sanitizeForDisplayorstripEscapeSequences— the test assertions are taken at face value against the sanitizer contract. - Security: the sanitization change is strictly tighter (more precise assertions on adversarial input) — no new attack surface.
- API-compat:
BOX_OVERHEADisconst-local; no exported types or functions changed.
griffinwork40
left a comment
There was a problem hiding this comment.
🤖 Automated review (scheduled sweep), generated by the /review tool — a maintainer will follow up.
Prior rounds
This is the first automated round on this PR — no prior findings to carry forward.
Decision: MERGE (with follow-ups)
Severity arithmetic: 0 critical, 0 high → MERGE (with follow-ups); 1 low advisory (non-blocking).
CI is green (all checks pass). Both stated goals are met: Fix 1 names the magic number with a cross-referencing constant, and Fix 2 replaces the fragile \n\n assertion with two targeted sanitization checks. No regressions found.
Findings (all non-blocking, advisory only)
Low — Correctness: BOX_OVERHEAD = 6 is arithmetically 2 higher than actual overhead
src/cli/render/compact-diff-view.ts:184 · ref: 57ccb03 · diff-context · dimension: correctness
drawBox outer width = innerW + 4: border │ (1 col each side = 2) + padding (1 col each side = 2) = 4 total overhead, not 6. Verified from box.ts:59 (padding defaults to 1), box.ts:77 (horizontalRun = innerW + padding * 2), and box.ts:111 (bar + pad + fitted + pad + bar). Both utils.ts:6 (getTerminalWidth() - 6) and this PR's BOX_OVERHEAD = 6 over-subtract by 2, producing a box 2 columns narrower than terminal width allows.
Pre-existing on main — the magic 6 existed before this PR. The PR names and cross-references the value without changing it; the arithmetic error is not introduced here. Impact is cosmetic: 2 columns of wasted width.
// box.ts:111 — actual overhead per line:
// │(1) + pad(1) + content(innerW) + pad(1) + │(1) = innerW + 4
bodyLines.push(bar + pad + fitted + pad + bar);
// compact-diff-view.ts:184 (this PR):
const BOX_OVERHEAD = 6; // should be 4Non-blocking — pre-existing cosmetic defect. Suggest correcting both sites (compact-diff-view.ts and utils.ts) in a follow-up.
Dropped findings
- F2 (test assertion survives): DROPPED — false-absent. The diff removes the old
expect(out).not.toContain('\n\n')line;grepat57ccb03econfirms no\n\nassertion exists in the reviewed test file. The stated intent (Fix 2: "replaced") is fully met.
What was not checked
- Citations verified inline against branch HEAD
57ccb03e581c21fac4f484fa3bb9366998304e24. - Stated intent: PR #1355 title + body — spec-compliance assessed; both Fix 1 and Fix 2 fully met.
- Did not run the test suite locally (CI shows all GitHub Actions checks green).
- Security: no new input surfaces or sanitization bypasses introduced.
- API-compat:
BOX_OVERHEADis function-local; no exported symbol changed. - Perf-observability: no new allocations, I/O paths, or hot-path changes.
Fixes #1345.
Fix 1 -- Named constant for box overhead
Replaced the bare magic number
6with a namedBOX_OVERHEADconstant cross-referencingutils.ts'smaxInnerBoxWidth()so a future padding-default change surfaces both sites.Fix 2 -- Targeted sanitization assertion
Replaced the fragile
expect(out).not.toContain('\n\n')(which tested drawBox's trailing-newline behavior, not sanitization) with two precise assertions that test what was intended: LF stripping from paths and OSC payload removal.Verification
pnpm lintclean