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 <noreply@anthropic.com>
This commit is contained in:
yinwm
2026-02-12 20:16:36 +08:00
parent 03b02cc7d7
commit e63f96794f
2 changed files with 36 additions and 1 deletions

View File

@@ -299,7 +299,7 @@
"go test ./pkg/heartbeat -run TestLogPath passes"
],
"priority": 20,
"passes": false,
"passes": true,
"notes": ""
},
{

View File

@@ -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)")
}
}