merge: t2db.40 sources and signing into pg/foundation

Resolves against t2db.36: captures carry both event_type and unsigned (proto field 10), the State Store serves sources and event types from the Postgres EDA store, the capture row shows event type and signature together, and the staterpc sentinels map both ways from one table.
This commit is contained in:
sam committed 2026-09-24 14:38:40 +10:00
commit 8a2b5b95f9
63 files changed
+3839 -1753

No files matched your search

+2 -4
View File
@@ -254,10 +254,8 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
deps.Bindings = b.eda
deps.BindingDispatcher = b.eda
deps.PlaybookDispatcher = b.eda
// Only the Postgres EDA store holds event types.
if eventTypes, ok := any(b.eda).(storecontract.EventTypeStore); ok {
deps.EventTypes = eventTypes
}
deps.EventTypes = b.eda
deps.Sources = b.eda
}
// tool_call events project into the tool_calls collection on the same
// event-capture store: this process legitimately owns both, so the
+2
View File
@@ -14,6 +14,8 @@ type eventCaptureStore interface {
storecontract.BindingStore
storecontract.BindingDispatcher
storecontract.PlaybookDispatcher
storecontract.EventTypeStore
storecontract.SourceStore
toolCallWriter
}
+16 -5
View File
@@ -12,7 +12,7 @@ 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"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/logging"
@@ -147,16 +147,27 @@ func TestStateStoreDepsServePlaybookDispatcher(t *testing.T) {
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)
// The playbook ledger, sources and event types are served by the
// event-capture store; the task store no longer serves them.
pool, err := postgres.Open(t.Context(), pgtest.URL(t))
if err != nil {
t.Fatalf("open postgres: %v", err)
}
defer pool.Close()
if err := postgres.Migrate(t.Context(), pool, postgres.Migrations()); err != nil {
t.Fatalf("migrate: %v", err)
}
eda := postgres.NewEDA(pool, 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 event-capture store", deps.PlaybookDispatcher)
}
if deps.Sources == nil || deps.EventTypes == nil {
t.Fatalf("stateStoreDeps Sources = %v, EventTypes = %v; want both served, or intake verifies nothing and nothing dispatches", deps.Sources, deps.EventTypes)
}
// A boot without a store must not fabricate one: nil keeps the RPCs honest
// as unavailable rather than depending on a nil receiver.
@@ -11,6 +11,8 @@ import (
"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/pgtest"
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
"github.com/samcharles93/archie-core/internal/store"
)
@@ -173,11 +175,15 @@ func TestInsertEventSucceedsWhenProjectionFails(t *testing.T) {
// around a nil writer.
func TestStateStoreDepsProjectToolCalls(t *testing.T) {
st := store.OpenTest(t)
eda := edastore.OpenTest(t)
pool, err := postgres.Open(t.Context(), pgtest.URL(t))
if err != nil {
t.Fatalf("open postgres: %v", err)
}
defer pool.Close()
b := newBootstrap()
b.st = st
b.eda = eda
b.eda = postgres.NewEDA(pool, nil)
deps := b.stateStoreDeps(&staterpc.TaskGrants{})
if _, ok := deps.Tasks.(*toolCallProjectingTaskStore); !ok {
t.Fatalf("deps.Tasks = %T, want the tool_call projecting decorator", deps.Tasks)
+14 -10
View File
@@ -134,21 +134,25 @@ func wireTaskLogs(d deps, srv *webui.Server) {
srv.TaskLogs = logs
}
// wireCaptureSurfaces attaches the capture read and the intake receiver.
// Both resolve from d.Store's contracts: CaptureStore backs the inspector's
// list and the mapping preview's scan window, BindingDispatcher resolves the
// armed binding whose secret HMAC-verifies a source. A store that does not
// implement one degrades that half with a warning rather than aborting the
// process, mirroring the daemon's own adapter selection.
// wireCaptureSurfaces attaches the capture read, the source editor and the
// intake receiver. All resolve from d.Store's contracts: CaptureStore backs
// the inspector's list and the mapping preview's scan window, SourceStore
// resolves the source whose signing setting verifies an event. A store that
// does not implement one degrades that half with a warning rather than
// aborting the process, mirroring the daemon's own adapter selection.
func wireCaptureSurfaces(d deps, srv *webui.Server) {
captures, hasCaptures := d.Store.(storecontract.CaptureStore)
bindings, hasBindings := d.Store.(storecontract.BindingDispatcher)
sources, hasSources := d.Store.(storecontract.SourceStore)
if !hasCaptures {
d.Log.Warn("capture storage unavailable: state store does not implement CaptureStore")
return
}
if !hasBindings {
d.Log.Warn("binding dispatcher unavailable: state store does not implement BindingDispatcher")
var resolver captureintake.SourceResolver
if hasSources {
srv.Sources = sources
resolver = sources
} else {
d.Log.Warn("source store unavailable: state store does not implement SourceStore; no capture will dispatch")
}
capture := d.Options.Capture.withDefaults()
@@ -157,7 +161,7 @@ func wireCaptureSurfaces(d deps, srv *webui.Server) {
srv.CaptureIntake = &captureintake.Receiver{
Captures: captures,
Limiter: webhookguard.NewRateLimiter(capture.RatePerSecond, capture.RateBurst, time.Now),
Bindings: bindings,
Sources: resolver,
Retention: capture.Retention,
MaxEvents: capture.MaxEvents,
MaxBodyBytes: int64(capture.MaxBodyBytes),