webui.Server declared Cfg *config.Holder with eight read sites, none of
which ran in the UI process: composition leaves it nil there. The field
survived because the daemon kept a webui.Server it never served, using it
to render the published ConfigView snapshot and to hold the readiness
probes (archie-core-ml30).
Split at the producer. LocalConfigView becomes webui.BuildConfigView, a
pure function over a ConfigViewInput the configuration owner assembles;
the DTO and its schema stay where the UI renders them. The daemon builds
that input from its own state (boot.configViewInput) and publishes the
result. Readiness reads the daemon's Holder, channel manager and chat
contract, and the registry it produces is a daemon field, not a field on
a server with no listener. Boot now owns one Holder instead of seeding a
second and replacing it in buildDaemon; operator retry caps read it too,
so they follow a reload rather than a boot-time snapshot.
Server loses Cfg, ConfigProvenance, LastReload, ConfigOverrides and
SetProvenance. The nil-guarded branches they fed went with them, each
checked first against what the UI process actually serves:
- chat.show_tool_calls and the /api/setup checklist were degraded, not
dead. ConfigView gains a chat section carrying show_tool_calls, the
operator name and whether a channel is configured, and both surfaces
read the projection. The end-to-end suite asserts the checklist renders
from the published snapshot.
- /api/logs takes its path as a process-local option. The history is on
the daemon's disk, so a dashboard elsewhere cannot read it by learning
the path; that route still needs a contract.
- handleChannels drops its config-derived fallback, superseded by the
status manager, which already carries the descriptions and detail.
- trustForwardedHeaders keeps only the process's own setting, which the
UI process already sets.
- resolveForge keeps the published-projection path it already had.
ConfigView.Editable moves to handleConfig, decided by whether this
process holds UpdateConfig. It describes the writer, not the document, so
the write contract (archie-core-j28m) makes the page editable by wiring
one field. The write handlers and their seams stay for it.
overlay.Store gains Keys: Snapshot nests dotted keys for decoding, so the
overridden-key list was publishing section names ("budgets") where the
dashboard marks and resets rows by stored key ("budgets.max_steps").
Multi-identity forge links move to archie-core-pv6t: forgeConfigForTask
resolved a task's forge from config.Config, had no reachable caller once
the holder was gone, and belongs in the projection rather than the
rendering package.
148 lines
5.7 KiB
Go
148 lines
5.7 KiB
Go
package archieui
|
|
|
|
import (
|
|
"log/slog"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
|
"github.com/samcharles93/archie-core/internal/store"
|
|
)
|
|
|
|
// isNil reports whether v is nil, including a typed nil func or pointer
|
|
// carried inside a non-nil interface -- a plain `v != nil` reports those as
|
|
// present.
|
|
func isNil(v any) bool {
|
|
rv := reflect.ValueOf(v)
|
|
if !rv.IsValid() {
|
|
return true
|
|
}
|
|
switch rv.Kind() {
|
|
case reflect.Func, reflect.Pointer, reflect.Interface, reflect.Map, reflect.Slice, reflect.Chan:
|
|
return rv.IsNil()
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// TestComposeUIServerHoldsNoDaemonState is the acceptance criterion the parent
|
|
// bead names first: the UI process's dashboard "no longer receives the
|
|
// daemon's live config.Holder". webui.Server no longer has a holder field to
|
|
// receive (archie-core-ml30), so that clause is now enforced by the type
|
|
// rather than asserted here. What remains to pin is the rest of the
|
|
// composition: the two contract-backed fields hold remote clients, and every
|
|
// daemon-local runtime handle stays nil so the process cannot hold in-process
|
|
// daemon state by accident (docs/prds/ui-service-boundary.md, "Boundary and
|
|
// ownership").
|
|
func TestComposeUIServerHoldsNoDaemonState(t *testing.T) {
|
|
stateConn, err := grpc.NewClient("passthrough:///127.0.0.1:1", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
t.Fatalf("state client: %v", err)
|
|
}
|
|
defer stateConn.Close()
|
|
gatewayConn, err := grpc.NewClient("passthrough:///127.0.0.1:1", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
t.Fatalf("gateway client: %v", err)
|
|
}
|
|
defer gatewayConn.Close()
|
|
|
|
srv := compose(deps{
|
|
Options: Options{Listen: "127.0.0.1:8484", Token: "tok"},
|
|
Log: slog.New(slog.DiscardHandler),
|
|
Store: staterpc.NewClient(stateConn),
|
|
Chat: gatewayrpc.NewClient(gatewayConn),
|
|
})
|
|
|
|
if _, ok := srv.Store.(*staterpc.Client); !ok {
|
|
t.Fatalf("Store = %T, want *staterpc.Client", srv.Store)
|
|
}
|
|
if _, ok := srv.Store.(*store.Store); ok {
|
|
t.Fatal("Store is the concrete *store.Store; the UI process must not open archie.db")
|
|
}
|
|
if srv.Chat == nil {
|
|
t.Fatal("Chat is nil; the UI process must dial the Gateway contract")
|
|
}
|
|
if _, ok := srv.Chat.Contract.(*gatewayrpc.Client); !ok {
|
|
t.Fatalf("Chat.Contract = %T, want *gatewayrpc.Client", srv.Chat.Contract)
|
|
}
|
|
if srv.Chat.Updates != nil {
|
|
t.Error("Chat.Updates is wired; host-local install/restart stays with the daemon")
|
|
}
|
|
if srv.Token != "tok" {
|
|
t.Fatalf("Token = %q, want the UI process's own token", srv.Token)
|
|
}
|
|
|
|
unwired := map[string]any{
|
|
"UpdateConfig": srv.UpdateConfig,
|
|
"ResetConfig": srv.ResetConfig,
|
|
"UpdateRepoField": srv.UpdateRepoField,
|
|
"ReloadChannel": srv.ReloadChannel,
|
|
"RunningVersions": srv.RunningVersions,
|
|
"Events": srv.Events,
|
|
"Curators": srv.Curators,
|
|
"Memory": srv.Memory,
|
|
"Channels": srv.Channels,
|
|
"LogFeed": srv.LogFeed,
|
|
"TaskLogs": srv.TaskLogs,
|
|
"WorkRequests": srv.WorkRequests,
|
|
}
|
|
for name, handle := range unwired {
|
|
if !isNil(handle) {
|
|
t.Errorf("%s is wired; it is a daemon-owned callback or runtime handle with no contract behind it yet", name)
|
|
}
|
|
}
|
|
if srv.Workflows != nil {
|
|
t.Error("Workflows is wired; the definition catalog is a filesystem scan on the daemon host")
|
|
}
|
|
// Mappings and bindings are the other way round: ratified State Store
|
|
// contracts, carried by the client this process already holds, so
|
|
// leaving them nil would degrade two pages that have an owner.
|
|
if srv.Mappings == nil || srv.Bindings == nil {
|
|
t.Error("Mappings/Bindings are unwired; both are State Store contracts the composed client implements")
|
|
}
|
|
if srv.UpdateReportPath != "" {
|
|
t.Error("UpdateReportPath is set; host-local update relay stays with the daemon")
|
|
}
|
|
}
|
|
|
|
// TestComposeWiresCaptureIntake pins the cutover rule: once the daemon's
|
|
// dashboard listener is gone (archie-core-8cda.5.4), this process is the
|
|
// only listener serving POST /webhooks/capture/{source}, so compose must
|
|
// mount the receiver when the store contract carries it -- a capture POST
|
|
// answered by a token-gated 404 would leave intake with no owner. Zero
|
|
// Options.Capture falls back to configuration.DefaultCapture, the same
|
|
// defaults a decoded config would project.
|
|
func TestComposeWiresCaptureIntake(t *testing.T) {
|
|
stateConn, err := grpc.NewClient("passthrough:///127.0.0.1:1", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
t.Fatalf("state client: %v", err)
|
|
}
|
|
defer stateConn.Close()
|
|
|
|
srv := compose(deps{
|
|
Options: Options{},
|
|
Log: slog.New(slog.DiscardHandler),
|
|
Store: staterpc.NewClient(stateConn),
|
|
})
|
|
if srv.Captures == nil || srv.CaptureIntake == nil {
|
|
t.Fatal("capture intake is unset; the UI process is the only listener serving POST /webhooks/capture/{source} after the cutover (bead archie-core-8cda.5.4)")
|
|
}
|
|
defaults := configuration.DefaultCapture()
|
|
if srv.CaptureMaxEvents != defaults.MaxEvents {
|
|
t.Errorf("CaptureMaxEvents = %d, want the default %d", srv.CaptureMaxEvents, defaults.MaxEvents)
|
|
}
|
|
|
|
// A store without the capture contract keeps both surfaces unset and
|
|
// degrades the read instead of mounting an intake route that cannot
|
|
// persist what arrives.
|
|
empty := compose(deps{Options: Options{}, Log: slog.New(slog.DiscardHandler)})
|
|
if empty.Captures != nil || empty.CaptureIntake != nil || empty.CaptureMaxEvents != 0 {
|
|
t.Error("capture surfaces wired without a CaptureStore behind them")
|
|
}
|
|
}
|