Skip to content

Keep workspace preview scripts in sync with the scaffold - #160

Open
gas2own wants to merge 9 commits into
mainfrom
workspace-sync-preview-scripts
Open

gas2own wants to merge 9 commits into
mainfrom
workspace-sync-preview-scripts

Conversation

@gas2own

@gas2own gas2own commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Bring the workspace skill's copied preview scripts in line with fixes already exercised in a workspace project. The Quarto check detects ANSI-colored warnings. The preview waiter checks the real default branch, requires an open PR whose head matches the pushed commit, verifies it remains open at that commit when Pages finishes, handles Pages API errors, and recognizes a successful Pages build at or after the preview commit among the latest 100 builds.

Validation: 24 focused preview and warning checks passed locally; shell syntax, Ruff format, Ruff lint, and diff checks passed. Independent review findings and their resolutions are recorded in PR comments. All PR checks pass on the current head. The automatic review chain is at its limit; human review is the next gate.

Reviewer requested: jbragg

Suggested-by: @jbragg

@gas2own

gas2own commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Automated review status

  • claude review of ddd02ed (job gas2own-98cd63ab34a5) — findings posted
  • codex review of 0ead726 (job gas2own-20be15da39d8) — findings posted
  • claude review of 725611d (job gas2own-5d30124c1b4b) — findings posted

Now: automated cycle open — it closes once two different reviewer backends have posted a whole-PR review of the same head (1958c0a).

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Independent AI code review (Claude)

Automated review of the PR by a separately invoked Claude reviewer. Prioritised P0/P1/P2; treat as advisory input for the human reviewer, not a merge gate.

P0 (blocking)

None.

P1 (should fix)

  • wait-for-preview.sh:85: On a detached HEAD, branch is empty, so "$branch" != main is true. gh pr view with no argument then fails, and the script exits with "No PR for yet". Before this change, an empty branch was tolerated, because the code below only adds --branch when it is non-empty. This new check now blocks that path. Fix: guard with [ -n "$branch" ] && [ "$branch" != main ] && ..., and add a detached-HEAD test.
  • wait-for-preview.sh:85: main is hardcoded as the branch that needs no PR. Repos whose default branch is master or trunk will be wrongly blocked. Fix: compare against gh repo view --json defaultBranchRef --jq .defaultBranchRef.name, which REPO resolution already calls gh repo view for.
  • wait-for-preview.sh:85: 2>&1 sends all gh pr view errors to /dev/null, including auth, network and rate-limit failures. These are then reported as "No PR … open a PR first", which is misleading. Fix: capture stderr and print it on failure, or reword the message to "Could not find a PR for $branch (is one open? is gh authenticated?)".

P2 (nits)

  • wait-for-preview.sh:85: gh pr view also resolves closed or merged PRs for the branch, so it can pass when no preview will run. Consider --json state --jq .state and require OPEN.
  • wait-for-preview.sh:85: --jq .number is pointless when the output is discarded. Drop it, or use the state check above.
  • wait-for-preview.sh:132-133: The same error message is duplicated on two consecutive lines. Combine them: after=$(pages_tip) && [ -n "$after" ] || { ...; }.
  • wait-for-preview.sh:180: per_page=100 only widens the window; it is still not paginated. On busy repos, a build older than the latest 100 is missed until PAGES_TIMEOUT. Acceptable, but worth a comment.
  • tests/test_workspace_workflow.py: There is no test that the main branch skips the PR check. Add one, plus the detached-HEAD case noted above.

Recommendation: approve-with-nits

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the independent review in commit 5af7615:

  • Detached HEAD: the PR lookup now runs only when a branch name exists. A detached-head test verifies the wait still succeeds.
  • Default branch: the script reads the repository's actual default branch, so main, master, or trunk can skip PR lookup. A trunk test verifies this.
  • Lookup errors and closed PRs: gh errors remain visible, the script gives a failure message, and it requires an OPEN PR. A closed-PR test covers the state check.
  • Other nits: removed the unused number query, combined the duplicate Pages error path, and documented the 100-build API window.

