Hand checked processing selections to execution
This commit is contained in:
@@ -1206,6 +1206,20 @@ func TestSubprocessInfeasibleSectionTargetIsAnInputFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSubprocessUnknownProfileFailsBeforeModelDispatchAndOutput(t *testing.T) {
|
||||||
|
f := newProcessFixture(t, "normal", "[grammar]")
|
||||||
|
code, stdout, stderr := f.run(t, true, "--proposal-profile", "unknown")
|
||||||
|
if code != 2 || stdout != "" || f.provider.callCount() != 0 ||
|
||||||
|
!strings.Contains(stderr, "stage 1 (grammar) proposal profile") || !strings.Contains(stderr, "unknown") {
|
||||||
|
t.Fatalf("readiness: code=%d stdout=%q stderr=%q calls=%d", code, stdout, stderr, f.provider.callCount())
|
||||||
|
}
|
||||||
|
for _, path := range []string{f.output, filepath.Join(f.dir, "errors.yml")} {
|
||||||
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("unexpected output at %s: %v", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSubprocessOutputPermissionsHonorUmask(t *testing.T) {
|
func TestSubprocessOutputPermissionsHonorUmask(t *testing.T) {
|
||||||
for _, mask := range []string{"0077", "0022"} {
|
for _, mask := range []string{"0077", "0022"} {
|
||||||
t.Run(mask, func(t *testing.T) {
|
t.Run(mask, func(t *testing.T) {
|
||||||
|
|||||||
@@ -41,5 +41,6 @@ only on explicit request.
|
|||||||
Process stdout contains transcript JSON when no output file is selected. Ordinary
|
Process stdout contains transcript JSON when no output file is selected. Ordinary
|
||||||
reports may record recoverable model failures even when processing completes.
|
reports may record recoverable model failures even when processing completes.
|
||||||
Exit status `0` means success, `1` runtime or output failure, `2` invalid usage
|
Exit status `0` means success, `1` runtime or output failure, `2` invalid usage
|
||||||
or input, and native comparison may return `3` for differences. See the
|
or input, and native comparison may return `3` for differences. A missing
|
||||||
|
processing profile or required glossary selection is an input failure. See the
|
||||||
[output contract](integrations/output-files.md) and [subprocess contract](integrations/subprocess.md).
|
[output contract](integrations/output-files.md) and [subprocess contract](integrations/subprocess.md).
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ stays independent of application runtime assembly. Preserve its behavior from
|
|||||||
the [CLI contract](../cli.md) when changing the command; the
|
the [CLI contract](../cli.md) when changing the command; the
|
||||||
adoption decision is recorded in [ADR 0001](../adr/0001-releasekit.md).
|
adoption decision is recorded in [ADR 0001](../adr/0001-releasekit.md).
|
||||||
|
|
||||||
|
Processing preflight checks glossary selections before inspecting proposal,
|
||||||
|
validation, and enabled repair profiles in pipeline order. The checked plan
|
||||||
|
carries the resolved module specs and glossary views into execution. It reuses
|
||||||
|
profile and backend inspections and equivalent glossary views within the
|
||||||
|
invocation. Native inspection commands continue to inspect configuration
|
||||||
|
without running processing readiness checks.
|
||||||
|
|
||||||
## Validating Examples
|
## Validating Examples
|
||||||
|
|
||||||
Keep complete copyable files in [examples](../../examples/) and link to them from
|
Keep complete copyable files in [examples](../../examples/) and link to them from
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ Modules implement `contracts.TranscriptModule`:
|
|||||||
Built-in modules also expose `RepairPromptID()` for the runner to select their
|
Built-in modules also expose `RepairPromptID()` for the runner to select their
|
||||||
repair definitions; proposal-only callers retain the existing interface.
|
repair definitions; proposal-only callers retain the existing interface.
|
||||||
|
|
||||||
Runner resolves configured module specs to module instances through `internal/framework/modules`.
|
The CLI supplies the built-in factory from `internal/modules` to the runner.
|
||||||
|
The runner resolves checked module specs through that factory. Module instances
|
||||||
|
can receive concurrent proposal calls across sections. Request inputs are
|
||||||
|
borrowed for the call and must be copied before modification or retention.
|
||||||
|
|
||||||
## Built-In Modules
|
## Built-In Modules
|
||||||
|
|
||||||
@@ -105,6 +108,6 @@ the selected default in the [configuration contract](../config.md#pipeline-and-g
|
|||||||
## Key Tests
|
## Key Tests
|
||||||
|
|
||||||
- `internal/modules/*/module_test.go`
|
- `internal/modules/*/module_test.go`
|
||||||
- `internal/framework/modules/registry_test.go`
|
- `internal/modules/registry_test.go`
|
||||||
- `internal/framework/proposal_generation/*_test.go`
|
- `internal/framework/proposal_generation/*_test.go`
|
||||||
- `internal/cli/process_ordered_integration_test.go` (pipeline/report integration)
|
- `internal/cli/process_ordered_integration_test.go` (pipeline/report integration)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ Core deterministic components:
|
|||||||
Framework orchestration and contracts:
|
Framework orchestration and contracts:
|
||||||
- `internal/framework/contracts`
|
- `internal/framework/contracts`
|
||||||
- `internal/framework/preflight`
|
- `internal/framework/preflight`
|
||||||
- `internal/framework/modules`
|
|
||||||
- `internal/framework/proposal_generation`
|
- `internal/framework/proposal_generation`
|
||||||
- `internal/framework/proposals`
|
- `internal/framework/proposals`
|
||||||
- `internal/framework/runner`
|
- `internal/framework/runner`
|
||||||
@@ -39,6 +38,7 @@ Framework orchestration and contracts:
|
|||||||
- `internal/framework/stagename`
|
- `internal/framework/stagename`
|
||||||
|
|
||||||
Domain implementations:
|
Domain implementations:
|
||||||
|
- `internal/modules` (built-in module composition)
|
||||||
- `internal/modules/*`
|
- `internal/modules/*`
|
||||||
- `internal/validators/*`
|
- `internal/validators/*`
|
||||||
- `internal/prompts`
|
- `internal/prompts`
|
||||||
|
|||||||
@@ -414,6 +414,14 @@ attribution, provider-free inspection, constructible catalog entries, and both
|
|||||||
request precedence paths. Update [CLI/config internals](../internal/cli-config.md),
|
request precedence paths. Update [CLI/config internals](../internal/cli-config.md),
|
||||||
[module internals](../internal/modules.md), and configuration docs where affected.
|
[module internals](../internal/modules.md), and configuration docs where affected.
|
||||||
|
|
||||||
|
**Complete.** Configuration uses common validation and role fallback after
|
||||||
|
composition. Preflight passes checked role and glossary selections to execution
|
||||||
|
and reuses inspection and glossary work within the invocation. The built-in
|
||||||
|
factory lives beside the modules. Processing and native inspection preserve
|
||||||
|
their respective variable precedence with one merge per request. The CLI build
|
||||||
|
and full offline suite passed, including status 2 for an unknown processing
|
||||||
|
profile before provider dispatch or output initialization.
|
||||||
|
|
||||||
## Stage 12 — Unify structured-call completion and failure facts
|
## Stage 12 — Unify structured-call completion and failure facts
|
||||||
|
|
||||||
Audit #23, #25, #41, #44.
|
Audit #23, #25, #41, #44.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
||||||
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/preflight"
|
||||||
"go.maximumdirect.net/ckconfig"
|
"go.maximumdirect.net/ckconfig"
|
||||||
commandkit "go.maximumdirect.net/commandkit"
|
commandkit "go.maximumdirect.net/commandkit"
|
||||||
ck "go.maximumdirect.net/configkit"
|
ck "go.maximumdirect.net/configkit"
|
||||||
@@ -36,6 +37,10 @@ func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcom
|
|||||||
}
|
}
|
||||||
prepared, err := prepareProcess(inv.Context, input, loaded, inv.Reporter().Output())
|
prepared, err := prepareProcess(inv.Context, input, loaded, inv.Reporter().Output())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var selection *preflight.SelectionError
|
||||||
|
if inv.Context.Err() == nil && errors.As(err, &selection) {
|
||||||
|
return commandkit.Usage(err.Error()).WithCause(err)
|
||||||
|
}
|
||||||
return commandkit.Failure(err.Error()).WithCause(err)
|
return commandkit.Failure(err.Error()).WithCause(err)
|
||||||
}
|
}
|
||||||
defer prepared.Prepared.Output.Close()
|
defer prepared.Prepared.Output.Close()
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"go.maximumdirect.net/ckconfig"
|
"go.maximumdirect.net/ckconfig"
|
||||||
commandkit "go.maximumdirect.net/commandkit"
|
commandkit "go.maximumdirect.net/commandkit"
|
||||||
ck "go.maximumdirect.net/configkit"
|
ck "go.maximumdirect.net/configkit"
|
||||||
|
pk "go.maximumdirect.net/promptkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
type processInputs struct {
|
type processInputs struct {
|
||||||
@@ -130,13 +131,25 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
|||||||
}
|
}
|
||||||
debug = &preflight.DebugInput{WorkDir: cfg.Diagnostics.WorkDir, RunID: runID, EffectiveConfig: effective.Bytes(), Metadata: diagnostics.InvocationMetadata{Operation: "process", TranscriptPath: input.Transcript, OutputPath: input.Output.Value, Overlay: input.Overlay.Value, ConfigVersion: &cfg.Version, RunID: runID, StartedAt: started}}
|
debug = &preflight.DebugInput{WorkDir: cfg.Diagnostics.WorkDir, RunID: runID, EffectiveConfig: effective.Bytes(), Metadata: diagnostics.InvocationMetadata{Operation: "process", TranscriptPath: input.Transcript, OutputPath: input.Output.Value, Overlay: input.Overlay.Value, ConfigVersion: &cfg.Version, RunID: runID, StartedAt: started}}
|
||||||
}
|
}
|
||||||
|
checkedBackends := make(map[string]struct{})
|
||||||
prepared, err := preflight.Prepare(ctx, preflight.Input{InspectProfile: func(ctx context.Context, id string) error {
|
prepared, err := preflight.Prepare(ctx, preflight.Input{InspectProfile: func(ctx context.Context, id string) error {
|
||||||
profile, err := loaded.Runtime.Engine.InspectProfile(ctx, id)
|
profile, err := loaded.Runtime.Engine.InspectProfile(ctx, id)
|
||||||
if err != nil {
|
if errors.Is(err, pk.ErrProfileNotFound) {
|
||||||
|
return &preflight.SelectionError{Cause: err}
|
||||||
|
}
|
||||||
|
if err != nil || profile.Backend == nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if profile.Backend != nil {
|
backend := *profile.Backend
|
||||||
_, err = loaded.Runtime.Engine.InspectBackend(ctx, *profile.Backend)
|
if _, ok := checkedBackends[backend]; ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err = loaded.Runtime.Engine.InspectBackend(ctx, backend)
|
||||||
|
if errors.Is(err, pk.ErrBackendNotFound) {
|
||||||
|
return &preflight.SelectionError{Cause: err}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
checkedBackends[backend] = struct{}{}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}, Config: cfg, Transcript: loaded.Source, Output: diagnostics.OutputSelection{InputTranscriptPath: input.Transcript, TranscriptPath: input.Output.Value, ReportDir: reportDir, ReportingEnabled: cfg.Reporting.Enabled, ProtectedPaths: loaded.ProtectedPaths, Stdout: stdout}, InitialReports: initial, FailedReports: failed, Debug: debug})
|
}, Config: cfg, Transcript: loaded.Source, Output: diagnostics.OutputSelection{InputTranscriptPath: input.Transcript, TranscriptPath: input.Output.Value, ReportDir: reportDir, ReportingEnabled: cfg.Reporting.Enabled, ProtectedPaths: loaded.ProtectedPaths, Stdout: stdout}, InitialReports: initial, FailedReports: failed, Debug: debug})
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/contracts"
|
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/modules"
|
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/processreport"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/processreport"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
||||||
|
"gitea.maximumdirect.net/eric/audita/v3/internal/modules"
|
||||||
)
|
)
|
||||||
|
|
||||||
func executePipeline(ctx context.Context, loaded *processInputs, prepared *preparedProcess, normalized *schema.Transcript, warn func(error)) (processResult, error) {
|
func executePipeline(ctx context.Context, loaded *processInputs, prepared *preparedProcess, normalized *schema.Transcript, warn func(error)) (processResult, error) {
|
||||||
cfg := &loaded.Configuration.Config
|
cfg := &loaded.Configuration.Config
|
||||||
specs := contracts.ResolveModuleRunSpecs(cfg)
|
specs := prepared.Prepared.Specs
|
||||||
debug := prepared.Prepared.Debug
|
debug := prepared.Prepared.Debug
|
||||||
var observer *llm.ObservationCollector
|
var observer *llm.ObservationCollector
|
||||||
var hooks llm.CallHooks
|
var hooks llm.CallHooks
|
||||||
|
|||||||
@@ -158,12 +158,7 @@ func validate(c *Config, v *ck.Validation) {
|
|||||||
check(entry.Plural == nil || *entry.Plural != "", path.Key("plural"), "plural must not be empty")
|
check(entry.Plural == nil || *entry.Plural != "", path.Key("plural"), "plural must not be empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check(c.LLM.TransientRetries >= 0, ck.Keys("llm", "transient_retries"), "retry budget must be non-negative")
|
validateRuntimeSettings(check, ck.Keys(), c.LLM, c.Validation, c.Context)
|
||||||
check(c.LLM.RepairAttempts >= 0 && c.LLM.RepairAttempts <= 3, ck.Keys("llm", "repair_attempts"), "repair attempts must be between zero and three")
|
|
||||||
check(c.LLM.CorrectionRepairAttempts >= 0, ck.Keys("llm", "correction_repair_attempts"), "correction repair attempts must be non-negative")
|
|
||||||
check(c.LLM.CorrectionRepairProfile == nil || *c.LLM.CorrectionRepairProfile != "", ck.Keys("llm", "correction_repair_profile"), "correction repair profile must not be empty; use null to clear it")
|
|
||||||
check(c.LLM.OperationTimeout > 0, ck.Keys("llm", "operation_timeout"), "operation timeout must be positive")
|
|
||||||
check(c.LLM.ValidationProfile == nil || *c.LLM.ValidationProfile != "", ck.Keys("llm", "validation_profile"), "validation profile must not be empty; use null to clear it")
|
|
||||||
validateSelections := func(values []string, path ck.Path) {
|
validateSelections := func(values []string, path ck.Path) {
|
||||||
for i, name := range values {
|
for i, name := range values {
|
||||||
_, exists := c.GlossaryCollections[name]
|
_, exists := c.GlossaryCollections[name]
|
||||||
@@ -183,17 +178,9 @@ func validate(c *Config, v *ck.Validation) {
|
|||||||
}
|
}
|
||||||
validateSelections(item.Glossaries, path.Key("glossaries"))
|
validateSelections(item.Glossaries, path.Key("glossaries"))
|
||||||
validateSelections(item.ProtectedTerms, path.Key("protected_terms"))
|
validateSelections(item.ProtectedTerms, path.Key("protected_terms"))
|
||||||
check(item.LLM.ValidationProfile == nil || *item.LLM.ValidationProfile != "", path.Key("llm").Key("validation_profile"), "validation profile must not be empty; use null to clear it")
|
validateRuntimeSettings(check, path, item.LLM, item.Validation, item.Context)
|
||||||
check(item.LLM.CorrectionRepairAttempts >= 0, path.Key("llm").Key("correction_repair_attempts"), "correction repair attempts must be non-negative")
|
|
||||||
check(item.LLM.CorrectionRepairProfile == nil || *item.LLM.CorrectionRepairProfile != "", path.Key("llm").Key("correction_repair_profile"), "correction repair profile must not be empty; use null to clear it")
|
|
||||||
check(item.LLM.TransientRetries >= 0, path.Key("llm").Key("transient_retries"), "retry budget must be non-negative")
|
|
||||||
check(item.LLM.RepairAttempts >= 0 && item.LLM.RepairAttempts <= 3, path.Key("llm").Key("repair_attempts"), "repair attempts must be between zero and three")
|
|
||||||
check(item.LLM.OperationTimeout > 0, path.Key("llm").Key("operation_timeout"), "operation timeout must be positive")
|
|
||||||
check(item.Validation.MaxPromptTokens > 0, path.Key("validation").Key("max_prompt_tokens"), "validation prompt budget must be positive")
|
|
||||||
check(len(strings.TrimSpace(item.Context.Description)) <= DefaultTranscriptDescriptionMaxChars, path.Key("context").Key("description"), fmt.Sprintf("description must be at most %d bytes after trimming", DefaultTranscriptDescriptionMaxChars))
|
|
||||||
}
|
}
|
||||||
check(outputschema.IsSupported(c.Output.Schema), ck.Keys("output", "schema"), "unsupported output schema")
|
check(outputschema.IsSupported(c.Output.Schema), ck.Keys("output", "schema"), "unsupported output schema")
|
||||||
check(c.Validation.MaxPromptTokens > 0, ck.Keys("validation", "max_prompt_tokens"), "validation prompt budget must be positive")
|
|
||||||
check(c.Chunking.MaxSectionTokens > 0, ck.Keys("chunking", "max_section_tokens"), "maximum section tokens must be positive")
|
check(c.Chunking.MaxSectionTokens > 0, ck.Keys("chunking", "max_section_tokens"), "maximum section tokens must be positive")
|
||||||
check(c.Chunking.MinSectionTokens > 0 && c.Chunking.MinSectionTokens <= c.Chunking.MaxSectionTokens, ck.Keys("chunking", "min_section_tokens"), "minimum section tokens must be positive and no greater than maximum")
|
check(c.Chunking.MinSectionTokens > 0 && c.Chunking.MinSectionTokens <= c.Chunking.MaxSectionTokens, ck.Keys("chunking", "min_section_tokens"), "minimum section tokens must be positive and no greater than maximum")
|
||||||
check(c.Chunking.TargetSections == nil || *c.Chunking.TargetSections > 0, ck.Keys("chunking", "target_sections"), "target sections must be positive when set")
|
check(c.Chunking.TargetSections == nil || *c.Chunking.TargetSections > 0, ck.Keys("chunking", "target_sections"), "target sections must be positive when set")
|
||||||
@@ -201,5 +188,16 @@ func validate(c *Config, v *ck.Validation) {
|
|||||||
check(c.Normalization.EllipsisGap >= 0, ck.Keys("normalization", "ellipsis_gap"), "ellipsis gap must be non-negative")
|
check(c.Normalization.EllipsisGap >= 0, ck.Keys("normalization", "ellipsis_gap"), "ellipsis gap must be non-negative")
|
||||||
check(c.Normalization.MaxSegmentDuration > 0, ck.Keys("normalization", "max_segment_duration"), "maximum segment duration must be positive")
|
check(c.Normalization.MaxSegmentDuration > 0, ck.Keys("normalization", "max_segment_duration"), "maximum segment duration must be positive")
|
||||||
check(c.Normalization.MaxSegmentTokens > 0, ck.Keys("normalization", "max_segment_tokens"), "maximum segment tokens must be positive")
|
check(c.Normalization.MaxSegmentTokens > 0, ck.Keys("normalization", "max_segment_tokens"), "maximum segment tokens must be positive")
|
||||||
check(len(strings.TrimSpace(c.Context.Description)) <= DefaultTranscriptDescriptionMaxChars, ck.Keys("context", "description"), fmt.Sprintf("description must be at most %d bytes after trimming", DefaultTranscriptDescriptionMaxChars))
|
}
|
||||||
|
|
||||||
|
func validateRuntimeSettings(check func(bool, ck.Path, string), base ck.Path, settings LLM, validation Validation, context Context) {
|
||||||
|
llm := base.Key("llm")
|
||||||
|
check(settings.TransientRetries >= 0, llm.Key("transient_retries"), "retry budget must be non-negative")
|
||||||
|
check(settings.RepairAttempts >= 0 && settings.RepairAttempts <= 3, llm.Key("repair_attempts"), "repair attempts must be between zero and three")
|
||||||
|
check(settings.CorrectionRepairAttempts >= 0, llm.Key("correction_repair_attempts"), "correction repair attempts must be non-negative")
|
||||||
|
check(settings.CorrectionRepairProfile == nil || *settings.CorrectionRepairProfile != "", llm.Key("correction_repair_profile"), "correction repair profile must not be empty; use null to clear it")
|
||||||
|
check(settings.OperationTimeout > 0, llm.Key("operation_timeout"), "operation timeout must be positive")
|
||||||
|
check(settings.ValidationProfile == nil || *settings.ValidationProfile != "", llm.Key("validation_profile"), "validation profile must not be empty; use null to clear it")
|
||||||
|
check(validation.MaxPromptTokens > 0, base.Key("validation").Key("max_prompt_tokens"), "validation prompt budget must be positive")
|
||||||
|
check(len(strings.TrimSpace(context.Description)) <= DefaultTranscriptDescriptionMaxChars, base.Key("context").Key("description"), fmt.Sprintf("description must be at most %d bytes after trimming", DefaultTranscriptDescriptionMaxChars))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,24 +20,46 @@ func defaultNames(r *ck.Resolution, path ck.Path, target *[]string, inherited []
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveRoleProfile inherits only an explicitly selected root role. An
|
||||||
|
// explicit null clears inheritance and derives the role from its own proposal.
|
||||||
|
func resolveRoleProfile(r *ck.Resolution, role, proposal ck.Path, target **string, proposalValue *string, name string, inheritedPath ck.Path, inherited *string) {
|
||||||
|
info, _ := r.EntryInfo(role)
|
||||||
|
reason := name + " defaults to proposal profile"
|
||||||
|
if r.IsExplicit(role) && info.Null {
|
||||||
|
*target = cloneSelection(proposalValue)
|
||||||
|
r.RecordDerivedDefault(role, reason, proposal)
|
||||||
|
} else if inherited != nil {
|
||||||
|
ck.Default(r, role, target, cloneSelection(inherited), "inherit "+name+" profile", inheritedPath)
|
||||||
|
} else {
|
||||||
|
ck.Default(r, role, target, cloneSelection(proposalValue), reason, proposal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func explicitProfile(r *ck.Resolution, path ck.Path, value *string) *string {
|
||||||
|
info, _ := r.EntryInfo(path)
|
||||||
|
if r.IsExplicit(path) && !info.Null {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// resolveSettings records root-derived defaults after all explicit assignments.
|
// resolveSettings records root-derived defaults after all explicit assignments.
|
||||||
func resolveSettings(c *Config, r *ck.Resolution) error {
|
func resolveSettings(c *Config, r *ck.Resolution) error {
|
||||||
glossaries := ck.Keys("glossaries")
|
glossaries := ck.Keys("glossaries")
|
||||||
protection := ck.Keys("protected_terms")
|
protection := ck.Keys("protected_terms")
|
||||||
defaultNames(r, protection, &c.ProtectedTerms, c.Glossaries, "protection defaults to selected glossaries", glossaries)
|
defaultNames(r, protection, &c.ProtectedTerms, c.Glossaries, "protection defaults to selected glossaries", glossaries)
|
||||||
rootValidation := ck.Keys("llm", "validation_profile")
|
rootLLM := ck.Keys("llm")
|
||||||
rootValidationInfo, _ := r.EntryInfo(rootValidation)
|
rootProposal := rootLLM.Key("proposal_profile")
|
||||||
inheritedValidation := r.IsExplicit(rootValidation) && !rootValidationInfo.Null && c.LLM.ValidationProfile != nil
|
rootValidation := rootLLM.Key("validation_profile")
|
||||||
rootRepair := ck.Keys("llm", "correction_repair_profile")
|
rootRepair := rootLLM.Key("correction_repair_profile")
|
||||||
rootRepairInfo, _ := r.EntryInfo(rootRepair)
|
inheritedValidation := explicitProfile(r, rootValidation, c.LLM.ValidationProfile)
|
||||||
inheritedRepair := r.IsExplicit(rootRepair) && !rootRepairInfo.Null && c.LLM.CorrectionRepairProfile != nil
|
inheritedRepair := explicitProfile(r, rootRepair, c.LLM.CorrectionRepairProfile)
|
||||||
for i := range c.Pipeline.Stages {
|
for i := range c.Pipeline.Stages {
|
||||||
item := &c.Pipeline.Stages[i]
|
item := &c.Pipeline.Stages[i]
|
||||||
base := ck.Keys("pipeline", "stages").Index(i)
|
base := ck.Keys("pipeline", "stages").Index(i)
|
||||||
defaultNames(r, base.Key("glossaries"), &item.Glossaries, c.Glossaries, "inherit root glossaries", glossaries)
|
defaultNames(r, base.Key("glossaries"), &item.Glossaries, c.Glossaries, "inherit root glossaries", glossaries)
|
||||||
defaultNames(r, base.Key("protected_terms"), &item.ProtectedTerms, c.ProtectedTerms, "inherit root protection", protection)
|
defaultNames(r, base.Key("protected_terms"), &item.ProtectedTerms, c.ProtectedTerms, "inherit root protection", protection)
|
||||||
llm := base.Key("llm")
|
llm := base.Key("llm")
|
||||||
rootLLM := ck.Keys("llm")
|
|
||||||
proposal := llm.Key("proposal_profile")
|
proposal := llm.Key("proposal_profile")
|
||||||
ck.Default(r, proposal, &item.LLM.ProposalProfile, cloneSelection(c.LLM.ProposalProfile), "inherit proposal profile", rootLLM.Key("proposal_profile"))
|
ck.Default(r, proposal, &item.LLM.ProposalProfile, cloneSelection(c.LLM.ProposalProfile), "inherit proposal profile", rootLLM.Key("proposal_profile"))
|
||||||
ck.Default(r, llm.Key("transient_retries"), &item.LLM.TransientRetries, c.LLM.TransientRetries, "inherit retry budget", rootLLM.Key("transient_retries"))
|
ck.Default(r, llm.Key("transient_retries"), &item.LLM.TransientRetries, c.LLM.TransientRetries, "inherit retry budget", rootLLM.Key("transient_retries"))
|
||||||
@@ -46,38 +68,10 @@ func resolveSettings(c *Config, r *ck.Resolution) error {
|
|||||||
ck.Default(r, llm.Key("operation_timeout"), &item.LLM.OperationTimeout, c.LLM.OperationTimeout, "inherit operation timeout", rootLLM.Key("operation_timeout"))
|
ck.Default(r, llm.Key("operation_timeout"), &item.LLM.OperationTimeout, c.LLM.OperationTimeout, "inherit operation timeout", rootLLM.Key("operation_timeout"))
|
||||||
ck.Default(r, base.Key("validation").Key("max_prompt_tokens"), &item.Validation.MaxPromptTokens, c.Validation.MaxPromptTokens, "inherit validation budget", ck.Keys("validation", "max_prompt_tokens"))
|
ck.Default(r, base.Key("validation").Key("max_prompt_tokens"), &item.Validation.MaxPromptTokens, c.Validation.MaxPromptTokens, "inherit validation budget", ck.Keys("validation", "max_prompt_tokens"))
|
||||||
ck.Default(r, base.Key("context").Key("description"), &item.Context.Description, c.Context.Description, "inherit description", ck.Keys("context", "description"))
|
ck.Default(r, base.Key("context").Key("description"), &item.Context.Description, c.Context.Description, "inherit description", ck.Keys("context", "description"))
|
||||||
repair := llm.Key("correction_repair_profile")
|
resolveRoleProfile(r, llm.Key("correction_repair_profile"), proposal, &item.LLM.CorrectionRepairProfile, item.LLM.ProposalProfile, "correction repair", rootRepair, inheritedRepair)
|
||||||
repairInfo, _ := r.EntryInfo(repair)
|
resolveRoleProfile(r, llm.Key("validation_profile"), proposal, &item.LLM.ValidationProfile, item.LLM.ProposalProfile, "validation", rootValidation, inheritedValidation)
|
||||||
if r.IsExplicit(repair) && repairInfo.Null {
|
|
||||||
item.LLM.CorrectionRepairProfile = cloneSelection(item.LLM.ProposalProfile)
|
|
||||||
r.RecordDerivedDefault(repair, "correction repair defaults to proposal profile", proposal)
|
|
||||||
} else if inheritedRepair {
|
|
||||||
ck.Default(r, repair, &item.LLM.CorrectionRepairProfile, cloneSelection(c.LLM.CorrectionRepairProfile), "inherit correction repair profile", rootRepair)
|
|
||||||
} else {
|
|
||||||
ck.Default(r, repair, &item.LLM.CorrectionRepairProfile, cloneSelection(item.LLM.ProposalProfile), "correction repair defaults to proposal profile", proposal)
|
|
||||||
}
|
|
||||||
validation := llm.Key("validation_profile")
|
|
||||||
info, _ := r.EntryInfo(validation)
|
|
||||||
if r.IsExplicit(validation) && info.Null {
|
|
||||||
item.LLM.ValidationProfile = cloneSelection(item.LLM.ProposalProfile)
|
|
||||||
r.RecordDerivedDefault(validation, "validation defaults to proposal profile", proposal)
|
|
||||||
} else if inheritedValidation {
|
|
||||||
ck.Default(r, validation, &item.LLM.ValidationProfile, cloneSelection(c.LLM.ValidationProfile), "inherit validation profile", rootValidation)
|
|
||||||
} else {
|
|
||||||
ck.Default(r, validation, &item.LLM.ValidationProfile, cloneSelection(item.LLM.ProposalProfile), "validation defaults to proposal profile", proposal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.IsExplicit(rootRepair) && rootRepairInfo.Null {
|
|
||||||
c.LLM.CorrectionRepairProfile = cloneSelection(c.LLM.ProposalProfile)
|
|
||||||
r.RecordDerivedDefault(rootRepair, "correction repair defaults to proposal profile", ck.Keys("llm", "proposal_profile"))
|
|
||||||
} else {
|
|
||||||
ck.Default(r, rootRepair, &c.LLM.CorrectionRepairProfile, cloneSelection(c.LLM.ProposalProfile), "correction repair defaults to proposal profile", ck.Keys("llm", "proposal_profile"))
|
|
||||||
}
|
|
||||||
if r.IsExplicit(rootValidation) && rootValidationInfo.Null {
|
|
||||||
c.LLM.ValidationProfile = cloneSelection(c.LLM.ProposalProfile)
|
|
||||||
r.RecordDerivedDefault(rootValidation, "validation defaults to proposal profile", ck.Keys("llm", "proposal_profile"))
|
|
||||||
} else {
|
|
||||||
ck.Default(r, rootValidation, &c.LLM.ValidationProfile, cloneSelection(c.LLM.ProposalProfile), "validation defaults to proposal profile", ck.Keys("llm", "proposal_profile"))
|
|
||||||
}
|
}
|
||||||
|
resolveRoleProfile(r, rootRepair, rootProposal, &c.LLM.CorrectionRepairProfile, c.LLM.ProposalProfile, "correction repair", rootRepair, nil)
|
||||||
|
resolveRoleProfile(r, rootValidation, rootProposal, &c.LLM.ValidationProfile, c.LLM.ProposalProfile, "validation", rootValidation, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import (
|
|||||||
type StructuredLLMClient = structuredoutput.Client
|
type StructuredLLMClient = structuredoutput.Client
|
||||||
|
|
||||||
// TranscriptModule is the minimal contract for framework-integrated modules.
|
// TranscriptModule is the minimal contract for framework-integrated modules.
|
||||||
|
// Propose may run concurrently on an instance across sections. Request data
|
||||||
|
// is borrowed for the call. Copy it before retaining it or modifying it.
|
||||||
type TranscriptModule interface {
|
type TranscriptModule interface {
|
||||||
Key() string
|
Key() string
|
||||||
ReplacementPolicy() proposals.ReplacementPolicy
|
ReplacementPolicy() proposals.ReplacementPolicy
|
||||||
@@ -31,18 +33,35 @@ type StructuredCompletionResponse = structuredoutput.Response
|
|||||||
|
|
||||||
// ModuleRunSpec identifies one resolved module instance in a pipeline.
|
// ModuleRunSpec identifies one resolved module instance in a pipeline.
|
||||||
type ModuleRunSpec struct {
|
type ModuleRunSpec struct {
|
||||||
ModuleKey string `json:"module_key"`
|
ModuleKey string `json:"module_key"`
|
||||||
InstanceName string `json:"instance_name"`
|
InstanceName string `json:"instance_name"`
|
||||||
ReplacementPolicy proposals.ReplacementPolicy `json:"replacement_policy"`
|
ReplacementPolicy proposals.ReplacementPolicy `json:"replacement_policy"`
|
||||||
Index int `json:"-"`
|
Index int `json:"-"`
|
||||||
ID *string `json:"-"`
|
ID *string `json:"-"`
|
||||||
Settings config.Stage `json:"-"`
|
Settings config.Stage `json:"-"`
|
||||||
Glossary []glossary.Entry `json:"-"`
|
Glossary []glossary.Entry `json:"-"`
|
||||||
ProtectedTerms []glossary.Term `json:"-"`
|
ProtectedTerms []glossary.Term `json:"-"`
|
||||||
CaptureProposalExchange bool `json:"-"`
|
GlossaryView *validators.GlossaryView `json:"-"`
|
||||||
ProposalClient StructuredLLMClient `json:"-"`
|
GlossaryVariables *promptcontext.GlossaryVariables `json:"-"`
|
||||||
ValidationClient StructuredLLMClient `json:"-"`
|
CaptureProposalExchange bool `json:"-"`
|
||||||
RepairClient StructuredLLMClient `json:"-"`
|
ProposalClient StructuredLLMClient `json:"-"`
|
||||||
|
ValidationClient StructuredLLMClient `json:"-"`
|
||||||
|
RepairClient StructuredLLMClient `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrepareGlossary constructs the read-only views used by proposal and validation.
|
||||||
|
func (s *ModuleRunSpec) PrepareGlossary() error {
|
||||||
|
if s.GlossaryVariables == nil {
|
||||||
|
variables, err := promptcontext.PrepareGlossaryVariables(s.Glossary, s.ProtectedTerms)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.GlossaryVariables = &variables
|
||||||
|
}
|
||||||
|
if s.GlossaryView == nil {
|
||||||
|
s.GlossaryView = validators.PrepareGlossaryView(s.Glossary, s.ProtectedTerms)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SectionMetadata captures chunk-level metadata without embedding full segment payloads.
|
// SectionMetadata captures chunk-level metadata without embedding full segment payloads.
|
||||||
|
|||||||
@@ -118,10 +118,7 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
|||||||
if contractErr != nil {
|
if contractErr != nil {
|
||||||
return fail(&structuredoutput.Failure{Class: structuredoutput.FailureFatal, Reason: outcomes.ReasonSetupFailure, Message: "unknown structured response schema", Cause: contractErr})
|
return fail(&structuredoutput.Failure{Class: structuredoutput.FailureFatal, Reason: outcomes.ReasonSetupFailure, Message: "unknown structured response schema", Cause: contractErr})
|
||||||
}
|
}
|
||||||
vars := prompts.WithSharedVariables(req.Variables)
|
vars := prompts.ProcessingVariables(req.Variables)
|
||||||
for name, value := range prompts.SharedVariables() {
|
|
||||||
vars[name] = value
|
|
||||||
}
|
|
||||||
var exchange *pk.Exchange
|
var exchange *pk.Exchange
|
||||||
if req.ContinueFrom != nil {
|
if req.ContinueFrom != nil {
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/modulecatalog"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/modulecatalog"
|
||||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||||
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/contracts"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Input contains already acquired application and transcript inputs.
|
// Input contains already acquired application and transcript inputs.
|
||||||
@@ -32,6 +33,7 @@ type DebugInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Prepared struct {
|
type Prepared struct {
|
||||||
|
Specs []contracts.ModuleRunSpec
|
||||||
Output *diagnostics.OutputSession
|
Output *diagnostics.OutputSession
|
||||||
Debug *diagnostics.RunDirectory
|
Debug *diagnostics.RunDirectory
|
||||||
Warnings []error
|
Warnings []error
|
||||||
@@ -48,7 +50,8 @@ func Prepare(ctx context.Context, input Input) (*Prepared, error) {
|
|||||||
if input.Transcript == nil {
|
if input.Transcript == nil {
|
||||||
return nil, fmt.Errorf("transcript is required")
|
return nil, fmt.Errorf("transcript is required")
|
||||||
}
|
}
|
||||||
if err := CheckReadiness(ctx, input.Config, input.InspectProfile); err != nil {
|
specs, err := ProcessingPlan(ctx, input.Config, input.InspectProfile)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
session, err := diagnostics.SelectOutput(input.Output)
|
session, err := diagnostics.SelectOutput(input.Output)
|
||||||
@@ -73,7 +76,7 @@ func Prepare(ctx context.Context, input Input) (*Prepared, error) {
|
|||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, cancelOutput(err)
|
return nil, cancelOutput(err)
|
||||||
}
|
}
|
||||||
result := &Prepared{Output: session}
|
result := &Prepared{Specs: specs, Output: session}
|
||||||
if input.Debug != nil {
|
if input.Debug != nil {
|
||||||
result.Debug, result.Warnings = diagnostics.PrepareDebug(input.Debug.WorkDir, input.Debug.RunID, input.Debug.Metadata, input.Debug.EffectiveConfig)
|
result.Debug, result.Warnings = diagnostics.PrepareDebug(input.Debug.WorkDir, input.Debug.RunID, input.Debug.Metadata, input.Debug.EffectiveConfig)
|
||||||
}
|
}
|
||||||
@@ -83,10 +86,19 @@ func Prepare(ctx context.Context, input Input) (*Prepared, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckReadiness checks all resolved processing selections before output preparation.
|
// SelectionError indicates that resolved operator settings cannot be used for processing.
|
||||||
func CheckReadiness(ctx context.Context, cfg *config.Config, inspectProfile func(context.Context, string) error) error {
|
type SelectionError struct{ Cause error }
|
||||||
|
|
||||||
|
func (e *SelectionError) Error() string { return e.Cause.Error() }
|
||||||
|
func (e *SelectionError) Unwrap() error { return e.Cause }
|
||||||
|
|
||||||
|
// ProcessingPlan checks all resolved selections before acquiring outputs.
|
||||||
|
func ProcessingPlan(ctx context.Context, cfg *config.Config, inspectProfile func(context.Context, string) error) ([]contracts.ModuleRunSpec, error) {
|
||||||
|
if err := ctx.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
return fmt.Errorf("application configuration is required")
|
return nil, fmt.Errorf("application configuration is required")
|
||||||
}
|
}
|
||||||
label := func(index int, item config.Stage) string {
|
label := func(index int, item config.Stage) string {
|
||||||
if item.ID != nil {
|
if item.ID != nil {
|
||||||
@@ -102,9 +114,10 @@ func CheckReadiness(ctx context.Context, cfg *config.Config, inspectProfile func
|
|||||||
return len(cfg.GlossaryCollections[name].Entries) > 0
|
return len(cfg.GlossaryCollections[name].Entries) > 0
|
||||||
})
|
})
|
||||||
if !hasEntries {
|
if !hasEntries {
|
||||||
return fmt.Errorf("%s has no glossary entries in selected collections %q", label(index, item), item.Glossaries)
|
return nil, &SelectionError{Cause: fmt.Errorf("%s has no glossary entries in selected collections %q", label(index, item), item.Glossaries)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
checkedProfiles := make(map[string]struct{})
|
||||||
for index, item := range cfg.Pipeline.Stages {
|
for index, item := range cfg.Pipeline.Stages {
|
||||||
selections := []struct {
|
selections := []struct {
|
||||||
role string
|
role string
|
||||||
@@ -118,15 +131,49 @@ func CheckReadiness(ctx context.Context, cfg *config.Config, inspectProfile func
|
|||||||
}
|
}
|
||||||
for _, selection := range selections {
|
for _, selection := range selections {
|
||||||
if selection.profile == nil || *selection.profile == "" {
|
if selection.profile == nil || *selection.profile == "" {
|
||||||
return fmt.Errorf("%s requires a %s profile", label(index, item), selection.role)
|
return nil, &SelectionError{Cause: fmt.Errorf("%s requires a %s profile", label(index, item), selection.role)}
|
||||||
}
|
}
|
||||||
if inspectProfile == nil {
|
if inspectProfile == nil {
|
||||||
return fmt.Errorf("profile inspection is required")
|
return nil, fmt.Errorf("profile inspection is required")
|
||||||
}
|
}
|
||||||
if err := inspectProfile(ctx, *selection.profile); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return fmt.Errorf("%s %s profile %q: %w", label(index, item), selection.role, *selection.profile, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
id := *selection.profile
|
||||||
|
if _, ok := checkedProfiles[id]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := inspectProfile(ctx, id); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s %s profile %q: %w", label(index, item), selection.role, id, err)
|
||||||
|
}
|
||||||
|
checkedProfiles[id] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ctx.Err()
|
specs := contracts.ResolveModuleRunSpecs(cfg)
|
||||||
|
type glossarySelection struct {
|
||||||
|
context, protected string
|
||||||
|
exempt bool
|
||||||
|
}
|
||||||
|
glossaryViews := make(map[glossarySelection]int)
|
||||||
|
for i := range specs {
|
||||||
|
if err := ctx.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
spec := &specs[i]
|
||||||
|
key := glossarySelection{
|
||||||
|
context: fmt.Sprintf("%q", spec.Settings.Glossaries),
|
||||||
|
protected: fmt.Sprintf("%q", spec.Settings.ProtectedTerms),
|
||||||
|
exempt: spec.ModuleKey == modulecatalog.KeyGlossary,
|
||||||
|
}
|
||||||
|
if prior, ok := glossaryViews[key]; ok {
|
||||||
|
spec.GlossaryVariables = specs[prior].GlossaryVariables
|
||||||
|
spec.GlossaryView = specs[prior].GlossaryView
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := spec.PrepareGlossary(); err != nil {
|
||||||
|
return nil, fmt.Errorf("%s glossary preparation: %w", label(i, spec.Settings), err)
|
||||||
|
}
|
||||||
|
glossaryViews[key] = i
|
||||||
|
}
|
||||||
|
return specs, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package preflight
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ func TestLaterEmptyGlossaryFailsBeforeOutputPreparation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyPipelineNeedsNoProfile(t *testing.T) {
|
func TestEmptyPipelineNeedsNoProfile(t *testing.T) {
|
||||||
if err := CheckReadiness(context.Background(), &config.Config{}, nil); err != nil {
|
if _, err := ProcessingPlan(context.Background(), &config.Config{}, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +50,7 @@ func TestCorrectionRepairReadinessDependsOnBudget(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := CheckReadiness(context.Background(), cfg, inspect); err != nil {
|
if _, err := ProcessingPlan(context.Background(), cfg, inspect); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
cfg.Pipeline.Stages[0].LLM.CorrectionRepairAttempts = 1
|
cfg.Pipeline.Stages[0].LLM.CorrectionRepairAttempts = 1
|
||||||
@@ -61,3 +63,55 @@ func TestCorrectionRepairReadinessDependsOnBudget(t *testing.T) {
|
|||||||
t.Fatalf("output exists: %v", err)
|
t.Fatalf("output exists: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessingPlanReusesOnlyMatchingGlossaryViews(t *testing.T) {
|
||||||
|
profile := "selected"
|
||||||
|
item := config.Stage{Module: "grammar", Glossaries: []string{"a", "b"}, ProtectedTerms: []string{"a"},
|
||||||
|
LLM: config.LLM{ProposalProfile: &profile, ValidationProfile: &profile}}
|
||||||
|
reversed := item
|
||||||
|
reversed.Glossaries = []string{"b", "a"}
|
||||||
|
exempt := item
|
||||||
|
exempt.Module = "glossary"
|
||||||
|
cfg := &config.Config{
|
||||||
|
GlossaryCollections: map[string]config.GlossaryCollection{
|
||||||
|
"a": {Entries: []config.GlossaryEntry{{ID: "a", Name: "A"}}},
|
||||||
|
"b": {Entries: []config.GlossaryEntry{{ID: "b", Name: "B"}}},
|
||||||
|
},
|
||||||
|
Pipeline: config.Pipeline{Stages: []config.Stage{item, item, reversed, exempt}},
|
||||||
|
}
|
||||||
|
var inspected []string
|
||||||
|
plan, err := ProcessingPlan(context.Background(), cfg, func(_ context.Context, id string) error {
|
||||||
|
inspected = append(inspected, id)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil || len(plan) != 4 || !slices.Equal(inspected, []string{profile}) {
|
||||||
|
t.Fatalf("plan=%+v inspections=%v error=%v", plan, inspected, err)
|
||||||
|
}
|
||||||
|
if plan[0].GlossaryView != plan[1].GlossaryView || plan[0].GlossaryVariables != plan[1].GlossaryVariables ||
|
||||||
|
plan[0].GlossaryView == plan[2].GlossaryView || plan[0].GlossaryView == plan[3].GlossaryView ||
|
||||||
|
plan[2].Glossary[0].ID != "b" || plan[3].GlossaryVariables.ProtectionJSON != "[]" {
|
||||||
|
t.Fatalf("incorrect glossary reuse or exemptions: %+v", plan)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessingPlanPreservesFirstInspectionFailureAndCause(t *testing.T) {
|
||||||
|
proposal, validation := "proposal", "bad"
|
||||||
|
cfg := &config.Config{Pipeline: config.Pipeline{Stages: []config.Stage{
|
||||||
|
{Module: "grammar", LLM: config.LLM{ProposalProfile: &proposal, ValidationProfile: &validation}},
|
||||||
|
{Module: "grammar"},
|
||||||
|
}}}
|
||||||
|
runtimeErr := errors.New("inspection failed")
|
||||||
|
var checked []string
|
||||||
|
_, err := ProcessingPlan(context.Background(), cfg, func(_ context.Context, id string) error {
|
||||||
|
checked = append(checked, id)
|
||||||
|
if id == validation {
|
||||||
|
return runtimeErr
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
var selection *SelectionError
|
||||||
|
if !errors.Is(err, runtimeErr) || errors.As(err, &selection) || !strings.Contains(err.Error(), "stage 1 (grammar) validation") ||
|
||||||
|
!slices.Equal(checked, []string{proposal, validation}) {
|
||||||
|
t.Fatalf("inspected %v, error %v", checked, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -163,11 +163,9 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
policy := module.ReplacementPolicy()
|
policy := module.ReplacementPolicy()
|
||||||
glossaryVariables, err := promptcontext.PrepareGlossaryVariables(spec.Glossary, spec.ProtectedTerms)
|
if err := spec.PrepareGlossary(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return snapshot(), fmt.Errorf("module %q glossary preparation: %w", spec.InstanceName, err)
|
return snapshot(), fmt.Errorf("module %q glossary preparation: %w", spec.InstanceName, err)
|
||||||
}
|
}
|
||||||
glossaryView := validators.PrepareGlossaryView(spec.Glossary, spec.ProtectedTerms)
|
|
||||||
pipelineResult, pipelineErr := runModulePipeline(ctx, collectSectionProposalsInput{
|
pipelineResult, pipelineErr := runModulePipeline(ctx, collectSectionProposalsInput{
|
||||||
Module: module,
|
Module: module,
|
||||||
Spec: spec,
|
Spec: spec,
|
||||||
@@ -176,8 +174,8 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
|||||||
ProposalClient: spec.ProposalClient,
|
ProposalClient: spec.ProposalClient,
|
||||||
Interactions: input.Interactions,
|
Interactions: input.Interactions,
|
||||||
ValidationClient: spec.ValidationClient,
|
ValidationClient: spec.ValidationClient,
|
||||||
GlossaryVariables: &glossaryVariables,
|
GlossaryVariables: spec.GlossaryVariables,
|
||||||
GlossaryView: glossaryView,
|
GlossaryView: spec.GlossaryView,
|
||||||
})
|
})
|
||||||
if input.CaptureCandidates {
|
if input.CaptureCandidates {
|
||||||
candidates = append(candidates, pipelineResult.Candidates...)
|
candidates = append(candidates, pipelineResult.Candidates...)
|
||||||
@@ -213,7 +211,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
|||||||
return snapshot(), fmt.Errorf("module %q failed: %w", spec.InstanceName, pipelineErr)
|
return snapshot(), fmt.Errorf("module %q failed: %w", spec.InstanceName, pipelineErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
updated, applied, skipped, appliedBySection, applyErr := applyWithinSections(sections, pipelineResult.Approved, policy, glossaryView.Protection, spec.ModuleKey == modulecatalog.KeySpokenWord)
|
updated, applied, skipped, appliedBySection, applyErr := applyWithinSections(sections, pipelineResult.Approved, policy, spec.GlossaryView.Protection, spec.ModuleKey == modulecatalog.KeySpokenWord)
|
||||||
if applyErr != nil {
|
if applyErr != nil {
|
||||||
for i := range pipelineResult.WorkUnits {
|
for i := range pipelineResult.WorkUnits {
|
||||||
unit := &pipelineResult.WorkUnits[i]
|
unit := &pipelineResult.WorkUnits[i]
|
||||||
|
|||||||
@@ -91,12 +91,21 @@ func SharedVariables() map[string]string {
|
|||||||
|
|
||||||
// WithSharedVariables fills missing Audita instruction variables without replacing caller values.
|
// WithSharedVariables fills missing Audita instruction variables without replacing caller values.
|
||||||
func WithSharedVariables(values map[string]string) map[string]string {
|
func WithSharedVariables(values map[string]string) map[string]string {
|
||||||
result := make(map[string]string, len(values)+3)
|
return mergeSharedVariables(values, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessingVariables uses the pipeline's instructions for shared variables.
|
||||||
|
func ProcessingVariables(values map[string]string) map[string]string {
|
||||||
|
return mergeSharedVariables(values, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeSharedVariables(values map[string]string, authoritative bool) map[string]string {
|
||||||
|
result := make(map[string]string, len(values)+4)
|
||||||
for key, value := range values {
|
for key, value := range values {
|
||||||
result[key] = value
|
result[key] = value
|
||||||
}
|
}
|
||||||
for key, value := range SharedVariables() {
|
for key, value := range SharedVariables() {
|
||||||
if _, exists := result[key]; !exists {
|
if _, exists := result[key]; authoritative || !exists {
|
||||||
result[key] = value
|
result[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user