Copy of internal/session from the supervisor module — the ingestion service needs it for the upcoming session_log MCP tool. The supervisor copy will be removed in the supervisor-retirement plan; until then the two packages are intentionally identical and pinned (no edits). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package session_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/session"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAppendAndRead(t *testing.T) {
|
|
dir := t.TempDir()
|
|
sid := "test-session"
|
|
|
|
e1 := session.Entry{
|
|
SessionID: sid,
|
|
Timestamp: time.Now().UTC().Truncate(time.Second),
|
|
Skill: "tdd",
|
|
Phase: "red",
|
|
FinalStatus: "ok",
|
|
}
|
|
e2 := session.Entry{
|
|
SessionID: sid,
|
|
Timestamp: time.Now().UTC().Truncate(time.Second),
|
|
Skill: "tdd",
|
|
Phase: "green",
|
|
FinalStatus: "ok",
|
|
}
|
|
|
|
require.NoError(t, session.Append(dir, sid, e1))
|
|
require.NoError(t, session.Append(dir, sid, e2))
|
|
|
|
got, err := session.Read(dir, sid)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 2)
|
|
assert.Equal(t, "red", got[0].Phase)
|
|
assert.Equal(t, "green", got[1].Phase)
|
|
|
|
_, statErr := os.Stat(filepath.Join(dir, sid+".jsonl"))
|
|
require.NoError(t, statErr, "session file should exist on disk")
|
|
}
|
|
|
|
func TestReadMissingReturnsEmpty(t *testing.T) {
|
|
got, err := session.Read(t.TempDir(), "nope")
|
|
require.NoError(t, err)
|
|
assert.Empty(t, got)
|
|
}
|