Files
archie/internal/infrastructure/staterpc/attribution_test.go
T
sam ae552db7e0 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.
2026-09-24 14:43:50 +10:00

72 lines
2.4 KiB
Go

package staterpc
import (
"testing"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
)
// TestEventAttributionSurvivesTheStateStoreBoundary runs the same insert through
// the local adapter and through a bufconn-backed gRPC client, because that hop is
// where the attribution was being lost: the daemon records the event and the State
// Store holds it, so a field the contract does not carry is a field the record
// never has.
//
// The failure this pins is specific and was live: the actor was named inside the
// event's detail text while actor_id, actor_kind and principal_id were all empty,
// so an audit query reading the columns found nothing and "who approved this"
// meant parsing a human-readable string. An in-process test passed throughout,
// because it never crossed this boundary.
func TestEventAttributionSurvivesTheStateStoreBoundary(t *testing.T) {
const (
actorID = "70000000-0000-5000-8000-000000000001"
principalID = "70000000-0000-5000-8000-000000000002"
actorKind = "bot"
)
for _, mode := range []string{"local", "grpc"} {
t.Run(mode, func(t *testing.T) {
ctx := t.Context()
local := pgstore.Open(t)
var c contract = local
if mode == "grpc" {
c = remoteTaskStore(t, local, nil, nil)
}
task, err := c.EnqueueChatTask(ctx, "acme", "widget", "title", "body", "implement", "")
if err != nil || task == nil {
t.Fatalf("EnqueueChatTask = (%+v, %v)", task, err)
}
recorded := events.Event{
Kind: events.KindAgentApproved,
TaskID: task.ID,
ActorID: actorID,
ActorKind: actorKind,
PrincipalID: principalID,
Detail: "approved by an agent, authorised by a person",
}
if _, err := c.InsertEvent(ctx, recorded); err != nil {
t.Fatalf("InsertEvent: %v", err)
}
got, err := c.TaskEvents(ctx, task.ID)
if err != nil {
t.Fatalf("TaskEvents: %v", err)
}
if len(got) != 1 {
t.Fatalf("TaskEvents returned %d events, want 1", len(got))
}
event := got[0]
if event.ActorID != actorID || event.ActorKind != actorKind || event.PrincipalID != principalID {
t.Fatalf("attribution did not cross the boundary: actor=%q kind=%q principal=%q",
event.ActorID, event.ActorKind, event.PrincipalID)
}
if event.Kind != events.KindAgentApproved {
t.Fatalf("kind = %q, want %q", event.Kind, events.KindAgentApproved)
}
})
}
}