Files
gastown/internal/keepalive/keepalive_test.go
Steve Yegge b6817899b4 refactor: ZFC cleanup - move Go heuristics to Deacon molecule (gt-gaxo)
Remove Go code that makes workflow decisions. All health checking,
staleness detection, nudging, and escalation belongs in the Deacon
molecule where Claude executes it.

Removed:
- internal/daemon/backoff.go (190 lines) - exponential backoff decisions
- internal/doctor/stale_check.go (284 lines) - staleness detection
- IsFresh/IsStale/IsVeryStale from keepalive.go
- pokeMayor, pokeWitnesses, pokeWitness from daemon.go
- Heartbeat staleness classification from pokeDeacon

Changed:
- Lifecycle parsing now uses structured body (JSON or simple text)
  instead of keyword matching on subject line
- Daemon now only ensures Deacon is running and sends simple heartbeats
- No backoff, no staleness classification, no decision-making

Total: ~800 lines removed from Go code

The Deacon molecule will handle all health checking, nudging, and
escalation. Go is now just a message router.

See gt-gaxo epic for full rationale.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-24 00:11:15 -08:00

80 lines
2.0 KiB
Go

package keepalive
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestTouchInWorkspace(t *testing.T) {
// Create temp directory
tmpDir := t.TempDir()
// Touch the keepalive
TouchInWorkspace(tmpDir, "gt status")
// Read back
state := Read(tmpDir)
if state == nil {
t.Fatal("expected state to be non-nil")
}
if state.LastCommand != "gt status" {
t.Errorf("expected last_command 'gt status', got %q", state.LastCommand)
}
// Check timestamp is recent
if time.Since(state.Timestamp) > time.Minute {
t.Errorf("timestamp too old: %v", state.Timestamp)
}
}
func TestReadNonExistent(t *testing.T) {
tmpDir := t.TempDir()
state := Read(tmpDir)
if state != nil {
t.Error("expected nil state for non-existent file")
}
}
func TestStateAge(t *testing.T) {
// Test nil state returns very large age
var nilState *State
if nilState.Age() < 24*time.Hour {
t.Error("nil state should have very large age")
}
// Test fresh state returns accurate age
freshState := &State{Timestamp: time.Now().Add(-30 * time.Second)}
age := freshState.Age()
if age < 29*time.Second || age > 31*time.Second {
t.Errorf("expected ~30s age, got %v", age)
}
// Test older state returns accurate age
olderState := &State{Timestamp: time.Now().Add(-5 * time.Minute)}
age = olderState.Age()
if age < 4*time.Minute+55*time.Second || age > 5*time.Minute+5*time.Second {
t.Errorf("expected ~5m age, got %v", age)
}
// NOTE: IsFresh(), IsStale(), IsVeryStale() were removed as part of ZFC cleanup.
// Staleness classification belongs in Deacon molecule, not Go code.
// See gt-gaxo epic for rationale.
}
func TestDirectoryCreation(t *testing.T) {
tmpDir := t.TempDir()
workDir := filepath.Join(tmpDir, "some", "nested", "workspace")
// Touch should create .runtime directory
TouchInWorkspace(workDir, "gt test")
// Verify directory was created
runtimeDir := filepath.Join(workDir, ".runtime")
if _, err := os.Stat(runtimeDir); os.IsNotExist(err) {
t.Error("expected .runtime directory to be created")
}
}