feat(wasm): Add review_from_sql / review_from_schema_json bindings#116
Merged
Conversation
`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.
Code Metrics Report
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%)
Reported by octocov |
Schema reviewTip ✅ No risk findings — schema changes look safe to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
review_from_sql/review_from_schema_jsonfromrelune-wasm, mirroring thediff_from_sqlpattern with full review controls (rules / except_rules / except_tables / deny / severity_overrides / dialect / format).contenton the wasm response so playground "Copy / Download JSON" matchesrelune review --format jsonbyte-for-byte, plus per-rule metadata snapshots for legend rendering.applied_rule_metadata(&ReviewResult)torelune-appsorelune-wasm(and any future surface) can expandapplied_rulesinto the rule-id / default severity / description triple without re-deriving locally.Changes
applied_rule_metadataincrates/relune-app/src/usecases/review.rsthat mapsReviewResult.review.applied_rulestoVec<ReviewRuleMetadata>viaReviewRuleId::metadata().format_review_*functions and surfaceReviewRuleMetadata/ReviewSeverityOverridefromrelune-app::libso downstream crates (wasm, future CLI catalog surfaces) do not have to depend onrelune-core::reviewdirectly.review_from_sql(and thereview_from_schema_jsonalias) plus aWasmReviewRequest/WasmReviewResponsepair that pass through the full review knobs and return the nested coreReviewResult, diagnostics,denied, the CLI-equivalent flattened JSONcontent, andapplied_rule_detailsper the playground rule legend requirement.wasm_input_source_with_dialecthelper (used only on the SQL path; schema_json inputs bypass the parser and ignore the hint).to_review_requestplumbing (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/markdowncontentheader smoke; the applied-rules count assertion usesReviewRuleId::all_rules().len()so future rule additions do not silently break the test.