Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: add --report-file flag to gh-aw logs to avoid shell redirect failure #40425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
fix: add --report-file flag to gh-aw logs to avoid shell redirect failure #40425
Changes from all commits
c03bf95f23c6ea6e209947832c590b4c547File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose]
--report-fileis silently ignored when--formatis notmarkdown. A user runninggh aw logs --report-file out.md(without--format markdown) will get no file and no error — confusing.💡 Add a validation guard early in RunE
Add a check in
RunE(or aPreRunE) before callingDownloadWorkflowLogs:The flag description could also be made more explicit:
"Write Markdown report to this file (requires --format markdown); creates parent directories"to set expectations at--help.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] No test covers the new
--report-filecode path. Without a regression test, the silentos.Stdoutswap and theMkdirAll+os.Createlogic can break undetected.💡 Sketch of a unit test
This would have caught the goroutine-safety issue during code review if the test were run with
-race, and confirms that parent-directory creation works on first use (cold-cache scenario).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose]
os.Stdoutis a global process variable — swapping it is not goroutine-safe. Any concurrent goroutine (logger, progress reporter, or parallel test) writing toos.Stdoutduring this window will write to the file instead of the terminal.💡 Suggested fix: pass an `io.Writer` instead of swapping the global
Refactor
renderCrossRunReportMarkdown(and everyrenderMarkdown*helper inaudit_cross_run_render.go) to accept anio.Writer:Then the call-site simplifies to:
This removes the IIFE entirely, is safe under concurrency, and makes unit tests trivial (pass a
bytes.Buffer). The existing tests inaudit_cross_run_test.goalready useos.Pipe()to capture stdout — those would simplify too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.Stdout = fis a process-global mutation and is not goroutine-safe. Any concurrent goroutine that writes toos.StdoutduringrenderCrossRunReportMarkdownwill redirect its output into the report file, silently corrupting it — or lose output if the file is already closed.💡 Suggested fix
Thread
io.WriterthroughrenderCrossRunReportMarkdownand its six sub-functions instead of swapping the global:Then update
renderCrossRunReportMarkdownand all its helpers (renderMarkdownExecutiveSummary,renderMarkdownMetricsTrend, etc.) to accept and forward anio.Writer.This eliminates the goroutine-safety risk and also fixes the silently-dropped write errors:
fmt.Fprintf(f, ...)returns errors that the current design discards becauserenderCrossRunReportMarkdownhas no error return — threadingio.Writermakes it straightforward to add one or to use abufio.Writer+ flush check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corresponding test only asserts the path string appears in the YAML, so it cannot distinguish
--report-file pathfrom the old> pathredirect. A regression that restores the shell redirect would pass undetected.💡 Suggested fix
Add an explicit assertion for the flag in
pkg/workflow/maintenance_workflow_test.go(and its counterpart inside_repo_maintenance_integration_test.go):The path-only check (
strings.Contains(yaml, "report.md")) will always pass regardless of how the path is used in the command.Uh oh!
There was an error while loading. Please reload this page.