Skip to content

Render pre-agent workspace audit as a step summary table - #50103

Merged
pelikhan merged 2 commits into
mainfrom
copilot/update-audit-script-table
Aug 3, 2026
Merged

pelikhan merged 2 commits into
mainfrom
copilot/update-audit-script-table

Conversation

Copilot AI commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

The pre-agent audit script wrote its file listing to /tmp/gh-aw/pre-agent-audit.txt and a GITHUB_OUTPUT value only, so the audited files were invisible in the run's step summary. This adds a collapsible table rendering, matching the progressive disclosure style used by other summary sections (e.g. log_runtime_features_summary.sh).

Changes

  • actions/setup/sh/audit_pre_agent_workspace.sh: parses the audit file into a | Section | Path | Size | table — section markers (--- label: dir ---) become the Section column, (not found) and blank lines are skipped, and sizes are reported for regular files (dir for directories).
  • Table is wrapped in <details> with a row-count label, appended to $GITHUB_STEP_SUMMARY; falls back to /dev/null when unset, so local/non-Actions invocations are unaffected.
  • audit_pre_agent_workspace_test.sh: covers heading, <details> wrapping, table header, row content, suppression of raw section markers, and the unset-GITHUB_STEP_SUMMARY path.

Example output:

### Pre-agent workspace audit

<details>
<summary>Show 3 audited entries</summary>

| Section | Path | Size |
| --- | --- | --- |
| Workspace agents | `/ws/.github/agents` | dir |
| Workspace agents | `/ws/.github/agents/a.md` | 3 |
| gh-aw temp directory | `/tmp/gh-aw` | dir |

</details>

No compiler or workflow changes were needed — the step already delegates entirely to this script.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

pelikhan commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

@copilot the title should be in the summary. See other templates

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the title should be in the summary. See other templates

Moved the title into the <summary> line (<summary>Pre-agent workspace audit (N entries)</summary>) and dropped the separate ### heading, matching print_prompt_summary.sh and the other templates. 69b2e33

@pelikhan
pelikhan marked this pull request as ready for review August 3, 2026 22:12
Copilot AI review requested due to automatic review settings August 3, 2026 22:12
@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has 0 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. The changes are shell script updates (audit_pre_agent_workspace.sh and audit_pre_agent_workspace_test.sh). Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a collapsible pre-agent workspace audit table to GitHub Actions step summaries.

Changes:

  • Renders audited paths, sections, and sizes as a Markdown table.
  • Adds summary rendering and unset-variable tests.
Show a summary per file
File Description
actions/setup/sh/audit_pre_agent_workspace.sh Generates and appends the audit summary table.
actions/setup/sh/audit_pre_agent_workspace_test.sh Tests summary output and optional summary handling.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Balanced

rows+="| ${section} | \`${line}\` | ${size} |"$'\n'
count=$((count + 1))
done < "${AUDIT_FILE}"
echo "<details>"
elif [ -d "${line}" ]; then
size="dir"
fi
rows+="| ${section} | \`${line}\` | ${size} |"$'\n'
# HOME - agent user home directory
# RUNNER_TEMP - runner temporary directory
# GITHUB_OUTPUT - path to the GitHub Actions output file
# GITHUB_STEP_SUMMARY- path to the GitHub Actions step summary file (optional)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Render pre-agent workspace audit as a step summary table

The implementation is clean, well-structured, and the tests are thorough. One minor test-isolation issue flagged inline — otherwise no blocking concerns.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 24.2 AIC · ⌖ 18.1 AIC · ⊞ 5.4K

if GITHUB_WORKSPACE="${TEST_ROOT}/workspace-8" HOME="${TEST_ROOT}/home9" RUNNER_TEMP="${TMPDIR}" GITHUB_OUTPUT="${GH_OUT9}" bash "${SCRIPT_PATH}" >/dev/null 2>&1; then
assert "Script succeeds without GITHUB_STEP_SUMMARY" "true"
else
assert "Script succeeds without GITHUB_STEP_SUMMARY" "false"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test 9 reuses workspace-8 created by Test 8, creating an implicit ordering dependency. If Test 8 were removed or failed before creating that directory, Test 9 would fail unexpectedly. Consider creating a dedicated workspace-9 directory in Test 9 for full isolation.

@copilot please address this.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Request changes

The table-rendering feature is a reasonable addition, but render_summary_table has an unguarded wc -c call inside a set -euo pipefail context that will abort the script (and skip the required GITHUB_OUTPUT writes) if it encounters an unreadable file during the walk.

Themes
  • Blocking: size="$(wc -c < "${line}" 2>/dev/null | tr -d ' ')" can propagate a non-zero exit status under set -e even with stderr suppressed, verified locally with a chmod 000 file — this crashes before pre-agent-audit-file/pre-agent-audit-line-count outputs are written, silently breaking downstream steps that read them.
  • No test covers the permission-denied / race-condition path, so this regression wouldn't be caught by the new test suite.
  • Everything else (details/summary wrapping, section parsing, GITHUB_STEP_SUMMARY fallback to /dev/null) is implemented cleanly and matches the stated style.

🔎 Code quality review by PR Code Quality Reviewer · auto · 36.3 AIC · ⌖ 4.51 AIC · ⊞ 7.9K
Comment /review to run again

