Add diagnostics references to reports

This commit is contained in:
2026-05-11 13:59:46 +00:00
parent 3e8d19cccd
commit 0e83991537
3 changed files with 98 additions and 3 deletions

View File

@@ -276,6 +276,21 @@ func TestRunProcessReportJSONSuccessIncludesNormalizationSummary(t *testing.T) {
if report.NormalizationMerges == nil || *report.NormalizationMerges != 1 {
t.Fatalf("expected 1 merge, got %v", report.NormalizationMerges)
}
if report.Diagnostics == nil {
t.Fatalf("expected diagnostics metadata in success report")
}
if report.Diagnostics.DirectoryPath == "" {
t.Fatalf("expected diagnostics directory path in success report")
}
if report.Diagnostics.SourceTranscriptPath == "" ||
report.Diagnostics.ParsedSourceTranscriptPath == "" ||
report.Diagnostics.NormalizedTranscriptPath == "" ||
report.Diagnostics.NormalizationSummaryPath == "" ||
report.Diagnostics.ChunkingSummaryPath == "" ||
report.Diagnostics.InvocationMetadataPath == "" ||
report.Diagnostics.RedactedEffectiveConfigPath == "" {
t.Fatalf("expected populated diagnostics artifact references in success report: %+v", report.Diagnostics)
}
}
func TestRunProcessReportJSONBestEffortOnFailure(t *testing.T) {
@@ -283,6 +298,7 @@ func TestRunProcessReportJSONBestEffortOnFailure(t *testing.T) {
var stderr bytes.Buffer
reportPath := filepath.Join(t.TempDir(), "report.json")
workDir := t.TempDir()
exitCode := Run([]string{
"process",
fixturePath("malformed_transcript.json"),
@@ -290,6 +306,10 @@ func TestRunProcessReportJSONBestEffortOnFailure(t *testing.T) {
fixturePath("tiny_glossary.yaml"),
"--report-json",
reportPath,
"--work-dir",
workDir,
"--work-dir-retention",
"always",
}, &stdout, &stderr)
if exitCode == 0 {
t.Fatalf("expected nonzero exit code")
@@ -308,6 +328,15 @@ func TestRunProcessReportJSONBestEffortOnFailure(t *testing.T) {
if !strings.Contains(report.ErrorMessage, "not valid JSON") {
t.Fatalf("expected parse error message, got %q", report.ErrorMessage)
}
if report.Diagnostics == nil {
t.Fatalf("expected diagnostics metadata in failed report")
}
if report.Diagnostics.DirectoryPath == "" || report.Diagnostics.ErrorLogPath == "" {
t.Fatalf("expected diagnostics directory and error log references in failed report: %+v", report.Diagnostics)
}
if _, err := os.Stat(report.Diagnostics.ErrorLogPath); err != nil {
t.Fatalf("expected error log file at reported path: %v", err)
}
}
func TestRunProcessReportJSONDoesNotLeakAPIKeys(t *testing.T) {
@@ -338,6 +367,42 @@ func TestRunProcessReportJSONDoesNotLeakAPIKeys(t *testing.T) {
}
}
func TestRunProcessReportJSONAndRunDirReportShareDiagnosticsMetadata(t *testing.T) {
var stdout bytes.Buffer
var stderr bytes.Buffer
workDir := t.TempDir()
reportPath := filepath.Join(t.TempDir(), "report.json")
exitCode := Run([]string{
"process",
fixturePath("tiny_transcript.json"),
"--glossary",
fixturePath("tiny_glossary.yaml"),
"--report-json",
reportPath,
"--work-dir",
workDir,
"--work-dir-retention",
"always",
}, &stdout, &stderr)
if exitCode != 0 {
t.Fatalf("expected exit code 0, got %d with stderr %q", exitCode, stderr.String())
}
externalReport := readProcessReport(t, reportPath)
runPath := onlyRunDir(t, workDir)
runDirReport := readProcessReport(t, filepath.Join(runPath, "report.json"))
if externalReport.Diagnostics == nil || runDirReport.Diagnostics == nil {
t.Fatalf("expected diagnostics metadata in both reports")
}
if *externalReport.Diagnostics != *runDirReport.Diagnostics {
t.Fatalf("expected same diagnostics metadata in --report-json and run-dir report\nexternal=%+v\nrun-dir=%+v",
*externalReport.Diagnostics, *runDirReport.Diagnostics)
}
}
func TestRunProcessWritesNormalizationDiagnosticsArtifacts(t *testing.T) {
var stdout bytes.Buffer
var stderr bytes.Buffer