frs_wsg_drainage: FWA WSG drainage-closure primitive (v0.32.0) (#211)#212
Merged
NewGraphEnvironment merged 6 commits intoMay 27, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Column confirmed: wsg varchar(4) (matches link's existing query) - Live PARS+BULK closure returns 15 WSGs DS-first, exact regression baseline match Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pure FWA topology primitive — given a focal set of WSG codes, returns the drainage closure (focal + every WSG they flow through) ordered downstream-first by outlet ltree depth (`nlevel(outlet) ASC`). SQL ported from link@v0.40.5 data-raw/study_area_wsgs.R; identifier validated, focal values quoted via DBI::dbQuoteLiteral, scalar table arg enforced, focal codes upper-cased internally, unmatched focals warn rather than silently drop. Live-validated against fwapg: PARS+BULK returns the exact 15-WSG closure (KISP, KLUM, LKEL, LSKE, MSKE, USKE, BULK, FINA, LBTN, LPCE, MORR, PARA, PCEA, UPCE, PARS) DS-first; lowercase input normalized; TYPO warns. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
11 test_that blocks / 14 expectations: - Arg validation (no DB): non-character, empty, NA, empty-string, vector table, and invalid identifier (asserts the validator's specific "table contains invalid characters" message — not a generic class match) - Live DB (skip on PG_DB_SHARE empty): PARS+BULK 15-WSG exact closure, focal-order invariance, lowercase input case-folds, unmatched-focal warning is raised + returned vector still valid, all-fake-focal errors All 14 pass against live fwapg. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
frs_wsg_drainage — FWA WSG drainage-closure primitive. Promotes the inline closure query from link@v0.40.5 data-raw/study_area_wsgs.R into a reusable, tested fresh export. Pure FWA topology; first consumer is link::lnk_wsg_resolve (NewGraphEnvironment/link#207). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
frs_wsg_drainage(conn, watershed_group_code, table = "public.wsg_outlet")— pure FWA-topology primitive returning a focal set's drainage closure, ordered downstream-first by outlet ltree depth.NewGraphEnvironment/link@v0.40.5 data-raw/study_area_wsgs.R:44-50into a reusable, tested fresh export. First consumer:link::lnk_wsg_resolve(lnk_wsg_resolve: bundle-aware WSG resolver (closure + species filter); study_area_wsgs.R → CLI shim link#207).@family wsg. 11 test_that blocks / 14 expectations (6 arg-validation + 5 live-DB gated onPG_DB_SHARE). Live-validated against fwapg.Related Issues
Test plan
devtools::test(filter = "frs_wsg_drainage")— all 14 expectations pass against live fwapgdevtools::document()—NAMESPACE+man/frs_wsg_drainage.Rdregenerated, no warningsfrs_wsg_drainage(conn, c("PARS","BULK"))returns the exact 15-WSG closureKISP, KLUM, LKEL, LSKE, MSKE, USKE, BULK, FINA, LBTN, LPCE, MORR, PARA, PCEA, UPCE, PARS(DS-first)Notes
Beyond the literal SQL port from link, the function adds three safety properties caught during
/code-check:tablearg enforced (.frs_validate_identifieris vectorized internally — a vector value would silently slip validation and produce malformed SQL)c("pars","bulk")doesn't silently missc("BULK","TYPO")is no longer a quiet partial successlintrnot run — fresh hasn't adopted lintr (not in Suggests); the convention is link-side.🤖 Generated with Claude Code