Skip to content

chore(test): cleanup_all reaps orphan test-room gists from prior runs - #126

Merged
joelteply merged 1 commit into
canaryfrom
chore/test-orphan-gist-cleanup
Apr 26, 2026
Merged

joelteply merged 1 commit into
canaryfrom
chore/test-orphan-gist-cleanup

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Test-only reliability fix. Integration scenarios that timeout get pkill -9'd, bypassing airc's EXIT trap, leaking room gists. cleanup_all now walks 'gh gist list' and deletes anything matching the test-scope name prefixes (sars-test-, pks-test-, hb-test-, bounce-test-, debug-room, etc). Filtered to avoid real rooms.

🤖 Generated with Claude Code

Pre-fix: integration test scenarios that timed out were pkill -9'd by
the harness wrapper, bypassing airc's EXIT trap that normally deletes
hosted gists on graceful shutdown. Result: every CI/dev run leaks
'airc room: sars-test-NNNN' / 'pks-test-NNNN' / 'debug-room' /
'sidecar-test-NNNN' gists onto the user's gh account, piling into
'airc list' output and slowly filling gist quota. Found 5 orphans
on this account post-session.

Fix: cleanup_all gains a cleanup_test_gists step that walks
'gh gist list' and deletes anything matching the test-scope name
prefixes (sars-test-, pks-test-, hb-test-, bounce-test-, etc).

Filtered carefully — won't touch real rooms (#general, #useideem,
#cambriantech, anything else). The prefix regex is the source of
truth; keep in sync as new scenarios are added.

No-op when gh isn't authed or lacks gist scope (CI without gh, or
local runs with gh logged out). Silent failure on individual deletes
(they may already be gone). The cleanup runs at every cleanup_all
boundary — start of each scenario AND end — so leaked gists get
swept the same run they were created.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 26, 2026 18:11
@joelteply
joelteply merged commit 7d70179 into canary Apr 26, 2026
@joelteply
joelteply deleted the chore/test-orphan-gist-cleanup branch April 26, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves integration-test hygiene by cleaning up orphaned GitHub gists created by prior test runs that were terminated before EXIT traps could delete their “room” gists.

Changes:

  • Adds cleanup_test_gists() to find and delete test-scoped “airc room:” gists via gh gist list + description-prefix filtering.
  • Extends cleanup_all() to call cleanup_test_gists alongside existing process/dir/known_hosts cleanup.

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

Comment thread test/integration.sh
Comment on lines +117 to +118
# left alone (real rooms or someone else's tests).
local _test_prefix_re='airc room: (sars-test-|pks-test-|pks-debug|debug-room|sidecar-test-|solo-test-|ronly-test-|new-room|myproject|hb-test-|bounce-test-|ttl-test-|test-irc-|useideem-test-|stalepid-)'

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

The prefix allowlist regex includes very generic room names (new-room, myproject) that are not clearly test-scoped. If a developer’s real account has an airc room: myproject (or airc room: new-room) gist, this cleanup will delete it. Consider removing these generic entries or tightening the match (e.g., require a *-test-/PID suffix and/or anchor the regex to exact expected test descriptions).

Suggested change
# left alone (real rooms or someone else's tests).
local _test_prefix_re='airc room: (sars-test-|pks-test-|pks-debug|debug-room|sidecar-test-|solo-test-|ronly-test-|new-room|myproject|hb-test-|bounce-test-|ttl-test-|test-irc-|useideem-test-|stalepid-)'
# left alone (real rooms or someone else's tests). Keep matches
# narrowly test-scoped: do not include generic room names such as
# "new-room" or "myproject", which may belong to a real account.
local _test_prefix_re='^airc room: (sars-test-|pks-test-|pks-debug|debug-room|sidecar-test-|solo-test-|ronly-test-|hb-test-|bounce-test-|ttl-test-|test-irc-|useideem-test-|stalepid-)'

Copilot uses AI. Check for mistakes.
Comment thread test/integration.sh
Comment on lines +111 to +114
cleanup_test_gists() {
command -v gh >/dev/null 2>&1 || return 0
gh auth status >/dev/null 2>&1 || return 0
gh auth status 2>&1 | grep -qiE '(scopes|token scopes):.*\bgist\b' || return 0

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

cleanup_all is invoked many times throughout this script; adding gh auth status + gh gist list on every cleanup can add noticeable latency and may trigger GitHub API throttling for authed developers. Consider guarding cleanup_test_gists so it runs at most once per script invocation (or only in the top-level EXIT trap / initial pre-run cleanup).

Copilot uses AI. Check for mistakes.
Comment thread test/integration.sh
# left alone (real rooms or someone else's tests).
local _test_prefix_re='airc room: (sars-test-|pks-test-|pks-debug|debug-room|sidecar-test-|solo-test-|ronly-test-|new-room|myproject|hb-test-|bounce-test-|ttl-test-|test-irc-|useideem-test-|stalepid-)'
local _ids
_ids=$(gh gist list --limit 50 2>/dev/null | awk -F'\t' -v re="$_test_prefix_re" '$2 ~ re { print $1 }')

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

gh gist list --limit 50 can miss older orphaned test gists when the account has >50 gists total (or >50 orphans), so the cleanup may never reach them. Consider paginating until no matches remain or using a sufficiently high limit to reliably reap all test-scoped gists.

Suggested change
_ids=$(gh gist list --limit 50 2>/dev/null | awk -F'\t' -v re="$_test_prefix_re" '$2 ~ re { print $1 }')
_ids=$(
gh api --paginate /gists 2>/dev/null \
| jq -r '.[] | [.id, (.description // "")] | @tsv' \
| awk -F'\t' -v re="$_test_prefix_re" '$2 ~ re { print $1 }'
)

Copilot uses AI. Check for mistakes.
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.

2 participants