test: add real unit coverage (sha/validate/registry-io) + extract pure helpers #6

Open
opened 2026-07-10 22:41:32 +00:00 by kavi · 0 comments
Owner

After the reconcile (#5), kua-deploy has zero wired tests (no test script, no CI). Add real coverage, importing prod logic instead of duplicating it.

Prereq: extract pure helpers (also fixes real duplication)

server.js is a monolith with import-time side effects and no exports. Extract into lib/, import back from server.js (no behavior change):

  • lib/sha.js — unify stripSha (currently defined ~3x inline: ~863, ~1728, plus a subtly different .trim()-ing normSha ~1853). stripSha = s => (s||"").replace(/^sha256:/,"").trim(); imageMatch(expected,actual) that NEVER true-passes on empty expected.
  • lib/validate.js — move validateMessage, validateBranchName, validateEntry (+REGISTRY_SERVERS), normalizedDiff; export them.
  • lib/registry-io.js (opt) — pure parseRegistry(jsonText) + data-dir param so seed/load/write are testable against a tmp dir.
  • add package.json "test": "node --test test/" + a CI workflow.

Tests to add (skeletons available from the review)

  • test/sha.test.js: prefixed==bare, different digests differ, null/undefined/empty→"", trailing-newline tolerated, imageMatch empty-never-matches + mixed-prefix.
  • test/registry-validate.test.js: good entry clean; rejects bad app name / missing required / bad mode / bad server / relative deploy_dir; branch-name injection (-x, a..b, a;rm -rf /, a$(x)) rejected & real names pass; message non-ASCII/>500 rejected, empty→default.
  • test/registry-io.test.js (after io extract): malformed JSON & non-object apps rejected; seed adopted only when engine file absent, never overwrites existing, corrupt seed→{apps:{}}; write→load round-trip leaves no .tmp residue.

Do NOT port the old registry-loader assertions about live content ("≥5 apps", "kua-deploy registered") — those are monitoring probes vs GET /api/v1/apps/registry, not unit tests.

Blocked-by: #5 (reconcile). Crown-jewel: reviewed PR, human merges.

After the reconcile (#5), kua-deploy has **zero wired tests** (no `test` script, no CI). Add real coverage, importing prod logic instead of duplicating it. ## Prereq: extract pure helpers (also fixes real duplication) `server.js` is a monolith with import-time side effects and no exports. Extract into `lib/`, import back from `server.js` (no behavior change): - `lib/sha.js` — unify `stripSha` (currently defined ~3x inline: ~863, ~1728, plus a subtly different `.trim()`-ing `normSha` ~1853). `stripSha = s => (s||"").replace(/^sha256:/,"").trim()`; `imageMatch(expected,actual)` that NEVER true-passes on empty expected. - `lib/validate.js` — move `validateMessage`, `validateBranchName`, `validateEntry` (+`REGISTRY_SERVERS`), `normalizedDiff`; export them. - `lib/registry-io.js` (opt) — pure `parseRegistry(jsonText)` + data-dir param so seed/load/write are testable against a tmp dir. - add `package.json` `"test": "node --test test/"` + a CI workflow. ## Tests to add (skeletons available from the review) - `test/sha.test.js`: prefixed==bare, different digests differ, null/undefined/empty→"", trailing-newline tolerated, `imageMatch` empty-never-matches + mixed-prefix. - `test/registry-validate.test.js`: good entry clean; rejects bad app name / missing required / bad mode / bad server / relative deploy_dir; branch-name injection (`-x`, `a..b`, `a;rm -rf /`, `a$(x)`) rejected & real names pass; message non-ASCII/>500 rejected, empty→default. - `test/registry-io.test.js` (after io extract): malformed JSON & non-object `apps` rejected; seed adopted only when engine file absent, never overwrites existing, corrupt seed→`{apps:{}}`; write→load round-trip leaves no `.tmp` residue. Do NOT port the old registry-loader assertions about live content ("≥5 apps", "kua-deploy registered") — those are monitoring probes vs `GET /api/v1/apps/registry`, not unit tests. Blocked-by: #5 (reconcile). Crown-jewel: reviewed PR, human merges.
Sign in to join this conversation.
No labels
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
kavi/kua-deploy#6
No description provided.