Adopt Audita native processing arguments
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user