Show configuration findings when processing cannot start
This commit is contained in:
@@ -158,6 +158,8 @@ stage vocabulary.
|
|||||||
|
|
||||||
## R4 — P2: Show Native Configuration Diagnostics During Processing
|
## R4 — P2: Show Native Configuration Diagnostics During Processing
|
||||||
|
|
||||||
|
**Status:** Completed. Processing now presents native ConfigKit error details through CommandKit and preserves the typed load error. CLI coverage checks migration guidance, an invalid setting, and the absence of output on failure.
|
||||||
|
|
||||||
**Category**
|
**Category**
|
||||||
|
|
||||||
Missing migration guidance and actionable failure detail in
|
Missing migration guidance and actionable failure detail in
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -9,7 +10,9 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
||||||
|
"go.maximumdirect.net/ckconfig"
|
||||||
commandkit "go.maximumdirect.net/commandkit"
|
commandkit "go.maximumdirect.net/commandkit"
|
||||||
|
ck "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// processResult carries the runner's transcript and ordinary report facts.
|
// processResult carries the runner's transcript and ordinary report facts.
|
||||||
@@ -24,6 +27,11 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
|
|||||||
if inv.Context.Err() != nil || llm.IsAssetError(err) {
|
if inv.Context.Err() != nil || llm.IsAssetError(err) {
|
||||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||||
}
|
}
|
||||||
|
var loadErr *ck.LoadError
|
||||||
|
if errors.As(err, &loadErr) {
|
||||||
|
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
|
||||||
|
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||||
|
}
|
||||||
return commandkit.Usage(err.Error()).WithCause(err)
|
return commandkit.Usage(err.Error()).WithCause(err)
|
||||||
}
|
}
|
||||||
prepared, err := prepareProcess(inv.Context, input, loaded, inv.Reporter().Output())
|
prepared, err := prepareProcess(inv.Context, input, loaded, inv.Reporter().Output())
|
||||||
|
|||||||
@@ -3,14 +3,50 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
commandkit "go.maximumdirect.net/commandkit"
|
commandkit "go.maximumdirect.net/commandkit"
|
||||||
|
ck "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestProcessShowsConfigurationLoadDiagnostics(t *testing.T) {
|
||||||
|
app, err := buildApplication()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name, config, finding string
|
||||||
|
}{
|
||||||
|
{"obsolete version", "version: 2\n", "docs/migrations/v3.md"},
|
||||||
|
{"invalid retry budget", "version: 3\nllm: {transient_retries: -1}\n", "retry budget must be non-negative"},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
configPath := filepath.Join(dir, "config.yml")
|
||||||
|
if err := os.WriteFile(configPath, []byte(tc.config), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
output := filepath.Join(dir, "out.json")
|
||||||
|
var out, stderr bytes.Buffer
|
||||||
|
args := []string{"process", "--quiet", "--config", configPath, "--output", output, filepath.Join(dir, "transcript.json")}
|
||||||
|
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
|
||||||
|
var loadErr *ck.LoadError
|
||||||
|
if result.Status != 2 || !errors.As(result.Cause, &loadErr) || out.Len() != 0 ||
|
||||||
|
!strings.Contains(stderr.String(), tc.finding) || !strings.Contains(stderr.String(), configPath) {
|
||||||
|
t.Fatalf("status=%d cause=%v out=%q err=%q", result.Status, result.Cause, out.String(), stderr.String())
|
||||||
|
}
|
||||||
|
entries, err := os.ReadDir(dir)
|
||||||
|
if err != nil || len(entries) != 1 {
|
||||||
|
t.Fatalf("outputs created on load failure: %v, err=%v", entries, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcessUsesResolvedReportingMode(t *testing.T) {
|
func TestProcessUsesResolvedReportingMode(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
for name, contents := range map[string]string{
|
for name, contents := range map[string]string{
|
||||||
|
|||||||
Reference in New Issue
Block a user