Use native configuration validation and diagnostics
This commit is contained in:
@@ -42,7 +42,7 @@ func finalizeLoadedPipeline(cfg *PipelineConfig) (*PipelineConfig, error) {
|
||||
|
||||
// LoadCampaign loads campaign configuration from a YAML file with strict field checking.
|
||||
func LoadCampaign(path string) (*CampaignConfig, error) {
|
||||
return loadCampaignWithConfigKit(path)
|
||||
return LoadCampaignWithIdentity(path, "")
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Passing only a session path is supported for package-internal compatibility;
|
||||
// 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")
|
||||
}
|
||||
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{}
|
||||
for _, field := range []struct {
|
||||
|
||||
Reference in New Issue
Block a user