Adopt Audita native processing arguments
This commit is contained in:
@@ -53,7 +53,7 @@ func (f *FakeRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
|
||||
res.ProcessedTranscriptPath = req.OutputProcessedPath
|
||||
}
|
||||
if res.Reports == (ReportBundle{}) {
|
||||
dir := filepath.Dir(req.OutputProcessedPath)
|
||||
dir := reportDirectory(req)
|
||||
res.Reports = ReportBundle{
|
||||
ErrorsPath: filepath.Join(dir, "errors.yml"),
|
||||
RecoveriesPath: filepath.Join(dir, "recoveries.yml"),
|
||||
@@ -78,7 +78,7 @@ func (f *FakeRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
|
||||
func materializePlaceholders(req PolishRequest, reports bool) error {
|
||||
if req.GeneratedConfigPath != "" {
|
||||
payload := map[string]any{
|
||||
"schema": "audita.generated.v2",
|
||||
"schema": "audita.generated.v3",
|
||||
"placeholder": true,
|
||||
"merged_transcript_path": req.MergedTranscriptPath,
|
||||
"output_path": req.OutputProcessedPath,
|
||||
@@ -111,7 +111,7 @@ func materializePlaceholders(req PolishRequest, reports bool) error {
|
||||
{"recoveries.yml", "schema: audita-recoveries\nversion: 1\nstatus: completed\nrecoveries: []\n"},
|
||||
{"report.md", "# Audita report\n"},
|
||||
} {
|
||||
path := filepath.Join(filepath.Dir(req.OutputProcessedPath), report.name)
|
||||
path := filepath.Join(reportDirectory(req), report.name)
|
||||
if err := fileops.WriteFileAtomic(path, []byte(report.contents), fileops.WorkspaceFileMode); err != nil {
|
||||
return fmt.Errorf("write report %q: %w", path, err)
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ type Runner interface {
|
||||
Run(ctx context.Context, req PolishRequest) (PolishResult, error)
|
||||
}
|
||||
|
||||
// PolishRequest describes an Audita invocation. Nil Modules uses the runner's
|
||||
// configured selection; a non-nil empty slice selects no modules.
|
||||
// PolishRequest describes an Audita invocation.
|
||||
type PolishRequest struct {
|
||||
GeneratedConfigPath string
|
||||
MergedTranscriptPath string
|
||||
OutputProcessedPath string
|
||||
GlossaryPath string
|
||||
Modules []string
|
||||
GlossaryFiles []string
|
||||
ReportDir string
|
||||
WorkDir string
|
||||
StdoutLogPath string
|
||||
StderrLogPath string
|
||||
}
|
||||
|
||||
// ReportBundle contains optional reports adjacent to the requested output.
|
||||
// ReportBundle contains optional reports in the requested report directory.
|
||||
type ReportBundle struct {
|
||||
ErrorsPath string
|
||||
RecoveriesPath string
|
||||
|
||||
@@ -26,7 +26,7 @@ type SubprocessRunnerConfig struct {
|
||||
Binary string
|
||||
Timeout time.Duration
|
||||
Credentials []configkit.Secret
|
||||
Modules []string
|
||||
Debug bool
|
||||
Overlay string
|
||||
ProposalProfile string
|
||||
ValidationProfile string
|
||||
@@ -49,11 +49,6 @@ func NewSubprocessRunner(cfg SubprocessRunnerConfig) (*SubprocessRunner, error)
|
||||
if cfg.Timeout <= 0 {
|
||||
return nil, fmt.Errorf("audita timeout must be > 0")
|
||||
}
|
||||
for i, module := range cfg.Modules {
|
||||
if strings.TrimSpace(module) == "" {
|
||||
return nil, fmt.Errorf("audita module at index %d is empty", i)
|
||||
}
|
||||
}
|
||||
switch strings.TrimSpace(cfg.OutputSchema) {
|
||||
case "", "bare-segments", "audita-v1":
|
||||
default:
|
||||
@@ -61,20 +56,9 @@ func NewSubprocessRunner(cfg SubprocessRunnerConfig) (*SubprocessRunner, error)
|
||||
}
|
||||
cfg.Binary = strings.TrimSpace(cfg.Binary)
|
||||
cfg.Credentials = append([]configkit.Secret(nil), cfg.Credentials...)
|
||||
cfg.Modules = cloneModules(cfg.Modules)
|
||||
for i := range cfg.Modules {
|
||||
cfg.Modules[i] = strings.TrimSpace(cfg.Modules[i])
|
||||
}
|
||||
return &SubprocessRunner{cfg: cfg, run: subprocess.Run}, nil
|
||||
}
|
||||
|
||||
func cloneModules(modules []string) []string {
|
||||
if modules == nil {
|
||||
return nil
|
||||
}
|
||||
return append([]string{}, modules...)
|
||||
}
|
||||
|
||||
// Run executes Audita process and validates its corrected transcript.
|
||||
func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishResult, error) {
|
||||
if r == nil {
|
||||
@@ -82,33 +66,24 @@ func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishRe
|
||||
}
|
||||
for _, field := range []struct{ name, value string }{
|
||||
{"merged transcript path", req.MergedTranscriptPath},
|
||||
{"glossary path", req.GlossaryPath},
|
||||
{"output processed path", req.OutputProcessedPath},
|
||||
} {
|
||||
if strings.TrimSpace(field.value) == "" {
|
||||
return PolishResult{}, fmt.Errorf("audita %s is required", field.name)
|
||||
}
|
||||
}
|
||||
modules := req.Modules
|
||||
if modules == nil {
|
||||
modules = r.cfg.Modules
|
||||
}
|
||||
for i, module := range modules {
|
||||
if strings.TrimSpace(module) == "" {
|
||||
return PolishResult{}, fmt.Errorf("audita module at index %d is empty", i)
|
||||
for i, path := range req.GlossaryFiles {
|
||||
if strings.TrimSpace(path) == "" {
|
||||
return PolishResult{}, fmt.Errorf("audita glossary file at index %d is empty", i)
|
||||
}
|
||||
}
|
||||
modules = cloneModules(modules)
|
||||
for i := range modules {
|
||||
modules[i] = strings.TrimSpace(modules[i])
|
||||
}
|
||||
args := r.buildArgs(req, modules)
|
||||
args := r.buildArgs("process", req)
|
||||
env, names, err := subprocess.CredentialEnvironment(r.cfg.Credentials)
|
||||
if err != nil {
|
||||
return PolishResult{}, fmt.Errorf("audita credentials: %w", err)
|
||||
}
|
||||
if req.GeneratedConfigPath != "" {
|
||||
if err := r.writeInvocationConfig(req, args, modules, names); err != nil {
|
||||
if err := r.writeInvocationConfig(req, args, names); err != nil {
|
||||
return PolishResult{}, fmt.Errorf("write audita invocation config %q: %w", req.GeneratedConfigPath, err)
|
||||
}
|
||||
}
|
||||
@@ -121,17 +96,17 @@ func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishRe
|
||||
EnvOverrides: env, SensitiveEnvNames: names, DiagnosticOwner: "audita",
|
||||
StdoutLogPath: req.StdoutLogPath, StderrLogPath: req.StderrLogPath,
|
||||
})
|
||||
result := r.result(req, modules, names, runRes)
|
||||
result := r.result(req, names, runRes)
|
||||
if runErr != nil {
|
||||
result.Reports, _ = discoverReports(req.OutputProcessedPath)
|
||||
result.Reports, _ = discoverReports(reportDirectory(req))
|
||||
return result, fmt.Errorf("run audita process (binary=%q, output_dir=%q, stdout_log=%q, stderr_log=%q): %w",
|
||||
r.cfg.Binary, filepath.Dir(req.OutputProcessedPath), req.StdoutLogPath, req.StderrLogPath, runErr)
|
||||
}
|
||||
if err := validateProcessedOutput(req.OutputProcessedPath); err != nil {
|
||||
result.Reports, _ = discoverReports(req.OutputProcessedPath)
|
||||
result.Reports, _ = discoverReports(reportDirectory(req))
|
||||
return result, fmt.Errorf("validate audita processed output %q: %w", req.OutputProcessedPath, err)
|
||||
}
|
||||
reports, err := discoverReports(req.OutputProcessedPath)
|
||||
reports, err := discoverReports(reportDirectory(req))
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -139,14 +114,14 @@ func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishRe
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *SubprocessRunner) result(req PolishRequest, modules, names []string, runRes subprocess.RunResult) PolishResult {
|
||||
func (r *SubprocessRunner) result(req PolishRequest, names []string, runRes subprocess.RunResult) PolishResult {
|
||||
return PolishResult{
|
||||
ProcessedTranscriptPath: req.OutputProcessedPath,
|
||||
StdoutLogPath: req.StdoutLogPath, StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath, ExitCode: runRes.ExitCode,
|
||||
Duration: runRes.Duration, InvokedBinary: r.cfg.Binary,
|
||||
Metadata: map[string]any{
|
||||
"adapter": "audita_subprocess", "modules": modules,
|
||||
"adapter": "audita_subprocess", "glossary_files": req.GlossaryFiles, "report_dir": req.ReportDir, "work_dir": req.WorkDir, "debug": r.cfg.Debug,
|
||||
"overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile,
|
||||
"validation_profile": r.cfg.ValidationProfile,
|
||||
"transcript_description": r.cfg.TranscriptDescription,
|
||||
@@ -156,37 +131,45 @@ func (r *SubprocessRunner) result(req PolishRequest, modules, names []string, ru
|
||||
}
|
||||
}
|
||||
|
||||
func (r *SubprocessRunner) buildArgs(req PolishRequest, modules []string) []string {
|
||||
args := []string{"process", req.MergedTranscriptPath, "--glossary", req.GlossaryPath, "--output", req.OutputProcessedPath}
|
||||
if modules != nil {
|
||||
args = append(args, "--modules", strings.Join(modules, ","))
|
||||
func (r *SubprocessRunner) buildArgs(command string, req PolishRequest) []string {
|
||||
args := []string{command, req.MergedTranscriptPath, "--output", req.OutputProcessedPath}
|
||||
for _, path := range req.GlossaryFiles {
|
||||
args = append(args, "--glossary-file", path)
|
||||
}
|
||||
for _, setting := range []struct{ flag, value string }{
|
||||
{"--config", r.cfg.ConfigPath}, {"--overlay", r.cfg.Overlay},
|
||||
{"--proposal-profile", r.cfg.ProposalProfile}, {"--validation-profile", r.cfg.ValidationProfile},
|
||||
{"--transcript-description", r.cfg.TranscriptDescription}, {"--output-schema", r.cfg.OutputSchema},
|
||||
{"--report-dir", req.ReportDir}, {"--work-dir", req.WorkDir},
|
||||
} {
|
||||
if setting.value != "" {
|
||||
args = append(args, setting.flag, setting.value)
|
||||
}
|
||||
}
|
||||
if r.cfg.Debug {
|
||||
args = append(args, "--debug")
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func (r *SubprocessRunner) writeInvocationConfig(req PolishRequest, args, modules, names []string) error {
|
||||
func (r *SubprocessRunner) writeInvocationConfig(req PolishRequest, args, names []string) error {
|
||||
return writeGeneratedYAML(req.GeneratedConfigPath, map[string]any{
|
||||
"schema": "audita.generated.v2", "binary": r.cfg.Binary, "args": args,
|
||||
"timeout": r.cfg.Timeout.String(), "modules": modules,
|
||||
"overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile,
|
||||
"validation_profile": r.cfg.ValidationProfile,
|
||||
"transcript_description": r.cfg.TranscriptDescription,
|
||||
"config_path": r.cfg.ConfigPath, "output_schema": r.cfg.OutputSchema,
|
||||
"merged_transcript_path": req.MergedTranscriptPath, "glossary_path": req.GlossaryPath,
|
||||
"output_path": req.OutputProcessedPath, "credential_names": names,
|
||||
"schema": "audita.generated.v3", "binary": r.cfg.Binary, "args": args, "timeout": r.cfg.Timeout.String(),
|
||||
"glossary_files": req.GlossaryFiles, "report_dir": req.ReportDir, "work_dir": req.WorkDir, "debug": r.cfg.Debug,
|
||||
"overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile, "validation_profile": r.cfg.ValidationProfile,
|
||||
"transcript_description": r.cfg.TranscriptDescription, "config_path": r.cfg.ConfigPath, "output_schema": r.cfg.OutputSchema,
|
||||
"merged_transcript_path": req.MergedTranscriptPath, "output_path": req.OutputProcessedPath, "credential_names": names,
|
||||
})
|
||||
}
|
||||
|
||||
func discoverReports(outputPath string) (ReportBundle, error) {
|
||||
func reportDirectory(req PolishRequest) string {
|
||||
if req.ReportDir != "" {
|
||||
return req.ReportDir
|
||||
}
|
||||
return filepath.Dir(req.OutputProcessedPath)
|
||||
}
|
||||
|
||||
func discoverReports(reportDir string) (ReportBundle, error) {
|
||||
var reports ReportBundle
|
||||
for _, report := range []struct {
|
||||
name string
|
||||
@@ -196,7 +179,7 @@ func discoverReports(outputPath string) (ReportBundle, error) {
|
||||
{"recoveries.yml", &reports.RecoveriesPath},
|
||||
{"report.md", &reports.OverviewPath},
|
||||
} {
|
||||
path := filepath.Join(filepath.Dir(outputPath), report.name)
|
||||
path := filepath.Join(reportDir, report.name)
|
||||
info, err := os.Lstat(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
continue
|
||||
|
||||
@@ -19,7 +19,7 @@ func auditaTestRequest(t *testing.T) PolishRequest {
|
||||
dir := t.TempDir()
|
||||
return PolishRequest{
|
||||
MergedTranscriptPath: filepath.Join(dir, "merged.json"),
|
||||
GlossaryPath: filepath.Join(dir, "glossary.yml"),
|
||||
GlossaryFiles: []string{filepath.Join(dir, "party.yml"), filepath.Join(dir, "campaign terms.yml")},
|
||||
OutputProcessedPath: filepath.Join(dir, "polished.json"),
|
||||
GeneratedConfigPath: filepath.Join(dir, "audita.generated.yml"),
|
||||
StdoutLogPath: filepath.Join(dir, "stdout.log"),
|
||||
@@ -62,7 +62,7 @@ func writeAuditaTestFile(t *testing.T, path, value string) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessRunnerUsesV2InvocationAndCapturedCredentials(t *testing.T) {
|
||||
func TestSubprocessRunnerUsesNativeInvocationAndCapturedCredentials(t *testing.T) {
|
||||
const first = "NARRATIO_AUDITA_CUSTOM_ONE"
|
||||
const second = "NARRATIO_AUDITA_CUSTOM_TWO"
|
||||
firstSecret := auditaTestSecret(t, first, "loaded-one")
|
||||
@@ -72,7 +72,6 @@ func TestSubprocessRunnerUsesV2InvocationAndCapturedCredentials(t *testing.T) {
|
||||
t.Setenv("NARRATIO_AUDITA_UNSELECTED", "not-forwarded")
|
||||
runner := auditaTestRunner(t, SubprocessRunnerConfig{
|
||||
Credentials: []configkit.Secret{firstSecret, secondSecret},
|
||||
Modules: []string{"grammar", "glossary", "grammar"},
|
||||
Overlay: "testing", ProposalProfile: "proposal", ValidationProfile: "validation",
|
||||
TranscriptDescription: "campaign", ConfigPath: "/etc/audita/config.yml", OutputSchema: "audita-v1",
|
||||
})
|
||||
@@ -90,8 +89,8 @@ func TestSubprocessRunnerUsesV2InvocationAndCapturedCredentials(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"process", req.MergedTranscriptPath, "--glossary", req.GlossaryPath, "--output", req.OutputProcessedPath,
|
||||
"--modules", "grammar,glossary,grammar", "--config", "/etc/audita/config.yml", "--overlay", "testing",
|
||||
want := []string{"process", req.MergedTranscriptPath, "--output", req.OutputProcessedPath,
|
||||
"--glossary-file", req.GlossaryFiles[0], "--glossary-file", req.GlossaryFiles[1], "--config", "/etc/audita/config.yml", "--overlay", "testing",
|
||||
"--proposal-profile", "proposal", "--validation-profile", "validation", "--transcript-description", "campaign", "--output-schema", "audita-v1"}
|
||||
if !reflect.DeepEqual(captured.Args, want) {
|
||||
t.Fatalf("args = %#v, want %#v", captured.Args, want)
|
||||
@@ -109,51 +108,11 @@ func TestSubprocessRunnerUsesV2InvocationAndCapturedCredentials(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(generated), "audita.generated.v2") || !strings.Contains(string(generated), first) || strings.Contains(string(generated), "loaded-one") {
|
||||
if !strings.Contains(string(generated), "audita.generated.v3") || !strings.Contains(string(generated), first) || strings.Contains(string(generated), "loaded-one") {
|
||||
t.Fatalf("unsafe or incomplete generated invocation: %s", generated)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessRunnerModulePresenceAndReportAbsence(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
configured []string
|
||||
requested []string
|
||||
wantFlag bool
|
||||
wantValue string
|
||||
}{
|
||||
{"omitted", nil, nil, false, ""},
|
||||
{"configured", []string{"grammar", "grammar"}, nil, true, "grammar,grammar"},
|
||||
{"empty override", []string{"grammar"}, []string{}, true, ""},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
runner := auditaTestRunner(t, SubprocessRunnerConfig{Modules: test.configured})
|
||||
req := auditaTestRequest(t)
|
||||
req.Modules = test.requested
|
||||
runner.run = func(_ context.Context, processReq subprocess.RunRequest) (subprocess.RunResult, error) {
|
||||
index := -1
|
||||
for i, arg := range processReq.Args {
|
||||
if arg == "--modules" {
|
||||
index = i
|
||||
}
|
||||
if strings.HasPrefix(arg, "--report") || arg == "--debug" || arg == "--work-dir" {
|
||||
t.Fatalf("retired or unwanted flag %q", arg)
|
||||
}
|
||||
}
|
||||
if (index >= 0) != test.wantFlag || (index >= 0 && processReq.Args[index+1] != test.wantValue) {
|
||||
t.Fatalf("args = %#v", processReq.Args)
|
||||
}
|
||||
writeAuditaTestFile(t, req.OutputProcessedPath, `{"segments":[]}`)
|
||||
return subprocess.RunResult{}, nil
|
||||
}
|
||||
result, err := runner.Run(context.Background(), req)
|
||||
if err != nil || result.Reports != (ReportBundle{}) {
|
||||
t.Fatalf("result = %#v, error = %v", result, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessRunnerRejectsMissingOrMalformedTranscript(t *testing.T) {
|
||||
for _, output := range []string{"", `{"segments":"wrong"}`} {
|
||||
t.Run(output, func(t *testing.T) {
|
||||
@@ -261,3 +220,39 @@ func TestSubprocessRunnerRedactsCustomCredentialStreams(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessRunnerDestinationsAndDebug(t *testing.T) {
|
||||
for _, debug := range []bool{false, true} {
|
||||
runner := auditaTestRunner(t, SubprocessRunnerConfig{Debug: debug})
|
||||
req := auditaTestRequest(t)
|
||||
req.ReportDir = filepath.Join(t.TempDir(), "reports")
|
||||
req.WorkDir = filepath.Join(t.TempDir(), "work")
|
||||
if err := os.MkdirAll(req.ReportDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
runner.run = func(_ context.Context, processReq subprocess.RunRequest) (subprocess.RunResult, error) {
|
||||
flags := strings.Join(processReq.Args, "|")
|
||||
if !strings.Contains(flags, "--report-dir|"+req.ReportDir) || !strings.Contains(flags, "--work-dir|"+req.WorkDir) || strings.Contains(flags, "--reporting=false") || strings.Contains(flags, "--modules") || strings.Contains(flags, "--debug") != debug {
|
||||
t.Fatalf("args: %v", processReq.Args)
|
||||
}
|
||||
writeAuditaTestFile(t, req.OutputProcessedPath, `{"segments":[]}`)
|
||||
writeAuditaTestFile(t, filepath.Join(req.ReportDir, "errors.yml"), "status: completed\n")
|
||||
return subprocess.RunResult{}, nil
|
||||
}
|
||||
result, err := runner.Run(context.Background(), req)
|
||||
if err != nil || result.Reports.ErrorsPath != filepath.Join(req.ReportDir, "errors.yml") {
|
||||
t.Fatalf("result: %+v %v", result, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkDirectoryAloneDoesNotEnableCapture(t *testing.T) {
|
||||
runner := auditaTestRunner(t, SubprocessRunnerConfig{})
|
||||
req := auditaTestRequest(t)
|
||||
req.WorkDir = filepath.Join(t.TempDir(), "work")
|
||||
args := runner.buildArgs("process", req)
|
||||
joined := strings.Join(args, "|")
|
||||
if !strings.Contains(joined, "--work-dir|"+req.WorkDir) || strings.Contains(joined, "--debug") || strings.Contains(joined, "--report-dir") || strings.Contains(joined, "--reporting") {
|
||||
t.Fatalf("args: %v", args)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ func buildDefaultAuditaRunner(cfg *config.Config) (audita.Runner, error) {
|
||||
}
|
||||
runner, err := audita.NewSubprocessRunner(audita.SubprocessRunnerConfig{
|
||||
Binary: a.Binary, Timeout: timeout, Credentials: a.Credentials,
|
||||
Modules: append(a.Modules[:0:0], a.Modules...),
|
||||
Debug: a.Debug,
|
||||
Overlay: a.Overlay, ProposalProfile: a.ProposalProfile,
|
||||
ValidationProfile: a.ValidationProfile,
|
||||
TranscriptDescription: a.TranscriptDescription, ConfigPath: a.ConfigPath,
|
||||
|
||||
@@ -218,7 +218,7 @@ type AuditaConfig struct {
|
||||
Binary string `yaml:"binary" json:"binary"`
|
||||
Timeout string `yaml:"timeout" json:"timeout"`
|
||||
Credentials []configkit.Secret `yaml:"credentials,omitempty" json:"credentials,omitempty"`
|
||||
Modules []string `yaml:"modules" json:"modules"`
|
||||
Debug bool `yaml:"debug" json:"debug"`
|
||||
Overlay string `yaml:"overlay" json:"overlay"`
|
||||
ProposalProfile string `yaml:"proposal_profile" json:"proposal_profile"`
|
||||
ValidationProfile string `yaml:"validation_profile" json:"validation_profile"`
|
||||
|
||||
@@ -24,25 +24,20 @@ func (cfg StorageS3Config) MarshalYAML() (any, error) {
|
||||
// MarshalYAML exposes only public Audita credential reference names.
|
||||
func (cfg AuditaConfig) MarshalYAML() (any, error) {
|
||||
type safeAudita struct {
|
||||
Binary string `yaml:"binary"`
|
||||
Timeout string `yaml:"timeout"`
|
||||
Credentials []string `yaml:"credentials,omitempty"`
|
||||
Modules *[]string `yaml:"modules,omitempty"`
|
||||
Overlay string `yaml:"overlay"`
|
||||
ProposalProfile string `yaml:"proposal_profile"`
|
||||
ValidationProfile string `yaml:"validation_profile"`
|
||||
TranscriptDescription string `yaml:"transcript_description"`
|
||||
ConfigPath string `yaml:"config_path"`
|
||||
OutputSchema string `yaml:"output_schema"`
|
||||
}
|
||||
// A nil pointer omits the override; a pointer to an empty slice disables modules.
|
||||
var modules *[]string
|
||||
if cfg.Modules != nil {
|
||||
modules = &cfg.Modules
|
||||
Binary string `yaml:"binary"`
|
||||
Timeout string `yaml:"timeout"`
|
||||
Credentials []string `yaml:"credentials,omitempty"`
|
||||
Debug bool `yaml:"debug,omitempty"`
|
||||
Overlay string `yaml:"overlay"`
|
||||
ProposalProfile string `yaml:"proposal_profile"`
|
||||
ValidationProfile string `yaml:"validation_profile"`
|
||||
TranscriptDescription string `yaml:"transcript_description"`
|
||||
ConfigPath string `yaml:"config_path"`
|
||||
OutputSchema string `yaml:"output_schema"`
|
||||
}
|
||||
return safeAudita{
|
||||
Binary: cfg.Binary, Timeout: cfg.Timeout, Credentials: secretReferenceNames(cfg.Credentials),
|
||||
Modules: modules, Overlay: cfg.Overlay, ProposalProfile: cfg.ProposalProfile,
|
||||
Debug: cfg.Debug, Overlay: cfg.Overlay, ProposalProfile: cfg.ProposalProfile,
|
||||
ValidationProfile: cfg.ValidationProfile, TranscriptDescription: cfg.TranscriptDescription,
|
||||
ConfigPath: cfg.ConfigPath, OutputSchema: cfg.OutputSchema,
|
||||
}, nil
|
||||
|
||||
@@ -1,33 +1,17 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAuditaYAMLPreservesModuleSelection(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
modules []string
|
||||
}{
|
||||
{name: "omitted"},
|
||||
{name: "explicit empty", modules: []string{}},
|
||||
{name: "ordered repetitions", modules: []string{"grammar", "names", "grammar"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
data, err := yaml.Marshal(AuditaConfig{Modules: tc.modules})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded AuditaConfig
|
||||
if err := yaml.Unmarshal(data, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(decoded.Modules, tc.modules) {
|
||||
t.Fatalf("modules = %#v, want %#v; YAML:\n%s", decoded.Modules, tc.modules, data)
|
||||
}
|
||||
})
|
||||
func TestAuditaYAMLPreservesDebug(t *testing.T) {
|
||||
data, err := yaml.Marshal(AuditaConfig{Debug: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded AuditaConfig
|
||||
if err := yaml.Unmarshal(data, &decoded); err != nil || !decoded.Debug {
|
||||
t.Fatalf("debug round trip: %s %v", data, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ type effectiveAuditaConfig struct {
|
||||
Binary string `yaml:"binary" json:"binary"`
|
||||
Timeout string `yaml:"timeout" json:"timeout"`
|
||||
Credentials []string `yaml:"credentials" json:"credentials"`
|
||||
Modules []string `yaml:"modules" json:"modules"`
|
||||
Debug bool `yaml:"debug" json:"debug"`
|
||||
Overlay string `yaml:"overlay" json:"overlay"`
|
||||
ProposalProfile string `yaml:"proposal_profile" json:"proposal_profile"`
|
||||
ValidationProfile string `yaml:"validation_profile" json:"validation_profile"`
|
||||
@@ -89,7 +89,7 @@ func projectEffectivePipeline(cfg *PipelineConfig) effectivePipelineProjection {
|
||||
projection.Storage.S3 = &effectiveStorageS3Config{Bucket: s3.Bucket, RootPrefix: s3.RootPrefix, Region: s3.Region, Endpoint: s3.Endpoint, ForcePathStyle: s3.ForcePathStyle, AccessKeyID: secretReferenceName(s3.AccessKeyID), SecretAccessKey: secretReferenceName(s3.SecretAccessKey)}
|
||||
}
|
||||
audita := cfg.Audita
|
||||
projection.Audita = effectiveAuditaConfig{Binary: audita.Binary, Timeout: audita.Timeout, Credentials: secretReferenceNames(audita.Credentials), Modules: audita.Modules, Overlay: audita.Overlay, ProposalProfile: audita.ProposalProfile, ValidationProfile: audita.ValidationProfile, TranscriptDescription: audita.TranscriptDescription, ConfigPath: audita.ConfigPath, OutputSchema: audita.OutputSchema}
|
||||
projection.Audita = effectiveAuditaConfig{Binary: audita.Binary, Timeout: audita.Timeout, Credentials: secretReferenceNames(audita.Credentials), Debug: audita.Debug, Overlay: audita.Overlay, ProposalProfile: audita.ProposalProfile, ValidationProfile: audita.ValidationProfile, TranscriptDescription: audita.TranscriptDescription, ConfigPath: audita.ConfigPath, OutputSchema: audita.OutputSchema}
|
||||
if n := cfg.Notarius; n != nil {
|
||||
projection.Notarius = &effectiveNotariusConfig{Enabled: n.Enabled, Binary: n.Binary, Credentials: secretReferenceNames(n.Credentials), ConfigOverlay: n.ConfigOverlay, Resume: n.Resume, ChunkCache: n.ChunkCache, ConfigPath: n.ConfigPath, PipelineID: n.PipelineID, Timeout: n.Timeout, WorkingDirectory: n.WorkingDirectory, References: n.References, Outputs: n.Outputs}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ notarius:
|
||||
|
||||
func TestPipelineMaterializationPreservesNilEmptyAndExactIntegers(t *testing.T) {
|
||||
base := &PipelineConfig{
|
||||
Audita: AuditaConfig{Modules: nil},
|
||||
Audita: AuditaConfig{},
|
||||
Scriptorium: &ScriptoriumConfig{Artifacts: nil},
|
||||
resolution: &pipelineResolutionMetadata{},
|
||||
}
|
||||
@@ -197,14 +197,13 @@ func TestPipelineMaterializationPreservesNilEmptyAndExactIntegers(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(nilYAML), "modules: null\n") || !strings.Contains(string(nilYAML), "artifacts: null\n") {
|
||||
if !strings.Contains(string(nilYAML), "artifacts: null\n") {
|
||||
t.Fatalf("effective YAML lost null collections: %q", nilYAML)
|
||||
}
|
||||
if err := recomputePipelineEffectiveDigest(base); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nilDigest := EffectivePipelineDigest(base)
|
||||
base.Audita.Modules = []string{}
|
||||
base.Scriptorium.Artifacts = map[string]ScriptoriumArtifactConfig{}
|
||||
if err := recomputePipelineEffectiveDigest(base); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -213,7 +212,7 @@ func TestPipelineMaterializationPreservesNilEmptyAndExactIntegers(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(emptyYAML), "modules: []\n") || !strings.Contains(string(emptyYAML), "artifacts: {}\n") {
|
||||
if !strings.Contains(string(emptyYAML), "artifacts: {}\n") {
|
||||
t.Fatalf("effective YAML lost empty collections: %q", emptyYAML)
|
||||
}
|
||||
if err := recomputePipelineEffectiveDigest(base); err != nil {
|
||||
|
||||
@@ -453,40 +453,8 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuditaModulesPreserveOmittedEmptyAndReplacementSelections(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name, base, overlay string
|
||||
wantNil bool
|
||||
want []string
|
||||
}{
|
||||
{name: "omitted", wantNil: true},
|
||||
{name: "null", base: " modules: null\n", wantNil: true},
|
||||
{name: "empty", base: " modules: []\n", want: []string{}},
|
||||
{name: "overlay empty", base: " modules: [glossary]\n", overlay: "audita:\n modules: []\n", want: []string{}},
|
||||
{name: "overlay order", base: " modules: []\n", overlay: "audita:\n modules: [grammar, glossary, grammar]\n", want: []string{"grammar", "glossary", "grammar"}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n binary: audita\n"+test.base)
|
||||
options := PipelineLoadOptions{}
|
||||
if test.overlay != "" {
|
||||
writePipelineFixture(t, dir, "overlays/testing.yml", test.overlay)
|
||||
selection := "testing"
|
||||
options.Overlay = &selection
|
||||
}
|
||||
cfg, err := LoadPipelineWithOptions(root, options)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if (cfg.Audita.Modules == nil) != test.wantNil || !reflect.DeepEqual(cfg.Audita.Modules, test.want) {
|
||||
t.Fatalf("modules = %#v, want %#v (nil=%v)", cfg.Audita.Modules, test.want, test.wantNil)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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", "modules"} {
|
||||
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")
|
||||
if _, err := LoadPipeline(root); err == nil || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
|
||||
|
||||
@@ -165,17 +165,6 @@ func validateAudita(cfg AuditaConfig) error {
|
||||
if err := validateDuration("pipeline.audita.timeout", cfg.Timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
for i, m := range cfg.Modules {
|
||||
module := strings.TrimSpace(m)
|
||||
if module == "" {
|
||||
return fmt.Errorf("pipeline.audita.modules[%d] must be non-empty", i)
|
||||
}
|
||||
switch module {
|
||||
case "glossary", "homophones", "spoken_word", "grammar":
|
||||
default:
|
||||
return fmt.Errorf("pipeline.audita.modules[%d] must be one of: glossary, homophones, spoken_word, grammar", i)
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(cfg.TranscriptDescription) == "" && cfg.TranscriptDescription != "" {
|
||||
return fmt.Errorf("pipeline.audita.transcript_description must be non-empty when provided")
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
GeneratedConfigPath: generatedConfigPath,
|
||||
MergedTranscriptPath: mergedPath,
|
||||
OutputProcessedPath: processedPath,
|
||||
GlossaryPath: glossaryPath,
|
||||
GlossaryFiles: []string{glossaryPath},
|
||||
StdoutLogPath: stdoutPath,
|
||||
StderrLogPath: stderrPath,
|
||||
}
|
||||
@@ -136,7 +136,6 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
|
||||
"glossary_path": glossaryPath,
|
||||
"run_output_path": finalProcessedPath,
|
||||
"output_path": canonicalProcessedPath,
|
||||
"modules": append(env.Config.Pipeline.Audita.Modules[:0:0], env.Config.Pipeline.Audita.Modules...),
|
||||
"overlay": env.Config.Pipeline.Audita.Overlay,
|
||||
"proposal_profile": env.Config.Pipeline.Audita.ProposalProfile,
|
||||
"validation_profile": env.Config.Pipeline.Audita.ValidationProfile,
|
||||
|
||||
@@ -49,8 +49,8 @@ func TestPolishStagePolishesMergedTranscriptAndRecordsMetadata(t *testing.T) {
|
||||
if req.MergedTranscriptPath != mergedPath {
|
||||
t.Fatalf("merged path = %q, want %q", req.MergedTranscriptPath, mergedPath)
|
||||
}
|
||||
if req.GlossaryPath != filepath.Join(paths.InputsDir, "glossary.yml") {
|
||||
t.Fatalf("glossary path = %q", req.GlossaryPath)
|
||||
if len(req.GlossaryFiles) != 1 || req.GlossaryFiles[0] != filepath.Join(paths.InputsDir, "glossary.yml") {
|
||||
t.Fatalf("glossary paths = %q", req.GlossaryFiles)
|
||||
}
|
||||
if len(result.Outputs) != 1 {
|
||||
t.Fatalf("outputs len = %d, want 1", len(result.Outputs))
|
||||
@@ -286,7 +286,6 @@ func setupPolishEnv(t *testing.T) (*Env, *manifest.Manifest) {
|
||||
Binary: "audita",
|
||||
Timeout: "3h",
|
||||
Credentials: []configkit.Secret{*testSecretReference("AUDITA_LLM_API_KEY")},
|
||||
Modules: []string{"glossary", "homophones", "grammar"},
|
||||
TranscriptDescription: "Campaign Session 42",
|
||||
ConfigPath: "/etc/audita/config.yml",
|
||||
OutputSchema: "audita-v1",
|
||||
|
||||
@@ -17,14 +17,13 @@ const (
|
||||
)
|
||||
|
||||
type polishSemanticConfig struct {
|
||||
Modules []string `json:"modules"`
|
||||
Overlay string `json:"overlay"`
|
||||
ProposalProfile string `json:"proposal_profile"`
|
||||
ValidationProfile string `json:"validation_profile"`
|
||||
TranscriptDescription string `json:"transcript_description"`
|
||||
OutputSchema string `json:"output_schema"`
|
||||
ConfigPath string `json:"config_path"`
|
||||
OutputIdentity string `json:"output_identity"`
|
||||
Overlay string `json:"overlay"`
|
||||
ProposalProfile string `json:"proposal_profile"`
|
||||
ValidationProfile string `json:"validation_profile"`
|
||||
TranscriptDescription string `json:"transcript_description"`
|
||||
OutputSchema string `json:"output_schema"`
|
||||
ConfigPath string `json:"config_path"`
|
||||
OutputIdentity string `json:"output_identity"`
|
||||
}
|
||||
|
||||
type normalizeSemanticConfig struct {
|
||||
@@ -67,15 +66,7 @@ func (polishStage) SemanticConfigFingerprint(env *Env) (manifest.SemanticConfigF
|
||||
return manifest.SemanticConfigFingerprint{}, fmt.Errorf("polish semantic configuration requires resolved pipeline config")
|
||||
}
|
||||
audita := env.Config.Pipeline.Audita
|
||||
var modules []string
|
||||
if audita.Modules != nil {
|
||||
modules = append([]string{}, audita.Modules...)
|
||||
}
|
||||
for index := range modules {
|
||||
modules[index] = strings.TrimSpace(modules[index])
|
||||
}
|
||||
return FingerprintSemanticConfig(polishSemanticConfigVersion, polishSemanticConfig{
|
||||
Modules: modules,
|
||||
Overlay: audita.Overlay,
|
||||
ProposalProfile: audita.ProposalProfile,
|
||||
ValidationProfile: audita.ValidationProfile,
|
||||
|
||||
@@ -12,11 +12,6 @@ func TestPolishSemanticConfigSensitivity(t *testing.T) {
|
||||
name string
|
||||
mutate func(*Env)
|
||||
}{
|
||||
{name: "modules", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"terms", "speakers", "style"} }},
|
||||
{name: "module order", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"terms", "speakers"} }},
|
||||
{name: "module repetition", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"speakers", "terms", "terms"} }},
|
||||
{name: "modules omitted", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = nil }},
|
||||
{name: "modules empty", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{} }},
|
||||
{name: "overlay", mutate: func(env *Env) { env.Config.Pipeline.Audita.Overlay = "testing" }},
|
||||
{name: "proposal profile", mutate: func(env *Env) { env.Config.Pipeline.Audita.ProposalProfile = "draft" }},
|
||||
{name: "validation profile", mutate: func(env *Env) { env.Config.Pipeline.Audita.ValidationProfile = "review" }},
|
||||
@@ -30,6 +25,7 @@ func TestPolishSemanticConfigSensitivity(t *testing.T) {
|
||||
mutate func(*Env)
|
||||
}{
|
||||
{name: "runner settings", mutate: func(env *Env) {
|
||||
env.Config.Pipeline.Audita.Debug = true
|
||||
env.Config.Pipeline.Audita.Binary = "/opt/audita"
|
||||
env.Config.Pipeline.Audita.Timeout = "1h"
|
||||
env.Config.Pipeline.Audita.Credentials = []configkit.Secret{*testSecretReference("OTHER_KEY")}
|
||||
@@ -37,23 +33,6 @@ func TestPolishSemanticConfigSensitivity(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestPolishSemanticConfigDistinguishesOmittedAndExplicitlyEmptyModules(t *testing.T) {
|
||||
env := refinementSemanticEnv()
|
||||
env.Config.Pipeline.Audita.Modules = nil
|
||||
omitted, err := (polishStage{}).SemanticConfigFingerprint(env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
env.Config.Pipeline.Audita.Modules = []string{}
|
||||
empty, err := (polishStage{}).SemanticConfigFingerprint(env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if omitted.Equal(empty) {
|
||||
t.Fatal("omitted and explicitly empty module selections have equal semantic evidence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSemanticConfigSensitivity(t *testing.T) {
|
||||
assertRefinementChanges(t, normalizeStage{}, []struct {
|
||||
name string
|
||||
@@ -137,8 +116,8 @@ func refinementSemanticEnv() *Env {
|
||||
env.Config.Session.Title = "Session title"
|
||||
env.Config.Pipeline.Audita = config.AuditaConfig{
|
||||
Binary: "audita", Timeout: "10m", Credentials: []configkit.Secret{*testSecretReference("AUDITA_KEY")},
|
||||
Modules: []string{"speakers", "terms"}, TranscriptDescription: "tabletop session",
|
||||
ConfigPath: "configs/audita.yml", OutputSchema: "audita.transcript.v1",
|
||||
TranscriptDescription: "tabletop session",
|
||||
ConfigPath: "configs/audita.yml", OutputSchema: "audita.transcript.v1",
|
||||
}
|
||||
env.Config.Pipeline.Normalize = &config.NormalizeConfig{
|
||||
OutputPath: "transcripts/final.json", OutputSchema: "seriatim.transcript.v1", Report: boolPointer(true),
|
||||
|
||||
Reference in New Issue
Block a user