refactor(servicekit): stop linking the State Store and control plane into archie-messaging

This commit is contained in:
sam committed 2026-10-17 17:22:53 +11:00
1 parent c451b1f055
commit 98e7378f2d
6 files changed
+64 -33

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
// The Messaging Service reaches the State Store and the workflow engine only
// through their contracts. Go imports are atomic, so one reference relinks a
// runtime, and the boundary holds only while something re-measures it.
package main
import (
"context"
"os/exec"
"strings"
"testing"
"time"
)
func TestMessagingDoesNotLinkStoreOrWorkflowRuntime(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
out, err := exec.CommandContext(ctx, "go", "list", "-deps", ".").Output()
if err != nil {
t.Fatalf("go list -deps .: %v", err)
}
linked := map[string]bool{}
for line := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") {
linked[line] = true
}
for _, pkg := range []string{
"github.com/jackc/pgx/v5/pgxpool",
"github.com/samcharles93/archie-core/internal/infrastructure/postgres",
"github.com/samcharles93/archie-core/internal/app/controlplane",
"github.com/samcharles93/archie-core/internal/domain/workflow",
"github.com/samcharles93/archie-core/internal/agentexec",
} {
t.Run(pkg, func(t *testing.T) {
if linked[pkg] {
t.Errorf("cmd/archie-messaging links %s: services reach each other only through contracts", pkg)
}
})
}
}
+1 -2
View File
@@ -11,7 +11,6 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/agentexec/modelloop"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
"github.com/samcharles93/archie-core/internal/gateway"
@@ -22,7 +21,7 @@ import (
)
func (b *server) openChatSessions(ctx context.Context) error {
pool, err := servicekit.OpenPool(ctx, b.cfg.DatabaseURL, "the conversation store")
pool, err := postgres.OpenMigrated(ctx, b.cfg.DatabaseURL, "the conversation store")
if err != nil {
return fmt.Errorf("open conversation store: %w", err)
}
-27
View File
@@ -1,27 +0,0 @@
package servicekit
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
)
// OpenPool opens and migrates the PostgreSQL pool a service owns its tables in.
// service names the owner in the error an empty database_url produces.
func OpenPool(ctx context.Context, url, service string) (*pgxpool.Pool, error) {
if url == "" {
return nil, fmt.Errorf("database_url is required: %s is Postgres-only", service)
}
pool, err := postgres.Open(ctx, url)
if err != nil {
return nil, err
}
if err := postgres.Migrate(ctx, pool, postgres.Migrations()); err != nil {
pool.Close()
return nil, err
}
return pool, nil
}
+6 -2
View File
@@ -6,20 +6,24 @@ import (
"log/slog"
"slices"
"github.com/samcharles93/archie-core/internal/app/controlplane"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/applystatus"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/secret"
)
// RuntimeConfigSource reads the control plane's stored settings.
type RuntimeConfigSource interface {
RuntimeConfig(ctx context.Context, base config.Config) (config.Config, map[string]int64, error)
}
// RuntimeConfig layers the control plane's stored settings over base, lets
// adjust apply the caller's own live settings, then validates the result and
// resolves its provider secrets. The outcome is reported for every layered
// kind in reportKinds (every kind when nil), so a refused document keeps the
// version still running on the record and a process never reports a kind it
// does not re-apply live.
func RuntimeConfig(ctx context.Context, cp *controlplane.Client, status *applystatus.Reporter, secrets *secret.Registry, log *slog.Logger, base config.Config, adjust func(*config.Config), reportKinds []string) (config.Config, map[string]int64, error) {
func RuntimeConfig(ctx context.Context, cp RuntimeConfigSource, status *applystatus.Reporter, secrets *secret.Registry, log *slog.Logger, base config.Config, adjust func(*config.Config), reportKinds []string) (config.Config, map[string]int64, error) {
cfg, versions, err := cp.RuntimeConfig(ctx, base)
if err != nil {
return config.Config{}, nil, err
+1 -2
View File
@@ -3,7 +3,6 @@ package statestore
import (
"context"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
)
@@ -16,7 +15,7 @@ import (
// The pool is stored on boot.pg and closed at shutdown; nothing opens a second
// pool per subsystem.
func (b *server) openStateStorePool(ctx context.Context) error {
pool, err := servicekit.OpenPool(ctx, b.cfg.DatabaseURL, "the State Store")
pool, err := postgres.OpenMigrated(ctx, b.cfg.DatabaseURL, "the State Store")
if err != nil {
b.log.Error("open state store postgres pool", "err", err)
return err
@@ -59,6 +59,23 @@ func Open(ctx context.Context, url string) (*pgxpool.Pool, error) {
return pool, nil
}
// OpenMigrated opens and migrates the pool a service owns its tables in.
// service names the owner in the error an empty database_url produces.
func OpenMigrated(ctx context.Context, url, service string) (*pgxpool.Pool, error) {
if url == "" {
return nil, fmt.Errorf("database_url is required: %s is Postgres-only", service)
}
pool, err := Open(ctx, url)
if err != nil {
return nil, err
}
if err := Migrate(ctx, pool, Migrations()); err != nil {
pool.Close()
return nil, err
}
return pool, nil
}
// Migrate applies the goose migrations in fsys. A session-level advisory lock
// makes processes that start together apply each migration once.
func Migrate(ctx context.Context, pool *pgxpool.Pool, fsys fs.FS) error {