Files
archie/internal/plugin/pluginextract/reachability_test.go
T
sam d2504d8023 chore(plugin): delete the unwired capability-host health surface (#882)
* chore(plugin): delete the unwired capability-host health surface

plugin.Host.Health, plugin.Host.Manifests, ModuleStatus and their private
safeHealth helper were implemented, exhaustively tested, and called from nowhere
but their own tests. AGENTS.md forbids speculative surfaces, and no settled
design places plugin module status anywhere that exists:

- docs/prds/status-health-surface.md Phase 2 is self-described as "a proposed
  resolution, awaiting Sam's sign-off -- not yet implemented", and does not
  mention plugin status even in that unapproved list.
- The readiness subsystem enumerates exactly five probes -- state_db, config,
  disk, model, gateway (internal/app/archied/readiness.go) -- with no plugin
  probe.
- docs/architecture/plugins-and-extensions.md names no operator-visible plugin
  status surface.
- The only bead naming it is closed.

plugin.Host itself stays: it is the daemon's live capability host, constructed
and Start/Stop-ed from internal/app/archied. Only the unconsumed observability
methods go.

host_contract_test.go encoded the defect -- it asserted plugin.Host *defines*
"Health" and "Manifests" -- so those two names are removed from its list, which
is now exactly the shipped lifecycle: Register, Start, Stop. The three tests
covering the deleted surface are removed with it.

The Yaegi symbol table (internal/plugin/pluginextract) was regenerated rather
than hand-edited, so ModuleStatus leaves the reflected type set with it.

Reachability evidence: Host.Health and Host.Manifests appear only in their own
tests; plugin.Host is otherwise reached from bootstrap.go and gateway.go for
Register/Start/Stop. Note that "task reachability" does NOT flag these -- the
address-taken constructor is a known blind spot of the whole-program RTA.

* chore(plugin): delete the dead Module.Health chain wired to nothing

Extends the capability-host observability deletion: plugin.Module.Health
was a required interface method with real implementations in
tools/provider/mcp and tools/provider/builtin, aggregated by
tools/provider.Registry.Health via a provider-package-local safeHealth,
and backed by per-module LifecycleState bookkeeping in plugin.Host
(registeredModule.state, setModuleState). None of it had a caller before
this change -- Host.Health was the only thing that would ever have read
a registered module's Health(), and Host.Health was already deleted as
unreachable. registeredModule.state was write-only: nothing ever read it.

Deleted:
- plugin.Module.Health, plugin.Health/HealthStatus (+ consts),
  plugin.LifecycleState (+ consts), legacyModule.Health,
  registeredModule.state, Host.setModuleState and its call sites.
- tools/provider.Registry.Health, tools/provider.safeHealth.
- tools/provider/mcp.Provider.Health, tools/provider/builtin.Provider.Health.
- Tests exclusively covering the above, and fakes' now-unnecessary Health
  methods (plugin/host_test.go, pluginextract/reachability_test.go,
  tools/provider/{provider,optional}_test.go, tools/provider/mcp/provider_test.go,
  app/agentworker/mcp_providers_test.go).

internal/plugin/pluginextract's generated file was regenerated via
`go generate ./internal/plugin/...` and the yaegi wrapper nil-guards
(dropped by fresh generation, as documented in reachability_test.go)
were reapplied by hand to WManifest/WStart/WStop/WName/WVersion,
following this repo's established post-regen pattern.
2026-09-19 14:10:39 +10:00

118 lines
3.7 KiB
Go

package pluginextract
import (
"context"
"testing"
"github.com/traefik/yaegi/interp"
"github.com/samcharles93/archie-core/internal/plugin"
"github.com/samcharles93/archie-core/internal/yaegiutil"
)
// TestPreviouslyMissingSymbolsReachableFromInterpretedCode is the regression
// test for the stale symbol-table drift (e7bo): the committed generated file
// predated internal/plugin/host.go (f73b2d1) and was never regenerated, so
// the Host/Module/Manifest/Permission/CapabilityKind types and the
// NewHost/AdaptLegacy/HostAPIVersion identifiers that plugin.go's LoadDir
// exposes to interpreted daemon plugins were absent from the table. A daemon
// plugin written against the capability-host API could not resolve them,
// silently.
//
// This test interprets a plugin that references the previously-missing
// symbols, resolves it, and calls it -- proving the symbols are wired.
func TestPreviouslyMissingSymbolsReachableFromInterpretedCode(t *testing.T) {
src := `package main
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/plugin"
)
// BuildHost exercises NewHost and HostAPIVersion -- the module-capability
// registration surface that was missing from the symbol table.
func BuildHost(m plugin.Module) (string, error) {
h := plugin.NewHost()
if h == nil {
return "", fmt.Errorf("NewHost returned nil")
}
if plugin.HostAPIVersion == "" {
return "", fmt.Errorf("HostAPIVersion empty")
}
if err := h.Register(m); err != nil {
return "", err
}
if err := h.Start(context.Background()); err != nil {
return "", err
}
defer h.Stop(context.Background())
return plugin.HostAPIVersion, nil
}
`
i, err := yaegiutil.New(interp.Options{}, Symbols)
if err != nil {
t.Fatalf("New: %v", err)
}
buildHost, err := yaegiutil.Resolve[func(plugin.Module) (string, error)](i, src, "main.BuildHost")
if err != nil {
t.Fatalf("Resolve BuildHost: %v", err)
}
// Call through with a Go-side module implementing the contract. This
// proves the interpreted host API works across the boundary end to end.
mod := testModule{}
version, err := buildHost(mod)
if err != nil {
t.Fatalf("BuildHost: %v", err)
}
if version != plugin.HostAPIVersion {
t.Errorf("BuildHost version = %q, want %q", version, plugin.HostAPIVersion)
}
}
// testModule implements plugin.Module for the Go-side call.
type testModule struct{}
func (testModule) Manifest() plugin.Manifest {
return plugin.Manifest{
ID: "test",
Name: "test",
Version: "1.0.0",
APIVersion: plugin.HostAPIVersion,
Capabilities: []plugin.CapabilityKind{"test.capability"},
}
}
func (testModule) Start(context.Context) error { return nil }
func (testModule) Stop(context.Context) error { return nil }
// TestWrapperNilGuardsPreserved follows the established pattern: yaegi's
// fresh wrapper generation omits nil-guards on interface-wrappers, so they
// are re-applied by hand after every regeneration. A zero-value wrapper
// (all function fields nil) must not panic.
func TestWrapperNilGuardsPreserved(t *testing.T) {
var mod _github_com_samcharles93_archie_core_internal_plugin_Module
if err := mod.Start(context.Background()); err != nil {
t.Errorf("Start on nil WStart = %v, want nil", err)
}
if got := mod.Manifest(); got.ID != "" || got.Name != "" || got.APIVersion != "" {
t.Errorf("Manifest on nil WManifest = %#v, want empty", got)
}
if err := mod.Stop(context.Background()); err != nil {
t.Errorf("Stop on nil WStop = %v, want nil", err)
}
var legacy _github_com_samcharles93_archie_core_internal_plugin_Plugin
if got := legacy.Name(); got != "" {
t.Errorf("Name on nil WName = %q, want empty", got)
}
if got := legacy.Version(); got != "" {
t.Errorf("Version on nil WVersion = %q, want empty", got)
}
}
var _ plugin.Module = testModule{}