mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-13 11:40:53 +08:00
Comments, doc comments, UI labels, log and error messages, LLM prompt strings, markdown docs, test data and assertions. Identifiers, enum keys, routes, placeholders and code structure are unchanged. Notes: - docs/漏洞流量证据.md renamed to docs/vulnerability-traffic-evidence.md - tests that exercised CJK specific handling (GBK zip names, Chinese full text search) now use ASCII equivalents; go build passes and the test suite matches the pre translation baseline (remaining failures need a PostgreSQL DSN and fail identically on the original) - frontend mention syntax now uses English kinds (finding, asset, ...) matching the backend, chat mentions tests pass
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestChatNowVarRenders verifies the universal {{.Now}} runtime variable: a custom
|
|
// (chat) agent prompt referencing it renders the live server time each turn, rather
|
|
// than failing template execution and falling back to DefaultAssistantPrompt.
|
|
func TestChatNowVarRenders(t *testing.T) {
|
|
prev := PromptOverride
|
|
defer func() { PromptOverride = prev }()
|
|
|
|
PromptOverride = func(key string) (string, bool) {
|
|
if key == "tec_benchmark" {
|
|
return "Current time: {{.Now}}", true
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
out := chatSystem("tec_benchmark", "/app/data", "/tmp/x")
|
|
if !strings.Contains(out, "Current time: ") {
|
|
t.Fatalf("custom prompt body missing, likely fell back to default: %q", out)
|
|
}
|
|
year := time.Now().Format("2006")
|
|
if !strings.Contains(out, year) {
|
|
t.Fatalf("{{.Now}} did not render the live time (want year %s): %q", year, out)
|
|
}
|
|
}
|
|
|
|
// TestChatDataDirVarRenders verifies the universal {{.DataDir}} runtime variable:
|
|
// a custom prompt referencing it renders the server data root (s.m.dir), rather
|
|
// than failing template execution and falling back to DefaultAssistantPrompt.
|
|
func TestChatDataDirVarRenders(t *testing.T) {
|
|
prev := PromptOverride
|
|
defer func() { PromptOverride = prev }()
|
|
|
|
PromptOverride = func(key string) (string, bool) {
|
|
return "Data root: {{.DataDir}}", true
|
|
}
|
|
|
|
out := chatSystem("tec_benchmark", "/app/data", "/tmp/x")
|
|
if !strings.Contains(out, "Data root: /app/data") {
|
|
t.Fatalf("{{.DataDir}} did not render the data root: %q", out)
|
|
}
|
|
}
|
|
|
|
// TestChatUnknownVarFallsBack verifies an out-of-catalog {{.X}} still degrades
|
|
// safely to the default assistant prompt (never a half-rendered prompt).
|
|
func TestChatUnknownVarFallsBack(t *testing.T) {
|
|
prev := PromptOverride
|
|
defer func() { PromptOverride = prev }()
|
|
|
|
PromptOverride = func(key string) (string, bool) {
|
|
return "References a nonexistent variable: {{.Bogus}}", true
|
|
}
|
|
|
|
out := chatSystem("whatever", "/app/data", "/tmp/x")
|
|
if strings.Contains(out, "References a nonexistent variable") {
|
|
t.Fatalf("broken template should have fallen back, got custom body: %q", out)
|
|
}
|
|
if !strings.Contains(out, DefaultAssistantPrompt) {
|
|
t.Fatalf("expected fallback to DefaultAssistantPrompt, got: %q", out)
|
|
}
|
|
}
|