Migrate application configuration to the new ConfigKit API
This commit is contained in:
@@ -154,6 +154,12 @@ Prompt size: dependency/toolchain preparation only.
|
|||||||
|
|
||||||
## Stage 2 — Migrate Application APIs And Separate Old PromptKit Types
|
## Stage 2 — Migrate Application APIs And Separate Old PromptKit Types
|
||||||
|
|
||||||
|
**Complete.** Application and CLI APIs now use the new module; PromptKit keeps
|
||||||
|
the old module at its boundary. The native build, package compilation, and
|
||||||
|
source-handoff test pass. Broader attempts exposed old control fixtures and CLI
|
||||||
|
assignment expectations owned by later stages; CLI/LLM tests using local HTTP
|
||||||
|
listeners also encountered this environment's socket restriction.
|
||||||
|
|
||||||
Goal: move the application loader and CLI to v1 APIs.
|
Goal: move the application loader and CLI to v1 APIs.
|
||||||
|
|
||||||
Inspect `internal/core/config/{load,loaded_config,operational_document,
|
Inspect `internal/core/config/{load,loaded_config,operational_document,
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||||
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runConfigEffective(args []string, stdout, stderr io.Writer, opts Options) int {
|
func runConfigEffective(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadConfigKit(configPath, overlay string, overrides []configkit.Override, opts Options) (*config.LoadedConfig, string, error) {
|
func loadConfigKit(configPath, overlay string, overrides []configkit.Override, opts Options) (*config.LoadedConfig, string, error) {
|
||||||
@@ -23,7 +23,7 @@ func loadConfigKit(configPath, overlay string, overrides []configkit.Override, o
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
return loaded, path, nil
|
return loaded, loaded.MainSourcePath(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeConfigLoadError(output io.Writer, err error) {
|
func writeConfigLoadError(output io.Writer, err error) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfigLoadDiagnosticsIdentifyComposedSources(t *testing.T) {
|
func TestConfigLoadDiagnosticsIdentifyComposedSources(t *testing.T) {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/buildinfo"
|
"gitea.maximumdirect.net/eric/notarius/internal/buildinfo"
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||||
@@ -27,6 +26,7 @@ import (
|
|||||||
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||||||
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultConfigPath = "/usr/local/etc/notarius/config.yml"
|
const defaultConfigPath = "/usr/local/etc/notarius/config.yml"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
import configkit "go.maximumdirect.net/configkit"
|
||||||
|
|
||||||
// documentNormalizer records leaf provenance and, while visiting a sequence,
|
// documentNormalizer records leaf provenance and, while visiting a sequence,
|
||||||
// covers its atomic mutation boundary. ConfigKit audits sequences as whole
|
// covers its atomic mutation boundary. ConfigKit audits sequences as whole
|
||||||
@@ -18,9 +18,9 @@ func (n documentNormalizer) inSequence(path configkit.Path) documentNormalizer {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n documentNormalizer) Record(path configkit.Path, kind configkit.ChangeKind, reason string, dependencies ...configkit.Path) {
|
func (n documentNormalizer) RecordNormalization(path configkit.Path, reason string, dependencies ...configkit.Path) {
|
||||||
n.Resolution.Record(path, kind, reason, dependencies...)
|
n.Resolution.RecordNormalization(path, reason, dependencies...)
|
||||||
if n.sequence != nil {
|
if n.sequence != nil {
|
||||||
n.Resolution.Record(*n.sequence, kind, reason, append([]configkit.Path{path}, dependencies...)...)
|
n.Resolution.RecordNormalization(*n.sequence, reason, append([]configkit.Path{path}, dependencies...)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func normalizeDocumentPaths(document *Document, context *configkit.Resolution, state *documentLoadState) {
|
func normalizeDocumentPaths(document *Document, context *configkit.Resolution, state *documentLoadState) {
|
||||||
@@ -63,7 +63,7 @@ func initializeDocumentMainDirectory(resolution documentNormalizer, state *docum
|
|||||||
if state == nil || state.mainDirectory != "" {
|
if state == nil || state.mainDirectory != "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
info, ok := resolution.InputInfo(configkit.Keys("version"))
|
info, ok := resolution.EntryInfo(configkit.Keys("version"))
|
||||||
if ok && len(info.Origin.Locations) == 1 {
|
if ok && len(info.Origin.Locations) == 1 {
|
||||||
if source, sourceOK := resolution.Source(info.Origin.Locations[0].SourceID); sourceOK && source.Path != "" {
|
if source, sourceOK := resolution.Source(info.Origin.Locations[0].SourceID); sourceOK && source.Path != "" {
|
||||||
state.mainDirectory = filepath.Dir(source.Path)
|
state.mainDirectory = filepath.Dir(source.Path)
|
||||||
@@ -102,7 +102,7 @@ func normalizeDocumentReferencePaths(references map[string]ReferenceDocument, pa
|
|||||||
} else {
|
} else {
|
||||||
value := filepath.Clean(filepath.Join(base, *source.Path))
|
value := filepath.Clean(filepath.Join(base, *source.Path))
|
||||||
if value != *source.Path {
|
if value != *source.Path {
|
||||||
resolution.Record(sourcePath, configkit.ChangeNormalization, "resolved external reference path")
|
resolution.RecordNormalization(sourcePath, "resolved external reference path")
|
||||||
source.Path = documentValue(value)
|
source.Path = documentValue(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ func documentPathBase(resolution documentNormalizer, state *documentLoadState, p
|
|||||||
if state != nil {
|
if state != nil {
|
||||||
original = state.originalPath(path)
|
original = state.originalPath(path)
|
||||||
}
|
}
|
||||||
info, ok := resolution.InputInfo(original)
|
info, ok := resolution.EntryInfo(original)
|
||||||
if !ok {
|
if !ok {
|
||||||
if state != nil && state.mainDirectory != "" {
|
if state != nil && state.mainDirectory != "" {
|
||||||
return state.mainDirectory, true
|
return state.mainDirectory, true
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDocumentPathsUseDeclaringFilesAcrossImports(t *testing.T) {
|
func TestDocumentPathsUseDeclaringFilesAcrossImports(t *testing.T) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDocumentLoadAcceptsVersion5AndCanonicalShapes(t *testing.T) {
|
func TestDocumentLoadAcceptsVersion5AndCanonicalShapes(t *testing.T) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPipelineInheritancePreservesCompositionAndReplacesSteps(t *testing.T) {
|
func TestPipelineInheritancePreservesCompositionAndReplacesSteps(t *testing.T) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoadOptions contains configuration selections supplied by an application
|
// LoadOptions contains configuration selections supplied by an application
|
||||||
@@ -57,7 +57,7 @@ func documentDefinition(state *documentLoadState) configkit.Definition[Document]
|
|||||||
Path: configkit.Keys("version"),
|
Path: configkit.Keys("version"),
|
||||||
Check: validateDocumentVersion,
|
Check: validateDocumentVersion,
|
||||||
},
|
},
|
||||||
Secret: sensitiveDocumentPath,
|
Sensitive: sensitiveDocumentPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoadedConfig keeps the finalized runtime configuration together with the
|
// LoadedConfig keeps the finalized runtime configuration together with the
|
||||||
@@ -59,6 +59,28 @@ func Load(path string, options LoadOptions) (*LoadedConfig, error) {
|
|||||||
return loadConfig(path, options)
|
return loadConfig(path, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadSource loads a selected source, including its imports, into an owned configuration.
|
||||||
|
func LoadSource(source configkit.Source, options LoadOptions) (*LoadedConfig, error) {
|
||||||
|
result, err := loadDocumentWithSource(source, options, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newLoadedConfig(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MainSourcePath returns the selected main file's recorded path, if any.
|
||||||
|
func (loaded *LoadedConfig) MainSourcePath() string {
|
||||||
|
if loaded == nil || loaded.result == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
for _, source := range loaded.result.Sources() {
|
||||||
|
if source.Layer == configkit.LayerMain && source.Kind == configkit.SourceKindFile && source.ImportedFrom == nil {
|
||||||
|
return source.Path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func loadConfigSource(source configkit.Source, options LoadOptions) (*LoadedConfig, error) {
|
func loadConfigSource(source configkit.Source, options LoadOptions) (*LoadedConfig, error) {
|
||||||
result, err := loadDocumentSource(source, options)
|
result, err := loadDocumentSource(source, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,16 +2,47 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
units "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
units "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
||||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestLoadSourceRetainsMainFileAndLoadsImports(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
main := filepath.Join(dir, "main.yml")
|
||||||
|
fragment := filepath.Join(dir, "fragment.yml")
|
||||||
|
if err := os.WriteFile(fragment, []byte("output:\n directory: imported-output\n"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(main, []byte("version: 5\nconfig:\n imports:\n - path: fragment.yml\n required: true\n"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
loaded, err := LoadSource(configkit.File(main), LoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := loaded.MainSourcePath(); got != main {
|
||||||
|
t.Fatalf("main source path = %q, want %q", got, main)
|
||||||
|
}
|
||||||
|
if got := loaded.Config.Output.Directory; got != filepath.Join(dir, "imported-output") {
|
||||||
|
t.Fatalf("imported output directory = %q", got)
|
||||||
|
}
|
||||||
|
bytesLoaded, err := loadConfigSource(configkit.Bytes("memory.yml", []byte("version: 5\n")), LoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := bytesLoaded.MainSourcePath(); got != "" {
|
||||||
|
t.Fatalf("non-file main source path = %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadedConfigConvertsDocumentsAndResolvesRuntimePipeline(t *testing.T) {
|
func TestLoadedConfigConvertsDocumentsAndResolvesRuntimePipeline(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resolveDocumentOperations(document *Document, resolution *configkit.Resolution, state *documentLoadState) error {
|
func resolveDocumentOperations(document *Document, resolution *configkit.Resolution, state *documentLoadState) error {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWorkerKeyNormalizationPreservesExplicitCount(t *testing.T) {
|
func TestWorkerKeyNormalizationPreservesExplicitCount(t *testing.T) {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// documentLoadState keeps the spelling supplied by the user while resolver
|
// documentLoadState keeps the spelling supplied by the user while resolver
|
||||||
@@ -255,7 +255,7 @@ func normalizeDocumentValue[T comparable](resolution documentNormalizer, path co
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if *target != value {
|
if *target != value {
|
||||||
resolution.Record(path, configkit.ChangeNormalization, reason)
|
resolution.RecordNormalization(path, reason)
|
||||||
*target = value
|
*target = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ func normalizePipelineDocumentString(resolution documentNormalizer, path configk
|
|||||||
}
|
}
|
||||||
value := strings.TrimSpace(**target)
|
value := strings.TrimSpace(**target)
|
||||||
if **target != value {
|
if **target != value {
|
||||||
resolution.Record(path, configkit.ChangeNormalization, reason)
|
resolution.RecordNormalization(path, reason)
|
||||||
**target = value
|
**target = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,7 +312,7 @@ func normalizeDocumentMap[T any](values map[string]T, path configkit.Path, kind
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if changed {
|
if changed {
|
||||||
resolution.Record(path, configkit.ChangeNormalization, "normalized "+kind+" keys", dependencies...)
|
resolution.RecordNormalization(path, "normalized "+kind+" keys", dependencies...)
|
||||||
values = result
|
values = result
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDocumentRejectsExplicitInvalidBranches(t *testing.T) {
|
func TestDocumentRejectsExplicitInvalidBranches(t *testing.T) {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e EffectiveConfig) RedactedResolvedPipelinePayload() pipeline.ResolvedPipeline {
|
func (e EffectiveConfig) RedactedResolvedPipelinePayload() pipeline.ResolvedPipeline {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidationPolicyFileConfigurationIsStrictAndPresenceAware(t *testing.T) {
|
func TestValidationPolicyFileConfigurationIsStrictAndPresenceAware(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user