Skip to content

Commit 709f0a0

Browse files
committed
Test: Split long failure diagnostics without truncation
Renames and updates the DiscordReportFormatter test to validate splitting of large failure diagnostics instead of step results. The test now builds a small report with a failed step and a 2500-character diagnostic payload, invokes the formatter, collects messages containing the "Failure Diagnostics" field, and asserts that diagnostics are split across multiple messages, that all 2500 'z' characters are preserved, that the relevant step label (Step 3) appears, and that no truncation marker is present. Replaces previous assertions which targeted "Step Results".
1 parent 0bf950b commit 709f0a0

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/Validator.Core.Tests/Reporter/DiscordReportFormatterTests.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,42 @@ namespace Validator.Core.Tests.Reporter;
1111
public class DiscordReportFormatterTests
1212
{
1313
[Fact]
14-
public void FormatMessages_ShouldSplitLongStepResults_WithoutTruncationMarker()
14+
public void FormatMessages_ShouldSplitLongFailureDiagnostics_WithoutTruncationMarker()
1515
{
16-
var report = CreateReport(140);
17-
var formatter = new DiscordReportFormatter();
16+
var report = CreateReport(3);
17+
report.Result.Status = ValidationStatus.Failed;
18+
report.Result.PassedSteps = 2;
19+
report.Result.FailedSteps = 1;
20+
report.Result.FailedAtStepId = 3;
21+
report.Result.StepResults[2].Status = StepExecutionStatus.Failed;
22+
report.Result.StepResults[2].ErrorMessage = "error";
23+
report.FailureDiagnostics =
24+
[
25+
new FailureDiagnostic
26+
{
27+
StepId = 3,
28+
Classification = FailureClassification.Unknown,
29+
Explanation = new string('z', 2500)
30+
}
31+
];
1832

33+
var formatter = new DiscordReportFormatter();
1934
var messages = formatter.FormatMessages(report);
20-
var stepMessages = messages
21-
.Where(m => m.Embeds.Count > 0 && m.Embeds[0].Fields.Any(f => f.Name == "Step Results"))
35+
var diagnosticsMessages = messages
36+
.Where(m => m.Embeds.Count > 0 && m.Embeds[0].Fields.Any(f => f.Name == "Failure Diagnostics"))
2237
.ToList();
2338

24-
Assert.True(stepMessages.Count > 1);
39+
Assert.True(diagnosticsMessages.Count > 1);
40+
41+
var fieldValues = diagnosticsMessages
42+
.Select(m => m.Embeds[0].Fields.First(f => f.Name == "Failure Diagnostics").Value)
43+
.ToList();
2544

26-
var allStepText = string.Join(
27-
'\n',
28-
stepMessages.Select(m => m.Embeds[0].Fields.First(f => f.Name == "Step Results").Value));
45+
var allDiagnosticsText = string.Join('\n', fieldValues);
2946

30-
Assert.Contains("Step 1", allStepText);
31-
Assert.Contains("Step 140", allStepText);
32-
Assert.DoesNotContain("… (truncated)", allStepText);
47+
Assert.Contains("Step 3", allDiagnosticsText);
48+
Assert.Equal(2500, fieldValues.Sum(v => v.Count(c => c == 'z')));
49+
Assert.DoesNotContain("… (truncated)", allDiagnosticsText);
3350
}
3451

3552
[Fact]

0 commit comments

Comments
 (0)