Files
Agent-System/internal/app/pi_swboot_test.go
T
weichenandCursor eee42d1d16 feat(workflow-design): catalog-driven software create wizard and docs_only PI
Software projects mount only bootstrap/delivery keys and skip the medical
seven-template clone. SWBOOT-10 stays a fail-closed stub.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 04:11:03 +00:00

96 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package app
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"
"chat-agent-system/internal/agent"
"chat-agent-system/internal/config"
)
type recordingSwbootBackend struct {
last agent.Request
body string
}
func (r *recordingSwbootBackend) Name() string { return "recording-swboot" }
func (r *recordingSwbootBackend) Execute(_ context.Context, req agent.Request) (*agent.Result, error) {
r.last = req
body := r.body
if body == "" {
body = "建议后续创建 software_delivery,auto_activate=false"
}
return &agent.Result{Success: true, Patches: map[string][]byte{"bootstrap.md": []byte(body)}}, nil
}
func TestPiSoftwareBootstrapAdvisor_NoTools(t *testing.T) {
rec := &recordingSwbootBackend{}
p := &PiSoftwareBootstrapAdvisor{Backend: rec}
got, err := p.Advise(context.Background(), "自举", "docs_only")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(got, "software_delivery") {
t.Fatalf("got=%s", got)
}
if !strings.Contains(strings.ToLower(rec.last.Instructions), "zero tool") {
t.Fatalf("instructions=%s", rec.last.Instructions)
}
}
func TestPiSoftwareBootstrapAdvisor_RejectsControlledPatch(t *testing.T) {
p := &PiSoftwareBootstrapAdvisor{Backend: &recordingSwbootBackend{}}
if _, err := p.Advise(context.Background(), "x", "controlled_patch"); err == nil {
t.Fatal("controlled_patch must be rejected in W5a")
}
}
func TestPiSoftwareBootstrapAdvisor_LiveMiniMax(t *testing.T) {
if os.Getenv("RUN_PI_E2E") != "1" {
t.Skip("set RUN_PI_E2E=1 for live PI software bootstrap")
}
if testing.Short() {
t.Skip("live PI is not a -short test")
}
if err := os.Chdir(filepath.Clean(filepath.Join("..", ".."))); err != nil {
t.Fatal(err)
}
cfg, err := config.Load("")
if err != nil || cfg == nil {
t.Fatalf("config: %v", err)
}
if strings.TrimSpace(cfg.PiAgentRunnerAuthToken) == "" {
if tok := runnerTokenFromDotenv(); tok != "" {
cfg.PiAgentRunnerAuthToken = tok
}
}
if strings.TrimSpace(cfg.PiAgentRunnerAuthToken) == "" {
t.Fatal("runner auth token missing")
}
cfg.PiAgentRunnerURL = "http://127.0.0.1:18865"
dataDir, err := filepath.Abs("data/dev")
if err != nil {
t.Fatal(err)
}
p := &PiSoftwareBootstrapAdvisor{
Backend: agent.NewBackend("pi-agent", cfg),
Model: cfg.PiAgentModel,
Timeout: 4 * time.Minute,
DataDir: dataDir,
}
start := time.Now()
got, err := p.Advise(context.Background(), "Agent-System 自举", "docs_only")
if err != nil {
t.Fatalf("live advise: %v", err)
}
t.Logf("elapsed=%s narrative=%s", time.Since(start).Round(time.Millisecond), got)
if !strings.Contains(got, "software_delivery") && !strings.Contains(got, "交付") {
t.Fatalf("expected delivery suggestion: %s", got)
}
}