package store import ( "path/filepath" "testing" "time" "antidrift/internal/domain" ) func TestLoadMissingFileReturnsLocked(t *testing.T) { path := filepath.Join(t.TempDir(), "state.json") s, err := Load(path) if err != nil { t.Fatalf("unexpected error: %v", err) } if s.RuntimeState != domain.RuntimeLocked { t.Errorf("missing file should be Locked, got %s", s.RuntimeState) } if s.Commitment != nil { t.Errorf("missing file should have nil commitment") } } func TestSaveThenLoadRoundTrips(t *testing.T) { path := filepath.Join(t.TempDir(), "nested", "state.json") c, _ := domain.NewManual("Port store", "store tests pass", 25*time.Minute) c.State = domain.CommitmentActive want := Snapshot{ RuntimeState: domain.RuntimeActive, Commitment: &c, DeadlineUnixSecs: 1748725200, } if err := Save(path, want); err != nil { t.Fatalf("save failed: %v", err) } got, err := Load(path) if err != nil { t.Fatalf("load failed: %v", err) } if got.RuntimeState != want.RuntimeState { t.Errorf("runtime state: got %s want %s", got.RuntimeState, want.RuntimeState) } if got.Commitment == nil || got.Commitment.NextAction != "Port store" { t.Errorf("commitment did not round-trip: %+v", got.Commitment) } if got.DeadlineUnixSecs != want.DeadlineUnixSecs { t.Errorf("deadline: got %d want %d", got.DeadlineUnixSecs, want.DeadlineUnixSecs) } }