The lint check applies revive to Go declarations and common style rules.
Unused callback and interface parameters have blank names, and the
command has a package comment for its entry points.
15 files changed:
- errorlint
- gocritic
- testifylint
- errorlint
- gocritic
- testifylint
var mutex sync.Mutex
running, most := 0, 0
server := newModelFake(t)
var mutex sync.Mutex
running, most := 0, 0
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
mutex.Lock()
running++
most = max(most, running)
mutex.Lock()
running++
most = max(most, running)
}{
{
name: "failed call",
}{
{
name: "failed call",
- reply: func(w http.ResponseWriter, call ModelFakeCall) {
+ reply: func(w http.ResponseWriter, _ ModelFakeCall) {
w.WriteHeader(http.StatusInternalServerError)
_, _ = io.WriteString(w, "down")
},
w.WriteHeader(http.StatusInternalServerError)
_, _ = io.WriteString(w, "down")
},
},
{
name: "tool call and no text",
},
{
name: "tool call and no text",
- reply: func(w http.ResponseWriter, call ModelFakeCall) {
+ reply: func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{map[string]any{"type": "function_call", "name": "zoom", "arguments": "{}"}}, 100, 0, 5))
},
want: "no line",
modelWriteEvents(w, modelCompletedEvent([]any{map[string]any{"type": "function_call", "name": "zoom", "arguments": "{}"}}, 100, 0, 5))
},
want: "no line",
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) {
close(arrived)
<-release
}
close(arrived)
<-release
}
+// Command onechat runs the agent daemon and its terminal client.
t.Helper()
f := &ModelFake{
t.Helper()
f := &ModelFake{
- reply: func(w http.ResponseWriter, call ModelFakeCall) {
+ reply: func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("a line")}, 100, 0, 5))
},
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("a line")}, 100, 0, 5))
},
}
func TestClientReadsTheStream(t *testing.T) {
server := newModelFake(t)
func TestClientReadsTheStream(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w,
map[string]any{"type": "response.created", "response": map[string]any{}},
map[string]any{"type": "response.output_item.done", "item": map[string]any{"type": "reasoning", "encrypted_content": "opaque"}},
modelWriteEvents(w,
map[string]any{"type": "response.created", "response": map[string]any{}},
map[string]any{"type": "response.output_item.done", "item": map[string]any{"type": "reasoning", "encrypted_content": "opaque"}},
func TestClientTakesTheOutputOfTheCompletedResponse(t *testing.T) {
server := newModelFake(t)
func TestClientTakesTheOutputOfTheCompletedResponse(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("only here")}, 10, 0, 2))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("only here")}, 10, 0, 2))
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
server := newModelFake(t)
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, tc.events...)
}
modelWriteEvents(w, tc.events...)
}
func TestStopEndsASubagentAndItsCommand(t *testing.T) {
server := newModelFake(t)
func TestStopEndsASubagentAndItsCommand(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelFunctionCallItem("fc_1", "call_1", "shell", `{"command":"touch started && sleep 30"}`)}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelFunctionCallItem("fc_1", "call_1", "shell", `{"command":"touch started && sleep 30"}`)}, 100, 0, 5))
}
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) {
close(arrived)
<-release
}
close(arrived)
<-release
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
tc.reply(w)
}))
t.Cleanup(server.Close)
tc.reply(w)
}))
t.Cleanup(server.Close)
func TestOwnerTalksToTheAgentThroughTelegram(t *testing.T) {
server := newModelFake(t)
func TestOwnerTalksToTheAgentThroughTelegram(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("Hello from the agent.")}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("Hello from the agent.")}, 100, 0, 5))
}
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) {
close(arrived)
<-release
}
close(arrived)
<-release
}
func TestBotStartsAtTheStoredOffset(t *testing.T) {
server := newModelFake(t)
func TestBotStartsAtTheStoredOffset(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5))
}
func TestBotTriesAgainAfterFailures(t *testing.T) {
server := newModelFake(t)
func TestBotTriesAgainAfterFailures(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5))
}
func TestRepliesGoAsRichMessages(t *testing.T) {
reply := "**Done.** The table:\n\n| Name | Size |\n|:-----|-----:|\n| `a.go` | 10 |\n\n- one\n- two\n\n```go\nx := 1\n```"
server := newModelFake(t)
func TestRepliesGoAsRichMessages(t *testing.T) {
reply := "**Done.** The table:\n\n| Name | Size |\n|:-----|-----:|\n| `a.go` | 10 |\n\n- one\n- two\n\n```go\nx := 1\n```"
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(reply)}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(reply)}, 100, 0, 5))
}
func TestBotLogsAnOutageOnlyAtItsStartAndEnd(t *testing.T) {
server := newModelFake(t)
func TestBotLogsAnOutageOnlyAtItsStartAndEnd(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5))
}
func TestFailedCallEndsTheTurnWithoutARetry(t *testing.T) {
server := newModelFake(t)
func TestFailedCallEndsTheTurnWithoutARetry(t *testing.T) {
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
http.Error(w, "busy", http.StatusServiceUnavailable)
}
http.Error(w, "busy", http.StatusServiceUnavailable)
}
// ViewBuiltTree is a tree with each node built, with 1 byte of text.
type ViewBuiltTree struct{}
// ViewBuiltTree is a tree with each node built, with 1 byte of text.
type ViewBuiltTree struct{}
-func (ViewBuiltTree) Built(level, index int) (bool, error) {
+func (v ViewBuiltTree) Built(_, _ int) (bool, error) {
}
// GetQRChannel gives a new channel of pairing items to the test.
}
// GetQRChannel gives a new channel of pairing items to the test.
-func (f *WhatsAppFake) GetQRChannel(ctx context.Context) (<-chan whatsmeow.QRChannelItem, error) {
+func (f *WhatsAppFake) GetQRChannel(_ context.Context) (<-chan whatsmeow.QRChannelItem, error) {
items := make(chan whatsmeow.QRChannelItem, 8)
f.pairings <- items
items := make(chan whatsmeow.QRChannelItem, 8)
f.pairings <- items
}
// PairPhone keeps phone and returns whatsappTestCode.
}
// PairPhone keeps phone and returns whatsappTestCode.
-func (f *WhatsAppFake) PairPhone(ctx context.Context, phone string, showPushNotification bool, clientType whatsmeow.PairClientType, clientDisplayName string) (string, error) {
+func (f *WhatsAppFake) PairPhone(_ context.Context, phone string, _ bool, _ whatsmeow.PairClientType, _ string) (string, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
f.mutex.Lock()
defer f.mutex.Unlock()
}
// Logout counts the logouts and returns logoutErr.
}
// Logout counts the logouts and returns logoutErr.
-func (f *WhatsAppFake) Logout(ctx context.Context) error {
+func (f *WhatsAppFake) Logout(_ context.Context) error {
f.mutex.Lock()
defer f.mutex.Unlock()
f.mutex.Lock()
defer f.mutex.Unlock()
}
// GetJoinedGroups returns groups.
}
// GetJoinedGroups returns groups.
-func (f *WhatsAppFake) GetJoinedGroups(ctx context.Context) ([]*types.GroupInfo, error) {
+func (f *WhatsAppFake) GetJoinedGroups(_ context.Context) ([]*types.GroupInfo, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
f.mutex.Lock()
defer f.mutex.Unlock()
}
// SendMessage keeps the send and returns sendErr.
}
// SendMessage keeps the send and returns sendErr.
-func (f *WhatsAppFake) SendMessage(ctx context.Context, to types.JID, message *waE2E.Message, extra ...whatsmeow.SendRequestExtra) (whatsmeow.SendResponse, error) {
+func (f *WhatsAppFake) SendMessage(_ context.Context, to types.JID, message *waE2E.Message, extra ...whatsmeow.SendRequestExtra) (whatsmeow.SendResponse, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
f.mutex.Lock()
defer f.mutex.Unlock()
}
// newClient keeps handle and returns the fake as the client of device.
}
// newClient keeps handle and returns the fake as the client of device.
-func (f *WhatsAppFake) newClient(device *store.Device, handle func(event any) bool) WhatsAppClient {
+func (f *WhatsAppFake) newClient(_ *store.Device, handle func(event any) bool) WhatsAppClient {
f.mutex.Lock()
defer f.mutex.Unlock()
f.mutex.Lock()
defer f.mutex.Unlock()
require.NoError(t, whatsapp.device.Contacts.PutContactName(t.Context(), whatsappTestAna, "Ana", "Ana Souza"))
server := newModelFake(t)
require.NoError(t, whatsapp.device.Contacts.PutContactName(t.Context(), whatsappTestAna, "Ana", "Ana Souza"))
server := newModelFake(t)
- server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+ server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5))
}
modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5))
}
- message: func(event *events.Message) {
+ message: func(_ *events.Message) {
},
line: "12:00 Bruno Lima: Who brings the cake?",
},
},
line: "12:00 Bruno Lima: Who brings the cake?",
},
{
name: "unlink",
stop: func(test *WhatsAppRetryTest) {
{
name: "unlink",
stop: func(test *WhatsAppRetryTest) {
- test.whatsapp.Command("unlink", func(text string) {})
+ test.whatsapp.Command("unlink", func(_ string) {
+ })
test.fake.connectErr = errors.New("network unavailable")
test.start(t)
synctest.Wait()
test.fake.connectErr = errors.New("network unavailable")
test.start(t)
synctest.Wait()
- test.whatsapp.Command("unlink", func(text string) {})
+ test.whatsapp.Command("unlink", func(_ string) {
+ })
synctest.Wait()
require.False(t, test.whatsapp.isLinked())
test.fake.mutex.Lock()
test.fake.connectErr = nil
test.fake.mutex.Unlock()
synctest.Wait()
require.False(t, test.whatsapp.isLinked())
test.fake.mutex.Lock()
test.fake.connectErr = nil
test.fake.mutex.Unlock()
- test.whatsapp.Command("pair 15550001111", func(text string) {})
+ test.whatsapp.Command("pair 15550001111", func(_ string) {
+ })
items := <-test.fake.pairings
items <- whatsmeow.QRChannelItem{Event: whatsmeow.QRChannelEventCode}
synctest.Wait()
items := <-test.fake.pairings
items <- whatsmeow.QRChannelItem{Event: whatsmeow.QRChannelEventCode}
synctest.Wait()
}{
{
name: "no session file",
}{
{
name: "no session file",
- session: func(t *testing.T, dir string) {
+ session: func(_ *testing.T, _ string) {