Validate explanation pointers before loading configuration
This commit is contained in:
@@ -78,7 +78,10 @@ Validation: `GOWORK=off go test ./internal/framework/llm ./internal/cli ./intern
|
|||||||
|
|
||||||
## Finding 2 — Validate Explanation Syntax Before Loading Configuration
|
## 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
|
Evidence: `internal/cli/configkit_commands.go:77–106`. PromptKit scope loads
|
||||||
Notarius configuration and constructs the inspection engine before validating
|
Notarius configuration and constructs the inspection engine before validating
|
||||||
|
|||||||
@@ -75,6 +75,11 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
pointer := fs.Arg(0)
|
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" {
|
if *scope == "promptkit" {
|
||||||
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -101,11 +106,6 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
|||||||
}
|
}
|
||||||
return 0
|
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)
|
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeConfigLoadError(stderr, err)
|
writeConfigLoadError(stderr, err)
|
||||||
|
|||||||
@@ -15,6 +15,23 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
"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) {
|
func TestConfigKitReadOnlyCommandsLoadImportsAndOverlays(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
|
|||||||
Reference in New Issue
Block a user