Validate explanation pointers before loading configuration

This commit is contained in:
2026-11-18 00:29:56 +00:00
parent 347ef05b41
commit 0663fe566a
3 changed files with 26 additions and 6 deletions

View File

@@ -78,7 +78,10 @@ Validation: `GOWORK=off go test ./internal/framework/llm ./internal/cli ./intern
## Finding 2 — Validate Explanation Syntax Before Loading Configuration
Priority: P3. Category: CLI correctness. Status: open.
Priority: P3. Category: CLI correctness. Status: complete.
Completed 2026-11-18: both scopes validate canonical pointer syntax before
loading configuration. Missing-file regression and CLI/LLM suites pass.
Evidence: `internal/cli/configkit_commands.go:77–106`. PromptKit scope loads
Notarius configuration and constructs the inspection engine before validating

View File

@@ -75,6 +75,11 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
return 2
}
pointer := fs.Arg(0)
parsed, err := configkit.ParsePath(pointer)
if err != nil || parsed.String() != pointer {
fmt.Fprintf(stderr, "notarius: %q is not a canonical JSON Pointer\n", pointer)
return 2
}
if *scope == "promptkit" {
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
if err != nil {
@@ -101,11 +106,6 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
}
return 0
}
parsed, err := configkit.ParsePath(pointer)
if err != nil || parsed.String() != pointer {
fmt.Fprintf(stderr, "notarius: %q is not a canonical JSON Pointer\n", pointer)
return 2
}
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
if err != nil {
writeConfigLoadError(stderr, err)

View File

@@ -15,6 +15,23 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)
func TestExplainRejectsMalformedPointerBeforeLoadingEitherScope(t *testing.T) {
for _, scope := range []string{"notarius", "promptkit"} {
t.Run(scope, func(t *testing.T) {
var stdout, stderr strings.Builder
options := commandContractOptions(t)
options.LookupEnv = func(string) (string, bool) {
t.Fatal("configuration discovery ran for invalid syntax")
return "", false
}
code := RunWithOptions([]string{"config", "explain", "--scope", scope, "--config", filepath.Join(t.TempDir(), "missing.yml"), "/profiles/~2"}, &stdout, &stderr, options)
if code != 2 || stdout.Len() != 0 || !strings.Contains(stderr.String(), "canonical JSON Pointer") {
t.Fatalf("code=%d stdout=%q stderr=%q", code, stdout.String(), stderr.String())
}
})
}
}
func TestConfigKitReadOnlyCommandsLoadImportsAndOverlays(t *testing.T) {
t.Parallel()
root := t.TempDir()