Use native configuration validation and diagnostics
This commit is contained in:
@@ -16,9 +16,10 @@ read completed values without mutation.
|
|||||||
|
|
||||||
Session definitions receive selected-campaign defaults before loading finishes.
|
Session definitions receive selected-campaign defaults before loading finishes.
|
||||||
Recorded resolution preserves explicit empty/null/false/zero behavior and
|
Recorded resolution preserves explicit empty/null/false/zero behavior and
|
||||||
truthful dependencies. Identity and previous-session assertions are separate
|
truthful dependencies. Campaign, session, and previous-session assertions run
|
||||||
request checks against completed values. Standalone document renderers preserve
|
against resolved values in native validation callbacks. Standalone document
|
||||||
materialization semantics without providing a second inspection authority.
|
renderers preserve materialization semantics without providing a second
|
||||||
|
inspection authority.
|
||||||
|
|
||||||
Resource resolution consults native entry origins and source contexts. A usable
|
Resource resolution consults native entry origins and source contexts. A usable
|
||||||
effective source supplies the base, otherwise the main source and then captured
|
effective source supplies the base, otherwise the main source and then captured
|
||||||
@@ -55,7 +56,9 @@ selectors. App-only overrides pass through native selection into ConfigKit;
|
|||||||
they remain invocation-local. Field overrides are unavailable to domain
|
they remain invocation-local. Field overrides are unavailable to domain
|
||||||
execution/planning and other scopes. Shared bootstrap does not imply shared
|
execution/planning and other scopes. Shared bootstrap does not imply shared
|
||||||
overridden results. Public inspection and error paths preserve typed-secret
|
overridden results. Public inspection and error paths preserve typed-secret
|
||||||
redaction and credential reference metadata.
|
redaction and credential reference metadata. Load failures retain native errors
|
||||||
|
and source evidence; domain commands use `ckconfig.AdaptDiagnostics` for their
|
||||||
|
presentation without rewriting diagnostic records.
|
||||||
|
|
||||||
## Canonical Party And Derived Catalog
|
## Canonical Party And Derived Catalog
|
||||||
|
|
||||||
|
|||||||
@@ -70,61 +70,32 @@ Required remediation:
|
|||||||
existing round-trip expectation rather than preserving the newly frozen
|
existing round-trip expectation rather than preserving the newly frozen
|
||||||
behavior as a contract.
|
behavior as a contract.
|
||||||
|
|
||||||
## 2. P2: Classify identifiable Narratio input errors consistently
|
## 2. Simplify native validation and error presentation
|
||||||
|
|
||||||
Status: Domain-validation unit completed; native identity classification remains
|
Status: Completed. Identity assertions now use ConfigKit validation, and domain
|
||||||
pending upstream support. Catalog derivation now identifies invalid relations
|
commands present loading diagnostics through `ckconfig.AdaptDiagnostics`. Removed
|
||||||
with a typed input error, retaining its underlying cause. Native `artifacts list`
|
the custom identity error and its classification/presentation branches, along
|
||||||
and `run --stage analyze` regressions return status 2 for an unknown dependency;
|
with configuration-layer diagnostic rewriting. Native causes and joined
|
||||||
joined storage/cancellation errors retain status 1. ckconfig v0.9.0 and the current
|
operational failures remain intact. Regression coverage exercises campaign and
|
||||||
upstream checkout classify native ConfigKit load errors only and expose no
|
session mismatches (including right-side comparisons), malformed and missing
|
||||||
consumer classification hook. An upstream extension and its adoption are still
|
sources, and native warning visibility alongside joined failures. Full tests,
|
||||||
needed for campaign/session assertions in native acquisition and comparison;
|
race tests, vet, and build pass with Go 1.27.4. No upstream changes were needed.
|
||||||
permission to modify that repository has been requested.
|
|
||||||
|
|
||||||
Stages: 1, 7–10, and 12; native outcome verification in Stage 21.
|
Use ConfigKit's validation lifecycle for campaign/session identity assertions,
|
||||||
|
including comparison selections. Let ckconfig present and classify their native
|
||||||
|
diagnostics. Remove the separate identity error type and its presentation and
|
||||||
|
classification branches; no upstream extension is required.
|
||||||
|
|
||||||
Locations: `internal/app/configuration_commands.go:75–96`,
|
Retain native ConfigKit load errors and source evidence. Use ckconfig's existing
|
||||||
`internal/app/configuration_acquisition.go:294–297`, and
|
diagnostic adapter at Narratio's command boundary instead of rewriting source IDs
|
||||||
`internal/app/command_outcome.go:30–55`.
|
and embedding rendered diagnostics in configuration errors. Preserve useful
|
||||||
|
operation context and all joined operational causes.
|
||||||
|
|
||||||
Two integration paths return operational status 1 for identifiable input errors:
|
Keep minimal outcome adaptation for Narratio-owned input errors, partial reports,
|
||||||
|
and execution/persistence/resource-release failures. Preserve native visibility,
|
||||||
1. Native configuration acquisition/comparison returns
|
classification, and secret-safe diagnostics. Verify identity mismatches, malformed
|
||||||
`config.SessionIdentityError` for a supplied campaign/session identity that
|
and missing sources, comparison sides, and mixed operational failures through
|
||||||
differs from the selected file. The scope wrapper adds explanatory text but
|
native invocations.
|
||||||
passes the same error to ckconfig, whose classifier does not know Narratio's
|
|
||||||
type. For example, `config show --scope campaign --campaign-file FILE
|
|
||||||
--campaign WRONG` returns status 1. Session assertions and comparison-side
|
|
||||||
assertions have the same problem. The application outcome adapter recognizes
|
|
||||||
the type for domain commands, but native config commands do not use it.
|
|
||||||
2. Catalog derivation returns plain errors for invalid configuration relations.
|
|
||||||
A configured artifact with `depends_on: [missing]` reaches domain derivation,
|
|
||||||
then `artifacts list` and `run --stage analyze` return status 1. The error
|
|
||||||
unambiguously identifies invalid supplied configuration, not a service failure.
|
|
||||||
Such relational validation belongs in domain derivation; moving family
|
|
||||||
expansion into native app inspection is not the remedy.
|
|
||||||
|
|
||||||
The roadmap and [CLI outcome contract](../cli.md#cancellation-and-exit-status)
|
|
||||||
reserve status 2 for invalid invocation or identifiable configuration input.
|
|
||||||
Current identity tests check only a nonzero status and explanatory text, leaving
|
|
||||||
this integration mismatch undetected.
|
|
||||||
|
|
||||||
Required remediation:
|
|
||||||
|
|
||||||
- Preserve the agreed status 2 classification for post-resolution identity
|
|
||||||
assertions in native config acquisition and comparison, including the right
|
|
||||||
side. Use genuine native resolution/validation or a supported classification
|
|
||||||
integration point while preserving the underlying typed cause. If the released
|
|
||||||
API lacks the necessary integration point, address that narrow capability
|
|
||||||
upstream rather than forking native commands or matching error strings.
|
|
||||||
- Give Narratio-owned invalid domain-configuration relations typed input
|
|
||||||
classification at their existing boundary. Keep cancellation, storage/access
|
|
||||||
failures, shutdown/persistence errors, and mixed operational causes at status 1.
|
|
||||||
Do not classify every acquisition or catalog error as user input indiscriminately.
|
|
||||||
- Add native invocation regressions asserting exact status classification for
|
|
||||||
campaign/session mismatch, comparison-side mismatch, and an unknown artifact
|
|
||||||
dependency, alongside an operational or joined-cause counterexample.
|
|
||||||
|
|
||||||
## 3. P2: Correct the documented empty spell-catalog behavior
|
## 3. P2: Correct the documented empty spell-catalog behavior
|
||||||
|
|
||||||
@@ -516,4 +487,5 @@ with official Go 1.27.4. Documentation checks and `git diff --check` also pass.
|
|||||||
Native regression coverage verifies equivalent-party resume, real roster changes,
|
Native regression coverage verifies equivalent-party resume, real roster changes,
|
||||||
source normalization, and typed domain-input outcomes. No upstream files,
|
source normalization, and typed domain-input outcomes. No upstream files,
|
||||||
dependencies, releases, tags, or remote repositories were changed. Finding 2's
|
dependencies, releases, tags, or remote repositories were changed. Finding 2's
|
||||||
native configuration identity classification remains outstanding as recorded above.
|
local simplifications are also complete and verified with the same checks on
|
||||||
|
Go 1.27.4, as recorded above.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func artifactCatalogCommand(deps commandDependencies) commandkit.Command {
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func cleanCommand(deps commandDependencies) commandkit.Command {
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"go.maximumdirect.net/ckconfig"
|
"go.maximumdirect.net/ckconfig"
|
||||||
"go.maximumdirect.net/commandkit"
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// inputError identifies an invalid Narratio request independently of native
|
// inputError identifies an invalid Narratio request independently of native
|
||||||
@@ -29,7 +30,7 @@ func operationOutcome(err error) commandkit.Outcome {
|
|||||||
|
|
||||||
func classifyOperationError(err error) commandkit.OutcomeKind {
|
func classifyOperationError(err error) commandkit.OutcomeKind {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *inputError, *config.SessionIdentityError, *config.ArtifactCatalogInputError:
|
case *inputError, *config.ArtifactCatalogInputError:
|
||||||
return commandkit.OutcomeUsage
|
return commandkit.OutcomeUsage
|
||||||
}
|
}
|
||||||
switch wrapped := err.(type) {
|
switch wrapped := err.(type) {
|
||||||
@@ -54,3 +55,37 @@ func classifyOperationError(err error) commandkit.OutcomeKind {
|
|||||||
}
|
}
|
||||||
return ckconfig.ClassifyConfigurationError(err)
|
return ckconfig.ClassifyConfigurationError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reportOperationOutcome leaves native configuration evidence to ckconfig while
|
||||||
|
// retaining the operation's context and any joined cleanup or persistence causes.
|
||||||
|
func reportOperationOutcome(inv commandkit.Invocation, err error) commandkit.Outcome {
|
||||||
|
outcome := operationOutcome(err)
|
||||||
|
var details []commandkit.Detail
|
||||||
|
var visit func(error)
|
||||||
|
visit = func(e error) {
|
||||||
|
if e == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if load, ok := e.(*configkit.LoadError); ok {
|
||||||
|
warnings, explanation := ckconfig.AdaptDiagnostics("Configuration:\n", load.Sources(), load.Diagnostics())
|
||||||
|
for _, warning := range warnings {
|
||||||
|
_ = inv.Reporter().Warn("", warning.Write)
|
||||||
|
}
|
||||||
|
details = append(details, explanation.Details...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch wrapped := e.(type) {
|
||||||
|
case interface{ Unwrap() []error }:
|
||||||
|
for _, child := range wrapped.Unwrap() {
|
||||||
|
visit(child)
|
||||||
|
}
|
||||||
|
case interface{ Unwrap() error }:
|
||||||
|
visit(wrapped.Unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
visit(err)
|
||||||
|
if len(details) > 0 {
|
||||||
|
outcome = outcome.WithExplanation(err.Error(), details...)
|
||||||
|
}
|
||||||
|
return outcome
|
||||||
|
}
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ func TestOperationOutcomePreservesCausesAndOperationalPrecedence(t *testing.T) {
|
|||||||
{catalogInput, 2},
|
{catalogInput, 2},
|
||||||
{errors.Join(catalogInput, operational), 1},
|
{errors.Join(catalogInput, operational), 1},
|
||||||
{errors.Join(catalogInput, context.Canceled), 1},
|
{errors.Join(catalogInput, context.Canceled), 1},
|
||||||
{&config.SessionIdentityError{Source: "session.yml", Field: "session_id", Expected: "one", Actual: "two"}, 2},
|
|
||||||
{fmt.Errorf("request: %w", errors.Join(input, invalid)), 2},
|
{fmt.Errorf("request: %w", errors.Join(input, invalid)), 2},
|
||||||
{errors.Join(input, operational), 1},
|
{errors.Join(input, operational), 1},
|
||||||
{fmt.Errorf("request: %w", errors.Join(invalid, context.Canceled)), 1},
|
{fmt.Errorf("request: %w", errors.Join(invalid, context.Canceled)), 1},
|
||||||
@@ -175,3 +174,62 @@ func TestNativeTreeRejectsRemovedRoutesAndMissingOperandsBeforeAcquisition(t *te
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDomainCommandsUseNativeConfigurationDiagnostics(t *testing.T) {
|
||||||
|
root := t.TempDir()
|
||||||
|
invalid := filepath.Join(root, "invalid.yml")
|
||||||
|
if err := os.WriteFile(invalid, []byte("unknown_field: true\n"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, tc := range []struct {
|
||||||
|
path, code string
|
||||||
|
status int
|
||||||
|
}{
|
||||||
|
{invalid, "decode.unknown_field", 2},
|
||||||
|
{filepath.Join(root, "missing.yml"), "source.missing", 1},
|
||||||
|
} {
|
||||||
|
for _, command := range [][]string{{"config", "show"}, {"artifacts", "list"}} {
|
||||||
|
var out, diag bytes.Buffer
|
||||||
|
args := append(append([]string{}, command...), "--config", tc.path, "--quiet")
|
||||||
|
result := Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diag})
|
||||||
|
var load *configkit.LoadError
|
||||||
|
if result.Status != tc.status || !errors.As(result.Cause, &load) || out.Len() != 0 {
|
||||||
|
t.Fatalf("%v: %+v", args, result)
|
||||||
|
}
|
||||||
|
if !strings.Contains(diag.String(), tc.code) || !strings.Contains(diag.String(), tc.path) || strings.Contains(diag.String(), "strict decode failed or validation failed") {
|
||||||
|
t.Fatalf("%v: %s", args, diag.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNativeDiagnosticsRetainWarningsAndJoinedOperationalCause(t *testing.T) {
|
||||||
|
_, loadErr := configkit.Load(configkit.NoSource(), configkit.Options[struct{}]{Definition: configkit.Definition[struct{}]{Validate: func(_ *struct{}, v *configkit.Validation) {
|
||||||
|
v.Warning(configkit.Keys(), "review warning")
|
||||||
|
v.Error(configkit.Keys(), "review invalid input")
|
||||||
|
}}})
|
||||||
|
if loadErr == nil {
|
||||||
|
t.Fatal("expected validation failure")
|
||||||
|
}
|
||||||
|
cleanup := errors.New("resource release failed")
|
||||||
|
for _, verbose := range []bool{false, true} {
|
||||||
|
application, err := commandkit.New(commandkit.Identity{Name: "test"}, commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "fail", Run: func(inv commandkit.Invocation, _ struct{}) commandkit.Outcome {
|
||||||
|
return reportOperationOutcome(inv, errors.Join(loadErr, cleanup))
|
||||||
|
}}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
args := []string{"fail"}
|
||||||
|
if verbose {
|
||||||
|
args = append(args, "--verbose")
|
||||||
|
}
|
||||||
|
var diag bytes.Buffer
|
||||||
|
outcome := application.Execute(context.Background(), args, commandkit.Streams{Out: io.Discard, Err: &diag})
|
||||||
|
if outcome.Status != 1 || !errors.Is(outcome.Cause, cleanup) || !errors.Is(outcome.Cause, loadErr) {
|
||||||
|
t.Fatalf("%+v", outcome)
|
||||||
|
}
|
||||||
|
if !strings.Contains(diag.String(), "review invalid input") || !strings.Contains(diag.String(), cleanup.Error()) || strings.Contains(diag.String(), "review warning") != verbose {
|
||||||
|
t.Fatalf("verbose=%t: %s", verbose, diag.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -115,14 +115,11 @@ func (a *configurationAcquisition) Campaign(ctx context.Context) (*config.Campai
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cfg, err := config.LoadCampaign(path)
|
cfg, err := config.LoadCampaignWithIdentity(path, a.selection.Campaign.Value)
|
||||||
err = errors.Join(err, ctx.Err())
|
err = errors.Join(err, ctx.Err())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if a.selection.Campaign.Set && config.CampaignID(cfg) != a.selection.Campaign.Value {
|
|
||||||
return nil, &config.SessionIdentityError{Source: path, Field: "campaign_id", Expected: a.selection.Campaign.Value, Actual: config.CampaignID(cfg)}
|
|
||||||
}
|
|
||||||
a.campaign, a.campaignPath = cfg, path
|
a.campaign, a.campaignPath = cfg, path
|
||||||
if a.deps.reporter != nil {
|
if a.deps.reporter != nil {
|
||||||
a.deps.reporter.Info("selected campaign configuration", "campaign", config.CampaignID(cfg), "source", path)
|
a.deps.reporter.Info("selected campaign configuration", "campaign", config.CampaignID(cfg), "source", path)
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ func TestConfigurationAcquisitionIdentityAndExplicitEmpty(t *testing.T) {
|
|||||||
CampaignFile: suppliedSelection(campaignPath), Campaign: suppliedSelection("other-campaign"),
|
CampaignFile: suppliedSelection(campaignPath), Campaign: suppliedSelection("other-campaign"),
|
||||||
}, commandDependencies{})
|
}, commandDependencies{})
|
||||||
_, err := acquired.Campaign(context.Background())
|
_, err := acquired.Campaign(context.Background())
|
||||||
var identity *config.SessionIdentityError
|
var identity *configkit.LoadError
|
||||||
if !errors.As(err, &identity) || identity.Field != "campaign_id" {
|
if !errors.As(err, &identity) {
|
||||||
t.Fatalf("identity error=%v", err)
|
t.Fatalf("identity error=%v", err)
|
||||||
}
|
}
|
||||||
acquired = newConfigurationAcquisition(configurationSelection{CampaignFile: suppliedSelection("")}, commandDependencies{})
|
acquired = newConfigurationAcquisition(configurationSelection{CampaignFile: suppliedSelection("")}, commandDependencies{})
|
||||||
|
|||||||
@@ -77,10 +77,6 @@ func configurationCommand(deps commandDependencies) commandkit.Command {
|
|||||||
scopes[index].Acquire = func(ctx context.Context, request ckconfig.Request, input configurationSelection, state *configurationInspectionState) (commandkit.Acquired[ckconfig.View], error) {
|
scopes[index].Acquire = func(ctx context.Context, request ckconfig.Request, input configurationSelection, state *configurationInspectionState) (commandkit.Acquired[ckconfig.View], error) {
|
||||||
result, err := acquire(ctx, request, input, state)
|
result, err := acquire(ctx, request, input, state)
|
||||||
result.Diagnostics = append(result.Diagnostics, state.bootstrapDiagnostics()...)
|
result.Diagnostics = append(result.Diagnostics, state.bootstrapDiagnostics()...)
|
||||||
var identity *config.SessionIdentityError
|
|
||||||
if errors.As(err, &identity) {
|
|
||||||
result.Explanation.Message = identity.Error()
|
|
||||||
}
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
compare := scopes[index].Compare
|
compare := scopes[index].Compare
|
||||||
@@ -89,10 +85,6 @@ func configurationCommand(deps commandDependencies) commandkit.Command {
|
|||||||
separate.independent = true
|
separate.independent = true
|
||||||
result, err := compare(ctx, request, &separate)
|
result, err := compare(ctx, request, &separate)
|
||||||
result.Diagnostics = append(result.Diagnostics, state.bootstrapDiagnostics()...)
|
result.Diagnostics = append(result.Diagnostics, state.bootstrapDiagnostics()...)
|
||||||
var identity *config.SessionIdentityError
|
|
||||||
if errors.As(err, &identity) {
|
|
||||||
result.Explanation.Message = identity.Error()
|
|
||||||
}
|
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,17 +175,18 @@ func TestConfigurationInspectionExplainsIdentityMismatches(t *testing.T) {
|
|||||||
{"config", "show", "--scope", "campaign", "--campaign-file", campaign, "--campaign", "other-campaign"},
|
{"config", "show", "--scope", "campaign", "--campaign-file", campaign, "--campaign", "other-campaign"},
|
||||||
{"config", "show", "--scope", "session", "--campaign-file", campaign, "--session-file", session, "--session", "other-session"},
|
{"config", "show", "--scope", "session", "--campaign-file", campaign, "--session-file", session, "--session", "other-session"},
|
||||||
{"config", "diff", "--scope", "campaign", "--campaign-file", campaign, "--against-campaign-file", campaign, "--against-campaign", "other-campaign"},
|
{"config", "diff", "--scope", "campaign", "--campaign-file", campaign, "--against-campaign-file", campaign, "--against-campaign", "other-campaign"},
|
||||||
|
{"config", "diff", "--scope", "session", "--campaign-file", campaign, "--session-file", session, "--against-campaign-file", campaign, "--against-session-file", session, "--against-session", "other-session"},
|
||||||
} {
|
} {
|
||||||
var output, diagnostics bytes.Buffer
|
var output, diagnostics bytes.Buffer
|
||||||
result := Execute(context.Background(), args, commandkit.Streams{Out: &output, Err: &diagnostics})
|
result := Execute(context.Background(), args, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||||
var identity *config.SessionIdentityError
|
var identity *configkit.LoadError
|
||||||
if result.Status == 0 || !errors.As(result.Cause, &identity) {
|
if result.Status != 2 || !errors.As(result.Cause, &identity) {
|
||||||
t.Fatalf("%v: identity cause missing: %#v", args, result)
|
t.Fatalf("%v: identity cause missing: %#v", args, result)
|
||||||
}
|
}
|
||||||
if output.Len() != 0 || !strings.Contains(diagnostics.String(), identity.Field) || !strings.Contains(diagnostics.String(), identity.Expected) || !strings.Contains(diagnostics.String(), identity.Actual) {
|
if output.Len() != 0 || !strings.Contains(diagnostics.String(), "mismatch") || !strings.Contains(diagnostics.String(), "other-") || !strings.Contains(diagnostics.String(), "validate.error") {
|
||||||
t.Fatalf("%v: assertion not explained: %s", args, diagnostics.String())
|
t.Fatalf("%v: assertion not explained: %s", args, diagnostics.String())
|
||||||
}
|
}
|
||||||
if identity.Field == "campaign_id" && strings.Contains(diagnostics.String(), "session file") {
|
if strings.Contains(diagnostics.String(), "campaign_id") && strings.Contains(diagnostics.String(), "session file") {
|
||||||
t.Fatalf("campaign assertion mislabeled: %s", diagnostics.String())
|
t.Fatalf("campaign assertion mislabeled: %s", diagnostics.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
internal/app/error_test.go
Normal file
21
internal/app/error_test.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
// configurationErrorText renders native evidence for assertions about validation messages.
|
||||||
|
func configurationErrorText(err error) string {
|
||||||
|
if err == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if !errors.As(err, &native) {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
var b bytes.Buffer
|
||||||
|
_ = configkit.WriteDiagnostics(&b, native.Diagnostics())
|
||||||
|
return err.Error() + "\n" + b.String()
|
||||||
|
}
|
||||||
@@ -73,7 +73,7 @@ func executionCommand(name, summary string, regenerate bool, deps commandDepende
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
}
|
}
|
||||||
return commandkit.NewCommand(spec)
|
return commandkit.NewCommand(spec)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func lockCommand(operation string, deps commandDependencies) commandkit.Command
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ inputs:
|
|||||||
if code == 0 {
|
if code == 0 {
|
||||||
t.Fatal("exit code = 0, want non-zero")
|
t.Fatal("exit code = 0, want non-zero")
|
||||||
}
|
}
|
||||||
if !strings.Contains(stderr.String(), "strict decode failed") {
|
if !strings.Contains(stderr.String(), "decode.unknown_field") {
|
||||||
t.Fatalf("stderr = %q, want strict decode error", stderr.String())
|
t.Fatalf("stderr = %q, want strict decode error", stderr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestRunOverlaySelectionFlowsThroughSharedLoader(t *testing.T) {
|
|||||||
|
|
||||||
for _, overlay := range []string{"unknown"} {
|
for _, overlay := range []string{"unknown"} {
|
||||||
err := invokeNativeCommandWith(context.Background(), []string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--overlay", overlay}, io.Discard, executor, commandDependencies{})
|
err := invokeNativeCommandWith(context.Background(), []string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--overlay", overlay}, io.Discard, executor, commandDependencies{})
|
||||||
if err == nil || !strings.Contains(err.Error(), "overlay") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "overlay") {
|
||||||
t.Fatalf("overlay %q error = %v, want selection rejection", overlay, err)
|
t.Fatalf("overlay %q error = %v, want selection rejection", overlay, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func sessionPlanCommand(deps commandDependencies) commandkit.Command {
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
}
|
}
|
||||||
return commandkit.NewCommand(spec)
|
return commandkit.NewCommand(spec)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ func TestExecuteRemoteSessionMalformedYAMLFailsStrictDecode(t *testing.T) {
|
|||||||
if code == 0 {
|
if code == 0 {
|
||||||
t.Fatal("exit code = 0, want non-zero")
|
t.Fatal("exit code = 0, want non-zero")
|
||||||
}
|
}
|
||||||
if !strings.Contains(stderr.String(), "strict decode failed") {
|
if !strings.Contains(stderr.String(), "decode.unknown_field") {
|
||||||
t.Fatalf("stderr = %q, want strict decode context", stderr.String())
|
t.Fatalf("stderr = %q, want strict decode context", stderr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ func restoreCommand(deps commandDependencies) commandkit.Command {
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ inputs:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "session.yml must be concrete") {
|
if !strings.Contains(configurationErrorText(err), "session.yml must be concrete") {
|
||||||
t.Fatalf("error = %q, want concrete session guidance", err.Error())
|
t.Fatalf("error = %q, want concrete session guidance", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "run narratio session init") {
|
if !strings.Contains(configurationErrorText(err), "run narratio session init") {
|
||||||
t.Fatalf("error = %q, want session init guidance", err.Error())
|
t.Fatalf("error = %q, want session init guidance", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ func TestPlanFailsWhenSessionIDMismatchesConcreteSession(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "session_id mismatch") {
|
if !strings.Contains(configurationErrorText(err), "session_id mismatch") {
|
||||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
t.Fatalf("error = %q, want mismatch context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +88,8 @@ inputs:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "previous_session_id mismatch") {
|
if !strings.Contains(configurationErrorText(err), "previous_session_id mismatch") {
|
||||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
t.Fatalf("error = %q, want mismatch context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,8 +106,8 @@ func TestPlanRequiresExpectedPreviousSessionID(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "previous_session_id is required") {
|
if !strings.Contains(configurationErrorText(err), "previous_session_id is required") {
|
||||||
t.Fatalf("error = %q, want missing previous-session expectation", err.Error())
|
t.Fatalf("error = %q, want missing previous-session expectation", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +130,10 @@ func TestResolveSessionConfigPathErrorIncludesSearchedPaths(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "searched") {
|
if !strings.Contains(configurationErrorText(err), "searched") {
|
||||||
t.Fatalf("error = %q, want searched paths", err.Error())
|
t.Fatalf("error = %q, want searched paths", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "pass --session") {
|
if !strings.Contains(configurationErrorText(err), "pass --session") {
|
||||||
t.Fatalf("error = %q, want explicit-session guidance", err.Error())
|
t.Fatalf("error = %q, want explicit-session guidance", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func sessionInitializationCommand(deps commandDependencies) commandkit.Command {
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func sessionValidationCommand(deps commandDependencies) commandkit.Command {
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
}
|
}
|
||||||
return commandkit.NewCommand(spec)
|
return commandkit.NewCommand(spec)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func sessionStateCommand(name string, status bool, deps commandDependencies) com
|
|||||||
if report != nil {
|
if report != nil {
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
}
|
}
|
||||||
return operationOutcome(err)
|
return reportOperationOutcome(invocation, err)
|
||||||
}
|
}
|
||||||
return commandkit.NewCommand(spec)
|
return commandkit.NewCommand(spec)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func TestArtifactFamiliesRejectInvalidExpansionDeclarations(t *testing.T) {
|
|||||||
writePartyResolutionFile(t, dir+"/party.yml", test.party)
|
writePartyResolutionFile(t, dir+"/party.yml", test.party)
|
||||||
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(test.families))
|
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(test.families))
|
||||||
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||||
if err == nil || !strings.Contains(err.Error(), test.wantError) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.wantError) {
|
||||||
t.Fatalf("LoadWithSessionOptions() error = %v, want %q", err, test.wantError)
|
t.Fatalf("LoadWithSessionOptions() error = %v, want %q", err, test.wantError)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -157,7 +157,7 @@ func TestArtifactFamilyStrictDecodeRejectsUnknownFields(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
pipelinePath, _, _ := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(validFamilyYAML+" unsupported: true\n"))
|
pipelinePath, _, _ := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(validFamilyYAML+" unsupported: true\n"))
|
||||||
_, err := LoadPipeline(pipelinePath)
|
_, err := LoadPipeline(pipelinePath)
|
||||||
if err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("LoadPipeline() error = %v", err)
|
t.Fatalf("LoadPipeline() error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ func TestArtifactFamiliesRejectGeneratedKeyAndOutputCollisions(t *testing.T) {
|
|||||||
Scriptorium: &ScriptoriumConfig{Artifacts: test.artifacts, ArtifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{"character_meta": base}},
|
Scriptorium: &ScriptoriumConfig{Artifacts: test.artifacts, ArtifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{"character_meta": base}},
|
||||||
}
|
}
|
||||||
_, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document})
|
_, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document})
|
||||||
if err == nil || !strings.Contains(err.Error(), test.wantError) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.wantError) {
|
||||||
t.Fatalf("DeriveArtifactCatalog() error = %v, want %q", err, test.wantError)
|
t.Fatalf("DeriveArtifactCatalog() error = %v, want %q", err, test.wantError)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -274,7 +274,7 @@ func TestArtifactFamiliesRejectInvalidMemberDependenciesAndSources(t *testing.T)
|
|||||||
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), canonicalPartyFixture)
|
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), canonicalPartyFixture)
|
||||||
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(test.families))
|
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(test.families))
|
||||||
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||||
if err == nil || !strings.Contains(err.Error(), test.want) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.want) {
|
||||||
t.Fatalf("error = %v, want %q", err, test.want)
|
t.Fatalf("error = %v, want %q", err, test.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -293,11 +293,11 @@ func TestArtifactFamiliesRejectInvalidMemberDependenciesAndSources(t *testing.T)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(err.Error(), "outside an artifact family") {
|
if _, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(configurationErrorText(err), "outside an artifact family") {
|
||||||
t.Fatalf("concrete member source error = %v", err)
|
t.Fatalf("concrete member source error = %v", err)
|
||||||
}
|
}
|
||||||
pipeline.Scriptorium.Artifacts["explicit"] = ScriptoriumArtifactConfig{Inputs: map[string]ScriptoriumInputConfig{"bad": {Source: "narratio.member_artifact."}}}
|
pipeline.Scriptorium.Artifacts["explicit"] = ScriptoriumArtifactConfig{Inputs: map[string]ScriptoriumInputConfig{"bad": {Source: "narratio.member_artifact."}}}
|
||||||
if _, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(err.Error(), "malformed member artifact source") {
|
if _, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(configurationErrorText(err), "malformed member artifact source") {
|
||||||
t.Fatalf("malformed concrete member source error = %v", err)
|
t.Fatalf("malformed concrete member source error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,7 +326,7 @@ func TestFamilyPublishRulesExpandToConcreteArtifacts(t *testing.T) {
|
|||||||
cfg.Publish.Outputs = nil
|
cfg.Publish.Outputs = nil
|
||||||
catalog.Families["character_meta"] = ArtifactFamilyOrigin{Members: []string{"character_meta_alpha"}, Publish: &ScriptoriumArtifactFamilyPublishConfig{Enabled: true}}
|
catalog.Families["character_meta"] = ArtifactFamilyOrigin{Members: []string{"character_meta_alpha"}, Publish: &ScriptoriumArtifactFamilyPublishConfig{Enabled: true}}
|
||||||
cfg.Publish = nil
|
cfg.Publish = nil
|
||||||
if err := deriveFamilyPublishRules(cfg, derived); err == nil || !strings.Contains(err.Error(), "requires pipeline.publish") {
|
if err := deriveFamilyPublishRules(cfg, derived); err == nil || !strings.Contains(configurationErrorText(err), "requires pipeline.publish") {
|
||||||
t.Fatalf("missing publish error = %v", err)
|
t.Fatalf("missing publish error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -565,7 +565,7 @@ publish:
|
|||||||
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, pipeline)
|
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, pipeline)
|
||||||
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||||
if test.wantErr != "" {
|
if test.wantErr != "" {
|
||||||
if err == nil || !strings.Contains(err.Error(), test.wantErr) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.wantErr) {
|
||||||
t.Fatalf("LoadWithSessionOptions() error = %v, want %q", err, test.wantErr)
|
t.Fatalf("LoadWithSessionOptions() error = %v, want %q", err, test.wantErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ inputs:
|
|||||||
audio_dir: ./audio
|
audio_dir: ./audio
|
||||||
`)
|
`)
|
||||||
_, err := Load(pipelinePath, sessionPath)
|
_, err := Load(pipelinePath, sessionPath)
|
||||||
if err == nil || !strings.Contains(err.Error(), "strict decode failed") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("Load() error = %v, want strict decode failed", err)
|
t.Fatalf("Load() error = %v, want strict decode failed", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ inputs:
|
|||||||
audio_dir: ./audio
|
audio_dir: ./audio
|
||||||
`)
|
`)
|
||||||
_, err := Load(pipelinePath, sessionPath)
|
_, err := Load(pipelinePath, sessionPath)
|
||||||
if err == nil || !strings.Contains(err.Error(), "pipeline.cache.root is required") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "pipeline.cache.root is required") {
|
||||||
t.Fatalf("Load() error = %v, want cache root error", err)
|
t.Fatalf("Load() error = %v, want cache root error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ func TestCampaignStrictDecodeRejectsLegacyCampaignField(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected load error, got nil")
|
t.Fatal("expected load error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "load campaign config") || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if !strings.Contains(configurationErrorText(err), "load campaign config") || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("error = %q, want campaign strict decode context", err.Error())
|
t.Fatalf("error = %q, want campaign strict decode context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +75,8 @@ func TestCampaignStrictDecodeRejectsUnknownFields(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected load error, got nil")
|
t.Fatal("expected load error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "load campaign config") || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if !strings.Contains(configurationErrorText(err), "load campaign config") || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("error = %q, want campaign strict decode context", err.Error())
|
t.Fatalf("error = %q, want campaign strict decode context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ func TestCampaignSessionMergeRejectsWhitespaceSpellCatalog(t *testing.T) {
|
|||||||
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n"+tt.sessionLine,
|
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n"+tt.sessionLine,
|
||||||
)
|
)
|
||||||
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantErr) {
|
||||||
t.Fatalf("LoadWithSessionOptions() error = %v, want containing %q", err, tt.wantErr)
|
t.Fatalf("LoadWithSessionOptions() error = %v, want containing %q", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -225,8 +225,8 @@ func TestCampaignSessionMismatchFails(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected load error, got nil")
|
t.Fatal("expected load error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "campaign mismatch") {
|
if !strings.Contains(configurationErrorText(err), "campaign mismatch") {
|
||||||
t.Fatalf("error = %q, want campaign mismatch context", err.Error())
|
t.Fatalf("error = %q, want campaign mismatch context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +241,8 @@ func TestLoadMissingCampaignFileFails(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected load error, got nil")
|
t.Fatal("expected load error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "load campaign config") {
|
if !strings.Contains(configurationErrorText(err), "load campaign config") {
|
||||||
t.Fatalf("error = %q, want campaign load context", err.Error())
|
t.Fatalf("error = %q, want campaign load context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
@@ -53,7 +54,7 @@ func documentResource(resolution *configkit.Resolution, path configkit.Path, val
|
|||||||
resolveHostResource(resolution, path, value, invocationDir)
|
resolveHostResource(resolution, path, value, invocationDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func campaignDefinition(invocationDir string, sources map[string]string) configkit.Definition[CampaignConfig] {
|
func campaignDefinition(invocationDir string, sources map[string]string, expected string) configkit.Definition[CampaignConfig] {
|
||||||
return configkit.Definition[CampaignConfig]{Resolve: func(cfg *CampaignConfig, resolution *configkit.Resolution) error {
|
return configkit.Definition[CampaignConfig]{Resolve: func(cfg *CampaignConfig, resolution *configkit.Resolution) error {
|
||||||
documentResource(resolution, configkit.Keys("session_template_file"), &cfg.SessionTemplateFile, invocationDir, sources)
|
documentResource(resolution, configkit.Keys("session_template_file"), &cfg.SessionTemplateFile, invocationDir, sources)
|
||||||
inputs := configkit.Keys("inputs")
|
inputs := configkit.Keys("inputs")
|
||||||
@@ -68,7 +69,10 @@ func campaignDefinition(invocationDir string, sources map[string]string) configk
|
|||||||
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, Validate: validateCampaignConfigKit}
|
}, Validate: func(cfg *CampaignConfig, v *configkit.Validation) {
|
||||||
|
validateCampaignConfigKit(cfg, v)
|
||||||
|
validateIdentity(v, "campaign_id", expected, CampaignID(cfg))
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sessionDefinition(invocationDir string, sources map[string]string, label string, opts SessionLoadOptions) configkit.Definition[SessionConfig] {
|
func sessionDefinition(invocationDir string, sources map[string]string, label string, opts SessionLoadOptions) configkit.Definition[SessionConfig] {
|
||||||
@@ -101,6 +105,12 @@ func sessionDefinition(invocationDir string, sources map[string]string, label st
|
|||||||
if !hasSource {
|
if !hasSource {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
validateIdentity(validation, "session_id", strings.TrimSpace(opts.SessionID), strings.TrimSpace(cfg.SessionID))
|
||||||
|
validateIdentity(validation, "previous_session_id", strings.TrimSpace(opts.PreviousSessionID), strings.TrimSpace(cfg.PreviousSessionID))
|
||||||
|
if opts.Campaign != nil {
|
||||||
|
validateIdentity(validation, "campaign", CampaignID(opts.Campaign), cfg.Campaign)
|
||||||
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(cfg)
|
data, err := json.Marshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
validation.Error(configkit.Keys(), "cannot inspect session configuration")
|
validation.Error(configkit.Keys(), "cannot inspect session configuration")
|
||||||
@@ -138,15 +148,16 @@ func applyCampaignSessionDefaults(cfg *SessionConfig, resolution *configkit.Reso
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadCampaignWithConfigKit(path string) (*CampaignConfig, error) {
|
// LoadCampaignWithIdentity validates an optional asserted identity within the native load.
|
||||||
|
func LoadCampaignWithIdentity(path, expected string) (*CampaignConfig, error) {
|
||||||
invocationDir, err := os.Getwd()
|
invocationDir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sources := make(map[string]string)
|
sources := make(map[string]string)
|
||||||
result, err := configkit.Load(configkit.File(path), configkit.Options[CampaignConfig]{Imports: true, Definition: campaignDefinition(invocationDir, sources)})
|
result, err := configkit.Load(configkit.File(path), configkit.Options[CampaignConfig]{Imports: true, Definition: campaignDefinition(invocationDir, sources, expected)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, describeConfigKitLoadError("campaign", err)
|
return nil, fmt.Errorf("load campaign config: %w", err)
|
||||||
}
|
}
|
||||||
cfg := &result.Config
|
cfg := &result.Config
|
||||||
cfg.resolution = &documentResolution{campaign: result, sources: sources}
|
cfg.resolution = &documentResolution{campaign: result, sources: sources}
|
||||||
@@ -180,7 +191,7 @@ func loadSessionSourceWithFilesystem(source configkit.Source, label string, opts
|
|||||||
sources := make(map[string]string)
|
sources := make(map[string]string)
|
||||||
result, err := configkit.Load(source, configkit.Options[SessionConfig]{Imports: imports, Filesystem: filesystem, Definition: sessionDefinition(invocationDir, sources, label, opts)})
|
result, err := configkit.Load(source, configkit.Options[SessionConfig]{Imports: imports, Filesystem: filesystem, Definition: sessionDefinition(invocationDir, sources, label, opts)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", describeConfigKitLoadError("session", err)
|
return nil, "", fmt.Errorf("load session config: %w", err)
|
||||||
}
|
}
|
||||||
acquired := result.Sources()
|
acquired := result.Sources()
|
||||||
if len(acquired) == 0 {
|
if len(acquired) == 0 {
|
||||||
@@ -191,9 +202,6 @@ func loadSessionSourceWithFilesystem(source configkit.Source, label string, opts
|
|||||||
selected = label
|
selected = label
|
||||||
}
|
}
|
||||||
cfg := &result.Config
|
cfg := &result.Config
|
||||||
if err := validateSessionIdentity(selected, cfg, opts); err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
cfg.resolution = &documentResolution{session: result, sources: sources}
|
cfg.resolution = &documentResolution{session: result, sources: sources}
|
||||||
return cfg, filepath.Clean(selected), nil
|
return cfg, filepath.Clean(selected), nil
|
||||||
}
|
}
|
||||||
@@ -203,3 +211,11 @@ func loadSessionSourceWithFilesystem(source configkit.Source, label string, opts
|
|||||||
func DiscoverSession(candidates []string, opts SessionLoadOptions) (*SessionConfig, string, error) {
|
func DiscoverSession(candidates []string, opts SessionLoadOptions) (*SessionConfig, string, error) {
|
||||||
return loadSessionSource(configkit.SearchConfig("narratio", configkit.SearchPaths(candidates...)), "", opts, true)
|
return loadSessionSource(configkit.SearchConfig("narratio", configkit.SearchPaths(candidates...)), "", opts, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateIdentity(v *configkit.Validation, field, expected, actual string) {
|
||||||
|
if expected != "" && actual == "" {
|
||||||
|
v.Error(configkit.Keys(field), fmt.Sprintf("%s is required when %q is selected", field, expected))
|
||||||
|
} else if expected != "" && actual != expected {
|
||||||
|
v.Error(configkit.Keys(field), fmt.Sprintf("%s mismatch: selected %q does not match %q", field, expected, actual))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestContextlessDocumentsRejectImports(t *testing.T) {
|
|||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
if err := load(); err == nil || !strings.Contains(err.Error(), "import.disabled") {
|
if err := load(); err == nil || !strings.Contains(configurationErrorText(err), "import.disabled") {
|
||||||
t.Fatalf("load error = %v, want disabled-import diagnostic", err)
|
t.Fatalf("load error = %v, want disabled-import diagnostic", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,10 @@ func TestContextlessDocumentsRejectImports(t *testing.T) {
|
|||||||
|
|
||||||
func TestInspectedDocumentsEnforceConfigKitSizeLimit(t *testing.T) {
|
func TestInspectedDocumentsEnforceConfigKitSizeLimit(t *testing.T) {
|
||||||
tooLarge := bytes.Repeat([]byte{' '}, int(maxConfigDocumentBytes)+1)
|
tooLarge := bytes.Repeat([]byte{' '}, int(maxConfigDocumentBytes)+1)
|
||||||
if _, err := LoadSessionBytesWithOptions("session.yml", tooLarge, SessionLoadOptions{}); err == nil || !strings.Contains(err.Error(), "exceeds") {
|
if _, err := LoadSessionBytesWithOptions("session.yml", tooLarge, SessionLoadOptions{}); err == nil || !strings.Contains(configurationErrorText(err), "exceeds") {
|
||||||
t.Fatalf("oversized session error = %v", err)
|
t.Fatalf("oversized session error = %v", err)
|
||||||
}
|
}
|
||||||
if _, err := ParseParty(tooLarge); err == nil || !strings.Contains(err.Error(), "exceeds") {
|
if _, err := ParseParty(tooLarge); err == nil || !strings.Contains(configurationErrorText(err), "exceeds") {
|
||||||
t.Fatalf("oversized party error = %v", err)
|
t.Fatalf("oversized party error = %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ func TestInspectedDocumentsEnforceConfigKitSizeLimit(t *testing.T) {
|
|||||||
if err := os.WriteFile(path, tooLarge, 0o644); err != nil {
|
if err := os.WriteFile(path, tooLarge, 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := LoadSession(path); err == nil || !strings.Contains(err.Error(), "limit") {
|
if _, err := LoadSession(path); err == nil || !strings.Contains(configurationErrorText(err), "limit") {
|
||||||
t.Fatalf("oversized local session error = %v", err)
|
t.Fatalf("oversized local session error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func TestSessionDiscoveryDistinguishesAbsenceFromInvalidSelection(t *testing.T)
|
|||||||
if cfg, path, err := DiscoverSession([]string{first, second}, SessionLoadOptions{}); err != nil || cfg == nil || path != second {
|
if cfg, path, err := DiscoverSession([]string{first, second}, SessionLoadOptions{}); err != nil || cfg == nil || path != second {
|
||||||
t.Fatalf("selected = %#v %q %v", cfg, path, err)
|
t.Fatalf("selected = %#v %q %v", cfg, path, err)
|
||||||
}
|
}
|
||||||
if _, _, err := DiscoverSession([]string{first, second}, SessionLoadOptions{SessionID: "different"}); err == nil || !strings.Contains(err.Error(), "mismatch") {
|
if _, _, err := DiscoverSession([]string{first, second}, SessionLoadOptions{SessionID: "different"}); err == nil || !strings.Contains(configurationErrorText(err), "mismatch") {
|
||||||
t.Fatalf("identity error = %v", err)
|
t.Fatalf("identity error = %v", err)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(first, []byte("inputs: [invalid\n"), 0o644); err != nil {
|
if err := os.WriteFile(first, []byte("inputs: [invalid\n"), 0o644); err != nil {
|
||||||
@@ -75,7 +75,7 @@ func TestImportedSessionPlaceholderIsRejected(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
root := writePipelineFixture(t, dir, "session.yml", "config:\n imports:\n - path: fragment.yml\nsession_id: test\n")
|
root := writePipelineFixture(t, dir, "session.yml", "config:\n imports:\n - path: fragment.yml\nsession_id: test\n")
|
||||||
writePipelineFixture(t, dir, "fragment.yml", "title: '{{ title }}'\n")
|
writePipelineFixture(t, dir, "fragment.yml", "title: '{{ title }}'\n")
|
||||||
if _, err := LoadSession(root); err == nil || !strings.Contains(err.Error(), "title") || !strings.Contains(err.Error(), "session init") {
|
if _, err := LoadSession(root); err == nil || !strings.Contains(configurationErrorText(err), "title") || !strings.Contains(configurationErrorText(err), "session init") {
|
||||||
t.Fatalf("placeholder error = %v", err)
|
t.Fatalf("placeholder error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
internal/config/error_test.go
Normal file
21
internal/config/error_test.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
// configurationErrorText renders native evidence for assertions about validation messages.
|
||||||
|
func configurationErrorText(err error) string {
|
||||||
|
if err == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if !errors.As(err, &native) {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
var b bytes.Buffer
|
||||||
|
_ = configkit.WriteDiagnostics(&b, native.Diagnostics())
|
||||||
|
return err.Error() + "\n" + b.String()
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ func finalizeLoadedPipeline(cfg *PipelineConfig) (*PipelineConfig, error) {
|
|||||||
|
|
||||||
// LoadCampaign loads campaign configuration from a YAML file with strict field checking.
|
// LoadCampaign loads campaign configuration from a YAML file with strict field checking.
|
||||||
func LoadCampaign(path string) (*CampaignConfig, error) {
|
func LoadCampaign(path string) (*CampaignConfig, error) {
|
||||||
return loadCampaignWithConfigKit(path)
|
return LoadCampaignWithIdentity(path, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadSession loads session configuration from a YAML file with strict field checking.
|
// LoadSession loads session configuration from a YAML file with strict field checking.
|
||||||
@@ -72,42 +72,6 @@ func LoadSessionBytesWithOptions(label string, data []byte, opts SessionLoadOpti
|
|||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionIdentityError identifies an explicit identity assertion that the
|
|
||||||
// completed session configuration does not satisfy.
|
|
||||||
type SessionIdentityError struct {
|
|
||||||
Source string
|
|
||||||
Field string
|
|
||||||
Expected string
|
|
||||||
Actual string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SessionIdentityError) Error() string {
|
|
||||||
sourceKind := "session"
|
|
||||||
if e.Field == "campaign_id" {
|
|
||||||
sourceKind = "campaign"
|
|
||||||
}
|
|
||||||
if e.Actual == "" {
|
|
||||||
return fmt.Sprintf("load %s config: %s file %q: %s is required when %q is selected", sourceKind, sourceKind, e.Source, e.Field, e.Expected)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("load %s config: %s file %q: %s mismatch: selected %q does not match %q", sourceKind, sourceKind, e.Source, e.Field, e.Expected, e.Actual)
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateSessionIdentity(label string, cfg *SessionConfig, opts SessionLoadOptions) error {
|
|
||||||
for _, assertion := range []struct{ field, expected, actual string }{
|
|
||||||
{"session_id", opts.SessionID, cfg.SessionID},
|
|
||||||
{"previous_session_id", opts.PreviousSessionID, cfg.PreviousSessionID},
|
|
||||||
} {
|
|
||||||
expected := strings.TrimSpace(assertion.expected)
|
|
||||||
if expected != "" && strings.TrimSpace(assertion.actual) != expected {
|
|
||||||
return &SessionIdentityError{Source: label, Field: assertion.field, Expected: expected, Actual: assertion.actual}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if opts.Campaign != nil && cfg.Campaign != CampaignID(opts.Campaign) {
|
|
||||||
return &SessionIdentityError{Source: label, Field: "campaign", Expected: CampaignID(opts.Campaign), Actual: cfg.Campaign}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load loads and resolves combined pipeline, campaign, and session configuration.
|
// Load loads and resolves combined pipeline, campaign, and session configuration.
|
||||||
// Passing only a session path is supported for package-internal compatibility;
|
// Passing only a session path is supported for package-internal compatibility;
|
||||||
// in that form campaign.yml is expected next to the session file.
|
// in that form campaign.yml is expected next to the session file.
|
||||||
@@ -307,7 +271,7 @@ func deriveStableInputs(campaignCfg *CampaignConfig, sessionCfg *SessionConfig,
|
|||||||
return ResolvedStableInputs{}, fmt.Errorf("session config is required")
|
return ResolvedStableInputs{}, fmt.Errorf("session config is required")
|
||||||
}
|
}
|
||||||
if sessionCfg.Campaign != CampaignID(campaignCfg) {
|
if sessionCfg.Campaign != CampaignID(campaignCfg) {
|
||||||
return ResolvedStableInputs{}, &SessionIdentityError{Source: sessionPath, Field: "campaign", Expected: CampaignID(campaignCfg), Actual: sessionCfg.Campaign}
|
return ResolvedStableInputs{}, fmt.Errorf("session campaign %q does not match selected campaign %q", sessionCfg.Campaign, CampaignID(campaignCfg))
|
||||||
}
|
}
|
||||||
stable := ResolvedStableInputs{}
|
stable := ResolvedStableInputs{}
|
||||||
for _, field := range []struct {
|
for _, field := range []struct {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func TestLoadersRejectTrailingYAMLDocuments(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
err := tt.load()
|
err := tt.load()
|
||||||
if err == nil || (!strings.Contains(err.Error(), "exactly one YAML document") && !strings.Contains(err.Error(), "yaml.multiple_documents")) {
|
if err == nil || (!strings.Contains(configurationErrorText(err), "exactly one YAML document") && !strings.Contains(configurationErrorText(err), "yaml.multiple_documents")) {
|
||||||
t.Fatalf("load error = %v, want exactly-one-document error", err)
|
t.Fatalf("load error = %v, want exactly-one-document error", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func TestNormalizeLoadAndValidate(t *testing.T) {
|
|||||||
report: true
|
report: true
|
||||||
bogus: true
|
bogus: true
|
||||||
`,
|
`,
|
||||||
wantLoadErr: "strict decode failed",
|
wantLoadErr: "decode.unknown_field",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,13 +98,13 @@ func TestNormalizeLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantLoadErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantLoadErr) {
|
||||||
t.Fatalf("load error = %q, want to contain %q", err.Error(), tt.wantLoadErr)
|
t.Fatalf("load error = %q, want to contain %q", configurationErrorText(err), tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && tt.wantValidateErr != "" {
|
if err != nil && tt.wantValidateErr != "" {
|
||||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidateErr) {
|
||||||
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
|
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -122,8 +122,8 @@ func TestNormalizeLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidateErr) {
|
||||||
t.Fatalf("validation error = %q, want to contain %q", err.Error(), tt.wantValidateErr)
|
t.Fatalf("validation error = %q, want to contain %q", configurationErrorText(err), tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ func TestNotariusCredentialReferenceFailures(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
_, err := LoadPipeline(path)
|
_, err := LoadPipeline(path)
|
||||||
if err == nil || !strings.Contains(err.Error(), test.want) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.want) {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want classification %q", err, test.want)
|
t.Fatalf("LoadPipeline() error = %v, want classification %q", err, test.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -135,7 +135,7 @@ func TestNotariusRejectsRetiredCredentialField(t *testing.T) {
|
|||||||
if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil {
|
if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := LoadPipeline(path); err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if _, err := LoadPipeline(path); err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want unknown field", err)
|
t.Fatalf("LoadPipeline() error = %v, want unknown field", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ notarius:
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
_, err := LoadPipeline(blankPath)
|
_, err := LoadPipeline(blankPath)
|
||||||
if err == nil || !strings.Contains(err.Error(), "working_directory is required") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "working_directory is required") {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want required working directory", err)
|
t.Fatalf("LoadPipeline() error = %v, want required working directory", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ func TestNotariusCacheControlNormalizationAndValidation(t *testing.T) {
|
|||||||
cfg := validNotariusConfig()
|
cfg := validNotariusConfig()
|
||||||
cfg.ChunkCache = mode
|
cfg.ChunkCache = mode
|
||||||
err := validateNotarius(cfg, nil)
|
err := validateNotarius(cfg, nil)
|
||||||
if err == nil || !strings.Contains(err.Error(), "pipeline.notarius.chunk_cache") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "pipeline.notarius.chunk_cache") {
|
||||||
t.Fatalf("validateNotarius() error = %v, want chunk_cache error", err)
|
t.Fatalf("validateNotarius() error = %v, want chunk_cache error", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -343,11 +343,11 @@ func TestNotariusStrictYAML(t *testing.T) {
|
|||||||
t.Fatalf("write pipeline: %v", err)
|
t.Fatalf("write pipeline: %v", err)
|
||||||
}
|
}
|
||||||
_, err := LoadPipeline(path)
|
_, err := LoadPipeline(path)
|
||||||
want := "strict decode failed"
|
want := "decode.unknown_field"
|
||||||
if tt.name == "duplicate reference selector" {
|
if tt.name == "duplicate reference selector" {
|
||||||
want = "yaml.duplicate_key"
|
want = "yaml.duplicate_key"
|
||||||
}
|
}
|
||||||
if err == nil || !strings.Contains(err.Error(), want) {
|
if err == nil || !strings.Contains(configurationErrorText(err), want) {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want containing %q", err, want)
|
t.Fatalf("LoadPipeline() error = %v, want containing %q", err, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -413,7 +413,7 @@ func TestNotariusReferenceValidationRejectsInvalidBindings(t *testing.T) {
|
|||||||
cfg := validNotariusConfig()
|
cfg := validNotariusConfig()
|
||||||
cfg.References = tt.references
|
cfg.References = tt.references
|
||||||
err := validateNotarius(cfg, nil)
|
err := validateNotarius(cfg, nil)
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantField) || !strings.Contains(err.Error(), tt.wantReason) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantField) || !strings.Contains(configurationErrorText(err), tt.wantReason) {
|
||||||
t.Fatalf("validateNotarius() error = %v, want field %q and reason %q", err, tt.wantField, tt.wantReason)
|
t.Fatalf("validateNotarius() error = %v, want field %q and reason %q", err, tt.wantField, tt.wantReason)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -435,7 +435,7 @@ func TestNotariusReferenceLimit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err == nil || !strings.Contains(err.Error(), "at most 256 bindings") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "at most 256 bindings") {
|
||||||
t.Fatalf("validateNotarius() above limit error = %v", err)
|
t.Fatalf("validateNotarius() above limit error = %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -482,7 +482,7 @@ func TestNotariusValidationFailureDoesNotMutateConfig(t *testing.T) {
|
|||||||
before := cloneNotariusConfigForTest(cfg)
|
before := cloneNotariusConfigForTest(cfg)
|
||||||
|
|
||||||
err := validateNotarius(cfg, nil)
|
err := validateNotarius(cfg, nil)
|
||||||
if err == nil || !strings.Contains(err.Error(), test.want) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.want) {
|
||||||
t.Fatalf("validateNotarius() error = %v, want field containing %q", err, test.want)
|
t.Fatalf("validateNotarius() error = %v, want field containing %q", err, test.want)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(cfg, before) {
|
if !reflect.DeepEqual(cfg, before) {
|
||||||
@@ -585,10 +585,10 @@ func TestNotariusDiagnosticsUseSortedMapKeys(t *testing.T) {
|
|||||||
cfg := validNotariusConfig()
|
cfg := validNotariusConfig()
|
||||||
test.configure(cfg, keys)
|
test.configure(cfg, keys)
|
||||||
err := validateNotarius(cfg, nil)
|
err := validateNotarius(cfg, nil)
|
||||||
if err == nil || !strings.Contains(err.Error(), test.wantField) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.wantField) {
|
||||||
t.Fatalf("validateNotarius() error = %v, want field %q", err, test.wantField)
|
t.Fatalf("validateNotarius() error = %v, want field %q", err, test.wantField)
|
||||||
}
|
}
|
||||||
diagnostics = append(diagnostics, err.Error())
|
diagnostics = append(diagnostics, configurationErrorText(err))
|
||||||
}
|
}
|
||||||
if diagnostics[0] != diagnostics[1] {
|
if diagnostics[0] != diagnostics[1] {
|
||||||
t.Fatalf("equivalent maps produced different diagnostics:\nfirst: %s\nsecond: %s", diagnostics[0], diagnostics[1])
|
t.Fatalf("equivalent maps produced different diagnostics:\nfirst: %s\nsecond: %s", diagnostics[0], diagnostics[1])
|
||||||
@@ -623,7 +623,7 @@ func TestNotariusSpellCatalogReferenceRequiresEffectiveInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := Validate(cfg)
|
err := Validate(cfg)
|
||||||
if err == nil || !strings.Contains(err.Error(), "pipeline.notarius.references.alpha") || !strings.Contains(err.Error(), "requires campaign.inputs.spell_catalog_file or session.inputs.spell_catalog_file") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "pipeline.notarius.references.alpha") || !strings.Contains(configurationErrorText(err), "requires campaign.inputs.spell_catalog_file or session.inputs.spell_catalog_file") {
|
||||||
t.Fatalf("Validate() error = %v, want sorted selector and missing spell catalog input", err)
|
t.Fatalf("Validate() error = %v, want sorted selector and missing spell catalog input", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,7 +715,7 @@ func TestNotariusEnabledValidation(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if len(tt.wantErr) > 0 {
|
if len(tt.wantErr) > 0 {
|
||||||
for _, fragment := range tt.wantErr {
|
for _, fragment := range tt.wantErr {
|
||||||
if !strings.Contains(err.Error(), fragment) {
|
if !strings.Contains(configurationErrorText(err), fragment) {
|
||||||
t.Fatalf("Load() error = %v, want containing %q", err, fragment)
|
t.Fatalf("Load() error = %v, want containing %q", err, fragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -738,7 +738,7 @@ func TestNotariusEnabledValidation(t *testing.T) {
|
|||||||
t.Fatalf("Validate() error = nil, want containing %q", tt.wantErr)
|
t.Fatalf("Validate() error = nil, want containing %q", tt.wantErr)
|
||||||
}
|
}
|
||||||
for _, fragment := range tt.wantErr {
|
for _, fragment := range tt.wantErr {
|
||||||
if !strings.Contains(err.Error(), fragment) {
|
if !strings.Contains(configurationErrorText(err), fragment) {
|
||||||
t.Fatalf("Validate() error = %v, want containing %q", err, fragment)
|
t.Fatalf("Validate() error = %v, want containing %q", err, fragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -814,7 +814,7 @@ func TestExtractionReferencesRequireDeclaredOutput(t *testing.T) {
|
|||||||
t.Fatalf("Validate() error = nil, want containing %q", tt.wantErr)
|
t.Fatalf("Validate() error = nil, want containing %q", tt.wantErr)
|
||||||
}
|
}
|
||||||
for _, fragment := range tt.wantErr {
|
for _, fragment := range tt.wantErr {
|
||||||
if !strings.Contains(err.Error(), fragment) {
|
if !strings.Contains(configurationErrorText(err), fragment) {
|
||||||
t.Fatalf("Validate() error = %v, want containing %q", err, fragment)
|
t.Fatalf("Validate() error = %v, want containing %q", err, fragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ func TestNotificationConfigSupportsOnlyNoopMode(t *testing.T) {
|
|||||||
pipelinePath, sessionPath := writeConfigFiles(t, testPipelineBaseYAML+"\n"+tt.section, testSessionBaseYAML)
|
pipelinePath, sessionPath := writeConfigFiles(t, testPipelineBaseYAML+"\n"+tt.section, testSessionBaseYAML)
|
||||||
cfg, err := Load(pipelinePath, sessionPath)
|
cfg, err := Load(pipelinePath, sessionPath)
|
||||||
if tt.wantLoad != "" {
|
if tt.wantLoad != "" {
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantLoad) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantLoad) {
|
||||||
t.Fatalf("Load() error = %v, want %q", err, tt.wantLoad)
|
t.Fatalf("Load() error = %v, want %q", err, tt.wantLoad)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && tt.wantValidate != "" {
|
if err != nil && tt.wantValidate != "" {
|
||||||
if !strings.Contains(err.Error(), tt.wantValidate) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidate) {
|
||||||
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidate)
|
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidate)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -61,7 +61,7 @@ func TestNotificationConfigSupportsOnlyNoopMode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
if tt.wantValidate != "" {
|
if tt.wantValidate != "" {
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantValidate) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantValidate) {
|
||||||
t.Fatalf("Validate() error = %v, want %q", err, tt.wantValidate)
|
t.Fatalf("Validate() error = %v, want %q", err, tt.wantValidate)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func loadParty(source configkit.Source, imports bool) (*CanonicalParty, error) {
|
|||||||
}
|
}
|
||||||
result, err := configkit.Load(source, configkit.Options[PartyConfig]{Imports: imports, Definition: definition})
|
result, err := configkit.Load(source, configkit.Options[PartyConfig]{Imports: imports, Definition: definition})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, describeConfigKitLoadError("party", err)
|
return nil, fmt.Errorf("load party config: %w", err)
|
||||||
}
|
}
|
||||||
return canonicalPartyFromResult(result), nil
|
return canonicalPartyFromResult(result), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func TestImportedPartyRejectsDuplicateEffectiveNames(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
root := writePipelineFixture(t, dir, "party.yml", "schema_version: narratio.party.v1\nconfig:\n imports:\n - path: roster.yml\ncharacters:\n first:\n player: {name: A}\n character: {name: Shared, classes: [{name: wizard}]}\n")
|
root := writePipelineFixture(t, dir, "party.yml", "schema_version: narratio.party.v1\nconfig:\n imports:\n - path: roster.yml\ncharacters:\n first:\n player: {name: A}\n character: {name: Shared, classes: [{name: wizard}]}\n")
|
||||||
writePipelineFixture(t, dir, "roster.yml", "characters:\n second:\n player: {name: B}\n character: {name: Other, alias: [shared], classes: [{name: fighter}]}\n")
|
writePipelineFixture(t, dir, "roster.yml", "characters:\n second:\n player: {name: B}\n character: {name: Other, alias: [shared], classes: [{name: fighter}]}\n")
|
||||||
if _, err := LoadParty(root); err == nil || !strings.Contains(err.Error(), "ambiguous") {
|
if _, err := LoadParty(root); err == nil || !strings.Contains(configurationErrorText(err), "ambiguous") {
|
||||||
t.Fatalf("duplicate effective name error = %v", err)
|
t.Fatalf("duplicate effective name error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func TestCanonicalPartyRejectsSeparatePlayersAndSessionPartyOverrides(t *testing
|
|||||||
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), canonicalPartyFixture)
|
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), canonicalPartyFixture)
|
||||||
pipelinePath, campaignPath, sessionPath := writePartyResolutionConfig(t, dir, "campaign_id: campaign\ninputs:\n speakers_file: speakers.yml\n autocorrect_file: autocorrect.yml\n glossary_file: glossary.yml\n party_file: party.yml\n"+test.campaignExtra, "session_id: session\ncampaign: campaign\ninputs:\n audio_dir: audio\n"+test.sessionExtra)
|
pipelinePath, campaignPath, sessionPath := writePartyResolutionConfig(t, dir, "campaign_id: campaign\ninputs:\n speakers_file: speakers.yml\n autocorrect_file: autocorrect.yml\n glossary_file: glossary.yml\n party_file: party.yml\n"+test.campaignExtra, "session_id: session\ncampaign: campaign\ninputs:\n audio_dir: audio\n"+test.sessionExtra)
|
||||||
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
|
||||||
if err == nil || !strings.Contains(err.Error(), test.want) {
|
if err == nil || !strings.Contains(configurationErrorText(err), test.want) {
|
||||||
t.Fatalf("LoadWithSessionOptions() error = %v, want %q", err, test.want)
|
t.Fatalf("LoadWithSessionOptions() error = %v, want %q", err, test.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -100,7 +100,7 @@ inputs:
|
|||||||
audio_dir: audio
|
audio_dir: audio
|
||||||
`)
|
`)
|
||||||
|
|
||||||
if _, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{}); err == nil || !strings.Contains(err.Error(), "schema_version is required") {
|
if _, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{}); err == nil || !strings.Contains(configurationErrorText(err), "schema_version is required") {
|
||||||
t.Fatalf("LoadWithSessionOptions() error = %v, want schema rejection before resolution", err)
|
t.Fatalf("LoadWithSessionOptions() error = %v, want schema rejection before resolution", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ characters:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("ParseParty() error = nil, want rejection")
|
t.Fatal("ParseParty() error = nil, want rejection")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), test.want) {
|
if !strings.Contains(configurationErrorText(err), test.want) {
|
||||||
t.Fatalf("ParseParty() error = %q, want %q", err, test.want)
|
t.Fatalf("ParseParty() error = %q, want %q", err, test.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -160,7 +160,7 @@ characters:
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
_, err := ParseParty([]byte(test.yaml))
|
_, err := ParseParty([]byte(test.yaml))
|
||||||
if err == nil || !strings.Contains(err.Error(), "ambiguous") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "ambiguous") {
|
||||||
t.Fatalf("ParseParty() error = %v, want ambiguity rejection", err)
|
t.Fatalf("ParseParty() error = %v, want ambiguity rejection", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -200,7 +200,7 @@ characters:
|
|||||||
alias: [""]
|
alias: [""]
|
||||||
classes: [{name: wizard}]
|
classes: [{name: wizard}]
|
||||||
`))
|
`))
|
||||||
if err == nil || !strings.Contains(err.Error(), "non-empty") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "non-empty") {
|
||||||
t.Fatalf("ParseParty() error = %v, want empty alias rejection", err)
|
t.Fatalf("ParseParty() error = %v, want empty alias rejection", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ func TestParsePartyRejectsMissingOrUnknownSchemaVersion(t *testing.T) {
|
|||||||
{name: "unknown", yaml: "schema_version: narratio.party.v2\ncharacters: {}\n", want: "supported schema_version is \"narratio.party.v1\""},
|
{name: "unknown", yaml: "schema_version: narratio.party.v2\ncharacters: {}\n", want: "supported schema_version is \"narratio.party.v1\""},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
if _, err := ParseParty([]byte(test.yaml)); err == nil || !strings.Contains(err.Error(), test.want) {
|
if _, err := ParseParty([]byte(test.yaml)); err == nil || !strings.Contains(configurationErrorText(err), test.want) {
|
||||||
t.Fatalf("ParseParty() error = %v, want %q", err, test.want)
|
t.Fatalf("ParseParty() error = %v, want %q", err, test.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -48,7 +46,7 @@ func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*Pipeline
|
|||||||
}
|
}
|
||||||
result, err := loadPipelineConfigKitResult(source, overlay, opts.Overrides)
|
result, err := loadPipelineConfigKitResult(source, overlay, opts.Overrides)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, describePipelineLoadError(err)
|
return nil, fmt.Errorf("load pipeline config: %w", err)
|
||||||
}
|
}
|
||||||
cfg := &result.Config
|
cfg := &result.Config
|
||||||
cfg.resolution = pipelineMetadataFromConfigKit(result, opts)
|
cfg.resolution = pipelineMetadataFromConfigKit(result, opts)
|
||||||
@@ -74,43 +72,6 @@ func loadPipelineConfigKitResult(source configkit.Source, overlay string, overri
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func describePipelineLoadError(err error) error {
|
|
||||||
return describeConfigKitLoadError("pipeline", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func describeConfigKitLoadError(kind string, err error) error {
|
|
||||||
var loadError *configkit.LoadError
|
|
||||||
if !errors.As(err, &loadError) {
|
|
||||||
return fmt.Errorf("load %s config: %w", kind, err)
|
|
||||||
}
|
|
||||||
var diagnostics bytes.Buffer
|
|
||||||
resolved := loadError.Diagnostics()
|
|
||||||
sourcePaths := make(map[string]string, len(loadError.Sources()))
|
|
||||||
for _, source := range loadError.Sources() {
|
|
||||||
if source.Path != "" {
|
|
||||||
sourcePaths[source.ID] = source.Path
|
|
||||||
} else if source.Label != "" {
|
|
||||||
sourcePaths[source.ID] = source.Label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for index := range resolved {
|
|
||||||
if resolved[index].Primary != nil {
|
|
||||||
if name := sourcePaths[resolved[index].Primary.SourceID]; name != "" {
|
|
||||||
resolved[index].Primary.SourceID = name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for relatedIndex := range resolved[index].Related {
|
|
||||||
if name := sourcePaths[resolved[index].Related[relatedIndex].SourceID]; name != "" {
|
|
||||||
resolved[index].Related[relatedIndex].SourceID = name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if writeErr := configkit.WriteDiagnostics(&diagnostics, resolved); writeErr != nil {
|
|
||||||
return fmt.Errorf("load %s config: %w", kind, err)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("load %s config: strict decode failed or validation failed: %w: %s", kind, err, strings.TrimSpace(diagnostics.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func selectedPipelineOverlayName(opts PipelineLoadOptions) string {
|
func selectedPipelineOverlayName(opts PipelineLoadOptions) string {
|
||||||
if opts.Overlay == nil || *opts.Overlay == "" || *opts.Overlay == "default" {
|
if opts.Overlay == nil || *opts.Overlay == "" || *opts.Overlay == "default" {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func TestPipelineOverlayDoesNotDiscoverLegacyDirectory(t *testing.T) {
|
|||||||
t.Fatalf("explicit import from profiles directory = %#v, %v", base, err)
|
t.Fatalf("explicit import from profiles directory = %#v, %v", base, err)
|
||||||
}
|
}
|
||||||
selected := "testing"
|
selected := "testing"
|
||||||
if _, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: &selected}); err == nil || !strings.Contains(err.Error(), "overlay.missing") {
|
if _, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: &selected}); err == nil || !strings.Contains(configurationErrorText(err), "overlay.missing") {
|
||||||
t.Fatalf("legacy selected file result = %v, want missing overlay", err)
|
t.Fatalf("legacy selected file result = %v, want missing overlay", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ whisperx:
|
|||||||
`)
|
`)
|
||||||
writePipelineFixture(t, dir, "first.yml", "workspace:\n root: /srv/first\n")
|
writePipelineFixture(t, dir, "first.yml", "workspace:\n root: /srv/first\n")
|
||||||
writePipelineFixture(t, dir, "second.yml", "workspace:\n root: /srv/second\n")
|
writePipelineFixture(t, dir, "second.yml", "workspace:\n root: /srv/second\n")
|
||||||
if _, err := LoadPipeline(filepath.Join(dir, "pipeline.yml")); err == nil || !strings.Contains(strings.ToLower(err.Error()), "conflict") {
|
if _, err := LoadPipeline(filepath.Join(dir, "pipeline.yml")); err == nil || !strings.Contains(strings.ToLower(configurationErrorText(err)), "conflict") {
|
||||||
t.Fatalf("structural conflict error = %v", err)
|
t.Fatalf("structural conflict error = %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -299,7 +299,7 @@ whisperx:
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
_, err := LoadPipeline(filepath.Join(dir, "pipeline.yml"))
|
_, err := LoadPipeline(filepath.Join(dir, "pipeline.yml"))
|
||||||
if err == nil || !strings.Contains(err.Error(), "timeout must be positive") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "timeout must be positive") {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want invalid zero timeout", err)
|
t.Fatalf("LoadPipeline() error = %v, want invalid zero timeout", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +489,7 @@ func TestAuditaRejectsRetiredConfigurationFields(t *testing.T) {
|
|||||||
for _, field := range []string{"llm_api_key", "base_url", "model", "validation_model", "total_llm_concurrency", "proposal_llm_concurrency", "validation_llm_concurrency", "work_dir_retention", "report"} {
|
for _, field := range []string{"llm_api_key", "base_url", "model", "validation_model", "total_llm_concurrency", "proposal_llm_concurrency", "validation_llm_concurrency", "work_dir_retention", "report"} {
|
||||||
t.Run(field, func(t *testing.T) {
|
t.Run(field, func(t *testing.T) {
|
||||||
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n "+field+": retired\n")
|
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n "+field+": retired\n")
|
||||||
if _, err := LoadPipeline(root); err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if _, err := LoadPipeline(root); err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("error = %v, want unknown field", err)
|
t.Fatalf("error = %v, want unknown field", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -650,7 +650,7 @@ func TestPipelineConfigKitRejectsUnknownDirectiveAlias(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
path := writePipelineFixture(t, dir, "pipeline.yml", "composition:\n imports: []\n")
|
path := writePipelineFixture(t, dir, "pipeline.yml", "composition:\n imports: []\n")
|
||||||
_, err := LoadPipeline(path)
|
_, err := LoadPipeline(path)
|
||||||
if err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("composition alias error = %v", err)
|
t.Fatalf("composition alias error = %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
@@ -37,7 +37,9 @@ func TestPipelineDiscoverySelectsFirstSourceAndExplicitFileWins(t *testing.T) {
|
|||||||
if err := os.WriteFile(first, []byte("workspace: [invalid\n"), 0o644); err != nil {
|
if err := os.WriteFile(first, []byte("workspace: [invalid\n"), 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := LoadPipelineWithOptions("", PipelineLoadOptions{Search: &search}); err == nil || !strings.Contains(err.Error(), first) {
|
_, err := LoadPipelineWithOptions("", PipelineLoadOptions{Search: &search})
|
||||||
|
var native *configkit.LoadError
|
||||||
|
if !errors.As(err, &native) || len(native.Sources()) == 0 || native.Sources()[0].Path != first {
|
||||||
t.Fatalf("invalid selected source should fail: %v", err)
|
t.Fatalf("invalid selected source should fail: %v", err)
|
||||||
}
|
}
|
||||||
missing := configkit.SearchPaths(filepath.Join(dir, "missing.yml"))
|
missing := configkit.SearchPaths(filepath.Join(dir, "missing.yml"))
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ func TestRenderLoadAndValidate(t *testing.T) {
|
|||||||
format: markdown
|
format: markdown
|
||||||
unknown: true
|
unknown: true
|
||||||
`,
|
`,
|
||||||
wantLoadErr: "strict decode failed",
|
wantLoadErr: "decode.unknown_field",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +109,13 @@ func TestRenderLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantLoadErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantLoadErr) {
|
||||||
t.Fatalf("load error = %q, want to contain %q", err.Error(), tt.wantLoadErr)
|
t.Fatalf("load error = %q, want to contain %q", configurationErrorText(err), tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && tt.wantValidateErr != "" {
|
if err != nil && tt.wantValidateErr != "" {
|
||||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidateErr) {
|
||||||
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
|
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -133,8 +133,8 @@ func TestRenderLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidateErr) {
|
||||||
t.Fatalf("validation error = %q, want to contain %q", err.Error(), tt.wantValidateErr)
|
t.Fatalf("validation error = %q, want to contain %q", configurationErrorText(err), tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
|||||||
binary: scriptorium
|
binary: scriptorium
|
||||||
bogus: true
|
bogus: true
|
||||||
`,
|
`,
|
||||||
wantLoadErr: "strict decode failed",
|
wantLoadErr: "decode.unknown_field",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing binary defaults when section present",
|
name: "missing binary defaults when section present",
|
||||||
@@ -550,8 +550,8 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantLoadErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantLoadErr) {
|
||||||
t.Fatalf("load error = %q, want to contain %q", err.Error(), tt.wantLoadErr)
|
t.Fatalf("load error = %q, want to contain %q", configurationErrorText(err), tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -566,8 +566,8 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
|||||||
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
for _, fragment := range tt.wantValidateErr {
|
for _, fragment := range tt.wantValidateErr {
|
||||||
if !strings.Contains(err.Error(), fragment) {
|
if !strings.Contains(configurationErrorText(err), fragment) {
|
||||||
t.Fatalf("validation error = %q, want to contain %q", err.Error(), fragment)
|
t.Fatalf("validation error = %q, want to contain %q", configurationErrorText(err), fragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -621,7 +621,7 @@ scriptorium:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
}
|
}
|
||||||
if err == nil || !strings.Contains(err.Error(), "pipeline.scriptorium.artifacts.session_recap.inputs.transcript.source") || !strings.Contains(err.Error(), "unsupported") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "pipeline.scriptorium.artifacts.session_recap.inputs.transcript.source") || !strings.Contains(configurationErrorText(err), "unsupported") {
|
||||||
t.Fatalf("Validate() error = %v, want source field and unsupported category", err)
|
t.Fatalf("Validate() error = %v, want source field and unsupported category", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,12 +152,12 @@ func TestSessionDefaultsRespectExplicitEmptyInputsAndIdentity(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = LoadSessionBytesWithOptions("session.yml", []byte("session_id: other\ninputs: {audio_dir: audio}\n"), opts)
|
_, err = LoadSessionBytesWithOptions("session.yml", []byte("session_id: other\ninputs: {audio_dir: audio}\n"), opts)
|
||||||
var mismatch *SessionIdentityError
|
var mismatch *configkit.LoadError
|
||||||
if !errors.As(err, &mismatch) || mismatch.Field != "session_id" || mismatch.Actual != "other" {
|
if !errors.As(err, &mismatch) || !strings.Contains(configurationErrorText(err), "session_id mismatch") {
|
||||||
t.Fatalf("identity assertion was concealed by defaults: %v", err)
|
t.Fatalf("identity assertion was concealed by defaults: %v", err)
|
||||||
}
|
}
|
||||||
_, err = LoadSessionBytesWithOptions("session.yml", []byte("session_id: session\ncampaign: other\ninputs: {audio_dir: audio}\n"), opts)
|
_, err = LoadSessionBytesWithOptions("session.yml", []byte("session_id: session\ncampaign: other\ninputs: {audio_dir: audio}\n"), opts)
|
||||||
if !errors.As(err, &mismatch) || mismatch.Field != "campaign" {
|
if !errors.As(err, &mismatch) || !strings.Contains(configurationErrorText(err), "campaign mismatch") {
|
||||||
t.Fatalf("campaign assertion was concealed: %v", err)
|
t.Fatalf("campaign assertion was concealed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,11 +74,11 @@ inputs:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "session_id mismatch") {
|
if !strings.Contains(configurationErrorText(err), "session_id mismatch") {
|
||||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
t.Fatalf("error = %q, want mismatch context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
if strings.Contains(err.Error(), "rendered") {
|
if strings.Contains(configurationErrorText(err), "rendered") {
|
||||||
t.Fatalf("error = %q, should not mention rendered session", err.Error())
|
t.Fatalf("error = %q, should not mention rendered session", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +105,11 @@ inputs:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "previous_session_id mismatch") {
|
if !strings.Contains(configurationErrorText(err), "previous_session_id mismatch") {
|
||||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
t.Fatalf("error = %q, want mismatch context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
if strings.Contains(err.Error(), "rendered") {
|
if strings.Contains(configurationErrorText(err), "rendered") {
|
||||||
t.Fatalf("error = %q, should not mention rendered session", err.Error())
|
t.Fatalf("error = %q, should not mention rendered session", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ func TestLoadSessionWithOptionsRequiresExpectedPreviousSession(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{PreviousSessionID: "2026-04-26"})
|
_, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{PreviousSessionID: "2026-04-26"})
|
||||||
if err == nil || !strings.Contains(err.Error(), "previous_session_id is required") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "previous_session_id is required") {
|
||||||
t.Fatalf("LoadSessionWithOptions() error = %v, want missing previous-session expectation error", err)
|
t.Fatalf("LoadSessionWithOptions() error = %v, want missing previous-session expectation error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,8 +147,8 @@ inputs:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error, got nil")
|
t.Fatal("expected error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "strict decode failed") {
|
if !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("error = %q, want strict-decode context", err.Error())
|
t.Fatalf("error = %q, want strict-decode context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,8 +204,8 @@ func TestLoadSessionBytesWithOptionsStrictDecode(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected strict decode error, got nil")
|
t.Fatal("expected strict decode error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "strict decode failed") {
|
if !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("error = %q, want strict decode context", err.Error())
|
t.Fatalf("error = %q, want strict decode context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,8 +214,8 @@ func TestLoadSessionBytesWithOptionsMismatchFails(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected mismatch error, got nil")
|
t.Fatal("expected mismatch error, got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "session_id mismatch") {
|
if !strings.Contains(configurationErrorText(err), "session_id mismatch") {
|
||||||
t.Fatalf("error = %q, want mismatch context", err.Error())
|
t.Fatalf("error = %q, want mismatch context", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,22 +225,22 @@ func TestLoadSessionBytesWithOptionsRequiresExpectedPreviousSession(t *testing.T
|
|||||||
[]byte("session_id: 2026-05-03\n"+standaloneSessionFields),
|
[]byte("session_id: 2026-05-03\n"+standaloneSessionFields),
|
||||||
SessionLoadOptions{PreviousSessionID: "2026-04-26"},
|
SessionLoadOptions{PreviousSessionID: "2026-04-26"},
|
||||||
)
|
)
|
||||||
if err == nil || !strings.Contains(err.Error(), "previous_session_id is required") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "previous_session_id is required") {
|
||||||
t.Fatalf("LoadSessionBytesWithOptions() error = %v, want missing previous-session expectation error", err)
|
t.Fatalf("LoadSessionBytesWithOptions() error = %v, want missing previous-session expectation error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertConcreteSessionTemplateError(t *testing.T, err error, vars ...string) {
|
func assertConcreteSessionTemplateError(t *testing.T, err error, vars ...string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if !strings.Contains(err.Error(), "session.yml must be concrete") {
|
if !strings.Contains(configurationErrorText(err), "session.yml must be concrete") {
|
||||||
t.Fatalf("error = %q, want concrete session guidance", err.Error())
|
t.Fatalf("error = %q, want concrete session guidance", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "run narratio session init") {
|
if !strings.Contains(configurationErrorText(err), "run narratio session init") {
|
||||||
t.Fatalf("error = %q, want session init guidance", err.Error())
|
t.Fatalf("error = %q, want session init guidance", configurationErrorText(err))
|
||||||
}
|
}
|
||||||
for _, name := range vars {
|
for _, name := range vars {
|
||||||
if !strings.Contains(err.Error(), name) {
|
if !strings.Contains(configurationErrorText(err), name) {
|
||||||
t.Fatalf("error = %q, want variable %q", err.Error(), name)
|
t.Fatalf("error = %q, want variable %q", configurationErrorText(err), name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ storage:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("LoadPipeline() error = nil, want strict decode error")
|
t.Fatal("LoadPipeline() error = nil, want strict decode error")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "strict decode failed") {
|
if !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want strict decode failed", err)
|
t.Fatalf("LoadPipeline() error = %v, want strict decode failed", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantField) {
|
if !strings.Contains(configurationErrorText(err), tt.wantField) {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want field %q", err, tt.wantField)
|
t.Fatalf("LoadPipeline() error = %v, want field %q", err, tt.wantField)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -90,7 +90,7 @@ func TestLegacyCredentialReferenceFieldsFailStrictDecode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pipelinePath, _ := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
pipelinePath, _ := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||||
_, err := LoadPipeline(pipelinePath)
|
_, err := LoadPipeline(pipelinePath)
|
||||||
if err == nil || !strings.Contains(err.Error(), field) || !strings.Contains(err.Error(), "strict decode") {
|
if err == nil || !strings.Contains(configurationErrorText(err), field) || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("LoadPipeline() error = %v, want strict rejection of %s", err, field)
|
t.Fatalf("LoadPipeline() error = %v, want strict rejection of %s", err, field)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -177,7 +177,7 @@ storage:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
err = ValidatePipelineConfig(cfg)
|
err = ValidatePipelineConfig(cfg)
|
||||||
}
|
}
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantErr) {
|
||||||
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -270,7 +270,7 @@ inputs:
|
|||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
}
|
}
|
||||||
if tt.wantErr != "" {
|
if tt.wantErr != "" {
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantErr) {
|
||||||
t.Fatalf("Validate() error = %v, want %q", err, tt.wantErr)
|
t.Fatalf("Validate() error = %v, want %q", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -462,7 +462,7 @@ publish:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
}
|
}
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantErr) {
|
||||||
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -482,7 +482,7 @@ publish:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
}
|
}
|
||||||
if err == nil || !strings.Contains(err.Error(), "pipeline.publish.outputs[0].source") || !strings.Contains(err.Error(), "unsupported") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "pipeline.publish.outputs[0].source") || !strings.Contains(configurationErrorText(err), "unsupported") {
|
||||||
t.Fatalf("Validate() error = %v, want source field and unsupported category", err)
|
t.Fatalf("Validate() error = %v, want source field and unsupported category", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -614,7 +614,7 @@ publish:
|
|||||||
`
|
`
|
||||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||||
_, err := Load(pipelinePath, sessionPath)
|
_, err := Load(pipelinePath, sessionPath)
|
||||||
if err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("Load() error = %v, want retired locks field rejected", err)
|
t.Fatalf("Load() error = %v, want retired locks field rejected", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -628,7 +628,7 @@ publish:
|
|||||||
`
|
`
|
||||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||||
_, err := Load(pipelinePath, sessionPath)
|
_, err := Load(pipelinePath, sessionPath)
|
||||||
if err == nil || !strings.Contains(err.Error(), "strict decode failed") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||||
t.Fatalf("Load() error = %v, want strict decode failed", err)
|
t.Fatalf("Load() error = %v, want strict decode failed", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,7 +708,7 @@ storage:
|
|||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
}
|
}
|
||||||
if tt.wantErr != "" {
|
if tt.wantErr != "" {
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantErr) {
|
||||||
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -742,7 +742,7 @@ inputs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = Validate(cfg)
|
err = Validate(cfg)
|
||||||
if err == nil || !strings.Contains(err.Error(), "pipeline.storage.s3.bucket is required") {
|
if err == nil || !strings.Contains(configurationErrorText(err), "pipeline.storage.s3.bucket is required") {
|
||||||
t.Fatalf("Validate() error = %v, want bucket requirement", err)
|
t.Fatalf("Validate() error = %v, want bucket requirement", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func TestTrimLoadAndValidate(t *testing.T) {
|
|||||||
output_path: artifacts/session_bounds.json
|
output_path: artifacts/session_bounds.json
|
||||||
bogus: true
|
bogus: true
|
||||||
`,
|
`,
|
||||||
wantLoadErr: "strict decode failed",
|
wantLoadErr: "decode.unknown_field",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,13 +130,13 @@ func TestTrimLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
t.Fatalf("expected load error containing %q, got nil", tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantLoadErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantLoadErr) {
|
||||||
t.Fatalf("load error = %q, want to contain %q", err.Error(), tt.wantLoadErr)
|
t.Fatalf("load error = %q, want to contain %q", configurationErrorText(err), tt.wantLoadErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && tt.wantValidateErr != "" {
|
if err != nil && tt.wantValidateErr != "" {
|
||||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidateErr) {
|
||||||
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
|
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -154,8 +154,8 @@ func TestTrimLoadAndValidate(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), tt.wantValidateErr) {
|
if !strings.Contains(configurationErrorText(err), tt.wantValidateErr) {
|
||||||
t.Fatalf("validation error = %q, want to contain %q", err.Error(), tt.wantValidateErr)
|
t.Fatalf("validation error = %q, want to contain %q", configurationErrorText(err), tt.wantValidateErr)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user