feat(statusfile): render the ambient drift line when idle
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,7 @@ func TestRender(t *testing.T) {
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := Render(tc.env, now); got != tc.want {
|
||||
if got := Render(tc.env, "", now); got != tc.want {
|
||||
t.Errorf("Render() = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
@@ -77,7 +77,7 @@ func TestWriterWritesAndDedups(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "status")
|
||||
now := time.Unix(1_000_000, 0)
|
||||
env := focusEnv(focusState(domain.RuntimePlanning))
|
||||
w := NewWriter(path, func() mode.Envelope { return env })
|
||||
w := NewWriter(path, func() mode.Envelope { return env }, nil)
|
||||
w.now = func() time.Time { return now }
|
||||
|
||||
w.write()
|
||||
@@ -107,7 +107,7 @@ func TestWriterRemovesFileOnCancel(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "status")
|
||||
w := NewWriter(path, func() mode.Envelope {
|
||||
return focusEnv(focusState(domain.RuntimePlanning))
|
||||
})
|
||||
}, nil)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
done := make(chan struct{})
|
||||
go func() { w.Run(ctx); close(done) }()
|
||||
@@ -131,7 +131,7 @@ func TestWriterWakeRendersPromptly(t *testing.T) {
|
||||
|
||||
var mu sync.Mutex
|
||||
st := activeState(in10m, "ontask", "")
|
||||
w := NewWriter(path, func() mode.Envelope { mu.Lock(); defer mu.Unlock(); return focusEnv(st) })
|
||||
w := NewWriter(path, func() mode.Envelope { mu.Lock(); defer mu.Unlock(); return focusEnv(st) }, nil)
|
||||
w.now = func() time.Time { return now }
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -148,6 +148,27 @@ func TestWriterWakeRendersPromptly(t *testing.T) {
|
||||
waitFor(t, func() bool { return fileEquals(path, "⚠ DRIFT 10m") })
|
||||
}
|
||||
|
||||
func TestRenderIdleShowsAmbientLine(t *testing.T) {
|
||||
got := Render(mode.Envelope{ActiveMode: ""}, "deep in YouTube, no goal", time.Unix(0, 0))
|
||||
if got != "⚠ deep in YouTube, no goal" {
|
||||
t.Fatalf("idle+ambient render = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderIdleNoAmbientLineIsIdle(t *testing.T) {
|
||||
if got := Render(mode.Envelope{ActiveMode: ""}, "", time.Unix(0, 0)); got != "idle" {
|
||||
t.Fatalf("idle+no-ambient render = %q, want idle", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderActiveModeIgnoresAmbientLine(t *testing.T) {
|
||||
// A non-idle envelope renders its own mode, never the ambient line.
|
||||
got := Render(mode.Envelope{ActiveMode: "offscreen", Mode: map[string]any{"status": "proposed", "next_action": "walk"}}, "ambient ignored", time.Unix(0, 0))
|
||||
if got == "ambient ignored" || got == "⚠ ambient ignored" {
|
||||
t.Fatalf("active mode must not render the ambient line, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func fileEquals(path, want string) bool {
|
||||
b, err := os.ReadFile(path)
|
||||
return err == nil && string(b) == want
|
||||
|
||||
Reference in New Issue
Block a user