fix(cleanup): accept --worktrees flag in argument parser (#220)#235
Merged
aviadshiber merged 9 commits intomainfrom Apr 11, 2026
Merged
fix(cleanup): accept --worktrees flag in argument parser (#220)#235aviadshiber merged 9 commits intomainfrom
aviadshiber merged 9 commits intomainfrom
Conversation
The --worktrees flag was missing from the case statement in the argument parser, causing it to fall through to the unknown-option handler which printed help text and exited with code 1. Since clean_worktrees() already runs unconditionally, the flag just needs to be recognized. https://claude.ai/code/session_01XuqoJYowUyYSnkCPCb4puT
- Remove CLEAN_WORKTREES variable since clean_worktrees() runs unconditionally — the flag only needs to be accepted, not set state - Replace manual echo|grep with assert_not_contains from test framework - Remove redundant static cat+assert_contains checks (the runtime invocation already validates the flag is accepted) https://claude.ai/code/session_01XuqoJYowUyYSnkCPCb4puT
The test_liveness_kill_when_no_api_connection test was flaky in CI because SIGTERM alone wasn't always enough to kill the sleep process within the 5-second wait window. Add SIGKILL as a fallback and wait to properly reap the process. https://claude.ai/code/session_01XuqoJYowUyYSnkCPCb4puT
Extract the kill decision logic from _liveness_monitor_loop into a pure _liveness_should_kill function that can be tested without spawning processes or sleeping. The old tests duplicated the decision logic inline (mirror test anti-pattern) and used sleep polling to verify process death — testing a kernel guarantee rather than application logic. The new tests call _liveness_should_kill directly with stubbed inputs and verify all 5 decision paths: not stale enough, I/O still active, API connection active (spare), no API (kill), and API skip cap exceeded (kill). Runs in <5ms with zero flakiness risk. https://claude.ai/code/session_01XuqoJYowUyYSnkCPCb4puT
- Fix misleading "pure decision function" comment — it has side effects
- Move debug log ("I/O still active") into _liveness_should_kill, removing
the io_before_decision workaround and elif branch from the caller
- Quote $? in test assertions (shellcheck SC2086)
- Use consistent $() pattern in all 5 tests for reliable error capture
- Add cycles-unchanged assertions to guard tests and no-API kill test
https://claude.ai/code/session_01XuqoJYowUyYSnkCPCb4puT
Three classes of bugs fixed, all pre-existing on main and carried into
the PR branch:
1. log_debug returns 1 with set -e (kapsis-status-hook.sh, kapsis-stop-hook.sh)
- [[ -n "" ]] && echo ... shortcircuits with exit 1 when KAPSIS_DEBUG is unset
- set -e in the calling function sees the non-zero return and exits silently
- Fix: return 0 explicitly when KAPSIS_DEBUG is empty
2. Test env var scoping in test-status-hooks.sh
- KAPSIS_STATUS_AGENT_ID="" echo '...' | bash hook.sh only applies the env
override to echo, not to the bash subprocess in the pipe; the hook
inherits KAPSIS_STATUS_AGENT_ID=c9dc90 from the container environment
- Fix: echo '...' | KAPSIS_STATUS_AGENT_ID="" bash hook.sh and
env -u KAPSIS_STATUS_AGENT_ID bash hook.sh to target the right process
3. Heartbeat test path in test-liveness-monitor.sh
- Tests hardcoded $KAPSIS_STATUS_DIR/kapsis-test-project-test-N.json but
_status_get_dir() overrides to /kapsis-status when running in a container
- Fix: use $_KAPSIS_STATUS_FILE (set by status_init) which always points to
the actual file location
All 108 tests pass: 30 liveness, 17 worktree, 23 k8s-config, 38 status-hooks.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
The --worktrees flag was missing from the case statement in the argument
parser, causing it to fall through to the unknown-option handler which
printed help text and exited with code 1. Since clean_worktrees() already
runs unconditionally, the flag just needs to be recognized.
https://claude.ai/code/session_01XuqoJYowUyYSnkCPCb4puT