refactor: extract daemon bootstrap into phased wiring
This commit is contained in:
1 parent
96263071bc
commit
ff4af61e2b
4 files changed
+1298
-919
No files matched your search
File diff suppressed because it is too large.
Load diff
+48
-906
File diff suppressed because it is too large.
Load diff
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user