From e3ee044c5e3ec994112ade999b519d4ef526f85d Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 24 Sep 2026 14:43:50 +1000 Subject: [PATCH] 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. --- cmd/archie-messaging/architecture_test.go | 4 +- cmd/archie-state-store/import_test.go | 15 +- cmd/archie-state-store/main_test.go | 28 +- cmd/archie-state-store/recovery.go | 16 +- cmd/archie-state-store/recovery_test.go | 526 ++++-------------- cmd/archie-ui/architecture_test.go | 4 +- cmd/archie-ui/main_test.go | 26 +- cmd/archie-ui/pgtest_test.go | 10 + go.mod | 18 +- go.sum | 51 -- internal/app/agentworker/pgtest_test.go | 10 + .../app/agentworker/task_execution_test.go | 13 +- internal/app/archied/binding_cipher.go | 6 +- .../archied/chat_store_composition_test.go | 8 +- .../archied/config_snapshot_channels_test.go | 9 +- internal/app/archied/config_snapshot_test.go | 19 +- .../app/archied/control_plane_restart_test.go | 4 +- .../control_plane_watch_outage_test.go | 13 +- internal/app/archied/cutover_test.go | 17 +- internal/app/archied/main.go | 5 - internal/app/archied/main_test.go | 24 +- internal/app/archied/readiness_test.go | 8 +- internal/app/archied/routing_bindings_test.go | 9 +- internal/app/archied/sd_notify_test.go | 8 +- .../app/archied/state_store_consumers_test.go | 34 +- internal/app/archied/state_store_eda.go | 4 +- internal/app/archied/state_store_recovery.go | 140 +---- .../archied/state_store_recovery_postgres.go | 5 +- internal/app/archied/state_store_test.go | 20 +- internal/app/archied/state_store_toolcalls.go | 10 +- .../app/archied/state_store_toolcalls_test.go | 24 +- internal/app/archied/status_health_test.go | 4 +- .../app/archied/task_action_adapter_test.go | 29 +- internal/app/archied/task_actions_test.go | 14 +- internal/app/archieui/compose_test.go | 6 +- internal/app/archieui/degraded_routes_test.go | 10 +- internal/app/archieui/pgtest_test.go | 10 + internal/app/archieui/run_test.go | 13 +- internal/app/archieui/task_logs_test.go | 10 +- internal/app/controlplane/controlplane.go | 18 +- .../app/controlplane/controlplane_test.go | 25 +- .../controlplane/controlplane_watch_test.go | 7 +- internal/app/controlplane/pgtest_test.go | 10 + internal/app/controlplane/registry.go | 8 +- internal/app/controlplane/runtime_config.go | 6 +- .../step_vocabulary_agreement_test.go | 6 +- .../app/controlplane/workflow_settings.go | 6 +- internal/daemon/daemon_test.go | 22 +- internal/daemon/dispatch_bindings_test.go | 38 +- internal/daemon/identity_dispatch_test.go | 6 +- internal/daemon/pgtest_test.go | 10 + internal/daemon/playbook_dispatch_test.go | 16 +- internal/daemon/playbook_run_test.go | 4 +- internal/daemon/task_cancellation_test.go | 10 +- internal/daemon/terminal_cleanup_test.go | 4 +- internal/daemon/workflow_definition_test.go | 4 +- internal/domain/workflow/pgtest_test.go | 10 + .../domain/workflow/store_integration_test.go | 21 +- .../infrastructure/bindingcipher/cipher.go | 4 +- .../bindingcipher/cipher_test.go | 107 +--- .../captureintake/pgtest_test.go | 10 + .../captureintake/receiver_test.go | 15 +- .../gatewayrpc/conformance_test.go | 4 +- .../legacyfixture/legacyfixture.go | 157 ++++++ .../legacyimport/legacyimport_test.go | 158 +----- internal/infrastructure/postgres/edastore.go | 58 +- .../infrastructure/postgres/edastore_test.go | 56 +- .../postgres/pgstore/pgstore.go | 61 ++ internal/infrastructure/postgres/resources.go | 3 +- .../staterpc/attribution_test.go | 4 +- .../staterpc/capture_stream_test.go | 12 +- .../staterpc/conformance_test.go | 67 +-- .../infrastructure/staterpc/error_test.go | 20 +- .../infrastructure/staterpc/pgtest_test.go | 10 + .../staterpc/task_grants_test.go | 20 +- .../staterpc/task_log_nilslice_test.go | 4 +- .../infrastructure/staterpc/task_log_test.go | 6 +- .../infrastructure/taskactions/pgtest_test.go | 10 + .../infrastructure/taskactions/rpc_test.go | 6 +- internal/webui/api_binding_test.go | 13 +- internal/webui/api_capture_test.go | 18 +- internal/webui/api_config_test.go | 14 +- internal/webui/api_mapping_test.go | 16 +- internal/webui/api_tasks_actions_test.go | 4 +- internal/webui/pgtest_test.go | 10 + internal/webui/remote_store_test.go | 12 +- internal/webui/sse_test.go | 3 +- internal/webui/webui_test.go | 17 +- tools/go.mod | 6 - tools/go.sum | 155 ++++-- 90 files changed, 1022 insertions(+), 1453 deletions(-) create mode 100644 cmd/archie-ui/pgtest_test.go create mode 100644 internal/app/agentworker/pgtest_test.go create mode 100644 internal/app/archieui/pgtest_test.go create mode 100644 internal/app/controlplane/pgtest_test.go create mode 100644 internal/daemon/pgtest_test.go create mode 100644 internal/domain/workflow/pgtest_test.go create mode 100644 internal/infrastructure/captureintake/pgtest_test.go create mode 100644 internal/infrastructure/legacyimport/legacyfixture/legacyfixture.go create mode 100644 internal/infrastructure/postgres/pgstore/pgstore.go create mode 100644 internal/infrastructure/staterpc/pgtest_test.go create mode 100644 internal/infrastructure/taskactions/pgtest_test.go create mode 100644 internal/webui/pgtest_test.go diff --git a/cmd/archie-messaging/architecture_test.go b/cmd/archie-messaging/architecture_test.go index 876f96c35..d2feb77cf 100644 --- a/cmd/archie-messaging/architecture_test.go +++ b/cmd/archie-messaging/architecture_test.go @@ -36,7 +36,9 @@ type bannedCategory struct { var deletionGate = []bannedCategory{ {"state store", []string{ "modernc.org/sqlite", - modulePath + "internal/store", + "github.com/jackc/pgx", + modulePath + "internal/infrastructure/postgres", + modulePath + "internal/infrastructure/legacyread", }}, {"daemon runtime", []string{ modulePath + "internal/daemon", diff --git a/cmd/archie-state-store/import_test.go b/cmd/archie-state-store/import_test.go index f0a61458c..97bcbb3bc 100644 --- a/cmd/archie-state-store/import_test.go +++ b/cmd/archie-state-store/import_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/legacyimport/legacyfixture" "github.com/samcharles93/archie-core/internal/infrastructure/postgres" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" ) @@ -17,18 +18,14 @@ func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } // against the same database is refused because the first one completed. func TestRecoveryImportMovesTheInstallOnce(t *testing.T) { dbPath := filepath.Join(t.TempDir(), "archie.db") - st := openTaskStore(t, dbPath+"-tasks.sqlite") - seedTask(t, st, "carried over") - if err := st.Close(); err != nil { - t.Fatalf("close task store: %v", err) - } + legacyfixture.Install(t, dbPath) url := pgtest.URL(t) code, stdout, stderr := runRecoveryCmd(t, "import", "-db-path", dbPath, "-database-url", url) if code != 0 { t.Fatalf("import exited %d; stderr = %q", code, stderr) } - if !strings.Contains(stdout, "tasks=1") { + if !strings.Contains(stdout, "tasks=2") { t.Errorf("import summary %q does not report the imported task", stdout) } @@ -37,9 +34,9 @@ func TestRecoveryImportMovesTheInstallOnce(t *testing.T) { t.Fatalf("postgres.Open: %v", err) } defer pool.Close() - var title string - if err := pool.QueryRow(t.Context(), "SELECT title FROM tasks").Scan(&title); err != nil || title != "carried over" { - t.Fatalf("imported task title = %q, %v; want %q", title, err, "carried over") + var issue int64 + if err := pool.QueryRow(t.Context(), "SELECT issue_number FROM tasks WHERE id = 1").Scan(&issue); err != nil || issue != 7 { + t.Fatalf("imported task 1 issue = %d, %v; want 7", issue, err) } code, _, stderr = runRecoveryCmd(t, "import", "-db-path", dbPath, "-database-url", url) diff --git a/cmd/archie-state-store/main_test.go b/cmd/archie-state-store/main_test.go index bf2c5f6a5..3f8d5d82b 100644 --- a/cmd/archie-state-store/main_test.go +++ b/cmd/archie-state-store/main_test.go @@ -37,10 +37,10 @@ import ( "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/events" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" - "github.com/samcharles93/archie-core/internal/store" ) // repoRoot walks up from the test's source directory to find the module root @@ -92,6 +92,12 @@ func buildBinary(t *testing.T, dir string) string { // db_path and database_url it owns. The // forge token resolves from an env var, so no real credential is needed. func writeMinimalConfig(t *testing.T, dir string) string { + t.Helper() + return writeConfigFor(t, dir, pgtest.URL(t)) +} + +// writeConfigFor is writeMinimalConfig naming the database at url. +func writeConfigFor(t *testing.T, dir, url string) string { t.Helper() cfg := filepath.Join(dir, "config.toml") content := fmt.Sprintf(`bot_user = "archie-bot" @@ -104,7 +110,7 @@ token = { engine = "env", key = "ARCHIE_GITHUB_TOKEN" } [[repos]] owner = "acme" name = "widget" -`, filepath.Join(dir, "archie.db"), pgtest.URL(t)) +`, filepath.Join(dir, "archie.db"), url) if err := os.WriteFile(cfg, []byte(content), 0o600); err != nil { t.Fatalf("write config: %v", err) } @@ -287,13 +293,13 @@ func (p *stateStoreProcess) stop(t *testing.T) { } // contract is the combined consumer surface a daemon/gateway/agent mixes: the -// task lifecycle + events surface (store.TaskStore) and the capture surface. +// task lifecycle + events surface (storecontract.TaskStore) and the capture surface. // Mapping/binding/dispatch is exercised separately in // TestStateStoreRealProcessRemoteSurfaces via the concrete Client, which // asserts against each narrow interface at compile time. type contract interface { - store.TaskStore - store.CaptureStore + storecontract.TaskStore + storecontract.CaptureStore } // dial opens a gRPC connection to the state store process and wraps it in the @@ -311,8 +317,8 @@ func dial(t *testing.T, addr string) contract { // capture builds a CapturedEvent without pulling the whole store field set // into every call site. -func capture(source, body string) store.CapturedEvent { - return store.CapturedEvent{Source: source, Body: body, Authenticated: true} +func capture(source, body string) storecontract.CapturedEvent { + return storecontract.CapturedEvent{Source: source, Body: body, Authenticated: true} } // TestStateStoreRealProcessSmoke exercises the actual archie-state-store @@ -409,14 +415,14 @@ func TestStateStoreRealProcessSmoke(t *testing.T) { } t.Run("error_sentinel_fidelity", func(t *testing.T) { - // A stale transition must rehydrate to store.ErrStaleTransition across + // A stale transition must rehydrate to storecontract.ErrStaleTransition across // the wire (§7). Because the binary is up and we dialed it, a sentinel // mismatch here would surface as a transport error, so a pass proves // the gRPC mapError/unmapError round-trip, not just the in-process // adapter. err := cl.Transition(ctx, task.ID, "queued", "merged", "") - if !errors.Is(err, store.ErrStaleTransition) { - t.Fatalf("stale Transition = %v, want store.ErrStaleTransition", err) + if !errors.Is(err, storecontract.ErrStaleTransition) { + t.Fatalf("stale Transition = %v, want storecontract.ErrStaleTransition", err) } }) @@ -612,7 +618,7 @@ func TestStateStoreRealProcessRemoteSurfaces(t *testing.T) { } // Remote surfaces share error-sentinel fidelity on the wire too. missing := mapping.Mapping{ID: "rabsent00000000", Name: "x", Fields: []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}} - if err := cl.UpdateMapping(ctx, missing); !errors.Is(err, store.ErrMappingNotFound) { + if err := cl.UpdateMapping(ctx, missing); !errors.Is(err, storecontract.ErrMappingNotFound) { t.Fatalf("UpdateMapping missing = %v, want ErrMappingNotFound", err) } } diff --git a/cmd/archie-state-store/recovery.go b/cmd/archie-state-store/recovery.go index dcab44c29..a2df7e8ac 100644 --- a/cmd/archie-state-store/recovery.go +++ b/cmd/archie-state-store/recovery.go @@ -20,10 +20,9 @@ const recoveryUsage = `usage: archie-state-store [flags] With no command, archie-state-store serves the State Store gRPC contract. The recovery commands are how an operator recovers a database the control -plane will not start on. Without -db they operate on the PostgreSQL database -the configuration's database_url names, through pg_dump and pg_restore (which -must be on PATH); with -db, on a legacy SQLite task file (the configured -db_path with "-tasks.sqlite" appended). +plane will not start on. They operate on the PostgreSQL database the +configuration's database_url names, through pg_dump and pg_restore (which +must be on PATH). backup takes a consistent snapshot of a serving database. restore is destructive and offline: stop every archie service first, since it refuses @@ -32,11 +31,11 @@ snapshot is lost. rollback refuses while the State Store serves. There is no automatic schema rollback: the way back from a migration is restoring the snapshot taken before it. - backup [-db FILE] -out FILE write a snapshot of the database - restore [-db FILE] -from FILE replace the database with a snapshot - validate [-db FILE] check the database, its stored settings and + backup -out FILE write a snapshot of the database + restore -from FILE replace the database with a snapshot + validate check the database, its stored settings and the configuration the daemon would boot with - rollback [-db FILE] -kind KIND replay an earlier revision of a stored + rollback -kind KIND replay an earlier revision of a stored [-revision N] resource through the ordinary replace import [-db-path PATH] copy the legacy SQLite stores named from [-database-url URL] db_path into an empty Postgres database, @@ -68,7 +67,6 @@ func runRecovery(args []string, stdout, stderr io.Writer) int { flags := flag.NewFlagSet("archie-state-store "+command, flag.ContinueOnError) flags.SetOutput(stderr) flags.Usage = func() { fmt.Fprint(stderr, recoveryUsage) } - flags.StringVar(&options.DB, "db", "", "legacy SQLite task file (-tasks.sqlite); omit to use the configured database_url") flags.StringVar(&options.Out, "out", "", "snapshot file backup writes") flags.StringVar(&options.From, "from", "", "snapshot file restore reads") flags.StringVar(&options.Kind, "kind", "", "control-plane resource kind rollback replays") diff --git a/cmd/archie-state-store/recovery_test.go b/cmd/archie-state-store/recovery_test.go index 436e18306..8756ba2c2 100644 --- a/cmd/archie-state-store/recovery_test.go +++ b/cmd/archie-state-store/recovery_test.go @@ -1,19 +1,18 @@ -// Package main tests the offline recovery subcommands of archie-state-store: -// backup, restore, validate and rollback against the task database file -// directly. They are the operator's only path back when the control plane's -// stored settings will not validate, because the daemon fails closed: the -// in-band remedy (replay an earlier revision while the State Store is up) is -// unavailable in exactly the case that needs it. +// Package main tests the offline recovery subcommands of archie-state-store +// against the PostgreSQL database the configuration names. They are the +// operator's only path back when the control plane's stored settings will not +// validate, because the daemon fails closed: the in-band remedy (replay an +// earlier revision while the State Store is up) is unavailable in exactly the +// case that needs it. // // The tests drive the subcommands the way an operator does -- through -// runRecovery, against real files on disk -- rather than through the internal -// helpers, so the flag surface and the exit codes are part of what is verified. +// runRecovery -- rather than through the internal helpers, so the flag surface +// and the exit codes are part of what is verified. package main import ( "bytes" - "database/sql" "encoding/json" "fmt" "os" @@ -22,13 +21,14 @@ import ( "strings" "testing" - _ "modernc.org/sqlite" - "github.com/samcharles93/archie-core/internal/app/archied" "github.com/samcharles93/archie-core/internal/app/controlplane" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/infrastructure/configuration" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" "github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps" - "github.com/samcharles93/archie-core/internal/store" ) // runRecoveryCmd runs one subcommand the way main does and returns its exit @@ -40,240 +40,38 @@ func runRecoveryCmd(t *testing.T, args ...string) (int, string, string) { return code, stdout.String(), stderr.String() } -// openTaskStore opens the task database the subcommands operate on. It does not -// take the ownership lock: only the serving process does that, and a test that -// wants a "live" store holds it explicitly with holdStoreOwnership. -func openTaskStore(t *testing.T, path string) *store.Store { +// recoveryFixture writes a config naming a fresh migrated database and returns +// it with the task database on that database. +func recoveryFixture(t *testing.T) (string, *pgstore.TaskDB) { t.Helper() - st, err := store.Open(t.Context(), path) - if err != nil { - t.Fatalf("open task store %s: %v", path, err) - } - t.Cleanup(func() { _ = st.Close() }) - return st + url := pgtest.URL(t) + configPath := writeConfigFor(t, t.TempDir(), url) + return configPath, pgstore.On(pgstore.PoolAt(t, url)) } -// holdStoreOwnership takes the ownership lock the running State Store holds for -// its whole life, so a test can prove a command refuses to touch a live store. -func holdStoreOwnership(t *testing.T, path string) { - t.Helper() - ownership, err := store.AcquireOwnership(path) - if err != nil { - t.Fatalf("acquire store ownership: %v", err) - } - t.Cleanup(func() { _ = ownership.Release() }) -} - -// seedTask writes one task so a snapshot can be distinguished from the live -// database by what it contains, not merely by its existence. -func seedTask(t *testing.T, st *store.Store, title string) { +// seedTask writes one task so the database holds more than its settings. +func seedTask(t *testing.T, st *pgstore.TaskDB, title string) { t.Helper() if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", ""); err != nil { t.Fatalf("seed task %q: %v", title, err) } } -func taskTitles(t *testing.T, path string) []string { +// execRaw runs one statement against the database the way an operator editing +// a broken store would, bypassing every check the store applies. +func execRaw(t *testing.T, st *pgstore.TaskDB, statement string) { t.Helper() - st := openTaskStore(t, path) - tasks, err := st.Tasks(t.Context(), 100) - if err != nil { - t.Fatalf("list tasks in %s: %v", path, err) - } - titles := make([]string, 0, len(tasks)) - for _, task := range tasks { - titles = append(titles, task.Title) - } - return titles -} - -// backupPath is the snapshot every restore test restores from. -func backupPath(t *testing.T, dir string) string { return filepath.Join(dir, "snapshot.sqlite") } - -// backup takes the snapshot the caller then restores, through the subcommand -// under test rather than through the store directly, so a broken backup fails -// the restore test too instead of silently passing an empty file. -func backup(t *testing.T, db, out string) { - t.Helper() - code, _, stderr := runRecoveryCmd(t, "backup", "-db", db, "-out", out) - if code != 0 { - t.Fatalf("backup exited %d: %s", code, stderr) - } -} - -// The update installer cannot stop the process that runs it, so it backs the -// task database up while the State Store is serving. VACUUM INTO is safe -// against a live writer; a backup that insisted on an exclusively-owned file -// would break the one caller it has, and the update would refuse to start. -func TestRecoveryBackupSnapshotsAStoreItsStateStoreIsServing(t *testing.T) { - dir := t.TempDir() - db := filepath.Join(dir, "archie.db-tasks.sqlite") - out := backupPath(t, dir) - seedTask(t, openTaskStore(t, db), "before") - holdStoreOwnership(t, db) - if err := os.WriteFile(out, []byte("stale snapshot"), 0o600); err != nil { + if _, err := st.Pool.Exec(t.Context(), statement); err != nil { t.Fatal(err) } - - code, stdout, stderr := runRecoveryCmd(t, "backup", "-db", db, "-out", out) - if code != 0 { - t.Fatalf("backup exited %d: %s", code, stderr) - } - if !strings.Contains(stdout, out) || !strings.Contains(stdout, db) { - t.Errorf("backup must report the database and the snapshot it wrote; stdout = %q", stdout) - } - // The stale file was replaced by a real snapshot, and the snapshot is a - // store a restore can put back: same rows, readable through the store. - if got := taskTitles(t, out); len(got) != 1 || got[0] != "before" { - t.Fatalf("snapshot tasks = %v, want the one seeded task", got) - } - if entries, err := filepath.Glob(out + ".tmp*"); err != nil || len(entries) != 0 { - t.Errorf("backup left scratch files beside the snapshot: %v (%v)", entries, err) - } -} - -// The snapshot is the rollback state, so an interrupted backup must never -// leave a truncated file where a good snapshot was. -func TestRecoveryBackupRefusesAMissingDatabase(t *testing.T) { - dir := t.TempDir() - code, _, stderr := runRecoveryCmd(t, "backup", "-db", filepath.Join(dir, "absent.sqlite"), "-out", backupPath(t, dir)) - if code == 0 { - t.Fatal("backup of a missing database succeeded") - } - if !strings.Contains(stderr, "absent.sqlite") { - t.Errorf("refusal must name the database it could not read; stderr = %q", stderr) - } -} - -// backup is the one recovery command allowed to run against a serving store, -// and that exemption is only sound while it never replaces the database. With -// -out naming the database it renames the snapshot over the live file and -// leaves the WAL of the database it just unlinked -- the state the restore path -// refuses up front and the code elsewhere calls unrecoverable. -func TestRecoveryBackupRefusesTheDatabaseAsItsOwnSnapshot(t *testing.T) { - db := filepath.Join(t.TempDir(), "archie.db-tasks.sqlite") - st := openTaskStore(t, db) - seedTask(t, st, "live") - - code, _, stderr := runRecoveryCmd(t, "backup", "-db", db, "-out", db) - if code == 0 { - t.Fatal("backup over the database itself succeeded") - } - if !strings.Contains(stderr, "is the database itself") { - t.Errorf("refusal must say the snapshot is the database; stderr = %q", stderr) - } - if got := taskTitles(t, db); len(got) != 1 || got[0] != "live" { - t.Fatalf("refused backup changed the database: tasks = %v", got) - } -} - -// Restoring is the forward-migration escape hatch: the previous release -// reads this file, so it must be exactly the snapshot, with the WAL that -// belongs to the replaced database gone rather than replayed over it. -func TestRecoveryRestorePutsTheSnapshotBackAndDropsItsWAL(t *testing.T) { - dir := t.TempDir() - db := filepath.Join(dir, "archie.db-tasks.sqlite") - out := backupPath(t, dir) - st := openTaskStore(t, db) - seedTask(t, st, "before") - backup(t, db, out) - seedTask(t, st, "after") - - code, stdout, stderr := runRecoveryCmd(t, "restore", "-db", db, "-from", out) - if code != 0 { - t.Fatalf("restore exited %d: %s", code, stderr) - } - if !strings.Contains(stdout, out) { - t.Errorf("restore must report the snapshot it restored from; stdout = %q", stdout) - } - // Checked before anything reopens the database: opening a store sets WAL - // mode, which creates these files, so the point is that the restore did not - // leave the replaced database's log behind -- not that a later reader - // cannot recreate its own. - for _, suffix := range []string{"-wal", "-shm"} { - if _, err := os.Stat(db + suffix); err == nil { - t.Errorf("%s survived the restore: the replaced database's write-ahead log must not be replayed over the snapshot", db+suffix) - } - } - if got := taskTitles(t, db); len(got) != 1 || got[0] != "before" { - t.Fatalf("restored tasks = %v, want only the snapshot's task", got) - } -} - -// Overwriting a database a running State Store still owns leaves that process -// writing to an unlinked inode while the store serves a file nobody owns -- -// the one way an offline command can destroy a task store. -func TestRecoveryRestoreRefusesAStoreTheStateStoreIsRunning(t *testing.T) { - dir := t.TempDir() - db := filepath.Join(dir, "archie.db-tasks.sqlite") - out := backupPath(t, dir) - st := openTaskStore(t, db) - seedTask(t, st, "before") - backup(t, db, out) - seedTask(t, st, "after") - holdStoreOwnership(t, db) - - code, _, stderr := runRecoveryCmd(t, "restore", "-db", db, "-from", out) - if code == 0 { - t.Fatal("restore against a live State Store succeeded") - } - if !strings.Contains(stderr, "owned by another process") { - t.Errorf("refusal must say the database is owned by another process; stderr = %q", stderr) - } - if got := taskTitles(t, db); len(got) != 2 { - t.Fatalf("refused restore changed the database: tasks = %v", got) - } -} - -func TestRecoveryRestoreRefusesAFileThatIsNotAStore(t *testing.T) { - dir := t.TempDir() - db := filepath.Join(dir, "archie.db-tasks.sqlite") - seedTask(t, openTaskStore(t, db), "live") - notAStore := filepath.Join(dir, "notes.txt") - if err := os.WriteFile(notAStore, []byte("this is not a database"), 0o600); err != nil { - t.Fatal(err) - } - - code, _, stderr := runRecoveryCmd(t, "restore", "-db", db, "-from", notAStore) - if code == 0 { - t.Fatal("restore from a file that is not a store succeeded") - } - if !strings.Contains(stderr, notAStore) { - t.Errorf("refusal must name the snapshot it could not read; stderr = %q", stderr) - } - if got := taskTitles(t, db); len(got) != 1 { - t.Fatalf("refused restore changed the database: tasks = %v", got) - } -} - -func TestRecoveryRestoreRefusesTheDatabaseAsItsOwnSnapshot(t *testing.T) { - // Restoring a database from itself would delete the write-ahead log of the - // file it is about to copy, so the one case that must never reach the swap - // is refused up front. - db := filepath.Join(t.TempDir(), "archie.db-tasks.sqlite") - seedTask(t, openTaskStore(t, db), "live") - - code, _, stderr := runRecoveryCmd(t, "restore", "-db", db, "-from", db) - if code == 0 { - t.Fatal("restore from the database itself succeeded") - } - if !strings.Contains(stderr, "is the database itself") { - t.Errorf("refusal must say the snapshot is the database; stderr = %q", stderr) - } - if got := taskTitles(t, db); len(got) != 1 { - t.Fatalf("refused restore changed the database: tasks = %v", got) - } } func TestRecoveryValidateAcceptsAHealthyStore(t *testing.T) { - dir := t.TempDir() - configPath := writeMinimalConfig(t, dir) - db := filepath.Join(dir, "archie.db-tasks.sqlite") - st := openTaskStore(t, db) + configPath, st := recoveryFixture(t) seedTask(t, st, "healthy") seedStoreResources(t, st, configPath) - code, stdout, stderr := runRecoveryCmd(t, "validate", "-db", db, "-config", configPath) + code, stdout, stderr := runRecoveryCmd(t, "validate", "-config", configPath) if code != 0 { t.Fatalf("validate exited %d: %s", code, stderr) } @@ -293,63 +91,54 @@ func TestRecoveryValidateAcceptsAHealthyStore(t *testing.T) { // path's own per-resource decode, and the two disagree: the write path accepts // a scheduling policy boot rejects. func TestRecoveryValidateRunsTheGateBootRuns(t *testing.T) { - dir := t.TempDir() - configPath := writeMinimalConfig(t, dir) - db := filepath.Join(dir, "archie.db-tasks.sqlite") - seedStoreResources(t, openTaskStore(t, db), configPath) + configPath, st := recoveryFixture(t) + seedStoreResources(t, st, configPath) // The control: a store seeded from this config is one the daemon boots on. - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db, "-config", configPath) + code, _, stderr := runRecoveryCmd(t, "validate", "-config", configPath) if code != 0 { t.Fatalf("validate exited %d on a store the daemon starts on: %s", code, stderr) } + // The upgrade case: a release defines a kind the store does not hold yet, + // and validate runs before the State Store has started again. The State + // Store seeds the kind it is missing, so the store is not the reason the + // daemon would refuse to start. + execRaw(t, st, `DELETE FROM resources WHERE kind='provider-settings'`) + code, stdout, stderr := runRecoveryCmd(t, "validate", "-config", configPath) + if code != 0 { + t.Fatalf("validate refused a store missing a kind the State Store seeds; stderr = %q", stderr) + } + if count := storedResourceCount(t, stdout); count == 0 { + t.Errorf("validate must still check the kinds the store does hold; stdout = %q", stdout) + } + // A hand-edited value, or an older revision of one: the write path's own // validator never inspects dispatch.trigger, so only the config gate // catches it, and the daemon exits 1 on it (validateDispatch). - if err := execRaw(t, db, `UPDATE resources SET value='{"poll_interval":"1m","max_retries":3,"dispatch":{"trigger":"bogus"}}' WHERE kind='scheduling-policy'`); err != nil { - t.Fatal(err) - } - code, stdout, stderr := runRecoveryCmd(t, "validate", "-db", db, "-config", configPath) + execRaw(t, st, `UPDATE resources SET value='{"poll_interval":"1m","max_retries":3,"dispatch":{"trigger":"bogus"}}' WHERE kind='scheduling-policy'`) + code, stdout, stderr = runRecoveryCmd(t, "validate", "-config", configPath) if code == 0 { t.Fatalf("validate accepted a stored policy the daemon refuses to boot with; stdout = %q", stdout) } if !strings.Contains(stderr, "dispatch.trigger") { t.Errorf("refusal must name what boot rejects; stderr = %q", stderr) } +} - // A store the State Store never seeded holds no kinds at all. Its next start - // creates the resources table and seeds every kind from this same config - // (internal/app/archied/state_store.go), so archied layers those seeds and - // starts: refusing the file here would send an operator to restore a - // snapshot for a store the daemon boots on perfectly well. - unseeded := filepath.Join(dir, "unseeded.db-tasks.sqlite") - openTaskStore(t, unseeded) - code, stdout, stderr = runRecoveryCmd(t, "validate", "-db", unseeded, "-config", configPath) +// A database the State Store never seeded holds no kinds at all. Its next +// start seeds every kind from this same config, so archied layers those seeds +// and starts: refusing it would send an operator to restore a snapshot for a +// database the daemon boots on perfectly well. +func TestRecoveryValidateAcceptsAnUnseededDatabase(t *testing.T) { + configPath, _ := recoveryFixture(t) + code, stdout, stderr := runRecoveryCmd(t, "validate", "-config", configPath) if code != 0 { t.Fatalf("validate refused a store the State Store would seed on its next start; stderr = %q", stderr) } if !strings.Contains(stdout, "0 stored resources validate") { t.Errorf("validate must report that there was nothing stored to check; stdout = %q", stdout) } - - // The upgrade case: a release defines a kind the store does not hold yet, - // and validate runs before the State Store has started again. The State - // Store seeds the kind it is missing, so this is the same stance as the - // store with nothing stored at all -- the file is not the reason the daemon - // would refuse to start, and saying otherwise costs the operator a snapshot. - partial := filepath.Join(dir, "partial.db-tasks.sqlite") - seedStoreResources(t, openTaskStore(t, partial), configPath) - if err := execRaw(t, partial, `DELETE FROM resources WHERE kind='provider-settings'`); err != nil { - t.Fatal(err) - } - code, stdout, stderr = runRecoveryCmd(t, "validate", "-db", partial, "-config", configPath) - if code != 0 { - t.Fatalf("validate refused a store missing a kind the State Store seeds; stderr = %q", stderr) - } - if count := storedResourceCount(t, stdout); count == 0 { - t.Errorf("validate must still check the kinds the store does hold; stdout = %q", stdout) - } } // The subcommands advertise -h as the way to read their flags, and the serve @@ -372,10 +161,7 @@ func TestRecoveryHelpExitsZero(t *testing.T) { func TestRecoveryValidateLeavesTheDaemonLogAlone(t *testing.T) { dir := t.TempDir() configPath, logFile := writeConfigWithLogFile(t, dir) - db := filepath.Join(dir, "archie.db-tasks.sqlite") - seedStoreResources(t, openTaskStore(t, db), configPath) - - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db, "-config", configPath) + code, _, stderr := runRecoveryCmd(t, "validate", "-config", configPath) if code != 0 { t.Fatalf("validate exited %d: %s", code, stderr) } @@ -419,11 +205,10 @@ func TestRecoveryDefaultConfigResolvesWhereTheDaemonReads(t *testing.T) { if err := os.MkdirAll(configDir, 0o700); err != nil { t.Fatalf("create %s: %v", configDir, err) } - configPath := writeMinimalConfig(t, configDir) - db := filepath.Join(root, "archie.db-tasks.sqlite") - seedStoreResources(t, openTaskStore(t, db), configPath) - - code, stdout, stderr := runRecoveryCmd(t, "validate", "-db", db) + url := pgtest.URL(t) + pgstore.PoolAt(t, url) + configPath := writeConfigFor(t, configDir, url) + code, stdout, stderr := runRecoveryCmd(t, "validate") if !tc.wantOK { if code == 0 { t.Fatalf("validate exited 0 with no config at the resolved path %s: %s", configPath, stdout) @@ -434,125 +219,28 @@ func TestRecoveryDefaultConfigResolvesWhereTheDaemonReads(t *testing.T) { t.Fatalf("validate with no -config exited %d, so it did not read %s: %s", code, configPath, stderr) } if !strings.Contains(stdout, "stored resources validate") { - t.Errorf("validate reported %q, want the verdict on the store seeded from the resolved config", stdout) + t.Errorf("validate reported %q, want the verdict on the database the resolved config names", stdout) } }) } } -// validate exists to answer "would archied start against this file". Each case -// below is a state the daemon fails closed on, or a file it cannot read at all. +// validate exists to answer "would archied start against this database". A +// stored value that both gates refuse -- the write path stops it at Decode +// (workflow.ExecutionSettings.Validate rejects a negative limit) and boot stops +// on it too -- can only get here by bypassing the write path, which is exactly +// the state the operator has no path back from. func TestRecoveryValidateRefusesWhatTheDaemonRefuses(t *testing.T) { - newStore := func(t *testing.T) string { - t.Helper() - db := filepath.Join(t.TempDir(), "archie.db-tasks.sqlite") - openTaskStore(t, db) - return db + configPath, st := recoveryFixture(t) + seedResource(t, st, controlplane.WorkflowExecutionSettingsKind, + `{"max_model_tool_steps":-1,"max_runtime_seconds":60,"max_consecutive_gate_failures":3}`, "hand-edited") + code, _, stderr := runRecoveryCmd(t, "validate", "-config", configPath) + if code == 0 { + t.Fatal("validate accepted a stored resource the write path would refuse") + } + if !strings.Contains(stderr, controlplane.WorkflowExecutionSettingsKind) { + t.Errorf("refusal must name the resource kind; stderr = %q", stderr) } - - t.Run("forward_migrated_schema", func(t *testing.T) { - // A database written by a newer release is the state a rollback has to - // recognise before it hands the file to an older binary. - db := newStore(t) - if err := execRaw(t, db, `PRAGMA user_version = 99`); err != nil { - t.Fatal(err) - } - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db) - if code == 0 { - t.Fatal("validate accepted a forward-migrated database") - } - if !strings.Contains(stderr, "newer than supported version") { - t.Errorf("refusal must name the schema version; stderr = %q", stderr) - } - }) - - t.Run("corrupt_file", func(t *testing.T) { - // A real database header over pages that are not a database. The magic - // is right, so this fails on the content rather than on the format, which - // is the shape a half-written or truncated store has. - db := filepath.Join(t.TempDir(), "archie.db-tasks.sqlite") - corrupt := append([]byte("SQLite format 3\x00"), bytes.Repeat([]byte{0xff}, 4096)...) - if err := os.WriteFile(db, corrupt, 0o600); err != nil { - t.Fatal(err) - } - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db) - if code == 0 { - t.Fatal("validate accepted a corrupt database") - } - if !strings.Contains(stderr, db) { - t.Errorf("refusal must name the file; stderr = %q", stderr) - } - }) - - t.Run("not_a_database", func(t *testing.T) { - // Pointing -db at the wrong file is the common operator mistake, and the - // configured db_path is a different file from the task database the - // State Store owns. - db := filepath.Join(t.TempDir(), "archie.db") - if err := os.WriteFile(db, []byte("db_path, not the task database"), 0o600); err != nil { - t.Fatal(err) - } - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db) - if code == 0 { - t.Fatal("validate accepted a file that is not a database") - } - if !strings.Contains(stderr, db) { - t.Errorf("refusal must name the file; stderr = %q", stderr) - } - }) - - t.Run("stored_resource_that_will_not_validate", func(t *testing.T) { - // A stored value that both gates refuse: the write path stops it at - // Decode (workflow.ExecutionSettings.Validate rejects a negative limit), - // and boot stops on it too -- startWorkflowExecutionSettings decodes the - // same document and exits 1. It can only get here by bypassing the write - // path, which is exactly the state the operator has no path back from. - db := newStore(t) - seedResource(t, openTaskStore(t, db), controlplane.WorkflowExecutionSettingsKind, - `{"max_model_tool_steps":-1,"max_runtime_seconds":60,"max_consecutive_gate_failures":3}`, "hand-edited") - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db) - if code == 0 { - t.Fatal("validate accepted a stored resource the write path would refuse") - } - if !strings.Contains(stderr, controlplane.WorkflowExecutionSettingsKind) { - t.Errorf("refusal must name the resource kind; stderr = %q", stderr) - } - }) - - t.Run("missing_database", func(t *testing.T) { - db := newStore(t) - if err := os.Remove(db); err != nil { - t.Fatal(err) - } - code, _, stderr := runRecoveryCmd(t, "validate", "-db", db) - if code == 0 { - t.Fatal("validate accepted a database that does not exist") - } - if !strings.Contains(stderr, db) { - t.Errorf("refusal must name the file; stderr = %q", stderr) - } - }) - - t.Run("store_without_the_control_plane_table", func(t *testing.T) { - // A store written before the control plane existed holds no stored - // settings. The serving process creates the table on its next start, so - // refusing this file would send an operator to restore a snapshot for a - // database that would have started perfectly well. - dir := t.TempDir() - configPath := writeMinimalConfig(t, dir) - db := filepath.Join(dir, "archie.db-tasks.sqlite") - openTaskStore(t, db) - if err := execRaw(t, db, `DROP TABLE resources`); err != nil { - t.Fatal(err) - } - code, stdout, stderr := runRecoveryCmd(t, "validate", "-db", db, "-config", configPath) - if code != 0 { - t.Fatalf("validate exited %d: %s", code, stderr) - } - if !strings.Contains(stdout, "0 stored resources validate") { - t.Errorf("validate must report that there was nothing stored to check; stdout = %q", stdout) - } - }) } // rollback is the one operation that closes the documented gap: with the State @@ -560,13 +248,11 @@ func TestRecoveryValidateRefusesWhatTheDaemonRefuses(t *testing.T) { // ordinary replace, so no rollback RPC is needed and the rollback itself is // audited as one more revision. func TestRecoveryRollbackReplaysTheRevisionThroughReplace(t *testing.T) { - dir := t.TempDir() - db := filepath.Join(dir, "archie.db-tasks.sqlite") - st := openTaskStore(t, db) + configPath, st := recoveryFixture(t) seedResource(t, st, controlplane.ModelRoleAssignmentsKind, `{"implement":"anthropic/claude"}`, "first") seedResource(t, st, controlplane.ModelRoleAssignmentsKind, `{"implement":"openai/gpt"}`, "second") - code, stdout, stderr := runRecoveryCmd(t, "rollback", "-db", db, "-kind", controlplane.ModelRoleAssignmentsKind) + code, stdout, stderr := runRecoveryCmd(t, "rollback", "-config", configPath, "-kind", controlplane.ModelRoleAssignmentsKind) if code != 0 { t.Fatalf("rollback exited %d: %s", code, stderr) } @@ -598,14 +284,12 @@ func TestRecoveryRollbackReplaysTheRevisionThroughReplace(t *testing.T) { // The revision to restore may be named, which is how an operator reaches past // the most recent change without replaying it first. func TestRecoveryRollbackRestoresANamedRevision(t *testing.T) { - dir := t.TempDir() - db := filepath.Join(dir, "archie.db-tasks.sqlite") - st := openTaskStore(t, db) + configPath, st := recoveryFixture(t) seedResource(t, st, controlplane.ModelRoleAssignmentsKind, `{"implement":"anthropic/claude"}`, "first") seedResource(t, st, controlplane.ModelRoleAssignmentsKind, `{"implement":"openai/gpt"}`, "second") seedResource(t, st, controlplane.ModelRoleAssignmentsKind, `{"implement":"google/gemini"}`, "third") - code, _, stderr := runRecoveryCmd(t, "rollback", "-db", db, "-kind", controlplane.ModelRoleAssignmentsKind, "-revision", "1") + code, _, stderr := runRecoveryCmd(t, "rollback", "-config", configPath, "-kind", controlplane.ModelRoleAssignmentsKind, "-revision", "1") if code != 0 { t.Fatalf("rollback exited %d: %s", code, stderr) } @@ -619,10 +303,9 @@ func TestRecoveryRollbackRestoresANamedRevision(t *testing.T) { } func TestRecoveryRollbackRefusesWhatItCannotReplay(t *testing.T) { - newStore := func(t *testing.T, revisions int) string { + newStore := func(t *testing.T, revisions int) (string, *pgstore.TaskDB) { t.Helper() - db := filepath.Join(t.TempDir(), "archie.db-tasks.sqlite") - st := openTaskStore(t, db) + configPath, st := recoveryFixture(t) for i := range revisions { value := `{"implement":"anthropic/claude"}` if i > 0 { @@ -630,12 +313,12 @@ func TestRecoveryRollbackRefusesWhatItCannotReplay(t *testing.T) { } seedResource(t, st, controlplane.ModelRoleAssignmentsKind, value, "seed") } - return db + return configPath, st } t.Run("unknown_kind", func(t *testing.T) { - db := newStore(t, 2) - code, _, stderr := runRecoveryCmd(t, "rollback", "-db", db, "-kind", "not-a-resource") + configPath, _ := newStore(t, 2) + code, _, stderr := runRecoveryCmd(t, "rollback", "-config", configPath, "-kind", "not-a-resource") if code == 0 { t.Fatal("rollback of an unknown resource kind succeeded") } @@ -645,8 +328,8 @@ func TestRecoveryRollbackRefusesWhatItCannotReplay(t *testing.T) { }) t.Run("no_earlier_revision", func(t *testing.T) { - db := newStore(t, 1) - code, _, stderr := runRecoveryCmd(t, "rollback", "-db", db, "-kind", controlplane.ModelRoleAssignmentsKind) + configPath, _ := newStore(t, 1) + code, _, stderr := runRecoveryCmd(t, "rollback", "-config", configPath, "-kind", controlplane.ModelRoleAssignmentsKind) if code == 0 { t.Fatal("rollback with no earlier revision succeeded") } @@ -656,8 +339,8 @@ func TestRecoveryRollbackRefusesWhatItCannotReplay(t *testing.T) { }) t.Run("current_revision", func(t *testing.T) { - db := newStore(t, 2) - code, _, stderr := runRecoveryCmd(t, "rollback", "-db", db, "-kind", controlplane.ModelRoleAssignmentsKind, "-revision", "2") + configPath, _ := newStore(t, 2) + code, _, stderr := runRecoveryCmd(t, "rollback", "-config", configPath, "-kind", controlplane.ModelRoleAssignmentsKind, "-revision", "2") if code == 0 { t.Fatal("rollback of the current revision succeeded") } @@ -667,14 +350,18 @@ func TestRecoveryRollbackRefusesWhatItCannotReplay(t *testing.T) { }) t.Run("live_state_store", func(t *testing.T) { - db := newStore(t, 2) - holdStoreOwnership(t, db) - code, _, stderr := runRecoveryCmd(t, "rollback", "-db", db, "-kind", controlplane.ModelRoleAssignmentsKind) + configPath, st := newStore(t, 2) + claim, err := postgres.AcquireOwnership(t.Context(), st.Pool, postgres.OwnerStateStore) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = claim.Release(t.Context()) }) + code, _, stderr := runRecoveryCmd(t, "rollback", "-config", configPath, "-kind", controlplane.ModelRoleAssignmentsKind) if code == 0 { t.Fatal("rollback against a live State Store succeeded") } - if !strings.Contains(stderr, "owned by another process") { - t.Errorf("refusal must say the database is owned by another process; stderr = %q", stderr) + if !strings.Contains(stderr, "stop the State Store") { + t.Errorf("refusal must say to stop the State Store; stderr = %q", stderr) } }) } @@ -683,7 +370,7 @@ func TestRecoveryRollbackRefusesWhatItCannotReplay(t *testing.T) { // an operator who mistyped a command watching a server start instead. func TestRecoveryRejectsAnUnknownSubcommand(t *testing.T) { var stdout, stderr bytes.Buffer - code := runRecovery([]string{"backp", "-db", "x"}, &stdout, &stderr) + code := runRecovery([]string{"backp", "-out", "x"}, &stdout, &stderr) if code == 0 { t.Fatal("an unknown subcommand exited 0") } @@ -696,7 +383,9 @@ func TestRecoveryRejectsAnUnknownSubcommand(t *testing.T) { // destination, which only the daemon may bring into existence. func writeConfigWithLogFile(t *testing.T, dir string) (string, string) { t.Helper() - configPath := writeMinimalConfig(t, dir) + url := pgtest.URL(t) + pgstore.PoolAt(t, url) + configPath := writeConfigFor(t, dir, url) logFile := filepath.Join(dir, "logs", "archied.log") f, err := os.OpenFile(configPath, os.O_APPEND|os.O_WRONLY, 0o600) if err != nil { @@ -725,7 +414,7 @@ func writeConfigWithLogFile(t *testing.T, dir string) (string, string) { // registers the same set itself rather than an empty manager: the definitions // are decoded with the vocabulary the served path validates against, which is // what makes the seeded values the ones validate is asked about. -func seedStoreResources(t *testing.T, st *store.Store, configPath string) { +func seedStoreResources(t *testing.T, st *pgstore.TaskDB, configPath string) { t.Helper() doc, err := configuration.New(nil).Resolve(configPath, "") if err != nil { @@ -772,7 +461,7 @@ func storedResourceCount(t *testing.T, stdout string) int { // from the label and the revision it produces: the store deduplicates a // repeated request ID, so a fixed one would make the second write of a series // a silent no-op. -func seedResource(t *testing.T, st *store.Store, kind, value, label string) { +func seedResource(t *testing.T, st *pgstore.TaskDB, kind, value, label string) { t.Helper() current, err := st.Resource(t.Context(), kind) expected := int64(0) @@ -787,23 +476,10 @@ func seedResource(t *testing.T, st *store.Store, kind, value, label string) { if err != nil { t.Fatal(err) } - if _, err := st.PutResource(t.Context(), store.ResourceWrite{ + if _, err := st.PutResource(t.Context(), storecontract.ResourceWrite{ Kind: kind, Value: encoded, Actor: label, Source: "test", RequestID: fmt.Sprintf("%s-%d", label, expected+1), ExpectedVersion: expected, }); err != nil { t.Fatalf("seed resource %s: %v", kind, err) } } - -// execRaw runs one statement against the database file the way an operator -// editing a broken store would, bypassing every check the store applies. -func execRaw(t *testing.T, path, statement string) error { - t.Helper() - db, err := sql.Open("sqlite", path) - if err != nil { - return err - } - defer func() { _ = db.Close() }() - _, err = db.ExecContext(t.Context(), statement) - return err -} diff --git a/cmd/archie-ui/architecture_test.go b/cmd/archie-ui/architecture_test.go index 96ab4fd1e..e8ad16a66 100644 --- a/cmd/archie-ui/architecture_test.go +++ b/cmd/archie-ui/architecture_test.go @@ -28,7 +28,9 @@ type bannedCategory struct { var deletionGate = []bannedCategory{ {"SQL/store implementation", []string{ "modernc.org/sqlite", - modulePath + "internal/store", + "github.com/jackc/pgx", + modulePath + "internal/infrastructure/postgres", + modulePath + "internal/infrastructure/legacyread", }}, {"daemon runtime", []string{ modulePath + "internal/daemon", diff --git a/cmd/archie-ui/main_test.go b/cmd/archie-ui/main_test.go index 60a902064..aba5c49ed 100644 --- a/cmd/archie-ui/main_test.go +++ b/cmd/archie-ui/main_test.go @@ -36,11 +36,11 @@ import ( "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/health" "github.com/samcharles93/archie-core/internal/domain/messaging" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/taskactions" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" "github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskstate" "github.com/samcharles93/archie-core/internal/webui" ) @@ -484,12 +484,9 @@ func streamChat(t *testing.T, d dashboard, prompt string) []chatFrame { // that forgets to publish a field, which is the failure mode this covers: // chat.show_tool_calls, the operator name and the channel flag all reach the // extracted process through this projection and nowhere else (GitHub #821). -func seedStore(t *testing.T, dir string) *store.Store { +func seedStore(t *testing.T, dir string) *pgstore.TaskDB { t.Helper() - st, err := store.Open(t.Context(), filepath.Join(dir, "tasks.sqlite")) - if err != nil { - t.Fatalf("open store: %v", err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) if _, err := st.EnqueueIssue(t.Context(), "acme", "widget", 7, "smoke task", "body", "", ""); err != nil { @@ -528,13 +525,13 @@ func daemonConfig(showToolCalls bool) config.Config { // writes the result to the store the UI process reads it back from. The UI // process holds no configuration, so this is the only path by which a setting // reaches its pages. -func publishConfig(t *testing.T, st *store.Store, cfg config.Config) { +func publishConfig(t *testing.T, st *pgstore.TaskDB, cfg config.Config) { t.Helper() document, err := json.Marshal(webui.BuildConfigView(webui.ConfigViewInput{Config: cfg})) if err != nil { t.Fatalf("render the configuration projection: %v", err) } - if err := st.PutConfigSnapshot(t.Context(), store.ConfigSnapshot{ + if err := st.PutConfigSnapshot(t.Context(), storecontract.ConfigSnapshot{ Schema: webui.ConfigViewSchema, Document: document, }); err != nil { t.Fatalf("publish config snapshot: %v", err) @@ -555,10 +552,7 @@ func publishConfig(t *testing.T, st *store.Store, cfg config.Config) { // that test's page underneath it. func TestUIProcessLinksMultiIdentityTaskRowsToTheirOwningForge(t *testing.T) { dir := t.TempDir() - st, err := store.Open(t.Context(), filepath.Join(dir, "tasks.sqlite")) - if err != nil { - t.Fatalf("open store: %v", err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) // One task carrying its identity (name resolves it), one without an @@ -595,14 +589,14 @@ func TestUIProcessLinksMultiIdentityTaskRowsToTheirOwningForge(t *testing.T) { if err != nil { t.Fatal(err) } - if err := st.PutConfigSnapshot(t.Context(), store.ConfigSnapshot{ + if err := st.PutConfigSnapshot(t.Context(), storecontract.ConfigSnapshot{ Schema: webui.ConfigViewSchema, Document: published, }); err != nil { t.Fatalf("publish config snapshot: %v", err) } stateTarget, stopState := serveGRPC(t, func(r grpc.ServiceRegistrar) { - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) staterpc.RegisterServer(r, staterpc.Deps{ Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, Log: slog.New(slog.DiscardHandler), @@ -659,7 +653,7 @@ func TestUIProcessServesTheDashboardAgainstLiveDependencies(t *testing.T) { gateway := &fakeGateway{} stateTarget, stopState := serveGRPC(t, func(r grpc.ServiceRegistrar) { - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) staterpc.RegisterServer(r, staterpc.Deps{ Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, Log: slog.New(slog.DiscardHandler), diff --git a/cmd/archie-ui/pgtest_test.go b/cmd/archie-ui/pgtest_test.go new file mode 100644 index 000000000..af786180f --- /dev/null +++ b/cmd/archie-ui/pgtest_test.go @@ -0,0 +1,10 @@ +package main + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/go.mod b/go.mod index 67a138e0d..9ae959d2c 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/ProtonMail/go-crypto v1.4.1 // indirect github.com/antithesishq/antithesis-sdk-go v0.8.0 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 // indirect - github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudflare/circl v1.6.5 // indirect @@ -21,30 +20,23 @@ require ( github.com/containerd/platforms v0.2.1 // indirect github.com/cpuguy83/dockercfg v0.3.2 // indirect github.com/davidmz/go-pageant v1.0.2 // indirect - github.com/disintegration/imaging v1.6.2 // indirect github.com/distribution/reference v0.6.0 // indirect github.com/docker/go-connections v0.8.1 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/domodwyer/mailyak/v3 v3.6.2 // indirect github.com/dustin/go-humanize v1.1.0 // indirect github.com/ebitengine/purego v0.10.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect - github.com/fatih/color v1.19.0 // indirect github.com/felixge/httpsnoop v1.1.0 // indirect - github.com/fsnotify/fsnotify v1.10.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.15 // indirect - github.com/ganigeorgiev/fexpr v0.6.0 // indirect github.com/go-fed/httpsig v1.1.0 // indirect github.com/go-git/gcfg/v2 v2.0.2 // indirect github.com/go-json-experiment/json v0.0.0-20260623181947-01eb4420fa68 // indirect github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect - github.com/golang-jwt/jwt/v5 v5.3.1 // indirect github.com/google/go-querystring v1.2.0 // indirect github.com/google/go-tpm v0.9.8 // indirect + github.com/google/pprof v0.0.0-20260902005441-ca85771921e4 // indirect github.com/hashicorp/go-version v1.9.0 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect @@ -53,7 +45,6 @@ require ( github.com/klauspost/cpuid/v2 v2.4.0 // indirect github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e // indirect github.com/magiconair/properties v1.8.10 // indirect - github.com/mattn/go-colorable v0.1.15 // indirect github.com/mattn/go-isatty v0.0.24 // indirect github.com/mfridman/interpolate v0.0.2 // indirect github.com/minio/highwayhash v1.0.4 // indirect @@ -72,16 +63,12 @@ require ( github.com/opencontainers/image-spec v1.1.1 // indirect github.com/pjbgf/sha1cd v0.6.0 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect - github.com/pocketbase/ozzo-validation/v4 v4.3.0 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/sergi/go-diff v1.4.0 // indirect github.com/sethvargo/go-retry v0.4.0 // indirect github.com/shirou/gopsutil/v4 v4.26.6 // indirect github.com/sirupsen/logrus v1.9.4 // indirect - github.com/spf13/cast v1.10.0 // indirect - github.com/spf13/cobra v1.10.2 // indirect - github.com/spf13/pflag v1.0.10 // indirect github.com/stretchr/testify v1.12.1 // indirect github.com/tklauser/go-sysconf v0.4.0 // indirect github.com/tklauser/numcpus v0.12.0 // indirect @@ -95,7 +82,6 @@ require ( go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/crypto v0.57.0 // indirect golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba // indirect - golang.org/x/image v0.46.0 // indirect golang.org/x/sync v0.23.0 // indirect golang.org/x/sys v0.48.0 // indirect golang.org/x/text v0.42.0 // indirect @@ -123,8 +109,6 @@ require ( github.com/moby/moby/client v0.6.0 github.com/nats-io/nats-server/v2 v2.15.0 github.com/nats-io/nats.go v1.54.0 - github.com/pocketbase/dbx v1.12.0 - github.com/pocketbase/pocketbase v0.40.4 github.com/pressly/goose/v3 v3.28.0 github.com/samcharles93/ai-sdk v0.1.39 github.com/testcontainers/testcontainers-go v0.44.0 diff --git a/go.sum b/go.sum index 1a7659729..2eff6127e 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,6 @@ code.gitea.io/sdk/gitea v0.25.1 h1:yywxWwoV+SdjHtbC6unBiXojWdZOtoHuGhEazEXeWuE= code.gitea.io/sdk/gitea v0.25.1/go.mod h1:uDFWYBU8dgZsgOHwe6C/6olxvf8FHguNB3wW1i83fgg= dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= -filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= -filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= github.com/42wim/httpsig v1.2.4 h1:mI5bH0nm4xn7K18fo1K3okNDRq8CCJ0KbBYWyA6r8lU= github.com/42wim/httpsig v1.2.4/go.mod h1:yKsYfSyTBEohkPik224QPFylmzEBtda/kjyIAJjh3ps= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= @@ -28,9 +26,6 @@ github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYW github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= -github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= -github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -49,41 +44,26 @@ github.com/coreos/go-oidc/v3 v3.21.0 h1:wZo4Q9Pum8dYEj0eMUPrqR+kvuGkeUplbLpNCkBq github.com/coreos/go-oidc/v3 v3.21.0/go.mod h1:DYCf24+ncYi+XkIH97GY1+dqoRlbaSI26KVTCI9SrY4= github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= -github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= -github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= -github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUExb29/M= github.com/docker/go-connections v0.8.1/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/domodwyer/mailyak/v3 v3.6.2 h1:x3tGMsyFhTCaxp6ycgR0FE/bu5QiNp+hetUuCOBXMn8= -github.com/domodwyer/mailyak/v3 v3.6.2/go.mod h1:lOm/u9CyCVWHeaAmHIdF4RiKVxKUT/H5XX10lIKAL6c= github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg= github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI= github.com/ebitengine/purego v0.10.1 h1:dewVBCBT2GaMu1SrNTYxQhgQBethzfhiwvZiLGP/qyY= github.com/ebitengine/purego v0.10.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= -github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= -github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= -github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho= -github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo= -github.com/gabriel-vasile/mimetype v1.4.15 h1:05iP/CYtZ/w455R/KZM6rZ5ieAdh99UPtd+d3YzLmaI= -github.com/gabriel-vasile/mimetype v1.4.15/go.mod h1:azpTcoLcDZRNgFou5j+APrqQx9HqVPWa6ijYQIIVswQ= -github.com/ganigeorgiev/fexpr v0.6.0 h1:Fza3O/QMBKEudUvxV862qe6GjxM60GJjjKytdp+VQus= -github.com/ganigeorgiev/fexpr v0.6.0/go.mod h1:RyGiGqmeXhEQ6+mlGdnUleLHgtzzu/VGO2WtJkF5drE= github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= @@ -108,14 +88,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= -github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw= -github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk= github.com/go-telegram/bot v1.27.0 h1:PG9yBDzM8O26oUerE9SZwWlHon4RpH8WcNslZ7CEZmE= github.com/go-telegram/bot v1.27.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM= -github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= -github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -135,8 +109,6 @@ github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaX github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= @@ -164,8 +136,6 @@ github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e h1:Q6MvJtQK/iRcRt github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY= -github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI= @@ -213,12 +183,6 @@ github.com/pjbgf/sha1cd v0.6.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pocketbase/dbx v1.12.0 h1:/oLErM+A0b4xI0PWTGPqSDVjzix48PqI/bng2l0PzoA= -github.com/pocketbase/dbx v1.12.0/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs= -github.com/pocketbase/ozzo-validation/v4 v4.3.0 h1:uKBDVma7bZqgR2a6AwE+k9hkuDFfiZMpBHQdZ1z3iQs= -github.com/pocketbase/ozzo-validation/v4 v4.3.0/go.mod h1:6XNjSTw/Jb2F8LOkKO3oyzIWExbrGiYoS4uVxVwz90g= -github.com/pocketbase/pocketbase v0.40.4 h1:0SvSUreR3NhUMCs9LchE59oEG53efZ3cKiMGyAGBN9U= -github.com/pocketbase/pocketbase v0.40.4/go.mod h1:2mU+80FLiY1fb13WZRg8Xx/lKg4nTjgKVJMigyRH6k0= github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/pressly/goose/v3 v3.28.0 h1:D2M+iL31GmpZxSHOhX8mqyqAT3CXnokUmm0eKoSP+Vc= @@ -227,7 +191,6 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samcharles93/ai-sdk v0.1.39 h1:gbNPYeA27MifReCruBiqMgb4fFSjCDi1Zv57a9bo0Vo= github.com/samcharles93/ai-sdk v0.1.39/go.mod h1:u4zrQ9/Q58L5mNEut4bNQ1ks+RCKq71LN5EDz2N/0Zk= github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw= @@ -238,13 +201,6 @@ github.com/shirou/gopsutil/v4 v4.26.6 h1:Mzr/npDtQC/xpeEuQKHZt8Zo9CmPvhTj8nkR8w5 github.com/shirou/gopsutil/v4 v4.26.6/go.mod h1:LZ6ewCSkBqUpvSOf+LsTGnRinC6iaNUNMGBtDkJBaLQ= github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= -github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= -github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= -github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= -github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= -github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= -github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= @@ -287,7 +243,6 @@ go.opentelemetry.io/otel/trace v1.46.0 h1:OULy7ccdJnZtJ0UDYFOIGaCmiWzJ8Vi2G/Rsu6 go.opentelemetry.io/otel/trace v1.46.0/go.mod h1:J7GAXweO77XSFkB/rmAqk9D6ihszhFjLU+d9WuUxDLI= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -297,13 +252,9 @@ golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba h1:Ck8QetSgk912qxWLMCKxd0in+aiyBQyDSMae6e/xmpU= golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba/go.mod h1:50RgIsmK7OwqzTTeqcSXQW8SswW0o8fRcDxmqGluJ8E= -golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.46.0 h1:b1+oYj0Jbp6K5MDT4i4/eZpYlk3V8SJhhDKh6LBHAyQ= -golang.org/x/image v0.46.0/go.mod h1:3B3W05VGVQyuXucLINLjXKrqISASfi4Xj+iCVkLMwew= golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues= golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= @@ -325,7 +276,6 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE= golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= @@ -336,7 +286,6 @@ golang.org/x/tools v0.50.0 h1:c2ifzfcuY7L90lZ2aKd8S4K2NpASF08SZx9ZuJkHmSU= golang.org/x/tools v0.50.0/go.mod h1:7ulVMw3831Mwi5EZD6RomGyffr4VFjuNYXf2BbCEAV0= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto/googleapis/api v0.0.0-20260921155816-b14227669459 h1:GS9OIt/j7c8bvBjYNgnKQysVfmV7e4jM0H8ZK95G4t8= google.golang.org/genproto/googleapis/api v0.0.0-20260921155816-b14227669459/go.mod h1:PX5/4vemwVoXtwEcRDWwcR1/r0qrosfx3qoVADMwnVE= google.golang.org/genproto/googleapis/rpc v0.0.0-20260921155816-b14227669459 h1:b0xCahf3FK2m2Cv0p4vTozGPWncCvLfwV86UNg8xWU8= diff --git a/internal/app/agentworker/pgtest_test.go b/internal/app/agentworker/pgtest_test.go new file mode 100644 index 000000000..4481d0ab0 --- /dev/null +++ b/internal/app/agentworker/pgtest_test.go @@ -0,0 +1,10 @@ +package agentworker + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/app/agentworker/task_execution_test.go b/internal/app/agentworker/task_execution_test.go index 208e6e043..341151338 100644 --- a/internal/app/agentworker/task_execution_test.go +++ b/internal/app/agentworker/task_execution_test.go @@ -30,11 +30,10 @@ import ( "github.com/samcharles93/archie-core/internal/forge" "github.com/samcharles93/archie-core/internal/forgerpc" agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats" - "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/infrastructure/workflowsteps" "github.com/samcharles93/archie-core/internal/installtype" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskrun" "github.com/samcharles93/archie-core/internal/worktree" "github.com/samcharles93/archie-core/internal/worktreerpc" @@ -370,14 +369,14 @@ func connectTaskRPC(t *testing.T, url string) *natsio.Conn { // on gRPC for its store calls (docs/prds/state-store-contract.md §12 step 4), // so an agentworker test that drives executeTaskRequest needs a real State // Store server rather than the deleted NATS storerpc path. -func startStateStoreGRPC(t *testing.T, local *store.Store) string { +func startStateStoreGRPC(t *testing.T, local *pgstore.TaskDB) string { t.Helper() listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) } server := grpc.NewServer() - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) staterpc.RegisterServer(server, staterpc.Deps{ Tasks: local, Captures: eda, Mappings: eda, Bindings: eda, BindingDispatcher: eda, BindingTaskCreator: local, @@ -393,7 +392,7 @@ func TestRunTaskExecutesBootstrapWorkflowEndToEnd(t *testing.T) { } ctx := t.Context() host := newLocalRemote(t, "acme", "widget") - st := store.OpenTest(t) + st := pgstore.Open(t) if _, err := st.EnqueueIssue(ctx, "acme", "widget", 1, "feat: bootstrap test", "", "bootstrap", ""); err != nil { t.Fatalf("enqueue: %v", err) } @@ -594,7 +593,7 @@ func TestExecuteTaskRequestUsesInfrastructureRPCDependencies(t *testing.T) { } ctx := t.Context() host := newLocalRemote(t, "acme", "rpc-widget") - st := store.OpenTest(t) + st := pgstore.Open(t) if _, err := st.EnqueueIssue(ctx, "acme", "rpc-widget", 2, "feat: RPC bootstrap test", "", "bootstrap", ""); err != nil { t.Fatal(err) } @@ -686,7 +685,7 @@ func TestExecuteTaskRequestForwardsWorkflowEventsOverNATS(t *testing.T) { } ctx := t.Context() host := newLocalRemote(t, "acme", "events-widget") - st := store.OpenTest(t) + st := pgstore.Open(t) if _, err := st.EnqueueIssue(ctx, "acme", "events-widget", 3, "feat: events bootstrap test", "", "bootstrap", ""); err != nil { t.Fatal(err) } diff --git a/internal/app/archied/binding_cipher.go b/internal/app/archied/binding_cipher.go index bbec81d1a..968cfc2fa 100644 --- a/internal/app/archied/binding_cipher.go +++ b/internal/app/archied/binding_cipher.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/samcharles93/archie-core/internal/config" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher" "github.com/samcharles93/archie-core/internal/secret" ) @@ -13,7 +13,7 @@ import ( // config through the secret registry and returns the EDA store's cipher. An unset // encryption_key returns a nil cipher, keeping the legacy plaintext path (the // store's default). See docs/prds/binding-secret-encryption.md. -func bindingCipherFromConfig(cfg config.Config, secrets *secret.Registry) (edastore.BindingCipher, error) { +func bindingCipherFromConfig(cfg config.Config, secrets *secret.Registry) (bindingcipher.BindingCipher, error) { if cfg.Bindings.EncryptionKey == (secret.SecretRef{}) { return nil, nil } @@ -36,5 +36,5 @@ func bindingCipherFromConfig(cfg config.Config, secrets *secret.Registry) (edast previous = append(previous, v) } } - return edastore.NewBindingCipher(active, previous) + return bindingcipher.NewBindingCipher(active, previous) } diff --git a/internal/app/archied/chat_store_composition_test.go b/internal/app/archied/chat_store_composition_test.go index b71be6779..b4e96a929 100644 --- a/internal/app/archied/chat_store_composition_test.go +++ b/internal/app/archied/chat_store_composition_test.go @@ -5,10 +5,11 @@ import ( "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/gateway" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" - "github.com/samcharles93/archie-core/internal/store" ) func TestRemoteChatCompositionPreservesChannelTurnLedger(t *testing.T) { @@ -17,10 +18,7 @@ func TestRemoteChatCompositionPreservesChannelTurnLedger(t *testing.T) { DatabaseURL: pgtest.URL(t), Services: config.Services{config.ServiceNameGateway: {Target: "127.0.0.1:1"}}, } - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state-store.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) b := &boot{cfg: cfg, log: slog.Default(), cfgHolder: config.NewHolder(cfg), stateStore: st, personas: gateway.NewPersonaRegistry(gateway.DefaultPersonas())} t.Cleanup(b.cleanup) diff --git a/internal/app/archied/config_snapshot_channels_test.go b/internal/app/archied/config_snapshot_channels_test.go index 1fc74f47d..cc85dd889 100644 --- a/internal/app/archied/config_snapshot_channels_test.go +++ b/internal/app/archied/config_snapshot_channels_test.go @@ -3,11 +3,11 @@ package archied import ( "encoding/json" "log/slog" - "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -49,10 +49,7 @@ func TestPublishedProjectionAgreesWithFrontEndsOnConfiguredChannels(t *testing.T for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) b := &boot{ diff --git a/internal/app/archied/config_snapshot_test.go b/internal/app/archied/config_snapshot_test.go index 9e7f2659a..c2f9546f5 100644 --- a/internal/app/archied/config_snapshot_test.go +++ b/internal/app/archied/config_snapshot_test.go @@ -4,12 +4,12 @@ import ( "context" "encoding/json" "log/slog" - "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/infrastructure/configuration" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -19,10 +19,7 @@ import ( // from its own state rather than from a webui.Server it never serves // (archie-core-ml30). func TestPublishConfigSnapshotRendersTheDaemonsConfiguration(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) cfg := config.Config{ @@ -83,10 +80,7 @@ func TestPublishConfigSnapshotRendersTheDaemonsConfiguration(t *testing.T) { } func TestPublishedSnapshotCarriesPerIdentityForges(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) b := &boot{ @@ -133,10 +127,7 @@ func TestPublishedSnapshotCarriesPerIdentityForges(t *testing.T) { // TestPublishConfigSnapshotWithoutConfiguration: called before the daemon has // a configuration Holder, publishing is a no-op rather than a panic. func TestPublishConfigSnapshotWithoutConfiguration(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) b := &boot{log: slog.New(slog.DiscardHandler), stateStore: st} diff --git a/internal/app/archied/control_plane_restart_test.go b/internal/app/archied/control_plane_restart_test.go index f94867025..1d8ff3b66 100644 --- a/internal/app/archied/control_plane_restart_test.go +++ b/internal/app/archied/control_plane_restart_test.go @@ -23,8 +23,8 @@ import ( "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow" "github.com/samcharles93/archie-core/internal/infrastructure/configuration" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -68,7 +68,7 @@ type controlPlaneRestartFixture struct { // reading apply status back. func newControlPlaneRestartFixture(t *testing.T) *controlPlaneRestartFixture { t.Helper() - local := store.OpenTest(t) + local := pgstore.Open(t) t.Cleanup(func() { _ = local.Close() }) steps, err := stepVocabulary() diff --git a/internal/app/archied/control_plane_watch_outage_test.go b/internal/app/archied/control_plane_watch_outage_test.go index 68ab01315..2e6998a8c 100644 --- a/internal/app/archied/control_plane_watch_outage_test.go +++ b/internal/app/archied/control_plane_watch_outage_test.go @@ -15,8 +15,9 @@ import ( "github.com/samcharles93/archie-core/internal/app/controlplane" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" + "github.com/samcharles93/archie-core/internal/domain/storecontract" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps" - "github.com/samcharles93/archie-core/internal/store" ) // outageStore is the State Store's resource half with a switch that makes every @@ -32,7 +33,7 @@ import ( // lasted longer than the minimum retry interval, which is a failed attempt // whichever way the store failed it. type outageStore struct { - *store.Store + *pgstore.TaskDB mu sync.Mutex failing bool @@ -46,15 +47,15 @@ func (s *outageStore) down(stall time.Duration) { s.failing, s.stall = true, stall } -func (s *outageStore) Resource(ctx context.Context, kind string) (store.Resource, error) { +func (s *outageStore) Resource(ctx context.Context, kind string) (storecontract.Resource, error) { s.mu.Lock() failing, stall := s.failing, s.stall s.mu.Unlock() if failing { time.Sleep(stall) - return store.Resource{}, errors.New("state store unreachable") + return storecontract.Resource{}, errors.New("state store unreachable") } - return s.Store.Resource(ctx, kind) + return s.TaskDB.Resource(ctx, kind) } // TestWatchRetryGrowsWhileTheStateStoreIsDown is the outage this reconnect @@ -113,7 +114,7 @@ func TestWatchRetryGrowsWhileTheStateStoreIsDown(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - database := &outageStore{Store: store.OpenTest(t)} + database := &outageStore{TaskDB: pgstore.Open(t)} defer database.Close() steps, err := workflowsteps.NewManager() if err != nil { diff --git a/internal/app/archied/cutover_test.go b/internal/app/archied/cutover_test.go index 8ecab7ddf..a8ea97ba5 100644 --- a/internal/app/archied/cutover_test.go +++ b/internal/app/archied/cutover_test.go @@ -7,13 +7,11 @@ import ( "path/filepath" "strings" "testing" - "time" "github.com/jackc/pgx/v5/pgxpool" "github.com/samcharles93/archie-core/internal/config" - "github.com/samcharles93/archie-core/internal/domain/messaging" - "github.com/samcharles93/archie-core/internal/gateway" + "github.com/samcharles93/archie-core/internal/infrastructure/legacyimport/legacyfixture" "github.com/samcharles93/archie-core/internal/infrastructure/postgres" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" ) @@ -23,18 +21,7 @@ import ( // see legacy data. func seedLegacyConversation(t *testing.T, dbPath string) { t.Helper() - legacy, err := gateway.OpenSQLiteSessionStore(conversationDBPath(dbPath)) - if err != nil { - t.Fatalf("open legacy conversation store: %v", err) - } - defer legacy.Close() - if err := legacy.Save(t.Context(), messaging.SessionContext{ - SessionID: "legacy", - Source: messaging.SessionSource{Platform: "telegram", BotUser: "archie"}, - CreatedAt: time.Now(), - }); err != nil { - t.Fatalf("seed legacy session: %v", err) - } + legacyfixture.Exec(t, conversationDBPath(dbPath), legacyfixture.GatewayDDL) } func testPool(t *testing.T, url string) *pgxpool.Pool { diff --git a/internal/app/archied/main.go b/internal/app/archied/main.go index 9a54b5d25..045dcffbe 100644 --- a/internal/app/archied/main.go +++ b/internal/app/archied/main.go @@ -43,7 +43,6 @@ import ( "github.com/samcharles93/archie-core/internal/plugin" "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/taskstate" "github.com/samcharles93/archie-core/internal/tools" "github.com/samcharles93/archie-core/internal/tools/mcp" @@ -284,10 +283,6 @@ func resolveForge(cfg config.Forge, secrets *secret.Registry, log *slog.Logger) return client, token } -func openProductionTaskStore(ctx context.Context, path string, opts ...store.OpenOption) (storecontract.TaskStore, error) { - return store.Open(ctx, path, opts...) -} - func taskDBPath(configuredPath string) string { return configuredPath + "-tasks.sqlite" } diff --git a/internal/app/archied/main_test.go b/internal/app/archied/main_test.go index bdd268404..bc99a28a7 100644 --- a/internal/app/archied/main_test.go +++ b/internal/app/archied/main_test.go @@ -7,13 +7,14 @@ import ( "fmt" "log/slog" "os" - "path/filepath" "slices" "strings" "sync" "testing" "time" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/nats-io/nats-server/v2/server" natssrv "github.com/nats-io/nats-server/v2/test" natsio "github.com/nats-io/nats.go" @@ -30,7 +31,6 @@ import ( "github.com/samcharles93/archie-core/internal/gateway" "github.com/samcharles93/archie-core/internal/logging" "github.com/samcharles93/archie-core/internal/secret" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/tools" "github.com/samcharles93/archie-core/internal/worktree" "github.com/samcharles93/archie-core/internal/worktreerpc" @@ -528,10 +528,7 @@ func TestManualRequeueTaskUsesPersistedStatus(t *testing.T) { tests := []string{workflow.StatusParked, workflow.StatusWaitingHuman} for index, status := range tests { t.Run(status, func(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) if _, err := st.EnqueueIssue(t.Context(), "acme", "widget", index+1, "task", "", "", ""); err != nil { t.Fatal(err) @@ -555,10 +552,7 @@ func TestManualRequeueTaskUsesPersistedStatus(t *testing.T) { } func TestManualRequeueTaskRejectsOtherStatuses(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) if _, err := st.EnqueueIssue(t.Context(), "acme", "widget", 1, "task", "", "", ""); err != nil { t.Fatal(err) @@ -573,10 +567,7 @@ func TestManualRequeueTaskRejectsOtherStatuses(t *testing.T) { } func TestChatTaskListerAdapterReadsSQLiteIdentity(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) want, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "identity task", "", "tdd", "reviewer") if err != nil { @@ -827,10 +818,7 @@ func TestChatTaskLogReaderAdapterRoundTrip(t *testing.T) { func TestChatTaskCommandsEndToEnd(t *testing.T) { ctx := context.Background() - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { if err := st.Close(); err != nil { t.Errorf("close store: %v", err) diff --git a/internal/app/archied/readiness_test.go b/internal/app/archied/readiness_test.go index f4596f3e8..b7c1644a1 100644 --- a/internal/app/archied/readiness_test.go +++ b/internal/app/archied/readiness_test.go @@ -5,9 +5,10 @@ import ( "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/gateway" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -49,10 +50,7 @@ func TestPingChat_ReportsUnwiredChat(t *testing.T) { // on the store, config, disk, model and gateway in the running daemon -- only // that every subsystem the epic names is actually wired. func TestSetupReadinessProbes_WiresEverySubsystem(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "test.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) cfg := config.Config{ diff --git a/internal/app/archied/routing_bindings_test.go b/internal/app/archied/routing_bindings_test.go index 33b478076..080cfc6a5 100644 --- a/internal/app/archied/routing_bindings_test.go +++ b/internal/app/archied/routing_bindings_test.go @@ -2,13 +2,13 @@ package archied import ( "log/slog" - "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/workflow" "github.com/samcharles93/archie-core/internal/domain/workintake" - "github.com/samcharles93/archie-core/internal/store" ) // TestBuildDaemonCarriesWorkflowRoutingBindings pins the composition hop in the @@ -21,10 +21,7 @@ import ( // the "tested in isolation, never verified wired" shape this repo has been bitten // by before. func TestBuildDaemonCarriesWorkflowRoutingBindings(t *testing.T) { - storeA, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "store-a.db")) - if err != nil { - t.Fatal(err) - } + storeA := pgstore.Open(t) t.Cleanup(func() { _ = storeA.Close() }) storeB := openSecondStore(t) diff --git a/internal/app/archied/sd_notify_test.go b/internal/app/archied/sd_notify_test.go index 7a3f3177e..1d44ea13e 100644 --- a/internal/app/archied/sd_notify_test.go +++ b/internal/app/archied/sd_notify_test.go @@ -14,9 +14,10 @@ import ( "testing" "time" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/daemon" - "github.com/samcharles93/archie-core/internal/store" ) // notifyRecorder captures every record at every level. The other recording @@ -126,10 +127,7 @@ func newNotifyTestBoot(t *testing.T, cadence time.Duration) (*boot, *daemon.Daem t.Helper() cfg := config.Config{PollInterval: config.Duration(cadence)} holder := config.NewHolder(cfg) - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatalf("open task store: %v", err) - } + st := pgstore.Open(t) log := slog.New(slog.DiscardHandler) d := &daemon.Daemon{Cfg: holder, Store: st, Log: log} return &boot{cfg: cfg, cfgHolder: holder, d: d, log: log}, d diff --git a/internal/app/archied/state_store_consumers_test.go b/internal/app/archied/state_store_consumers_test.go index a0cbb6c3e..a78e15d7c 100644 --- a/internal/app/archied/state_store_consumers_test.go +++ b/internal/app/archied/state_store_consumers_test.go @@ -2,47 +2,36 @@ package archied import ( "log/slog" - "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres" + "github.com/samcharles93/archie-core/internal/config" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" taskactionstore "github.com/samcharles93/archie-core/internal/infrastructure/taskactions" - "github.com/samcharles93/archie-core/internal/store" ) -// openSecondStore opens a second, independent *store.Store on a fresh temp +// openSecondStore opens a second, independent *pgstore.TaskDB on a fresh temp // path so a boot consumer test can prove the composition routes through // b.stateStore rather than b.st: the two differ by identity, so an assertion // that a consumer field holds storeB (not storeA) can only pass if the wiring // reads b.stateStore. // stateStoreAdapter stands in for the real adapter (*staterpc.Client), which // fronts both halves of the contract over one connection: the task store and -// the event-capture store. A plain *store.Store no longer satisfies the +// the event-capture store. A plain *pgstore.TaskDB no longer satisfies the // event-capture surfaces, so a test that asserts "everything routes through // the adapter" needs something that implements them, exactly as the client // does in production. -// edaSide aliases the event-capture store so it can be embedded beside -// *store.Store: both are named Store, and Go allows only one embedded field -// per name. -type edaSide = edastore.Store - type stateStoreAdapter struct { - *store.Store - *edaSide + *pgstore.TaskDB + *postgres.EDA } -// Close disambiguates the two embedded stores, which both have one. -func (a *stateStoreAdapter) Close() error { return a.Store.Close() } - func openSecondStore(t *testing.T) *stateStoreAdapter { t.Helper() - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state-store.db")) - if err != nil { - t.Fatalf("open second store: %v", err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) - return &stateStoreAdapter{Store: st, edaSide: edastore.OpenTest(t)} + return &stateStoreAdapter{TaskDB: st, EDA: pgstore.EDA(t, nil)} } // TestBuildDaemonRoutesTaskStoreThroughStateStore proves the daemon's task @@ -52,10 +41,7 @@ func openSecondStore(t *testing.T) *stateStoreAdapter { // (docs/prds/state-store-contract.md §12 step 6): the daemon's Store field and // its mapping/binding dispatch surfaces all come from the adapter. func TestBuildDaemonRoutesTaskStoreThroughStateStore(t *testing.T) { - storeA, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "store-a.db")) - if err != nil { - t.Fatal(err) - } + storeA := pgstore.Open(t) t.Cleanup(func() { _ = storeA.Close() }) storeB := openSecondStore(t) diff --git a/internal/app/archied/state_store_eda.go b/internal/app/archied/state_store_eda.go index c35c51f4a..785d6c4e5 100644 --- a/internal/app/archied/state_store_eda.go +++ b/internal/app/archied/state_store_eda.go @@ -2,7 +2,7 @@ package archied import ( "github.com/samcharles93/archie-core/internal/domain/storecontract" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher" "github.com/samcharles93/archie-core/internal/infrastructure/postgres" ) @@ -19,6 +19,6 @@ type eventCaptureStore interface { // openEDAStore serves the event-capture store from the State Store's Postgres // pool, sealing binding secrets with cipher. -func (b *boot) openEDAStore(cipher edastore.BindingCipher) { +func (b *boot) openEDAStore(cipher bindingcipher.BindingCipher) { b.eda = postgres.NewEDA(b.pg, cipher) } diff --git a/internal/app/archied/state_store_recovery.go b/internal/app/archied/state_store_recovery.go index 61864fa7e..a1040505c 100644 --- a/internal/app/archied/state_store_recovery.go +++ b/internal/app/archied/state_store_recovery.go @@ -5,12 +5,12 @@ // State Store is up -- is unavailable in exactly the case that needs it // (docs/architecture/safe-change-and-recovery.md). // -// With -db an operation works on the legacy SQLite task file; without it, on -// the PostgreSQL database database_url names (state_store_recovery_postgres.go). -// The ones that write refuse while a serving process owns the store. Backup is -// the exception and deliberately so: the update installer cannot stop the -// process that runs it, so the snapshot that makes a failed update recoverable -// is taken against a serving store through a consistent copy. +// Every operation but import works on the PostgreSQL database database_url +// names (state_store_recovery_postgres.go). The ones that write refuse while a +// serving process owns the store. Backup is the exception and deliberately so: +// the update installer cannot stop the process that runs it, so the snapshot +// that makes a failed update recoverable is taken against a serving store +// through a consistent copy. // // The control-plane server both validate and rollback read through is built by // openStateStoreControlPlane -- the same root helper the served path uses -- so @@ -28,8 +28,8 @@ import ( "github.com/samcharles93/archie-core/internal/app/controlplane" "github.com/samcharles93/archie-core/internal/config" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/infrastructure/configuration" - "github.com/samcharles93/archie-core/internal/store" ) // The audit identity every offline rollback records. A rollback is one more @@ -55,9 +55,6 @@ const ( type StateStoreRecoveryOptions struct { // Operation is one of backup, restore, validate, rollback. Operation string - // DB is the task database file the State Store owns: the configured - // db_path with "-tasks.sqlite" appended, not the configured path itself. - DB string // Out is the snapshot backup writes. Out string // From is the snapshot restore reads. @@ -88,90 +85,7 @@ func RunStateStoreRecovery(ctx context.Context, options StateStoreRecoveryOption if options.Operation == RecoveryImport { return importLegacy(ctx, options) } - // -db names the legacy SQLite task file; without it the command works on - // the PostgreSQL database the configuration names. - if options.DB == "" { - return runPostgresRecovery(ctx, options) - } - switch options.Operation { - case RecoveryBackup: - if options.Out == "" { - return "", errors.New("backup requires -out") - } - return summarise(store.Backup(ctx, options.DB, options.Out), "backed up %s to %s", options.DB, options.Out) - case RecoveryRestore: - if options.From == "" { - return "", errors.New("restore requires -from") - } - return summarise(store.Restore(ctx, options.DB, options.From), - "restored %s from %s; start the State Store again", options.DB, options.From) - case RecoveryValidate: - return validateStore(ctx, options) - case RecoveryRollback: - if options.Kind == "" { - return "", errors.New("rollback requires -kind") - } - return rollbackResource(ctx, options) - default: - return "", fmt.Errorf("unknown recovery command %q", options.Operation) - } -} - -// summarise is an operation's stdout line, or its error. -func summarise(err error, format string, args ...any) (string, error) { - if err != nil { - return "", err - } - return fmt.Sprintf(format, args...), nil -} - -// validateStore answers the question an operator actually has: would archied -// start against this file. It runs the checks that stop it, in the order boot -// meets them. -// -// First the file itself, since a database that is corrupt, newer than this -// binary, or not a database is one the serving process refuses to open. Then -// the writer's own per-resource validation, which is what a hand-edited value -// violated. Then boot's gate: the file config with every stored resource -// layered onto it, and configuration.Validate -- the check whose failure the -// daemon reports as "validate database settings". -// -// The two validation layers disagree in both directions, and both are reported -// rather than merged. The write path is stricter about shape (it rejects -// unknown fields boot's decode ignores), while boot is stricter about meaning -// (only boot checks dispatch.trigger and a positive poll interval, both of -// which the write path's own validators let through). A store either check -// refuses is a store somebody has to look at. -func validateStore(ctx context.Context, options StateStoreRecoveryOptions) (string, error) { - version, err := store.ValidateFile(ctx, options.DB) - if err != nil { - return "", err - } - st, err := store.OpenReadOnly(ctx, options.DB) - if err != nil { - return "", err - } - defer func() { _ = st.Close() }() - - server, err := openStateStoreControlPlane(st) - if err != nil { - return "", err - } - // Is there a resources table at all? A store written before the control plane - // existed has none, and the State Store creates it and seeds every kind from - // this same config on its next start -- so there is nothing stored to check - // with the writer's validator, and boot's gate is the config check alone. - // That is the same stance the layering takes for a kind the table is missing: - // what the daemon reads for a kind nothing was ever stored for is the seed. - stored, err := st.StoresResources(ctx) - if err != nil { - return "", err - } - checked, err := checkBootGate(ctx, server, stored, options) - if err != nil { - return "", err - } - return fmt.Sprintf("%s is a valid store at schema version %d; %d stored resources validate", options.DB, version, checked), nil + return runPostgresRecovery(ctx, options) } // checkBootGate runs the writer's per-resource validation over what is stored, @@ -222,32 +136,6 @@ func bootConfig(ctx context.Context, options StateStoreRecoveryOptions) (config. return b.cfg, nil } -// rollbackResource is the one operation the Web UI cannot be asked to perform -// here: the daemon fails closed on the bad value, so the store that would serve -// the rollback is the store that will not start. It replays the revision's own -// value through the ordinary replace, so no rollback RPC exists or is needed, -// and the rollback is audited as one more revision. -func rollbackResource(ctx context.Context, options StateStoreRecoveryOptions) (string, error) { - // Before the lock and before the open: opening a store creates the file, - // and a rollback pointed at a mistyped path must not leave an empty - // database where the operator expected theirs. - if err := store.RequireDatabase(options.DB); err != nil { - return "", err - } - ownership, err := store.AcquireOwnership(options.DB) - if err != nil { - return "", err - } - defer func() { _ = ownership.Release() }() - - st, err := store.Open(ctx, options.DB) - if err != nil { - return "", err - } - defer func() { _ = st.Close() }() - return replayRevision(ctx, st, options) -} - // replayRevision puts back the revision options names through the control // plane's ordinary replace. The caller holds the store's ownership claim. func replayRevision(ctx context.Context, resources controlplane.ResourceStore, options StateStoreRecoveryOptions) (string, error) { @@ -259,7 +147,7 @@ func replayRevision(ctx context.Context, resources controlplane.ResourceStore, o return "", fmt.Errorf("unknown resource kind %q", options.Kind) } current, err := resources.Resource(ctx, options.Kind) - if errors.Is(err, store.ErrResourceNotFound) { + if errors.Is(err, storecontract.ErrResourceNotFound) { return "", fmt.Errorf("%s has no stored value to roll back", options.Kind) } if err != nil { @@ -287,10 +175,10 @@ func replayRevision(ctx context.Context, resources controlplane.ResourceStore, o // revisionToReplay picks the value to put back: the revision the operator // named, or the newest one older than the value the resource carries now. -func revisionToReplay(ctx context.Context, st controlplane.ResourceStore, kind string, current, requested int64) (store.Resource, error) { +func revisionToReplay(ctx context.Context, st controlplane.ResourceStore, kind string, current, requested int64) (storecontract.Resource, error) { history, err := st.ResourceHistory(ctx, kind, 0) if err != nil { - return store.Resource{}, fmt.Errorf("read %s history: %w", kind, err) + return storecontract.Resource{}, fmt.Errorf("read %s history: %w", kind, err) } if requested > 0 { for _, revision := range history { @@ -298,16 +186,16 @@ func revisionToReplay(ctx context.Context, st controlplane.ResourceStore, kind s continue } if revision.Version == current { - return store.Resource{}, fmt.Errorf("%s revision %d is the current version; there is nothing to roll back to", kind, requested) + return storecontract.Resource{}, fmt.Errorf("%s revision %d is the current version; there is nothing to roll back to", kind, requested) } return revision, nil } - return store.Resource{}, fmt.Errorf("%s has no revision %d", kind, requested) + return storecontract.Resource{}, fmt.Errorf("%s has no revision %d", kind, requested) } for _, revision := range history { if revision.Version < current { return revision, nil } } - return store.Resource{}, fmt.Errorf("%s has no earlier revision to roll back to", kind) + return storecontract.Resource{}, fmt.Errorf("%s has no earlier revision to roll back to", kind) } diff --git a/internal/app/archied/state_store_recovery_postgres.go b/internal/app/archied/state_store_recovery_postgres.go index ace209b07..6d97a330c 100644 --- a/internal/app/archied/state_store_recovery_postgres.go +++ b/internal/app/archied/state_store_recovery_postgres.go @@ -21,7 +21,7 @@ func runPostgresRecovery(ctx context.Context, options StateStoreRecoveryOptions) } url := cfg.DatabaseURL if url == "" { - return "", errors.New("database_url is required: the configuration names no PostgreSQL database (pass -db for a legacy SQLite task file)") + return "", errors.New("database_url is required: the configuration names no PostgreSQL database") } switch options.Operation { case RecoveryBackup: @@ -70,7 +70,8 @@ func openRecoveryPool(ctx context.Context, url string) (*pgxpool.Pool, int64, er return pool, version, nil } -// validatePostgres is validateStore for the PostgreSQL database. An +// validatePostgres answers whether archied would start against the database: +// the stored resources pass the writer's validation and boot's gate. An // unmigrated database holds nothing to check; the State Store migrates and // seeds it on its next start, so only boot's config gate applies. func validatePostgres(ctx context.Context, url string, options StateStoreRecoveryOptions) (string, error) { diff --git a/internal/app/archied/state_store_test.go b/internal/app/archied/state_store_test.go index a2bec8385..9ffbe30f9 100644 --- a/internal/app/archied/state_store_test.go +++ b/internal/app/archied/state_store_test.go @@ -12,11 +12,10 @@ import ( "github.com/samcharles93/archie-core/internal/config" pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" "github.com/samcharles93/archie-core/internal/domain/storecontract" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" "github.com/samcharles93/archie-core/internal/logging" - "github.com/samcharles93/archie-core/internal/store" ) func TestStateStoreServerOptsLoopbackIsInsecure(t *testing.T) { @@ -60,11 +59,7 @@ func TestStateStoreServerOptsMalformedListen(t *testing.T) { // in-process, now extracted into its own process. A read-only StatusCounts // call proves the service is registered and wired to the opened store. func TestServeStateStoreServesContract(t *testing.T) { - dir := t.TempDir() - st, err := store.Open(t.Context(), filepath.Join(dir, "tasks.sqlite")) - if err != nil { - t.Fatalf("open temp store: %v", err) - } + st := pgstore.Open(t) defer st.Close() b := newBootstrap() @@ -132,31 +127,28 @@ func TestStateStoreDepsServeTaskLogs(t *testing.T) { } // TestStateStoreDepsServePlaybookDispatcher verifies stateStoreDeps lifts the -// opened *store.Store's PlaybookDispatcher surface onto Deps, so the +// opened *pgstore.TaskDB's PlaybookDispatcher surface onto Deps, so the // standalone State Store has a server for the two playbook RPCs. It does not // dial those RPCs here -- it inspects the assembled Deps only. The nil check // is the load-bearing part: a boot without a store must leave // PlaybookDispatcher nil (the server then answers codes.Unavailable) rather // than fabricating a dispatcher. func TestStateStoreDepsServePlaybookDispatcher(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.sqlite")) - if err != nil { - t.Fatalf("open temp store: %v", err) - } + st := pgstore.Open(t) defer st.Close() b := newBootstrap() b.st = st // The playbook ledger moved to the event-capture store with the rest of // the dispatch tables; the task store no longer serves it. - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) b.eda = eda deps := b.stateStoreDeps(&staterpc.TaskGrants{}) if deps.PlaybookDispatcher == nil { t.Fatal("stateStoreDeps leaves PlaybookDispatcher nil; the standalone State Store is the only production server for the playbook dispatch ledger") } if deps.PlaybookDispatcher != storecontract.PlaybookDispatcher(eda) { - t.Fatalf("PlaybookDispatcher = %T, want the opened *edastore.Store", deps.PlaybookDispatcher) + t.Fatalf("PlaybookDispatcher = %T, want the opened *postgres.EDA", deps.PlaybookDispatcher) } // A boot without a store must not fabricate one: nil keeps the RPCs honest // as unavailable rather than depending on a nil receiver. diff --git a/internal/app/archied/state_store_toolcalls.go b/internal/app/archied/state_store_toolcalls.go index f4ba41edc..05d3f0981 100644 --- a/internal/app/archied/state_store_toolcalls.go +++ b/internal/app/archied/state_store_toolcalls.go @@ -7,13 +7,13 @@ import ( "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres" ) -// toolCallWriter is the edastore surface the projection writes through. Kept +// toolCallWriter is the EDA store surface the projection writes through. Kept // narrow so a test can fail it without touching the real store. type toolCallWriter interface { - InsertToolCall(ctx context.Context, tc edastore.ToolCall) error + InsertToolCall(ctx context.Context, tc postgres.ToolCall) error } // toolCallProjectingTaskStore decorates the State Store's task store so every @@ -69,10 +69,10 @@ func (s *toolCallProjectingTaskStore) InsertEvent(ctx context.Context, e events. // fields stay unwritten -- the event reports neither -- so they are schema // reserved for a producer that one day reports them, not promises this // projection makes. -func toolCallFromEvent(e events.Event) edastore.ToolCall { +func toolCallFromEvent(e events.Event) postgres.ToolCall { tool, _ := e.Data["tool"].(string) failed, _ := e.Data["failed"].(bool) - tc := edastore.ToolCall{ + tc := postgres.ToolCall{ TaskID: e.TaskID, Attempt: e.Attempt, Tool: tool, diff --git a/internal/app/archied/state_store_toolcalls_test.go b/internal/app/archied/state_store_toolcalls_test.go index 1371f7d55..92a7048c6 100644 --- a/internal/app/archied/state_store_toolcalls_test.go +++ b/internal/app/archied/state_store_toolcalls_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" - "github.com/samcharles93/archie-core/internal/store" ) func toolCallEvent(taskID int64, attempt int) events.Event { @@ -33,8 +33,8 @@ func toolCallEvent(taskID int64, attempt int) events.Event { // tool_calls row, with the row's fields taken from the event -- the tool name // from data, the output summary in result for a succeeded call. func TestInsertEventProjectsToolCall(t *testing.T) { - st := store.OpenTest(t) - eda := edastore.OpenTest(t) + st := pgstore.Open(t) + eda := pgstore.EDA(t, nil) ts := newToolCallProjectingTaskStore(st, eda, slog.Default()) id, err := ts.InsertEvent(t.Context(), toolCallEvent(42, 2)) @@ -74,8 +74,8 @@ func TestInsertEventProjectsToolCall(t *testing.T) { // event whose call failed stores its detail under error, not result, so the // transcript can distinguish the two without re-parsing text. func TestInsertEventProjectsFailedToolCall(t *testing.T) { - st := store.OpenTest(t) - eda := edastore.OpenTest(t) + st := pgstore.Open(t) + eda := pgstore.EDA(t, nil) ts := newToolCallProjectingTaskStore(st, eda, slog.Default()) e := toolCallEvent(42, 2) @@ -104,8 +104,8 @@ func TestInsertEventProjectsFailedToolCall(t *testing.T) { // tool_call events reach the collection; the task timeline's other kinds must // not grow tool_calls rows. func TestInsertEventLeavesOtherKindsUnprojected(t *testing.T) { - st := store.OpenTest(t) - eda := edastore.OpenTest(t) + st := pgstore.Open(t) + eda := pgstore.EDA(t, nil) ts := newToolCallProjectingTaskStore(st, eda, slog.Default()) if _, err := ts.InsertEvent(t.Context(), events.Event{ @@ -129,7 +129,7 @@ func TestInsertEventLeavesOtherKindsUnprojected(t *testing.T) { // store. type failingToolCallWriter struct{ err error } -func (f failingToolCallWriter) InsertToolCall(context.Context, edastore.ToolCall) error { +func (f failingToolCallWriter) InsertToolCall(context.Context, postgres.ToolCall) error { return f.err } @@ -138,7 +138,7 @@ func (f failingToolCallWriter) InsertToolCall(context.Context, edastore.ToolCall // event persistence is the contract, the projection is observability -- and // the failure is recorded, not swallowed silently. func TestInsertEventSucceedsWhenProjectionFails(t *testing.T) { - st := store.OpenTest(t) + st := pgstore.Open(t) var buf bytes.Buffer ts := newToolCallProjectingTaskStore(st, failingToolCallWriter{ err: errors.New("disk on fire"), @@ -172,8 +172,8 @@ func TestInsertEventSucceedsWhenProjectionFails(t *testing.T) { // event-capture store, Tasks is passed through untouched rather than wrapped // around a nil writer. func TestStateStoreDepsProjectToolCalls(t *testing.T) { - st := store.OpenTest(t) - eda := edastore.OpenTest(t) + st := pgstore.Open(t) + eda := pgstore.EDA(t, nil) b := newBootstrap() b.st = st diff --git a/internal/app/archied/status_health_test.go b/internal/app/archied/status_health_test.go index c2e1adb9a..3983d5bff 100644 --- a/internal/app/archied/status_health_test.go +++ b/internal/app/archied/status_health_test.go @@ -23,7 +23,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/curator" "github.com/samcharles93/archie-core/internal/domain/messaging" "github.com/samcharles93/archie-core/internal/gateway" - "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" ) // TestProviderOutcomeRecorderRecordsTheLastCallOnly pins the producer behind @@ -356,7 +356,7 @@ func TestRouterWithHealthAnswersStatus(t *testing.T) { sessions := gateway.NewSessionStoreMemory() t.Cleanup(func() { _ = sessions.Close() }) - st := store.OpenTest(t) + st := pgstore.Open(t) router := gateway.NewRouter(st, nil, "web") router.InitSessions(sessions) router.Health = statusHealth{broker: func() (bool, bool) { return true, true }} diff --git a/internal/app/archied/task_action_adapter_test.go b/internal/app/archied/task_action_adapter_test.go index a49b4915a..fc7e66286 100644 --- a/internal/app/archied/task_action_adapter_test.go +++ b/internal/app/archied/task_action_adapter_test.go @@ -4,15 +4,16 @@ import ( "context" "fmt" "log/slog" - "path/filepath" "strings" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "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/gateway" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskstate" ) @@ -35,7 +36,7 @@ func (a testTaskActor) ApplyChatTaskAction( }, nil } -func newChatTaskActorForTest(t *testing.T, st store.TaskStore, cfg config.Config) chatTaskActorAdapter { +func newChatTaskActorForTest(t *testing.T, st storecontract.TaskStore, cfg config.Config) chatTaskActorAdapter { t.Helper() b := &boot{ st: st, @@ -48,10 +49,7 @@ func newChatTaskActorForTest(t *testing.T, st store.TaskStore, cfg config.Config func TestChatTaskActorAdapterCrossIdentityRefused(t *testing.T) { ctx := context.Background() - st, err := store.Open(ctx, filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) task, err := st.EnqueueChatTask(ctx, "acme", "widget", "parked job", "", "", "identity-owner") @@ -111,10 +109,7 @@ func TestChatTaskActorAdapterCrossIdentityRefused(t *testing.T) { func TestChatTaskActorAdapterRefusesDisallowedStateAction(t *testing.T) { ctx := context.Background() - st, err := store.Open(ctx, filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) adapter := newChatTaskActorForTest(t, st, config.Config{}) @@ -188,15 +183,12 @@ func TestChatTaskActorAdapterRefusesDisallowedStateAction(t *testing.T) { func TestChatTaskActorAdapterTaskNotFound(t *testing.T) { ctx := context.Background() - st, err := store.Open(ctx, filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) adapter := newChatTaskActorForTest(t, st, config.Config{}) - _, err = adapter.ApplyChatTaskAction(ctx, new("archie"), taskactions.Actor{}, 999999, taskstate.ActionAbandon) + _, err := adapter.ApplyChatTaskAction(ctx, new("archie"), taskactions.Actor{}, 999999, taskstate.ActionAbandon) if err == nil { t.Fatal("expected error for non-existent task, got nil") } @@ -260,10 +252,7 @@ func TestChatTaskActorAdapterAppliesActionsToStore(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { ctx := context.Background() - st, err := store.Open(ctx, filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) adapter := newChatTaskActorForTest(t, st, config.Config{MaxRetries: 3}) diff --git a/internal/app/archied/task_actions_test.go b/internal/app/archied/task_actions_test.go index e2545d9a4..cbe1af4d2 100644 --- a/internal/app/archied/task_actions_test.go +++ b/internal/app/archied/task_actions_test.go @@ -6,14 +6,15 @@ import ( "log/slog" "net/http" "net/http/httptest" - "path/filepath" "strconv" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow" "github.com/samcharles93/archie-core/internal/gateway" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -44,10 +45,7 @@ func TestDashboardAndChatAgreeOnTerminalStates(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { ctx := context.Background() - st, err := store.Open(ctx, filepath.Join(t.TempDir(), "tasks.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) task, err := st.EnqueueChatTask(ctx, "acme", "widget", "decide on me", "", "", "reviewer") @@ -78,7 +76,7 @@ func TestDashboardAndChatAgreeOnTerminalStates(t *testing.T) { // runChatAction performs the approve/cancel action through the chat // controller path and fails the test on error. -func runChatAction(t *testing.T, ctx context.Context, st store.TaskStore, action string, taskID int64) { +func runChatAction(t *testing.T, ctx context.Context, st storecontract.TaskStore, action string, taskID int64) { t.Helper() controller := gateway.NewStoreTaskController(chatTaskControllerAdapter{ taskByID: st.TaskByID, @@ -99,7 +97,7 @@ func runChatAction(t *testing.T, ctx context.Context, st store.TaskStore, action // runDashboardAction performs the approve/cancel action through the // dashboard's HTTP handler and fails the test when the request is // rejected. -func runDashboardAction(t *testing.T, ctx context.Context, st store.TaskStore, action string, taskID int64) { +func runDashboardAction(t *testing.T, ctx context.Context, st storecontract.TaskStore, action string, taskID int64) { t.Helper() // The dashboard reaches task actions through the Gateway contract, which // in production carries them back to this daemon's own service. Wiring diff --git a/internal/app/archieui/compose_test.go b/internal/app/archieui/compose_test.go index cd36972a0..a2d853c1c 100644 --- a/internal/app/archieui/compose_test.go +++ b/internal/app/archieui/compose_test.go @@ -10,8 +10,8 @@ import ( "github.com/samcharles93/archie-core/internal/infrastructure/configuration" "github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" - "github.com/samcharles93/archie-core/internal/store" ) // isNil reports whether v is nil, including a typed nil func or pointer @@ -61,8 +61,8 @@ func TestComposeUIServerHoldsNoDaemonState(t *testing.T) { if _, ok := srv.Store.(*staterpc.Client); !ok { t.Fatalf("Store = %T, want *staterpc.Client", srv.Store) } - if _, ok := srv.Store.(*store.Store); ok { - t.Fatal("Store is the concrete *store.Store; the UI process must not open archie.db") + if _, ok := srv.Store.(*pgstore.TaskDB); ok { + t.Fatal("Store is the concrete *pgstore.TaskDB; the UI process must not open archie.db") } if srv.Chat == nil { t.Fatal("Chat is nil; the UI process must dial the Gateway contract") diff --git a/internal/app/archieui/degraded_routes_test.go b/internal/app/archieui/degraded_routes_test.go index ac245e04a..d405f7847 100644 --- a/internal/app/archieui/degraded_routes_test.go +++ b/internal/app/archieui/degraded_routes_test.go @@ -13,10 +13,9 @@ import ( "google.golang.org/grpc" - "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/logging" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -153,10 +152,7 @@ func TestRoutesWithoutAContractDegradeExplicitly(t *testing.T) { // all -- the shape every route below has to survive. func composeUIProcess(t *testing.T) (*webui.Server, int64) { t.Helper() - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.sqlite")) - if err != nil { - t.Fatalf("open store: %v", err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) // The task-log reader lives on the state-directory side of the boundary: @@ -166,7 +162,7 @@ func composeUIProcess(t *testing.T) (*webui.Server, int64) { logs := logging.NewTaskRegistry(filepath.Join(t.TempDir(), "logs", "tasks"), logging.NewFeed(10), logging.TaskSinkOptions{}) target, stop := serveGRPC(t, func(r grpc.ServiceRegistrar) { - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) staterpc.RegisterServer(r, staterpc.Deps{ Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, TaskLogs: logs, Log: slog.New(slog.DiscardHandler), diff --git a/internal/app/archieui/pgtest_test.go b/internal/app/archieui/pgtest_test.go new file mode 100644 index 000000000..3d73cc3eb --- /dev/null +++ b/internal/app/archieui/pgtest_test.go @@ -0,0 +1,10 @@ +package archieui + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/app/archieui/run_test.go b/internal/app/archieui/run_test.go index 47529eecb..278368eb5 100644 --- a/internal/app/archieui/run_test.go +++ b/internal/app/archieui/run_test.go @@ -18,13 +18,13 @@ import ( "github.com/samcharles93/archie-core/internal/domain/health" "github.com/samcharles93/archie-core/internal/domain/messaging" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/taskactions" "github.com/samcharles93/archie-core/internal/events" "github.com/samcharles93/archie-core/internal/gateway" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" "github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskstate" "github.com/samcharles93/archie-core/internal/webui" ) @@ -100,10 +100,7 @@ func serveGRPC(t *testing.T, register func(grpc.ServiceRegistrar)) (target strin // every route with no contract behind it degrades exactly as // docs/prds/ui-service-boundary.md:130-131 permits. func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.sqlite")) - if err != nil { - t.Fatalf("open temp store: %v", err) - } + st := pgstore.Open(t) defer st.Close() seeded, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", "") if err != nil { @@ -119,7 +116,7 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) { if err != nil { t.Fatal(err) } - if err := st.PutConfigSnapshot(t.Context(), store.ConfigSnapshot{ + if err := st.PutConfigSnapshot(t.Context(), storecontract.ConfigSnapshot{ Schema: webui.ConfigViewSchema, Document: published, }); err != nil { t.Fatalf("publish config snapshot: %v", err) @@ -152,7 +149,7 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) { } stateTarget, stopState := serveGRPC(t, func(r grpc.ServiceRegistrar) { - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) staterpc.RegisterServer(r, staterpc.Deps{Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, Log: slog.New(slog.DiscardHandler)}) }) defer stopState() diff --git a/internal/app/archieui/task_logs_test.go b/internal/app/archieui/task_logs_test.go index dffa54f2e..fe6390d39 100644 --- a/internal/app/archieui/task_logs_test.go +++ b/internal/app/archieui/task_logs_test.go @@ -13,10 +13,9 @@ import ( "google.golang.org/grpc" - "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/logging" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/webui" ) @@ -154,10 +153,7 @@ func TestUIProcessReportsMissingTaskLogsHonestly(t *testing.T) { // file, so the dashboard's read has to cross the wire to see anything. func composeUIProcessWithLog(t *testing.T) (*webui.Server, int64, int) { t.Helper() - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.sqlite")) - if err != nil { - t.Fatalf("open store: %v", err) - } + st := pgstore.Open(t) t.Cleanup(func() { _ = st.Close() }) task, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "a task", "body", "implement", "") @@ -179,7 +175,7 @@ func composeUIProcessWithLog(t *testing.T) (*webui.Server, int64, int) { } target, stop := serveGRPC(t, func(r grpc.ServiceRegistrar) { - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) staterpc.RegisterServer(r, staterpc.Deps{ Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, TaskLogs: logs, Log: slog.New(slog.DiscardHandler), diff --git a/internal/app/controlplane/controlplane.go b/internal/app/controlplane/controlplane.go index 42da58c88..0ba5704ce 100644 --- a/internal/app/controlplane/controlplane.go +++ b/internal/app/controlplane/controlplane.go @@ -11,9 +11,9 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow" "github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc" - "github.com/samcharles93/archie-core/internal/store" ) // The control-plane wire sentinels cross gRPC matched on (code, canonical @@ -31,9 +31,9 @@ var ( // root asserts the State Store against it, so this is the single definition of // what a control-plane backing store must offer. type ResourceStore interface { - Resource(context.Context, string) (store.Resource, error) - ResourceHistory(context.Context, string, int) ([]store.Resource, error) - PutResource(context.Context, store.ResourceWrite) (store.Resource, error) + Resource(context.Context, string) (storecontract.Resource, error) + ResourceHistory(context.Context, string, int) ([]storecontract.Resource, error) + PutResource(context.Context, storecontract.ResourceWrite) (storecontract.Resource, error) } // defaultHistoryLimit caps an unbounded request. A settings resource edited @@ -121,7 +121,7 @@ func (s *Server) Command(ctx context.Context, request *pb.CommandRequest) (*pb.C if err != nil { return nil, mapError(err) } - resource, err := s.store.PutResource(ctx, store.ResourceWrite{Kind: request.Kind, Value: value, Actor: request.Actor, Source: request.Source, RequestID: request.RequestId, ExpectedVersion: request.ExpectedVersion, At: time.Now().UTC()}) + resource, err := s.store.PutResource(ctx, storecontract.ResourceWrite{Kind: request.Kind, Value: value, Actor: request.Actor, Source: request.Source, RequestID: request.RequestId, ExpectedVersion: request.ExpectedVersion, At: time.Now().UTC()}) if err != nil { return nil, mapError(err) } @@ -142,7 +142,7 @@ func (s *Server) Watch(request *pb.WatchRequest, stream pb.ControlPlaneService_W return err } version = resource.Version - } else if err != nil && !errors.Is(err, store.ErrResourceNotFound) { + } else if err != nil && !errors.Is(err, storecontract.ErrResourceNotFound) { return mapError(err) } select { @@ -153,7 +153,7 @@ func (s *Server) Watch(request *pb.WatchRequest, stream pb.ControlPlaneService_W } } -func resourceProto(resource store.Resource) *pb.Resource { +func resourceProto(resource storecontract.Resource) *pb.Resource { return &pb.Resource{Kind: resource.Kind, Version: resource.Version, ValueJson: resource.Value, UpdatedAt: timestamp(resource.At)} } @@ -168,9 +168,9 @@ func mapError(err error) error { switch { case errors.Is(err, ErrValidation): return status.Error(codes.InvalidArgument, err.Error()) - case errors.Is(err, store.ErrResourceNotFound): + case errors.Is(err, storecontract.ErrResourceNotFound): return status.Error(codes.NotFound, err.Error()) - case errors.Is(err, store.ErrResourceVersionConflict): + case errors.Is(err, storecontract.ErrResourceVersionConflict): return status.Error(codes.Aborted, err.Error()) default: return status.Error(codes.Unavailable, err.Error()) diff --git a/internal/app/controlplane/controlplane_test.go b/internal/app/controlplane/controlplane_test.go index fcbe17061..a73928322 100644 --- a/internal/app/controlplane/controlplane_test.go +++ b/internal/app/controlplane/controlplane_test.go @@ -13,9 +13,10 @@ import ( "github.com/samcharles93/archie-core/internal/config" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" "github.com/samcharles93/archie-core/internal/domain/agent" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps" - "github.com/samcharles93/archie-core/internal/store" ) // testSteps builds the production workflow step vocabulary for tests that are @@ -45,7 +46,7 @@ func testServer(t *testing.T, resources ResourceStore) *Server { func TestCatalogCarriesShippedWorkflowDefinitionsForRestore(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() catalog, err := testServer(t, resources).Catalog(t.Context(), &pb.CatalogRequest{}) if err != nil { @@ -72,7 +73,7 @@ func TestCatalogCarriesShippedWorkflowDefinitionsForRestore(t *testing.T) { func TestImportConfigSeedsWorkflowDefinitionsWithoutOverwritingOverride(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) if _, _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil { @@ -94,7 +95,7 @@ func TestImportConfigSeedsWorkflowDefinitionsWithoutOverwritingOverride(t *testi if err != nil { t.Fatal(err) } - if _, err := resources.PutResource(t.Context(), store.ResourceWrite{Kind: WorkflowDefinitionsKind, Value: value, ExpectedVersion: resource.Version, Actor: "test", Source: "test", RequestID: "override"}); err != nil { + if _, err := resources.PutResource(t.Context(), storecontract.ResourceWrite{Kind: WorkflowDefinitionsKind, Value: value, ExpectedVersion: resource.Version, Actor: "test", Source: "test", RequestID: "override"}); err != nil { t.Fatal(err) } if _, _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil { @@ -112,7 +113,7 @@ func TestImportConfigSeedsWorkflowDefinitionsWithoutOverwritingOverride(t *testi func TestImportConfigSeedsPersonasWithoutOverwritingEdits(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) if _, _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil { @@ -131,7 +132,7 @@ func TestImportConfigSeedsPersonasWithoutOverwritingEdits(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err := resources.PutResource(t.Context(), store.ResourceWrite{Kind: PersonasKind, Value: value, ExpectedVersion: resource.Version, Actor: "test", Source: "test", RequestID: "persona-edit"}); err != nil { + if _, err := resources.PutResource(t.Context(), storecontract.ResourceWrite{Kind: PersonasKind, Value: value, ExpectedVersion: resource.Version, Actor: "test", Source: "test", RequestID: "persona-edit"}); err != nil { t.Fatal(err) } if _, _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil { @@ -150,7 +151,7 @@ func TestImportConfigSeedsPersonasWithoutOverwritingEdits(t *testing.T) { func TestImportWorkflowExecutionSettingsDoesNotOverwriteExistingValue(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) first := workflow.ExecutionSettings{MaxModelToolSteps: 10, MaxRuntime: time.Minute, MaxConsecutiveGateFailures: 2} @@ -176,7 +177,7 @@ func TestImportWorkflowExecutionSettingsDoesNotOverwriteExistingValue(t *testing func TestRegistryRoutesAndValidatesDefinitions(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) // The image is required, here as in the file document: a seed without one is @@ -212,7 +213,7 @@ func TestRegistryRoutesAndValidatesDefinitions(t *testing.T) { func TestProviderSeedKeepsReferencesAndNeverResolvedSecrets(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) cfg := config.Config{Providers: map[string]config.Provider{"openai": {Class: "openai", APIKeyEnv: "OPENAI_API_KEY", APIKey: config.SecretRef{Engine: "env", Key: "OPENAI_API_KEY"}}}} @@ -239,7 +240,7 @@ func TestProviderSeedKeepsReferencesAndNeverResolvedSecrets(t *testing.T) { func TestHistoryCarriesEveryRevisionWithItsAudit(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) if _, _, err := server.ImportConfig(t.Context(), config.Config{}); err != nil { @@ -288,7 +289,7 @@ func TestHistoryCarriesEveryRevisionWithItsAudit(t *testing.T) { func TestImportConfigSkipsASeedItCannotValidate(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) // Every other field is filled in the way the loader fills it (Validate @@ -307,7 +308,7 @@ func TestImportConfigSkipsASeedItCannotValidate(t *testing.T) { if len(skipped) != 1 || skipped[0].Kind != RepositoryPoliciesKind || skipped[0].Err == nil { t.Fatalf("skipped = %+v, want the repository policies and the reason", skipped) } - if _, err := resources.Resource(t.Context(), RepositoryPoliciesKind); !errors.Is(err, store.ErrResourceNotFound) { + if _, err := resources.Resource(t.Context(), RepositoryPoliciesKind); !errors.Is(err, storecontract.ErrResourceNotFound) { t.Errorf("repository policies Resource = %v, want ErrResourceNotFound: an invalid seed must not be stored", err) } // Kinds that are fine are still seeded: one skipped kind does not abandon diff --git a/internal/app/controlplane/controlplane_watch_test.go b/internal/app/controlplane/controlplane_watch_test.go index 0cfbfedd4..ff8308815 100644 --- a/internal/app/controlplane/controlplane_watch_test.go +++ b/internal/app/controlplane/controlplane_watch_test.go @@ -15,8 +15,9 @@ import ( "google.golang.org/grpc/test/bufconn" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow" - "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" ) // scriptedWatchClient is the rpc end of a Watch call whose stream is scripted @@ -222,7 +223,7 @@ func TestWatchClientsDeliverNothingForAStreamThatDidNotFail(t *testing.T) { func TestWatchServesOnlyVersionsAfterTheRequestedOne(t *testing.T) { t.Parallel() - resources := store.OpenTest(t) + resources := pgstore.Open(t) defer resources.Close() server := testServer(t, resources) version, err := server.ImportWorkflowExecutionSettings(t.Context(), workflow.ExecutionSettings{MaxModelToolSteps: 10, MaxRuntime: time.Minute, MaxConsecutiveGateFailures: 2}) @@ -280,7 +281,7 @@ func TestWatchServesOnlyVersionsAfterTheRequestedOne(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err := resources.PutResource(ctx, store.ResourceWrite{Kind: WorkflowExecutionSettingsKind, Value: value, ExpectedVersion: version, Actor: "test", Source: "test", RequestID: "watch-next"}); err != nil { + if _, err := resources.PutResource(ctx, storecontract.ResourceWrite{Kind: WorkflowExecutionSettingsKind, Value: value, ExpectedVersion: version, Actor: "test", Source: "test", RequestID: "watch-next"}); err != nil { t.Fatal(err) } select { diff --git a/internal/app/controlplane/pgtest_test.go b/internal/app/controlplane/pgtest_test.go new file mode 100644 index 000000000..2fbd3b187 --- /dev/null +++ b/internal/app/controlplane/pgtest_test.go @@ -0,0 +1,10 @@ +package controlplane + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/app/controlplane/registry.go b/internal/app/controlplane/registry.go index eada7eb79..cdea1f87a 100644 --- a/internal/app/controlplane/registry.go +++ b/internal/app/controlplane/registry.go @@ -10,7 +10,7 @@ import ( "github.com/samcharles93/archie-core/internal/config" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" - "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/domain/storecontract" ) type Definition struct { @@ -96,7 +96,7 @@ func (s *Server) ImportConfig(ctx context.Context, cfg config.Config) (map[strin versions[definition.Kind] = resource.Version continue } - if !errors.Is(err, store.ErrResourceNotFound) { + if !errors.Is(err, storecontract.ErrResourceNotFound) { return nil, nil, err } value, err := definition.seededValue(cfg) @@ -111,7 +111,7 @@ func (s *Server) ImportConfig(ctx context.Context, cfg config.Config) (map[strin skipped = append(skipped, SeedSkip{Kind: definition.Kind, Err: err}) continue } - resource, err = s.store.PutResource(ctx, store.ResourceWrite{Kind: definition.Kind, Value: value, Actor: "system:migration", Source: "legacy-config", RequestID: "import:" + definition.Kind, ExpectedVersion: 0, At: time.Now().UTC()}) + resource, err = s.store.PutResource(ctx, storecontract.ResourceWrite{Kind: definition.Kind, Value: value, Actor: "system:migration", Source: "legacy-config", RequestID: "import:" + definition.Kind, ExpectedVersion: 0, At: time.Now().UTC()}) if err != nil { return nil, nil, fmt.Errorf("seed %s: %w", definition.Kind, err) } @@ -176,7 +176,7 @@ func (s *Server) ValidateStored(ctx context.Context) (int, error) { var failures []error for _, definition := range s.ordered { resource, err := s.store.Resource(ctx, definition.Kind) - if errors.Is(err, store.ErrResourceNotFound) { + if errors.Is(err, storecontract.ErrResourceNotFound) { continue } if err != nil { diff --git a/internal/app/controlplane/runtime_config.go b/internal/app/controlplane/runtime_config.go index ef4483492..390a923bd 100644 --- a/internal/app/controlplane/runtime_config.go +++ b/internal/app/controlplane/runtime_config.go @@ -8,8 +8,8 @@ import ( "time" "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc" - "github.com/samcharles93/archie-core/internal/store" ) // resourceReader is the one read the layering performs: a resource kind's value @@ -72,10 +72,10 @@ type storeReader struct { func (r storeReader) Query(ctx context.Context, kind string, decode func([]byte) error) (int64, bool, error) { resource, err := r.resources.Resource(ctx, kind) - if errors.Is(err, store.ErrResourceNotFound) { + if errors.Is(err, storecontract.ErrResourceNotFound) { seed, ok := r.seeds[kind] if !ok { - return 0, false, fmt.Errorf("read %s: %w", kind, store.ErrResourceNotFound) + return 0, false, fmt.Errorf("read %s: %w", kind, storecontract.ErrResourceNotFound) } if err := decode(seed); err != nil { return 0, false, fmt.Errorf("decode %s seed: %w", kind, err) diff --git a/internal/app/controlplane/step_vocabulary_agreement_test.go b/internal/app/controlplane/step_vocabulary_agreement_test.go index 4c8a37f4f..7700212ac 100644 --- a/internal/app/controlplane/step_vocabulary_agreement_test.go +++ b/internal/app/controlplane/step_vocabulary_agreement_test.go @@ -35,8 +35,8 @@ import ( "github.com/samcharles93/archie-core/internal/app/agentworker" pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" "github.com/samcharles93/archie-core/internal/domain/workflow" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskrun" ) @@ -191,7 +191,7 @@ func TestEveryProductionResolutionSiteResolvesTheRegisteredStepType(t *testing.T // than dereference it: a nil-pointer panic is the same failure with no clue in // it. func TestNilStepVocabularyFailsClosedAtEveryResolutionSite(t *testing.T) { - resources := store.OpenTest(t) + resources := pgstore.Open(t) t.Cleanup(func() { if err := resources.Close(); err != nil { t.Errorf("close test store: %v", err) @@ -256,7 +256,7 @@ func requireRefusal(t *testing.T, side, stepType string, err error) { func admitThroughStateStore(t *testing.T, steps *workflow.Manager, stepType string) (before, after int64, err error) { t.Helper() - resources := store.OpenTest(t) + resources := pgstore.Open(t) t.Cleanup(func() { if closeErr := resources.Close(); closeErr != nil { t.Errorf("close test store: %v", closeErr) diff --git a/internal/app/controlplane/workflow_settings.go b/internal/app/controlplane/workflow_settings.go index f92f67fb0..2295f61b3 100644 --- a/internal/app/controlplane/workflow_settings.go +++ b/internal/app/controlplane/workflow_settings.go @@ -8,8 +8,8 @@ import ( "time" "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/workflow" - "github.com/samcharles93/archie-core/internal/store" ) const WorkflowExecutionSettingsKind = "workflow-execution-settings" @@ -27,7 +27,7 @@ func (s *Server) ImportWorkflowExecutionSettings(ctx context.Context, settings w if err == nil { return resource.Version, nil } - if !errors.Is(err, store.ErrResourceNotFound) { + if !errors.Is(err, storecontract.ErrResourceNotFound) { return 0, err } value, err := encodeSettings(settings) @@ -38,7 +38,7 @@ func (s *Server) ImportWorkflowExecutionSettings(ctx context.Context, settings w if err != nil { return 0, err } - resource, err = s.store.PutResource(ctx, store.ResourceWrite{Kind: WorkflowExecutionSettingsKind, Value: value, Actor: "system:migration", Source: "legacy-config", RequestID: "import:" + WorkflowExecutionSettingsKind, ExpectedVersion: 0, At: time.Now().UTC()}) + resource, err = s.store.PutResource(ctx, storecontract.ResourceWrite{Kind: WorkflowExecutionSettingsKind, Value: value, Actor: "system:migration", Source: "legacy-config", RequestID: "import:" + WorkflowExecutionSettingsKind, ExpectedVersion: 0, At: time.Now().UTC()}) return resource.Version, err } diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index 1ec0d07ff..8c9dbd1be 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -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 { diff --git a/internal/daemon/dispatch_bindings_test.go b/internal/daemon/dispatch_bindings_test.go index 362e920fc..d460aaa31 100644 --- a/internal/daemon/dispatch_bindings_test.go +++ b/internal/daemon/dispatch_bindings_test.go @@ -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 { diff --git a/internal/daemon/identity_dispatch_test.go b/internal/daemon/identity_dispatch_test.go index 0bcc6b839..5797ea3e5 100644 --- a/internal/daemon/identity_dispatch_test.go +++ b/internal/daemon/identity_dispatch_test.go @@ -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) diff --git a/internal/daemon/pgtest_test.go b/internal/daemon/pgtest_test.go new file mode 100644 index 000000000..c666a5715 --- /dev/null +++ b/internal/daemon/pgtest_test.go @@ -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)) } diff --git a/internal/daemon/playbook_dispatch_test.go b/internal/daemon/playbook_dispatch_test.go index feab28f23..bf8387c77 100644 --- a/internal/daemon/playbook_dispatch_test.go +++ b/internal/daemon/playbook_dispatch_test.go @@ -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") diff --git a/internal/daemon/playbook_run_test.go b/internal/daemon/playbook_run_test.go index 7b7b069b4..7b1851428 100644 --- a/internal/daemon/playbook_run_test.go +++ b/internal/daemon/playbook_run_test.go @@ -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 diff --git a/internal/daemon/task_cancellation_test.go b/internal/daemon/task_cancellation_test.go index 838b03b6a..92a51d45c 100644 --- a/internal/daemon/task_cancellation_test.go +++ b/internal/daemon/task_cancellation_test.go @@ -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{ diff --git a/internal/daemon/terminal_cleanup_test.go b/internal/daemon/terminal_cleanup_test.go index f23435933..58f5002d8 100644 --- a/internal/daemon/terminal_cleanup_test.go +++ b/internal/daemon/terminal_cleanup_test.go @@ -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()} diff --git a/internal/daemon/workflow_definition_test.go b/internal/daemon/workflow_definition_test.go index 29096c4e2..7de49ebea 100644 --- a/internal/daemon/workflow_definition_test.go +++ b/internal/daemon/workflow_definition_test.go @@ -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 { diff --git a/internal/domain/workflow/pgtest_test.go b/internal/domain/workflow/pgtest_test.go new file mode 100644 index 000000000..c734ec0bb --- /dev/null +++ b/internal/domain/workflow/pgtest_test.go @@ -0,0 +1,10 @@ +package workflow + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/domain/workflow/store_integration_test.go b/internal/domain/workflow/store_integration_test.go index 37575e83d..84d3061e7 100644 --- a/internal/domain/workflow/store_integration_test.go +++ b/internal/domain/workflow/store_integration_test.go @@ -4,20 +4,20 @@ import ( "bytes" "context" "log/slog" - "path/filepath" "strings" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" + "github.com/samcharles93/archie-core/internal/agentexec" "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/workflow" - "github.com/samcharles93/archie-core/internal/store" ) // storeIntegrationRunner is a minimal agentexec.Runner stub, duplicated // here (rather than reused from the in-package tests) because this file // lives in the external workflow_test package: it needs the real -// *store.Store as a workflow.Store, and the package under test now owns +// *pgstore.TaskDB as a workflow.Store, and the package under test now owns // workflow.Task/Status/Source, which would otherwise cycle back through // internal/store's dependency on internal/domain/workflow. type storeIntegrationRunner struct { @@ -44,10 +44,7 @@ func (r *storeIntegrationRunner) Run( // and the store as park_reason, but never the log. A workflow that ends without // an outcome is the smallest way to reach that path. func TestRunRecordsAParkReasonInTheRunsOwnLog(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { if err := st.Close(); err != nil { t.Errorf("close store: %v", err) @@ -82,10 +79,7 @@ func TestRunRecordsAParkReasonInTheRunsOwnLog(t *testing.T) { } func TestAgentStagePersistsReturnedNotes(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { if err := st.Close(); err != nil { t.Errorf("close store: %v", err) @@ -119,10 +113,7 @@ func TestAgentStagePersistsReturnedNotes(t *testing.T) { } func TestRunLeavesInterruptedTaskForCrashRecovery(t *testing.T) { - st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db")) - if err != nil { - t.Fatal(err) - } + st := pgstore.Open(t) t.Cleanup(func() { if err := st.Close(); err != nil { t.Errorf("close store: %v", err) diff --git a/internal/infrastructure/bindingcipher/cipher.go b/internal/infrastructure/bindingcipher/cipher.go index 6c398adaf..9790e8233 100644 --- a/internal/infrastructure/bindingcipher/cipher.go +++ b/internal/infrastructure/bindingcipher/cipher.go @@ -1,4 +1,6 @@ -package edastore +// Package bindingcipher seals binding secrets at rest with AES-256-GCM under +// a rotatable keyring. +package bindingcipher import ( "crypto/aes" diff --git a/internal/infrastructure/bindingcipher/cipher_test.go b/internal/infrastructure/bindingcipher/cipher_test.go index 42ae13d26..769b3f3b6 100644 --- a/internal/infrastructure/bindingcipher/cipher_test.go +++ b/internal/infrastructure/bindingcipher/cipher_test.go @@ -1,8 +1,7 @@ -package edastore +package bindingcipher import ( "encoding/base64" - "path/filepath" "strings" "testing" ) @@ -121,110 +120,6 @@ func TestBindingCipherDerivesDistinctKeys(t *testing.T) { } } -// openWithCipher builds a store whose binding secrets are encrypted at rest. -func openWithCipher(t *testing.T, cipher BindingCipher) *Store { - t.Helper() - dir := t.TempDir() - s, err := Open(Config{ - DBPath: filepath.Join(dir, "eda.sqlite"), - DataDir: filepath.Join(dir, "pb_data"), - Cipher: cipher, - }) - if err != nil { - t.Fatalf("Open() error = %v", err) - } - t.Cleanup(func() { _ = s.Close() }) - return s -} - -func sampleBinding() bindingInput { - return bindingInput{Name: "n", Source: "sentry", Workflow: "implement", Secret: "supersecretvalue0123"} -} - -// TestBindingSecretIsEncryptedAtRest pins that the plaintext secret never -// reaches the database file. Reading the column directly is the point: a -// round-trip through the store would decrypt and prove nothing. -func TestBindingSecretIsEncryptedAtRest(t *testing.T) { - cipher, err := NewBindingCipher(testBindingKey, nil) - if err != nil { - t.Fatalf("NewBindingCipher() error = %v", err) - } - s := openWithCipher(t, cipher) - in := sampleBinding() - id := insertBinding(t, s, in) - - var stored string - if err := s.App().DB().NewQuery("SELECT secret FROM " + CollBindings + " WHERE id = {:id}"). - Bind(map[string]any{"id": id}).Row(&stored); err != nil { - t.Fatalf("read raw secret: %v", err) - } - if stored == in.Secret { - t.Fatal("secret is stored as plaintext; it must be encrypted at rest") - } - if !strings.Contains(stored, ":") { - t.Errorf("stored secret %q does not look like a cipher envelope", stored) - } -} - -// TestBindingSecretDecryptsOnRead pins the other half: what was encrypted -// comes back as the original plaintext. -func TestBindingSecretDecryptsOnRead(t *testing.T) { - cipher, _ := NewBindingCipher(testBindingKey, nil) - s := openWithCipher(t, cipher) - in := sampleBinding() - id := insertBinding(t, s, in) - - got, err := s.GetBinding(t.Context(), id) - if err != nil { - t.Fatalf("GetBinding() error = %v", err) - } - if got.Secret != in.Secret { - t.Errorf("Secret = %q, want %q", got.Secret, in.Secret) - } -} - -// TestNoCipherKeepsPlaintext pins the behaviour that predates encryption: a -// deployment with no configured key still works, storing plaintext. -func TestNoCipherKeepsPlaintext(t *testing.T) { - s := openWithCipher(t, nil) - in := sampleBinding() - id := insertBinding(t, s, in) - - var stored string - if err := s.App().DB().NewQuery("SELECT secret FROM " + CollBindings + " WHERE id = {:id}"). - Bind(map[string]any{"id": id}).Row(&stored); err != nil { - t.Fatalf("read raw secret: %v", err) - } - if stored != in.Secret { - t.Errorf("stored secret = %q, want the plaintext %q with no cipher configured", stored, in.Secret) - } -} - -// TestRotatedKeyStillReadsOldRows pins key rotation: a secret written under -// the previous key must stay readable once a new active key is installed, -// otherwise a rotation silently bricks every armed binding. -func TestRotatedKeyStillReadsOldRows(t *testing.T) { - const oldKey = "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210" - oldCipher, _ := NewBindingCipher(oldKey, nil) - s := openWithCipher(t, oldCipher) - in := sampleBinding() - id := insertBinding(t, s, in) - - rotated, err := NewBindingCipher(testBindingKey, []string{oldKey}) - if err != nil { - t.Fatalf("NewBindingCipher(rotated) error = %v", err) - } - s.cipher = rotated - - got, err := s.GetBinding(t.Context(), id) - if err != nil { - t.Fatalf("GetBinding() after rotation error = %v", err) - } - if got.Secret != in.Secret { - t.Errorf("Secret after rotation = %q, want %q: the previous key must still decrypt", got.Secret, in.Secret) - } -} - // tamperEnvelope flips one byte inside the ciphertext region so Decrypt must // fail authentication rather than return altered plaintext. func tamperEnvelope(t *testing.T, envelope string) string { diff --git a/internal/infrastructure/captureintake/pgtest_test.go b/internal/infrastructure/captureintake/pgtest_test.go new file mode 100644 index 000000000..f3fea01d9 --- /dev/null +++ b/internal/infrastructure/captureintake/pgtest_test.go @@ -0,0 +1,10 @@ +package captureintake + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/infrastructure/captureintake/receiver_test.go b/internal/infrastructure/captureintake/receiver_test.go index 7889ff515..29400ece4 100644 --- a/internal/infrastructure/captureintake/receiver_test.go +++ b/internal/infrastructure/captureintake/receiver_test.go @@ -14,9 +14,10 @@ import ( "time" "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/events" - "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" "github.com/samcharles93/archie-core/internal/webhookguard" ) @@ -39,7 +40,7 @@ type testReceiver struct { *Receiver // store is the event-capture store the receiver writes through, kept so a // test asserts on persisted rows rather than on a mock's recollection. - store *edastore.Store + store *postgres.EDA } // Handler serves the receiver's route the way its host process mounts it, @@ -60,7 +61,7 @@ func captureTestServerWithoutStore(t *testing.T) testReceiver { func captureTestServer(t *testing.T) testReceiver { t.Helper() - s := edastore.OpenTest(t) + s := pgstore.EDA(t, nil) return testReceiver{ Receiver: &Receiver{ Log: slog.New(slog.DiscardHandler), @@ -131,7 +132,7 @@ func (s *stubBindingStore) RecordDispatch( return nil } -func (s *stubBindingStore) ListUndispatchedCaptures(_ context.Context, _ []string, _ int) ([]store.CapturedEvent, error) { +func (s *stubBindingStore) ListUndispatchedCaptures(_ context.Context, _ []string, _ int) ([]storecontract.CapturedEvent, error) { return nil, nil } @@ -420,10 +421,10 @@ func TestHandleCaptureWithoutCapturesConfiguredIs503(t *testing.T) { // captureInsertErrorStore forces InsertCapture to fail so the handler's // error path is exercised without relying on a real storage failure. type captureInsertErrorStore struct { - store.CaptureStore + storecontract.CaptureStore } -func (captureInsertErrorStore) InsertCapture(context.Context, store.CapturedEvent, time.Duration, int) (string, error) { +func (captureInsertErrorStore) InsertCapture(context.Context, storecontract.CapturedEvent, time.Duration, int) (string, error) { return "", errors.New("boom") } diff --git a/internal/infrastructure/gatewayrpc/conformance_test.go b/internal/infrastructure/gatewayrpc/conformance_test.go index 52f749398..4e135ece0 100644 --- a/internal/infrastructure/gatewayrpc/conformance_test.go +++ b/internal/infrastructure/gatewayrpc/conformance_test.go @@ -15,9 +15,9 @@ import ( "google.golang.org/grpc/test/bufconn" "github.com/samcharles93/archie-core/internal/domain/messaging" + "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/domain/taskactions" "github.com/samcharles93/archie-core/internal/gateway" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskstate" ) @@ -213,7 +213,7 @@ func TestTaskActionErrorsKeepTheirSentinelOverGRPC(t *testing.T) { }{ {name: "not found", err: fmt.Errorf("task 7: %w", taskactions.ErrNotFound)}, {name: "conflict", err: fmt.Errorf("%w: action \"approve\" is not available while task is parked", taskactions.ErrConflict)}, - {name: "stale transition", err: fmt.Errorf("stop task 7: %w", store.ErrStaleTransition)}, + {name: "stale transition", err: fmt.Errorf("stop task 7: %w", storecontract.ErrStaleTransition)}, {name: "unavailable", err: taskactions.ErrUnavailable}, } { t.Run(tc.name, func(t *testing.T) { diff --git a/internal/infrastructure/legacyimport/legacyfixture/legacyfixture.go b/internal/infrastructure/legacyimport/legacyfixture/legacyfixture.go new file mode 100644 index 000000000..3425069b1 --- /dev/null +++ b/internal/infrastructure/legacyimport/legacyfixture/legacyfixture.go @@ -0,0 +1,157 @@ +// Package legacyfixture writes the legacy SQLite files an existing install +// holds, for tests of the one-time import and the boot gate that requires it. +package legacyfixture + +import ( + "database/sql" + "path/filepath" + "testing" + + _ "modernc.org/sqlite" +) + +// StateStoreDDL, EDADDL and GatewayDDL apply the legacy schemas as their production openers leave +// them, columns added by ALTER TABLE included, with values in the layouts the +// production writers used. +const StateStoreDDL = ` +CREATE TABLE tasks (id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT NOT NULL, repo TEXT NOT NULL, + issue_number INTEGER NOT NULL, title TEXT DEFAULT '', body TEXT DEFAULT '', labels TEXT DEFAULT '', + status TEXT DEFAULT 'queued', workflow TEXT DEFAULT '', stage TEXT DEFAULT '', branch TEXT DEFAULT '', + plan TEXT DEFAULT '', notes TEXT DEFAULT '', pr_number INTEGER DEFAULT 0, tokens_used INTEGER DEFAULT 0, + iterations INTEGER DEFAULT 0, attempt INTEGER DEFAULT 0, park_reason TEXT DEFAULT '', + watch_comment_id INTEGER DEFAULT 0, park_class TEXT DEFAULT 'needs_human', remediation_rounds INTEGER DEFAULT 0, + retry_count INTEGER DEFAULT 0, source TEXT DEFAULT 'forge', identity TEXT DEFAULT '', binding_id TEXT DEFAULT '', + binding_version INTEGER DEFAULT 0, review_payload TEXT DEFAULT '', workflow_definition_version INTEGER DEFAULT 0, + workflow_definition_digest TEXT DEFAULT '', workflow_definition_yaml TEXT DEFAULT '', + created_at TEXT DEFAULT (datetime('now')), updated_at TEXT DEFAULT (datetime('now'))); +ALTER TABLE tasks ADD COLUMN review_cursor INTEGER NOT NULL DEFAULT 0; +CREATE TABLE transitions (id INTEGER PRIMARY KEY AUTOINCREMENT, task_id INTEGER NOT NULL, + at TEXT DEFAULT (datetime('now')), from_status TEXT NOT NULL, to_status TEXT NOT NULL, detail TEXT DEFAULT ''); +CREATE TABLE events (id INTEGER PRIMARY KEY AUTOINCREMENT, at TEXT NOT NULL, kind TEXT NOT NULL, + task_id INTEGER DEFAULT 0, repo TEXT DEFAULT '', issue INTEGER DEFAULT 0, workflow TEXT DEFAULT '', + stage TEXT DEFAULT '', attempt INTEGER DEFAULT 0, actor_id TEXT DEFAULT '', actor_kind TEXT DEFAULT '', + principal_id TEXT DEFAULT '', detail TEXT DEFAULT '', data TEXT DEFAULT '{}'); +CREATE TABLE resources (kind TEXT PRIMARY KEY, value BLOB NOT NULL, version INTEGER NOT NULL, updated_at TEXT NOT NULL); +CREATE TABLE resource_history (id INTEGER PRIMARY KEY AUTOINCREMENT, kind TEXT NOT NULL, value BLOB NOT NULL, + version INTEGER NOT NULL, actor TEXT NOT NULL, source TEXT NOT NULL, request_id TEXT NOT NULL, + expected_version INTEGER NOT NULL, current_version INTEGER NOT NULL, at TEXT NOT NULL); +CREATE TABLE channel_status (id TEXT PRIMARY KEY, name TEXT DEFAULT '', state TEXT DEFAULT '', detail TEXT DEFAULT '', + configured INTEGER NOT NULL DEFAULT 0, reload_supported INTEGER NOT NULL DEFAULT 0, observed_at TEXT NOT NULL); +CREATE TABLE apply_status (process TEXT NOT NULL, kind TEXT NOT NULL, applied_version INTEGER DEFAULT 0, + error TEXT DEFAULT '', reported_at TEXT NOT NULL, PRIMARY KEY (process, kind)); +CREATE TABLE config_snapshot (id INTEGER PRIMARY KEY CHECK (id = 1), schema TEXT DEFAULT '', document TEXT DEFAULT '', + published_at TEXT NOT NULL); +CREATE TABLE identities (id TEXT PRIMARY KEY, kind TEXT NOT NULL, display_name TEXT NOT NULL, lifecycle TEXT NOT NULL, + version INTEGER NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL); +CREATE TABLE identity_aliases (alias TEXT PRIMARY KEY COLLATE NOCASE, identity_id TEXT NOT NULL REFERENCES identities(id)); +CREATE TABLE identity_events (id INTEGER PRIMARY KEY AUTOINCREMENT, identity_id TEXT NOT NULL, event_type TEXT NOT NULL, + from_lifecycle TEXT NOT NULL, to_lifecycle TEXT NOT NULL, display_name TEXT NOT NULL, actor_id TEXT NOT NULL, + source TEXT NOT NULL, request_id TEXT NOT NULL UNIQUE, at TEXT NOT NULL); +CREATE TABLE identity_subjects (issuer TEXT NOT NULL, subject TEXT NOT NULL, + identity_id TEXT NOT NULL REFERENCES identities(id), bound_at TEXT NOT NULL, PRIMARY KEY (issuer, subject)); + +INSERT INTO tasks (id, owner, repo, issue_number, review_cursor, created_at, updated_at) VALUES + (1, 'o', 'r', 7, 3, '2026-01-01 00:00:00', '2026-01-01 00:00:01'), + (4, 'o', 'r', 1000000000000000, 0, '2026-01-02 00:00:00', '2026-01-02 00:00:00'), + (9, 'o', 'r', 8, 0, '2026-01-02 00:00:00', '2026-01-02 00:00:00'); +DELETE FROM tasks WHERE id = 9; +INSERT INTO transitions (task_id, at, from_status, to_status) VALUES (1, '2026-01-01 00:00:00', 'queued', 'running'); +INSERT INTO events (id, at, kind, data) VALUES + (1, '2026-01-01T00:00:00.000000100Z', 'a', 'null'), + (2, '2026-01-01T00:00:01.000000000Z', 'b', '{"k":1}'), + (5, '2026-01-01T00:00:00.500000000Z', 'c', '{}'); +INSERT INTO resources VALUES ('config', X'00ff10', 2, '2026-01-01T00:00:00.123456789Z'); +INSERT INTO resource_history (kind, value, version, actor, source, request_id, expected_version, current_version, at) + VALUES ('config', X'00ff10', 2, 'sam', 'ui', 'req-1', 1, 1, '2026-01-01T00:00:00Z'); +INSERT INTO channel_status VALUES ('tg', 'Telegram', 'up', '', 1, 0, '2026-01-01T00:00:00Z'); +INSERT INTO apply_status VALUES ('daemon', 'config', 2, '', '2026-01-01T00:00:00Z'); +INSERT INTO config_snapshot VALUES (1, 's', '{}', '2026-01-01T00:00:00Z'); +INSERT INTO identities VALUES ('id-1', 'agent', 'Archie', 'active', 1, '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z'); +INSERT INTO identity_aliases VALUES ('archie', 'id-1'); +INSERT INTO identity_events (identity_id, event_type, from_lifecycle, to_lifecycle, display_name, actor_id, source, request_id, at) + VALUES ('id-1', 'created', '', 'active', 'Archie', 'sam', 'boot', 'rq-1', '2026-01-01T00:00:00Z'); +INSERT INTO identity_subjects VALUES ('https://issuer', 'sub-1', 'id-1', '2026-01-01T00:00:00Z'); +` + +// Secret is an encrypted binding secret envelope; it must arrive unchanged. +const Secret = "arcie-binding:v1:0123456789abcdef:AbC-_dEf012" + +const EDADDL = ` +CREATE TABLE captures (id TEXT PRIMARY KEY NOT NULL, authenticated BOOLEAN DEFAULT FALSE NOT NULL, + body TEXT DEFAULT '' NOT NULL, content_type TEXT DEFAULT '' NOT NULL, headers JSON DEFAULT NULL, + received_at TEXT DEFAULT '' NOT NULL, remote_addr TEXT DEFAULT '' NOT NULL, source TEXT DEFAULT '' NOT NULL); +CREATE TABLE mappings (id TEXT PRIMARY KEY NOT NULL, created_at TEXT DEFAULT '' NOT NULL, fields JSON DEFAULT NULL, + name TEXT DEFAULT '' NOT NULL, source_hint TEXT DEFAULT '' NOT NULL, updated_at TEXT DEFAULT '' NOT NULL); +CREATE TABLE bindings (id TEXT PRIMARY KEY NOT NULL, created_at TEXT DEFAULT '' NOT NULL, mapping TEXT DEFAULT '' NOT NULL, + name TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL, repo TEXT DEFAULT '' NOT NULL, + secret TEXT DEFAULT '' NOT NULL, source TEXT DEFAULT '' NOT NULL, status TEXT DEFAULT '' NOT NULL, + updated_at TEXT DEFAULT '' NOT NULL, version NUMERIC DEFAULT 0 NOT NULL, workflow TEXT DEFAULT '' NOT NULL); +CREATE TABLE binding_dispatches (id TEXT PRIMARY KEY NOT NULL, binding TEXT DEFAULT '' NOT NULL, + binding_version NUMERIC DEFAULT 0 NOT NULL, capture TEXT DEFAULT '' NOT NULL, dispatched_at TEXT DEFAULT '' NOT NULL, + task_id NUMERIC DEFAULT 0 NOT NULL); +CREATE UNIQUE INDEX idx_binding_dispatch_once ON binding_dispatches (binding, capture); +CREATE TABLE playbook_dispatches (id TEXT PRIMARY KEY NOT NULL, action_id TEXT DEFAULT '' NOT NULL, + dispatched_at TEXT DEFAULT '' NOT NULL, event_id TEXT DEFAULT '' NOT NULL, playbook_id TEXT DEFAULT '' NOT NULL, + playbook_version TEXT DEFAULT '' NOT NULL); +CREATE TABLE tool_calls (id TEXT PRIMARY KEY NOT NULL, args JSON DEFAULT NULL, attempt NUMERIC DEFAULT 0 NOT NULL, + called_at TEXT DEFAULT '' NOT NULL, duration_ms NUMERIC DEFAULT 0 NOT NULL, error TEXT DEFAULT '' NOT NULL, + result JSON DEFAULT NULL, task_id NUMERIC DEFAULT 0 NOT NULL, tool TEXT DEFAULT '' NOT NULL); + +INSERT INTO captures VALUES ('rcap1', 1, '{}', 'application/json', '{"x":["1"]}', '2026-01-01T00:00:00.000000000Z', '127.0.0.1', 'gh'); +INSERT INTO captures VALUES ('rcap2', 0, '', '', NULL, '2026-01-01T00:00:01.000000000Z', '', 'gh'); +INSERT INTO mappings VALUES ('rmap1', '2026-01-01 00:00:00.000Z', '[]', 'm', 'gh', '2026-01-01 00:00:00.000Z'); +INSERT INTO bindings VALUES ('rbind1', '2026-01-01 00:00:00.000Z', 'rmap1', 'b', 'o', 'r', '` + Secret + `', 'gh', 'armed', '2026-01-01 00:00:00.000Z', 1, 'implement'); +INSERT INTO binding_dispatches VALUES ('rdisp1', 'rbind1', 1, 'rcap1', '2026-01-01 00:00:00.000Z', 4); +INSERT INTO playbook_dispatches VALUES ('rpb1', 'act', '2026-01-01 00:00:00.000Z', 'ev', 'pb', 'v1'); +INSERT INTO tool_calls VALUES ('rtool1', NULL, 1, '2026-01-01 00:00:00.000Z', 12, '', '"exit 0"', 4, 'bash'); +` + +const GatewayDDL = ` +CREATE TABLE sessions (session_id TEXT PRIMARY KEY, platform TEXT NOT NULL DEFAULT '', bot_user TEXT NOT NULL DEFAULT '', + channel_id TEXT NOT NULL DEFAULT '', thread_id TEXT NOT NULL DEFAULT '', title TEXT NOT NULL DEFAULT '', + parent_session_id TEXT NOT NULL DEFAULT '', branch_name TEXT NOT NULL DEFAULT '', + created_at INTEGER NOT NULL DEFAULT 0, last_active_at INTEGER NOT NULL DEFAULT 0); +CREATE TABLE messages (id INTEGER PRIMARY KEY AUTOINCREMENT, message_id TEXT NOT NULL, session_id TEXT NOT NULL, + source_id TEXT NOT NULL DEFAULT '', sender TEXT NOT NULL DEFAULT '', text TEXT NOT NULL DEFAULT '', ts INTEGER NOT NULL, + UNIQUE(session_id, message_id)); +ALTER TABLE messages ADD COLUMN role TEXT NOT NULL DEFAULT ''; +ALTER TABLE messages ADD COLUMN sender_id TEXT NOT NULL DEFAULT ''; +CREATE VIRTUAL TABLE messages_fts USING fts5(sender, text, content='messages', content_rowid='id'); +CREATE TRIGGER messages_ai AFTER INSERT ON messages BEGIN + INSERT INTO messages_fts(rowid, sender, text) VALUES (new.id, new.sender, new.text); +END; +CREATE TABLE turns (turn_id TEXT PRIMARY KEY, session_id TEXT NOT NULL, source_id TEXT NOT NULL DEFAULT '', + status TEXT NOT NULL, attempt INTEGER NOT NULL DEFAULT 0, owner_id TEXT NOT NULL DEFAULT '', + input_message_id TEXT NOT NULL DEFAULT '', assistant_message_id TEXT NOT NULL DEFAULT '', + partial_text TEXT NOT NULL DEFAULT '', response_text TEXT NOT NULL DEFAULT '', tool_calls TEXT NOT NULL DEFAULT '[]', + error TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL); + +INSERT INTO sessions VALUES ('s1', 'telegram', 'bot', 'c1', '', 'Chat', '', '', 1000, 2000); +INSERT INTO messages (message_id, session_id, sender, text, ts, role) VALUES ('m1', 's1', 'sam', 'hello there', 1000, 'user'); +INSERT INTO messages (message_id, session_id, sender, text, ts, role) VALUES ('m2', 's1', 'archie', 'hi', 1001, 'assistant'); +INSERT INTO turns VALUES ('t1', 's1', '', 'done', 1, '', 'm1', 'm2', '', 'hi', '[]', '', 1000, 1001); +` + +// Install writes the three legacy files the configured db_path names in dir +// and returns their paths. +func Install(t testing.TB, dbPath string) (stateStore, eda, gateway string) { + t.Helper() + stateStore, eda, gateway = dbPath+"-tasks.sqlite", dbPath+"-eda.sqlite", dbPath+"-conversations.sqlite" + Exec(t, stateStore, StateStoreDDL) + Exec(t, eda, EDADDL) + Exec(t, gateway, GatewayDDL) + return stateStore, eda, gateway +} + +// Exec runs stmt against the SQLite file at path, creating it if absent. +func Exec(t testing.TB, path, stmt string) { + t.Helper() + db, err := sql.Open("sqlite", "file:"+path) + if err != nil { + t.Fatalf("open fixture: %v", err) + } + defer func() { _ = db.Close() }() + if _, err := db.ExecContext(t.Context(), stmt); err != nil { + t.Fatalf("fixture %s: %v", filepath.Base(path), err) + } +} diff --git a/internal/infrastructure/legacyimport/legacyimport_test.go b/internal/infrastructure/legacyimport/legacyimport_test.go index 0c07fb6cc..843a39286 100644 --- a/internal/infrastructure/legacyimport/legacyimport_test.go +++ b/internal/infrastructure/legacyimport/legacyimport_test.go @@ -3,7 +3,6 @@ package legacyimport import ( "bytes" "crypto/sha256" - "database/sql" "errors" "os" "path/filepath" @@ -11,175 +10,34 @@ import ( "testing" "github.com/jackc/pgx/v5/pgxpool" - _ "modernc.org/sqlite" + "github.com/samcharles93/archie-core/internal/infrastructure/legacyimport/legacyfixture" "github.com/samcharles93/archie-core/internal/infrastructure/postgres" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" ) func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } -// The fixtures apply the legacy schemas as their production openers leave -// them, columns added by ALTER TABLE included, with values in the layouts the -// production writers used. -const stateStoreDDL = ` -CREATE TABLE tasks (id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT NOT NULL, repo TEXT NOT NULL, - issue_number INTEGER NOT NULL, title TEXT DEFAULT '', body TEXT DEFAULT '', labels TEXT DEFAULT '', - status TEXT DEFAULT 'queued', workflow TEXT DEFAULT '', stage TEXT DEFAULT '', branch TEXT DEFAULT '', - plan TEXT DEFAULT '', notes TEXT DEFAULT '', pr_number INTEGER DEFAULT 0, tokens_used INTEGER DEFAULT 0, - iterations INTEGER DEFAULT 0, attempt INTEGER DEFAULT 0, park_reason TEXT DEFAULT '', - watch_comment_id INTEGER DEFAULT 0, park_class TEXT DEFAULT 'needs_human', remediation_rounds INTEGER DEFAULT 0, - retry_count INTEGER DEFAULT 0, source TEXT DEFAULT 'forge', identity TEXT DEFAULT '', binding_id TEXT DEFAULT '', - binding_version INTEGER DEFAULT 0, review_payload TEXT DEFAULT '', workflow_definition_version INTEGER DEFAULT 0, - workflow_definition_digest TEXT DEFAULT '', workflow_definition_yaml TEXT DEFAULT '', - created_at TEXT DEFAULT (datetime('now')), updated_at TEXT DEFAULT (datetime('now'))); -ALTER TABLE tasks ADD COLUMN review_cursor INTEGER NOT NULL DEFAULT 0; -CREATE TABLE transitions (id INTEGER PRIMARY KEY AUTOINCREMENT, task_id INTEGER NOT NULL, - at TEXT DEFAULT (datetime('now')), from_status TEXT NOT NULL, to_status TEXT NOT NULL, detail TEXT DEFAULT ''); -CREATE TABLE events (id INTEGER PRIMARY KEY AUTOINCREMENT, at TEXT NOT NULL, kind TEXT NOT NULL, - task_id INTEGER DEFAULT 0, repo TEXT DEFAULT '', issue INTEGER DEFAULT 0, workflow TEXT DEFAULT '', - stage TEXT DEFAULT '', attempt INTEGER DEFAULT 0, actor_id TEXT DEFAULT '', actor_kind TEXT DEFAULT '', - principal_id TEXT DEFAULT '', detail TEXT DEFAULT '', data TEXT DEFAULT '{}'); -CREATE TABLE resources (kind TEXT PRIMARY KEY, value BLOB NOT NULL, version INTEGER NOT NULL, updated_at TEXT NOT NULL); -CREATE TABLE resource_history (id INTEGER PRIMARY KEY AUTOINCREMENT, kind TEXT NOT NULL, value BLOB NOT NULL, - version INTEGER NOT NULL, actor TEXT NOT NULL, source TEXT NOT NULL, request_id TEXT NOT NULL, - expected_version INTEGER NOT NULL, current_version INTEGER NOT NULL, at TEXT NOT NULL); -CREATE TABLE channel_status (id TEXT PRIMARY KEY, name TEXT DEFAULT '', state TEXT DEFAULT '', detail TEXT DEFAULT '', - configured INTEGER NOT NULL DEFAULT 0, reload_supported INTEGER NOT NULL DEFAULT 0, observed_at TEXT NOT NULL); -CREATE TABLE apply_status (process TEXT NOT NULL, kind TEXT NOT NULL, applied_version INTEGER DEFAULT 0, - error TEXT DEFAULT '', reported_at TEXT NOT NULL, PRIMARY KEY (process, kind)); -CREATE TABLE config_snapshot (id INTEGER PRIMARY KEY CHECK (id = 1), schema TEXT DEFAULT '', document TEXT DEFAULT '', - published_at TEXT NOT NULL); -CREATE TABLE identities (id TEXT PRIMARY KEY, kind TEXT NOT NULL, display_name TEXT NOT NULL, lifecycle TEXT NOT NULL, - version INTEGER NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL); -CREATE TABLE identity_aliases (alias TEXT PRIMARY KEY COLLATE NOCASE, identity_id TEXT NOT NULL REFERENCES identities(id)); -CREATE TABLE identity_events (id INTEGER PRIMARY KEY AUTOINCREMENT, identity_id TEXT NOT NULL, event_type TEXT NOT NULL, - from_lifecycle TEXT NOT NULL, to_lifecycle TEXT NOT NULL, display_name TEXT NOT NULL, actor_id TEXT NOT NULL, - source TEXT NOT NULL, request_id TEXT NOT NULL UNIQUE, at TEXT NOT NULL); -CREATE TABLE identity_subjects (issuer TEXT NOT NULL, subject TEXT NOT NULL, - identity_id TEXT NOT NULL REFERENCES identities(id), bound_at TEXT NOT NULL, PRIMARY KEY (issuer, subject)); - -INSERT INTO tasks (id, owner, repo, issue_number, review_cursor, created_at, updated_at) VALUES - (1, 'o', 'r', 7, 3, '2026-01-01 00:00:00', '2026-01-01 00:00:01'), - (4, 'o', 'r', 1000000000000000, 0, '2026-01-02 00:00:00', '2026-01-02 00:00:00'), - (9, 'o', 'r', 8, 0, '2026-01-02 00:00:00', '2026-01-02 00:00:00'); -DELETE FROM tasks WHERE id = 9; -INSERT INTO transitions (task_id, at, from_status, to_status) VALUES (1, '2026-01-01 00:00:00', 'queued', 'running'); -INSERT INTO events (id, at, kind, data) VALUES - (1, '2026-01-01T00:00:00.000000100Z', 'a', 'null'), - (2, '2026-01-01T00:00:01.000000000Z', 'b', '{"k":1}'), - (5, '2026-01-01T00:00:00.500000000Z', 'c', '{}'); -INSERT INTO resources VALUES ('config', X'00ff10', 2, '2026-01-01T00:00:00.123456789Z'); -INSERT INTO resource_history (kind, value, version, actor, source, request_id, expected_version, current_version, at) - VALUES ('config', X'00ff10', 2, 'sam', 'ui', 'req-1', 1, 1, '2026-01-01T00:00:00Z'); -INSERT INTO channel_status VALUES ('tg', 'Telegram', 'up', '', 1, 0, '2026-01-01T00:00:00Z'); -INSERT INTO apply_status VALUES ('daemon', 'config', 2, '', '2026-01-01T00:00:00Z'); -INSERT INTO config_snapshot VALUES (1, 's', '{}', '2026-01-01T00:00:00Z'); -INSERT INTO identities VALUES ('id-1', 'agent', 'Archie', 'active', 1, '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z'); -INSERT INTO identity_aliases VALUES ('archie', 'id-1'); -INSERT INTO identity_events (identity_id, event_type, from_lifecycle, to_lifecycle, display_name, actor_id, source, request_id, at) - VALUES ('id-1', 'created', '', 'active', 'Archie', 'sam', 'boot', 'rq-1', '2026-01-01T00:00:00Z'); -INSERT INTO identity_subjects VALUES ('https://issuer', 'sub-1', 'id-1', '2026-01-01T00:00:00Z'); -` - -// secret is an encrypted binding secret envelope; it must arrive unchanged. -const secret = "arcie-binding:v1:0123456789abcdef:AbC-_dEf012" - -const edaDDL = ` -CREATE TABLE captures (id TEXT PRIMARY KEY NOT NULL, authenticated BOOLEAN DEFAULT FALSE NOT NULL, - body TEXT DEFAULT '' NOT NULL, content_type TEXT DEFAULT '' NOT NULL, headers JSON DEFAULT NULL, - received_at TEXT DEFAULT '' NOT NULL, remote_addr TEXT DEFAULT '' NOT NULL, source TEXT DEFAULT '' NOT NULL); -CREATE TABLE mappings (id TEXT PRIMARY KEY NOT NULL, created_at TEXT DEFAULT '' NOT NULL, fields JSON DEFAULT NULL, - name TEXT DEFAULT '' NOT NULL, source_hint TEXT DEFAULT '' NOT NULL, updated_at TEXT DEFAULT '' NOT NULL); -CREATE TABLE bindings (id TEXT PRIMARY KEY NOT NULL, created_at TEXT DEFAULT '' NOT NULL, mapping TEXT DEFAULT '' NOT NULL, - name TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL, repo TEXT DEFAULT '' NOT NULL, - secret TEXT DEFAULT '' NOT NULL, source TEXT DEFAULT '' NOT NULL, status TEXT DEFAULT '' NOT NULL, - updated_at TEXT DEFAULT '' NOT NULL, version NUMERIC DEFAULT 0 NOT NULL, workflow TEXT DEFAULT '' NOT NULL); -CREATE TABLE binding_dispatches (id TEXT PRIMARY KEY NOT NULL, binding TEXT DEFAULT '' NOT NULL, - binding_version NUMERIC DEFAULT 0 NOT NULL, capture TEXT DEFAULT '' NOT NULL, dispatched_at TEXT DEFAULT '' NOT NULL, - task_id NUMERIC DEFAULT 0 NOT NULL); -CREATE UNIQUE INDEX idx_binding_dispatch_once ON binding_dispatches (binding, capture); -CREATE TABLE playbook_dispatches (id TEXT PRIMARY KEY NOT NULL, action_id TEXT DEFAULT '' NOT NULL, - dispatched_at TEXT DEFAULT '' NOT NULL, event_id TEXT DEFAULT '' NOT NULL, playbook_id TEXT DEFAULT '' NOT NULL, - playbook_version TEXT DEFAULT '' NOT NULL); -CREATE TABLE tool_calls (id TEXT PRIMARY KEY NOT NULL, args JSON DEFAULT NULL, attempt NUMERIC DEFAULT 0 NOT NULL, - called_at TEXT DEFAULT '' NOT NULL, duration_ms NUMERIC DEFAULT 0 NOT NULL, error TEXT DEFAULT '' NOT NULL, - result JSON DEFAULT NULL, task_id NUMERIC DEFAULT 0 NOT NULL, tool TEXT DEFAULT '' NOT NULL); - -INSERT INTO captures VALUES ('rcap1', 1, '{}', 'application/json', '{"x":["1"]}', '2026-01-01T00:00:00.000000000Z', '127.0.0.1', 'gh'); -INSERT INTO captures VALUES ('rcap2', 0, '', '', NULL, '2026-01-01T00:00:01.000000000Z', '', 'gh'); -INSERT INTO mappings VALUES ('rmap1', '2026-01-01 00:00:00.000Z', '[]', 'm', 'gh', '2026-01-01 00:00:00.000Z'); -INSERT INTO bindings VALUES ('rbind1', '2026-01-01 00:00:00.000Z', 'rmap1', 'b', 'o', 'r', '` + secret + `', 'gh', 'armed', '2026-01-01 00:00:00.000Z', 1, 'implement'); -INSERT INTO binding_dispatches VALUES ('rdisp1', 'rbind1', 1, 'rcap1', '2026-01-01 00:00:00.000Z', 4); -INSERT INTO playbook_dispatches VALUES ('rpb1', 'act', '2026-01-01 00:00:00.000Z', 'ev', 'pb', 'v1'); -INSERT INTO tool_calls VALUES ('rtool1', NULL, 1, '2026-01-01 00:00:00.000Z', 12, '', '"exit 0"', 4, 'bash'); -` - -const gatewayDDL = ` -CREATE TABLE sessions (session_id TEXT PRIMARY KEY, platform TEXT NOT NULL DEFAULT '', bot_user TEXT NOT NULL DEFAULT '', - channel_id TEXT NOT NULL DEFAULT '', thread_id TEXT NOT NULL DEFAULT '', title TEXT NOT NULL DEFAULT '', - parent_session_id TEXT NOT NULL DEFAULT '', branch_name TEXT NOT NULL DEFAULT '', - created_at INTEGER NOT NULL DEFAULT 0, last_active_at INTEGER NOT NULL DEFAULT 0); -CREATE TABLE messages (id INTEGER PRIMARY KEY AUTOINCREMENT, message_id TEXT NOT NULL, session_id TEXT NOT NULL, - source_id TEXT NOT NULL DEFAULT '', sender TEXT NOT NULL DEFAULT '', text TEXT NOT NULL DEFAULT '', ts INTEGER NOT NULL, - UNIQUE(session_id, message_id)); -ALTER TABLE messages ADD COLUMN role TEXT NOT NULL DEFAULT ''; -ALTER TABLE messages ADD COLUMN sender_id TEXT NOT NULL DEFAULT ''; -CREATE VIRTUAL TABLE messages_fts USING fts5(sender, text, content='messages', content_rowid='id'); -CREATE TRIGGER messages_ai AFTER INSERT ON messages BEGIN - INSERT INTO messages_fts(rowid, sender, text) VALUES (new.id, new.sender, new.text); -END; -CREATE TABLE turns (turn_id TEXT PRIMARY KEY, session_id TEXT NOT NULL, source_id TEXT NOT NULL DEFAULT '', - status TEXT NOT NULL, attempt INTEGER NOT NULL DEFAULT 0, owner_id TEXT NOT NULL DEFAULT '', - input_message_id TEXT NOT NULL DEFAULT '', assistant_message_id TEXT NOT NULL DEFAULT '', - partial_text TEXT NOT NULL DEFAULT '', response_text TEXT NOT NULL DEFAULT '', tool_calls TEXT NOT NULL DEFAULT '[]', - error TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL); - -INSERT INTO sessions VALUES ('s1', 'telegram', 'bot', 'c1', '', 'Chat', '', '', 1000, 2000); -INSERT INTO messages (message_id, session_id, sender, text, ts, role) VALUES ('m1', 's1', 'sam', 'hello there', 1000, 'user'); -INSERT INTO messages (message_id, session_id, sender, text, ts, role) VALUES ('m2', 's1', 'archie', 'hi', 1001, 'assistant'); -INSERT INTO turns VALUES ('t1', 's1', '', 'done', 1, '', 'm1', 'm2', '', 'hi', '[]', '', 1000, 1001); -` - // install writes the three legacy files the way an existing install holds // them and returns their paths. mutate runs extra statements against a file // before the import sees it. func install(t *testing.T, mutate map[string]string) Sources { t.Helper() - dir := t.TempDir() - src := Sources{ - StateStore: filepath.Join(dir, "archie.db-tasks.sqlite"), - EDA: filepath.Join(dir, "archie.db-eda.sqlite"), - Gateway: filepath.Join(dir, "archie.db-conversations.sqlite"), - } - for path, ddl := range map[string]string{src.StateStore: stateStoreDDL, src.EDA: edaDDL, src.Gateway: gatewayDDL} { - sqliteExec(t, path, ddl) - } + var src Sources + src.StateStore, src.EDA, src.Gateway = legacyfixture.Install(t, filepath.Join(t.TempDir(), "archie.db")) for path, stmt := range mutate { switch path { case "state": - sqliteExec(t, src.StateStore, stmt) + legacyfixture.Exec(t, src.StateStore, stmt) case "eda": - sqliteExec(t, src.EDA, stmt) + legacyfixture.Exec(t, src.EDA, stmt) case "gateway": - sqliteExec(t, src.Gateway, stmt) + legacyfixture.Exec(t, src.Gateway, stmt) } } return src } -func sqliteExec(t *testing.T, path, stmt string) { - t.Helper() - db, err := sql.Open("sqlite", "file:"+path) - if err != nil { - t.Fatalf("open fixture: %v", err) - } - defer func() { _ = db.Close() }() - if _, err := db.ExecContext(t.Context(), stmt); err != nil { - t.Fatalf("fixture %s: %v", filepath.Base(path), err) - } -} - func hashFiles(t *testing.T, dir string) map[string][32]byte { t.Helper() entries, err := os.ReadDir(dir) @@ -297,8 +155,8 @@ func TestImportCopiesEverySourceAndLeavesThemUntouched(t *testing.T) { if !bytes.Equal(value, []byte{0x00, 0xff, 0x10}) { t.Errorf("resource_history.value = %x, want 00ff10", value) } - if gotSecret != secret { - t.Errorf("binding secret = %q, want %q", gotSecret, secret) + if gotSecret != legacyfixture.Secret { + t.Errorf("binding secret = %q, want %q", gotSecret, legacyfixture.Secret) } if headers != "" || result != "exit 0" || !configured { t.Errorf("headers %q, result %q, configured %v; want \"\", \"exit 0\", true", headers, result, configured) diff --git a/internal/infrastructure/postgres/edastore.go b/internal/infrastructure/postgres/edastore.go index 9c7cb2481..e1389a930 100644 --- a/internal/infrastructure/postgres/edastore.go +++ b/internal/infrastructure/postgres/edastore.go @@ -1,8 +1,7 @@ // Package postgres opens archie's PostgreSQL database and applies its schema // migrations. This file is the PostgreSQL implementation of the EDA // persistence contracts (captures, mappings, bindings and the two dispatch -// ledgers) plus the tool_calls transcript, mirroring the PocketBase-backed -// internal/infrastructure/edastore.Store it will replace in the cutover wave. +// ledgers) plus the tool_calls transcript. package postgres import ( @@ -20,14 +19,12 @@ import ( "github.com/samcharles93/archie-core/internal/domain/mapping" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb" ) // EDA is the PostgreSQL implementation of every event-capture contract, plus -// the tool_calls transcript the composition projection writes through. It -// satisfies the same surface as *edastore.Store, so the cutover wave can swap -// one for the other behind storecontract without touching the consumers. +// the tool_calls transcript the composition projection writes through. var ( _ storecontract.CaptureStore = (*EDA)(nil) _ storecontract.MappingStore = (*EDA)(nil) @@ -40,26 +37,23 @@ var ( type EDA struct { pool *pgxpool.Pool q *postgresdb.Queries - cipher edastore.BindingCipher + cipher bindingcipher.BindingCipher notify func(events.Event) } // NewEDA builds an EDA store over pool. A nil cipher keeps binding secrets in -// plaintext (the behaviour that predates the option); the caller resolves the -// keyring through edastore.NewBindingCipher, exactly as the PocketBase store -// does. The pool is owned by the caller, not this store. -func NewEDA(pool *pgxpool.Pool, cipher edastore.BindingCipher) *EDA { +// plaintext; the caller resolves the keyring through +// bindingcipher.NewBindingCipher. The pool is owned by the caller, not this store. +func NewEDA(pool *pgxpool.Pool, cipher bindingcipher.BindingCipher) *EDA { return &EDA{pool: pool, q: postgresdb.New(pool), cipher: cipher} } -// SetNotify wires the change-event callback that the PocketBase store's -// Config.Notify provides. It is the same injection point: nil is a silent -// no-op, which is what every production construction gets today. +// SetNotify wires the change-event callback. nil is a silent no-op, which is +// what every production construction gets today. func (s *EDA) SetNotify(fn func(events.Event)) { s.notify = fn } // notifyWrite announces one successful write on the bindings or mappings -// tables. It mirrors edastore.(*Store).notifyWrite byte-for-byte: the data -// carries the record id and action, and consumers refetch the row themselves. +// tables. The data carries the record id and action, and consumers refetch the row themselves. func (s *EDA) notifyWrite(kind, subject, action, id string) { if s.notify == nil { return @@ -77,8 +71,7 @@ func newRecordID() string { return uuid.NewString() } // --- captures --- // InsertCapture stores one inbound event verbatim. retention and maxEvents are -// accepted for contract compatibility and applied as a prune after the insert, -// exactly as the PocketBase store does. +// applied as a prune after the insert. func (s *EDA) InsertCapture(ctx context.Context, c storecontract.CapturedEvent, retention time.Duration, maxEvents int) (string, error) { received := c.ReceivedAt if received.IsZero() { @@ -208,8 +201,8 @@ func (s *EDA) InsertMapping(ctx context.Context, m mapping.Mapping) (string, err return id, nil } -// GetMapping returns (nil, nil) for an absent mapping, matching the -// PocketBase store's found=false convention the gRPC layer translates. +// GetMapping returns (nil, nil) for an absent mapping, the found=false +// convention the gRPC layer translates. func (s *EDA) GetMapping(ctx context.Context, id string) (*mapping.Mapping, error) { r, err := s.q.GetMapping(ctx, id) if errors.Is(err, pgx.ErrNoRows) { @@ -347,8 +340,8 @@ func (s *EDA) InsertBinding(ctx context.Context, b binding.Binding) (string, err return id, nil } -// GetBinding returns (nil, nil) for an absent binding, matching the -// PocketBase store's found=false convention the gRPC layer translates. +// GetBinding returns (nil, nil) for an absent binding, the found=false +// convention the gRPC layer translates. func (s *EDA) GetBinding(ctx context.Context, id string) (*binding.Binding, error) { r, err := s.q.GetBinding(ctx, id) if errors.Is(err, pgx.ErrNoRows) { @@ -522,8 +515,21 @@ func ledgerWrite(err error, what string) error { // --- tool calls --- +// ToolCall is one completed tool invocation during an agent stage run, as the +// tool_call event projection stores it: a tool's output summary in Result, a +// failure's detail in Error. +type ToolCall struct { + ID string + TaskID int64 + Attempt int + Tool string + Result string + Error string + CalledAt time.Time +} + // InsertToolCall appends one row to the tool_calls transcript. -func (s *EDA) InsertToolCall(ctx context.Context, tc edastore.ToolCall) error { +func (s *EDA) InsertToolCall(ctx context.Context, tc ToolCall) error { calledAt := tc.CalledAt if calledAt.IsZero() { calledAt = time.Now() @@ -543,14 +549,14 @@ func (s *EDA) InsertToolCall(ctx context.Context, tc edastore.ToolCall) error { } // TaskToolCalls returns one task's tool calls in call order. -func (s *EDA) TaskToolCalls(ctx context.Context, taskID int64) ([]edastore.ToolCall, error) { +func (s *EDA) TaskToolCalls(ctx context.Context, taskID int64) ([]ToolCall, error) { rows, err := s.q.TaskToolCalls(ctx, taskID) if err != nil { return nil, fmt.Errorf("edastore: list tool calls: %w", err) } - out := make([]edastore.ToolCall, 0, len(rows)) + out := make([]ToolCall, 0, len(rows)) for _, r := range rows { - out = append(out, edastore.ToolCall{ + out = append(out, ToolCall{ ID: r.ID, TaskID: r.TaskID, Attempt: int(r.Attempt), diff --git a/internal/infrastructure/postgres/edastore_test.go b/internal/infrastructure/postgres/edastore_test.go index 71a934b14..87f8de9ab 100644 --- a/internal/infrastructure/postgres/edastore_test.go +++ b/internal/infrastructure/postgres/edastore_test.go @@ -12,7 +12,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/mapping" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" + "github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher" ) const edaTestKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" @@ -24,7 +24,7 @@ func edaFor(t *testing.T) *EDA { return NewEDA(pool, nil) } -func edaWithCipher(t *testing.T, cipher edastore.BindingCipher) (*pgxpool.Pool, *EDA) { +func edaWithCipher(t *testing.T, cipher bindingcipher.BindingCipher) (*pgxpool.Pool, *EDA) { t.Helper() pool, _ := migrated(t) return pool, NewEDA(pool, cipher) @@ -131,7 +131,7 @@ func TestConcurrentInsertBindingSameSource(t *testing.T) { // untouched, so an edit form that does not echo the secret cannot blank an // armed binding's HMAC key. func TestUpdateBindingEmptySecretPreservesStored(t *testing.T) { - cipher, err := edastore.NewBindingCipher(edaTestKey, nil) + cipher, err := bindingcipher.NewBindingCipher(edaTestKey, nil) if err != nil { t.Fatalf("NewBindingCipher() error = %v", err) } @@ -173,7 +173,7 @@ func readRawSecret(t *testing.T, pool *pgxpool.Pool, id string) string { // The cipher path must keep decrypt-in-store: what is stored is an envelope, // what reads back is the plaintext HMAC key the intake verifies with. func TestBindingSecretEncryptedAtRestAndDecryptedOnRead(t *testing.T) { - cipher, err := edastore.NewBindingCipher(edaTestKey, nil) + cipher, err := bindingcipher.NewBindingCipher(edaTestKey, nil) if err != nil { t.Fatalf("NewBindingCipher() error = %v", err) } @@ -200,6 +200,50 @@ func TestBindingSecretEncryptedAtRestAndDecryptedOnRead(t *testing.T) { } } +// A deployment with no configured key stores plaintext. +func TestNoCipherKeepsPlaintext(t *testing.T) { + pool, s := edaWithCipher(t, nil) + id, err := s.InsertBinding(t.Context(), binding.Binding{ + Name: "n", Matcher: binding.Matcher{Source: "src-plain"}, Workflow: "implement", + Secret: "supersecretvalue0123", + }) + if err != nil { + t.Fatalf("InsertBinding() error = %v", err) + } + if stored := readRawSecret(t, pool, id); stored != "supersecretvalue0123" { + t.Errorf("stored secret = %q, want the plaintext with no cipher configured", stored) + } +} + +// A secret written under the previous key stays readable once a new active +// key is installed; otherwise rotation bricks every armed binding. +func TestRotatedKeyStillReadsOldRows(t *testing.T) { + const oldKey = "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210" + oldCipher, err := bindingcipher.NewBindingCipher(oldKey, nil) + if err != nil { + t.Fatalf("NewBindingCipher(old) error = %v", err) + } + pool, s := edaWithCipher(t, oldCipher) + id, err := s.InsertBinding(t.Context(), binding.Binding{ + Name: "n", Matcher: binding.Matcher{Source: "src-rotate"}, Workflow: "implement", + Secret: "supersecretvalue0123", + }) + if err != nil { + t.Fatalf("InsertBinding() error = %v", err) + } + rotated, err := bindingcipher.NewBindingCipher(edaTestKey, []string{oldKey}) + if err != nil { + t.Fatalf("NewBindingCipher(rotated) error = %v", err) + } + got, err := NewEDA(pool, rotated).GetBinding(t.Context(), id) + if err != nil { + t.Fatalf("GetBinding() after rotation error = %v", err) + } + if got.Secret != "supersecretvalue0123" { + t.Errorf("Secret after rotation = %q: the previous key must still decrypt", got.Secret) + } +} + // The lifecycle gate survives the port: pending_approval -> armed, and only // from pending_approval. func TestBindingLifecycle(t *testing.T) { @@ -308,13 +352,13 @@ func TestToolCallRoundTrip(t *testing.T) { at := time.Date(2026, 9, 23, 1, 2, 3, 0, time.UTC) for range 2 { - if err := s.InsertToolCall(t.Context(), edastore.ToolCall{ + if err := s.InsertToolCall(t.Context(), ToolCall{ TaskID: 42, Attempt: 2, Tool: "shell", Result: "all checks passed", CalledAt: at, }); err != nil { t.Fatalf("InsertToolCall() error = %v", err) } } - if err := s.InsertToolCall(t.Context(), edastore.ToolCall{ + if err := s.InsertToolCall(t.Context(), ToolCall{ TaskID: 7, Attempt: 1, Tool: "read_file", Error: "no such file", CalledAt: at.Add(time.Second), }); err != nil { t.Fatalf("InsertToolCall(other task) error = %v", err) diff --git a/internal/infrastructure/postgres/pgstore/pgstore.go b/internal/infrastructure/postgres/pgstore/pgstore.go new file mode 100644 index 000000000..12ef3aa53 --- /dev/null +++ b/internal/infrastructure/postgres/pgstore/pgstore.go @@ -0,0 +1,61 @@ +// Package pgstore opens migrated PostgreSQL stores on a throwaway pgtest +// database, for tests outside internal/infrastructure/postgres. A package +// using it calls pgtest.Main from TestMain. +package pgstore + +import ( + "testing" + + "github.com/jackc/pgx/v5/pgxpool" + + "github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +// TaskDB is the State Store's task database: the task, event, status and +// identity surface plus the control-plane resources, over one pool. +type TaskDB struct { + *postgres.Store + *postgres.Resources + Pool *pgxpool.Pool +} + +// Pool opens a pool on a fresh migrated database, closed when t ends. +func Pool(t testing.TB) *pgxpool.Pool { + t.Helper() + return PoolAt(t, pgtest.URL(t)) +} + +// PoolAt opens a pool on url and migrates it, closed when t ends. Opening a +// second pool on the same url is how a test models a restart. +func PoolAt(t testing.TB, url string) *pgxpool.Pool { + t.Helper() + pool, err := postgres.Open(t.Context(), url) + if err != nil { + t.Fatalf("pgstore: open: %v", err) + } + t.Cleanup(pool.Close) + if err := postgres.Migrate(t.Context(), pool, postgres.Migrations()); err != nil { + t.Fatalf("pgstore: migrate: %v", err) + } + return pool +} + +// On returns the task database over pool. +func On(pool *pgxpool.Pool) *TaskDB { + return &TaskDB{Store: postgres.New(pool), Resources: postgres.NewResources(pool), Pool: pool} +} + +// Open returns the task database on a fresh migrated database. +func Open(t testing.TB) *TaskDB { + t.Helper() + return On(Pool(t)) +} + +// EDA returns the event-capture store on a fresh migrated database. A nil +// cipher keeps binding secrets in plaintext. +func EDA(t testing.TB, cipher bindingcipher.BindingCipher) *postgres.EDA { + t.Helper() + return postgres.NewEDA(Pool(t), cipher) +} diff --git a/internal/infrastructure/postgres/resources.go b/internal/infrastructure/postgres/resources.go index 2294fb663..6b7593787 100644 --- a/internal/infrastructure/postgres/resources.go +++ b/internal/infrastructure/postgres/resources.go @@ -14,8 +14,7 @@ import ( ) // Resources is the PostgreSQL implementation of the State Store's -// control-plane resource document operations. It is separate while the rest -// of the transitional SQLite Store is still being ported. +// control-plane resource document operations. type Resources struct { pool *pgxpool.Pool } diff --git a/internal/infrastructure/staterpc/attribution_test.go b/internal/infrastructure/staterpc/attribution_test.go index 8535e00b4..47e21a0f7 100644 --- a/internal/infrastructure/staterpc/attribution_test.go +++ b/internal/infrastructure/staterpc/attribution_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" ) // TestEventAttributionSurvivesTheStateStoreBoundary runs the same insert through @@ -28,7 +28,7 @@ func TestEventAttributionSurvivesTheStateStoreBoundary(t *testing.T) { for _, mode := range []string{"local", "grpc"} { t.Run(mode, func(t *testing.T) { ctx := t.Context() - local := store.OpenTest(t) + local := pgstore.Open(t) var c contract = local if mode == "grpc" { c = remoteTaskStore(t, local, nil, nil) diff --git a/internal/infrastructure/staterpc/capture_stream_test.go b/internal/infrastructure/staterpc/capture_stream_test.go index 2bc059e87..0cb54894c 100644 --- a/internal/infrastructure/staterpc/capture_stream_test.go +++ b/internal/infrastructure/staterpc/capture_stream_test.go @@ -6,16 +6,16 @@ import ( "github.com/samcharles93/archie-core/internal/domain/binding" "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" ) func TestCaptureListsExceedUnaryMessageLimit(t *testing.T) { - local := store.OpenTest(t) - eda := edastore.OpenTest(t) + local := pgstore.Open(t) + eda := pgstore.EDA(t, nil) body := strings.Repeat("x", 256<<10) for range 20 { - if _, err := eda.InsertCapture(t.Context(), store.CapturedEvent{Source: "large", Body: body, Authenticated: true}, 0, 0); err != nil { + if _, err := eda.InsertCapture(t.Context(), storecontract.CapturedEvent{Source: "large", Body: body, Authenticated: true}, 0, 0); err != nil { t.Fatal(err) } } @@ -49,7 +49,7 @@ func TestCaptureListsExceedUnaryMessageLimit(t *testing.T) { } remote := remoteEDA(t, local, eda) for _, undispatched := range []bool{false, true} { - var captures []store.CapturedEvent + var captures []storecontract.CapturedEvent var err error if undispatched { captures, err = remote.ListUndispatchedCaptures(t.Context(), []string{"large"}, 20) diff --git a/internal/infrastructure/staterpc/conformance_test.go b/internal/infrastructure/staterpc/conformance_test.go index d940341c7..d84ddcf07 100644 --- a/internal/infrastructure/staterpc/conformance_test.go +++ b/internal/infrastructure/staterpc/conformance_test.go @@ -13,56 +13,57 @@ import ( "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/events" - "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" ) // contract is the union of every store surface staterpc fronts (minus the // playbook-dispatch ledger, split out below to keep the interface under the // repo's 8-method cap), so the same test battery drives both the local -// *store.Store and the remote *Client through one interface value, per +// *pgstore.TaskDB and the remote *Client through one interface value, per // docs/prds/state-store-contract.md §11's conformance requirement. type contract interface { - store.TaskStore - store.BindingTaskCreator - store.ConfigSnapshotStore - store.ApplyStatusStore + storecontract.TaskStore + storecontract.BindingTaskCreator + storecontract.ConfigSnapshotStore + storecontract.ApplyStatusStore } // edaContract is the event-capture half, which the PocketBase store serves. // It is a separate interface because no single type implements both halves // any more: that split is the point of the migration, not an accident. type edaContract interface { - store.CaptureStore - store.MappingStore - store.BindingStore - store.BindingDispatcher + storecontract.CaptureStore + storecontract.MappingStore + storecontract.BindingStore + storecontract.BindingDispatcher } // playbookContract is the playbook-dispatch idempotency-ledger surface, split // out from contract so each aggregate stays under the repo's interfacebloat // cap without weakening what the conformance battery proves. type playbookContract interface { - store.PlaybookDispatcher + storecontract.PlaybookDispatcher } // taskLogContract is the task-log read group, driven separately because it is -// not a *store.Store surface: the reader is internal/logging's own registry, +// not a *pgstore.TaskDB surface: the reader is internal/logging's own registry, // which owns the log format, so the local side of this contract is a registry // rather than a store. type taskLogContract interface { - store.TaskLogStore + storecontract.TaskLogStore } // remoteEDA fronts both stores for a battery that exercises event-capture // surfaces over the wire. -func remoteEDA(t *testing.T, local *store.Store, eda *edastore.Store) *Client { +func remoteEDA(t *testing.T, local *pgstore.TaskDB, eda *postgres.EDA) *Client { t.Helper() return remoteTaskStore(t, local, nil, eda) } -func remoteContract(t *testing.T, local *store.Store) contract { +func remoteContract(t *testing.T, local *pgstore.TaskDB) contract { t.Helper() return remoteTaskStore(t, local, nil, nil) } @@ -75,7 +76,7 @@ func remoteContract(t *testing.T, local *store.Store) contract { // task store for the task surfaces, the event-capture store for captures, // mappings, bindings and the dispatch ledgers. eda may be nil for a battery // that exercises only task surfaces. -func remoteTaskStore(t *testing.T, local *store.Store, logs store.TaskLogStore, eda *edastore.Store) *Client { +func remoteTaskStore(t *testing.T, local *pgstore.TaskDB, logs storecontract.TaskLogStore, eda *postgres.EDA) *Client { t.Helper() listener := bufconn.Listen(1 << 20) server := grpc.NewServer() @@ -112,8 +113,8 @@ func TestStateStoreConformance(t *testing.T) { for _, mode := range []string{"local", "grpc"} { t.Run(mode, func(t *testing.T) { ctx := t.Context() - local := store.OpenTest(t) - eda := edastore.OpenTest(t) + local := pgstore.Open(t) + eda := pgstore.EDA(t, nil) var c contract = local var ec edaContract = eda var pc playbookContract = eda @@ -168,7 +169,7 @@ func TestStateStoreConformance(t *testing.T) { // Stale transition: from no longer matches current status. err = c.Transition(ctx, task.ID, "queued", "merged", "") - if !errors.Is(err, store.ErrStaleTransition) { + if !errors.Is(err, storecontract.ErrStaleTransition) { t.Fatalf("Transition stale = %v, want ErrStaleTransition", err) } @@ -181,7 +182,7 @@ func TestStateStoreConformance(t *testing.T) { if err := c.BeginRemediation(ctx, task.ID, `{"review_id":7}`); err != nil { t.Fatalf("BeginRemediation: %v", err) } - if err := c.BeginRemediation(ctx, task.ID, `{"review_id":7}`); !errors.Is(err, store.ErrStaleTransition) { + if err := c.BeginRemediation(ctx, task.ID, `{"review_id":7}`); !errors.Is(err, storecontract.ErrStaleTransition) { t.Fatalf("BeginRemediation stale = %v, want ErrStaleTransition", err) } remediated, err := c.TaskByID(ctx, task.ID) @@ -197,7 +198,7 @@ func TestStateStoreConformance(t *testing.T) { if err := c.Transition(ctx, task.ID, "queued", "running", "claimed"); err != nil { t.Fatalf("claim: %v", err) } - if err := c.UpdateReviewPayload(ctx, task.ID, `{}`); !errors.Is(err, store.ErrStaleTransition) { + if err := c.UpdateReviewPayload(ctx, task.ID, `{}`); !errors.Is(err, storecontract.ErrStaleTransition) { t.Fatalf("UpdateReviewPayload stale = %v, want ErrStaleTransition", err) } @@ -309,7 +310,7 @@ func TestStateStoreConformance(t *testing.T) { if parked.Status != "parked" || parked.ParkClass != "transient" || parked.ParkReason != "container pool unavailable" { t.Fatalf("ParkTask row = status:%q class:%q reason:%q", parked.Status, parked.ParkClass, parked.ParkReason) } - if err := c.ParkTask(ctx, claimed.ID, "running", "late park", "transient"); !errors.Is(err, store.ErrStaleTransition) { + if err := c.ParkTask(ctx, claimed.ID, "running", "late park", "transient"); !errors.Is(err, storecontract.ErrStaleTransition) { t.Fatalf("ParkTask stale = %v, want ErrStaleTransition", err) } // An unclassified park normalizes to needs_human store-side rather @@ -371,11 +372,11 @@ func TestStateStoreConformance(t *testing.T) { t.Fatalf("UpdateMapping: %v", err) } err = ec.UpdateMapping(ctx, mapping.Mapping{ID: "rabsent00000000", Name: "x", Fields: gotMapping.Fields}) - if !errors.Is(err, store.ErrMappingNotFound) { + if !errors.Is(err, storecontract.ErrMappingNotFound) { t.Fatalf("UpdateMapping missing = %v, want ErrMappingNotFound", err) } err = ec.DeleteMapping(ctx, "rabsent00000000") - if !errors.Is(err, store.ErrMappingNotFound) { + if !errors.Is(err, storecontract.ErrMappingNotFound) { t.Fatalf("DeleteMapping missing = %v, want ErrMappingNotFound", err) } @@ -393,7 +394,7 @@ func TestStateStoreConformance(t *testing.T) { Name: "b2", Matcher: binding.Matcher{Source: "sentry"}, MappingID: mappingID, Workflow: "implement", Secret: "0123456789abcdef0123456789abcdef", }) - if !errors.Is(err, store.ErrBindingOverlap) { + if !errors.Is(err, storecontract.ErrBindingOverlap) { t.Fatalf("InsertBinding overlap = %v, want ErrBindingOverlap", err) } missingBinding, err := ec.GetBinding(ctx, "rabsent00000000") @@ -411,16 +412,16 @@ func TestStateStoreConformance(t *testing.T) { t.Fatalf("ApproveBinding from pending_approval = %v", err) } err = ec.ApproveBinding(ctx, bindingID) - if !errors.Is(err, store.ErrBindingTransition) { + if !errors.Is(err, storecontract.ErrBindingTransition) { t.Fatalf("ApproveBinding when armed = %v, want ErrBindingTransition", err) } err = ec.DeleteBinding(ctx, "rabsent00000000") - if !errors.Is(err, store.ErrBindingNotFound) { + if !errors.Is(err, storecontract.ErrBindingNotFound) { t.Fatalf("DeleteBinding missing = %v, want ErrBindingNotFound", err) } // Capture + dispatch. - captureID, err := ec.InsertCapture(ctx, store.CapturedEvent{Source: "sentry", Body: `{"id":1}`, Authenticated: true}, 0, 0) + captureID, err := ec.InsertCapture(ctx, storecontract.CapturedEvent{Source: "sentry", Body: `{"id":1}`, Authenticated: true}, 0, 0) if err != nil || captureID == "" { t.Fatalf("InsertCapture: %v %v", captureID, err) } @@ -438,7 +439,7 @@ func TestStateStoreConformance(t *testing.T) { t.Fatalf("RecordDispatch: %v", err) } err = ec.RecordDispatch(ctx, bindingID, 1, captureID, bindingTask.ID) - if !errors.Is(err, store.ErrAlreadyDispatched) { + if !errors.Is(err, storecontract.ErrAlreadyDispatched) { t.Fatalf("RecordDispatch dup = %v, want ErrAlreadyDispatched", err) } if _, err := ec.ListUndispatchedCaptures(ctx, []string{"sentry"}, 10); err != nil { @@ -466,7 +467,7 @@ func TestStateStoreConformance(t *testing.T) { t.Fatalf("RecordPlaybookDispatch (distinct action_id) = %v, want success", err) } err = pc.RecordPlaybookDispatch(ctx, "pb.yaml", "v1", "archie:acme/widget/7", "notify") - if !errors.Is(err, store.ErrAlreadyDispatched) { + if !errors.Is(err, storecontract.ErrAlreadyDispatched) { t.Fatalf("RecordPlaybookDispatch dup = %v, want ErrAlreadyDispatched", err) } if err := pc.DeletePlaybookDispatches(ctx, "pb.yaml"); err != nil { @@ -487,7 +488,7 @@ func TestStateStoreConformance(t *testing.T) { func TestConfigSnapshotContract(t *testing.T) { for _, mode := range []string{"local", "grpc"} { t.Run(mode, func(t *testing.T) { - local := store.OpenTest(t) + local := pgstore.Open(t) var st contract = local if mode == "grpc" { st = remoteContract(t, local) @@ -498,7 +499,7 @@ func TestConfigSnapshotContract(t *testing.T) { t.Fatalf("unpublished snapshot = (found %v, %v), want (false, nil)", found, err) } - published := store.ConfigSnapshot{ + published := storecontract.ConfigSnapshot{ Schema: "webui.ConfigView/1", Document: []byte(`{"identity":{"bot_user":"archie"},"providers":{"openai":{"api_key_env":"OPENAI_API_KEY","configured":true}}}`), PublishedAt: time.Date(2026, 9, 9, 12, 30, 0, 0, time.UTC), diff --git a/internal/infrastructure/staterpc/error_test.go b/internal/infrastructure/staterpc/error_test.go index 913620274..ff204b6a4 100644 --- a/internal/infrastructure/staterpc/error_test.go +++ b/internal/infrastructure/staterpc/error_test.go @@ -9,7 +9,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/domain/storecontract" ) // TestUnmapErrorPreservesContextIdentity pins the §6 deadline contract that @@ -34,7 +34,7 @@ func TestUnmapErrorPreservesContextIdentity(t *testing.T) { if !errors.Is(got, tt.want) { t.Fatalf("unmapError(%q) = %v, want errors.Is(err, %v)", tt.err, got, tt.want) } - if errors.Is(got, store.ErrStaleTransition) { + if errors.Is(got, storecontract.ErrStaleTransition) { t.Fatalf("unmapError(%q) = %v, must not map to a store sentinel", tt.err, got) } }) @@ -75,12 +75,12 @@ func TestUnmapErrorSentinelFidelity(t *testing.T) { store error rehyd error }{ - {name: "stale transition", store: store.ErrStaleTransition, rehyd: store.ErrStaleTransition}, - {name: "binding not found", store: store.ErrBindingNotFound, rehyd: store.ErrBindingNotFound}, - {name: "mapping not found", store: store.ErrMappingNotFound, rehyd: store.ErrMappingNotFound}, - {name: "binding overlap", store: store.ErrBindingOverlap, rehyd: store.ErrBindingOverlap}, - {name: "binding transition", store: store.ErrBindingTransition, rehyd: store.ErrBindingTransition}, - {name: "already dispatched", store: store.ErrAlreadyDispatched, rehyd: store.ErrAlreadyDispatched}, + {name: "stale transition", store: storecontract.ErrStaleTransition, rehyd: storecontract.ErrStaleTransition}, + {name: "binding not found", store: storecontract.ErrBindingNotFound, rehyd: storecontract.ErrBindingNotFound}, + {name: "mapping not found", store: storecontract.ErrMappingNotFound, rehyd: storecontract.ErrMappingNotFound}, + {name: "binding overlap", store: storecontract.ErrBindingOverlap, rehyd: storecontract.ErrBindingOverlap}, + {name: "binding transition", store: storecontract.ErrBindingTransition, rehyd: storecontract.ErrBindingTransition}, + {name: "already dispatched", store: storecontract.ErrAlreadyDispatched, rehyd: storecontract.ErrAlreadyDispatched}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -104,7 +104,7 @@ func TestUnmapErrorDoesNotLeakInternalDetail(t *testing.T) { const detail = "sql: path=/var/lib/archie/archie.db secret=abcdef" internal := mapError(errors.New(detail)) got := unmapError(internal) - if errors.Is(got, store.ErrStaleTransition) || errors.Is(got, store.ErrBindingNotFound) || errors.Is(got, store.ErrAlreadyDispatched) { + if errors.Is(got, storecontract.ErrStaleTransition) || errors.Is(got, storecontract.ErrBindingNotFound) || errors.Is(got, storecontract.ErrAlreadyDispatched) { t.Fatalf("unmapError(internal) = %v, must not map to a store sentinel", got) } if st, ok := status.FromError(got); !ok || st.Code() != codes.Internal { @@ -118,7 +118,7 @@ func TestUnmapErrorDoesNotLeakInternalDetail(t *testing.T) { // status or a store sentinel). raw := errors.New("transport failure") got = unmapError(raw) - if errors.Is(got, store.ErrStaleTransition) { + if errors.Is(got, storecontract.ErrStaleTransition) { t.Fatalf("unmapError(raw) = %v, must not map to a store sentinel", got) } if !errors.Is(got, raw) { diff --git a/internal/infrastructure/staterpc/pgtest_test.go b/internal/infrastructure/staterpc/pgtest_test.go new file mode 100644 index 000000000..1a5f0ceb1 --- /dev/null +++ b/internal/infrastructure/staterpc/pgtest_test.go @@ -0,0 +1,10 @@ +package staterpc + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/infrastructure/staterpc/task_grants_test.go b/internal/infrastructure/staterpc/task_grants_test.go index 46bbf252e..def46342a 100644 --- a/internal/infrastructure/staterpc/task_grants_test.go +++ b/internal/infrastructure/staterpc/task_grants_test.go @@ -14,10 +14,10 @@ import ( "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/events" - "github.com/samcharles93/archie-core/internal/infrastructure/edastore" - "github.com/samcharles93/archie-core/internal/store" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" ) // grantsServer wires TaskGrants' Unary/Stream interceptors -- the same @@ -28,14 +28,14 @@ func grantsServer(t *testing.T, adminToken string) (grants *TaskGrants, dial fun t.Helper() grants = &TaskGrants{} listener := bufconn.Listen(1 << 20) - local := store.OpenTest(t) + local := pgstore.Open(t) server := grpc.NewServer( grpc.ChainUnaryInterceptor(grants.UnaryInterceptor(adminToken)), grpc.ChainStreamInterceptor(grants.StreamInterceptor(adminToken)), ) // One event-capture store serves every EDA surface, as the real // composition does: separate instances would not share a database. - eda := edastore.OpenTest(t) + eda := pgstore.EDA(t, nil) RegisterServer(server, Deps{ Tasks: local, ConfigSnapshots: local, ApplyStatus: local, Captures: eda, Mappings: eda, Bindings: eda, @@ -79,7 +79,7 @@ func TestCaptureStreamsCarryTheAdminToken(t *testing.T) { body := strings.Repeat("x", 256<<10) for range 20 { - if _, err := admin.InsertCapture(ctx, store.CapturedEvent{Source: "large", Body: body, Authenticated: true}, 0, 0); err != nil { + if _, err := admin.InsertCapture(ctx, storecontract.CapturedEvent{Source: "large", Body: body, Authenticated: true}, 0, 0); err != nil { t.Fatalf("InsertCapture: %v", err) } } @@ -114,10 +114,10 @@ func TestCaptureStreamsCarryTheAdminToken(t *testing.T) { for _, tc := range []struct { name string - list func(context.Context) ([]store.CapturedEvent, error) + list func(context.Context) ([]storecontract.CapturedEvent, error) }{ - {"ListCaptures", func(ctx context.Context) ([]store.CapturedEvent, error) { return admin.ListCaptures(ctx, 20) }}, - {"ListUndispatchedCaptures", func(ctx context.Context) ([]store.CapturedEvent, error) { + {"ListCaptures", func(ctx context.Context) ([]storecontract.CapturedEvent, error) { return admin.ListCaptures(ctx, 20) }}, + {"ListUndispatchedCaptures", func(ctx context.Context) ([]storecontract.CapturedEvent, error) { return admin.ListUndispatchedCaptures(ctx, []string{"large"}, 20) }}, } { @@ -263,7 +263,7 @@ func TestOnlyAdminPublishesTheConfigSnapshot(t *testing.T) { } worker := dial(t, workerToken) - snapshot := store.ConfigSnapshot{Schema: "webui.ConfigView/1", Document: []byte(`{}`)} + snapshot := storecontract.ConfigSnapshot{Schema: "webui.ConfigView/1", Document: []byte(`{}`)} if err := admin.PutConfigSnapshot(ctx, snapshot); err != nil { t.Fatalf("admin PutConfigSnapshot: %v", err) } @@ -298,7 +298,7 @@ func TestOnlyAdminReportsApplyStatus(t *testing.T) { } worker := dial(t, workerToken) - status := store.ApplyStatus{Process: "archied", Kind: "tool-settings", AppliedVersion: 2} + status := storecontract.ApplyStatus{Process: "archied", Kind: "tool-settings", AppliedVersion: 2} if err := admin.PutApplyStatus(ctx, status); err != nil { t.Fatalf("admin PutApplyStatus: %v", err) } diff --git a/internal/infrastructure/staterpc/task_log_nilslice_test.go b/internal/infrastructure/staterpc/task_log_nilslice_test.go index fcef50e59..8129fd79e 100644 --- a/internal/infrastructure/staterpc/task_log_nilslice_test.go +++ b/internal/infrastructure/staterpc/task_log_nilslice_test.go @@ -5,8 +5,8 @@ import ( "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/logging" - "github.com/samcharles93/archie-core/internal/store" ) // A decoded task-log page must never carry a nil slice for a collection field. @@ -54,7 +54,7 @@ func TestTaskLogPageCarriesNoNilCollectionFields(t *testing.T) { var c taskLogContract = reader if mode == "grpc" { - c = remoteTaskStore(t, store.OpenTest(t), reader, nil) + c = remoteTaskStore(t, pgstore.Open(t), reader, nil) } page, err := c.TaskLog(ctx, taskID, 0, logging.Query{}) diff --git a/internal/infrastructure/staterpc/task_log_test.go b/internal/infrastructure/staterpc/task_log_test.go index c87185888..5683da7d8 100644 --- a/internal/infrastructure/staterpc/task_log_test.go +++ b/internal/infrastructure/staterpc/task_log_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore" "github.com/samcharles93/archie-core/internal/logging" - "github.com/samcharles93/archie-core/internal/store" ) // TestTaskLogContract drives the task-log read group through both adapters, @@ -41,7 +41,7 @@ func TestTaskLogContract(t *testing.T) { var c taskLogContract = reader if mode == "grpc" { - c = remoteTaskStore(t, store.OpenTest(t), reader, nil) + c = remoteTaskStore(t, pgstore.Open(t), reader, nil) } t.Run("a page carries the decoded entries and their fields", func(t *testing.T) { @@ -162,7 +162,7 @@ func TestTaskLogContract(t *testing.T) { // that has no log, and the dashboard rendered that as "task logging is // optional and was not enabled for this run". func TestTaskLogContractWithoutAReaderIsUnavailable(t *testing.T) { - local := store.OpenTest(t) + local := pgstore.Open(t) // remoteContract leaves Deps.TaskLogs nil, which is what a store service // sharing no state directory with the daemon looks like. c := remoteContract(t, local) diff --git a/internal/infrastructure/taskactions/pgtest_test.go b/internal/infrastructure/taskactions/pgtest_test.go new file mode 100644 index 000000000..2d3baad7b --- /dev/null +++ b/internal/infrastructure/taskactions/pgtest_test.go @@ -0,0 +1,10 @@ +package taskactions + +import ( + "os" + "testing" + + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest" +) + +func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) } diff --git a/internal/infrastructure/taskactions/rpc_test.go b/internal/infrastructure/taskactions/rpc_test.go index 39b4e974a..a30288856 100644 --- a/internal/infrastructure/taskactions/rpc_test.go +++ b/internal/infrastructure/taskactions/rpc_test.go @@ -10,9 +10,9 @@ import ( natssrv "github.com/nats-io/nats-server/v2/test" "github.com/nats-io/nats.go" + "github.com/samcharles93/archie-core/internal/domain/storecontract" domain "github.com/samcharles93/archie-core/internal/domain/taskactions" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/store" "github.com/samcharles93/archie-core/internal/taskstate" ) @@ -86,10 +86,10 @@ func TestActionErrorKeepsItsSentinelAcrossNATS(t *testing.T) { }, { name: "store refused a stale transition", - store: stubStore{task: running, err: store.ErrStaleTransition}, + store: stubStore{task: running, err: storecontract.ErrStaleTransition}, cancel: func(int64) bool { return true }, action: taskstate.ActionStop, - want: store.ErrStaleTransition, + want: storecontract.ErrStaleTransition, }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/internal/webui/api_binding_test.go b/internal/webui/api_binding_test.go index 0efa8db44..1076af8df 100644 --- a/internal/webui/api_binding_test.go +++ b/internal/webui/api_binding_test.go @@ -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), diff --git a/internal/webui/api_capture_test.go b/internal/webui/api_capture_test.go index d1fd68eb9..982fac3c6 100644 --- a/internal/webui/api_capture_test.go +++ b/internal/webui/api_capture_test.go @@ -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}`, diff --git a/internal/webui/api_config_test.go b/internal/webui/api_config_test.go index 7733b2d83..d39db97bd 100644 --- a/internal/webui/api_config_test.go +++ b/internal/webui/api_config_test.go @@ -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 } diff --git a/internal/webui/api_mapping_test.go b/internal/webui/api_mapping_test.go index d5306b9a0..fe96a41f2 100644 --- a/internal/webui/api_mapping_test.go +++ b/internal/webui/api_mapping_test.go @@ -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) diff --git a/internal/webui/api_tasks_actions_test.go b/internal/webui/api_tasks_actions_test.go index 8e9977c14..506708e7a 100644 --- a/internal/webui/api_tasks_actions_test.go +++ b/internal/webui/api_tasks_actions_test.go @@ -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 } diff --git a/internal/webui/pgtest_test.go b/internal/webui/pgtest_test.go new file mode 100644 index 000000000..cc4bc1719 --- /dev/null +++ b/internal/webui/pgtest_test.go @@ -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)) } diff --git a/internal/webui/remote_store_test.go b/internal/webui/remote_store_test.go index 445fbd101..3426e6881 100644 --- a/internal/webui/remote_store_test.go +++ b/internal/webui/remote_store_test.go @@ -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, diff --git a/internal/webui/sse_test.go b/internal/webui/sse_test.go index ce798f011..68c0a439a 100644 --- a/internal/webui/sse_test.go +++ b/internal/webui/sse_test.go @@ -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 } diff --git a/internal/webui/webui_test.go b/internal/webui/webui_test.go index 4267d5f4f..f62e8fbd2 100644 --- a/internal/webui/webui_test.go +++ b/internal/webui/webui_test.go @@ -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 } diff --git a/tools/go.mod b/tools/go.mod index 462f0af7a..625613f12 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -16,7 +16,6 @@ require ( github.com/coreos/go-semver v0.3.1 // indirect github.com/cubicdaiya/gonp v1.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dustin/go-humanize v1.1.0 // indirect github.com/fatih/structtag v1.2.0 // indirect github.com/go-sql-driver/mysql v1.9.3 // indirect github.com/google/cel-go v0.28.0 // indirect @@ -27,9 +26,7 @@ require ( github.com/jackc/pgx/v5 v5.11.0 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect - github.com/mattn/go-isatty v0.0.24 // indirect github.com/ncruces/go-sqlite3 v0.32.0 // indirect - github.com/ncruces/go-strftime v1.0.0 // indirect github.com/ncruces/julianday v1.0.0 // indirect github.com/pb33f/ordered-map/v2 v2.3.1 // indirect github.com/pganalyze/pg_query_go/v6 v6.2.2 // indirect @@ -38,7 +35,6 @@ require ( github.com/pingcap/log v1.1.0 // indirect github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/riza-io/grpc-go v0.2.0 // indirect github.com/samcharles93/ai-sdk v0.1.39 // indirect github.com/spf13/cobra v1.10.2 // indirect @@ -65,8 +61,6 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect modernc.org/libc v1.77.1 // indirect - modernc.org/mathutil v1.7.1 // indirect - modernc.org/memory v1.12.1 // indirect modernc.org/sqlite v1.59.0 // indirect ) diff --git a/tools/go.sum b/tools/go.sum index 55d08c6f5..1c6fda4c3 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -1,41 +1,75 @@ cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0= cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= +dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= +dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= filippo.io/edwards25519 v1.1.1 h1:YpjwWWlNmGIDyXOn8zLzqiD+9TyIlPhGFG96P39uBpw= filippo.io/edwards25519 v1.1.1/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg= +github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= -github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk= -github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/buger/jsonparser v1.6.1 h1:I0phFv0PlbLHnM7TZAVjZ2MJ2/eWRTDyuO7GLR98IEs= github.com/buger/jsonparser v1.6.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= +github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= +github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= +github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= +github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= +github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= +github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/cubicdaiya/gonp v1.0.4 h1:ky2uIAJh81WiLcGKBVD5R7KsM/36W6IqqTy6Bo6rGws= github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYYACpOI0I= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUExb29/M= +github.com/docker/go-connections v0.8.1/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg= github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI= +github.com/ebitengine/purego v0.10.1 h1:dewVBCBT2GaMu1SrNTYxQhgQBethzfhiwvZiLGP/qyY= +github.com/ebitengine/purego v0.10.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= +github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= +github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= +github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/cel-go v0.28.0 h1:KjSWstCpz/MN5t4a8gnGJNIYUsJRpdi/r97xWDphIQc= github.com/google/cel-go v0.28.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8= -github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3 h1:LMLX+LgTNWpfvCBdFebv6EsYotImrt/Ppc5cXIriCSo= -github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= -github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg= @@ -50,17 +84,51 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA= +github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e h1:Q6MvJtQK/iRcRtzAscm/zF23XxJlbECiGPyRicsX+Ak= +github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= +github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= +github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= +github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY= +github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/go-archive v0.2.0 h1:zg5QDUM2mi0JIM9fdQZWC7U8+2ZfixfTYoHL7rWUcP8= +github.com/moby/go-archive v0.2.0/go.mod h1:mNeivT14o8xU+5q1YnNrkQVpK+dnNe/K6fHqnTg4qPU= +github.com/moby/moby/api v1.56.0 h1:GQzua3NA599ASSIICx0iFgiJeO9YkdDARvQsm23ZZuQ= +github.com/moby/moby/api v1.56.0/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk= +github.com/moby/moby/client v0.6.0 h1:AJjEB21QPbXSXjDsZorFBoDZPhMrfbpaPLgSMAW9Bgs= +github.com/moby/moby/client v0.6.0/go.mod h1:OCo00wNRyA3m4lmJ228W3JbyCN4ZNNYjpOXiJydBdcQ= +github.com/moby/patternmatcher v0.6.1 h1:qlhtafmr6kgMIJjKJMDmMWq7WLkKIo23hsrpR3x084U= +github.com/moby/patternmatcher v0.6.1/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/sequential v0.7.0 h1:ASQNGNROJSuOO6LL6bPHbKvuZu6NU8P4ldPWk31zj/8= +github.com/moby/sys/sequential v0.7.0/go.mod h1:NfSTAp6V3fw4tmkD62PEcOKeZKquXT8VKCkf7aVR79o= +github.com/moby/sys/user v0.4.0 h1:jhcMKit7SA80hivmFJcbB1vqmw//wU61Zdui2eQXuMs= +github.com/moby/sys/user v0.4.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= +github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= +github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= +github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ= +github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc= github.com/ncruces/go-sqlite3 v0.32.0 h1:hNBUXp88LrfQCsuyXLqWTbTUG35sUuktDsqhhgHvU20= github.com/ncruces/go-sqlite3 v0.32.0/go.mod h1:MIWTK60ONDl0oVY073zYvJP21C3Dly6P9bxVpgkLwdQ= github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M= github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= +github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY= github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ= github.com/pganalyze/pg_query_go/v6 v6.2.2 h1:O0L6zMC226R82RF3X5n0Ki6HjytDsoAzuzp4ATVAHNo= @@ -77,15 +145,26 @@ github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124/go.mod h1: github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= +github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/pressly/goose/v3 v3.28.0 h1:D2M+iL31GmpZxSHOhX8mqyqAT3CXnokUmm0eKoSP+Vc= +github.com/pressly/goose/v3 v3.28.0/go.mod h1:v26MOuB8bL3kzzrt3Vqhb3R0PRVsl8hFQKdrht/L6Rk= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/riza-io/grpc-go v0.2.0 h1:2HxQKFVE7VuYstcJ8zqpN84VnAoJ4dCL6YFhJewNcHQ= github.com/riza-io/grpc-go v0.2.0/go.mod h1:2bDvR9KkKC3KhtlSHfR3dAXjUMT86kg4UfWFyVGWqi8= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samcharles93/ai-sdk v0.1.39 h1:gbNPYeA27MifReCruBiqMgb4fFSjCDi1Zv57a9bo0Vo= github.com/samcharles93/ai-sdk v0.1.39/go.mod h1:u4zrQ9/Q58L5mNEut4bNQ1ks+RCKq71LN5EDz2N/0Zk= +github.com/sethvargo/go-retry v0.4.0 h1:9qy1OoIAxBL+gBYnkTnTnWle5wlfsXQlwRzIbbpdqPw= +github.com/sethvargo/go-retry v0.4.0/go.mod h1:tvsjdKG6xfiCx4LSiUZ06kcv38xvdVQwv8R6/VnnVWg= +github.com/shirou/gopsutil/v4 v4.26.6 h1:Mzr/npDtQC/xpeEuQKHZt8Zo9CmPvhTj8nkR8w5TLDs= +github.com/shirou/gopsutil/v4 v4.26.6/go.mod h1:LZ6ewCSkBqUpvSOf+LsTGnRinC6iaNUNMGBtDkJBaLQ= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -99,22 +178,44 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/testcontainers/testcontainers-go v0.44.0 h1:/Fwh6HY1mIikhnm9e7HwoxGycx0lzRAE0f5VQpjFxzI= +github.com/testcontainers/testcontainers-go v0.44.0/go.mod h1:IcnwQrYTO86xHXu5bvMaBH7ATlbS3Qn1M1QWW3c66rE= +github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0 h1:8fdv/9y3JMxjQ+ULAcOG8RtgeNu5t9XF9LolSXDuTwM= +github.com/testcontainers/testcontainers-go/modules/postgres v0.44.0/go.mod h1:CFr2LncGYokw+OKjXcr8ARCKG1SaC2UEnGxFBovE86g= github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA= github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU= +github.com/tklauser/go-sysconf v0.4.0 h1:7H0uAN+7RkwWRaxhYXDLqa5V3LPrJeV8wmD9dRUgPQU= +github.com/tklauser/go-sysconf v0.4.0/go.mod h1:8mTNWyog7H+MpKijp4VmKJAd2bbYQ2zuUwkYRbUArPI= +github.com/tklauser/numcpus v0.12.0 h1:NR85qdvHA9pFse3x3weVZ0r0ST8R6l5RHbZrlRaqob4= +github.com/tklauser/numcpus v0.12.0/go.mod h1:ABHeXzJnr/qqwguhClkZKT1/8VABcYrsyUiUGobwWJg= github.com/traefik/yaegi v0.16.1 h1:f1De3DVJqIDKmnasUF6MwmWv1dSEEat0wcpXhD2On3E= github.com/traefik/yaegi v0.16.1/go.mod h1:4eVhbPb3LnD2VigQjhYbEJ69vDRFdT2HQNrXx8eEwUY= github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo= github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM= github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0 h1:3g7B90UzBltIDKq1/5mrTGxTnOFDV0ICOhLoxiZ8jlg= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0/go.mod h1:Ef8SuTh59BT7+ofpDxN9z+yOlc4t2GjLmKDgYNJL/NU= +go.opentelemetry.io/otel v1.46.0 h1:FHt5/CDyVxi/8IM1CH7VE/rRgq3kLHa2mSTVMO8AWyc= +go.opentelemetry.io/otel v1.46.0/go.mod h1:Gj3SEScelsNC45tp4nSxRYlS+f5iez7W8XPMCt905kE= +go.opentelemetry.io/otel/metric v1.46.0 h1:yBnkXvgV7AXFILZc5K6IZe/CBFF3OS7BJ8ov6/lj0K8= +go.opentelemetry.io/otel/metric v1.46.0/go.mod h1:iPmdWqifKUdzziPkvvzIJXITl56fQx2mGM/DHLB3/2o= +go.opentelemetry.io/otel/trace v1.46.0 h1:OULy7ccdJnZtJ0UDYFOIGaCmiWzJ8Vi2G/Rsu60qs1c= +go.opentelemetry.io/otel/trace v1.46.0/go.mod h1:J7GAXweO77XSFkB/rmAqk9D6ihszhFjLU+d9WuUxDLI= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -123,16 +224,16 @@ go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -go.yaml.in/yaml/v4 v4.0.0-rc.2 h1:/FrI8D64VSr4HtGIlUtlFMGsm7H7pWTbj6vOLVZcA6s= -go.yaml.in/yaml/v4 v4.0.0-rc.2/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4= go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= +golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba h1:Ck8QetSgk912qxWLMCKxd0in+aiyBQyDSMae6e/xmpU= golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba/go.mod h1:50RgIsmK7OwqzTTeqcSXQW8SswW0o8fRcDxmqGluJ8E= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= -golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues= @@ -150,9 +251,9 @@ golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.50.0 h1:c2ifzfcuY7L90lZ2aKd8S4K2NpASF08SZx9ZuJkHmSU= -golang.org/x/tools v0.50.0/go.mod h1:7ulVMw3831Mwi5EZD6RomGyffr4VFjuNYXf2BbCEAV0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= +gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= google.golang.org/genproto/googleapis/api v0.0.0-20260921155816-b14227669459 h1:GS9OIt/j7c8bvBjYNgnKQysVfmV7e4jM0H8ZK95G4t8= google.golang.org/genproto/googleapis/api v0.0.0-20260921155816-b14227669459/go.mod h1:PX5/4vemwVoXtwEcRDWwcR1/r0qrosfx3qoVADMwnVE= google.golang.org/genproto/googleapis/rpc v0.0.0-20260921155816-b14227669459 h1:b0xCahf3FK2m2Cv0p4vTozGPWncCvLfwV86UNg8xWU8= @@ -161,10 +262,10 @@ google.golang.org/grpc v1.85.0-dev.0.20260825072537-93e31b48545e h1:ar+feAPij1Zn google.golang.org/grpc v1.85.0-dev.0.20260825072537-93e31b48545e/go.mod h1:7aY/KlAHanMAVIWHnk8wloQsdlfwzDz/PP9vCbJG6CU= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= @@ -174,33 +275,11 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -modernc.org/cc/v4 v4.29.7 h1:q+NXGJ0bK3b4TXFYQQVr9pYETGnmwFWkrUzJnMya/Tg= -modernc.org/cc/v4 v4.29.7/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI= -modernc.org/ccgo/v4 v4.36.0 h1:T5h7ZMcrw2r94oDLtBcU3YI6e1W8DiUg2SJIs2fwD2s= -modernc.org/ccgo/v4 v4.36.0/go.mod h1:rrtGc2QkS239nYb/mQNuBMyjq3/y3ZXWbBjPoV3wqzA= -modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM= -modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU= -modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI= -modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito= -modernc.org/gc/v3 v3.1.5 h1:21ldfPfRYE31Tb7B3mwAK8gy1AxP4+dKjrOQPfqakoc= -modernc.org/gc/v3 v3.1.5/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY= -modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks= -modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI= -modernc.org/libc v1.77.0 h1:wV+faa9ixRoUNlakU0fHLi/1kV2YLG8D8Ksk3c2mPtY= -modernc.org/libc v1.77.0/go.mod h1:BmXDCJcMkRMRbX2EI8+Zhh4fKWlHNbCCZEy0tiZevP4= modernc.org/libc v1.77.1 h1:Ct8j47QtiZ1Enj2DtFXQtUqrPCAjdCmPjtCuvrYQ0Hs= modernc.org/libc v1.77.1/go.mod h1:87/pZ4L6nD1zqW4nItuS12YO7hN1igAah34xjnQo/W0= modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= modernc.org/memory v1.12.1 h1:nFMiWrpStgZczNl6XI9GnIk/rWhYIyHGUaR04pGbp9g= modernc.org/memory v1.12.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= -modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg= -modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns= -modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w= -modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE= modernc.org/sqlite v1.59.0 h1:X1es1GpqBlS/5T+vbM4HLUdaa8OtQx468DF2vrx+38A= modernc.org/sqlite v1.59.0/go.mod h1:+paeT2A3iPRHkQDwG7oA6Tk0zQd5woMEI8q7orfry8k= -modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0= -modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A= -modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= -modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=