Validation: 17 focused checks passed; shell syntax, Ruff format, Ruff lint, and git diff --check passed. Full CI is rerunning on the fix.

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Added one more preview-readiness guard in commit 0ead726: if a PR closes while Pages is building, wait-for-preview.sh now checks that the PR is still open before it reports a live preview. This matches the template's current behavior and keeps the shared asset from drifting again. A focused test closes the mock PR between the initial lookup and the Pages result. All 18 focused checks, Ruff, shell syntax, and diff checks pass; full CI is rerunning.

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Independent AI code review (Codex)

Automated review of the PR by a separately invoked Codex reviewer. Prioritised P0/P1/P2; treat as advisory input for the human reviewer, not a merge gate.

P0 (blocking)

None.

P1 (should fix)

  • plugins/asta-tools/skills/workspace/assets/wait-for-preview.sh:94 — Checking only state lets an open PR for the same branch pass after its head has moved away from $sha. Fetch headRefOid and require it to equal the commit whose preview was published.
  • plugins/asta-tools/skills/workspace/assets/wait-for-preview.sh:94 — GitHub CLI interprets a numeric selector as a PR number. A branch named 123 can therefore check unrelated PR Theorizer plugin output lags web: dense theory statements + prose-only novelty #123. Resolve the PR by head branch, then check its identity.
  • plugins/asta-tools/skills/workspace/assets/wait-for-preview.sh:94 — A bare branch selector matches a same-repository PR head, so a valid PR from a fork is rejected. Resolve the head repository and use a qualified head ref or PR URL.

P2 (nits)

None.

Recommendation: request-changes

@gas2own

gas2own commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Resolved the second independent review in commit 14bccda:

  • The preview waiter now checks both OPEN state and the PR head SHA against the commit whose workflow run it found, including a second check just before reporting Pages ready. A test moves the PR head during deployment.
  • It lets gh pr view resolve the current branch without a positional selector, avoiding numeric branch names being parsed as PR numbers. A numeric-branch test checks the invocation.
  • The same no-selector lookup avoids the same-repo-only branch resolution that rejected fork heads. The gh query shape was verified against a live branch; the focused tests cover the branch and SHA behavior.

Validation: 20 focused checks passed; shell syntax, Ruff format, Ruff lint, and diff checks passed. Full CI is rerunning.

@gas2own
gas2own requested a review from jbragg October 3, 2026 00:27
@gas2own
gas2own marked this pull request as ready for review October 3, 2026 00:27
@gas2own
gas2own marked this pull request as draft October 3, 2026 00:28
@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up to the latest independent review: commit 725611d completes all three findings.

  • Moved PR head: the initial lookup requires an open PR whose headRefOid equals the commit being previewed. Immediately before reporting Pages ready, the script checks the same PR number for both OPEN state and that SHA. Tests cover a stale head at lookup and a head that moves during deployment.
  • Numeric branch: gh pr list --head searches by branch name; gh pr view receives only the returned PR number. The numeric-branch test covers this.
  • Fork branch: the base repository is passed explicitly to both lookups. I verified that gh pr list --head finds a live fork PR, while no-selector gh pr view from that fork's checkout reports no PR. A regression test requires the explicit PR number for the fork case.

The earlier 14bccda resolution correctly checked state and SHA, but its no-selector lookup still missed the verified fork case; 725611d replaces it. Validation: 19 focused preview tests, Ruff format and lint, shell syntax, and diff checks pass. The five unrelated tests in the file that call make cannot run in this dispatcher image because make is absent; PR CI is running them.

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

The overlapping PR 161 is closed as superseded. Its closed-PR guard is covered here, along with the current-head and default-branch checks.

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Independent AI code review (Claude)

Automated review of the PR by a separately invoked Claude reviewer. Prioritised P0/P1/P2; treat as advisory input for the human reviewer, not a merge gate.

P0 (blocking)

None.

