The deletion gate checked which packages the messaging binary links, so a process that reads a decoded [models]/[providers] value passed while building an LLM client in-process. Go imports are atomic, but a config read leaves no import to measure. - add the model-provider capability packages (transcription, embedding) to the banned-link table and classify links through a testable bannedLink rule. - scan internal/app/archiemessaging's production sources for a read of a top-level config section the PRD forbids, so the projection that built the transcriber cannot come back. - unit-test both rules, including a synthetic copy of the old wiring, so the live gate cannot rot into a no-op and still pass. Red first: TestMessagingReadsNoBannedConfigSection failed on cfg.Models and cfg.Providers before the capability moved, and the link gate failed on internal/infrastructure/transcription.
164 lines
6.4 KiB
Go
164 lines
6.4 KiB
Go
// This file enforces the objective half of the Messaging Service deletion gate
|
|
// (docs/prds/messaging-service-boundary.md, "Deletion Gate and Verification"): the
|
|
// linked binary carries no state-store, daemon, workflow, forge, gateway or
|
|
// dashboard runtime. Go imports are atomic, so a single reference to a type living
|
|
// beside a runtime relinks the runtime, and the severance holds only while
|
|
// something re-measures it. That is exactly how this package came to link the
|
|
// SQLite driver, the workflow engine and agentexec through one import of
|
|
// internal/app/controlplane (archie-core-1ng1).
|
|
|
|
package main
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const modulePath = "github.com/samcharles93/archie-core/"
|
|
|
|
// bannedCategory is one class of runtime the Messaging Service must not link.
|
|
// The names are the PRD's wording; the prefixes are how that class appears in
|
|
// this module.
|
|
type bannedCategory struct {
|
|
name string
|
|
prefixes []string
|
|
}
|
|
|
|
// deletionGate is the PRD's list, one entry per category it names. Two deliberate
|
|
// absences:
|
|
//
|
|
// - internal/channels is NOT here. The Messaging Service hosts those adapters;
|
|
// it is the process they live in, not a consumer of them.
|
|
// - internal/gatewayrpc needs no exception. It is the Gateway's contract, not
|
|
// its runtime, and it does not sit under the internal/gateway prefix -- the
|
|
// check below would catch it if it ever did.
|
|
var deletionGate = []bannedCategory{
|
|
{"state store", []string{
|
|
"modernc.org/sqlite",
|
|
"github.com/jackc/pgx",
|
|
modulePath + "internal/infrastructure/postgres",
|
|
}},
|
|
{"daemon runtime", []string{
|
|
modulePath + "internal/daemon",
|
|
modulePath + "internal/app/archied",
|
|
modulePath + "internal/container",
|
|
modulePath + "internal/worktree",
|
|
}},
|
|
{"workflow engine", []string{
|
|
modulePath + "internal/domain/workflow",
|
|
modulePath + "internal/agentexec",
|
|
modulePath + "internal/taskrun",
|
|
}},
|
|
{"forge client", []string{
|
|
modulePath + "internal/forge",
|
|
modulePath + "internal/forgerpc",
|
|
}},
|
|
{"gateway runtime", []string{
|
|
modulePath + "internal/gateway",
|
|
}},
|
|
// The PRD names "Direct LLM providers, model runtimes" among what the
|
|
// Messaging Service must not own or link. These are the in-module
|
|
// infrastructure packages that construct one; building either here means
|
|
// a model-provider credential is in the messaging process.
|
|
{"model providers", []string{
|
|
modulePath + "internal/infrastructure/transcription",
|
|
modulePath + "internal/infrastructure/embedding",
|
|
}},
|
|
{"dashboard", []string{
|
|
modulePath + "internal/webui",
|
|
}},
|
|
}
|
|
|
|
// gateExceptions are packages under a banned prefix that carry only contract,
|
|
// vocabulary or view types, so linking them is the intended end state rather
|
|
// than a tolerated leak. internal/domain/workflow/task is the Task status and
|
|
// view vocabulary the Messaging Service renders; its own dependency set holds
|
|
// none of the banned runtimes, which is what makes the exception defensible
|
|
// rather than a hole. cmd/archie-ui/architecture_test.go carries the same entry
|
|
// for the same reason.
|
|
//
|
|
// Each one must stay linked: an exception nothing needs any more is a hole in
|
|
// the fence, so this list is checked in both directions.
|
|
var gateExceptions = []string{
|
|
modulePath + "internal/domain/workflow/task",
|
|
}
|
|
|
|
// under reports whether importPath is prefix or a package below it.
|
|
func under(importPath, prefix string) bool {
|
|
return importPath == prefix || strings.HasPrefix(importPath, prefix+"/")
|
|
}
|
|
|
|
func TestMessagingProcessLinksNoRuntimeItOnlyDials(t *testing.T) {
|
|
listed, err := exec.CommandContext(t.Context(), "go", "list", "-deps", ".").CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("go list -deps .: %v\n%s", err, listed)
|
|
}
|
|
|
|
linked := make(map[string]bool, len(gateExceptions))
|
|
for importPath := range strings.FieldsSeq(string(listed)) {
|
|
if excepted(importPath, linked) {
|
|
continue
|
|
}
|
|
if category, banned := bannedLink(importPath); banned {
|
|
t.Errorf("archie-messaging links %s (%s); the Messaging Service reaches that capability over a contract, never in-process (docs/prds/messaging-service-boundary.md, deletion gate)", importPath, category)
|
|
}
|
|
}
|
|
for _, exception := range gateExceptions {
|
|
if !linked[exception] {
|
|
t.Errorf("%s is excepted from the deletion gate but is no longer linked; drop the exception instead of leaving its prefix open", exception)
|
|
}
|
|
}
|
|
// A gate that cannot fail, and a `go list` that returns nothing usable, both
|
|
// read as a pass. This pins the one thing the loop above assumes.
|
|
if !strings.Contains(string(listed), modulePath+"cmd/archie-messaging") {
|
|
t.Fatal("go list -deps returned a list that does not even name this package: the gate asserted nothing")
|
|
}
|
|
}
|
|
|
|
// bannedLink reports the deletion-gate category importPath falls under, or
|
|
// ("", false). Classifying a single package is the rule the unit test below
|
|
// pins, so the gate can be exercised without a live `go list`.
|
|
func bannedLink(importPath string) (category string, banned bool) {
|
|
for _, c := range deletionGate {
|
|
for _, prefix := range c.prefixes {
|
|
if under(importPath, prefix) {
|
|
return c.name, true
|
|
}
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
// TestDeletionGateBansModelProviderCapabilities pins the PRD category that the
|
|
// voice-transcription violation slipped past: the link gate would not flag
|
|
// anything merely because the process built an LLM client, so the capability
|
|
// packages are named explicitly. gatewayrpc is checked as the negative, since
|
|
// it is the permitted contract and must not be swept up by the internal/
|
|
// infrastructure/ prefix.
|
|
func TestDeletionGateBansModelProviderCapabilities(t *testing.T) {
|
|
for _, pkg := range []string{
|
|
modulePath + "internal/infrastructure/transcription",
|
|
modulePath + "internal/infrastructure/embedding",
|
|
} {
|
|
if _, banned := bannedLink(pkg); !banned {
|
|
t.Errorf("bannedLink(%q) = not banned; the Messaging Service must not construct a model-provider capability in-process", pkg)
|
|
}
|
|
}
|
|
if category, banned := bannedLink(modulePath + "internal/infrastructure/gatewayrpc"); banned {
|
|
t.Errorf("bannedLink(gatewayrpc) = %q; the Gateway contract is permitted", category)
|
|
}
|
|
}
|
|
|
|
// excepted reports whether importPath sits under an excepted package, recording
|
|
// the ones actually linked so a stale exception fails.
|
|
func excepted(importPath string, linked map[string]bool) bool {
|
|
for _, exception := range gateExceptions {
|
|
if under(importPath, exception) {
|
|
linked[exception] = true
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|