| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "testing" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | func TestExtraTurnToolReturnsError(t *testing.T) { |
| 11 | for _, name := range []string{"ask_person", "submit_candidate"} { |
| 12 | t.Run(name, func(t *testing.T) { |
| 13 | s, b := toolFixture(t) |
| 14 | cap, err := readToolCapability(s.CapabilityPath) |
| 15 | mustJournal(t, err) |
| 16 | args := json.RawMessage(`{"question":"Which?"}`) |
| 17 | if name == "submit_candidate" { |
| 18 | args = json.RawMessage(`{"commit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}`) |
| 19 | } |
| 20 | q := toolRequest{Capability: cap.Secret, InstanceID: b.InstanceID, TaskID: b.TaskID, Attempt: b.Attempt, Fence: b.Fence, RequestID: "one", Name: name, Arguments: args} |
| 21 | mustJournal(t, callToolSocket(context.Background(), s.SocketPath, q)) |
| 22 | q.RequestID = "two" |
| 23 | if callToolSocket(context.Background(), s.SocketPath, q) == nil { |
| 24 | t.Fatal("second turn submission accepted") |
| 25 | } |
| 26 | if s.invalid { |
| 27 | t.Fatal("extra submission invalidated attempt") |
| 28 | } |
| 29 | pending, err := b.Journal.ToolSubmissions(context.Background(), 10) |
| 30 | mustJournal(t, err) |
| 31 | if len(pending) != 1 { |
| 32 | t.Fatal("extra submission reached workflow", pending) |
| 33 | } |
| 34 | q.RequestID = "one" |
| 35 | mustJournal(t, callToolSocket(context.Background(), s.SocketPath, q)) |
| 36 | }) |
| 37 | } |
| 38 | } |
| 39 | func TestToolRenewalDoesNotRefetchAuthority(t *testing.T) { |
| 40 | s, _ := toolFixture(t) |
| 41 | s.mu.Lock() |
| 42 | s.binding.Current = func(context.Context) error { t.Error("renewal repeated authority network call"); return nil } |
| 43 | s.mu.Unlock() |
| 44 | mustJournal(t, s.RenewLease(context.Background(), time.Now().Add(time.Minute))) |
| 45 | } |
| 46 | |