test(v0.4): cover session finalize end-to-end
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFinalizeWritesSummaryAndClearsLease(t *testing.T) {
|
||||
wsDir := t.TempDir()
|
||||
os.MkdirAll(filepath.Join(wsDir, ".ctask"), 0755)
|
||||
|
||||
start := time.Now().UTC().Truncate(time.Second)
|
||||
lease := NewLease(start, "claude", "local")
|
||||
WriteLease(LeasePath(wsDir), lease)
|
||||
|
||||
os.WriteFile(filepath.Join(wsDir, "notes.md"), []byte("before"), 0644)
|
||||
startManifest, err := CaptureManifest(wsDir)
|
||||
if err != nil {
|
||||
t.Fatalf("CaptureManifest: %v", err)
|
||||
}
|
||||
if err := WriteManifest(manifestStartPath(wsDir), startManifest); err != nil {
|
||||
t.Fatalf("WriteManifest: %v", err)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
os.WriteFile(filepath.Join(wsDir, "notes.md"), []byte("after change"), 0644)
|
||||
os.WriteFile(filepath.Join(wsDir, "output.md"), []byte("new"), 0644)
|
||||
|
||||
end := time.Now().UTC().Truncate(time.Second)
|
||||
opts := LaunchOpts{
|
||||
WsDir: wsDir,
|
||||
Agent: "claude",
|
||||
Mode: "local",
|
||||
Slug: "test",
|
||||
}
|
||||
|
||||
if err := finalize(opts, startManifest, start, end, true); err != nil {
|
||||
t.Fatalf("finalize: %v", err)
|
||||
}
|
||||
|
||||
summary, err := ReadSummary(SummaryPath(wsDir))
|
||||
if err != nil {
|
||||
t.Fatalf("ReadSummary: %v", err)
|
||||
}
|
||||
if summary == nil {
|
||||
t.Fatal("expected summary to be written")
|
||||
}
|
||||
if len(summary.FilesAdded) == 0 {
|
||||
t.Error("expected files_added to contain output.md")
|
||||
}
|
||||
if len(summary.FilesModified) == 0 {
|
||||
t.Error("expected files_modified to contain notes.md")
|
||||
}
|
||||
if len(summary.EndManifest) < 2 {
|
||||
t.Errorf("expected end_manifest to include notes.md + output.md, got %d entries", len(summary.EndManifest))
|
||||
}
|
||||
|
||||
logData, err := os.ReadFile(filepath.Join(wsDir, "logs", "sessions.log"))
|
||||
if err != nil {
|
||||
t.Fatalf("read session log: %v", err)
|
||||
}
|
||||
if len(logData) == 0 {
|
||||
t.Error("session log should have content")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(LeasePath(wsDir)); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("lease should be removed after finalize, got err=%v", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(manifestStartPath(wsDir)); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("manifest-start should be removed after finalize, got err=%v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user