refactor(store)!: remove the SQLite task store, the PocketBase event store and the SQLite session store

The State Store, event capture and Gateway conversations already serve from
PostgreSQL. This deletes internal/store and internal/infrastructure/edastore,
the SQLite gateway session store and openProductionTaskStore, and the -db
recovery path on a legacy task file; backup, restore, validate and rollback
work on the database database_url names.

- The binding-secret cipher moves to internal/infrastructure/bindingcipher and
  ToolCall to internal/infrastructure/postgres.
- NewSessionStoreMemory is now a pure in-memory store that passes the shared
  SessionStore conformance suite.
- Tests run against PostgreSQL through internal/infrastructure/postgres/pgstore;
  legacyimport/legacyfixture writes the legacy files the import and the boot
  gate read.
- The cron dialect is owned in internal/domain/scheduling, so
  github.com/pocketbase/pocketbase and pocketbase/dbx leave go.mod.
  modernc.org/sqlite stays for the one-time import (legacyread).
- The UI and Messaging architecture gates ban the Postgres and legacy readers
  in place of internal/store.
This commit is contained in:
sam committed 2026-09-24 14:43:50 +10:00
1 parent dda12dcdba
commit ae552db7e0
90 files changed
+1022 -1453

No files matched your search

+4 -9
View File
@@ -4,28 +4,23 @@ import (
"encoding/json"
"log/slog"
"net/http"
"path/filepath"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/domain/binding"
"github.com/samcharles93/archie-core/internal/domain/mapping"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/infrastructure/edastore"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
)
// bindingTestServer wires a Server backed by a single *store.Store for all
// bindingTestServer wires a Server backed by a single *pgstore.TaskDB for all
// three dashboards surfaces (Captures, Mappings, Bindings) and seeds the
// one workflow binding tests need to pass server-side validation.
func bindingTestServer(t *testing.T) *Server {
t.Helper()
s, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "test.db"))
if err != nil {
t.Fatal(err)
}
s := pgstore.Open(t)
t.Cleanup(func() { _ = s.Close() })
eda := edastore.OpenTest(t)
eda := pgstore.EDA(t, nil)
return &Server{
Store: s,
Log: slog.New(slog.DiscardHandler),
+7 -11
View File
@@ -5,32 +5,28 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/infrastructure/edastore"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
)
// captureTestServer builds a Server whose Captures field points at the same
// concrete *store.Store as Store, so tests can assert on persisted rows
// concrete *pgstore.TaskDB as Store, so tests can assert on persisted rows
// through the narrower CaptureStore interface -- Server.Store's static type
// (store.TaskStore) does not expose ListCaptures.
// (storecontract.TaskStore) does not expose ListCaptures.
func captureTestServer(t *testing.T) *Server {
t.Helper()
s, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "test.db"))
if err != nil {
t.Fatal(err)
}
s := pgstore.Open(t)
t.Cleanup(func() { _ = s.Close() })
return &Server{
Store: s,
Log: slog.New(slog.DiscardHandler),
// Captures come from the event-capture store; the task store no
// longer holds them.
Captures: edastore.OpenTest(t),
Captures: pgstore.EDA(t, nil),
}
}
@@ -39,7 +35,7 @@ func captureTestServer(t *testing.T) *Server {
// internal/infrastructure/captureintake and is tested there.
func seedCapture(t *testing.T, srv *Server, source string) string {
t.Helper()
id, err := srv.Captures.InsertCapture(t.Context(), store.CapturedEvent{
id, err := srv.Captures.InsertCapture(t.Context(), storecontract.CapturedEvent{
ReceivedAt: time.Now().UTC(),
Source: source,
Body: `{"n":1}`,
+8 -6
View File
@@ -10,9 +10,9 @@ import (
"github.com/samcharles93/archie-core/internal/channels/status"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/secret"
"github.com/samcharles93/archie-core/internal/store"
)
// fakeSecrets are recognisable strings that must never appear anywhere in
@@ -553,7 +553,7 @@ func TestRemoteConfigViewRendersThePublishedSnapshot(t *testing.T) {
if err != nil {
t.Fatal(err)
}
source := RemoteConfigView(stubSnapshots{snapshot: store.ConfigSnapshot{
source := RemoteConfigView(stubSnapshots{snapshot: storecontract.ConfigSnapshot{
Schema: ConfigViewSchema,
Document: document,
}, found: true})
@@ -573,7 +573,7 @@ func TestRemoteConfigViewRendersThePublishedSnapshot(t *testing.T) {
// TestRemoteConfigViewRefusesAnUnknownSchema: a document whose shape this
// build does not know is not something to render half of.
func TestRemoteConfigViewRefusesAnUnknownSchema(t *testing.T) {
source := RemoteConfigView(stubSnapshots{snapshot: store.ConfigSnapshot{
source := RemoteConfigView(stubSnapshots{snapshot: storecontract.ConfigSnapshot{
Schema: "webui.ConfigView/99",
Document: []byte(`{}`),
}, found: true})
@@ -600,14 +600,16 @@ func TestConfigWithNoPublishedSnapshotIsEmpty(t *testing.T) {
}
type stubSnapshots struct {
snapshot store.ConfigSnapshot
snapshot storecontract.ConfigSnapshot
found bool
err error
}
func (s stubSnapshots) PutConfigSnapshot(context.Context, store.ConfigSnapshot) error { return s.err }
func (s stubSnapshots) PutConfigSnapshot(context.Context, storecontract.ConfigSnapshot) error {
return s.err
}
func (s stubSnapshots) ConfigSnapshot(context.Context) (store.ConfigSnapshot, bool, error) {
func (s stubSnapshots) ConfigSnapshot(context.Context) (storecontract.ConfigSnapshot, bool, error) {
return s.snapshot, s.found, s.err
}
+6 -10
View File
@@ -6,25 +6,21 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
"github.com/samcharles93/archie-core/internal/domain/mapping"
"github.com/samcharles93/archie-core/internal/infrastructure/edastore"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
)
// mappingTestServer builds a Server with both Mappings and Captures backed
// by the same concrete *store.Store, so preview tests can insert a real
// by the same concrete *pgstore.TaskDB, so preview tests can insert a real
// capture and resolve a mapping against it end to end.
func mappingTestServer(t *testing.T) *Server {
t.Helper()
s, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "test.db"))
if err != nil {
t.Fatal(err)
}
s := pgstore.Open(t)
t.Cleanup(func() { _ = s.Close() })
eda := edastore.OpenTest(t)
eda := pgstore.EDA(t, nil)
return &Server{
Store: s,
Log: slog.New(slog.DiscardHandler),
@@ -200,7 +196,7 @@ func TestHandleMappingDelete(t *testing.T) {
func TestHandleMappingPreviewResolvesAgainstARealCapture(t *testing.T) {
srv := mappingTestServer(t)
capID, err := srv.Captures.InsertCapture(t.Context(), store.CapturedEvent{
capID, err := srv.Captures.InsertCapture(t.Context(), storecontract.CapturedEvent{
Source: "sentry",
Body: `{"issue":{"title":"bug found"},"count":3}`,
}, 0, 0)
+2 -2
View File
@@ -15,13 +15,13 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/taskactions"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/gateway"
taskactionstore "github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/taskstate"
)
@@ -185,7 +185,7 @@ type recordingTaskStopper struct {
}
type archiveFailingStore struct {
store.TaskStore
storecontract.TaskStore
err error
}
+10
View File
@@ -0,0 +1,10 @@
package webui
import (
"os"
"testing"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
)
func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) }
+4 -8
View File
@@ -3,7 +3,7 @@ package webui
// Remote-contract coverage for the dashboard data paths. The production UI
// process (archie-ui, and the daemon's webui) serves task, capture, mapping
// and binding routes against a *staterpc.Client — the remote read contract —
// not a concrete *store.Store. Every other webui test feeds a local store
// not a concrete *pgstore.TaskDB. Every other webui test feeds a local store
// directly, so none of them prove the handlers work once the data crosses the
// gRPC wire. These do: they stand up a real SQLite store behind
// staterpc.RegisterServer, dial it, and assert the handlers serve correctly.
@@ -21,9 +21,8 @@ import (
"google.golang.org/grpc"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/infrastructure/edastore"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/store"
)
// newRemoteTestServer serves a real SQLite store behind a gRPC listener and
@@ -33,10 +32,7 @@ import (
// rather than a fake.
func newRemoteTestServer(t *testing.T) *Server {
t.Helper()
st, err := store.Open(t.Context(), t.TempDir()+"/remote.db")
if err != nil {
t.Fatalf("open temp store: %v", err)
}
st := pgstore.Open(t)
t.Cleanup(func() { _ = st.Close() })
listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0")
@@ -48,7 +44,7 @@ func newRemoteTestServer(t *testing.T) *Server {
// surfaces, the event-capture store serves captures/mappings/bindings.
// Leaving one nil makes ListMappings/ListBindings fail closed with
// err*Unavailable, which is also the real wiring.
eda := edastore.OpenTest(t)
eda := pgstore.EDA(t, nil)
staterpc.RegisterServer(server, staterpc.Deps{
Tasks: st,
Captures: eda,
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/store"
)
// testAt is a fixed instant every synthetic event in this file shares, so a
@@ -130,7 +129,7 @@ var errWriteFailed = errors.New("write failed")
// fakeEventStore serves EventsSince from a fixed, pre-seeded slice, paginating
// the same way the real store does: up to limit events after cursor.
type fakeEventStore struct {
store.TaskStore
storecontract.TaskStore
all []events.Event
}
+7 -10
View File
@@ -20,24 +20,21 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/store"
)
func newTestServer(t *testing.T) *Server {
t.Helper()
s, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "test.db"))
if err != nil {
t.Fatal(err)
}
s := pgstore.Open(t)
t.Cleanup(func() { _ = s.Close() })
srv := &Server{Store: s, Log: slog.New(slog.DiscardHandler)}
// Composition always gives the dashboard a Gateway contract; task
@@ -51,7 +48,7 @@ func newTestServer(t *testing.T) *Server {
// inject errors. Methods that are not overridden delegate to the inner
// store via the embedded interface.
type stubStore struct {
store.TaskStore
storecontract.TaskStore
workflowStatsErr error
stageStatsErr error
tokensByDayErr error
@@ -75,21 +72,21 @@ func (s *stubStore) Requeue(ctx context.Context, id int64, from, workflow string
return s.TaskStore.Requeue(ctx, id, from, workflow)
}
func (s *stubStore) WorkflowStats(ctx context.Context) ([]store.WorkflowStat, error) {
func (s *stubStore) WorkflowStats(ctx context.Context) ([]storecontract.WorkflowStat, error) {
if s.workflowStatsErr != nil {
return nil, s.workflowStatsErr
}
return s.TaskStore.WorkflowStats(ctx)
}
func (s *stubStore) StageStats(ctx context.Context) ([]store.StageStat, error) {
func (s *stubStore) StageStats(ctx context.Context) ([]storecontract.StageStat, error) {
if s.stageStatsErr != nil {
return nil, s.stageStatsErr
}
return s.TaskStore.StageStats(ctx)
}
func (s *stubStore) TokensByDay(ctx context.Context, days int) ([]store.DayTokens, error) {
func (s *stubStore) TokensByDay(ctx context.Context, days int) ([]storecontract.DayTokens, error) {
if s.tokensByDayErr != nil {
return nil, s.tokensByDayErr
}