Remove unnecessary output restrictions and simplify report tests
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package reporting
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -30,25 +29,46 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
|
||||
Recoveries: []RecoveryRecord{{Reasons: []string{"output_repaired", "proposals_filtered"}}, {Reasons: []string{"output_repaired"}}, {Reasons: []string{"service_recovered"}}},
|
||||
}
|
||||
got := Markdown(snapshot, "secret")
|
||||
fixture := filepath.Join("testdata", "report.md")
|
||||
if os.Getenv("UPDATE_REPORT_GOLDEN") == "1" {
|
||||
if err := os.WriteFile(fixture, got, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
want, err := os.ReadFile(fixture)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Fatalf("Markdown differs from %s:\n%s", fixture, got)
|
||||
}
|
||||
text := string(got)
|
||||
for _, fragment := range []string{"| grammar_1 | grammar_2 |", "| Chunk 1 (segments 1–2) | 1 | 0* |", "| Chunk 1 (segments 1–2) | 1 | 2* |", "| Chunk 2 (segments 3–4) | 0 | — |", "in\\|put.json", "out<br>file.json", "glossary\\`[REDACTED]\\`.yaml", "- `transport_failed`: 1", "- `output_repaired`: 2"} {
|
||||
// Compare only complete table rows, preserving order and states while leaving
|
||||
// prose and spacing outside the fixed matrices free to change.
|
||||
wantRows := []string{
|
||||
"| Chunk | grammar_1 | grammar_2 |",
|
||||
"| --- | ---: | ---: |",
|
||||
"| Chunk 1 (segments 1–2) | 1 | 0* |",
|
||||
"| Chunk 2 (segments 3–4) | 0 | — |",
|
||||
"| Chunk | grammar_1 | grammar_2 |",
|
||||
"| --- | ---: | ---: |",
|
||||
"| Chunk 1 (segments 1–2) | 1 | 2* |",
|
||||
"| Chunk 2 (segments 3–4) | 0 | — |",
|
||||
}
|
||||
if rows := markdownTableRows(text); !reflect.DeepEqual(rows, wantRows) {
|
||||
t.Fatalf("matrices: got %v; want %v", rows, wantRows)
|
||||
}
|
||||
for _, fragment := range []string{"in\\|put.json", "out<br>file.json", "glossary\\`[REDACTED]\\`.yaml", "`transport_failed`: 1", "`output_repaired`: 2", "`proposals_filtered`: 1", "`service_recovered`: 1"} {
|
||||
if !strings.Contains(text, fragment) {
|
||||
t.Fatalf("missing %q in:\n%s", fragment, text)
|
||||
}
|
||||
}
|
||||
|
||||
// Assert summary quantities independently of the surrounding explanation.
|
||||
numbers := regexp.MustCompile(`[0-9]+`)
|
||||
for label, want := range map[string][]string{
|
||||
"Corrections applied": {"1"},
|
||||
"Errors": {"1", "0"},
|
||||
"Recoveries": {"3", "4"},
|
||||
} {
|
||||
var got []string
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
if value, ok := strings.CutPrefix(strings.TrimSpace(line), label+":"); ok {
|
||||
got = numbers.FindAllString(value, -1)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("%s summary: got %v; want %v", label, got, want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(text, "secret") {
|
||||
t.Fatal("secret leaked")
|
||||
}
|
||||
@@ -69,7 +89,7 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
|
||||
|
||||
func TestMarkdownNoWorkAndEscapedStageLabel(t *testing.T) {
|
||||
text := string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}}, "secret"))
|
||||
if strings.Count(text, "No work units.") != 2 || strings.Contains(text, "secret") {
|
||||
if len(markdownTableRows(text)) != 0 || strings.Contains(text, "secret") {
|
||||
t.Fatal(text)
|
||||
}
|
||||
text = string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}, WorkUnits: []WorkUnit{{StageIndex: 0, ChunkIndex: 0, State: "completed"}}}, "secret"))
|
||||
@@ -77,3 +97,13 @@ func TestMarkdownNoWorkAndEscapedStageLabel(t *testing.T) {
|
||||
t.Fatal(text)
|
||||
}
|
||||
}
|
||||
|
||||
func markdownTableRows(text string) []string {
|
||||
var rows []string
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
if line = strings.TrimSpace(line); strings.HasPrefix(line, "|") {
|
||||
rows = append(rows, line)
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
43
internal/core/reporting/testdata/report.md
vendored
43
internal/core/reporting/testdata/report.md
vendored
@@ -1,43 +0,0 @@
|
||||
# Audita report: run-123
|
||||
|
||||
Status: completed
|
||||
|
||||
Corrections applied: 1
|
||||
Work units: 4 total; 2 completed; 1 interrupted; 1 not started
|
||||
Errors: 1 work units; 0 run errors
|
||||
Recoveries: 3 of 4 model operations
|
||||
Proposal responses: 1; with filtering: 1
|
||||
|
||||
Transcript input: in\|put.json
|
||||
Glossary input: glossary\`[REDACTED]\`.yaml
|
||||
Transcript output: out<br>file.json
|
||||
|
||||
## Work-unit errors
|
||||
|
||||
| Chunk | grammar_1 | grammar_2 |
|
||||
| --- | ---: | ---: |
|
||||
| Chunk 1 (segments 1–2) | 1 | 0* |
|
||||
| Chunk 2 (segments 3–4) | 0 | — |
|
||||
|
||||
## Recoveries
|
||||
|
||||
| Chunk | grammar_1 | grammar_2 |
|
||||
| --- | ---: | ---: |
|
||||
| Chunk 1 (segments 1–2) | 1 | 2* |
|
||||
| Chunk 2 (segments 3–4) | 0 | — |
|
||||
|
||||
Legend: `—` = not started; `n*` = interrupted with n recorded errors or recoveries. Completed error cells are 0 or 1.
|
||||
|
||||
### Error reasons
|
||||
|
||||
- `transport_failed`: 1
|
||||
|
||||
### Recovery reasons
|
||||
|
||||
- `output_repaired`: 2
|
||||
- `proposals_filtered`: 1
|
||||
- `service_recovered`: 1
|
||||
|
||||
A recovery can have multiple reasons; reason counts need not sum to the recovery total.
|
||||
|
||||
Details: `errors.yml` and `recoveries.yml`.
|
||||
Reference in New Issue
Block a user