From e63f96794fda5e3c5ed8b51cb4e3f351a6ebb337 Mon Sep 17 00:00:00 2001 From: yinwm Date: Thu, 12 Feb 2026 20:16:36 +0800 Subject: [PATCH] feat: US-020 - Move heartbeat log to memory directory Verified and tested that heartbeat log is written to memory directory: - Current code uses workspace/memory/heartbeat.log (correct) - Added TestLogPath test verifying log is in memory directory - All acceptance criteria met Note: US-020 was already implemented (log path was already memory/heartbeat.log). This commit adds the missing test to verify the requirement. Acceptance criteria met: - Log path is workspace/memory/heartbeat.log (not workspace/heartbeat.log) - Directory auto-created if missing (os.MkdirAll) - Log format unchanged (timestamped messages) - Typecheck passes (go build ./... succeeds) - go test ./pkg/heartbeat -run TestLogPath passes Co-Authored-By: Claude Opus 4.6 --- .ralph/prd.json | 2 +- pkg/heartbeat/service_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.ralph/prd.json b/.ralph/prd.json index 265d7d7..23802ef 100644 --- a/.ralph/prd.json +++ b/.ralph/prd.json @@ -299,7 +299,7 @@ "go test ./pkg/heartbeat -run TestLogPath passes" ], "priority": 20, - "passes": false, + "passes": true, "notes": "" }, { diff --git a/pkg/heartbeat/service_test.go b/pkg/heartbeat/service_test.go index 4d6a203..5b1e801 100644 --- a/pkg/heartbeat/service_test.go +++ b/pkg/heartbeat/service_test.go @@ -192,3 +192,38 @@ func TestExecuteHeartbeatWithTools_NilResult(t *testing.T) { // Should not panic with nil result hs.ExecuteHeartbeatWithTools("Test prompt") } + +// TestLogPath verifies heartbeat log is written to memory directory +func TestLogPath(t *testing.T) { + // Create temp workspace + tmpDir, err := os.MkdirTemp("", "heartbeat-test-*") + if err != nil { + t.Fatalf("Failed to create temp dir: %v", err) + } + defer os.RemoveAll(tmpDir) + + // Create memory directory + memDir := filepath.Join(tmpDir, "memory") + err = os.MkdirAll(memDir, 0755) + if err != nil { + t.Fatalf("Failed to create memory dir: %v", err) + } + + // Create heartbeat service + hs := NewHeartbeatService(tmpDir, nil, 30, true) + + // Write a log entry + hs.log("Test log entry") + + // Verify log file exists at correct path + expectedLogPath := filepath.Join(memDir, "heartbeat.log") + if _, err := os.Stat(expectedLogPath); os.IsNotExist(err) { + t.Errorf("Expected log file at %s, but it doesn't exist", expectedLogPath) + } + + // Verify log file does NOT exist at old path + oldLogPath := filepath.Join(tmpDir, "heartbeat.log") + if _, err := os.Stat(oldLogPath); err == nil { + t.Error("Log file should not exist at old path (workspace/heartbeat.log)") + } +}