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:
1 parent
dda12dcdba
commit
ae552db7e0
90 files changed
+1022
-1453
No files matched your search
@@ -27,10 +27,10 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
|
||||
arnats "github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
"github.com/samcharles93/archie-core/internal/logging"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
"github.com/samcharles93/archie-core/internal/storage"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/taskrun"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
@@ -558,7 +558,7 @@ func startEmbeddedNATSForDaemon(t *testing.T) *server.Server {
|
||||
// daemonWithNATS returns the daemon, its store, and the concrete bus
|
||||
// client -- tests that drive core-NATS subscriptions directly need the
|
||||
// connection, which the TaskBus contract deliberately does not expose.
|
||||
func daemonWithNATS(t *testing.T) (*Daemon, *store.Store, *arnats.Client) {
|
||||
func daemonWithNATS(t *testing.T) (*Daemon, *pgstore.TaskDB, *arnats.Client) {
|
||||
t.Helper()
|
||||
srv := startEmbeddedNATSForDaemon(t)
|
||||
client, err := arnats.Connect(context.Background(), arnats.Config{URL: srv.ClientURL(), Subjects: []string{workintake.SubjectTaskWildcard}, FilterSubject: workintake.SubjectTaskWildcard}, slog.New(slog.DiscardHandler))
|
||||
@@ -567,7 +567,7 @@ func daemonWithNATS(t *testing.T) (*Daemon, *store.Store, *arnats.Client) {
|
||||
}
|
||||
t.Cleanup(client.Close)
|
||||
|
||||
s := store.OpenTest(t)
|
||||
s := pgstore.Open(t)
|
||||
d := &Daemon{
|
||||
Cfg: config.NewHolder(config.Config{
|
||||
Dispatch: config.Dispatch{Labels: map[string]string{
|
||||
@@ -1115,10 +1115,10 @@ func (f *testForge) React(context.Context, string, string, int, string) error
|
||||
func (f *testForge) VerifyPush(context.Context, string, string) error { return nil }
|
||||
func (f *testForge) LinkBranch(context.Context, string, string, int, string) error { return nil }
|
||||
|
||||
func testDaemon(t *testing.T, maxRetries, _ int) (*Daemon, *store.Store, *testForge) {
|
||||
func testDaemon(t *testing.T, maxRetries, _ int) (*Daemon, *pgstore.TaskDB, *testForge) {
|
||||
t.Helper()
|
||||
|
||||
s := store.OpenTest(t)
|
||||
s := pgstore.Open(t)
|
||||
fg := &testForge{}
|
||||
|
||||
cfg := config.Config{
|
||||
@@ -1256,9 +1256,9 @@ func TestDaemonStoresIdentityRunners(t *testing.T) {
|
||||
// only ever be acted on through that identity's own forge client and
|
||||
// worktree manager; it must never fall back to the root d.Forge/d.Trees
|
||||
// or leak into the other identity's client.
|
||||
func twoIdentityDaemon(t *testing.T) (d *Daemon, s *store.Store, rootFg, archieFg, winterFg *testForge) {
|
||||
func twoIdentityDaemon(t *testing.T) (d *Daemon, s *pgstore.TaskDB, rootFg, archieFg, winterFg *testForge) {
|
||||
t.Helper()
|
||||
s = store.OpenTest(t)
|
||||
s = pgstore.Open(t)
|
||||
rootFg = &testForge{}
|
||||
archieFg = &testForge{}
|
||||
winterFg = &testForge{}
|
||||
@@ -1439,7 +1439,7 @@ func TestStartupSweepsEveryConfiguredForge(t *testing.T) {
|
||||
|
||||
d := &Daemon{
|
||||
Cfg: config.NewHolder(config.Config{Repos: tc.rootRepos}),
|
||||
Store: store.OpenTest(t),
|
||||
Store: pgstore.Open(t),
|
||||
Forge: rootFg,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
Identities: runners,
|
||||
@@ -1499,7 +1499,7 @@ func TestStartupSweepIsolatesAStalledForge(t *testing.T) {
|
||||
siblingFg := &sweepForge{}
|
||||
d := &Daemon{
|
||||
Cfg: config.NewHolder(config.Config{}),
|
||||
Store: store.OpenTest(t),
|
||||
Store: pgstore.Open(t),
|
||||
Forge: rootFg,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
Identities: []*IdentityRunner{{Name: "sibling", Forge: siblingFg}},
|
||||
@@ -2139,7 +2139,7 @@ func TestDispatchCapturesTheAttemptsEffectiveConfig(t *testing.T) {
|
||||
// always fails, so the fail-open policy of the capture can be observed without
|
||||
// breaking everything else the dispatch needs.
|
||||
type failingEventStore struct {
|
||||
*store.Store
|
||||
*pgstore.TaskDB
|
||||
}
|
||||
|
||||
func (f failingEventStore) InsertEvent(context.Context, events.Event) (int64, error) {
|
||||
@@ -2151,7 +2151,7 @@ func (f failingEventStore) InsertEvent(context.Context, events.Event) (int64, er
|
||||
// go out anyway, and nothing may park.
|
||||
func TestCaptureAttemptConfigFailureDoesNotStopTheDispatch(t *testing.T) {
|
||||
d, s, busClient := daemonWithNATS(t)
|
||||
d.Store = failingEventStore{Store: s}
|
||||
d.Store = failingEventStore{TaskDB: s}
|
||||
ctx := context.Background()
|
||||
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 6, "t", "b", "", ""); err != nil {
|
||||
|
||||
@@ -3,16 +3,18 @@ package daemon
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"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"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
)
|
||||
|
||||
// Test 30: an armed binding + an authenticated capture creates a task
|
||||
@@ -249,23 +251,20 @@ func TestDispatchBindingsNilDispatcherIsNoOp(t *testing.T) {
|
||||
// production uses (CREATE TABLE + ALTER TABLE migrations), so
|
||||
// binding_id / binding_version / binding_dispatches all exist on the
|
||||
// store by the time a test runs.
|
||||
// dispatchStores pairs the two stores the dispatcher spans: tasks stay on
|
||||
// SQLite, event capture is the PocketBase store. They are embedded so a seed
|
||||
// helper still reads as one handle; the method sets no longer overlap, which
|
||||
// is exactly what the split bought.
|
||||
// dispatchStores pairs the two stores the dispatcher spans: the task store and
|
||||
// the event-capture store, so a seed helper reads as one handle.
|
||||
type dispatchStores struct {
|
||||
*store.Store
|
||||
EdaStore *edastore.Store
|
||||
*pgstore.TaskDB
|
||||
EdaStore *postgres.EDA
|
||||
edaPool *pgxpool.Pool
|
||||
}
|
||||
|
||||
func openDispatchTestStore(t *testing.T) *dispatchStores {
|
||||
t.Helper()
|
||||
s, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "dispatch.db"))
|
||||
if err != nil {
|
||||
t.Fatalf("store.Open: %v", err)
|
||||
}
|
||||
s := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = s.Close() })
|
||||
return &dispatchStores{Store: s, EdaStore: edastore.OpenTest(t)}
|
||||
pool := pgstore.Pool(t)
|
||||
return &dispatchStores{TaskDB: s, EdaStore: postgres.NewEDA(pool, nil), edaPool: pool}
|
||||
}
|
||||
|
||||
// seedMapping inserts a mapping with the given fields and returns its id.
|
||||
@@ -327,7 +326,7 @@ func seedArmedBindingWithRepo(t *testing.T, s *dispatchStores, source, mappingID
|
||||
// maxEvents=0's "no cap" reading.
|
||||
func seedCapture(t *testing.T, s *dispatchStores, source string, authenticated bool, body string) {
|
||||
t.Helper()
|
||||
_, err := s.EdaStore.InsertCapture(t.Context(), store.CapturedEvent{
|
||||
_, err := s.EdaStore.InsertCapture(t.Context(), storecontract.CapturedEvent{
|
||||
Source: source,
|
||||
Body: body,
|
||||
Authenticated: authenticated,
|
||||
@@ -339,7 +338,7 @@ func seedCapture(t *testing.T, s *dispatchStores, source string, authenticated b
|
||||
}
|
||||
|
||||
// newDispatchDaemon builds a Daemon whose store-related handles all
|
||||
// point at the same *store.Store so dispatchBindings can resolve
|
||||
// point at the same *pgstore.TaskDB so dispatchBindings can resolve
|
||||
// captures through the dispatcher handles and mappings through
|
||||
// d.Mappings. Exactly one repo is configured so resolveBindingRepo's
|
||||
// single-repo fallback accepts the dispatch; with zero or many
|
||||
@@ -377,10 +376,9 @@ func assertDispatchRecorded(t *testing.T, s *dispatchStores, bindingID string, t
|
||||
t.Helper()
|
||||
var gotBindingID string
|
||||
var gotTaskID int64
|
||||
if err := s.EdaStore.App().DB().NewQuery(
|
||||
"SELECT binding, task_id FROM binding_dispatches WHERE binding = {:binding}").
|
||||
Bind(map[string]any{"binding": bindingID}).
|
||||
Row(&gotBindingID, &gotTaskID); err != nil {
|
||||
if err := s.edaPool.QueryRow(t.Context(),
|
||||
"SELECT binding, task_id FROM binding_dispatches WHERE binding = $1", bindingID).
|
||||
Scan(&gotBindingID, &gotTaskID); err != nil {
|
||||
t.Fatalf("binding_dispatches row missing: %v", err)
|
||||
}
|
||||
if gotBindingID != bindingID || gotTaskID != taskID {
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workintake"
|
||||
"github.com/samcharles93/archie-core/internal/eventbus"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ var _ eventbus.Message = (*fakeMessage)(nil)
|
||||
// not know must not be written to the store at all. Today it is enqueued and
|
||||
// only fails open later, when forgeFor/repoFor fall back to the root forge.
|
||||
func TestProcessNATSTaskRejectsUnresolvableIdentity(t *testing.T) {
|
||||
s := store.OpenTest(t)
|
||||
s := pgstore.Open(t)
|
||||
d := &Daemon{
|
||||
Store: s,
|
||||
Cfg: config.NewHolder(config.Config{}),
|
||||
@@ -110,7 +110,7 @@ func TestProcessParksTaskWhoseIdentityNoLongerResolves(t *testing.T) {
|
||||
// still has a runner but has been retired may not act, so its tasks park
|
||||
// rather than running under a credential the control plane has retired.
|
||||
func TestProcessParksRetiredIdentity(t *testing.T) {
|
||||
s := store.OpenTest(t)
|
||||
s := pgstore.Open(t)
|
||||
ctx := context.Background()
|
||||
log := slog.New(slog.DiscardHandler)
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) }
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/eda/module"
|
||||
"github.com/samcharles93/archie-core/internal/domain/eda/playbook"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
)
|
||||
|
||||
// playbookStore loads a single playbook document from a temp directory, so
|
||||
@@ -42,7 +42,7 @@ func routableDefinitions() *workflowDefinitionsStub {
|
||||
}
|
||||
|
||||
// forgeTask enqueues a labelled forge-sourced task and returns its row.
|
||||
func forgeTask(t *testing.T, resources *store.Store, labels string) *workflow.Task {
|
||||
func forgeTask(t *testing.T, resources *pgstore.TaskDB, labels string) *workflow.Task {
|
||||
t.Helper()
|
||||
if _, err := resources.EnqueueIssue(t.Context(), "acme", "widget", 7, "title", "body", labels, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -60,7 +60,7 @@ func forgeTask(t *testing.T, resources *store.Store, labels string) *workflow.Ta
|
||||
// chosen for the same labels. Bypassing the coordinator pins "tdd" (the
|
||||
// default binding for kind bug) and fails this test.
|
||||
func TestPinWorkflowDefinitionPrefersMatchingPlaybook(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, "bug")
|
||||
|
||||
@@ -95,7 +95,7 @@ actions:
|
||||
// an additional routing source, not a replacement. A non-matching playbook
|
||||
// set leaves the existing kind/label bindings in charge.
|
||||
func TestPinWorkflowDefinitionFallsBackWhenNoPlaybookMatches(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, "bug")
|
||||
|
||||
@@ -125,7 +125,7 @@ actions:
|
||||
// Silently running the kind binding's choice instead would run the wrong
|
||||
// workflow under a rule the operator wrote.
|
||||
func TestPinWorkflowDefinitionPlaybookWorkflowMustExist(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, "bug")
|
||||
|
||||
@@ -155,7 +155,7 @@ actions:
|
||||
// assignment is a decision already made about this task and must not be
|
||||
// re-routed by a playbook trigger that still matches its labels.
|
||||
func TestPinWorkflowDefinitionPreAssignedWorkflowBeatsPlaybook(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, "bug")
|
||||
task.Workflow = "tdd"
|
||||
@@ -203,7 +203,7 @@ actions:
|
||||
{name: "condition false leaves the kind binding in charge", labels: "bug", want: "tdd"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, tc.labels)
|
||||
d := &Daemon{
|
||||
@@ -228,7 +228,7 @@ actions:
|
||||
// recognises still triggers a playbook, which is the only way an operator can
|
||||
// bind a workflow to their own taxonomy without a code change.
|
||||
func TestPinWorkflowDefinitionTriggersOnInstanceDefinedLabel(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, "ops::security-review,needs-triage")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/eda/playbook"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
)
|
||||
|
||||
// runRecorder is a playbook set that matches no workflow playbook and records
|
||||
@@ -50,7 +50,7 @@ func TestPinWorkflowDefinitionRunsActionPlaybooks(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task := forgeTask(t, resources, "bug")
|
||||
task.Workflow = tt.workflow
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
archiecontainer "github.com/samcharles93/archie-core/internal/container"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
"github.com/samcharles93/archie-core/internal/storage"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/taskrun"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
@@ -240,7 +240,7 @@ func TestCleanupTerminalTaskWorktreeWithCancelledContext(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // cancel context before calling cleanup
|
||||
|
||||
st := store.OpenTest(t)
|
||||
st := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
|
||||
trees := &worktree.Manager{WorkDir: t.TempDir()}
|
||||
@@ -409,7 +409,7 @@ func TestParkRunningTaskGuardedAndLogging(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := store.OpenTest(t)
|
||||
s := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = s.Close() })
|
||||
|
||||
var buf logBuffer
|
||||
@@ -443,7 +443,7 @@ func TestParkRunningTaskGuardedAndLogging(t *testing.T) {
|
||||
}
|
||||
|
||||
if tt.closeStore {
|
||||
_ = s.Close()
|
||||
s.Pool.Close()
|
||||
}
|
||||
|
||||
d.parkRunningTask(callCtx, task.ID, "simulated park reason", taskstate.ParkTransient)
|
||||
@@ -494,7 +494,7 @@ func TestAcquireTaskContainerFailureParksTaskOnCancelledContext(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := store.OpenTest(t)
|
||||
s := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = s.Close() })
|
||||
|
||||
d := &Daemon{
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
archiecontainer "github.com/samcharles93/archie-core/internal/container"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
"github.com/samcharles93/archie-core/internal/storage"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/taskrun"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
)
|
||||
@@ -148,7 +148,7 @@ func TestCleanupTerminalTaskWorktreeLifecycle(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := store.OpenTest(t)
|
||||
st := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
|
||||
rootTrees := &worktree.Manager{WorkDir: t.TempDir()}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
)
|
||||
|
||||
type workflowDefinitionsStub struct {
|
||||
@@ -18,7 +18,7 @@ func (s *workflowDefinitionsStub) WorkflowDefinitions(context.Context) (workflow
|
||||
}
|
||||
|
||||
func TestWorkflowDefinitionPinSurvivesActiveOverride(t *testing.T) {
|
||||
resources := store.OpenTest(t)
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task, err := resources.EnqueueChatTask(t.Context(), "acme", "widget", "custom", "", "custom", "operator")
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user