Files
goclaw/internal/tools/credential_context_test.go
T
viettranx 17170b404e fix(tools): scope credentialed-CLI blocked-command wording to [CREDENTIALED EXEC] marker
Generic "operation requires admin approval" wording was over-applied
by the LLM to plain shell exec failures, causing unjustified pre-refusals.
Scope the section to commands returning the [CREDENTIALED EXEC] error
marker (already emitted at 7 sites in credentialed_exec.go).

Adds characterization test pinning the new wording and rejecting the
unqualified phrase.
2026-04-24 20:53:28 +07:00

41 lines
1.3 KiB
Go

package tools
import (
"strings"
"testing"
"github.com/nextlevelbuilder/goclaw/internal/store"
)
// TestGenerateCredentialContext_BlockedSectionScopedToMarker pins the wording
// that scopes the "blocked command" guidance to credentialed-CLI errors only.
// The LLM must see: (a) a header that says "credentialed CLI command",
// (b) the literal `[CREDENTIALED EXEC]` marker, and (c) the qualifier
// "credentialed CLI operation" — not the bare phrase from previous wording.
func TestGenerateCredentialContext_BlockedSectionScopedToMarker(t *testing.T) {
creds := []store.SecureCLIBinary{{
BinaryName: "gh",
Description: "GitHub CLI",
}}
out := GenerateCredentialContext(creds)
wantContains := []string{
"### When a credentialed CLI command is blocked:",
"[CREDENTIALED EXEC]",
"credentialed CLI operation",
}
for _, s := range wantContains {
if !strings.Contains(out, s) {
t.Errorf("expected output to contain %q, but it did not.\nOutput:\n%s", s, out)
}
}
// Old unqualified wording must not survive — that wording over-generalized
// to plain shell exec failures and caused unjustified pre-refusals.
dontWant := "Tell the user: \"This operation requires admin approval"
if strings.Contains(out, dontWant) {
t.Errorf("output still contains unqualified wording %q.\nOutput:\n%s", dontWant, out)
}
}