Share native pipeline source selection and loading
This commit is contained in:
@@ -70,6 +70,12 @@ change startup behavior; this compatibility check is not sprint completion.
|
|||||||
|
|
||||||
## Stage 2 — Share native source selection and pure pipeline loading
|
## Stage 2 — Share native source selection and pure pipeline loading
|
||||||
|
|
||||||
|
**Completed.** Centralized explicit/discovered native source selection and added
|
||||||
|
a pure source-taking loader that retains existing resolution and metadata. A
|
||||||
|
prepared-source regression verifies captured main content, source-relative
|
||||||
|
context, provenance, and that ordinary loading does not bootstrap secrets. The
|
||||||
|
full configuration package passes with Go 1.27.4.
|
||||||
|
|
||||||
Read `internal/config/load.go`, `pipeline_configkit.go`,
|
Read `internal/config/load.go`, `pipeline_configkit.go`,
|
||||||
`pipeline_discovery_test.go`, `pipeline_configkit_test.go`, and
|
`pipeline_discovery_test.go`, `pipeline_configkit_test.go`, and
|
||||||
`native_results_test.go`. Consult ConfigKit's prepared-source contract.
|
`native_results_test.go`. Consult ConfigKit's prepared-source contract.
|
||||||
|
|||||||
@@ -26,7 +26,25 @@ type PipelineLoadOptions struct {
|
|||||||
// LoadPipelineWithOptions loads pipeline configuration with strict field
|
// LoadPipelineWithOptions loads pipeline configuration with strict field
|
||||||
// checking and optional named-overlay selection.
|
// checking and optional named-overlay selection.
|
||||||
func LoadPipelineWithOptions(path string, opts PipelineLoadOptions) (*PipelineConfig, error) {
|
func LoadPipelineWithOptions(path string, opts PipelineLoadOptions) (*PipelineConfig, error) {
|
||||||
cfg, err := loadPipelineWithConfigKit(path, opts)
|
return LoadPipelineSourceWithOptions(PipelineSource(path, opts), opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PipelineSource selects the explicit pipeline file or required discovery source.
|
||||||
|
func PipelineSource(path string, opts PipelineLoadOptions) configkit.Source {
|
||||||
|
path = strings.TrimSpace(path)
|
||||||
|
if path != "" {
|
||||||
|
return configkit.File(path)
|
||||||
|
}
|
||||||
|
search := configkit.Searches(configkit.WorkingDirectory(), configkit.UserConfigDirectory(), configkit.UnixSystemDirectories())
|
||||||
|
if opts.Search != nil {
|
||||||
|
search = *opts.Search
|
||||||
|
}
|
||||||
|
return configkit.SearchConfig("narratio", search, configkit.SearchOptions{Required: true})
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadPipelineSourceWithOptions loads a native source without applying secrets.
|
||||||
|
func LoadPipelineSourceWithOptions(source configkit.Source, opts PipelineLoadOptions) (*PipelineConfig, error) {
|
||||||
|
cfg, err := loadPipelineWithConfigKit(source, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,16 +34,8 @@ type pipelineOverlaySelection struct {
|
|||||||
overlayPath string
|
overlayPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*PipelineConfig, error) {
|
func loadPipelineWithConfigKit(source configkit.Source, opts PipelineLoadOptions) (*PipelineConfig, error) {
|
||||||
overlay := selectedPipelineOverlayName(opts)
|
overlay := selectedPipelineOverlayName(opts)
|
||||||
source := configkit.File(strings.TrimSpace(path))
|
|
||||||
if strings.TrimSpace(path) == "" {
|
|
||||||
search := configkit.Searches(configkit.WorkingDirectory(), configkit.UserConfigDirectory(), configkit.UnixSystemDirectories())
|
|
||||||
if opts.Search != nil {
|
|
||||||
search = *opts.Search
|
|
||||||
}
|
|
||||||
source = configkit.SearchConfig("narratio", search, configkit.SearchOptions{Required: true})
|
|
||||||
}
|
|
||||||
result, err := loadPipelineConfigKitResult(source, overlay, opts.Overrides)
|
result, err := loadPipelineConfigKitResult(source, overlay, opts.Overrides)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("load pipeline config: %w", err)
|
return nil, fmt.Errorf("load pipeline config: %w", err)
|
||||||
|
|||||||
@@ -87,3 +87,41 @@ func TestPipelineDiscoveryUsesWorkingDirectoryBeforeUserConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPipelineSourceRetainsPreparedMainAndPureLoading(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
path := filepath.Join(dir, "pipeline.yml")
|
||||||
|
secretDir := filepath.Join(dir, "secrets")
|
||||||
|
if err := os.Mkdir(secretDir, 0700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
const name = "NARRATIO_SOURCE_HANDOFF_TEST"
|
||||||
|
t.Setenv(name, "")
|
||||||
|
if err := os.WriteFile(filepath.Join(secretDir, name), []byte("synthetic-secret"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
body := "config: {secrets_dir: secrets}\n" + testTranscriptionConfig + "workspace: {root: captured}\n"
|
||||||
|
if err := os.WriteFile(path, []byte(body), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := LoadPipelineWithOptions(path, PipelineLoadOptions{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := os.Getenv(name); got != "" {
|
||||||
|
t.Fatal("pure loading changed environment")
|
||||||
|
}
|
||||||
|
_, prepared, err := configkit.LoadSecretsIntoEnvironmentFromConfig(PipelineSource(path, PipelineLoadOptions{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(path, []byte("invalid: ["), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
cfg, err := LoadPipelineSourceWithOptions(prepared, PipelineLoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if cfg.Workspace.Root != filepath.Join(dir, "captured") || EffectivePipelineRootPath(cfg) != path {
|
||||||
|
t.Fatalf("prepared context lost: root=%q source=%q", cfg.Workspace.Root, EffectivePipelineRootPath(cfg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user