Load shared PromptKit settings with native secrets bootstrap
This commit is contained in:
@@ -89,6 +89,19 @@ Build failures from removed schema APIs or old fixtures are expected at this poi
|
||||
|
||||
## Stage 2 — Replace The Configuration Schema And Loader
|
||||
|
||||
**Status: Complete.** Embedded native PromptKit settings and composed its
|
||||
definition with application validation and normalization. Configuration loading
|
||||
now bootstraps the selected source once, retains its native report and typed
|
||||
errors, and performs one layered load with the bundled underlay. Retired fields
|
||||
and raw backend/profile keys are rejected at their effective paths; native
|
||||
sensitivity is composed with the application raw-key boundary.
|
||||
|
||||
The offline configuration package tests pass on Go 1.27.4, covering native
|
||||
extensions, diagnostics, discovery, overrides, server normalization, and
|
||||
configured bootstrap preservation, overwrite, exhaustion, and failure effects.
|
||||
The old conversion and callers remain temporarily for the next stage, so the
|
||||
assembled application is not yet expected to compile or pass its full suite.
|
||||
|
||||
**Files:** `internal/config/document.go`, `load.go`, their tests,
|
||||
`internal/defaults/defaults.go`; remove obsolete settings definitions when callers
|
||||
are migrated in Stage 3.
|
||||
|
||||
@@ -2,23 +2,19 @@ package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// Document is Scriptorium's ConfigKit-native application configuration shape.
|
||||
type Document struct {
|
||||
PromptKit PromptKitDocument `yaml:"promptkit"`
|
||||
TransientRetries *int `yaml:"transient_retries"`
|
||||
Server ServerDocument `yaml:"server"`
|
||||
}
|
||||
|
||||
// PromptKitDocument selects framework acquisition, not embedded definitions.
|
||||
type PromptKitDocument struct {
|
||||
Configuration string `yaml:"configuration"`
|
||||
SchemaDir string `yaml:"schema_dir"`
|
||||
PromptKit promptkit.Settings `yaml:"promptkit"`
|
||||
TransientRetries *int `yaml:"transient_retries"`
|
||||
Server ServerDocument `yaml:"server"`
|
||||
}
|
||||
|
||||
type ServerDocument struct {
|
||||
@@ -30,16 +26,19 @@ type ServerDocument struct {
|
||||
}
|
||||
|
||||
func documentDefinition() configkit.Definition[Document] {
|
||||
return configkit.Definition[Document]{
|
||||
Defaults: documentDefaults,
|
||||
Resolve: resolveDocument,
|
||||
Validate: validateDocument,
|
||||
definition := configkit.Definition[Document]{
|
||||
Defaults: documentDefaults,
|
||||
Resolve: resolveDocument,
|
||||
Validate: validateDocument,
|
||||
Sensitive: func(path configkit.Path) bool { return rawKeyPath.MatchString(path.String()) },
|
||||
}
|
||||
return promptkit.Configure(definition, func(document *Document) *promptkit.Settings { return &document.PromptKit })
|
||||
}
|
||||
|
||||
var rawKeyPath = regexp.MustCompile(`^/promptkit/(?:backends|profiles)/[0-9]+/api_key$|^/promptkit/collections/[^/]+/(?:backends|profiles)/[0-9]+/api_key$`)
|
||||
|
||||
func documentDefaults() Document {
|
||||
return Document{
|
||||
PromptKit: PromptKitDocument{SchemaDir: defaults.SchemaDirDefault},
|
||||
Server: ServerDocument{
|
||||
Addr: defaults.HTTPAddrDefault,
|
||||
MaxRequestBytes: defaults.HTTPMaxRequestBytesDefault,
|
||||
@@ -65,8 +64,6 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
||||
}
|
||||
}
|
||||
|
||||
normalizePath(configkit.Keys("promptkit", "configuration"), &document.PromptKit.Configuration)
|
||||
normalizePath(configkit.Keys("promptkit", "schema_dir"), &document.PromptKit.SchemaDir)
|
||||
normalizePath(configkit.Keys("server", "artifact_root"), &document.Server.ArtifactRoot)
|
||||
normalizeString(configkit.Keys("server", "addr"), &document.Server.Addr,
|
||||
strings.TrimSpace(document.Server.Addr), "trimmed server address")
|
||||
@@ -74,6 +71,27 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
||||
}
|
||||
|
||||
func validateDocument(document *Document, validation *configkit.Validation) {
|
||||
for _, key := range []string{"configuration", "schema_dir"} {
|
||||
if _, exists := document.PromptKit.Application[key]; exists {
|
||||
validation.Error(configkit.Keys("promptkit", key), "retired setting; migrate to native PromptKit configuration")
|
||||
}
|
||||
}
|
||||
validateResources := func(path configkit.Path, backends []promptkit.BackendSettings, profiles []promptkit.ProfileSettings) {
|
||||
for index, backend := range backends {
|
||||
if _, exists := backend.Application["api_key"]; exists {
|
||||
validation.Error(path.Key("backends").Index(index).Key("api_key"), "raw API keys are not supported; use an environment variable")
|
||||
}
|
||||
}
|
||||
for index, profile := range profiles {
|
||||
if _, exists := profile.Application["api_key"]; exists {
|
||||
validation.Error(path.Key("profiles").Index(index).Key("api_key"), "raw API keys are not supported; use an environment variable")
|
||||
}
|
||||
}
|
||||
}
|
||||
validateResources(configkit.Keys("promptkit"), document.PromptKit.Backends, document.PromptKit.Profiles)
|
||||
for name, collection := range document.PromptKit.Collections {
|
||||
validateResources(configkit.Keys("promptkit", "collections", name), collection.Backends, collection.Profiles)
|
||||
}
|
||||
if document.TransientRetries != nil && *document.TransientRetries < 0 {
|
||||
validation.Error(configkit.Keys("transient_retries"), "must be greater than or equal to zero")
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package config
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -16,21 +15,17 @@ func loadDocumentBytes(content string) (*configkit.Result[Document], error) {
|
||||
|
||||
func TestDocumentDefaultsAndExplicitValues(t *testing.T) {
|
||||
result, err := loadDocumentBytes("{}\n")
|
||||
if err != nil || !reflect.DeepEqual(result.Config, documentDefaults()) {
|
||||
if err != nil || result.Config.Server != documentDefaults().Server {
|
||||
t.Fatalf("defaults: %+v %v", result, err)
|
||||
}
|
||||
result, err = loadDocumentBytes("promptkit:\n configuration: ''\n schema_dir: ''\ntransient_retries: 0\nserver:\n addr: ''\n artifact_root: ''\n max_request_bytes: 0\n max_artifact_bytes: 0\n max_response_bytes: 0\n")
|
||||
result, err = loadDocumentBytes("transient_retries: 0\nserver:\n addr: ''\n artifact_root: ''\n max_request_bytes: 0\n max_artifact_bytes: 0\n max_response_bytes: 0\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := result.Config
|
||||
if got.PromptKit.Configuration != "" || got.PromptKit.SchemaDir != "" || got.Server.Addr != "" || got.Server.ArtifactRoot != "" || got.Server.MaxRequestBytes != 0 || got.Server.MaxArtifactBytes != 0 || got.Server.MaxResponseBytes != 0 || got.TransientRetries == nil || *got.TransientRetries != 0 {
|
||||
if got.Server.Addr != "" || got.Server.ArtifactRoot != "" || got.Server.MaxRequestBytes != 0 || got.Server.MaxArtifactBytes != 0 || got.Server.MaxResponseBytes != 0 || got.TransientRetries == nil || *got.TransientRetries != 0 {
|
||||
t.Fatalf("explicit values: %+v", got)
|
||||
}
|
||||
settings := Settings(got)
|
||||
if settings.SchemaDir != "" || settings.PromptKitConfiguration != "" || settings.ServerAddr != "" || settings.MaxRequestBytes != 0 || settings.TransientRetries == nil || *settings.TransientRetries != 0 {
|
||||
t.Fatalf("settings changed resolved values: %+v", settings)
|
||||
}
|
||||
result, err = loadDocumentBytes("transient_retries: null\n")
|
||||
if err != nil || result.Config.TransientRetries != nil {
|
||||
t.Fatalf("nullable retries: %+v %v", result, err)
|
||||
@@ -38,15 +33,15 @@ func TestDocumentDefaultsAndExplicitValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDocumentNormalizesWithoutAcquiringFramework(t *testing.T) {
|
||||
result, err := loadDocumentBytes("promptkit:\n configuration: ' ./missing/../framework.yml '\n schema_dir: ' ./a/../schemas '\nserver:\n addr: ' :9000 '\n artifact_root: ' ./a/../artifacts '\n")
|
||||
result, err := loadDocumentBytes("server:\n addr: ' :9000 '\n artifact_root: ' ./a/../artifacts '\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Config.PromptKit.Configuration != "framework.yml" || result.Config.PromptKit.SchemaDir != "schemas" || result.Config.Server.Addr != ":9000" || result.Config.Server.ArtifactRoot != "artifacts" {
|
||||
if result.Config.Server.Addr != ":9000" || result.Config.Server.ArtifactRoot != "artifacts" {
|
||||
t.Fatalf("normalized: %+v", result.Config)
|
||||
}
|
||||
for _, key := range []string{"configuration", "schema_dir"} {
|
||||
explanation, ok := result.Explain(configkit.Keys("promptkit", key))
|
||||
for _, key := range []string{"addr", "artifact_root"} {
|
||||
explanation, ok := result.Explain(configkit.Keys("server", key))
|
||||
if !ok {
|
||||
t.Fatal("missing path evidence", key)
|
||||
}
|
||||
@@ -62,14 +57,14 @@ func TestDocumentNormalizesWithoutAcquiringFramework(t *testing.T) {
|
||||
if err := result.WriteEffective(&output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(output.String(), "configuration: framework.yml") || !strings.Contains(output.String(), "schema_dir: schemas") {
|
||||
if !strings.Contains(output.String(), "artifact_root: artifacts") {
|
||||
t.Fatal(output.String())
|
||||
}
|
||||
unchanged, err := loadDocumentBytes("promptkit:\n configuration: framework.yml\n")
|
||||
unchanged, err := loadDocumentBytes("server:\n artifact_root: artifacts\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
explanation, _ := unchanged.Explain(configkit.Keys("promptkit", "configuration"))
|
||||
explanation, _ := unchanged.Explain(configkit.Keys("server", "artifact_root"))
|
||||
for _, change := range explanation.History {
|
||||
if change.Origin.Operation == configkit.ChangeNormalization {
|
||||
t.Fatal("unchanged path was normalized")
|
||||
@@ -107,7 +102,6 @@ func TestDocumentRejectsRetiredAndInvalidShapes(t *testing.T) {
|
||||
for _, content := range []string{
|
||||
"promptkit_sources: []\n", "schema_dir: .\n", "defaults:\n render_format: text\n",
|
||||
"promptkit: null\n", "promptkit:\n configuration: null\n", "promptkit:\n schema_dir: null\n",
|
||||
"promptkit:\n profiles: []\n", "promptkit:\n backends: []\n", "promptkit:\n collections: {}\n",
|
||||
"server: null\n", "server:\n addr: null\n", "server:\n max_request_bytes: null\n",
|
||||
"server:\n unknown_field: 1\n", "prompt_dir: ./old-prompts\n",
|
||||
"profile_dir: ./old-profiles\n", "backends: []\n",
|
||||
@@ -117,3 +111,38 @@ func TestDocumentRejectsRetiredAndInvalidShapes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeSettingsExtensionsAndRawKeyBoundary(t *testing.T) {
|
||||
result, err := loadDocumentBytes("promptkit:\n custom: permitted\n backends:\n - id: local\n endpoint: http://localhost:1234\n extension: retained\n extra_params: {ordinary: visible}\n")
|
||||
if err != nil || result.Config.PromptKit.Application["custom"] != "permitted" || result.Config.PromptKit.Backends[0].Application["extension"] != "retained" {
|
||||
t.Fatalf("native extensions: %+v %v", result, err)
|
||||
}
|
||||
var effective bytes.Buffer
|
||||
if err := result.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), "visible") {
|
||||
t.Fatalf("ordinary extra params: %q %v", effective.String(), err)
|
||||
}
|
||||
for _, test := range []struct{ body, path string }{
|
||||
{"promptkit: {configuration: null}", "/promptkit/configuration"},
|
||||
{"promptkit: {schema_dir: null}", "/promptkit/schema_dir"},
|
||||
{"promptkit: {backends: [{id: b, api_key: forbidden-secret}]}", "/promptkit/backends/0/api_key"},
|
||||
{"promptkit: {profiles: [{id: p, api_key: forbidden-secret}]}", "/promptkit/profiles/0/api_key"},
|
||||
{"promptkit: {collections: {team: {backends: [{id: b, api_key: forbidden-secret}]}}}", "/promptkit/collections/team/backends/0/api_key"},
|
||||
{"promptkit: {collections: {team: {profiles: [{id: p, api_key: forbidden-secret}]}}}", "/promptkit/collections/team/profiles/0/api_key"},
|
||||
} {
|
||||
_, err := loadDocumentBytes(test.body)
|
||||
var native *configkit.LoadError
|
||||
if !errors.As(err, &native) {
|
||||
t.Fatalf("%s: %v", test.path, err)
|
||||
}
|
||||
found := false
|
||||
for _, diagnostic := range native.Diagnostics() {
|
||||
found = found || diagnostic.Path.String() == test.path && diagnostic.Code == configkit.CodeValidateError
|
||||
if strings.Contains(diagnostic.Message, "forbidden-secret") {
|
||||
t.Fatalf("secret leaked: %+v", diagnostic)
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("missing diagnostic %s: %+v", test.path, native.Diagnostics())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// LoadOptions selects one application source and explicit configuration values.
|
||||
@@ -20,7 +21,7 @@ var applicationSearch = configkit.Searches(
|
||||
)
|
||||
|
||||
// Load resolves one ConfigKit document and retains its inspection snapshot.
|
||||
func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
||||
func Load(options LoadOptions) (*configkit.Result[Document], *configkit.SecretsReport, error) {
|
||||
var source configkit.Source
|
||||
if options.Explicit {
|
||||
source = configkit.File(options.Path)
|
||||
@@ -28,29 +29,31 @@ func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
||||
source = configkit.SearchConfig("scriptorium", applicationSearch)
|
||||
}
|
||||
|
||||
result, err := configkit.Load(source, configkit.Options[Document]{
|
||||
report, captured, err := configkit.LoadSecretsIntoEnvironmentFromConfig(source)
|
||||
if err != nil {
|
||||
return nil, report, fmt.Errorf("bootstrap application secrets: %w", err)
|
||||
}
|
||||
result, err := configkit.LoadLayered(configkit.Input{Source: captured, Imports: true}, configkit.LayeredOptions[Document]{
|
||||
Definition: documentDefinition(),
|
||||
Imports: true,
|
||||
Underlays: []configkit.Underlay{promptkit.BundledOpenRouterUnderlay()},
|
||||
Overlay: options.Overlay,
|
||||
Overrides: options.Overrides,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load application configuration: %w", err)
|
||||
return nil, report, fmt.Errorf("load application configuration: %w", err)
|
||||
}
|
||||
return result, nil
|
||||
return result, report, nil
|
||||
}
|
||||
|
||||
// Settings converts a validated document without another merge or normalization.
|
||||
func Settings(document Document) AppSettings {
|
||||
settings := AppSettings{
|
||||
SchemaDir: document.PromptKit.SchemaDir,
|
||||
PromptKitConfiguration: document.PromptKit.Configuration,
|
||||
ServerAddr: document.Server.Addr,
|
||||
ArtifactRoot: document.Server.ArtifactRoot,
|
||||
MaxRequestBytes: document.Server.MaxRequestBytes,
|
||||
MaxArtifactBytes: document.Server.MaxArtifactBytes,
|
||||
MaxResponseBytes: document.Server.MaxResponseBytes,
|
||||
TransientRetries: document.TransientRetries,
|
||||
ServerAddr: document.Server.Addr,
|
||||
ArtifactRoot: document.Server.ArtifactRoot,
|
||||
MaxRequestBytes: document.Server.MaxRequestBytes,
|
||||
MaxArtifactBytes: document.Server.MaxArtifactBytes,
|
||||
MaxResponseBytes: document.Server.MaxResponseBytes,
|
||||
TransientRetries: document.TransientRetries,
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
@@ -48,11 +47,11 @@ func TestLoadNativeDiscoveryOrderAndFilenames(t *testing.T) {
|
||||
writeApplicationFile(t, path, "server:\n addr: '"+string(rune('a'+index))+"'\n")
|
||||
}
|
||||
for index, path := range paths {
|
||||
result, err := Load(LoadOptions{Path: "ignored.yml"})
|
||||
result, _, err := Load(LoadOptions{Path: "ignored.yml"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Config.Server.Addr != string(rune('a'+index)) || len(result.Sources()) != 1 || result.Sources()[0].Path != path {
|
||||
if result.Config.Server.Addr != string(rune('a'+index)) || len(result.Sources()) < 2 || result.Sources()[0].Path != path {
|
||||
t.Fatalf("selected wrong source: %+v %+v", result.Config, result.Sources())
|
||||
}
|
||||
if err := os.Remove(path); err != nil {
|
||||
@@ -62,8 +61,8 @@ func TestLoadNativeDiscoveryOrderAndFilenames(t *testing.T) {
|
||||
// Do not let a host's system configuration influence exhaustion checks.
|
||||
// The system preset's filename expansion remains upstream-owned.
|
||||
useIsolatedSearch(t)
|
||||
result, err := Load(LoadOptions{})
|
||||
if err != nil || len(result.Sources()) != 0 || !reflect.DeepEqual(result.Config, documentDefaults()) {
|
||||
result, _, err := Load(LoadOptions{})
|
||||
if err != nil || len(result.Sources()) == 0 || result.Config.Server.Addr != documentDefaults().Server.Addr {
|
||||
t.Fatalf("exhaustion: %+v %v", result, err)
|
||||
}
|
||||
}
|
||||
@@ -72,7 +71,7 @@ func TestLoadDoesNotFallThroughSelectedInvalidSource(t *testing.T) {
|
||||
root := isolatedDiscovery(t)
|
||||
writeApplicationFile(t, filepath.Join(root, "scriptorium.yml"), "server: [\n")
|
||||
writeApplicationFile(t, filepath.Join(root, "scriptorium.yaml"), "{}\n")
|
||||
if _, err := Load(LoadOptions{}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{}); err == nil {
|
||||
t.Fatal("invalid first candidate fell through")
|
||||
}
|
||||
}
|
||||
@@ -83,11 +82,11 @@ func TestLoadExplicitSelectionAndOverlayPresence(t *testing.T) {
|
||||
for _, content := range []string{"", "server: [\n"} {
|
||||
path := filepath.Join(root, "selected.yml")
|
||||
writeApplicationFile(t, path, content)
|
||||
if _, err := Load(LoadOptions{Explicit: true, Path: path}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{Explicit: true, Path: path}); err == nil {
|
||||
t.Fatal("accepted invalid explicit file")
|
||||
}
|
||||
}
|
||||
_, err := Load(LoadOptions{Explicit: true})
|
||||
_, _, err := Load(LoadOptions{Explicit: true})
|
||||
var native *configkit.LoadError
|
||||
if !errors.As(err, &native) {
|
||||
t.Fatalf("empty path lost typed error: %v", err)
|
||||
@@ -95,15 +94,15 @@ func TestLoadExplicitSelectionAndOverlayPresence(t *testing.T) {
|
||||
base := filepath.Join(root, "selected.yml")
|
||||
writeApplicationFile(t, base, "{}\n")
|
||||
for _, overlay := range []string{"", "default"} {
|
||||
result, err := Load(LoadOptions{Explicit: true, Path: base, Overlay: overlay})
|
||||
if err != nil || !reflect.DeepEqual(result.Config, documentDefaults()) {
|
||||
result, _, err := Load(LoadOptions{Explicit: true, Path: base, Overlay: overlay})
|
||||
if err != nil || result.Config.Server.Addr != documentDefaults().Server.Addr {
|
||||
t.Fatalf("no overlay: %+v %v", result, err)
|
||||
}
|
||||
}
|
||||
if _, err := Load(LoadOptions{Explicit: true, Path: base, Overlay: "missing"}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{Explicit: true, Path: base, Overlay: "missing"}); err == nil {
|
||||
t.Fatal("missing overlay accepted")
|
||||
}
|
||||
if _, err := Load(LoadOptions{Overlay: "local"}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{Overlay: "local"}); err == nil {
|
||||
t.Fatal("overlay without main context accepted")
|
||||
}
|
||||
}
|
||||
@@ -111,19 +110,19 @@ func TestLoadExplicitSelectionAndOverlayPresence(t *testing.T) {
|
||||
func TestLoadImportsOverlayAndNativeOverrides(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
main := filepath.Join(root, "config.yml")
|
||||
writeApplicationFile(t, main, "config:\n imports:\n - glob: fragments/*.yml\n required: true\npromptkit:\n configuration: base.yml\n")
|
||||
writeApplicationFile(t, main, "config:\n imports:\n - glob: fragments/*.yml\n required: true\n")
|
||||
writeApplicationFile(t, filepath.Join(root, "fragments", "a.yml"), "server:\n addr: :8081\n")
|
||||
writeApplicationFile(t, filepath.Join(root, "fragments", "b.yml"), "promptkit:\n schema_dir: ./schemas\n")
|
||||
writeApplicationFile(t, filepath.Join(root, "overlays", "local.yml"), "promptkit:\n configuration: overlay.yml\nserver:\n addr: :9090\n")
|
||||
result, err := Load(LoadOptions{Explicit: true, Path: main, Overlay: "local", Overrides: []configkit.Override{{Path: configkit.Keys("promptkit", "configuration"), Value: "native.yml", Flag: "--set"}}})
|
||||
writeApplicationFile(t, filepath.Join(root, "fragments", "b.yml"), "promptkit:\n custom_field: present\n")
|
||||
writeApplicationFile(t, filepath.Join(root, "overlays", "local.yml"), "server:\n addr: :9090\n")
|
||||
result, _, err := Load(LoadOptions{Explicit: true, Path: main, Overlay: "local", Overrides: []configkit.Override{{Path: configkit.Keys("server", "max_request_bytes"), Value: int64(0), Flag: "--set"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Config.PromptKit.Configuration != "native.yml" || result.Config.PromptKit.SchemaDir != "schemas" || result.Config.Server.Addr != ":9090" || len(result.Sources()) != 5 {
|
||||
if result.Config.PromptKit.Application["custom_field"] != "present" || result.Config.Server.MaxRequestBytes != 0 || result.Config.Server.Addr != ":9090" {
|
||||
t.Fatalf("composition: %+v %+v", result.Config, result.Sources())
|
||||
}
|
||||
writeApplicationFile(t, filepath.Join(root, "fragments", "b.yml"), "server:\n addr: :8082\n")
|
||||
if _, err := Load(LoadOptions{Explicit: true, Path: main}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{Explicit: true, Path: main}); err == nil {
|
||||
t.Fatal("peer conflict accepted")
|
||||
}
|
||||
}
|
||||
@@ -131,17 +130,17 @@ func TestLoadImportsOverlayAndNativeOverrides(t *testing.T) {
|
||||
func TestLoadNativeOverrideEvidenceAndConflicts(t *testing.T) {
|
||||
root := isolatedDiscovery(t)
|
||||
useIsolatedSearch(t)
|
||||
result, err := Load(LoadOptions{Overrides: []configkit.Override{
|
||||
result, _, err := Load(LoadOptions{Overrides: []configkit.Override{
|
||||
{Path: configkit.Keys("server", "max_request_bytes"), Value: int64(0), Flag: "--set"},
|
||||
{Path: configkit.Keys("promptkit", "configuration"), Value: " ./one/../framework.yml ", Flag: "--set"},
|
||||
{Path: configkit.Keys("server", "artifact_root"), Value: " ./one/../artifacts ", Flag: "--set"},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Config.Server.MaxRequestBytes != 0 || result.Config.PromptKit.Configuration != "framework.yml" {
|
||||
if result.Config.Server.MaxRequestBytes != 0 || result.Config.Server.ArtifactRoot != "artifacts" {
|
||||
t.Fatal(result.Config)
|
||||
}
|
||||
explanation, ok := result.Explain(configkit.Keys("promptkit", "configuration"))
|
||||
explanation, ok := result.Explain(configkit.Keys("server", "artifact_root"))
|
||||
if !ok || len(explanation.History) < 2 {
|
||||
t.Fatalf("native evidence missing: %+v", explanation)
|
||||
}
|
||||
@@ -149,7 +148,7 @@ func TestLoadNativeOverrideEvidenceAndConflicts(t *testing.T) {
|
||||
{{Path: configkit.Keys("server", "addr"), Value: "a", Flag: "--set"}, {Path: configkit.Keys("server", "addr"), Value: "b", Flag: "--set"}},
|
||||
{{Path: configkit.Keys("server"), Value: map[string]any{"addr": "a"}, Flag: "--set"}, {Path: configkit.Keys("server", "addr"), Value: "b", Flag: "--set"}},
|
||||
} {
|
||||
_, err := Load(LoadOptions{Overrides: records})
|
||||
_, _, err := Load(LoadOptions{Overrides: records})
|
||||
var native *configkit.LoadError
|
||||
if !errors.As(err, &native) {
|
||||
t.Fatalf("native conflict lost: %v", err)
|
||||
@@ -165,12 +164,12 @@ func TestLoadNativeOverrideEvidenceAndConflicts(t *testing.T) {
|
||||
}
|
||||
path := filepath.Join(root, "invalid.yml")
|
||||
writeApplicationFile(t, path, "server:\n max_request_bytes: -1\n")
|
||||
result, err = Load(LoadOptions{Explicit: true, Path: path, Overrides: []configkit.Override{{Path: configkit.Keys("server", "max_request_bytes"), Value: int64(0), Flag: "--set"}}})
|
||||
result, _, err = Load(LoadOptions{Explicit: true, Path: path, Overrides: []configkit.Override{{Path: configkit.Keys("server", "max_request_bytes"), Value: int64(0), Flag: "--set"}}})
|
||||
if err != nil || result.Config.Server.MaxRequestBytes != 0 {
|
||||
t.Fatalf("override did not precede validation: %+v %v", result, err)
|
||||
}
|
||||
writeApplicationFile(t, path, "server:\n max_request_bytes: not-a-number\n")
|
||||
if _, err := Load(LoadOptions{Explicit: true, Path: path, Overrides: []configkit.Override{{Path: configkit.Keys("server", "max_request_bytes"), Value: int64(0), Flag: "--set"}}}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{Explicit: true, Path: path, Overrides: []configkit.Override{{Path: configkit.Keys("server", "max_request_bytes"), Value: int64(0), Flag: "--set"}}}); err == nil {
|
||||
t.Fatal("override repaired decode failure")
|
||||
}
|
||||
}
|
||||
@@ -179,16 +178,16 @@ func TestLoadImportRequirednessAndDestination(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
main := filepath.Join(root, "config.yml")
|
||||
writeApplicationFile(t, main, "config:\n imports:\n - path: absent.yml\n")
|
||||
if _, err := Load(LoadOptions{Explicit: true, Path: main}); err != nil {
|
||||
if _, _, err := Load(LoadOptions{Explicit: true, Path: main}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeApplicationFile(t, main, "config:\n imports:\n - path: absent.yml\n required: true\n")
|
||||
if _, err := Load(LoadOptions{Explicit: true, Path: main}); err == nil {
|
||||
if _, _, err := Load(LoadOptions{Explicit: true, Path: main}); err == nil {
|
||||
t.Fatal("required import accepted")
|
||||
}
|
||||
writeApplicationFile(t, filepath.Join(root, "fragments", "server.yml"), "addr: ':8181'\n")
|
||||
writeApplicationFile(t, main, "config:\n imports:\n - dir: fragments\n pattern: '*.yml'\n destination: [server]\n required: true\n")
|
||||
result, err := Load(LoadOptions{Explicit: true, Path: main})
|
||||
result, _, err := Load(LoadOptions{Explicit: true, Path: main})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -197,3 +196,38 @@ func TestLoadImportRequirednessAndDestination(t *testing.T) {
|
||||
t.Fatalf("value/origin: %+v %+v", result.Config, info)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfiguredSecrets(t *testing.T) {
|
||||
root := isolatedDiscovery(t)
|
||||
useIsolatedSearch(t)
|
||||
const variable = "SCRIPTORIUM_TEST_BOOTSTRAP_VALUE"
|
||||
t.Setenv(variable, "")
|
||||
main := filepath.Join(root, "config.yml")
|
||||
writeApplicationFile(t, filepath.Join(root, "secrets", variable), "synthetic")
|
||||
writeApplicationFile(t, main, "config: {secrets_dir: secrets}\n")
|
||||
_, report, err := Load(LoadOptions{Explicit: true, Path: main})
|
||||
if err != nil || os.Getenv(variable) != "" || len(report.Entries()) != 1 || report.Entries()[0].Status != configkit.SecretFileSkippedExisting || !report.Entries()[0].ExistingEmpty {
|
||||
t.Fatalf("preserve empty: report=%+v err=%v", report.Entries(), err)
|
||||
}
|
||||
writeApplicationFile(t, main, "config: {secrets_dir: secrets, secrets_overwrite: true}\nserver: {max_request_bytes: -1}\n")
|
||||
_, report, err = Load(LoadOptions{Explicit: true, Path: main})
|
||||
var loadErr *configkit.LoadError
|
||||
if !errors.As(err, &loadErr) || os.Getenv(variable) != "synthetic" || len(report.Entries()) != 1 || report.Entries()[0].Status != configkit.SecretFileLoaded {
|
||||
t.Fatalf("later failure: report=%+v err=%v", report.Entries(), err)
|
||||
}
|
||||
writeApplicationFile(t, main, "config: {secrets_dir: missing}\n")
|
||||
_, report, err = Load(LoadOptions{Explicit: true, Path: main})
|
||||
var secretsErr *configkit.SecretsError
|
||||
if !errors.As(err, &secretsErr) || report == nil {
|
||||
t.Fatalf("bootstrap error: report=%+v err=%v", report, err)
|
||||
}
|
||||
writeApplicationFile(t, main, "{}\n")
|
||||
_, report, err = Load(LoadOptions{Explicit: true, Path: main})
|
||||
if err != nil || report == nil || len(report.Entries()) != 0 {
|
||||
t.Fatalf("no directory: report=%+v err=%v", report, err)
|
||||
}
|
||||
_, report, err = Load(LoadOptions{})
|
||||
if err != nil || report == nil || len(report.Entries()) != 0 {
|
||||
t.Fatalf("optional exhaustion: report=%+v err=%v", report, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user