diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 2f18d8af..4b3cd619 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -1,5 +1,13 @@ # Configuration Upgrade Review Remediation +All eight findings were completed on 2026-11-18, with one commit per finding. +Assessment and evidence paragraphs below retain their review-time context; +each finding's completion marker records the implemented resolution. + +Final verification passed: full offline tests, vet, race checks for configuration, +CLI and LLM packages, module tidy consistency, a native temporary build, and +credential-free minimal/complete/development configuration and inspection checks. + The earlier PromptKit findings below retain their original scope and status. The ConfigKit 1.2.0 review and subsequent focused audits appear below; they do not reopen or attribute earlier issues to that upgrade. @@ -444,7 +452,12 @@ retain their earlier scope and status. ### Finding CK-4 — Memoize Source Directories During Path Normalization -Priority: P3. Category: efficiency/scalability opportunity. Status: open. +Priority: P3. Category: efficiency/scalability opportunity. Status: complete. + +Completed 2026-11-18: source-directory results, including missing/non-file +results, are memoized by source ID in load-local state. Main-directory setup +shares the lookup. Cache-sharing/isolation and existing path-origin tests pass; +the full offline suite, vet, race, and tidy checks pass. Path policy is unchanged. Affected stages: 2–3; exposed by adoption of richer ConfigKit source metadata. `internal/core/config/document_paths.go:144–176`, `documentPathBase`, calls diff --git a/internal/core/config/document_paths.go b/internal/core/config/document_paths.go index d4d23b4b..fac2371d 100644 --- a/internal/core/config/document_paths.go +++ b/internal/core/config/document_paths.go @@ -70,8 +70,8 @@ func initializeDocumentMainDirectory(resolution *configkit.Resolution, state *do } info, ok := resolution.EntryInfo(configkit.Keys("version")) if ok && len(info.Origin.Locations) == 1 { - if source, sourceOK := resolution.Source(info.Origin.Locations[0].SourceID); sourceOK && source.Path != "" { - state.mainDirectory = filepath.Dir(source.Path) + if directory := state.sourceDirectory(info.Origin.Locations[0].SourceID, resolution.Source); directory != "" { + state.mainDirectory = directory return } } @@ -166,14 +166,35 @@ func documentPathBase(resolution *configkit.Resolution, state *documentLoadState if len(info.Origin.Locations) != 1 { return "", false } - source, ok := resolution.Source(info.Origin.Locations[0].SourceID) - if !ok || source.Path == "" { + directory := state.sourceDirectory(info.Origin.Locations[0].SourceID, resolution.Source) + if directory == "" { if state != nil && state.mainDirectory != "" { return state.mainDirectory, true } return "", false } - return filepath.Dir(source.Path), true + return directory, true } return "", false } + +// Source evidence is fixed during resolution. Cache only the directory needed +// by paths, avoiding repeated copies of unrelated import-selection evidence. +func (state *documentLoadState) sourceDirectory(id string, lookup func(string) (configkit.SourceInfo, bool)) string { + if state != nil { + if directory, ok := state.sourceDirectories[id]; ok { + return directory + } + } + directory := "" + if source, ok := lookup(id); ok && source.Path != "" { + directory = filepath.Dir(source.Path) + } + if state != nil { + if state.sourceDirectories == nil { + state.sourceDirectories = make(map[string]string) + } + state.sourceDirectories[id] = directory + } + return directory +} diff --git a/internal/core/config/document_paths_test.go b/internal/core/config/document_paths_test.go index 686706d3..42e65f20 100644 --- a/internal/core/config/document_paths_test.go +++ b/internal/core/config/document_paths_test.go @@ -8,6 +8,44 @@ import ( configkit "go.maximumdirect.net/configkit" ) +func TestSourceDirectoryLookupIsMemoizedPerLoad(t *testing.T) { + dir := t.TempDir() + state := newDocumentLoadState(dir) + calls := make(map[string]int) + lookup := func(id string) (configkit.SourceInfo, bool) { + calls[id]++ + if id == "missing" { + return configkit.SourceInfo{}, false + } + if id == "memory" { + return configkit.SourceInfo{}, true + } + return configkit.SourceInfo{Path: filepath.Join(dir, id, "config.yml")}, true + } + for range 2 { + for _, id := range []string{"first", "second", "missing", "memory"} { + want := "" + if id == "first" || id == "second" { + want = filepath.Join(dir, id) + } + if got := state.sourceDirectory(id, lookup); got != want { + t.Fatalf("directory(%s) = %q, want %q", id, got, want) + } + } + } + for id, count := range calls { + if count != 1 { + t.Fatalf("source %s queried %d times", id, count) + } + } + other := newDocumentLoadState(dir) + if got := other.sourceDirectory("first", func(string) (configkit.SourceInfo, bool) { + return configkit.SourceInfo{Path: filepath.Join(dir, "changed", "config.yml")}, true + }); got != filepath.Join(dir, "changed") { + t.Fatalf("another load reused directory %q", got) + } +} + func TestDocumentPathsUseDeclaringFilesAcrossImports(t *testing.T) { t.Parallel() diff --git a/internal/core/config/pipeline_document.go b/internal/core/config/pipeline_document.go index 81242886..359f303e 100644 --- a/internal/core/config/pipeline_document.go +++ b/internal/core/config/pipeline_document.go @@ -8,11 +8,10 @@ import ( configkit "go.maximumdirect.net/configkit" ) -// documentLoadState keeps the spelling supplied by the user while resolver -// operations move map entries to their canonical keys. It is intentionally -// load-local: source-location handling consumes it during a later resolver -// pass and it never becomes runtime configuration state. +// documentLoadState keeps source-directory lookups and original map-key +// spellings local to one load. It never becomes runtime configuration state. type documentLoadState struct { + sourceDirectories map[string]string originalPaths map[string]configkit.Path mainDirectory string invocationDirectory string