a221502356
A detailed plan that nothing enforces is a document. This makes the phases
executable: the implementer may write exactly one status, and every other
status is a conclusion Orchestra reaches by running the plan's own commands.
agent may request: ready_for_verification
agent may not assert: verified, awaiting_manual_verification, failed, skipped
The worker resolves commands from the coordinator, never from the request, so a
request cannot smuggle in a command the planner did not write. They run as argv
through exec with Dir set to the worktree, which is the quality gate's existing
envelope and not a weaker one. There is no shell, so a pipe is a literal
argument.
Project policy decides executable reach. registry.Project.Verification matches
argv positionally, and an absent policy refuses everything: a plan command is
agent-authored, so inheriting the operator-authored gate's reach by default
would be the wrong direction to fail in. A refused command is refused before
anything runs, and the refusal names the project and the command so the planner
learns its real reach.
Two bindings make the record mean something later. PlanRef, so progress earned
under plan A cannot survive into plan B. AtSHA, so "verified" does not outlive
the code that made it true: a record whose commit has moved is retained as
provenance and rendered as stale, never as a claim about the current tree.
Both are the same failure this codebase already fixed for reviews, which bind
to the commit they examined.
Manual steps hold a phase at awaiting_manual_verification. The sign-off is an
ordinary human decision whose subject carries the plan ref and the phase id, so
a later "looks good" on an unrelated thread cannot satisfy a gate nobody was
discussing.
A plan sealed before plan.md declares no executable unit, and says so: the
implement context states that phase progress is unavailable and the work
continues under the old semantics. Inventing phases it never had would be worse
than admitting it has none.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVbaKucEYBjMqVeUgJUsc1
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
// Progress earned under plan A must not survive into plan B. Without this, a
|
|
// replan inherits verification it did not earn, which is the same shape as a
|
|
// review outliving the commit it examined.
|
|
//
|
|
// The reducer also clears the records on a re-seal. This guards the read side,
|
|
// so a record that reaches a reader by any other route is still not counted.
|
|
func TestPlanPhasesIgnoresRecordsFromASupersededPlan(t *testing.T) {
|
|
task := Task{
|
|
PlanRef: "plan-b",
|
|
PlanProgress: &PlanProgress{PlanRef: "plan-a", Phases: []PlanPhaseRecord{
|
|
{PhaseID: "phase-1", PlanRef: "plan-a", Status: PlanPhaseVerified, AtSHA: "abc"},
|
|
}},
|
|
}
|
|
if got := task.PlanPhases(); len(got) != 0 {
|
|
t.Fatalf("progress from plan-a counted under plan-b: %+v", got)
|
|
}
|
|
if _, ok := task.PlanPhase("phase-1"); ok {
|
|
t.Fatal("a superseded phase was addressable")
|
|
}
|
|
task.PlanProgress.PlanRef = "plan-b"
|
|
if got := task.PlanPhases(); len(got) != 1 {
|
|
t.Fatalf("progress for the accepted plan was discarded: %+v", got)
|
|
}
|
|
}
|
|
|
|
// A task with no accepted plan counts nothing, whatever the projection holds.
|
|
func TestPlanPhasesRequiresAnAcceptedPlan(t *testing.T) {
|
|
task := Task{PlanProgress: &PlanProgress{PlanRef: "plan-a", Phases: []PlanPhaseRecord{{PhaseID: "phase-1"}}}}
|
|
if got := task.PlanPhases(); len(got) != 0 {
|
|
t.Fatalf("progress counted with no PlanRef: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestPlanPhaseSubjectBindsPlanAndPhase(t *testing.T) {
|
|
if PlanPhaseSubject("ref-a", "phase-1") == PlanPhaseSubject("ref-b", "phase-1") {
|
|
t.Fatal("two plans share a manual sign-off subject")
|
|
}
|
|
if PlanPhaseSubject("ref-a", "phase-1") == PlanPhaseSubject("ref-a", "phase-2") {
|
|
t.Fatal("two phases share a manual sign-off subject")
|
|
}
|
|
}
|
|
|
|
// An agent may request verification. Every other status is a conclusion
|
|
// Orchestra reaches, so a payload claiming one with a failing command is a
|
|
// contradiction the reducer could not detect later.
|
|
func TestVerifiedStatusCannotCarryAFailingCommand(t *testing.T) {
|
|
sha := "1111111111111111111111111111111111111111"
|
|
base := func() map[string]any {
|
|
return map[string]any{"plan_ref": "r", "phase_id": "phase-1", "at_sha": sha}
|
|
}
|
|
ok := base()
|
|
ok["status"] = string(PlanPhaseVerified)
|
|
ok["exit_codes"] = []any{float64(0)}
|
|
if err := ValidatePlanPhaseVerified(ok); err != nil {
|
|
t.Fatalf("a passing verification was refused: %v", err)
|
|
}
|
|
bad := base()
|
|
bad["status"] = string(PlanPhaseVerified)
|
|
bad["exit_codes"] = []any{float64(1)}
|
|
if err := ValidatePlanPhaseVerified(bad); err == nil {
|
|
t.Fatal("verified with a non-zero exit code was accepted")
|
|
}
|
|
agent := base()
|
|
agent["status"] = PlanPhaseRequestStatus
|
|
if err := ValidatePlanPhaseVerified(agent); err == nil {
|
|
t.Fatal("ready_for_verification was accepted as a durable status")
|
|
}
|
|
noSHA := base()
|
|
noSHA["status"] = string(PlanPhaseVerified)
|
|
noSHA["at_sha"] = "abc"
|
|
if err := ValidatePlanPhaseVerified(noSHA); err == nil {
|
|
t.Fatal("a verification with no anchored commit was accepted")
|
|
}
|
|
}
|