Six mechanical fixes from `golangci-lint run ./...` (30 findings total, 23
deliberately left -- see the next commit's message for the one that grew
into something bigger, and the following note for the rest):
- apply.go: %v -> %w for the wrapped yaml error, matching the identical
double-%w pattern already used in decode.go/discovery.go/loader.go in the
same package (errorlint).
- contract_test.go: filepath.Join("provider.go") with a single argument is a
no-op join; replaced with the literal (gocritic).
- inprocess_test.go, yaegi_test.go: two goroutines whose whole purpose is
timing (does Execute return promptly on cancellation / does Run block
forever), where the call's result is irrelevant -- explicitly discarded
with `_, _ =` and a comment saying why, rather than silently ignored
(errcheck).
- find_test.go: an unchecked os.MkdirAll now matches the file's own
createTestFile helper, which already checks and t.Fatals on the same
operation (errcheck).
Not touched, and why: 18 cyclop/gocognit/gocyclo/funlen/nestif findings
require extracting helpers to reduce complexity -- the exact shape of two
regressions already recorded in CLAUDE.md's Lint-driven changes section
(one from --fix silently dropping a predicate, one from a nestif extraction
that doubled data), so a blind sweep across 9 unfamiliar files was declined
rather than risk a third. 2 godox findings (storage.go, worktree.go) mark
real missing work; deleting the comment would hide debt, not fix it. 3
recvcheck findings (Duration, TaskEnvelope, Provenance) each mix a
mandatory-pointer-receiver method (UnmarshalText/UnmarshalJSON's interface
contract, or genuine mutation) with correctly-value-receiver read-only
methods -- forcing consistency would either break interface conformance or
force pointer receivers onto call sites where the value isn't addressable.
Adversarially reviewed by a fresh subagent: all six confirmed
behavior-neutral or behavior-improving, all touched packages pass -race,
golangci-lint confirms exactly 23 issues remain (not more, not fewer), and
none are new.
81 lines
2.6 KiB
Go
81 lines
2.6 KiB
Go
package provider_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestToolProviderEngineContractExists(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
source, err := os.ReadFile("provider.go")
|
|
if err != nil {
|
|
t.Fatalf("read provider.go: %v", err)
|
|
}
|
|
text := string(source)
|
|
for _, required := range []string{
|
|
"type Engine interface",
|
|
"plugin.Module",
|
|
"Discover(context.Context) ([]tools.ToolEntry, error)",
|
|
"type Registry struct",
|
|
"func (r *Registry) Register(engine Engine) error",
|
|
"func (r *Registry) Get(id string) (Engine, bool)",
|
|
} {
|
|
if !strings.Contains(text, required) {
|
|
t.Errorf("provider.go does not contain required typed-family contract %q", required)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestArchiedWiresTypedProvidersAndExecutableConsumers(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
mainPath := filepath.Join("..", "..", "..", "cmd", "archied", "main.go")
|
|
source, err := os.ReadFile(mainPath)
|
|
if err != nil {
|
|
t.Fatalf("read archied main: %v", err)
|
|
}
|
|
var text strings.Builder
|
|
text.WriteString(string(source))
|
|
|
|
// 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", "bootstrap.go"} {
|
|
path := filepath.Join("..", "..", "..", "cmd", "archied", name)
|
|
source, readErr := os.ReadFile(path)
|
|
if readErr == nil {
|
|
text.WriteString(string(source))
|
|
}
|
|
}
|
|
|
|
for _, required := range []string{
|
|
// 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, cfg.WorkDir)",
|
|
"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(b.llm, log, b.toolReg)",
|
|
} {
|
|
if !strings.Contains(text.String(), required) {
|
|
t.Errorf("archied wiring not found: %q", required)
|
|
}
|
|
}
|
|
if strings.Contains(text.String(), ".RegisterTools(ctx, toolReg)") {
|
|
t.Error("composition bypasses the typed provider registry with direct MCP registration")
|
|
}
|
|
if strings.Contains(text.String(), "memManager.GetToolSchemas()") {
|
|
t.Error("composition bypasses the typed memory tool provider")
|
|
}
|
|
}
|