| 1 | package builtin |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/tool" |
| 9 | ) |
| 10 | |
| 11 | func TestGoalToolsExcludeObservationalWorkDuration(t *testing.T) { |
| 12 | for _, tc := range []struct { |
| 13 | name string |
| 14 | tool tool.Tool |
| 15 | args string |
| 16 | }{ |
| 17 | {"get", getGoal{}, `{}`}, |
| 18 | {"update", updateGoal{}, `{"goal_id":"goal-1","revision":3,"action":"pause"}`}, |
| 19 | {"create", createGoal{}, `{"objective":"ship"}`}, |
| 20 | } { |
| 21 | t.Run(tc.name, func(t *testing.T) { |
| 22 | stub := &goalLifecycleStub{view: goalView()} |
| 23 | ctx := goalLifecycleContext(stub, tool.GoalSourceDirectHuman) |
| 24 | before, err := tc.tool.Execute(ctx, json.RawMessage(tc.args)) |
| 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | stub.view.WorkDurationMs = 123456 |
| 29 | after, err := tc.tool.Execute(ctx, json.RawMessage(tc.args)) |
| 30 | if err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | if strings.Contains(after, "workDurationMs") || before != after { |
| 34 | t.Fatalf("observational time changed tool payload:\nbefore: %s\nafter: %s", before, after) |
| 35 | } |
| 36 | if stub.view.WorkDurationMs != 123456 { |
| 37 | t.Fatal("tool serialization mutated the host view") |
| 38 | } |
| 39 | }) |
| 40 | } |
| 41 | } |
| 42 |