Implement continuity handoffs and pickup validation
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package continuity
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"orchestra/internal/store"
|
||||
)
|
||||
|
||||
func TestHandoffCASAndPickup(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
run := func(a ...string) {
|
||||
c := exec.Command("git", append([]string{"-C", root}, a...)...)
|
||||
c.Env = append(os.Environ(), "GIT_AUTHOR_NAME=test", "GIT_AUTHOR_EMAIL=test@example", "GIT_COMMITTER_NAME=test", "GIT_COMMITTER_EMAIL=test@example")
|
||||
if b, e := c.CombinedOutput(); e != nil {
|
||||
t.Fatalf("git: %s %v", b, e)
|
||||
}
|
||||
}
|
||||
os.WriteFile(filepath.Join(root, "TASK.md"), []byte("original"), 0644)
|
||||
run("init")
|
||||
run("add", "TASK.md")
|
||||
run("commit", "-m", "init")
|
||||
head := runOut(t, root, "rev-parse", "HEAD")
|
||||
task := sha256.Sum256([]byte("original"))
|
||||
s, _ := store.Open(t.TempDir())
|
||||
h := Handoff{Meta: Meta{ID: "h1", Reason: "manual"}, Anchor: Anchor{GitSHA: head, Branch: "main"}, Goal: "ship", DoneWhen: []string{"tests pass"}, Action: "test", Command: "go test ./...", LastResult: Result{AtSHA: head}}
|
||||
ref, e := Save(h, s)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := Load(ref, s)
|
||||
if e != nil || got.Meta.ID != "h1" {
|
||||
t.Fatalf("load: %v", e)
|
||||
}
|
||||
if e = ValidatePickup(root, got, hex.EncodeToString(task[:])); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
func runOut(t *testing.T, root string, a ...string) string {
|
||||
b, e := exec.Command("git", append([]string{"-C", root}, a...)...).Output()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
return string(b[:len(b)-1])
|
||||
}
|
||||
|
||||
func TestDecodeRejectsUnknownKnowledgeFields(t *testing.T) {
|
||||
_, e := Decode([]byte(`{"meta":{"id":"x","reason":"manual","rotation_index":0},"unknown":1}`))
|
||||
if e == nil {
|
||||
t.Fatal("expected strict schema error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user