Files
coder/coderd/x/chatd/generation_internal_test.go
T
Hugo Dutka 96130e2bc5 chore(coderd/x/chatd): address generation review items (#26517)
Addresses the deferred `coderd/x/chatd/generation.go` review comments
from PR #26109: [required generation
dependencies](https://github.com/coder/coder/pull/26109#discussion_r3380311853),
[scoped chat
variables](https://github.com/coder/coder/pull/26109#discussion_r3387161874),
[generation state error
handling](https://github.com/coder/coder/pull/26109#discussion_r3387191468),
[generation attempt return
values](https://github.com/coder/coder/pull/26109#discussion_r3387251382),
[generation fence
verification](https://github.com/coder/coder/pull/26109#discussion_r3387288234),
and [chatdebug outcome
recording](https://github.com/coder/coder/pull/26109#discussion_r3387544273).

This makes generation task dependencies explicit, packages generation
attempt episode state into a struct, and centralizes generation task
fence checks for generation transitions.

Generated by Coder Agents, closely reviewed by Hugo.
2026-07-06 16:37:45 +00:00

50 lines
1.4 KiB
Go

package chatd //nolint:testpackage // Exercises unexported generation helpers.
import (
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/x/chatd/chatdebug"
"github.com/coder/coder/v2/coderd/x/chatd/chatstate"
"github.com/coder/coder/v2/testutil"
)
func TestRecordGenerationFinishFailure(t *testing.T) {
t.Parallel()
tests := []struct {
name string
err error
wantRecorded bool
}{
{
name: "TerminalFailureRecordsError",
err: normalizeTaskTransitionError(chatstate.ErrTransitionNotAllowed, "finish generation error"),
wantRecorded: true,
},
{
name: "ExpectedExitSkips",
err: normalizeTaskTransitionError(errTaskExpectedExit, "finish generation error"),
wantRecorded: false,
},
{
name: "RetryableSkips",
err: normalizeTaskTransitionError(xerrors.New("transient infrastructure failure"), "finish generation error"),
wantRecorded: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
turn := newRunnerDebugTurn(testutil.Context(t, testutil.WaitShort), testutil.Logger(t))
recordGenerationFinishFailure(turn, tt.err)
require.Equal(t, tt.wantRecorded, turn.statusSet)
if tt.wantRecorded {
require.Equal(t, chatdebug.StatusError, turn.status)
}
})
}
}