Skip to content

test: unit tests for the profile, the registry and the update check - #9

Merged
fcsouza merged 2 commits into
mainfrom
test/unit-tests
Sep 13, 2026
Merged

fcsouza merged 2 commits into
mainfrom
test/unit-tests

Conversation

@fcsouza

@fcsouza fcsouza commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

This repo had no unit test. What it had was one end-to-end run that needs Docker and a Foundry licence, so CI never ran a line of it.

What is covered

Forty tests over the three parts that decide what a GM gets.

The settings registry (settings-registry.ts). Each entry narrowed to what the vault needs, core left out, registration order kept, and a package that throws from its own getter handed back as undefined instead of stopping an export.

The profile (profile.ts). A value whose name looks like a credential stays out of the file unless asked for. A setting that changed scope is skipped rather than written somewhere else. A setting whose package is not installed here is skipped with a reason. An import carries on past a value the setting refuses, because a profile older than the world is the ordinary case.

The update check (updates/check.ts, updates/github.ts). A player is refused before a single request is spent. An answer younger than a day costs nothing, the button asks again, and so does an answer older than a day. A refusal from GitHub stops the loop and caches nothing for the modules it never reached. A tag that is not a version is reported as unreadable rather than shown as the version to upgrade to. A 403 is told apart from the hourly budget by its header.

Proof they catch something

Two guards were broken on purpose: the scope check in applyProfile, and the break after a rate limit in checkUpdates.

× skips a setting that changed scope, rather than writing it somewhere else
× stops at the first refusal and caches nothing for the rest
Tests  2 failed | 38 passed (40)

Both passed again when the guards came back.

CI

pnpm run test runs after lint. pnpm run build still produces a zip with no test file in it.

Needs @vttforge/testing 0.12.0, whose mock fills game.settings.settings and answers registerMenu and game.keybindings. @vttforge/types moves to ^0.8.0 with it.

This repo had no unit test. What it had was one end-to-end run that needs
Docker and a Foundry licence, so CI never ran a line of it.

Forty tests now cover the three parts that decide what a GM gets: reading the
settings registry, writing and reading a profile, and the update check with the
request budget around it. The rules that would be expensive to get wrong are
each pinned by one test. A value whose name looks like a credential stays out
of the file. A setting that changed scope is skipped rather than written
somewhere else. An import carries on past a value the setting refuses. A
refusal from GitHub stops the loop and caches nothing for the modules it never
reached.

Proven by breaking two of those guards on purpose: the scope check and the stop
after a rate limit. Two tests failed, and passed again when the guards came
back.

`pnpm run test` runs in CI, after lint. Needs @vttforge/testing 0.12.0, whose
mock fills the settings registry.
`restore()` replaces the whole `game` object, so a patch written over
`game.settings.get` or `set` goes with it. That makes the two tests that
patch one depend on `beforeEach` rebuilding the mock. They put it back
themselves now.
@fcsouza

fcsouza commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Re-ran the end-to-end check against the published @vttforge/testing 0.12.0, not the version this branch replaces: 32/32, including the five that cross between worlds.

Two tests patch game.settings.get / set and now put it back themselves. restore() replaces the whole game object, so the patch went with it either way, but that made the tests depend on beforeEach rebuilding the mock.

On the mutation check: it proves those two tests bite, and nothing wider. The secret filter, the day-long cache and the version comparison are covered by tests that have not been mutated.

@fcsouza
fcsouza merged commit 6b4f314 into main Sep 13, 2026
1 check passed
@fcsouza
fcsouza deleted the test/unit-tests branch September 13, 2026 23:35
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.

1 participant