Skip to content

feat(wasm): Add review_from_sql / review_from_schema_json bindings#116

Merged
mhiro2 merged 2 commits into
mainfrom
feat/review-wasm-bindings
Apr 30, 2026
Merged

feat(wasm): Add review_from_sql / review_from_schema_json bindings#116
mhiro2 merged 2 commits into
mainfrom
feat/review-wasm-bindings

Conversation

@mhiro2

@mhiro2 mhiro2 commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • Expose review_from_sql / review_from_schema_json from relune-wasm, mirroring the diff_from_sql pattern with full review controls (rules / except_rules / except_tables / deny / severity_overrides / dialect / format).
  • Surface a CLI-equivalent flattened JSON content on the wasm response so playground "Copy / Download JSON" matches relune review --format json byte-for-byte, plus per-rule metadata snapshots for legend rendering.
  • Add applied_rule_metadata(&ReviewResult) to relune-app so relune-wasm (and any future surface) can expand applied_rules into the rule-id / default severity / description triple without re-deriving locally.

Changes

  • 5b941cf feat(review): add applied_rule_metadata helper for downstream surfaces
    • Add applied_rule_metadata in crates/relune-app/src/usecases/review.rs that maps ReviewResult.review.applied_rules to Vec<ReviewRuleMetadata> via ReviewRuleId::metadata().
    • Re-export the helper alongside the existing format_review_* functions and surface ReviewRuleMetadata / ReviewSeverityOverride from relune-app::lib so downstream crates (wasm, future CLI catalog surfaces) do not have to depend on relune-core::review directly.
  • 68080aa feat(wasm): add review_from_sql / review_from_schema_json bindings
    • Add review_from_sql (and the review_from_schema_json alias) plus a WasmReviewRequest / WasmReviewResponse pair that pass through the full review knobs and return the nested core ReviewResult, diagnostics, denied, the CLI-equivalent flattened JSON content, and applied_rule_details per the playground rule legend requirement.
    • Thread the SQL parser dialect hint through a new wasm_input_source_with_dialect helper (used only on the SQL path; schema_json inputs bypass the parser and ignore the hint).
    • Cover the bindings with native tests for the to_review_request plumbing (dialect threading, severity override serde round-trip, missing-input rejection) and wasm-bindgen tests for the SQL no-findings / breaking-fk-drop round-trips, the schema_json input path, and the text/markdown content header smoke; the applied-rules count assertion uses ReviewRuleId::all_rules().len() so future rule additions do not silently break the test.

mhiro2 added 2 commits April 30, 2026 21:39
`applied_rule_metadata(&ReviewResult)` expands the `applied_rules` array
on a `ReviewResult` into the same `ReviewRuleMetadata` triple that
`ReviewRuleId::all_metadata()` produces, so CLI / wasm / future surfaces
do not have to re-derive `default_severity` and `description` from each
rule id locally. The function is re-exported alongside the existing
`format_review_*` helpers and `ReviewRuleMetadata` /
`ReviewSeverityOverride` are surfaced from `relune-app` to keep the
downstream `relune-wasm` and CLI crates from depending on
`relune-core::review` directly.
`review_from_sql` and its `review_from_schema_json` alias mirror the
existing `diff_from_sql` pattern: deserialize a `WasmReviewRequest`
(before/after sql or schema_json + rules / except_rules / except_tables
/ deny / severity_overrides / dialect / format) into a
`ReviewRequest`, run the shared `relune_app::review` pipeline, and
serialize a `WasmReviewResponse` carrying the nested core review
payload, diagnostics, the `denied` flag, the CLI-equivalent flattened
JSON `content`, and the per-rule metadata snapshots produced by
`applied_rule_metadata`. The dialect hint is threaded through a new
`wasm_input_source_with_dialect` helper that calls
`InputSource::sql_text_with_dialect` for SQL inputs and is silently
ignored for schema_json (which bypasses the parser).

`format = "json"` populates `content` with the same flattened
`relune-app::ReviewResult` JSON that `relune review --format json`
emits, and `format = "text" | "markdown"` reuses
`format_review_text` / `format_review_markdown` so playground surfaces
can render the CLI strings as-is. Native tests cover the request to
`ReviewRequest` plumbing (dialect threading, severity override serde
round-trip, missing-input rejection); wasm-bindgen tests cover the SQL
no-findings round-trip, the breaking-fk-drop round-trip with denied=
true, the schema_json input path through `review_from_schema_json`,
and the text/markdown content header smoke. The applied-rules count
assertion uses `ReviewRuleId::all_rules().len()` so adding new rules
in later phases does not silently break the test.
@mhiro2 mhiro2 self-assigned this Apr 30, 2026
@mhiro2 mhiro2 added the enhancement New feature or request label Apr 30, 2026
@github-actions

Copy link
Copy Markdown

Code Metrics Report

main (6c66253) #116 (d1b9533) +/-
Coverage 94.7% 94.6% -0.1%
Test Execution Time 1m25s 1m33s +8s
Details
  |                     | main (6c66253) | #116 (d1b9533) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          94.7% |          94.6% | -0.1% |
  |   Files             |             81 |             81 |     0 |
  |   Lines             |          37184 |          37324 |  +140 |
+ |   Covered           |          35229 |          35334 |  +105 |
- | Test Execution Time |          1m25s |          1m33s |   +8s |

Code coverage of files in pull request scope (86.9% → 85.6%)

Files Coverage +/- Status
crates/relune-app/src/lib.rs 96.2% 0.0% modified
crates/relune-app/src/usecases/review.rs 93.8% -1.7% modified
crates/relune-wasm/src/lib.rs 4.8% -1.0% modified
crates/relune-wasm/src/request.rs 98.2% -0.7% modified

Reported by octocov

@github-actions

Copy link
Copy Markdown

Schema review

Tip

✅ No risk findings — schema changes look safe to merge.

@mhiro2
mhiro2 merged commit 1aee9bd into main Apr 30, 2026
6 checks passed
@mhiro2
mhiro2 deleted the feat/review-wasm-bindings branch April 30, 2026 12:46
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