Files
coder/agent/x/agentacp/process_internal_test.go
T
Hugo Dutka 78a681fb9f fix: route ACP diagnostics through Coder logging (#31405)
Route ACP SDK diagnostics through the workspace agent's Coder logger
instead of the process-wide standard slog logger, which Trivy replaces
with an unsafe buffering handler. Install the logger before starting the
harness so even immediate output and disconnects use the configured
logger.

Bump the ACP SDK to commit `0da7315c23b5`, which merged the synchronized
`SetLogger` fix into SDK main in
https://github.com/coder/acp-go-sdk/pull/59. Preserve diagnostic levels
and structured fields, identify the harness, and omit raw protocol
frames that can contain conversation content or workspace secrets. The
previous Trivy dependency update is removed;
https://github.com/coder/trivy/pull/87 is closed as superseded.

Fixes
https://linear.app/codercom/issue/ENG-3489/flake-testagent-acpreadiness-data-race-in-trivy-slog-deferredhandler

Generated by Coder Agents on behalf of @hugodutka.
2026-10-29 10:54:04 +01:00

52 lines
1.4 KiB
Go

package agentacp
import (
"fmt"
"os"
"runtime"
"testing"
"github.com/stretchr/testify/require"
"cdr.dev/slog/v3"
"github.com/coder/coder/v2/agent/agentexec"
"github.com/coder/coder/v2/testutil"
"github.com/coder/quartz"
)
func TestProcessLogger(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("shell scripts")
}
sink := testutil.NewFakeSink(t)
ctx := testutil.Context(t, testutil.WaitLong)
p, err := launch(ctx, harnessConfig{
slug: "fake",
// Emit malformed output immediately, then keep stdout open.
command: `printf '%s\n' '{"private":"workspace-secret-marker"'; cat`,
}, t.TempDir(), &discoveryClient{}, launchOptions{
logger: sink.Logger(),
clock: quartz.NewMock(t),
execer: agentexec.DefaultExecer,
envInfo: testEnv{home: t.TempDir()},
env: os.Environ(),
})
require.NoError(t, err)
t.Cleanup(p.close)
var entries []slog.SinkEntry
require.Eventually(t, func() bool {
entries = sink.Entries(func(entry slog.SinkEntry) bool {
return entry.Message == "failed to parse incoming message"
})
return len(entries) > 0
}, testutil.WaitLong, testutil.IntervalFast)
require.Len(t, entries, 1)
require.Equal(t, slog.LevelError, entries[0].Level)
require.Equal(t, []string{"transport"}, entries[0].LoggerNames)
require.Contains(t, entries[0].Fields, slog.F("harness", "fake"))
require.NotContains(t, fmt.Sprint(entries), "workspace-secret-marker")
}