Skip to content

Daily Test Coverage Improver - Comprehensive CSV parsing tests (parseCSV & exportCSVWithFormattingRules)#7941

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test/csv-util-parsecsv-coverage-ab18151ef5b6d63c
Draft

Daily Test Coverage Improver - Comprehensive CSV parsing tests (parseCSV & exportCSVWithFormattingRules)#7941
github-actions[bot] wants to merge 1 commit into
mainfrom
test/csv-util-parsecsv-coverage-ab18151ef5b6d63c

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Added comprehensive test coverage for previously untested CSV utility functions in react/src/helper/csv-util.ts, focusing on parseCSV and exportCSVWithFormattingRules.

Goal and Rationale

The csv-util.ts file had 41.66% test coverage with two critical functions completely untested:

  • parseCSV: RFC 4180-compliant CSV parser handling complex edge cases (quoted fields, escaped quotes, line breaks within fields)
  • exportCSVWithFormattingRules: High-level export function combining CSV generation with download functionality

These functions are used throughout the application for importing/exporting user data, making comprehensive testing crucial for data integrity and preventing silent corruption bugs.

Approach

Added 24 new test cases covering:

parseCSV tests (21 cases):

  • UTF-8 BOM handling (prevents broken header matching)
  • RFC 4180 quoted field parsing:
    • Commas inside quoted fields
    • Escaped double quotes (""")
    • Line breaks inside quoted fields
  • Line ending variations (LF vs CRLF)
  • Whitespace trimming behavior
  • Empty line handling
  • File termination edge cases (with/without trailing newline)
  • Sparse rows (missing values)
  • Error handling for malformed CSV (unterminated quotes)
  • Empty fields and special characters in headers
  • Complex real-world scenarios

exportCSVWithFormattingRules tests (3 cases):

  • Export with formatting rules applied
  • Export without formatting rules
  • UTF-8 BOM inclusion verification

Impact Measurement

Test Coverage Results

Metric Before After Improvement
csv-util.ts Statements 41.66% 98.8% +57.14%
csv-util.ts Branches 33.33% 93.75% +60.42%
csv-util.ts Functions 56.25% 100% +43.75%
csv-util.ts Lines 43.03% 98.73% +55.7%
Overall React Statements 5.48% 5.6% +0.12%
Overall React Lines 6.68% 6.83% +0.15%

Test Suite Results

  • 31 total tests in csv-util.test.ts (up from 7)
  • All tests passing
  • No linting errors
  • Code formatted with Prettier

Trade-offs

Complexity: Added ~230 lines of test code, but the comprehensive coverage significantly reduces risk of CSV parsing bugs that could corrupt user data.

Maintenance: Tests are well-documented and follow existing patterns, making them easy to maintain. Edge cases are explicitly named for clarity.

Validation

All tests pass locally:

✓ src/helper/csv-util.test.ts (31 tests) 28ms
  Test Files  1 passed (1)
  Tests  31 passed (31)

Coverage verified through Vitest's V8 provider showing 98.8% statement coverage for csv-util.ts.

Reproducibility

Setup

cd /home/runner/work/backend.ai-webui/backend.ai-webui
pnpm install --ignore-scripts
pnpm run relay

Run Tests

cd react
pnpm run test src/helper/csv-util.test.ts

Generate Coverage

cd react
pnpm run test --coverage
# Check coverage/lcov-report/index.html for detailed report

Expected Results

  • All 31 tests should pass
  • csv-util.ts should show ~98.8% statement coverage
  • No linting or formatting errors

Future Work

Additional coverage opportunities identified in src/helper/:

  • bulkUserCSV.ts (0% coverage) - CSV parsing for bulk user import
  • loginConfig.ts (0.71% coverage) - Login configuration parsing
  • multiAgentSessionAuth.ts (0% coverage) - Authentication utilities

These are good candidates for future test coverage improvements.


What Happens Next

  • Maintainers review the test cases for correctness and completeness
  • Once merged, the next workflow run will select a different coverage improvement area
  • Phase 3 will continue systematically improving test coverage across the repository

AI generated by Daily Test Coverage Improver

…ttingRules

- Add 24 new test cases for parseCSV function covering:
  - UTF-8 BOM handling
  - RFC 4180 quoted field parsing (commas, quotes, line breaks)
  - CRLF line ending support
  - Whitespace trimming
  - Empty line handling
  - Error handling for malformed CSV
  - Edge cases (sparse rows, empty fields, special characters)
- Add 3 test cases for exportCSVWithFormattingRules
- Improve csv-util.ts coverage from 41.66% to 98.8%
- All 31 tests passing

Coverage impact:
- csv-util.ts: 41.66% → 98.8% statements (+57.14%)
- Overall React: 5.48% → 5.6% statements (+0.12%)
- Overall React lines: 6.68% → 6.83% (+0.15%)
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.

0 participants