test(hooks): add cross-platform regression matrix for MCP readiness#354
Open
sebastianbreguel wants to merge 5 commits intomksglu:nextfrom
Open
test(hooks): add cross-platform regression matrix for MCP readiness#354sebastianbreguel wants to merge 5 commits intomksglu:nextfrom
sebastianbreguel wants to merge 5 commits intomksglu:nextfrom
Conversation
Locks in the directory-scan + PID-liveness contract from mksglu#347. The 11 test files updated by mksglu#347 changed the sentinel path but never asserted that isMCPReady() returns true for a sentinel whose PID is outside the test runner's process tree — the exact condition the PPID-keyed lookup failed on under WSL2 / `bash -c "node ..."` topologies. Coverage: - sentinelPathForPid + deprecated sentinelPath shape - sentinelDir platform branch (/tmp on Unix, os.tmpdir on win32) - isMCPReady happy path + resilience to malformed payloads - Stale-sentinel self-healing (gated to clean envs) - PPID-independence regression: child PID ∉ runner tree → still true Pure test-only PR. No production changes.
…h, env-var path) - Drop sentinelPath() deprecated-export test. The JSDoc says it's kept for one release cycle; testing what's about to die is a maintenance trap. - Collapse empty-payload + non-numeric-payload tests into a single it.each. Same contract, fewer lines. - Pass resolved sentinel directory to the regression child via env var instead of recomputing the platform branch inline. Keeps mcp-ready.mjs as the single source of truth for the path shape.
Owner
|
Hi @sebastianbreguel! Thanks for the PR. Please use existing Unit Test file instead of new one. |
Per review feedback: move the three describe blocks (`contract`, `stale-cleanup self-healing`, `PPID-independence`) from the standalone tests/hooks/mcp-ready.test.ts into tests/hooks/core-routing.test.ts as top-level describes after the existing `routePreToolUse` block. Same test bodies, same assertions; only the host file changed. The stale-cleanup block adds a local `beforeEach` that unlinks the file-level `mcpSentinel` so the runner's own live sentinel does not mask the dead-PID cleanup the test verifies.
Contributor
Author
|
Done — moved the three describe blocks into |
Merge imports from both branches and fix sentinelDir tests to temporarily clear env override when testing platform defaults.
Contributor
Author
|
Resolved merge conflict with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / Why / How
What. Adds
tests/hooks/mcp-ready.test.ts— a dedicated regression matrix forhooks/core/mcp-ready.mjs, the module that #347 rewrote.Why. PR #347 fixed the PPID-bypass on WSL2 /
bash -c "node ..."by switching from aprocess.ppid-keyed sentinel lookup to a directory-scan withkill(pid, 0)liveness probes. The 11 test files touched in #347 updated the sentinel path to useprocess.pid, but none of them assert the load-bearing contract: thatisMCPReady()returnstruewhen the only live sentinel was written by a process whose PID is outside the test runner's process tree. A future refactor that re-introduces PPID coupling, hardcodes a different temp root, or removes the stale-cleanup branch would not be caught by current CI.How. One new file, three
describeblocks, no production code changes:mcp-ready: contract— locks insentinelPathForPidshape, deprecatedsentinelPathbackward-compat (still keyed byprocess.ppidfor one release cycle per the JSDoc),sentinelDir()platform branch (/tmpon Unix,os.tmpdir()on win32), happy path, and resilience to malformed payloads (empty, non-numeric).mcp-ready: stale-cleanup self-healing—isMCPReady()unlinks dead-PID sentinels (usesINT32_MAXas a guaranteed-dead PID, no spawn). Gated bydescribe.skipIf(POLLUTED)to skip locally when an unrelated MCP server's live sentinel exists in/tmp(iteration order would make assertions flaky); CI runners are clean and run these.mcp-ready: PPID-independence (regression for #347)— spawns a child Node process whose PID ∉ {process.pid,process.ppid}, has it write its own sentinel via the same path shapesrc/server.tsuses, then assertsisMCPReady() === true. This is the test that, if removed, allows Regression in #230: PPID mismatch — mcpRedirect swallows all redirects when hook spawned via shell wrapper #347 to silently regress.Affected platforms
Cross-platform notes:
path.jointhroughout, no hardcoded/separators.sentinelDir()test mocksprocess.platformviaObject.defineProperty(..., { configurable: true })and restores inafterEach.process.execPath+-einline script for portability.Test plan
npx vitest run tests/hooks/mcp-ready.test.tspasses locally on macOS (8 passed, 2 skipped under POLLUTED gate; in clean envs the 2 skipped also pass).npx tsc -b --noEmitpasses.Checklist
npm testpassesnpm run typecheckpassesnextbranch