返回 DeepSeek-Reasonix
goal_lifecycle_test.go
根目录 / internal / tool / goal_lifecycle_test.go
1 package tool
2
3 import (
4 "context"
5 "testing"
6
7 "reasonix/internal/goal"
8 )
9
10 type lifecycleOwnerStub struct{}
11
12 func (lifecycleOwnerStub) GetGoal(context.Context) (*goal.View, error) { return nil, nil }
13 func (lifecycleOwnerStub) CreateGoal(context.Context, goal.CreateRequest, GoalAuthority) (goal.View, error) {
14 return goal.View{}, nil
15 }
16 func (lifecycleOwnerStub) UpdateGoal(context.Context, GoalUpdateRequest, GoalAuthority) (goal.View, error) {
17 return goal.View{}, nil
18 }
19
20 func TestGoalLifecycleBindingCarriesHostAttestedAuthority(t *testing.T) {
21 authority := GoalAuthority{
22 Source: GoalSourceDirectHuman,
23 SessionID: "session-1",
24 RuntimeEpoch: "epoch-1",
25 ActivityID: 7,
26 }
27 ctx := WithGoalLifecycle(context.Background(), lifecycleOwnerStub{}, authority)
28 binding, ok := GoalLifecycleFromContext(ctx)
29 if !ok {
30 t.Fatal("goal lifecycle binding is missing")
31 }
32 if binding.Authority != authority {
33 t.Fatalf("authority = %+v", binding.Authority)
34 }
35 }
36
37 func TestWithoutGoalLifecycleShadowsParentAuthority(t *testing.T) {
38 parent := WithGoalLifecycle(context.Background(), lifecycleOwnerStub{}, GoalAuthority{Source: GoalSourceGoalRound})
39 child := WithoutGoalLifecycle(parent)
40 if _, ok := GoalLifecycleFromContext(child); ok {
41 t.Fatal("child inherited parent goal authority")
42 }
43 }
44
45 func TestGoalAuthorityClassifiesMutationRights(t *testing.T) {
46 human := GoalAuthority{Source: GoalSourceDirectHuman}
47 round := GoalAuthority{Source: GoalSourceGoalRound, GoalID: "goal-1", Revision: 3, Round: 2}
48 for _, action := range []GoalAction{GoalActionCreate, GoalActionEdit, GoalActionPause, GoalActionResume, GoalActionClear} {
49 if !human.Allows(action) {
50 t.Fatalf("direct human authority rejected %q", action)
51 }
52 if round.Allows(action) {
53 t.Fatalf("goal round authority allowed %q", action)
54 }
55 }
56 for _, action := range []GoalAction{GoalActionComplete, GoalActionBlocked} {
57 if !human.Allows(action) || !round.Allows(action) {
58 t.Fatalf("terminal action %q was rejected", action)
59 }
60 }
61 if (GoalAuthority{}).Allows(GoalActionComplete) {
62 t.Fatal("empty authority may not mutate a goal")
63 }
64 }
65
65 lines GO