Skip to content

fix: Correctness and consistency improvements across core, render, introspect, and CLI#84

Merged
mhiro2 merged 4 commits into
mainfrom
fix/correctness-and-consistency
Apr 25, 2026
Merged

fix: Correctness and consistency improvements across core, render, introspect, and CLI#84
mhiro2 merged 4 commits into
mainfrom
fix/correctness-and-consistency

Conversation

@mhiro2

@mhiro2 mhiro2 commented Apr 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Harden paths in core / render / introspect / parser / wasm / cli / app that could silently change behavior or panic on malformed input
  • Eliminate misclassification and ID collisions in FK / unique validation and stable_id construction caused by identifier case or embedded ., and convert panicking paths in JSON import and
    export into Result
  • Align WASM RenderRequest input validation with the other variants, switch SVG output to single-pass XML escaping, and replace magic-string theme detection with a structural field

Changes

  • ad24491 : fix(core): case-insensitive FK/unique validation and Result-based import
    • Make validate_fk / column_list_has_prefix / referenced_columns_are_unique case-insensitive so they match the from_columns behavior and stop emitting false-positive
      ForeignKeyNonUniqueTarget on mixed-case names
    • Convert import_schema to return Result<Schema, ImportError> so malformed JSON input produces an error instead of panicking via assert!
    • Assert non-empty stable_id during import to prevent empty IDs from corrupting downstream overlay / diff
  • 3fc1804 : fix(render): single-pass XML escape and theme-based light detection
    • Replace the 5-chain .replace() in escape_xml_text with a single-pass char scan, removing 4 intermediate String allocations
    • Add an is_light field to ThemeColors so is_light_theme reads a structural flag instead of comparing against the hardcoded #f7f8fc background
  • 63b26e0 : fix(introspect,parser,wasm): harden stable IDs and unify input validation
    • Switch generate_table_id / generate_column_id separators from . to \0 to remove hash collisions when identifiers contain dots
    • Quote .-containing components when building introspect / parser stable_id so that schema="a.b"+table="c" and schema="a"+table="b.c" no longer collapse to the same key, eliminating
      ambiguous lookups in diff / export / graph nodes
    • Route WasmRenderRequest through wasm_input_source() to match the Inspect / Export / Lint / Diff input-validation semantics
  • 7f0572b : fix(cli,app): avoid redundant file read and replace .expect() with Result
    • Reuse already-read file contents in read_sniffed_file instead of returning a path variant that triggered a second disk read
    • Replace 5 .expect() calls in the export use case with ok_or_else + AppError so that adding a new ExportFormat variant without updating export_format_uses_graph cannot panic

mhiro2 added 4 commits April 25, 2026 22:54
- validate_fk: use case-insensitive comparison for to_columns against
  target table columns, matching the from_columns behavior
- column_list_has_prefix: use case-insensitive comparison for FK index
  prefix matching to avoid false positives across dialects
- referenced_columns_are_unique: normalize to lowercase before comparing
  FK to_columns against PK and unique index columns, preventing
  ForeignKeyNonUniqueTarget false positives on mixed-case names
- import_schema: return Result<Schema, ImportError> instead of
  panicking via assert!, so malformed user-supplied JSON produces an
  error rather than crashing the CLI/WASM process; also asserts that
  stable_id is non-empty to prevent downstream overlay/diff corruption
- escape_xml_text: replace 5-chain .replace() with single-pass char
  scan to avoid 4 intermediate String allocations
- ThemeColors: add is_light field so theme detection does not depend on
  a hardcoded background color string
- is_light_theme: read the structural field instead of comparing against
  a magic "#f7f8fc" value
…tion

- generate_table_id/generate_column_id: use '\0' as separator instead of
  '.' to prevent hash collisions when identifiers contain dots
- introspect/parser stable_id construction: quote components that
  contain '.' so that schema="a.b"+table="c" and schema="a"+table="b.c"
  no longer collapse to the same string, eliminating ambiguous keys in
  diff, export, and graph node lookups
- WasmRenderRequest: delegate to wasm_input_source() for input
  validation, consistent with all other WASM request types
…sult

- read_sniffed_file: reuse the already-read file content instead of
  returning a file-path variant that causes a second read from disk
- export: replace 5 .expect() calls with .ok_or_else() returning
  AppError, so that adding a new ExportFormat variant cannot panic
@mhiro2 mhiro2 self-assigned this Apr 25, 2026
@mhiro2 mhiro2 added the enhancement New feature or request label Apr 25, 2026
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (cf85e4b) #84 (7f0e7cd) +/-
Coverage 94.6% 94.6% -0.1%
Test Execution Time 1m25s 1m27s +2s
Details
  |                     | main (cf85e4b) | #84 (7f0e7cd) |  +/-  |
  |---------------------|----------------|---------------|-------|
- | Coverage            |          94.6% |         94.6% | -0.1% |
  |   Files             |             77 |            77 |     0 |
  |   Lines             |          33774 |         33826 |   +52 |
+ |   Covered           |          31981 |         32012 |   +31 |
- | Test Execution Time |          1m25s |         1m27s |   +2s |

Code coverage of files in pull request scope (95.1% → 94.9%)

Files Coverage +/- Status
crates/relune-app/src/request.rs 81.8% -1.2% affected
crates/relune-app/src/schema_input.rs 85.0% -5.6% modified
crates/relune-app/src/usecases/export.rs 100.0% +0.4% modified
crates/relune-cli/src/commands/input.rs 83.7% -0.3% modified
crates/relune-core/src/export.rs 98.2% -1.5% modified
crates/relune-core/src/lint.rs 95.1% +0.0% modified
crates/relune-core/src/model.rs 96.4% 0.0% modified
crates/relune-introspect/src/common.rs 99.6% -0.4% modified
crates/relune-parser-sql/src/lib.rs 93.2% -0.1% modified
crates/relune-render-svg/src/edge.rs 95.8% +0.0% modified
crates/relune-render-svg/src/group.rs 98.9% +0.0% modified
crates/relune-render-svg/src/legend.rs 97.1% +0.0% modified
crates/relune-render-svg/src/lib.rs 97.9% 0.0% modified
crates/relune-render-svg/src/node.rs 91.4% 0.0% modified
crates/relune-render-theme/src/lib.rs 100.0% 0.0% modified
crates/relune-render-theme/src/xml_escape.rs 100.0% 0.0% modified
crates/relune-wasm/src/request.rs 98.8% +0.8% modified

Reported by octocov

@mhiro2
mhiro2 merged commit c3c66ec into main Apr 25, 2026
5 checks passed
@mhiro2
mhiro2 deleted the fix/correctness-and-consistency branch April 25, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant