feat: update AI command to streamline token management and remove unnecessary flags

This commit is contained in:
2025-11-04 18:17:56 +08:00
parent 3867736858
commit ad8ca2b1f7
9 changed files with 265 additions and 327 deletions

View File

@@ -44,7 +44,7 @@ func TestAIApplyAndUndoFlow(t *testing.T) {
writeFile(t, filepath.Join(root, "draft_one.txt"))
writeFile(t, filepath.Join(root, "draft_two.txt"))
planPath := filepath.Join(root, "ai-plan.json")
planPath := filepath.Join(root, "renamer.plan.json")
preview := renamercmd.NewRootCommand()
var previewOut, previewErr bytes.Buffer
@@ -54,7 +54,6 @@ func TestAIApplyAndUndoFlow(t *testing.T) {
"ai",
"--path", root,
"--dry-run",
"--export-plan", planPath,
})
if err := preview.Execute(); err != nil {
@@ -124,7 +123,6 @@ func TestAIApplyAndUndoFlow(t *testing.T) {
"ai",
"--path", root,
"--dry-run",
"--import-plan", planPath,
})
if err := previewEdited.Execute(); err != nil {
@@ -148,7 +146,6 @@ func TestAIApplyAndUndoFlow(t *testing.T) {
applyCmd.SetArgs([]string{
"ai",
"--path", root,
"--import-plan", planPath,
"--yes",
})

View File

@@ -47,9 +47,6 @@ func TestAIPolicyValidationFailsWithActionableMessage(t *testing.T) {
"ai",
"--path", rootDir,
"--dry-run",
"--naming-casing", "kebab",
"--naming-prefix", "proj",
"--banned", "offer",
})
err := rootCmd.Execute()
@@ -58,9 +55,6 @@ func TestAIPolicyValidationFailsWithActionableMessage(t *testing.T) {
}
lines := stderr.String()
if !strings.Contains(lines, "Policy violation (prefix)") {
t.Fatalf("expected prefix violation message in stderr, got: %s", lines)
}
if !strings.Contains(lines, "Policy violation (banned)") {
t.Fatalf("expected banned token message in stderr, got: %s", lines)
}

View File

@@ -53,19 +53,18 @@ func TestAIPreviewFlowRendersSequenceTable(t *testing.T) {
createAIPreviewFile(t, filepath.Join(root, "promo SALE 01.JPG"))
createAIPreviewFile(t, filepath.Join(root, "family_photo.png"))
t.Setenv("default_MODEL_AUTH_TOKEN", "test-token")
t.Setenv("OPENAI_TOKEN", "test-token")
rootCmd := renamercmd.NewRootCommand()
var stdout, stderr bytes.Buffer
rootCmd.SetOut(&stdout)
rootCmd.SetErr(&stderr)
exportPath := filepath.Join(root, "plan.json")
exportPath := filepath.Join(root, "renamer.plan.json")
rootCmd.SetArgs([]string{
"ai",
"--path", root,
"--dry-run",
"--debug-genkit",
"--export-plan", exportPath,
})
if err := rootCmd.Execute(); err != nil {