Files
archie/internal/infrastructure/staterpc/dial_test.go
T
sam 3d611f18ab feat(archieui): standalone UI process over remote Gateway and State Store
Add cmd/archie-ui and internal/app/archieui: a second composition root that
serves the dashboard and the compiled SPA against the two contracts the daemon
already dials, so the UI stops needing the daemon's in-process objects.

The composition root lives outside internal/app/archied deliberately. That
package pulls 88 internal packages (daemon, forge, containers, NATS, secrets,
workflow); reusing its boot the way RunGateway and RunStateStore do would make
the PRD's deletion gate unreachable. archieui links 41, and cmd/archie-ui 42.

Configuration ownership follows docs/prds/ui-service-boundary.md: the process
reads the shared file, but only [services.gateway].{target,target_token},
[services.state].{target,target_token} and [web].{listen,
trust_forwarded_headers}, with flags taking precedence. Options has no field
for anything else in that file to land in, and no config.Holder.

compose() sets only the contract-backed and process-local fields. Every daemon
runtime handle stays nil on purpose and its route degrades through the
existing 501/503/empty paths. Captures, CaptureLimiter and BindingDispatcher
are withheld for the duration of the seam: the daemon's dashboard still serves
POST /webhooks/capture/{source}, and two intakes are not permitted.

Readiness is the UI's own registry over its two dependencies via a new bounded
readiness.ContractProbe. The existing GatewayProbe was unusable here: with no
channel manager to inject it reports "no gateway channels configured", i.e.
permanently degraded.

The State Store's fail-closed non-loopback rule and the two dial paths move to
staterpc.Dial/TargetIsLoopback and gatewayrpc.Dial, so the server side and
every client share one implementation instead of three copies.

The Gateway remains loopback-only with no auth interceptor, so this process is
scoped to being colocated with it; filed as archie-core-juqx.

Refs: archie-core-8cda.5.2
2026-09-08 22:54:26 +10:00

68 lines
2.0 KiB
Go

package staterpc
import "testing"
func TestTargetIsLoopback(t *testing.T) {
tests := []struct {
name string
addr string
want bool
}{
{"loopback ipv4", "127.0.0.1:9090", true},
{"loopback ipv6", "[::1]:9090", true},
{"localhost hostname", "localhost:9090", true},
{"localhost uppercase", "LOCALHOST:9090", true},
{"wildcard", "0.0.0.0:9090", false},
{"private ip", "192.168.1.10:9090", false},
{"dns name", "store.example.com:9090", false},
{"empty host", ":9090", false},
{"malformed", "127.0.0.1", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := TargetIsLoopback(tt.addr)
if tt.name == "malformed" {
if err == nil {
t.Fatalf("TargetIsLoopback(%q) = (%v, nil), want error", tt.addr, got)
}
return
}
if err != nil {
t.Fatalf("TargetIsLoopback(%q): %v", tt.addr, err)
}
if got != tt.want {
t.Fatalf("TargetIsLoopback(%q) = %v, want %v", tt.addr, got, tt.want)
}
})
}
}
// TestDialFailsClosedOffLoopbackWithoutToken is the transport half of the §9
// rule: a target reachable from the network must present a bearer token, so a
// missing credential stops the dial rather than opening an unauthenticated
// connection.
func TestDialFailsClosedOffLoopbackWithoutToken(t *testing.T) {
if _, _, err := Dial("", ""); err == nil {
t.Fatal("Dial with an empty target should fail")
}
if _, _, err := Dial("0.0.0.0:9090", ""); err == nil {
t.Fatal("Dial to a non-loopback target without a token should fail closed")
}
client, cleanup, err := Dial("0.0.0.0:9090", "secret")
if err != nil {
t.Fatalf("Dial to a non-loopback target with a token: %v", err)
}
defer cleanup()
if client == nil {
t.Fatal("Dial returned no client")
}
loopback, cleanupLoopback, err := Dial("127.0.0.1:9090", "")
if err != nil {
t.Fatalf("Dial to a loopback target without a token: %v", err)
}
defer cleanupLoopback()
if loopback == nil {
t.Fatal("Dial returned no client for a loopback target")
}
}