feat(ai): test saved summary model generation (#43)
This commit is contained in:
51
backend/internal/ai/model_probe_cli_ticket43_test.go
Normal file
51
backend/internal/ai/model_probe_cli_ticket43_test.go
Normal file
@ -0,0 +1,51 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicket43ClaudeModelTestUsesStructuredNonemptyResultAndBoundedChildOptions(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
script := `#!/bin/sh
|
||||
[ "$CLAUDE_CODE_MAX_OUTPUT_TOKENS" = 16 ] || exit 1
|
||||
[ "$CLAUDE_CODE_MAX_RETRIES" = 0 ] || exit 1
|
||||
[ -z "$CLAUDE_CODE_RETRY_WATCHDOG" ] || exit 1
|
||||
case " $* " in *" --output-format json "*) ;; *) exit 1;; esac
|
||||
case " $* " in *" --no-session-persistence "*) ;; *) exit 1;; esac
|
||||
printf '%s' '{"type":"result","subtype":"success","is_error":false,"result":"PRIVATE_GENERATED_RESULT"}'
|
||||
printf '%s' 'PRIVATE_STDERR' >&2
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(directory, "claude"), []byte(script), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", directory+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
t.Setenv("CLAUDE_CODE_MAX_OUTPUT_TOKENS", "9999")
|
||||
t.Setenv("CLAUDE_CODE_MAX_RETRIES", "10")
|
||||
t.Setenv("CLAUDE_CODE_RETRY_WATCHDOG", "1")
|
||||
// Use the same marked context as the admin test service.
|
||||
ctx := context.WithValue(context.Background(), modelTestContextKey{}, true)
|
||||
response, err := newClaudeCode("exact-saved-model").Summarize(ctx, modelTestPrompt, GenOptions{MaxOutputTokens: modelTestMaxOutputTokens})
|
||||
if err != nil || response != "PRIVATE_GENERATED_RESULT" {
|
||||
t.Fatal("CLI test options or structured generation result missing")
|
||||
}
|
||||
}
|
||||
func TestTicket43ClaudeErrorEnvelopeCannotBecomeSuccessfulGeneratedText(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
script := `#!/bin/sh
|
||||
printf '%s' '{"type":"result","subtype":"error_during_execution","is_error":true,"result":"PRIVATE_ERROR_TEXT"}'
|
||||
printf '%s' 'PRIVATE_STDERR' >&2
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(directory, "claude"), []byte(script), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", directory+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
ctx := context.WithValue(context.Background(), modelTestContextKey{}, true)
|
||||
response, err := newClaudeCode("exact").Summarize(ctx, modelTestPrompt, GenOptions{MaxOutputTokens: modelTestMaxOutputTokens})
|
||||
if err == nil || response != "" || strings.Contains(err.Error(), "PRIVATE") {
|
||||
t.Fatal("CLI error envelope leaked or became generated content")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user