Problem
The two live-DB tests in tests/testthat/test-lnk_wsg_resolve.R (closure
mode, line ~138; province mode, line ~148) fail with:
Error: Failed to prepare query : ERROR: relation "public.wsg_outlet" does not exist
even when a valid database is available. This is a test-harness
connection mismatch, not a real missing-table problem — the skip gate
and the query run against two different databases.
Root cause
skip_if_no_db() (tests/testthat/setup.R:19-45) opens + validates a
connection to the local Docker fwapg (127.0.0.1:5432, db fwapg),
which has public.wsg_outlet (246 rows). Because that connection
succeeds and is writable, the test does not skip. The helper returns
that conn (with a deferred disconnect).
- The two closure/province tests ignore the returned conn and call
lnk_wsg_resolve(cfg, loaded, ...) with no conn argument.
lnk_wsg_resolve (R/lnk_wsg_resolve.R:122-124) then opens its own
connection via lnk_db_conn(), which (via PG_*_SHARE env vars / the
SSH tunnel) lands on the remote bcfishpass database. That DB does
not have public.wsg_outlet → the query errors.
So the gate greenlights on local fwapg (table present) while the actual
query dials the remote bcfishpass DB (table absent). public.wsg_outlet
is correct and present where it belongs (fwapg); the tests just route to
the wrong DB.
public.wsg_outlet is a 246-row FWA watershed-group outlet-topology table
(one row per WSG, outlet as an ltree) consumed by
fresh::frs_wsg_drainage() for downstream drainage-closure ordering — the
backbone of lnk_wsg_resolve() closure mode and DS-first study-area runs.
Fix options
- Thread the gated conn through (preferred, smallest): capture the
conn from skip_if_no_db() and pass it explicitly:
conn <- skip_if_no_db()
expect_identical(
lnk_wsg_resolve(cfg, loaded, wsgs = c("PARS", "BULK"), conn = conn),
expected
)
This makes the gate and the query use the same DB by construction.
- Point the resolver's default connection at fwapg, or make
skip_if_no_db() additionally assert public.wsg_outlet exists on the
connection the resolver will actually use. More involved; only needed if
lnk_db_conn()'s default target is intended to be fwapg.
Option 1 is the surgical fix and mirrors how the gated conn is meant to be
consumed.
Scope / notes
- Pre-existing; surfaced while running the full suite during link#221
(accessible_km) work — unrelated to that change.
- Two other closure/strict tests that use
.wsg_stub() (offline mocks) are
unaffected; only the two live-DB tests hit this.
Problem
The two live-DB tests in
tests/testthat/test-lnk_wsg_resolve.R(closuremode, line ~138; province mode, line ~148) fail with:
even when a valid database is available. This is a test-harness
connection mismatch, not a real missing-table problem — the skip gate
and the query run against two different databases.
Root cause
skip_if_no_db()(tests/testthat/setup.R:19-45) opens + validates aconnection to the local Docker fwapg (
127.0.0.1:5432, dbfwapg),which has
public.wsg_outlet(246 rows). Because that connectionsucceeds and is writable, the test does not skip. The helper returns
that conn (with a deferred disconnect).
lnk_wsg_resolve(cfg, loaded, ...)with noconnargument.lnk_wsg_resolve(R/lnk_wsg_resolve.R:122-124) then opens its ownconnection via
lnk_db_conn(), which (viaPG_*_SHAREenv vars / theSSH tunnel) lands on the remote
bcfishpassdatabase. That DB doesnot have
public.wsg_outlet→ the query errors.So the gate greenlights on local fwapg (table present) while the actual
query dials the remote bcfishpass DB (table absent).
public.wsg_outletis correct and present where it belongs (fwapg); the tests just route to
the wrong DB.
public.wsg_outletis a 246-row FWA watershed-group outlet-topology table(one row per WSG, outlet as an
ltree) consumed byfresh::frs_wsg_drainage()for downstream drainage-closure ordering — thebackbone of
lnk_wsg_resolve()closure mode and DS-first study-area runs.Fix options
conn from
skip_if_no_db()and pass it explicitly:skip_if_no_db()additionally assertpublic.wsg_outletexists on theconnection the resolver will actually use. More involved; only needed if
lnk_db_conn()'s default target is intended to be fwapg.Option 1 is the surgical fix and mirrors how the gated conn is meant to be
consumed.
Scope / notes
(accessible_km) work — unrelated to that change.
.wsg_stub()(offline mocks) areunaffected; only the two live-DB tests hit this.