Skip to content

Commit 7089cd1

Browse files
committed
[aiconformance]: better output of shell commands in markdown
1 parent e0c8974 commit 7089cd1

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

tests/e2e/scenarios/ai-conformance/validators/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (h *ValidatorHarness) ShellExec(shellCommand string) *CommandResult {
3030
var stderr bytes.Buffer
3131
cmd.Stderr = &stderr
3232

33-
h.Logf("ShellExec(%q)", shellCommand)
33+
h.output.BeforeShellExec(shellCommand)
3434
err := cmd.Run()
3535

3636
result := &CommandResult{
@@ -39,7 +39,7 @@ func (h *ValidatorHarness) ShellExec(shellCommand string) *CommandResult {
3939
err: err,
4040
}
4141

42-
h.output.OnShellExec(shellCommand, result)
42+
h.output.AfterShellExec(shellCommand, result)
4343

4444
if err != nil {
4545
h.Logf("Command failed: %q", shellCommand)

tests/e2e/scenarios/ai-conformance/validators/markdown.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ func (o *MarkdownOutput) renderHTML() error {
101101
return nil
102102
}
103103

104-
// OnShellExec writes the executed shell command and its output to the markdown file in a formatted code block.
105-
func (o *MarkdownOutput) OnShellExec(command string, results *CommandResult) {
104+
// BeforeShellExec writes the executed shell command to the markdown file in a formatted code block.
105+
func (o *MarkdownOutput) BeforeShellExec(command string) {
106106
o.printf("```bash\n> %s\n", command)
107+
o.printf("```\n")
108+
}
109+
110+
// AfterShellExec writes the result of the executed shell command to the markdown file in a formatted code block.
111+
func (o *MarkdownOutput) AfterShellExec(command string, results *CommandResult) {
112+
o.printf("```bash")
107113
o.printf("%s", results.Stdout())
108114
o.printf("%s", results.Stderr())
115+
o.printf("```\n")
109116

110117
if results.Err() != nil {
111118
o.printf("Error:\n```\n%v\n```\n", results.Err())
112119
}
113-
114-
o.printf("```\n")
115120
}
116121

117122
// printf is a helper method to write formatted text to the markdown file.

tests/e2e/scenarios/ai-conformance/validators/output.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ type OutputSink interface {
2727
// WriteText writes a text string to the output sink.
2828
WriteText(text string)
2929

30-
// OnShellExec is called when a shell command is executed, with the command, its stdout, stderr, and any error that occurred.
31-
OnShellExec(command string, results *CommandResult)
30+
// BeforeShellExec is called when a shell command is about to be executed, with the command string.
31+
BeforeShellExec(command string)
32+
// AfterShellExec is called when a shell command has been executed, with the command, its stdout, stderr, and any error that occurred.
33+
AfterShellExec(command string, results *CommandResult)
3234

3335
// Success indicates a successful check, allowing the output sink to format it accordingly.
3436
Success(text string)

0 commit comments

Comments
 (0)