Skip to content

lnk_wsg_resolve: bundle-aware WSG resolver + study_area_wsgs.R → CLI shim (v0.41.0) (#207)#208

Merged
NewGraphEnvironment merged 7 commits into
mainfrom
207-lnk-wsg-resolve-bundle-aware-wsg-resolve
May 27, 2026
Merged

lnk_wsg_resolve: bundle-aware WSG resolver + study_area_wsgs.R → CLI shim (v0.41.0) (#207)#208
NewGraphEnvironment merged 7 commits into
mainfrom
207-lnk-wsg-resolve-bundle-aware-wsg-resolve

Conversation

@NewGraphEnvironment

Copy link
Copy Markdown
Owner

Summary

  • Adds lnk_wsg_resolve(cfg, loaded, wsgs = NULL, expand = TRUE) — the bundle-aware "what WSGs should we model?" resolver. Composes fresh::frs_wsg_drainage() (FWA drainage closure, fresh v0.32.0) with the bundle's wsg_species_presence filter (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.R shrunk 76 → 33 lines — pure CLI shim now. Byte-identical stdout for the PARS+BULK regression baseline; data-raw/study_area_run.sh unaffected.
  • fresh dep pin: Remotes: fresh@v0.31.0 → @v0.32.0. New @family wsg pre-stages future lnk_wsg_* helpers.

Related Issues

Test plan

  • devtools::test(filter = "lnk_wsg_resolve") — 22 expectations pass against live fwapg
  • lintr::lint() clean on all 3 changed files (R/lnk_wsg_resolve.R, tests, data-raw/study_area_wsgs.R)
  • Live regression baseline: closure mode returns exact 15-WSG PARS+BULK closure; province mode 217 WSGs sorted alphabetically; strict mode preserves caller order
  • diff /tmp/pre207_stdout.txt /tmp/post207_stdout.txt returns 0 — shim is a byte-identical drop-in
  • devtools::document() regenerates NAMESPACE + man/lnk_wsg_resolve.Rd, no warnings

Notes

/code-check ran 2 rounds on the function and 2 on the tests; 4 findings total, all fixed:

  • Province mode return ordering was undocumented (CSV row order) → now sort()ed alphabetically + documented in @return
  • Strict mode silently dropped species-less focal WSGs → now emits message() listing dropped
  • Closure mode silently dropped species-less closure WSGs → now emits message() (parity with the previous inline diagnostic at study_area_wsgs.R:67-71)
  • Stub fixture was pre-sorted, so the sort() test would pass without sort() → reordered stub to c("CCCC","AAAA","BBBB") so sort() is load-bearing

🤖 Generated with Claude Code

NewGraphEnvironment and others added 7 commits May 27, 2026 06:39
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>
@NewGraphEnvironment NewGraphEnvironment merged commit f0399d9 into main May 27, 2026
1 check passed
@NewGraphEnvironment NewGraphEnvironment deleted the 207-lnk-wsg-resolve-bundle-aware-wsg-resolve branch May 27, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lnk_wsg_resolve: bundle-aware WSG resolver (closure + species filter); study_area_wsgs.R → CLI shim

1 participant