Skip to content

feat: Add tests, bump TS - #11

Merged
srl295 merged 5 commits into
masterfrom
add-tests
Oct 10, 2026
Merged

srl295 merged 5 commits into
masterfrom
add-tests

Conversation

@srl295

@srl295 srl295 commented Oct 9, 2026

Copy link
Copy Markdown
Member

No description provided.

@types/node 17 ships no node:test typings, so the upcoming test suite
cannot be type-checked without this bump.

@types/node 26 only declares typesVersions for TS <= 5.7, so TS 4.5 would
fall through to the root typings and fail to parse them. Bump both.

The @tsconfig/node16 base is deliberately left in place so the emitted
JS shape is unchanged for consumers. The consequence is that the type
surface now describes a far newer Node than the compile target, making
"node16 support" advisory rather than enforced. Noted in AGENTS.md.

Verified: npm run build is clean under TS 5.9.3 / @types/node 26.6.3
with no new errors in lib/*.ts.
-dirtecting the config store used to require -D, which persists. That made
it awkward to run mourt against a scratch data dir without rewriting the
real config, which is an easy way to lose settings.

dir and plugin.taskw.command stay file-backed via configstore's dotted
lookup, so a single knob is enough: point at a different config file.

Precedence is -c/--config > $MOURT_CONFIG > configstore's default.
`-c <path>` alone prints the resolved path, as does `-P path`, so the
active config is never a guess.

The store moves from module scope into the Cli constructor, since argv has
to be parsed before the store is opened. That also gives tests a place to
inject a throwaway store.

Two configstore sharp edges are handled explicitly:

- Its constructor writes the file when given a truthy defaults argument,
  so createConfig passes none. Passing one would rewrite the config on
  every read.
- Its `all` getter silently empties any file it cannot JSON.parse, so
  resolveConfigPath validates the target first and throws instead. A typo
  in --config must not blank a config file.

bin/mourt now wraps construction in try/catch: a bad --config throws
outside the run() promise chain, so it would otherwise escape as a raw
stack trace rather than a clean message.

Locals in config.ts are prefixed (nodefs/nodepath/openConfig) because
lib/*.ts are CommonJS scripts sharing one global scope. Using `export {}`
instead would emit an __esModule marker into the CJS and could confuse
bundler interop.

Verified: redirected stores write only to the target; a corrupt --config is
rejected with the file left byte-identical; the real configstore file hashes
the same before and after.
59 tests across 7 files, run with no new dependencies:

  npm test  # npm run build && tsc -p tsconfig.test.json && node --test

tsconfig.test.json compiles to dist-test/ rather than dist/, so test code
can never reach the published artifact. This matters because the files
field is dist/**/*.js: adding test/ to the main tsconfig would have
shipped the tests in the tarball.

Coverage is weighted toward the behaviour that was previously only
verified by hand:

- getList()'s four-case project filter, including the documented rule that
  entries with no taskwarrior field are excluded under a project filter
- plugin-taskw via a real spawned fake `task` script, covering the empty
  array, non-array JSON, oversized-field truncation, and the fact that
  taskwarrior's stderr reaches the rejection message rather than a bare
  "non zero exit". A fake executable is used instead of an injected
  function on purpose: the stderr fix only manifests at the process
  boundary.
- config resolution precedence, rejection of unparseable JSON, and the
  fact that opening a store does not rewrite the file
- doMessage's ISO date agreeing with both its filename and its local
  YYYY/MM/DD directory. No clock is injected, so assertions check
  internal consistency rather than a fixed timestamp.
- e2e runs spawning bin/mourt, which is what would have caught the dist/
  layout break that tsc allowed silently.

Verified by mutation: reverting the requireBaseDir guard, the j[0] guard,
the config precedence order, and the bin/mourt require path each turn the
suite red (8, 2, 4 and 8 failures respectively). All were restored and
lib/ matches HEAD.

Every test is scoped to a temp config and data dir. The suite hashes the
real configstore file before and after and it is byte-identical, so
running the tests cannot rewrite the user's real settings.

No real journal content is used anywhere in the suite; values are
synthetic. The AGENTS.md "Handling real data" section records why.
@srl295 srl295 self-assigned this Oct 9, 2026
srl295 added 2 commits October 9, 2026 14:19
The matrix was pinned to 10.x/12.x/14.x, all long EOL. Two of those
predate node:test entirely, so the new suite could not have run there.

matrix is now 22.x (Jod), 24.x (Krypton) and 26.x (Current). 26.x is not
LTS yet but reaches it in Oct 2026, and testing it now surfaces breakage
before promotion day rather than after.

Also updated:

- actions/checkout v2 -> v7, actions/setup-node v1 -> v7, and enable
  `cache: npm`.
- `npm run build --if-present` is gone; `npm test` runs `npm run build`
  first, so the build is covered without a redundant step.
- `npm test || echo 'HEY! write some tests, already'` is now a plain
  `npm test`. That guard swallowed every failure, which is indefensible
  now that the suite is real. A failure must fail the build.
- fail-fast: false, so all three versions report instead of one
  cancelling the rest.

engines.node is set to >=22.3, the floor implied by the tests: node:test
glob arguments landed in Node 21, and t.after() in 22.3. Without the
engines field nothing warns on an unsupported runtime.

--test-reporter=spec is now explicit. Node 22 defaults to tap and Node 24+
to spec, so CI logs were inconsistent between matrix entries.

Verified locally against real interpreters rather than assumed: v22.23.3
and v24.21.0 downloaded from nodejs.org, full build plus 59/59 tests
green on both, and again on the local v26.7.0. The YAML parses. The
user's real configstore file is byte-identical after the runs.
The list had drifted out of date in ways that would mislead:

- "No tests exist yet / npm test exits 1" was still asserted in the
  Commands section and Gotchas, months after that stopped being true. Now
  states the real 59 cases and the build-then-test ordering.
- Test suite, config redirect and CI are recorded as done under a new
  "Later" section instead of being missing entirely.

Four genuinely open items are now listed rather than implied:

- CI is Linux-only, so macOS and Windows are untested. The binary and
  configstore both have platform-specific behaviour.
- The semver@6.3.0 ReDoS advisory, and what it would actually take to
  clear it.
- No lint or typecheck-only script exists.
- `getList()` remains O(all entries).

The two `// TODO` markers still in lib/ are recorded as decisions that
need making, not as chores.

The one place that kept a historical note ("npm test failing meant no
tests yet, not tests are broken") is reworded so it describes what was
true when written rather than claiming to be the current state.
@srl295
srl295 merged commit 8200356 into master Oct 10, 2026
3 checks passed
@srl295
srl295 deleted the add-tests branch October 10, 2026 00:41
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