refactor: extract daemon bootstrap into phased wiring

This commit is contained in:
sam committed 2026-08-16 03:12:18 +10:00
1 parent a47ca4ec78
commit edf38eb3e4
4 files changed
+1298 -919

No files matched your search

File diff suppressed because it is too large. Load diff
+48 -906
View File
File diff suppressed because it is too large. Load diff
+24 -8
View File
@@ -85,12 +85,28 @@ func TestCapabilityHostContractHasNoGenericCapabilityHooks(t *testing.T) {
func TestArchiedWiresCapabilityHostLifecycle(t *testing.T) {
t.Parallel()
mainPath := filepath.Join("..", "..", "cmd", "archied", "main.go")
source, err := os.ReadFile(mainPath)
// The daemon composition lives in cmd/archied, whose wiring is now
// split across main.go (driver) and bootstrap.go (phase methods); the
// contract reads the whole package so the enforcement survives that
// split.
archiedDir := filepath.Join("..", "..", "cmd", "archied")
var text strings.Builder
entries, err := os.ReadDir(archiedDir)
if err != nil {
t.Fatal(err)
}
text := string(source)
for _, entry := range entries {
if entry.IsDir() || filepath.Ext(entry.Name()) != ".go" || strings.HasSuffix(entry.Name(), "_test.go") {
continue
}
source, err := os.ReadFile(filepath.Join(archiedDir, entry.Name()))
if err != nil {
t.Fatal(err)
}
text.Write(source)
text.WriteString("\n")
}
wiring := text.String()
for _, required := range []string{
"plugin.NewHost()",
"plugin.AdaptLegacy(",
@@ -99,18 +115,18 @@ func TestArchiedWiresCapabilityHostLifecycle(t *testing.T) {
"capabilityHost.Stop(",
"CapabilityHost:",
} {
if !strings.Contains(text, required) {
t.Errorf("cmd/archied/main.go does not contain capability-host wiring %q", required)
if !strings.Contains(wiring, required) {
t.Errorf("cmd/archied does not contain capability-host wiring %q", required)
}
}
before, _, ok := strings.Cut(text, "if err := capabilityHost.Start(")
before, _, ok := strings.Cut(wiring, "capabilityHost.Start(")
if !ok {
t.Fatal("capability host Start call not found")
}
if !strings.Contains(before, "capabilityHost.Stop(") {
t.Error("capability host cleanup must be deferred before Start so failed rollback cleanup is retried")
t.Error("capability host cleanup must be registered before Start so failed rollback cleanup is retried")
}
if strings.Contains(text, "PluginRegistry:") {
if strings.Contains(wiring, "PluginRegistry:") {
t.Error("daemon composition exposes divergent legacy plugin inventory")
}
}
+9 -5
View File
@@ -42,7 +42,7 @@ func TestArchiedWiresTypedProvidersAndExecutableConsumers(t *testing.T) {
// Also check the chat composition files, which hold the chat-turn wiring
// extracted from main.go during the structural refactor.
for _, name := range []string{"telegram_setup.go", "chat_turn_model.go"} {
for _, name := range []string{"telegram_setup.go", "chat_turn_model.go", "bootstrap.go"} {
path := filepath.Join("..", "..", "..", "cmd", "archied", name)
source, readErr := os.ReadFile(path)
if readErr == nil {
@@ -51,17 +51,21 @@ func TestArchiedWiresTypedProvidersAndExecutableConsumers(t *testing.T) {
}
for _, required := range []string{
"toolprovider.NewRegistry(toolReg)",
"memorytoolprovider.New(memManager)",
// The provider registry, its engines and the consumer wiring live
// in bootstrap.go (the boot-phase carrier) since the composition
// root was decomposed; the receiver makes the arg expressions
// carry the b. prefix there.
"toolprovider.NewRegistry(b.toolReg)",
"memorytoolprovider.New(b.memManager)",
"configuredMCPProvider(srv)",
"capabilityHost.Register(providerRegistry)",
"capabilityHost.Register(b.providerRegistry)",
// The chat turn builds its toolset from the registry before the
// system prompt is rendered, so the prompt can advertise exactly
// the tools the model is handed. After the structural refactor these
// calls live in the chat composition files.
"chatGenerateOptions(ctx,",
"toolSummaries(options.Tools)",
"agentexec.NewInProcessRunner(llm, log, toolReg)",
"agentexec.NewInProcessRunner(b.llm, log, b.toolReg)",
} {
if !strings.Contains(text.String(), required) {
t.Errorf("archied wiring not found: %q", required)