Classify configuration acquisition errors consistently
This commit is contained in:
@@ -232,6 +232,11 @@ model's own budget, and retain live progress and presentation-failure coverage.
|
|||||||
|
|
||||||
### R7 — Classify Configuration Acquisition Errors Consistently (P2)
|
### R7 — Classify Configuration Acquisition Errors Consistently (P2)
|
||||||
|
|
||||||
|
**Complete.** Processing uses the native configuration error classifier and
|
||||||
|
retains source diagnostics and typed causes. Tests compare processing,
|
||||||
|
catalog listing, and configuration inspection for malformed content,
|
||||||
|
permission failure, and caller cancellation.
|
||||||
|
|
||||||
**Affected plan:** Stages 1, 11, and 20.
|
**Affected plan:** Stages 1, 11, and 20.
|
||||||
|
|
||||||
**Evidence:** The adopted `ckconfig` v0.8.0 and `ckprompt` v0.9.0 paths use
|
**Evidence:** The adopted `ckconfig` v0.8.0 and `ckprompt` v0.9.0 paths use
|
||||||
|
|||||||
@@ -26,13 +26,19 @@ type processResult struct {
|
|||||||
func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcome {
|
func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcome {
|
||||||
loaded, err := loadProcessInputs(inv.Context, input, inv.ReportingMode())
|
loaded, err := loadProcessInputs(inv.Context, input, inv.ReportingMode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if inv.Context.Err() != nil || llm.IsAssetError(err) {
|
if canceled := inv.Context.Err(); canceled != nil && !errors.Is(err, canceled) {
|
||||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
err = errors.Join(err, canceled)
|
||||||
}
|
}
|
||||||
var loadErr *ck.LoadError
|
var loadErr *ck.LoadError
|
||||||
if errors.As(err, &loadErr) {
|
if errors.As(err, &loadErr) {
|
||||||
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
|
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
|
||||||
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
if ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
|
||||||
|
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||||
|
}
|
||||||
|
return commandkit.Failure(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||||
|
}
|
||||||
|
if inv.Context.Err() != nil || llm.IsAssetError(err) {
|
||||||
|
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||||
}
|
}
|
||||||
return commandkit.Usage(err.Error()).WithCause(err)
|
return commandkit.Usage(err.Error()).WithCause(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,32 @@ func TestMalformedCompanionReturnsInputFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnreadableCompanionReturnsOperationalFailure(t *testing.T) {
|
||||||
|
main := writeRuntimeErrorConfig(t, "profiles: []\n")
|
||||||
|
companion := filepath.Join(filepath.Dir(main), "prompts.yml")
|
||||||
|
if err := os.Chmod(companion, 0); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := os.ReadFile(companion); !errors.Is(err, os.ErrPermission) {
|
||||||
|
t.Skipf("file permissions do not prevent reads: %v", err)
|
||||||
|
}
|
||||||
|
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
|
||||||
|
if err := os.WriteFile(transcript, []byte("[]\n"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, args := range [][]string{
|
||||||
|
{"promptkit", "list", "prompts"},
|
||||||
|
{"config", "show", "--scope", "promptkit"},
|
||||||
|
{"process", transcript},
|
||||||
|
} {
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
code := Run(context.Background(), append(args, "--config", main), &stdout, &stderr)
|
||||||
|
if code != 1 || !strings.Contains(stderr.String(), "source.permission") || !strings.Contains(stderr.String(), "prompts.yml") || stdout.Len() != 0 {
|
||||||
|
t.Errorf("%v: status=%d want=1 stdout=%q stderr=%q", args, code, stdout.String(), stderr.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestResourceCommandKeepsCallerCancellationAsFailure(t *testing.T) {
|
func TestResourceCommandKeepsCallerCancellationAsFailure(t *testing.T) {
|
||||||
main := writeRuntimeErrorConfig(t, "profiles:\n - id: proposal\n model: local-model\n")
|
main := writeRuntimeErrorConfig(t, "profiles:\n - id: proposal\n model: local-model\n")
|
||||||
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
|
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
|
||||||
|
|||||||
Reference in New Issue
Block a user