feat(session): export PrependHistory for shared use across skills
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
package session_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mathiasbq/supervisor/internal/session"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFormatHistoryEmpty(t *testing.T) {
|
||||
@@ -39,3 +41,45 @@ func TestFormatHistoryExcludesCurrentPhase(t *testing.T) {
|
||||
assert.Contains(t, result, "red done")
|
||||
assert.NotContains(t, result, "green done")
|
||||
}
|
||||
|
||||
func TestPrependHistoryNoSessionID(t *testing.T) {
|
||||
result := session.PrependHistory("", "", "review", "do the task")
|
||||
assert.Equal(t, "do the task", result)
|
||||
}
|
||||
|
||||
func TestPrependHistoryNoLog(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
result := session.PrependHistory(dir, "sess-abc", "review", "do the task")
|
||||
assert.Equal(t, "do the task", result)
|
||||
}
|
||||
|
||||
func TestPrependHistoryPrependsHistory(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
entry := session.Entry{
|
||||
SessionID: "sess-abc", Skill: "tdd", Phase: "red",
|
||||
FinalStatus: "pass", Message: "wrote test",
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
require.NoError(t, session.Append(dir, "sess-abc", entry))
|
||||
|
||||
result := session.PrependHistory(dir, "sess-abc", "review", "do the task")
|
||||
assert.Contains(t, result, "## Session history")
|
||||
assert.Contains(t, result, "wrote test")
|
||||
assert.True(t, strings.HasSuffix(result, "do the task"))
|
||||
}
|
||||
|
||||
func TestPrependHistoryExcludesCurrentPhase(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, session.Append(dir, "sess-abc", session.Entry{
|
||||
SessionID: "sess-abc", Skill: "tdd", Phase: "red",
|
||||
FinalStatus: "pass", Message: "red done", Timestamp: time.Now(),
|
||||
}))
|
||||
require.NoError(t, session.Append(dir, "sess-abc", session.Entry{
|
||||
SessionID: "sess-abc", Skill: "tdd", Phase: "green",
|
||||
FinalStatus: "pass", Message: "green done", Timestamp: time.Now(),
|
||||
}))
|
||||
|
||||
result := session.PrependHistory(dir, "sess-abc", "green", "do the task")
|
||||
assert.Contains(t, result, "red done")
|
||||
assert.NotContains(t, result, "green done")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user