7f12c7fc37
The v3 stack, previously an uncommitted working tree, plus this session's two units and the burn-in instrument. This commit is the burn-in build identity: coordinator and worker must both report this revision before a task is created. Workflow (earlier sessions, uncommitted until now): human decision events and reduction, source cursors and reconcile-before-launch, turn-boundary reconciliation, internal/agentctx as the single renderer, ace-fca phases with sealed artifacts, the trajectory gate, bounded grilling, independent review, task pr enforcement, and human review reflection. Capability restrictions at the agent boundary: an authz.Agent surface at GatedWrite may ask and may not act. It also fixes two bugs the unit exposed -- gated surfaces could not reach the two endpoints written for them, and RequestHumanDecision would block an unowned task while rejecting a question from the session that did own it. Turn-boundary reconcile-failure escalation: a streak of consecutive failures asks the session to hand off, fenced on the lease epoch, with reconcile_failure as a real handoff reason. The worker was dropping the coordinator's verdict on the floor; it now acts on it. Burn-in: herdr.WriteLaunchContext dumps the exact agentctx.Build result to <worktree>/.orchestra/launch.md at every launch, local and federated. BURNIN.md is the runbook. deploy/build.sh stamps both binaries from one commit. go build, go vet and go test ./... pass, 20 packages. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
166 lines
5.3 KiB
Go
166 lines
5.3 KiB
Go
package operations
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"orchestra/internal/authz"
|
|
"orchestra/internal/domain"
|
|
"orchestra/internal/registry"
|
|
"orchestra/internal/store"
|
|
"orchestra/internal/workphase"
|
|
)
|
|
|
|
func phaseStore(t *testing.T) (*store.Store, string) {
|
|
t.Helper()
|
|
s, err := store.Open(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, _ := json.Marshal(map[string]any{"source": "gitea", "external_id": "381", "project": "p"})
|
|
id := domain.NewID()
|
|
if err := s.Append(domain.Event{ID: domain.NewID(), Type: "TaskCreated", TaskID: id, Version: 1, Payload: b, Surface: string(authz.System)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return s, id
|
|
}
|
|
|
|
// lease gives the task an owning session. A question or a phase change comes
|
|
// from a live session, so a test that skips the lease is exercising a state no
|
|
// agent can be in.
|
|
func lease(t *testing.T, s *store.Store, id string) {
|
|
t.Helper()
|
|
if _, err := s.Lease(id, "h1", time.Hour); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func sealed(t *testing.T, v interface{ Validate() error }) []byte {
|
|
t.Helper()
|
|
b, err := workphase.Encode(v)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return b
|
|
}
|
|
|
|
var research = workphase.Research{Findings: []workphase.Finding{{Claim: "runs per figure", Evidence: "attr.go:88"}}}
|
|
var plan = workphase.Plan{Changes: []workphase.Change{{Target: "attr.go", Intent: "aggregate per person"}}}
|
|
|
|
func TestFullPhasePathSealsEachArtifact(t *testing.T) {
|
|
s, id := phaseStore(t)
|
|
project := registry.Project{ID: "p"}
|
|
|
|
// frame -> research needs no artifact: framing produces none.
|
|
if _, err := AdvanceWorkPhase(s, project, id, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, _ := s.Task(id); got.WorkPhase != domain.WorkPhaseResearch {
|
|
t.Fatalf("phase = %q", got.WorkPhase)
|
|
}
|
|
|
|
// research -> plan must seal the research.
|
|
if _, err := AdvanceWorkPhase(s, project, id, nil); !errors.Is(err, domain.ErrInvalid) {
|
|
t.Fatalf("leaving research without an artifact must fail, got %v", err)
|
|
}
|
|
if _, err := AdvanceWorkPhase(s, project, id, []byte(`{"findings":[]}`)); err == nil {
|
|
t.Fatal("an invalid research artifact must be rejected")
|
|
}
|
|
if _, err := AdvanceWorkPhase(s, project, id, sealed(t, research)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _ := s.Task(id)
|
|
if got.WorkPhase != domain.WorkPhasePlan || got.ResearchRef == "" {
|
|
t.Fatalf("task = %+v", got)
|
|
}
|
|
|
|
// plan -> implement must seal the plan, and must not overwrite the
|
|
// research ref.
|
|
researchRef := got.ResearchRef
|
|
if _, err := AdvanceWorkPhase(s, project, id, sealed(t, plan)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _ = s.Task(id)
|
|
if got.WorkPhase != domain.WorkPhaseImplement || got.PlanRef == "" {
|
|
t.Fatalf("task = %+v", got)
|
|
}
|
|
if got.ResearchRef != researchRef {
|
|
t.Fatal("research ref was overwritten by the plan")
|
|
}
|
|
if got.PlanRef == got.ResearchRef {
|
|
t.Fatal("plan and research sealed to the same ref")
|
|
}
|
|
|
|
// implement -> review, then review sends work back to implement.
|
|
if _, err := AdvanceWorkPhase(s, project, id, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, _ := s.Task(id); got.WorkPhase != domain.WorkPhaseReview {
|
|
t.Fatalf("phase = %q", got.WorkPhase)
|
|
}
|
|
if _, err := AdvanceWorkPhase(s, project, id, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, _ := s.Task(id); got.WorkPhase != domain.WorkPhaseImplement {
|
|
t.Fatalf("phase = %q, review must be able to return work", got.WorkPhase)
|
|
}
|
|
}
|
|
|
|
// A project that declares a short path skips the phases it omits.
|
|
func TestProjectPathSkipsUndeclaredPhases(t *testing.T) {
|
|
s, id := phaseStore(t)
|
|
project := registry.Project{ID: "p", WorkPhases: []domain.WorkPhase{domain.WorkPhaseFrame, domain.WorkPhaseImplement, domain.WorkPhaseReview}}
|
|
if _, err := AdvanceWorkPhase(s, project, id, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, _ := s.Task(id)
|
|
if got.WorkPhase != domain.WorkPhaseImplement {
|
|
t.Fatalf("phase = %q, want implement", got.WorkPhase)
|
|
}
|
|
if got.ResearchRef != "" || got.PlanRef != "" {
|
|
t.Fatal("a skipped phase must not seal an artifact")
|
|
}
|
|
}
|
|
|
|
// The store refuses a phase move that is not legal, whatever a caller asks.
|
|
func TestIllegalTransitionRejectedAtTheAppendBoundary(t *testing.T) {
|
|
s, id := phaseStore(t)
|
|
task, _ := s.Task(id)
|
|
b, _ := json.Marshal(map[string]any{"phase": string(domain.WorkPhaseReview)})
|
|
err := s.Append(domain.Event{ID: domain.NewID(), Type: domain.EventWorkPhaseChanged, TaskID: id, Version: task.Version + 1, Payload: b, Surface: string(authz.System)})
|
|
if !errors.Is(err, domain.ErrInvalid) {
|
|
t.Fatalf("frame to review must be rejected, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestEndOfPathIsRefused(t *testing.T) {
|
|
s, id := phaseStore(t)
|
|
project := registry.Project{ID: "p", WorkPhases: []domain.WorkPhase{domain.WorkPhaseFrame}}
|
|
if _, err := AdvanceWorkPhase(s, project, id, nil); !errors.Is(err, domain.ErrInvalid) {
|
|
t.Fatalf("want ErrInvalid at the end of the path, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestPhaseChangeDoesNotTouchLifecycle(t *testing.T) {
|
|
s, id := phaseStore(t)
|
|
if _, err := s.Lease(id, "h1", 60_000_000_000); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before, _ := s.Task(id)
|
|
if _, err := AdvanceWorkPhase(s, registry.Project{ID: "p"}, id, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
after, _ := s.Task(id)
|
|
if after.State != before.State {
|
|
t.Fatalf("state changed %s -> %s", before.State, after.State)
|
|
}
|
|
if after.Lease == nil || *after.Lease != *before.Lease {
|
|
t.Fatal("lease changed")
|
|
}
|
|
if after.WorkPhase != domain.WorkPhaseResearch {
|
|
t.Fatalf("phase = %q", after.WorkPhase)
|
|
}
|
|
}
|