9b4c7ac28b
The env-vars doctor check was skipping deacon with a stale comment "it doesn't use standard env vars". After the AgentEnv refactor, deacon/manager.go now uses config.AgentEnv() like all other roles. - Remove the skip condition for deacon in env_check.go - Update test from TestEnvVarsCheck_DeaconSkipped to test deacon is actually checked (TestEnvVarsCheck_DeaconCorrect/DeaconMissing) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
143 lines
3.8 KiB
Go
143 lines
3.8 KiB
Go
package doctor
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/gastown/internal/config"
|
|
"github.com/steveyegge/gastown/internal/session"
|
|
"github.com/steveyegge/gastown/internal/tmux"
|
|
)
|
|
|
|
// SessionEnvReader abstracts tmux session environment access for testing.
|
|
type SessionEnvReader interface {
|
|
ListSessions() ([]string, error)
|
|
GetAllEnvironment(session string) (map[string]string, error)
|
|
}
|
|
|
|
// tmuxEnvReader wraps real tmux operations.
|
|
type tmuxEnvReader struct {
|
|
t *tmux.Tmux
|
|
}
|
|
|
|
func (r *tmuxEnvReader) ListSessions() ([]string, error) {
|
|
return r.t.ListSessions()
|
|
}
|
|
|
|
func (r *tmuxEnvReader) GetAllEnvironment(session string) (map[string]string, error) {
|
|
return r.t.GetAllEnvironment(session)
|
|
}
|
|
|
|
// EnvVarsCheck verifies that tmux session environment variables match expected values.
|
|
type EnvVarsCheck struct {
|
|
BaseCheck
|
|
reader SessionEnvReader // nil means use real tmux
|
|
}
|
|
|
|
// NewEnvVarsCheck creates a new env vars check.
|
|
func NewEnvVarsCheck() *EnvVarsCheck {
|
|
return &EnvVarsCheck{
|
|
BaseCheck: BaseCheck{
|
|
CheckName: "env-vars",
|
|
CheckDescription: "Verify tmux session environment variables match expected values",
|
|
},
|
|
}
|
|
}
|
|
|
|
// NewEnvVarsCheckWithReader creates a check with a custom reader (for testing).
|
|
func NewEnvVarsCheckWithReader(reader SessionEnvReader) *EnvVarsCheck {
|
|
c := NewEnvVarsCheck()
|
|
c.reader = reader
|
|
return c
|
|
}
|
|
|
|
// Run checks environment variables for all Gas Town sessions.
|
|
func (c *EnvVarsCheck) Run(ctx *CheckContext) *CheckResult {
|
|
reader := c.reader
|
|
if reader == nil {
|
|
reader = &tmuxEnvReader{t: tmux.NewTmux()}
|
|
}
|
|
|
|
sessions, err := reader.ListSessions()
|
|
if err != nil {
|
|
// No tmux server - treat as success (valid when Gas Town is down)
|
|
return &CheckResult{
|
|
Name: c.Name(),
|
|
Status: StatusOK,
|
|
Message: "No tmux sessions running",
|
|
}
|
|
}
|
|
|
|
// Filter to Gas Town sessions only (gt-* and hq-*)
|
|
var gtSessions []string
|
|
for _, sess := range sessions {
|
|
if strings.HasPrefix(sess, "gt-") || strings.HasPrefix(sess, "hq-") {
|
|
gtSessions = append(gtSessions, sess)
|
|
}
|
|
}
|
|
|
|
if len(gtSessions) == 0 {
|
|
// No Gas Town sessions - treat as success (valid when Gas Town is down)
|
|
return &CheckResult{
|
|
Name: c.Name(),
|
|
Status: StatusOK,
|
|
Message: "No Gas Town sessions running",
|
|
}
|
|
}
|
|
|
|
var mismatches []string
|
|
checkedCount := 0
|
|
|
|
for _, sess := range gtSessions {
|
|
identity, err := session.ParseSessionName(sess)
|
|
if err != nil {
|
|
// Skip unparseable sessions
|
|
continue
|
|
}
|
|
|
|
// Get expected env vars based on role
|
|
expected := config.AgentEnvSimple(string(identity.Role), identity.Rig, identity.Name)
|
|
|
|
// Get actual tmux env vars
|
|
actual, err := reader.GetAllEnvironment(sess)
|
|
if err != nil {
|
|
mismatches = append(mismatches, fmt.Sprintf("%s: could not read env vars: %v", sess, err))
|
|
continue
|
|
}
|
|
|
|
checkedCount++
|
|
|
|
// Compare each expected var
|
|
for key, expectedVal := range expected {
|
|
actualVal, exists := actual[key]
|
|
if !exists {
|
|
mismatches = append(mismatches, fmt.Sprintf("%s: missing %s (expected %q)", sess, key, expectedVal))
|
|
} else if actualVal != expectedVal {
|
|
mismatches = append(mismatches, fmt.Sprintf("%s: %s=%q (expected %q)", sess, key, actualVal, expectedVal))
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(mismatches) == 0 {
|
|
return &CheckResult{
|
|
Name: c.Name(),
|
|
Status: StatusOK,
|
|
Message: fmt.Sprintf("All %d session(s) have correct environment variables", checkedCount),
|
|
}
|
|
}
|
|
|
|
// Add explanation about needing restart
|
|
details := append(mismatches,
|
|
"",
|
|
"Note: Mismatched session env vars won't affect running Claude until sessions restart.",
|
|
)
|
|
|
|
return &CheckResult{
|
|
Name: c.Name(),
|
|
Status: StatusWarning,
|
|
Message: fmt.Sprintf("Found %d env var mismatch(es) across %d session(s)", len(mismatches), checkedCount),
|
|
Details: details,
|
|
FixHint: "Run 'gt shutdown && gt up' to restart sessions with correct env vars",
|
|
}
|
|
}
|