Skip to content

feat: Add --checksum flag for SHA-256 result set hashing (issue #204) - #215

Merged
vmvarela merged 5 commits into
masterfrom
feature/checksum-flag-issue-204
Aug 2, 2026
Merged

feat: Add --checksum flag for SHA-256 result set hashing (issue #204)#215
vmvarela merged 5 commits into
masterfrom
feature/checksum-flag-issue-204

Conversation

@vmvarela

@vmvarela vmvarela commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Closes #204.

Summary

Adds a flag that computes the SHA-256 hash of the result set and emits it to stderr as checksum: <hash>. The hash covers only stdout output (the result set), making it compatible with all output formats and other stderr-writing flags.

Changes

  • src/args.zig: Flag parsing, ParsedArgs.checksum field, help text
  • src/main.zig: BufferWriter struct with custom vtable for output buffering, emitChecksum() function using std.crypto.hash.sha2.Sha256
  • src/completions.zig: Added --checksum to bash, zsh, and fish completion scripts
  • build.zig: 25 integration tests (204a-204y) covering all output formats, --output file, --disk, --save, --repl, inspect modes, --explain, --verbose, --null-value
  • README.md: Flag documentation and usage example
  • docs/sql-pipe.1.scd: Man page documentation and example

Behavior

  • Works with all output formats: CSV, TSV, JSON, NDJSON, XML, HTML, SQL, table, markdown
  • Works with --output (hashes the file content), --disk, --save, --repl, --explain, --verbose, --null-value
  • Skipped in inspect modes (--columns, --validate, --sample, --stats, --schema) since they don't produce result sets
  • All 388+ tests pass

- Add --checksum flag to args.zig with parsing and help text
- Implement BufferWriter in main.zig with custom vtable for output buffering
- Add emitChecksum() function computing SHA-256 via std.crypto.hash.sha2.Sha256
- Wire checksum into all output paths: CSV/TSV/JSON/NDJSON/XML/HTML/SQL/table/markdown
- Add --checksum to bash, zsh, and fish completion scripts
- Add 25 integration tests (204a-204y) covering all formats and flag combinations
- Update README.md and docs/sql-pipe.1.scd with documentation
@vmvarela vmvarela changed the title Add --checksum flag for SHA-256 result set hashing (issue #204) feat: Add --checksum flag for SHA-256 result set hashing (issue #204) Aug 2, 2026
@github-actions github-actions Bot added the type:feature New functionality label Aug 2, 2026
- Remove global current_buffer_writer anti-pattern
- Simplify BufferWriter using std.Io.Writer.Allocating
- Extract computeChecksum() and emitChecksum() helpers
- Thread stderr_writer through call chain
- Add 4 unit tests for computeChecksum() with known SHA-256 vectors
- Add memory warning to README.md and man page
- Create portable checksum-verify tool (replaces sha256sum/awk)
- Update all 23 integration tests (204a-204w) to use portable tool
- All 15 output formats verified, all 5 inspect modes correctly skip checksum
- Removed duplicated SHA-256 logic (src/checksum_verify.zig deleted)
- Collapsed 3 duplicated if/else checksum blocks into writeWithChecksum helper
- Parameterized 25 integration tests into ChecksumTest struct array
- Fixed /tmp/checksum_err race (mktemp per test)
- Replaced manual hex loop with std.fmt.bytesToHex
- Reordered writeTable/writeMarkdown to writer-last convention
- Net: -266 lines
- writeWithChecksum: buffer ArrayList never freed after toArrayList();
  in --repl mode this leaked per query. Added defer buffer.deinit(allocator).
- run(): execQuery catch now switches on error type like repl.zig;
  OutOfMemory gets specific message, not misleading SQL error.
- Extended ponytail comment: --checksum defeats --disk (all in RAM).
… tests (ora-3)

- README/man page: --max-rows caps input rows, not output rows.
  Suggest LIMIT clause instead. Note --disk defeated by --checksum.
- Tests: --checksum --silent verifies checksum still emits.
  --checksum --repl multi-query verifies per-query behavior.
@vmvarela
vmvarela merged commit 144c364 into master Aug 2, 2026
4 checks passed
@vmvarela
vmvarela deleted the feature/checksum-flag-issue-204 branch August 2, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: --checksum — emit SHA-256 hash of result set

1 participant