Add unit tests for scripts/local-install.mjs (node --test) #93

Closed
opened 2026-08-27 23:59:07 +00:00 by david · 1 comment
Owner

Summary

Add scripts/local-install.test.mjs using Node's built-in test runner (node --test) and wire it as npm test, covering the script's preflight checks, URL dedupe matching, step ordering, and failure paths.

Background

The script's logic — preflight checks, dedupe URL matching, orchestration — is testable by importing its exported helper functions. Tests lock in the fail-fast behavior and the exact remediation messages. Requires the script's helpers to be importable without running main() (the entry guard was added when the script was created — verify it is present).

Part of the npm run install:local feature (tracking issue #41).

Depends on: #90 (Implement pi registration with URL dedupe and reload reminder in scripts/local-install.mjs) — the script must be complete before the tests can cover it.

Implementation Details

  • New file scripts/local-install.test.mjs using node:test and node:assert/strict.
  • The tests must run fully offline: no real pi, git, npm, rg, or fj invocations, no network. Use a mocked or injected command runner — prefer the script accepting an injected spawnSync-like runner (or otherwise injectable dependencies) so the script itself stays clean.
  • Cover at minimum:
    • Every preflight check's pass and fail branch, asserting the exact remediation message on failure.
    • URL-form matching: plain https://, git:, and ssh:// forms of this repo's identity all match; a different repo's URL does not; trailing .git/slashes are normalized.
    • Ordering: the first failing check stops execution; later checks do not run.
    • FORGEJO_TOKEN missing → warning path, not an abort.
    • Step sequencing: preflight → pull → install → register → reminder; non-zero exit on any failure.
  • Wire in package.json scripts: "test": "node --test scripts/local-install.test.mjs" (alongside install:local).

Acceptance Criteria

  • npm test runs the test file and all tests pass.
  • Every preflight check has at least one failing-branch test asserting its exact remediation message.
  • Dedupe matching has tests for the plain https://, git:, and ssh:// forms of the repo URL (plus a negative case for an unrelated URL).
  • All tests run fully offline with no real pi/git/npm/tool invocations.
  • node --test scripts/local-install.test.mjs also passes when run directly.

Test Plan

  • npm test → all green.
  • node --test scripts/local-install.test.mjs → all green.
## Summary Add `scripts/local-install.test.mjs` using Node's built-in test runner (`node --test`) and wire it as `npm test`, covering the script's preflight checks, URL dedupe matching, step ordering, and failure paths. ## Background The script's logic — preflight checks, dedupe URL matching, orchestration — is testable by importing its exported helper functions. Tests lock in the fail-fast behavior and the exact remediation messages. Requires the script's helpers to be importable without running `main()` (the entry guard was added when the script was created — verify it is present). Part of the `npm run install:local` feature (tracking issue #41). **Depends on:** #90 (Implement pi registration with URL dedupe and reload reminder in scripts/local-install.mjs) — the script must be complete before the tests can cover it. ## Implementation Details - New file `scripts/local-install.test.mjs` using `node:test` and `node:assert/strict`. - The tests must run fully offline: no real `pi`, `git`, `npm`, `rg`, or `fj` invocations, no network. Use a mocked or injected command runner — prefer the script accepting an injected `spawnSync`-like runner (or otherwise injectable dependencies) so the script itself stays clean. - Cover at minimum: - Every preflight check's pass and fail branch, asserting the exact remediation message on failure. - URL-form matching: plain `https://`, `git:`, and `ssh://` forms of this repo's identity all match; a different repo's URL does not; trailing `.git`/slashes are normalized. - Ordering: the first failing check stops execution; later checks do not run. - `FORGEJO_TOKEN` missing → warning path, not an abort. - Step sequencing: preflight → pull → install → register → reminder; non-zero exit on any failure. - Wire in `package.json` scripts: `"test": "node --test scripts/local-install.test.mjs"` (alongside `install:local`). ## Acceptance Criteria - [ ] `npm test` runs the test file and all tests pass. - [ ] Every preflight check has at least one failing-branch test asserting its exact remediation message. - [ ] Dedupe matching has tests for the plain `https://`, `git:`, and `ssh://` forms of the repo URL (plus a negative case for an unrelated URL). - [ ] All tests run fully offline with no real pi/git/npm/tool invocations. - [ ] `node --test scripts/local-install.test.mjs` also passes when run directly. ## Test Plan - `npm test` → all green. - `node --test scripts/local-install.test.mjs` → all green.
david added this to the M3 - Unit tests milestone 2026-08-27 23:59:07 +00:00
david closed this issue 2026-08-28 03:26:16 +00:00
Author
Owner

pi-loop opened and merged a pull request for this issue: #100

pi-loop opened and merged a pull request for this issue: https://git.excelera.net/david/pi-extensions-and-skills/pulls/100
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
david/pi-extensions-and-skills#93
No description provided.