test: add real unit coverage (sha/validate/registry-io) + extract pure helpers #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
After the reconcile (#5), kua-deploy has zero wired tests (no
testscript, no CI). Add real coverage, importing prod logic instead of duplicating it.Prereq: extract pure helpers (also fixes real duplication)
server.jsis a monolith with import-time side effects and no exports. Extract intolib/, import back fromserver.js(no behavior change):lib/sha.js— unifystripSha(currently defined ~3x inline: ~863, ~1728, plus a subtly different.trim()-ingnormSha~1853).stripSha = s => (s||"").replace(/^sha256:/,"").trim();imageMatch(expected,actual)that NEVER true-passes on empty expected.lib/validate.js— movevalidateMessage,validateBranchName,validateEntry(+REGISTRY_SERVERS),normalizedDiff; export them.lib/registry-io.js(opt) — pureparseRegistry(jsonText)+ data-dir param so seed/load/write are testable against a tmp dir.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,imageMatchempty-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-objectappsrejected; seed adopted only when engine file absent, never overwrites existing, corrupt seed→{apps:{}}; write→load round-trip leaves no.tmpresidue.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.