Skip to content

tests(#468): 37 unit tests for cli/plugins-update.js (checksum diff, disk I/O, tarball pipeline)#326

Open
javimosch wants to merge 1 commit into
masterfrom
mago/task-468
Open

tests(#468): 37 unit tests for cli/plugins-update.js (checksum diff, disk I/O, tarball pipeline)#326
javimosch wants to merge 1 commit into
masterfrom
mago/task-468

Conversation

@javimosch

@javimosch javimosch commented Jun 27, 2026

Copy link
Copy Markdown
Owner

What changed

Export five private helpers from cli/plugins-update.js for direct testing, then add __tests__/plugins-update.test.js with 37 unit tests covering all exported functions.

Why

plugins-update.js had zero test coverage. The module owns the complete plugin-update pipeline: catalog diff (checksum-based stale detection), disk read/write, tarball download, and extraction. Each of those paths has real error branches that were untested.

Test coverage added

Group Tests What is verified
diffCatalogs 7 null/empty local → all added; identical checksums → unchanged; stale checksum → changed; mixed add+change+unchanged; no plugins key; empty remote
readLocalCatalog 6 missing file → null; valid JSON → parsed object; invalid JSON → null; null/non-object parsed value → null; readFileSync throws → null
writeLocalCatalog 4 creates dir when missing; skips mkdirSync when dir exists; writes to correct path; trailing newline
downloadTarball 5 spawnSync error → integration_error; non-zero exit → throws; missing archive → throws; zero-byte archive → throws; success → returns path
extractPluginsFromTarball 7 creates destDir; correct tar args; tolerates exit 2 (some paths missing); exit 1 → throws; spawnSync error → throws; >200 plugins batched into 2 calls; exactly 200 → 1 call
updatePlugins 8 check=true skips download; up-to-date skips download; force=true ignores local catalog; stale catalog triggers full update+write; tmpDir cleaned via finally even on error; remote_count in result; fetch failure throws with code: 105; invalid remote catalog format throws

Verification

npx jest __tests__/plugins-update.test.js --no-coverage
# 37 passed in 0.262 s

Closes #468 (mago task #468)

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for plugin update behavior, including catalog comparison, local cache handling, download and extraction failures, batching, cleanup, and update flows.
  • Chores
    • Expanded the plugin update module’s exposed helpers to support the new test coverage.

Export diffCatalogs, readLocalCatalog, writeLocalCatalog, downloadTarball,
and extractPluginsFromTarball for direct testing.

Test coverage:
- diffCatalogs (7): null/empty local → all added, identical checksums → unchanged,
  stale checksum → changed, mixed add+change+unchanged
- readLocalCatalog (6): missing file, valid JSON, invalid JSON, null/non-object
  parsed value, fs.readFileSync throws
- writeLocalCatalog (4): creates dir when missing, skips mkdirSync when dir exists,
  writes to correct path, trailing newline
- downloadTarball (5): spawnSync error, non-zero exit, missing archive, zero-byte
  archive, success path
- extractPluginsFromTarball (7): creates destDir, correct tar args, tolerates exit 2,
  throws on exit 1, throws on spawnSync error, batches >200 into 2 calls, 200 uses 1 call
- updatePlugins (8): check=true skips download, up-to-date skips download, force=true
  ignores local catalog, stale catalog triggers full update+write, tmpDir cleaned via
  finally even on error, remote_count in result, fetch failure throws, invalid catalog format throws

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The module now exports plugin update helper functions alongside updatePlugins. A new Jest suite covers catalog diffing, local catalog read/write, tarball download and extraction, and end-to-end update orchestration.

Changes

Plugin update workflow

Layer / File(s) Summary
Helper exports
cli/plugins-update.js
cli/plugins-update.js exports updatePlugins plus the helper functions used by the plugin update flow.
Catalog diffing and local catalog I/O
__tests__/plugins-update.test.js
The suite sets up mocks and covers diffCatalogs, readLocalCatalog, and writeLocalCatalog across missing, invalid, and successful catalog cases.
Tarball download and extraction
__tests__/plugins-update.test.js
The suite covers downloadTarball failures and success, extractPluginsFromTarball argument handling, exit-status handling, and batching behavior.
Update orchestration
__tests__/plugins-update.test.js
The suite covers updatePlugins in check, force, up-to-date, stale-catalog, cleanup-failure, remote-count, and error cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A bunny hops through catalog light,
Checksums sparkle, tarballs bite.
With helper hops and tests aligned,
The plugin trail is neatly signed.
Hooray, wee updates take their flight! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding unit tests for cli/plugins-update.js and its key workflows.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mago/task-468

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@javimosch

Copy link
Copy Markdown
Owner Author

Review — Head of Org Engineering: The PR adds a new test file __tests__/plugins-update.test.js that tests the plugins-update module; it is syntactically valid JS, scoped only to the new test file, and contains no correctness bugs, secrets, or destructive changes. All five merge criteria are satisfied.

(approved — review-only mode; merge when ready.)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cli/plugins-update.js (1)

204-211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep test-only helpers off the top-level public API.

Exporting these helpers alongside updatePlugins turns internal implementation details into supported module surface. That makes future refactors of catalog I/O and tar handling externally breaking for consumers, even though they were only exposed for tests. Consider hanging them off a clearly-internal namespace instead.

♻️ Possible shape
 module.exports = {
   updatePlugins,
-  diffCatalogs,
-  readLocalCatalog,
-  writeLocalCatalog,
-  downloadTarball,
-  extractPluginsFromTarball,
+  _internal: {
+    diffCatalogs,
+    readLocalCatalog,
+    writeLocalCatalog,
+    downloadTarball,
+    extractPluginsFromTarball,
+  },
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/plugins-update.js` around lines 204 - 211, The top-level export object in
updatePlugins is exposing internal test-only helpers as public API, so move
those helpers off the main module surface. Keep updatePlugins as the primary
export and place diffCatalogs, readLocalCatalog, writeLocalCatalog,
downloadTarball, and extractPluginsFromTarball under a clearly internal
namespace or equivalent internal-only export path, so consumers only depend on
supported functionality.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cli/plugins-update.js`:
- Around line 204-211: The top-level export object in updatePlugins is exposing
internal test-only helpers as public API, so move those helpers off the main
module surface. Keep updatePlugins as the primary export and place diffCatalogs,
readLocalCatalog, writeLocalCatalog, downloadTarball, and
extractPluginsFromTarball under a clearly internal namespace or equivalent
internal-only export path, so consumers only depend on supported functionality.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8992585c-08f1-48a2-b73c-4e8c37db8c04

📥 Commits

Reviewing files that changed from the base of the PR and between afda2f7 and 868f63d.

📒 Files selected for processing (2)
  • __tests__/plugins-update.test.js
  • cli/plugins-update.js

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