mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-05 21:39:54 +02:00
* feat: add daemon skill bundle refs Co-authored-by: multica-agent <github@multica.ai> * fix: tighten skill bundle resolve safeguards Co-authored-by: multica-agent <github@multica.ai> * feat: add task prepare lease Co-authored-by: multica-agent <github@multica.ai> * fix: isolate prepare lease concurrent index migration Co-authored-by: multica-agent <github@multica.ai> * fix: keep prepare lease active through start Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: J <j@multica.ai> Co-authored-by: multica-agent <github@multica.ai>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package daemon
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestSkillBundleCacheLoadStore(t *testing.T) {
|
|
cache := NewSkillBundleCache(t.TempDir())
|
|
bundle := testSkillBundle()
|
|
ref := skillRefFromBundle(bundle)
|
|
|
|
if err := cache.Store("ws-1", bundle); err != nil {
|
|
t.Fatalf("Store: %v", err)
|
|
}
|
|
got, ok := cache.Load("ws-1", ref)
|
|
if !ok {
|
|
t.Fatal("expected cache hit")
|
|
}
|
|
if got.Content != bundle.Content || len(got.Files) != 1 || got.Files[0].Content != "rules" {
|
|
t.Fatalf("unexpected bundle: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestSkillBundleCacheRejectsCorruptBundle(t *testing.T) {
|
|
cache := NewSkillBundleCache(t.TempDir())
|
|
bundle := testSkillBundle()
|
|
ref := skillRefFromBundle(bundle)
|
|
if err := cache.Store("ws-1", bundle); err != nil {
|
|
t.Fatalf("Store: %v", err)
|
|
}
|
|
|
|
path := cache.bundlePath("ws-1", ref)
|
|
if err := os.WriteFile(path, []byte(`{"id":"skill-1","source":"workspace","hash":"sha256:bad","content":"tampered"}`), 0o644); err != nil {
|
|
t.Fatalf("tamper cache: %v", err)
|
|
}
|
|
if _, ok := cache.Load("ws-1", ref); ok {
|
|
t.Fatal("expected corrupt cache miss")
|
|
}
|
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
t.Fatalf("expected corrupt cache file to be removed, stat err=%v", err)
|
|
}
|
|
}
|
|
|
|
func testSkillBundle() SkillData {
|
|
bundle := SkillData{
|
|
ID: "skill-1",
|
|
Source: "workspace",
|
|
Name: "deploy",
|
|
Content: "main",
|
|
Files: []SkillFileData{{Path: "rules.md", Content: "rules"}},
|
|
}
|
|
ref := skillRefFromBundle(bundle)
|
|
bundle.Hash = ref.Hash
|
|
bundle.SizeBytes = ref.SizeBytes
|
|
bundle.Files[0].SHA256 = ref.Files[0].SHA256
|
|
bundle.Files[0].SizeBytes = ref.Files[0].SizeBytes
|
|
return bundle
|
|
}
|