Files
coder/provisioner/terraform/serve_internal_test.go
T
edee917d88 feat: add experimental agents support (#22290)
feat: add AI chat system with agent tools and chat UI

Introduce the chatd subsystem and Agents UI for AI-powered chat
within Coder workspaces.

- Add chatd package with chat loop, message compaction, prompt
  management, and LLM provider integration (OpenAI, Anthropic)
- Add agent tools: create workspace, list/read templates, read/write/
  edit files, execute commands
- Add chat API endpoints with streaming, message editing, and
  durable reconnection
- Add database schema and migrations for chats, chat messages, chat
  providers, and chat model configs
- Add RBAC policies and dbauthz enforcement for chat resources
- Add Agents UI pages with conversation timeline, queued messages
  list, diff viewer, and model configuration panel
- Add comprehensive test coverage including coderd integration tests,
  chatd unit tests, and Storybook stories
- Gate feature behind experiments flag

---------

Co-authored-by: Cian Johnston <cian@coder.com>
Co-authored-by: Danielle Maywood <danielle@themaywoods.com>
Co-authored-by: Jeremy Ruppel <jeremy@coder.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 16:50:56 +00:00

99 lines
2.3 KiB
Go

package terraform
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/testutil"
)
// nolint:paralleltest
func Test_absoluteBinaryPath(t *testing.T) {
tests := []struct {
name string
terraformVersion string
expectedErr error
}{
{
name: "TestCorrectVersion",
terraformVersion: "1.3.0",
expectedErr: nil,
},
{
name: "TestOldVersion",
terraformVersion: "1.0.9",
expectedErr: errTerraformMinorVersionMismatch,
},
{
name: "TestNewVersion",
terraformVersion: "1.3.0",
expectedErr: nil,
},
{
name: "TestNewestNewVersion",
terraformVersion: "9.9.9",
expectedErr: nil,
},
{
name: "TestMalformedVersion",
terraformVersion: "version",
expectedErr: xerrors.Errorf("Terraform binary get version failed: malformed version: version"),
},
}
// nolint:paralleltest
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Dummy terraform executable on Windows requires sh which isn't very practical.")
}
// Create a temp dir with the binary
tempDir := t.TempDir()
terraformBinaryOutput := fmt.Sprintf(`#!/bin/sh
cat <<-EOF
{
"terraform_version": "%s",
"platform": "linux_amd64",
"provider_selections": {},
"terraform_outdated": false
}
EOF`, tt.terraformVersion)
// #nosec
err := os.WriteFile(
filepath.Join(tempDir, "terraform"),
[]byte(terraformBinaryOutput),
0o770,
)
require.NoError(t, err)
// Add the binary to PATH
pathVariable := os.Getenv("PATH")
t.Setenv("PATH", strings.Join([]string{tempDir, pathVariable}, ":"))
var expectedAbsoluteBinary string
if tt.expectedErr == nil {
expectedAbsoluteBinary = filepath.Join(tempDir, "terraform")
}
ctx := testutil.Context(t, testutil.WaitShort)
actualBinaryDetails, actualErr := systemBinary(ctx)
if tt.expectedErr == nil {
require.NoError(t, actualErr)
require.Equal(t, expectedAbsoluteBinary, actualBinaryDetails.absolutePath)
require.Equal(t, tt.terraformVersion, actualBinaryDetails.version.String())
} else {
require.EqualError(t, actualErr, tt.expectedErr.Error())
}
})
}
}