Skip to content
This repository was archived by the owner on Sep 24, 2026. It is now read-only.

Add a testthat suite and CI - #4

Merged
eliotmcintire merged 2 commits into
developmentfrom
feat/add-testthat-ci
Sep 11, 2026
Merged

eliotmcintire merged 2 commits into
developmentfrom
feat/add-testthat-ci

Conversation

@eliotmcintire

Copy link
Copy Markdown
Collaborator

Pilot for the module test workflow. This is the first module outside the CBM set to run tests in CI.

Depends on PredictiveEcology/actions#44 (the testthat-module reusable workflow). The caller here pins @feat/testthat-module-workflow so this can be validated before that merges — switch to @main once it does.

What it adds

  • tests/testthat/test-metadata.R — asserts the module's public contract: input and output object names and classes, plus parameter names.
  • tests/testthat/setup.R — options and module path resolution. testthat runs from tests/testthat, so modulePath is three levels up; getting it wrong fails silently (the module simply isn't found).
  • .github/workflows/testthat-module.yaml — thin caller.

Why metadata first

A module's metadata is its public contract — a project binds to these object names and classes. The raster → terra migration now reaching the release branches changes object classes across the family, so this is the assertion that catches a rename or retype here rather than in a downstream project. It is also cheap and mechanical enough to generate for every module.

Verified locally against this module: convertToPackage() builds the package rendition in a throwaway directory (the module itself is untouched), and all 5 assertions pass.

Removals

tests/testthat/test-template.R and tests/unitTests.R — the dead newModule() scaffolding, still carrying C:/Users/yonluo/... paths. Neither was ever run.

These are not merely noise. Once a module is converted to a package for testing, R CMD check runs unitTests.R, and it fails with No test files found because it hardcodes a relative tests/testthat path that does not resolve in the installed test directory. The dead scaffolding actively breaks the build.

Flagged, not changed

tests/Test_EscapeFit.R is stale. It sets formula and data parameters; this module has neither. Its parameters are .runInitialTime, .runInterval, .saveInitialTime, .saveInterval, .useCache, and its inputs are fireSense_escapeCovariates and fireSense_escapeFormula. It is a manual script, not run by anything. Left in place — deleting it is the maintainer's call.

Also noticed: reqdPkgs = list() is empty, yet spatialExtent calls raster::extent(). Not touched here.

🤖 Generated with Claude Code

https://claude.ai/code/session_0125hLaqRWaPcutdboenVK2g

eliotmcintire and others added 2 commits September 10, 2026 07:21
First module to run tests in CI outside the CBM set.

Adds:

- `.github/workflows/testthat-module.yaml` — a thin caller for the shared
  reusable workflow. It pins `@feat/testthat-module-workflow` for now, because
  that workflow is still in review (PredictiveEcology/actions#44); switch to
  `@main` once it merges.
- `tests/testthat/setup.R` — sets options and resolves the module path. testthat
  runs from `tests/testthat`, so `modulePath` is three levels up, not one.
- `tests/testthat/test-metadata.R` — asserts the module's public contract: input
  and output object names AND classes, and parameter names.

Removes the dead `newModule()` scaffolding: `tests/testthat/test-template.R` and
`tests/unitTests.R`. Neither was ever run. They are not merely noise -- once a
module is converted to a package for testing, `R CMD check` runs `unitTests.R`
and it fails with "No test files found", because it hardcodes a relative
`tests/testthat` path that does not resolve in the installed test directory.

The metadata test is deliberately the first one. A module's metadata is its public
contract, and the raster -> terra migration now reaching the release branches
changes object classes across the family. This is the assertion that catches a
rename or a retype before a downstream project does.

`tests/Test_EscapeFit.R` is left alone but is stale: it sets `formula` and `data`
parameters, and this module has neither -- its parameters are `.runInitialTime`,
`.runInterval`, `.saveInitialTime`, `.saveInterval` and `.useCache`, and its
inputs are `fireSense_escapeCovariates` and `fireSense_escapeFormula`. It is a
manual script, not run by anything. Flagging rather than deleting.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0125hLaqRWaPcutdboenVK2g
PredictiveEcology/actions#44 merged and its branch was deleted, so the
@feat/testthat-module-workflow ref no longer resolves.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0133867aFrmKtbhpNXasToP9
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant