feat(test): add --watch mode, re-running whenever the target config changes#284
Closed
albatrossflyon-coder wants to merge 1 commit into
Closed
feat(test): add --watch mode, re-running whenever the target config changes#284albatrossflyon-coder wants to merge 1 commit into
albatrossflyon-coder wants to merge 1 commit into
Conversation
…hanges Add --watch to the test command: after the initial check, watches the target config file (fs.watch, no new dependency needed for a single file) and re-runs a one-shot check+diff on each change, reusing watch.ts's existing runWatchOneShot for the re-run/render/diff logic rather than test.ts's own richer interactive flow (enforce prompts, CI conversion) -- that flow only makes sense once, not in a loop. 300ms debounce since a single file write commonly fires multiple fs.watch events. Ctrl+C closes the watcher and exits cleanly. The issue's own example usage (`test --watch npx -y <server>`, a raw command with no --target) has no config file to actually watch -- --watch now errors clearly in that case rather than doing nothing, telling the user --target is required. Also fixes a real bug this surfaced: --watch (and --enforce, --auto-enforce, etc.) placed after a raw server command (`test npx -y <server> --watch`) was being silently swallowed into the variadic command-args array instead of being parsed as a test option, because of how passThroughOptions() interacts with a variadic positional argument. This repo already has a known workaround for exactly this (extractTrailingConversionFlags, handling --setup-ci/--enforce/etc. the same way) -- --watch just wasn't added to it. Fixed and covered with a regression test; this exact scenario (the issue's own example command) now works. Fixes KryptosAI#254
KryptosAI
added a commit
that referenced
this pull request
Jul 15, 2026
Co-authored-by: albatrossflyon-coder <albatrossflyon-coder@users.noreply.github.com>
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.
Summary
Fixes #254.
Adds
--watchtotest: after the initial check, watches the target config file and re-runs a check+diff whenever it changes, until Ctrl+C.Design choices
fs.watchoverchokidar— the issue offered either;chokidarisn't a dependency here and watching a single file doesn't need glob support, so no new dependency.watch.ts'srunWatchOneShotfor the re-run/render/diff logic on each change, rather than re-runningtest's own much richer flow (interactive enforce prompts, CI-conversion offers, SARIF writing) — that flow makes sense once, at the start, not on every file save. The initial check still getstest's full behavior unchanged; only the watch-triggered re-runs use the lighterwatch-style rendering.fs.watchcommonly fires multiple events for a single file write; without debouncing this would re-run 2-3x per save.A real ambiguity in the issue, and how I resolved it
The issue's own expected-usage example is:
mcp-observatory test --watch npx -y @modelcontextprotocol/server-memoryThat's a raw command, not
--target <file>— there's no config file to actually watch in that invocation. I made--watchrequire--targetand error clearly when it's missing, rather than silently doing nothing:A real bug this surfaced (fixed as part of this PR)
Testing the issue's own example command (
test <raw-command> --watch) initially did nothing — no error,--watchjust silently had no effect. Root cause:testusespassThroughOptions()with a variadic[command...]argument, so flags placed after a raw command get swallowed into the command-args array meant for the server invocation, instead of being parsed astest's own options. This repo already has a known, existing workaround for exactly this (extractTrailingConversionFlags, which manually re-extracts--setup-ci/--enforce/--auto-enforce/etc. out of the trailing args) —--watchjust wasn't added to that list. Fixed, with a regression test covering the exact scenario.Verified live
Initial run + watch message:
Edited the config file → detected, debounced, re-ran, rendered via
watch.ts's diff renderer:No-
--targeterror path also confirmed (exit code 1, clear message) — including with the issue's exact raw-command example, after theextractTrailingConversionFlagsfix above.Testing
--watchextraction viaextractTrailingConversionFlags(including the exact "raw command + trailing--watch" scenario that was broken), 1 forwatchAndRerun's no---targeterror pathnpx tsc --noEmit: cleannpx eslinton changed files: cleanmain, unrelated (see feat(scan): add passed/failed/warnings summary line #280/fix(cli): wire up --quiet to actually suppress logo and CTAs #281/feat(cli): remediation hints on scan/test failures #283)