Show stage labels as literal Markdown text

This commit is contained in:
2026-11-10 20:24:18 +00:00
parent bae96e5dd5
commit a0e45c8f92
3 changed files with 41 additions and 7 deletions

View File

@@ -33,11 +33,11 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
// 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 | grammar\\_1 | grammar\\_2 |",
"| --- | ---: | ---: |",
"| Chunk 1 (segments 1–2) | 1 | 0* |",
"| Chunk 2 (segments 3–4) | 0 | — |",
"| Chunk | grammar_1 | grammar_2 |",
"| Chunk | grammar\\_1 | grammar\\_2 |",
"| --- | ---: | ---: |",
"| Chunk 1 (segments 1–2) | 1 | 2* |",
"| Chunk 2 (segments 3–4) | 0 | — |",
@@ -93,11 +93,35 @@ func TestMarkdownNoWorkAndEscapedStageLabel(t *testing.T) {
t.Fatal(text)
}
text = string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}, WorkUnits: []WorkUnit{{StageIndex: 0, ChunkIndex: 0, State: "completed"}}}, "secret"))
if !strings.Contains(text, "bad\\|label\\`<br>[REDACTED]") {
if !strings.Contains(text, "bad\\|label\\`<br>\\[REDACTED\\]") {
t.Fatal(text)
}
}
func TestStageIDIsLiteralInMarkdownAndExactInYAML(t *testing.T) {
id := `[party](https://example.invalid/) *bold* _emphasis_ ~~strike~~ \| <tag>`
snapshot := Snapshot{
StageNames: []string{StageLabel(0, "grammar", &id), StageLabel(1, "grammar", nil)},
WorkUnits: []WorkUnit{{StageIndex: 0, ChunkIndex: 0, State: "completed", ErrorCount: 1}},
Errors: []ErrorRecord{{Scope: "work_unit", StageID: &id}},
}
header := `| Chunk | 1: grammar (\[party\](https&#58;//example.invalid/) \*bold\* \_emphasis\_ \~\~strike\~\~ &#92;\| &lt;tag&gt;) | 2: grammar |`
if rows := markdownTableRows(string(Markdown(snapshot))); len(rows) == 0 || rows[0] != header {
t.Fatalf("stage labels did not stay in their cells: %v", rows)
}
data, err := YAML(snapshot.ErrorsDocument())
if err != nil {
t.Fatal(err)
}
var decoded struct{ Errors []ErrorRecord }
if err := yaml.Unmarshal(data, &decoded); err != nil {
t.Fatal(err)
}
if len(decoded.Errors) != 1 || decoded.Errors[0].StageID == nil || *decoded.Errors[0].StageID != id {
t.Fatalf("stage ID changed in YAML: %s", data)
}
}
func markdownTableRows(text string) []string {
var rows []string
for _, line := range strings.Split(text, "\n") {