Skip to content

fix(cleanup): accept --worktrees flag in argument parser (#220)#235

Merged
aviadshiber merged 9 commits intomainfrom
claude/review-open-issues-7K6k3
Apr 11, 2026
Merged

fix(cleanup): accept --worktrees flag in argument parser (#220)#235
aviadshiber merged 9 commits intomainfrom
claude/review-open-issues-7K6k3

Conversation

@aviadshiber
Copy link
Copy Markdown
Owner

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

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
claude and others added 8 commits April 10, 2026 13:17
- 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>
@aviadshiber aviadshiber merged commit ef9d17a into main Apr 11, 2026
12 checks passed
@aviadshiber aviadshiber deleted the claude/review-open-issues-7K6k3 branch April 11, 2026 20:05
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.

4 participants