P1 (should fix)

  • wait-for-preview.sh:85-106: The PR lookup is a one-shot check that runs before the run-polling loop. The usual flow is git push && gh pr create && wait-for-preview.sh wait. In that flow, GitHub's eventual consistency, or a PR opened a few seconds late, makes wait fail immediately with "No open PR", even though the polling loop below would have tolerated the delay. Fix: retry the gh pr list lookup inside the same POLL/timeout budget, or resolve the PR lazily at the end next to the pr view check. Fail only when the timeout expires.
  • wait-for-preview.sh:92-94: gh pr list --head "$branch" matches on branch name only, not owner. A fork PR and a base-repo PR can share a branch name and the same headRefOid, for example a fork that mirrors the commit. In that case [0] picks one arbitrarily, and the later pr view validates the wrong PR. Fix: also select on headRepositoryOwner.login or isCrossRepository, matching the remote the user pushed to. Alternatively, fail when more than one PR matches.

P2 (nits)

  • tests/test_workspace_workflow.py (test_preview_wait_resolves_fork_pr_via_base_repo): The fake GH_FORK_PR only asserts pr view receives 123, which the non-fork path already covers. This test does not exercise any fork-specific behavior. Fix: make the fake pr list return a cross-repo entry and assert it is selected or rejected. Otherwise drop the test.
  • tests/test_workspace_workflow.py fake pr list: The fake never checks that --state open was passed. It emulates closed PRs by returning [], so dropping --state open from the script would go unnoticed. Fix: make the fake return closed entries unless --state open is present.
  • wait-for-preview.sh:85-107: check_pr=0 is assigned in three places. Fix: initialize it once before the if and remove the else branch.
  • wait-for-preview.sh:216: The "(now: $pr_head)" message prints a raw STATE sha pair. Fix: format it as state=…, head=… for clarity.
  • quarto-check.sh:28: The ANSI strip handles only SGR sequences (…m). Other CSI sequences, such as cursor or erase codes, would survive and could break the ^WARN: anchor. Fix: use s/${esc}\[[0-9;]*[A-Za-z]//g.

Recommendation: approve-with-nits

@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the latest independent review in commit 1958c0a:

  • PR creation lag: wait now polls for the matching open PR within its existing workflow timeout. A test has the PR appear after the first lookup.
  • Branch-name ambiguity: the lookup rejects multiple open PRs with the same branch name and head commit instead of selecting the first. A test covers that case.
  • Fork fixture: the mock now includes a same-repo PR at another commit and a fork PR at the target commit; the test checks the fork PR number is used.
  • Open-state fixture: the mock only filters closed PRs when --state open is supplied, so the closed-PR test detects a missing filter.
  • Other nits: initialized check_pr once, made the final PR state/head error explicit, and broadened ANSI stripping to cover cursor/erase CSI codes before checking Quarto warnings.

Validation: 22 focused preview and warning tests pass; Ruff lint and format, shell syntax, and diff checks pass. Five unrelated Makefile tests in the full file cannot run in this dispatcher image because make is absent; PR CI runs them.

The automatic review chain is at its limit. Please use human review for this head.

@gas2own
gas2own marked this pull request as ready for review October 3, 2026 00:34
@gas2own

gas2own commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Commit 90bf8e3 carries the template's coalesced Pages-build behavior into the shared waiter. GitHub may build a later gh-pages commit that includes this run's marker without building the marker commit separately. The waiter now accepts that descendant build, but still rejects an unrelated build and rechecks that the PR remains open at the expected head.

After rebasing onto the latest review fixes, 24 focused preview checks passed; shell syntax, Ruff lint/format, and diff checks passed. Full CI is running. This commit came after the last independent review, and the automatic cycle has reached its limit, so it needs human review on the current head.

@gas2own

gas2own commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Updated with current main (v0.109.0) in 71d1e92, a clean merge. Locally, tests/test_workspace_workflow.py has 82 passed and 7 failed. The same 7 also fail on main here, because the local runtime has no make, so CI on the new head is the real check. #201 does not change or supersede it.

This branch has not been deployed

No deployments
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.

1 participant