Files
orchestra/internal/registry/verification_test.go
T
kami a221502356 Let Orchestra establish plan progress instead of the implementer asserting it
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
2026-08-28 11:59:39 +04:00

86 lines
2.6 KiB
Go

package registry
import "testing"
func TestVerificationPolicyMatchesPositionally(t *testing.T) {
p := VerificationPolicy{Allowed: [][]string{
{"go", "test", "./..."},
{"go", "test", "./internal/..."},
{"go", "vet", "./..."},
{"npm", "test", "--", "*"},
{"make", "*"},
}}
allowed := [][]string{
{"go", "test", "./..."},
{"go", "test", "./internal/store/..."},
{"go", "vet", "./..."},
{"npm", "test", "--", "unit"},
// A trailing "*" covers the remaining elements, which is the only way
// a pattern authorises a longer command. The operator writes that
// deliberately when a runner takes free-form arguments.
{"npm", "test", "--", "unit", "extra"},
{"make", "check"},
{"make", "check", "verbose"},
// Narrower than an allowed pattern: ./other/... is a subset of ./...
{"go", "test", "./other/..."},
}
for _, argv := range allowed {
if ok, why := p.Allows(argv); !ok {
t.Errorf("%v refused: %s", argv, why)
}
}
refused := [][]string{
// A shorter pattern must not authorise a longer command, or
// ["go","test"] would cover ["go","test","-exec","curl"].
{"go", "test", "./...", "-exec", "curl"},
{"go", "test"},
{"go", "build", "./..."},
{"curl", "https://example.com"},
{},
}
for _, argv := range refused {
if ok, _ := p.Allows(argv); ok {
t.Errorf("%v allowed, want a refusal", argv)
}
}
}
// Absence is a refusal. A project that declares no policy must not inherit the
// quality gate's operator-authored envelope, because a plan command is written
// by an agent.
func TestAbsentVerificationPolicyRefusesEverything(t *testing.T) {
var p VerificationPolicy
ok, why := p.Allows([]string{"go", "test", "./..."})
if ok {
t.Fatal("an empty policy allowed a command")
}
if why == "" {
t.Fatal("a refusal with no reason sends the planner guessing")
}
}
// The path prefix is a prefix of the path, not of the argument text. Tested
// against a policy that does not also allow ./..., which would cover
// everything and hide the distinction.
func TestPathPrefixDoesNotMatchASiblingWithTheSameLetters(t *testing.T) {
p := VerificationPolicy{Allowed: [][]string{{"go", "test", "./internal/..."}}}
for _, argv := range [][]string{
{"go", "test", "./internalsecrets"},
{"go", "test", "./internal-tools/..."},
{"go", "test", "./..."},
} {
if ok, _ := p.Allows(argv); ok {
t.Errorf("%v allowed, want a refusal", argv)
}
}
for _, argv := range [][]string{
{"go", "test", "./internal/..."},
{"go", "test", "./internal/store/..."},
{"go", "test", "./internal"},
} {
if ok, why := p.Allows(argv); !ok {
t.Errorf("%v refused: %s", argv, why)
}
}
}