Complete library adoption validation and cleanup
This commit is contained in:
@@ -41,6 +41,10 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
|
||||
if errors.As(err, &secretsErr) {
|
||||
return commandkit.Failure(secretsErr.Error()).WithCause(err)
|
||||
}
|
||||
var runtimeErr *runtimePreparationError
|
||||
if errors.As(err, &runtimeErr) {
|
||||
return commandkit.Failure(err.Error()).WithCause(err)
|
||||
}
|
||||
if inv.Context.Err() != nil || appconfig.IsAssetError(err) {
|
||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,11 @@ type processInputs struct {
|
||||
ProtectedPaths []string
|
||||
}
|
||||
|
||||
type runtimePreparationError struct{ cause error }
|
||||
|
||||
func (e *runtimePreparationError) Error() string { return e.cause.Error() }
|
||||
func (e *runtimePreparationError) Unwrap() error { return e.cause }
|
||||
|
||||
func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.ReportingMode) (*processInputs, error) {
|
||||
if mode == commandkit.ReportingModeQuiet && input.Output.Value == "" {
|
||||
return nil, fmt.Errorf("quiet processing requires an output file or /dev/null")
|
||||
@@ -44,7 +49,7 @@ func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.
|
||||
}
|
||||
runtime, err := llm.NewRuntime(ctx, loaded, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, &runtimePreparationError{cause: err}
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -60,6 +60,19 @@ func TestMalformedCompanionReturnsInputFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimePreparationFailureIsOperational(t *testing.T) {
|
||||
main := writeRuntimeErrorConfig(t, "collections:\n audita:\n prompts:\n - id: modules.grammar.proposal\n messages:\n - role: user\n content: '{{'\n output:\n format: text\n validation_mode: none\n")
|
||||
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
|
||||
if err := os.WriteFile(transcript, []byte("[]\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stdout, stderr bytes.Buffer
|
||||
status := Run(context.Background(), []string{"process", transcript, "--config", main}, &stdout, &stderr)
|
||||
if status != 1 || stdout.Len() != 0 {
|
||||
t.Fatalf("runtime error: status=%d stdout=%q stderr=%q", status, stdout.String(), stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnreadableCompanionReturnsOperationalFailure(t *testing.T) {
|
||||
main := writeRuntimeErrorConfig(t, "profiles: []\n")
|
||||
companion := filepath.Join(filepath.Dir(main), "prompts.yml")
|
||||
|
||||
Reference in New Issue
Block a user