]> git.giacomolli.uk - onechat/commitdiff
Check test assertions with testifylint
authorAnderson A. Giacomolli <agiacomolli@gmail.com>
Mon, 9 Nov 2026 20:52:43 +0000 (17:52 -0300)
committerAnderson A. Giacomolli <agiacomolli@gmail.com>
Mon, 9 Nov 2026 20:52:43 +0000 (17:52 -0300)
Test assertions use the specific require helpers for errors, lengths,
JSON, and numeric values. Test setup completes before its server starts
so that a failed assertion stops the test goroutine, not a worker.

.golangci.yml
daemon_start_helper_test.go
log_test.go
replay_test.go
telegram_test.go
tools_test.go
tree_test.go
turn_test.go

index 082c4f4e25c14d919b85c7a5ee69c52b61340d1f..1a7a596e15cbc0bc972760258c61626ad2d4f0ab 100644 (file)
@@ -5,3 +5,4 @@ linters:
   enable:
     - errorlint
     - gocritic
+    - testifylint
index 8ed36e990e2f9b34121f6870b7053af66ce324fc..81399ce3ca3c3548d815bd52294723e58863d6c3 100644 (file)
@@ -50,9 +50,10 @@ func daemonStartTestWithSchedules(t *testing.T, server *ModelFake, bot *Telegram
        client := newModelClient(server.URL, ModelAPIKey(modelTestKey), agent.CacheKey(), filepath.Join(agent.dir, "usage.jsonl"))
        ctx, cancel := context.WithCancel(t.Context())
        done := make(chan error)
+       subagents := newTestSubagents(t)
        go func() {
                done <- daemonServe(ctx, listener, bot, whatsapp, schedules, func(notify func(Event)) (*TurnLoop, error) {
-                       return newTurnLoop(agent, memory, newTestSubagents(t), whatsapp, schedules, client, clock, discardLog(), notify)
+                       return newTurnLoop(agent, memory, subagents, whatsapp, schedules, client, clock, discardLog(), notify)
                })
        }()
 
index 306b21fb8da4dc6eea651c342cee2310ed97e123..e8e07ac2ff0ad58a7b831aff6abea50c5af12ffe 100644 (file)
@@ -95,11 +95,11 @@ func TestLogWritesOneFilePerDay(t *testing.T) {
 
        first, err := os.ReadFile(filepath.Join(root, "main", "2026-01-01.jsonl"))
        require.NoError(t, err)
-       require.Equal(t, `{"i":0,"kind":"user","text":"first day","size":9,"date":"2026-01-01T12:00:00Z"}`+"\n", string(first))
+       require.JSONEq(t, `{"i":0,"kind":"user","text":"first day","size":9,"date":"2026-01-01T12:00:00Z"}`+"\n", string(first))
 
        second, err := os.ReadFile(filepath.Join(root, "main", "2026-01-02.jsonl"))
        require.NoError(t, err)
-       require.Equal(t, `{"i":1,"kind":"user","text":"second day","size":10,"date":"2026-01-02T12:00:00Z"}`+"\n", string(second))
+       require.JSONEq(t, `{"i":1,"kind":"user","text":"second day","size":10,"date":"2026-01-02T12:00:00Z"}`+"\n", string(second))
 }
 
 func TestLogAllowsOneWriter(t *testing.T) {
index 96091c2c9dde431fa12367f950bd34d6ff015f16..547b5e4efd44e9284103f8ddd016929d0a197ba0 100644 (file)
@@ -71,7 +71,7 @@ func TestReplaySyntheticLog(t *testing.T) {
 
        memory = replayRequireRestart(t, memory, root, clock)
        require.Equal(t, messages, memory.log.Len())
-       require.Greater(t, batches, 0)
+       require.Positive(t, batches)
 
        require.NoError(t, memory.Wait(t.Context()))
        t.Logf("%d messages, %d nodes, %d batches in %s", messages, memory.tree.Count(), batches, time.Since(start).Round(time.Second))
index 48e550392fee45ad3f8ceef0e7e02cb6deeb0372..5ced143eae9b1d8dbd55916ead35f3e6becdc4cc 100644 (file)
@@ -223,7 +223,7 @@ func TestBotStartsAtTheStoredOffset(t *testing.T) {
        terminal.WaitFor(t, "[connected to OneChat]")
        telegramWaitForSent(t, telegram, "ok")
 
-       require.Equal(t, float64(10), telegram.Calls()[0].params["offset"])
+       require.InDelta(t, float64(10), telegram.Calls()[0].params["offset"], 0)
        require.NotContains(t, terminal.Output(), "handled before the restart")
 
        require.Eventually(t, func() bool {
@@ -569,7 +569,7 @@ func TestRefusedRichPartGoesWithTheTextAsWritten(t *testing.T) {
                require.LessOrEqual(t, telegramUTF16Units(text), telegramMessageUnits)
        }
 
-       require.True(t, reply == strings.Join(fallback, "")+telegramUnescapeTags(rich[0]), "reply is not sent once and whole")
+       require.Equal(t, reply, strings.Join(fallback, "")+telegramUnescapeTags(rich[0]), "reply is not sent once and whole")
 }
 
 func TestRefusedEntitiesGoAgainAsPlainText(t *testing.T) {
index 3ab784551cc56b76f7071a9372279078c8eea14d..45cd4a242f1ee6024406c6d56a4c918d8fc14998 100644 (file)
@@ -211,7 +211,7 @@ func TestHeadTailKeepsTheEndsOfALongOutput(t *testing.T) {
        require.True(t, strings.HasPrefix(text, "0000xxx"))
        require.True(t, strings.HasSuffix(text, "0999"+strings.Repeat("x", 995)+"\n"))
        require.Contains(t, text, fmt.Sprintf("\n[... %d bytes cut ...]\n", 1000*1000-toolClipCharacters))
-       require.Equal(t, toolClipCharacters+len(fmt.Sprintf("\n[... %d bytes cut ...]\n", 1000*1000-toolClipCharacters)), len(text))
+       require.Len(t, text, toolClipCharacters+len(fmt.Sprintf("\n[... %d bytes cut ...]\n", 1000*1000-toolClipCharacters)))
 }
 
 // ToolRecordingLog is a chat log that records each append and flush. The flush
index 46c17c728125f326c8ae451669b73f03fc6271c0..f2cec1761d7b36e25d590f159b03f3ad29a938cf 100644 (file)
@@ -80,7 +80,7 @@ func TestTreeReopenLoadsTheSameNodes(t *testing.T) {
 
        data, err := os.ReadFile(filepath.Join(root, "tree", "2026-01-01.jsonl"))
        require.NoError(t, err)
-       require.Equal(t, `{"l":0,"i":1,"text":"reply: b","size":8}`+"\n", strings.SplitAfter(string(data), "\n")[0])
+       require.JSONEq(t, `{"l":0,"i":1,"text":"reply: b","size":8}`+"\n", strings.SplitAfter(string(data), "\n")[0])
 
        tree, err = openTree(t.Context(), root, 2, clock.Now)
        require.NoError(t, err)
index 9bb0e995d5b66393d8c5b46fdeb2480e50e8a233..2763965ea6ad1d6343f49af0f2cfb2685fe28a36 100644 (file)
@@ -3,7 +3,6 @@ package main
 import (
        "context"
        "encoding/json"
-       "errors"
        "log"
        "net/http"
        "path/filepath"
@@ -410,7 +409,7 @@ func newTestTurnLoopWith(t *testing.T, server *ModelFake, summarizer Summarizer)
 
        t.Cleanup(func() {
                cancel()
-               require.True(t, errors.Is(<-done, context.Canceled))
+               require.ErrorIs(t, <-done, context.Canceled)
                require.NoError(t, memory.Close())
        })