test(kugetsu): add unit tests for status, delegate, doctor, notify commands
Added 10 new tests: - kugetsu status (5 tests): uninitialized, base missing, pm-agent missing, Python None handling, session expired - kugetsu delegate (2 tests): no message, pm-agent missing - kugetsu doctor (1 test): basic command execution - kugetsu notify (2 tests): list with no file, clear with no file Total tests: 38 (all passing)
This commit is contained in:
@@ -354,6 +354,135 @@ else
|
|||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# Test 21: status when not initialized
|
||||||
|
echo "--- Test: status (not initialized) ---"
|
||||||
|
cleanup
|
||||||
|
OUTPUT=$($KUGETSU status 2>&1 || true)
|
||||||
|
if [ "$OUTPUT" = "kugetsu_not_initialized" ]; then
|
||||||
|
pass "status returns kugetsu_not_initialized when no index.json"
|
||||||
|
else
|
||||||
|
fail "status not initialized: got '$OUTPUT', expected 'kugetsu_not_initialized'"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 22: status when base missing
|
||||||
|
echo "--- Test: status (base missing) ---"
|
||||||
|
mkdir -p ~/.kugetsu/sessions
|
||||||
|
cat > ~/.kugetsu/index.json << EOF
|
||||||
|
{
|
||||||
|
"base": null,
|
||||||
|
"pm_agent": "$TEST_PM_AGENT_SESSION_ID",
|
||||||
|
"issues": {}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
OUTPUT=$($KUGETSU status 2>&1 || true)
|
||||||
|
if [ "$OUTPUT" = "base_session_missing" ]; then
|
||||||
|
pass "status returns base_session_missing when base is null"
|
||||||
|
else
|
||||||
|
fail "status base missing: got '$OUTPUT', expected 'base_session_missing'"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 23: status when pm-agent missing
|
||||||
|
echo "--- Test: status (pm-agent missing) ---"
|
||||||
|
cat > ~/.kugetsu/index.json << EOF
|
||||||
|
{
|
||||||
|
"base": "$TEST_BASE_SESSION_ID",
|
||||||
|
"pm_agent": null,
|
||||||
|
"issues": {}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
OUTPUT=$($KUGETSU status 2>&1 || true)
|
||||||
|
if [ "$OUTPUT" = "pm_agent_missing" ]; then
|
||||||
|
pass "status returns pm_agent_missing when pm_agent is null"
|
||||||
|
else
|
||||||
|
fail "status pm_agent missing: got '$OUTPUT', expected 'pm_agent_missing'"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 24: status when pm-agent is "None" (Python None output)
|
||||||
|
echo "--- Test: status (pm-agent is Python None) ---"
|
||||||
|
cat > ~/.kugetsu/index.json << EOF
|
||||||
|
{
|
||||||
|
"base": "$TEST_BASE_SESSION_ID",
|
||||||
|
"pm_agent": "None",
|
||||||
|
"issues": {}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
OUTPUT=$($KUGETSU status 2>&1 || true)
|
||||||
|
if [ "$OUTPUT" = "pm_agent_missing" ]; then
|
||||||
|
pass "status returns pm_agent_missing when pm_agent is 'None'"
|
||||||
|
else
|
||||||
|
fail "status pm_agent 'None': got '$OUTPUT', expected 'pm_agent_missing'"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 25: status when all good (pm-agent in json but session expired)
|
||||||
|
echo "--- Test: status (session expired) ---"
|
||||||
|
setup_mock_base
|
||||||
|
OUTPUT=$($KUGETSU status 2>&1 || true)
|
||||||
|
if [ "$OUTPUT" = "pm_agent_expired" ]; then
|
||||||
|
pass "status returns pm_agent_expired when session not in opencode"
|
||||||
|
else
|
||||||
|
fail "status session expired: got '$OUTPUT', expected 'pm_agent_expired'"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 26: delegate without message
|
||||||
|
echo "--- Test: delegate (no message) ---"
|
||||||
|
cleanup
|
||||||
|
OUTPUT=$($KUGETSU delegate 2>&1 || true)
|
||||||
|
if echo "$OUTPUT" | grep -q "Error: message is required"; then
|
||||||
|
pass "delegate fails without message"
|
||||||
|
else
|
||||||
|
fail "delegate no message: got '$OUTPUT', expected error about message required"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 27: delegate when pm-agent missing
|
||||||
|
echo "--- Test: delegate (pm-agent missing) ---"
|
||||||
|
setup_mock_base
|
||||||
|
OUTPUT=$($KUGETSU delegate "test" 2>&1 || true)
|
||||||
|
if echo "$OUTPUT" | grep -q "Error: PM agent session"; then
|
||||||
|
pass "delegate fails when PM agent not found"
|
||||||
|
else
|
||||||
|
fail "delegate pm-agent missing: got '$OUTPUT', expected error about PM agent"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 28: doctor command works
|
||||||
|
echo "--- Test: doctor command ---"
|
||||||
|
cleanup
|
||||||
|
OUTPUT=$($KUGETSU doctor 2>&1 || true)
|
||||||
|
if echo "$OUTPUT" | grep -q "kugetsu doctor"; then
|
||||||
|
pass "doctor command works"
|
||||||
|
else
|
||||||
|
fail "doctor command: got '$OUTPUT', expected doctor output"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 29: notify list when no file
|
||||||
|
echo "--- Test: notify list (no file) ---"
|
||||||
|
cleanup
|
||||||
|
OUTPUT=$($KUGETSU notify list 2>&1 || true)
|
||||||
|
if [ "$OUTPUT" = "[]" ]; then
|
||||||
|
pass "notify list returns empty array when file missing"
|
||||||
|
else
|
||||||
|
fail "notify list no file: got '$OUTPUT', expected '[]'"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Test 30: notify clear when no file
|
||||||
|
echo "--- Test: notify clear (no file) ---"
|
||||||
|
cleanup
|
||||||
|
OUTPUT=$($KUGETSU notify clear 2>&1 || true)
|
||||||
|
if [ -z "$OUTPUT" ] || echo "$OUTPUT" | grep -q "marked as read"; then
|
||||||
|
pass "notify clear works when file missing (no-op)"
|
||||||
|
else
|
||||||
|
fail "notify clear: got '$OUTPUT', expected success or empty"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
cleanup
|
cleanup
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user