esac
local size="-"
if [ -f "${line}" ]; then
size="$(wc -c < "${line}" 2>/dev/null | tr -d ' ')"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under set -euo pipefail, a permission-denied or race-condition file read here will abort the whole script mid-loop, silently skipping the required GITHUB_OUTPUT writes on lines 143-144 that downstream steps depend on.

💡 Details and fix

find (line ~65) can list files owned by another user, mode 000, or deleted between the find scan and this read (race). Because size="$(wc -c < "${line}" 2>/dev/null | tr -d ' ')" is a command substitution assigned to a variable, bash's set -e treats a failure in the substitution's pipeline as fatal even though stderr is redirected to /dev/null — the 2>/dev/null only suppresses the error message, not the non-zero exit status of wc. I verified this locally: a chmod 000 file inside a scanned directory causes the script to exit with status 1 partway through render_summary_table, before pre-agent-audit-file / pre-agent-audit-line-count are ever written to GITHUB_OUTPUT. Since the workflow step uses continue-on-error, the job won't fail loudly, but any downstream step reading those outputs will silently get empty/undefined values.

Fix by not letting the substitution's exit status propagate:

if [ -f "${line}" ]; then
  size="$(wc -c < "${line}" 2>/dev/null | tr -d ' ')" || size="?"
elif [ -d "${line}" ]; then
  size="dir"
fi

or wrap the whole render_summary_table call with || true so a rendering failure never blocks the critical GITHUB_OUTPUT writes that follow it.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /tdd and /grill-with-docs — requesting changes on a missing heading and undertested assertions.

📋 Key Themes & Highlights

Issues

  • Missing ### heading: The PR description example shows a ### Pre-agent workspace audit heading above <details>, but the implementation emits <details> as its very first line. Without it the table is invisible in a busy step summary (matching the pattern used by log_runtime_features_summary.sh).
  • Undertested assertions: Test 8 checks that agent.md appears in the summary but doesn't verify the Section column value, the numeric size, or the row count in the <summary> tag — easy regressions to miss.
  • Undocumented symlink behaviour: Paths that are neither files nor directories (symlinks, disappeared paths) produce a silent | section | /path | - | row; a comment or test would document the intentional behaviour.

Positive Highlights

  • ✅ Clean progressive-disclosure structure (<details>/<summary>) matching the project's existing style
  • ✅ Graceful /dev/null fallback for non-Actions environments
  • ✅ Good test structure — two focused tests covering the happy path and the unset-env-var edge case
  • ✅ Section-marker parsing is correct and the %%:* extraction idiom is idiomatic Bash

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 52 AIC · ⌖ 9.85 AIC · ⊞ 7.1K
Comment /matt to run again

rows+="| ${section} | \`${line}\` | ${size} |"$'\n'
count=$((count + 1))
done < "${AUDIT_FILE}"
echo "<details>"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/grill-with-docs] The function emits <details> as its first output line, but the PR description example shows a ### Pre-agent workspace audit heading above it — matching the pattern used by log_runtime_features_summary.sh. Without the heading the table is unfindable in a busy step summary.

💡 Suggested fix
render_summary_table() {
  echo "### Pre-agent workspace audit"
  echo
  echo "<details>"
  ...

The test assertion on <summary>Pre-agent workspace audit is then also underconstrained — add a separate assertion for the heading.

@copilot please address this.

section="${section%%:*}"
continue
;;
"--- "*" ---") continue ;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The size field falls back to "-" for paths that are neither files nor directories (e.g., symlinks, sockets, or paths that disappear between write and read). This produces a silent, misleading | section | /path | - | row. A test covering a symlink entry — or at minimum a comment noting the limitation — would make the intent explicit.

@copilot please address this.

assert "Summary closes details tag" "grep -q '</details>' '${SUMMARY8}'"
assert "Summary has table header" "grep -q '| Section | Path | Size |' '${SUMMARY8}'"
assert "Summary lists agent.md row" "grep -q 'agent.md' '${SUMMARY8}'"
assert "Summary omits section marker lines" "! grep -q -- '--- Workspace agents' '${SUMMARY8}'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] Test 8 only asserts that agent.md appears in the summary, not that it has the correct Section column value (Workspace agents) or a numeric size. Without those assertions a future change that corrupts section parsing or the size column would pass this test undetected.

💡 Stronger assertions
assert "Summary row has correct section" "grep -q '| Workspace agents |' '${SUMMARY8}'"
assert "Summary row has numeric size" "grep -qE 'agent\.md.*\| [0-9]+' '${SUMMARY8}'"

@copilot please address this.

printf '%s' "${rows}"
echo
echo "</details>"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The row-count label in <summary> (e.g., "Pre-agent workspace audit (3 entries)") is never tested — Test 8 only checks for the prefix. If the count is zero or wrong no test will catch it.

💡 Add count assertion
assert "Summary entry count is correct" "grep -q 'Pre-agent workspace audit (2 entries)' '${SUMMARY8}'"

(adjust the expected count to match the test fixture)

@copilot please address this.

@pelikhan

pelikhan commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@pelikhan
pelikhan merged commit f1d36ff into main Aug 3, 2026
84 of 88 checks passed
@pelikhan
pelikhan deleted the copilot/update-audit-script-table branch August 3, 2026 22:25
Copilot stopped work on behalf of pelikhan due to an error August 3, 2026 22:25
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants