lnk_wsg_resolve: bundle-aware WSG resolver + study_area_wsgs.R → CLI shim (v0.41.0) (#207)#208
Merged
NewGraphEnvironment merged 7 commits intoMay 27, 2026
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Unblocks lnk_wsg_resolve composition with fresh::frs_wsg_drainage() (fresh#211). Live smoke test from link's session confirms the function is reachable and returns the expected 15-WSG PARS+BULK closure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Bundle-aware WSG resolver. Three call patterns: - wsgs = NULL → province mode (sorted alphabetically) - wsgs + expand = TRUE → focal + drainage closure via fresh::frs_wsg_drainage(), DS-first order preserved - wsgs + expand = FALSE → strict mode, species-filter input verbatim Validation mirrors lnk_pipeline_species. Closure mode opens conn via lnk_db_conn() with on.exit-cleanup. Species filter uses the existing study_area_wsgs.R:60-64 idiom (defensive against "t"/"TRUE"/TRUE). Closure + strict modes emit message() listing species-less WSGs dropped from the result (parity with the CLI script's diagnostic). Live-validated against fwapg: PARS+BULK returns the exact 15-WSG closure; province mode 217 WSGs sorted alphabetically; strict mode returns input verbatim or species-filters with diagnostic message. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
13 test_that blocks / 22 expectations: - Arg validation (no DB): non-lnk_config cfg, non-list loaded, malformed wsgs (non-char / empty / NA / empty-string), malformed expand (non- logical / non-scalar / NA), missing/empty wsg_species_presence, missing species columns - Stub-based (no DB): province-mode sort, strict-mode preserve-order- when-all-pass, strict-mode message-on-drop, strict-mode case-fold. Stub row order is deliberately NOT alphabetical (CCCC, AAAA, BBBB) so the province `sort()` is load-bearing (per /code-check Round 1). - Live DB (skip_if_no_db): closure mode 15-WSG PARS+BULK exact match, province mode >= 200 WSGs alphabetically sorted. All 22 pass against live fwapg. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
76 → 33 lines. The closure + species-filter + ordering logic that lived inline now delegates to lnk_wsg_resolve(cfg, loaded, wsgs = focal). Args parsing, LNK_LOAD env dispatch, and loud-fail-on-empty are preserved. Byte-identical stdout vs pre-#207 (`diff /tmp/pre... /tmp/post...` exits 0 for the PARS+BULK regression baseline; 76 bytes both). data-raw/study_area_run.sh interface unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lnk_wsg_resolve() — bundle-aware "what WSGs should we model?" resolver that composes fresh::frs_wsg_drainage() (FWA drainage closure, fresh v0.32.0) with the bundle's wsg_species_presence filter (link#157). Three call patterns: province (NULL, sorted alphabetically), closure (focal + drainage, DS-first), strict (focal verbatim, species-filtered). study_area_wsgs.R shrunk to a thin CLI shim around it; stdout byte- identical for the PARS+BULK regression baseline. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 tasks
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
lnk_wsg_resolve(cfg, loaded, wsgs = NULL, expand = TRUE)— the bundle-aware "what WSGs should we model?" resolver. Composesfresh::frs_wsg_drainage()(FWA drainage closure, fresh v0.32.0) with the bundle'swsg_species_presencefilter (trifecta + balance + run_provincial: filter dispatch list to bundle species (skip 15 known-empty WSGs) #157). Three call patterns: province (NULL, sorted alphabetically), closure (focal + drainage DS-first), strict (focal verbatim, species-filtered).data-raw/study_area_wsgs.Rshrunk 76 → 33 lines — pure CLI shim now. Byte-identical stdout for the PARS+BULK regression baseline;data-raw/study_area_run.shunaffected.Remotes: fresh@v0.31.0 → @v0.32.0. New@family wsgpre-stages futurelnk_wsg_*helpers.Related Issues
Test plan
devtools::test(filter = "lnk_wsg_resolve")— 22 expectations pass against live fwapglintr::lint()clean on all 3 changed files (R/lnk_wsg_resolve.R, tests, data-raw/study_area_wsgs.R)diff /tmp/pre207_stdout.txt /tmp/post207_stdout.txtreturns 0 — shim is a byte-identical drop-indevtools::document()regeneratesNAMESPACE+man/lnk_wsg_resolve.Rd, no warningsNotes
/code-checkran 2 rounds on the function and 2 on the tests; 4 findings total, all fixed:sort()ed alphabetically + documented in@returnmessage()listing droppedmessage()(parity with the previous inline diagnostic atstudy_area_wsgs.R:67-71)sort()test would pass withoutsort()→ reordered stub toc("CCCC","AAAA","BBBB")sosort()is load-bearing🤖 Generated with Claude Code