From 6f6130fd1239bcad8e86799b06a93c4973cd4b32 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sun, 25 Oct 2026 22:19:38 +0000 Subject: [PATCH] Use production directive extraction in import tests --- docs/roadmap/implementation.md | 8 ++++++++ internal/engine/import_spec.go | 20 -------------------- internal/engine/import_spec_test.go | 8 ++++---- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 158a54f..cbaebb2 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -578,6 +578,14 @@ Focused check: `go test ./internal/engine` and `go test .`. Finding: **F03**. Owners: `internal/engine/import_spec.go`, `import_spec_test.go`, directive/selector tests. +Status: **complete** (F03). Prior completed commits: `2736ddf`, `deb9aa5`, +`ae3408a`, `ea27f17`, `08a8c25`, `877c497`, `8aba43d`, `7bf2f0c`, +`0f9ecf1`, `119b42c`, `247a12b`, `4fcff5f`, `12d350a`, `08f2a8f`, +`826062a`, `e4a5ecb`, `3122e2f`. Validation passed: +`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -run 'Import|Directive|Directory|Glob|SourceVersion' -count=1`, +`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine`, +and `git diff --check`. + Change `parseImportSpecsYAML` to enter `extractRootDirectives` with the appropriate source context and return its imports/diagnostics. Keep parsing source fixtures through the real YAML boundary. Remove `parseImportSpecificationDirective`, its diff --git a/internal/engine/import_spec.go b/internal/engine/import_spec.go index 42defd0..0c5efd8 100644 --- a/internal/engine/import_spec.go +++ b/internal/engine/import_spec.go @@ -179,26 +179,6 @@ func boolOr(explicit, application *bool, fallback bool) bool { return fallback } -// parseImportSpecificationDirective validates every declaration before callers select candidates. -func parseImportSpecificationDirective(node *document.Node, directivePath Path) ([]importDeclarationSpec, []Diagnostic) { - if node.Kind != document.Mapping { - return nil, []Diagnostic{nodeImportDiagnostic(CodeImportInvalid, directivePath, "configuration directive must be a mapping", node)} - } - var specs []importDeclarationSpec - var diagnostics []Diagnostic - for _, entry := range node.Mapping { - fieldPath := directivePath.Key(entry.Key) - if entry.Key != "imports" { - diagnostics = append(diagnostics, nodeImportDiagnostic(CodeImportInvalid, fieldPath, "configuration directive field is not recognized", entry.Value)) - continue - } - parsed, issues := parseImportDeclarations(entry.Value, fieldPath) - specs = append(specs, parsed...) - diagnostics = append(diagnostics, issues...) - } - return specs, canonicalDiagnostics(diagnostics) -} - func parseImportDeclarations(node *document.Node, declarationPath Path) ([]importDeclarationSpec, []Diagnostic) { if node == nil || node.Kind != document.Sequence { return nil, []Diagnostic{nodeImportDiagnostic(CodeImportInvalid, declarationPath, "imports must be a sequence", node)} diff --git a/internal/engine/import_spec_test.go b/internal/engine/import_spec_test.go index 01d92ab..7dc66dc 100644 --- a/internal/engine/import_spec_test.go +++ b/internal/engine/import_spec_test.go @@ -224,11 +224,11 @@ func parseImportSpecsYAML(t *testing.T, declarations string) ([]importDeclaratio if len(diagnostics) != 0 { return nil, diagnostics } - index := documentEntryIndex(parsed.document.Mapping, directiveKey) - if index < 0 { - t.Fatal("missing root directive in test fixture") + extracted, diagnostics := extractRootDirectives(parsed.document, rootDirectiveContextSource) + if len(diagnostics) != 0 { + return nil, diagnostics } - return parseImportSpecificationDirective(parsed.document.Mapping[index].Value, Keys(directiveKey)) + return extracted.imports, nil } type countingImportSpecReader struct {