bdc589e1c0
Cross-cutting cleanup that lands alongside the new feature surface: - `--limit / -L` and `--all-pages` on every list command. Default --limit 30 (gh-parity); --all-pages drains every server page client-side, capped by --limit. Closes the audit finding that the old "1000 max per call" implicit cap was undiscoverable. - `auth token` emits a TTY-only stderr advisory when stdout is a terminal (the credential just got displayed in scrollback) plus an api-key-mode rotation hint. - Comment + doc discipline pass: drop external project name references from in-code comments (we reference them in design notes, not inline). - Bump `go` directive to 1.26.0 and CI matrix to 1.26.x to align with the main module's go.mod. - Rename `cli/internal/agent` → `cli/internal/aiclient` to disambiguate from the new `cli/cmd/agent` resource subtree. The package handles AI coding-agent env detection + per-command --help annotations; the new name reflects that more precisely.
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package aiclient
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// clearAgentEnv unsets every env var DetectAIAgent inspects, so a developer
|
|
// running these tests from inside Claude Code / Cursor doesn't see false
|
|
// positives.
|
|
func clearAgentEnv(t *testing.T) {
|
|
t.Helper()
|
|
for _, a := range aiAgentEnvs {
|
|
t.Setenv(a.env, "")
|
|
}
|
|
t.Setenv("WEKNORA_NO_AGENT_AUTODETECT", "")
|
|
t.Setenv("WEKNORA_AGENT", "")
|
|
}
|
|
|
|
func TestDetectAIAgent(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
set map[string]string
|
|
want AIAgentName
|
|
}{
|
|
{name: "empty env", set: nil, want: ""},
|
|
{name: "unrelated env", set: map[string]string{"PATH": "/usr/bin"}, want: ""},
|
|
{name: "claude code", set: map[string]string{"CLAUDECODE": "1"}, want: "claude-code"},
|
|
{name: "cursor", set: map[string]string{"CURSOR_AGENT": "yes"}, want: "cursor"},
|
|
// Other entries (codex / aider / continue / opencode / gemini-coder)
|
|
// were dropped in v0.2 ADR-3 — env names had no official agent docs.
|
|
// New entries should arrive with a documented source URL.
|
|
{
|
|
name: "first-match precedence",
|
|
set: map[string]string{"CLAUDECODE": "1", "CURSOR_AGENT": "1"},
|
|
want: "claude-code",
|
|
},
|
|
{name: "empty value treated as unset", set: map[string]string{"CLAUDECODE": ""}, want: ""},
|
|
{
|
|
name: "WEKNORA_NO_AGENT_AUTODETECT=1 suppresses detection",
|
|
set: map[string]string{"CLAUDECODE": "1", "WEKNORA_NO_AGENT_AUTODETECT": "1"},
|
|
want: "",
|
|
},
|
|
{
|
|
name: "WEKNORA_NO_AGENT_AUTODETECT=0 still allows detection",
|
|
set: map[string]string{"CLAUDECODE": "1", "WEKNORA_NO_AGENT_AUTODETECT": "0"},
|
|
want: "claude-code",
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
clearAgentEnv(t)
|
|
for k, v := range tc.set {
|
|
t.Setenv(k, v)
|
|
}
|
|
assert.Equal(t, tc.want, DetectAIAgent())
|
|
})
|
|
}
|
|
}
|
|
|