Skip to content

CSV export: opt-in values: true writes raw cell values (#2648) - #2666

Merged
h-a-n-a-s-h-i merged 3 commits into
storytold:mainfrom
Harrison-Booth:gc-csv-values
Oct 30, 2026
Merged

h-a-n-a-s-h-i merged 3 commits into
storytold:mainfrom
Harrison-Booth:gc-csv-values

Conversation

@Harrison-Booth

@Harrison-Booth Harrison-Booth commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong: automation callers (MCP, CLI) of file.exportCsv only get displayed text (currency strings, rounded numbers), which loses data. Excel's own Save As CSV writes displayed text too, so that default is Excel parity and is unchanged.

Fix: file.exportCsv takes an optional values param. values: true writes raw values: numbers at full precision, dates and times as ISO 8601, TRUE/FALSE, error text, text as stored. Without it, or with values: false, the output is the same bytes as before. The param is in the command's params doc (so MCP and the catalog show it) and in docs/file-format-parity.md, which also said we wrote raw values (stale).

Verified: cargo fmt --check only. The new test (tests.rs) checks the default export equals Save As CSV bytes, values: false equals the default, and the raw output for currency, rounded, date, datetime, time, bool, quoted text and error cells. Not run locally (fork CI runs the suite). Not re-checked in real Excel: the test asserts only GridCraft's own output; Excel's displayed-text behaviour is as recorded in earlier observation.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • CSV export now supports an option to export raw cell values, preserving full numeric precision and formatting dates and times in ISO 8601.
    • By default, CSV exports continue to use the values displayed in cells. Exports retain the workbook’s CSV separator when available.
  • Documentation
    • Updated the file-format guide with details about raw-value CSV exports.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d8c5f58 and f4f48f3.

Files selected for processing: 5
  • crates/engine/src/cmd/file.rs
  • crates/engine/src/io.rs
  • crates/engine/src/tests.rs
  • crates/numfmt/src/lib.rs
  • docs/file-format-parity.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

file.exportCsv now accepts values. When omitted or false, it retains displayed-value export behavior. When true, it exports active-sheet values with raw numeric precision and ISO date or time formatting.

Changes: CSV export

Layer / File(s) Summary
Date-format shape
crates/numfmt/src/lib.rs
NumberFormat::date_shape identifies whether a selected date format displays calendar parts, time parts, or both. It returns None for non-date and elapsed-time formats.
Raw-value CSV serialization
crates/engine/src/io.rs, crates/engine/src/cmd/file.rs, crates/engine/src/tests.rs, docs/file-format-parity.md
file.exportCsv uses csv_values_bytes when values is true. The serializer uses the workbook delimiter or a comma by default, writes text as stored, and formats applicable dates and times as ISO 8601. Tests cover both export modes, and the parity document records the option.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ExportCsv as file.exportCsv
  participant CsvValuesBytes as csv_values_bytes
  participant Workbook
  ExportCsv->>CsvValuesBytes: Pass workbook when values is true
  CsvValuesBytes->>Workbook: Read active-sheet values and export settings
  Workbook-->>CsvValuesBytes: Return values, delimiter, and date metadata
  CsvValuesBytes-->>ExportCsv: Return CSV bytes
Loading

Suggested reviewers: echelon, marcoarnulfo, mouhand-kaddo

Merge Risk: Minimal · up to f4f48

The opt-in export preserves raw values as documented. No actionable merge-blocking issue remains after normal checks.

Security architecture risk: Moderate · up to f4f48

Default exports remain unchanged, and raw output requires an explicit request. However, raw export can expose formula-leading text previously hidden by display formatting. A recipient opening that output in a spreadsheet may interpret those fields as formulas. The effect is limited to the requested export and depends on how the recipient consumes it; no broader privilege expansion was established.

Retained concerns

  • Medium · security · inferred: Opt-in raw CSV export can newly expose formula-leading stored text that display formatting previously masked. CSV quoting preserves field structure but does not prevent a downstream spreadsheet from interpreting that text as a formula. This is a conditional change in effective exposure, not a claim that all CSV formula exposure originated in this PR.
Security review details

Security Blast Radius

  • inferred — The supported attack scope is attacker-influenced stored text in the exported sheet, an explicit raw-export request, and a recipient application that evaluates CSV fields as formulas. No new execution authority, cross-tenant access, or additional service exposure was established.

Security Findings and Attack Paths

  • inferred — The retained injection finding has a narrower PR-specific case: stored text such as =1 can display as safe=1 under a text format such as ;;;"safe"@, but raw export emits =1. Spreadsheet interpretation is downstream and was not demonstrated here. Formula-leading text already visible under ordinary formatting was exportable before this PR; that broader exposure predates the change.

Trust Boundaries and Controls

  • observed — The registered command requires an open document, and raw mode requires an explicit boolean true. These limit activation but do not neutralize formula text. The inspected registration and handler do not establish the authentication or authorization policy of external command callers.

Resilience and Maintainability Implications

  • observed — The new serializer completes before the existing output-write transition. That writer uses an exclusive temporary file, writes and flushes it, then renames it, with cleanup on handled failures. The PR does not introduce a separate partial-write or rollback mechanism; crash recovery and cross-platform replacement semantics were not independently verified.

Hardening Proposals

  • proposed — Keep raw preservation distinct from spreadsheet-safe consumption: document the formula-interpretation boundary and consider a separately named safe-export policy or downstream import-as-text handling. Silently altering stored text in raw mode would conflict with its stated contract.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: opt-in raw cell values for CSV export with values: true.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@FredApps FredApps 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.

Reviewed at SHA f4f48f3.

What it does: file.exportCsv takes an optional values param (#2648). With values: true it writes raw cell values for automation: numbers at full precision, date/time cells as ISO 8601, TRUE/FALSE, error text, text as stored. Without it, or with values: false, it takes the unchanged save_bytes path, so the default stays byte-identical to Save As CSV (displayed text). Supporting pieces: io::csv_values_bytes and iso, and NumberFormat::date_shape in numfmt, which reports whether the section that formats a value shows calendar and/or time parts and returns None for non-dates and for elapsed codes like [h]:mm; docs and the command's params text are updated.

Checked (whole diff read): the new path only triggers for ext == "csv" with a truthy values; non-finite numbers and non-numbers fall back to the existing text rendering; date vs time-only vs date-time is decided from the format section that applies to the value (so [>=3]yyyy-mm-dd;[<3]hh:mm picks per value), milliseconds are appended only when non-zero, elapsed formats stay numeric (1.5); the test pins default == file.saveBytes csv bytes, values:false == default, and a 13-cell raw row including date, datetime, time-only, 1-day time, [h]:mm, conditional sections, a comma string and an error.

Not verified: I did not run the tests (the PR says only cargo fmt --check was run locally); the hosted gate is green at this head. Time-only cells larger than one day print the time of day (a value of 1 shows 00:00:00), which matches what the format displays but loses the day count; fine for this opt-in mode but worth knowing.

alehel added a commit to alehel/gridcraft that referenced this pull request Oct 30, 2026
alehel added a commit to alehel/gridcraft that referenced this pull request Oct 30, 2026
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 6f77f68 into storytold:main Oct 30, 2026
6 checks passed
@echelon

echelon commented Oct 30, 2026

Copy link
Copy Markdown
Member

Landed in main (75f7056). Thank you for the contribution, @Harrison-Booth!

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.

4 participants