package runner import ( "context" "encoding/json" "testing" "time" ) func TestExtraTurnToolReturnsError(t *testing.T) { for _, name := range []string{"ask_person", "submit_candidate"} { t.Run(name, func(t *testing.T) { s, b := toolFixture(t) cap, err := readToolCapability(s.CapabilityPath) mustJournal(t, err) args := json.RawMessage(`{"question":"Which?"}`) if name == "submit_candidate" { args = json.RawMessage(`{"commit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}`) } q := toolRequest{Capability: cap.Secret, InstanceID: b.InstanceID, TaskID: b.TaskID, Attempt: b.Attempt, Fence: b.Fence, RequestID: "one", Name: name, Arguments: args} mustJournal(t, callToolSocket(context.Background(), s.SocketPath, q)) q.RequestID = "two" if callToolSocket(context.Background(), s.SocketPath, q) == nil { t.Fatal("second turn submission accepted") } if s.invalid { t.Fatal("extra submission invalidated attempt") } pending, err := b.Journal.ToolSubmissions(context.Background(), 10) mustJournal(t, err) if len(pending) != 1 { t.Fatal("extra submission reached workflow", pending) } q.RequestID = "one" mustJournal(t, callToolSocket(context.Background(), s.SocketPath, q)) }) } } func TestToolRenewalDoesNotRefetchAuthority(t *testing.T) { s, _ := toolFixture(t) s.mu.Lock() s.binding.Current = func(context.Context) error { t.Error("renewal repeated authority network call"); return nil } s.mu.Unlock() mustJournal(t, s.RenewLease(context.Background(), time.Now().Add(time.Minute))) }