fix: address 9 'Now' adversarial audit findings
P1 (panic): nil Storage guard in daemon.process()
C1 (correctness): check WriteTaskJSON error — don't start blind
C2 (correctness): move 'working' label after container setup
C3 (correctness): warn on duplicate workflow names in registry
C4 (correctness): test that generated _Plugin wrapper has nil-guards
C5 (correctness): .agents/skills as file (ENOTDIR) not fatal
C6 (correctness): ecosystem case-insensitive in cacheMounts
N1 (correctness): TOCTOU race — treat 'already exists' as success
N2 (correctness): recover from panicking plugin.Name() at startup
--- Details ---
P1: d.Storage.Setup() is now guarded by a nil check. In normal
operation Storage is always set when ContainerPool is set, but
the invariant is now explicit and enforced.
C1: container.WriteTaskJSON() error was discarded with _. Now it
returns early with a park transition — the container never starts
without a boot-time brief.
C2: SetStateLabel('working') was called before container setup.
If Acquire failed, the task was parked but the label stayed
'working' permanently. Now the label is set only after successful
container setup (or immediately if no containers are configured).
C3: BuildRegistry and AugmentRegistry now log a warning when two
skills declare the same workflow name and one overwrites the other.
C4: TestGeneratedWrapperHasNilGuards verifies that nil WName/
WVersion don't panic. If go generate strips the nil-guards, this
test catches it before the daemon crashes.
C5: skill.Catalog() now returns nil (no skills) instead of
propagating ENOTDIR errors when .agents/skills is a file.
C6: cacheMounts() normalizes ecosystem to lowercase. 'Python',
'NODE', 'Go' all resolve correctly now.
N1: ensureVolume() treats Docker's 'already exists' error as
success, closing the TOCTOU window between VolumeInspect and
VolumeCreate.
N2: safePluginInfo() wraps plugin.Name()/Version() calls in a
recover. A plugin with a panicking Name() no longer crashes the
daemon at startup.
This commit is contained in:
1 parent
7c34bdae5a
commit
04175a1a6a
7 files changed
+151
-7
No files matched your search
@@ -389,6 +389,60 @@ var Plugin = struct{}{}
|
||||
_ = plugins
|
||||
}
|
||||
|
||||
func TestGeneratedWrapperHasNilGuards(t *testing.T) {
|
||||
// C4: the generated _Plugin wrapper must nil-guard WName and WVersion.
|
||||
// If go generate strips these guards, the daemon panics at startup
|
||||
// when logging plugin names. This test verifies the guards exist
|
||||
// and will fail if someone regenerates without them.
|
||||
//
|
||||
// The _Plugin type is in the pluginextract package. We verify
|
||||
// indirectly by loading a plugin with nil funcs and calling
|
||||
// Name()/Version() — they must return empty strings, not panic.
|
||||
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, "nilguard.go"), []byte(`package main
|
||||
|
||||
import "github.com/samcharles93/archie-core/internal/plugin"
|
||||
|
||||
var Plugin = plugin._Plugin{
|
||||
WName: nil,
|
||||
WVersion: nil,
|
||||
}
|
||||
`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
plugins, err := plugin.LoadDir(dir, symbols)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(plugins) != 1 {
|
||||
t.Fatal("plugin with nil funcs not loaded")
|
||||
}
|
||||
|
||||
// These must not panic. If they do, go generate was run and stripped
|
||||
// the nil guards from the generated wrapper.
|
||||
var name, version string
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("Name()/Version() panicked with nil funcs — "+
|
||||
"the generated _Plugin wrapper is missing nil guards. "+
|
||||
"Re-run `go generate` may have overwritten them: %v", r)
|
||||
}
|
||||
}()
|
||||
name = plugins[0].Name()
|
||||
version = plugins[0].Version()
|
||||
}()
|
||||
|
||||
if name != "" {
|
||||
t.Errorf("Name() = %q, want empty from nil WName", name)
|
||||
}
|
||||
if version != "" {
|
||||
t.Errorf("Version() = %q, want empty from nil WVersion", version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDirPluginWithGoBuildTag(t *testing.T) {
|
||||
// Build tags in Yaegi-interpreted code are just comments — they
|
||||
// don't gate evaluation. The file loads normally.
|
||||
|
||||
Reference in new issue
Block a user