130 -> 96. forcetypeassert, predeclared and usetesting are now at zero.
Fanned out across four isolated worktrees partitioned by package so no
two workers could touch the same file: internal/tools (20 assertions),
internal/webui, internal/memory + internal/ratelimit, internal/secret.
Four stragglers outside those scopes fixed inline (internal/pairing,
internal/forge, internal/channels/telegram, internal/tools/mcp).
Unchecked type assertions became comma-ok with a t.Fatalf naming the
actual type. One site in a goroutine uses t.Errorf + return instead,
since t.Fatalf from a non-test goroutine is undefined behaviour.
predeclared renames chose names from meaning rather than adding a
suffix: max -> maxQueryLen, maxMatchLen, maxRequests, alphabetLen, and
nextBackoff's max -> ceiling. `real` -> `base` in the webui tests.
os.Setenv became t.Setenv, which restores on cleanup, so the paired
deferred Unsetenv calls went with it.
Note for future fan-outs: the agent worktrees branched from origin/main
(a7388a0), not from this branch, so every diff arrived based on a tree
without the phase 1 autofix. They were applied with `git apply --3way`
and the phase 1 changes to internal/memory/manager.go were verified to
survive — in particular the repaired `ctx, cancel =` assignment. A plain
`git apply` would have silently reverted it.
103 lines
2.0 KiB
Go
103 lines
2.0 KiB
Go
package secret
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestEnvEngineResolve(t *testing.T) {
|
|
t.Setenv("TEST_SECRET_KEY", "test-value")
|
|
|
|
e := &envEngine{}
|
|
if e.Name() != "env" {
|
|
t.Errorf("Name = %q", e.Name())
|
|
}
|
|
if e.Version() != "1.0.0" {
|
|
t.Errorf("Version = %q", e.Version())
|
|
}
|
|
v, err := e.Resolve("TEST_SECRET_KEY")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v != "test-value" {
|
|
t.Errorf("got %q, want test-value", v)
|
|
}
|
|
}
|
|
|
|
func TestEnvEngineResolveMissing(t *testing.T) {
|
|
e := &envEngine{}
|
|
_, err := e.Resolve("NONEXISTENT_VAR_12345")
|
|
if err == nil {
|
|
t.Error("expected error for missing env var")
|
|
}
|
|
}
|
|
|
|
func TestSecretRefZeroValue(t *testing.T) {
|
|
r := NewRegistry()
|
|
var s SecretRef
|
|
v, err := s.Resolve(r)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if v != "" {
|
|
t.Errorf("zero-value SecretRef should return empty string, got %q", v)
|
|
}
|
|
}
|
|
|
|
func TestRegistryRegisterAndGet(t *testing.T) {
|
|
r := NewRegistry()
|
|
e, ok := r.Get("env")
|
|
if !ok {
|
|
t.Fatal("env engine should be registered by default")
|
|
}
|
|
if e.Name() != "env" {
|
|
t.Errorf("Name = %q", e.Name())
|
|
}
|
|
}
|
|
|
|
func TestRegistryGetMissing(t *testing.T) {
|
|
r := NewRegistry()
|
|
_, ok := r.Get("nonexistent")
|
|
if ok {
|
|
t.Error("should not find nonexistent engine")
|
|
}
|
|
}
|
|
|
|
func TestRegistryResolve(t *testing.T) {
|
|
t.Setenv("TEST_SECRET", "resolved")
|
|
|
|
r := NewRegistry()
|
|
v, err := r.Resolve(SecretRef{Engine: "env", Key: "TEST_SECRET"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v != "resolved" {
|
|
t.Errorf("got %q, want resolved", v)
|
|
}
|
|
}
|
|
|
|
func TestRegistryResolveUnknownEngine(t *testing.T) {
|
|
r := NewRegistry()
|
|
_, err := r.Resolve(SecretRef{Engine: "unknown", Key: "x"})
|
|
if err == nil {
|
|
t.Error("expected error for unknown engine")
|
|
}
|
|
}
|
|
|
|
func TestLoadDirNonexistent(t *testing.T) {
|
|
r := NewRegistry()
|
|
n, err := r.LoadDir("/nonexistent/path/12345")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n != 0 {
|
|
t.Errorf("expected 0 loaded, got %d", n)
|
|
}
|
|
}
|
|
|
|
func TestNewRegistryHasEnv(t *testing.T) {
|
|
r := NewRegistry()
|
|
if _, ok := r.Get("env"); !ok {
|
|
t.Error("NewRegistry must pre-register env engine")
|
|
}
|
|
}
|