Skip to content

tests: unit-test cli/plugins-hooks.js (validateHooks, validateNodeHook, executeOutputHooks)#324

Open
javimosch wants to merge 3 commits into
masterfrom
mago/task-455
Open

tests: unit-test cli/plugins-hooks.js (validateHooks, validateNodeHook, executeOutputHooks)#324
javimosch wants to merge 3 commits into
masterfrom
mago/task-455

Conversation

@javimosch

Copy link
Copy Markdown
Owner

What changed

Added __tests__/plugins-hooks.test.js — 55 unit tests for cli/plugins-hooks.js.

Coverage

Function Cases tested
validateHooks empty manifest, valid/invalid manifest-level kinds (all 6), valid/invalid command-level kinds (all 4), namespace.resource.action in error message, multi-error accumulation, commands with no hooks
validateNodeHook null/undefined guard → null, code-85 on missing/non-string script, non-node runtime rejection, timeout_ms out-of-range (0, negative, >15000), NaN, non-numeric string, boundary acceptance (1, 15000), undefined→15000 default, return shape
executeNodeHook code-92 when script file missing, code-105 on spawnSync error object, code-105 on non-zero exit (stderr used / fallback message), JSON parse, null on invalid JSON, {} on empty stdout, timeout propagation, context JSON arg serialisation
executeOutputHooks no hooks → [], missing on_output → [], no-script hookDef → [], output mutation (string/null/undefined/empty), hook result push, null stdout → [], {} truthy → pushed, commandManifest preference, throw propagation
runHook null when no hooks, null when kind absent, null when no script, executeNodeHook dispatch, context.kind mutation

How verified

npx jest __tests__/plugins-hooks.test.js --no-coverage
# Tests: 55 passed, 55 total

Closes #455 (mago task #455)

root and others added 3 commits June 27, 2026 00:57
…, stale-lock detection

Add 60 tests in __tests__/config-sync-advanced.test.js covering the six
exports not yet tested: runServerPluginPostInstall (hook policy, timeout
cap, path-traversal guard, spawnSync result handling), extractZipToDir
(ENOENT/non-zero exit, code-105 error shape), ensurePluginDir (sanitization,
recursive mkdir), syncServerPlugins (conflict resolution via shadowed_by_local,
partial updates with unchanged/updated split, stale-lock removal, checksum
detection, disabled-plugin skip, missing manifest throw, zip download+extract
path), syncClientPluginResources (skip when no server_resources, POST body
includes client_id, network/non-ok error handling), syncCliAdapters (stale
local file removal, header generation, per-adapter failure counting).

Also fix a pre-existing scope bug in cli/config-sync.js: `const manifest`
was declared inside the try{} block but referenced after the catch{} close,
causing a ReferenceError for every non-zip plugin install. Moved the
declaration to before the try block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lveHookScriptPath, serializeHook)

- Export parsePostInstallResult, resolveHookScriptPath, serializeHook for direct testing
- 26 unit tests across three describe blocks:
  - parsePostInstallResult (10): null/undefined/empty/whitespace→null, valid JSON
    object/array parsed, invalid JSON→{raw:text} fallback, trim before parse,
    raw fallback preserves trimmed text
  - resolveHookScriptPath (7): ../traversal throws code 85, absolute outside dir
    throws code 85, multi-level subdir/../../ traversal throws code 85,
    missing file throws code 92 (resource_not_found), valid path+exists returns
    resolved path, nested path within dir allowed, kind label in error message
  - serializeHook (9): null/undefined hook→null, full serialized object with all
    fields, round-trip script_name===basename(script_path), readFileSync called
    with correct path, validateNodeHook error propagated, traversal code 85
    propagated, missing script code 92 propagated, underscores→hyphens in kind

Closes #456  _(mago task #456)_

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…k, executeNodeHook, executeOutputHooks, runHook)

55 tests covering:
- validateHooks: valid/invalid manifest-level and command-level hook kinds, missing-field guards,
  multi-error accumulation, namespace.resource.action in error messages
- validateNodeHook: null/undefined guards, code-85 on missing/non-string script, non-node runtime,
  out-of-range/NaN/missing timeout_ms, boundary acceptance at 1 and 15000, return shape
- executeNodeHook: code-92 on missing script, code-105 on spawnSync error/non-zero exit,
  JSON parse/null return, timeout propagation, context serialisation
- executeOutputHooks: no-hook → [], null/empty/undefined output mutation, hook result push,
  null-stdout → [], {} truthy → pushed, commandManifest preference over pluginManifest, throw propagation
- runHook: null routing, missing kind, no-script no-op, context.kind mutation

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

Warning

Review limit reached

@javimosch, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 58 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d52f7562-e294-4b12-8dd0-b9341e52aa02

📥 Commits

Reviewing files that changed from the base of the PR and between afda2f7 and 695439d.

📒 Files selected for processing (5)
  • __tests__/config-sync-advanced.test.js
  • __tests__/plugins-hooks.test.js
  • __tests__/plugins-install.test.js
  • cli/config-sync.js
  • cli/plugins-install.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mago/task-455

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 for cli/config-sync.js exports, which is valid JavaScript, scoped only to the new test file, and contains no secrets, destructive changes, or correctness bugs visible in the diff. It aligns with the current focus on unit/integration tests for logic-holding modules.

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

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