Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
permissions:
contents: read
env:
# openwizdev/OpenWiz main at the merge of #981 (openwiz loop validate,
# OpenWiz #790), whose pinned format is WizLoops c7c2ed4. A full commit,
# never a branch: change it only to another merged OpenWiz commit.
OPENWIZ_REV: ef63380829f2aa946c7dae867c85ea1ec21a61f9
RUST_VERSION: 1.99.1
jobs:
Expand All @@ -19,6 +16,11 @@ jobs:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: comment-check
if: github.event_name == 'pull_request'
run: |
git fetch --no-tags --depth=2 origin "$GITHUB_SHA"
sh ci/comment-check.sh HEAD^1
- name: Rust ${{ env.RUST_VERSION }}
run: |
rustup toolchain install "$RUST_VERSION" --profile minimal --no-self-update
Expand Down
22 changes: 3 additions & 19 deletions catalog/fleet-check/check.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
#!/bin/sh
# The check of one spec's fleet thread: it runs OpenWiz's launch-fleet
# helper for that spec alone and prints its due lines. Nothing
# due, nothing printed: the wake is quiet and no agent starts.
#
# It needs no loop secret. The loop's thread is "same", so the check runs in
# the fleet thread's own sandbox, with that thread's own gh login and the
# helper's cache, which it keeps between wakes.
#
# A GitHub rate limit is a quiet wake too (one note on stderr; the helper
# itself backs off the same way when the allowance runs low). Any other
# failure prints one "look:" line, which wakes the thread to see why.
#
# Its params arrive as data, in the environment: WIZLOOP_PARAM_REPO,
# WIZLOOP_PARAM_SPEC and WIZLOOP_PARAM_FLEET_SH (the helper's path).
GH_REPO=$WIZLOOP_PARAM_REPO; export GH_REPO
spec=$WIZLOOP_PARAM_SPEC
helper=$WIZLOOP_PARAM_FLEET_SH
[ -f "$helper" ] || { printf 'look: fleet #%s check: no launch-fleet helper at %s\n' "$spec" "$helper"; exit 0; }
err=$(mktemp) || { printf 'look: fleet #%s check: cannot make a temporary file\n' "$spec"; exit 0; }
trap 'rm -f "$err"' EXIT
# Stop the helper before the loop's own 60-second limit, so an overrun is
# reported here instead of failing the run.
limit=
command -v timeout > /dev/null 2>&1 && limit='timeout 50'
out=$($limit sh "$helper" spec "$spec" 2> "$err"); rc=$?
stop_before_the_loops_60s_limit=
command -v timeout > /dev/null 2>&1 && stop_before_the_loops_60s_limit='timeout 50'
out=$($stop_before_the_loops_60s_limit sh "$helper" spec "$spec" 2> "$err"); rc=$?
[ -n "$out" ] && printf '%s\n' "$out"
if [ "$rc" -ne 0 ]; then
if grep -qiE 'rate limit already exceeded|secondary rate limit' "$err"; then
Expand Down
34 changes: 8 additions & 26 deletions catalog/fleet-check/test.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
#!/bin/sh
# Runs fleet-check's check, rendered as the Cloudroom adapter renders it
# (catalog/test-params.sh), against a stand-in launch-fleet helper, and
# checks what the loop promises: the helper's due lines wake the fleet
# thread, nothing due or a rate limit is a quiet wake, and any other failure
# prints one "look:" line. Its params reach the helper as data.
# Needs python3. Usage, from anywhere: sh catalog/fleet-check/test.sh
set -u
here=$(cd "$(dirname "$0")" && pwd)
. "$here/../test-params.sh"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
mkdir "$work/run"

# helper <path>: a stand-in fleet.sh that records its arguments and GH_REPO,
# then prints $HELPER_OUT, writes $HELPER_ERR to stderr and exits $HELPER_RC.
helper() {
write_stand_in_helper() {
mkdir -p "$(dirname "$1")"
cat > "$1" <<'H'
for a in "$@"; do printf '%s\n' "$a"; done > "$RECORD"
Expand All @@ -27,7 +19,6 @@ H
json() { python3 -I -c 'import json, sys; print(json.dumps(dict(zip(sys.argv[1::2], sys.argv[2::2]))))' "$@"; }

fails=0
# wake <case> <params JSON> <want stdout> [<want recorded args and GH_REPO>]
wake() {
render_check "$here/../fleet-check.md" "$work/check.sh" "$2" || { echo "FAIL $1: not rendered"; fails=$((fails + 1)); return; }
rm -f "$work/record"; rm -rf "$work/run"; mkdir "$work/run"
Expand All @@ -42,42 +33,33 @@ wake() {
else printf 'ok %s\n' "$1"; fi
}
H="$work/openwiz/skills/launch-fleet/scripts/fleet.sh"
helper "$H"
write_stand_in_helper "$H"
P=$(json fleet_sh "$H")
R='spec
1
GH_REPO=example-org/example-repo'

# catches: a wake with nothing due that still prints, so the fleet thread
# is prompted for nothing
wake "nothing due: quiet" "$P" "" "$R"
# catches: due lines lost, or the helper asked about another spec or repository
wake "nothing due is a quiet wake, never prompting the fleet thread for nothing" "$P" "" "$R"
out_lines='due: #2 ready for a builder'
wake "due lines wake the thread" "$P" "due: #2 ready for a builder" "$R"
# catches: a rate limit waking the thread every ten minutes for nothing
wake "due lines wake the thread, asked about this spec and repository alone" "$P" "due: #2 ready for a builder" "$R"
out_lines= err_lines='gh: API rate limit already exceeded for user' rc=1
wake "a rate limit is a quiet wake" "$P" ""
wake "a rate limit is a quiet wake, not a wake every ten minutes for nothing" "$P" ""
grep -q 'fleet #1: GitHub rate limit; skipping this wake' "$work/err" ||
{ echo "FAIL a rate limit is a quiet wake: no note on stderr"; fails=$((fails + 1)); }
# catches: a broken helper read as a quiet wake, so the fleet stalls unseen
err_lines='fleet.sh: cannot parse the plan' rc=3
wake "any other failure prints one look line" "$P" "look: fleet #1 check failed (exit 3; 124 = timeout): fleet.sh: cannot parse the plan "
wake "any other failure prints one look line, so a broken helper never stalls the fleet unseen" "$P" "look: fleet #1 check failed (exit 3; 124 = timeout): fleet.sh: cannot parse the plan "
err_lines= rc=0
# catches: a missing helper read as a quiet wake
wake "no helper prints one look line" "$(json fleet_sh "$work/missing/fleet.sh")" \
wake "a missing helper prints one look line, never a quiet wake" "$(json fleet_sh "$work/missing/fleet.sh")" \
"look: fleet #1 check: no launch-fleet helper at $work/missing/fleet.sh"

# The payloads from the review of workflow-kick's first pull request.
# catches: a param value read as shell code, which could run commands with
# the fleet thread's GitHub access or print and wake the thread.
for v in 'example-org/x"$(touch${IFS}marker)"' 'example-org/`touch marker`' \
"example-org/x';touch marker;'" 'release/";printf${IFS}WAKE;false${IFS}"' 'example-org/a\cb'; do
wake "payload repo stays data: $v" "$(json fleet_sh "$H" repo "$v")" "" "spec
1
GH_REPO=$v"
done
weird="$work/it's \$(touch marker) \`touch marker\`/fleet.sh"
helper "$weird"
write_stand_in_helper "$weird"
wake "payload helper path stays data" "$(json fleet_sh "$weird")" "" "$R"
wake "payload spec stays one argument" "$(json fleet_sh "$H" spec '1;touch marker $(touch marker)')" "" \
'spec
Expand Down
17 changes: 0 additions & 17 deletions catalog/hourly-status/check.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
#!/bin/sh
# hourly-status check for spec $WIZLOOP_PARAM_SPEC in $WIZLOOP_PARAM_REPO. Both
# params arrive as data, in the environment.
#
# Reads every one of the spec's tickets (all pages) with its labels, and for
# each ticket the open pull requests GitHub links as closing that exact
# issue, with their head, draft state, review decision, latest reviews, CI
# state and comment count. It prints that state only when it differs from
# the last status line the agent posted. Nothing changed: it prints nothing,
# so no agent starts. GitHub can't be read, or cut a list short: it fails the
# run (exit 2), never a silent quiet hour.
#
# The state it printed waits in <key>.pending until the agent has posted the
# line and renamed it to <key>.posted, so a run that fails before posting
# shows the same change again next hour.
set -eu
dir="$HOME/.wizloops/hourly-status"
repo=$WIZLOOP_PARAM_REPO
Expand Down Expand Up @@ -41,9 +27,6 @@ query='query($owner: String!, $name: String!, $spec: Int!, $endCursor: String) {
}
} }
}'
# One line per ticket and per open pull request that closes it; a line
# "cut-short" when GitHub has more labels, pull requests or reviews than
# were read.
filter='.data.repository.issue.subIssues.nodes[] |
(if .labels.pageInfo.hasNextPage or .closedByPullRequestsReferences.pageInfo.hasNextPage
or any(.closedByPullRequestsReferences.nodes[]; .latestReviews.pageInfo.hasNextPage)
Expand Down
96 changes: 29 additions & 67 deletions catalog/hourly-status/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#!/bin/sh
# Runs hourly-status's check against a stand-in `gh` that serves raw,
# synthetic GitHub JSON and applies the check's own --jq filter with jq, and
# checks the one promise the loop makes: it prints the spec's state when it
# changed since the last posted status line, and nothing otherwise, so a
# quiet hour starts no agent.
#
# Needs jq and python3. Usage, from anywhere: sh catalog/hourly-status/test.sh
set -eu
here=$(cd "$(dirname "$0")" && pwd)
. "$here/../test-params.sh"
Expand All @@ -14,18 +7,10 @@ work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
mkdir -p "$work/bin" "$work/home" "$work/data"

# The check as the adapter renders it: the file's synthetic defaults
# exported by the preamble.
render_check "$here/../hourly-status.md" "$work/check.sh"

# A stand-in for `gh`. `api graphql` serves page1.json, and page2.json only
# with --paginate and an $endCursor query, as gh does; `issue view` and
# `pr list` serve the same world in their shapes (pr list honours --limit).
# Each answer goes through the caller's --jq, applied by jq. With
# data/fail it fails as gh does when GitHub can't be read.
cat > "$work/bin/gh" <<'EOF'
#!/bin/sh
# With GH_ARGS set, it also records its arguments, one per line.
[ -n "${GH_ARGS-}" ] && for a in "$@"; do printf '%s\n' "$a"; done > "$GH_ARGS"
[ -f "$FAKE/fail" ] && { echo "gh: could not connect" >&2; exit 1; }
cmd="$1 $2"; shift 2
Expand All @@ -51,21 +36,19 @@ esac
EOF
chmod +x "$work/bin/gh"

# The synthetic world. Spec 1 has tickets #2 and #3 on the first page of its
# sub-issues and #4 on the second. #12 closes #3; #30 closes #4 and is the
# 201st open pull request; #40 closes other-org/other-repo#2, not ticket #2.
t2=CLOSED t3=OPEN t3_labels='"ready-for-agent"'
h12=abc1234 draft12=false reviews12= checks12=PENDING comments12=1
h30=ccc3000 h40=ddd4000 more_labels=false
pr() { # number repo head draft reviews checks comments
pr() {
printf '{"number":%s,"state":"OPEN","isDraft":%s,"headRefOid":"%s000000000000000000000000000000000","reviewDecision":null,"repository":{"nameWithOwner":"%s"},"comments":{"totalCount":%s},"latestReviews":{"pageInfo":{"hasNextPage":false},"nodes":[%s]},"commits":{"nodes":[{"commit":{"statusCheckRollup":{"state":"%s"}}}]},"closingIssuesReferences":[]}' \
"$1" "$4" "$3" "$2" "$7" "$5" "$6"
}
ticket() { # number state labels prs
ticket() {
label_nodes=$(printf '%s' "$3" | sed 's/"\([^",]*\)"/{"name":"\1"}/g')
printf '{"number":%s,"state":"%s","repository":{"nameWithOwner":"example-org/example-repo"},"labels":{"pageInfo":{"hasNextPage":%s},"nodes":[%s]},"closedByPullRequestsReferences":{"pageInfo":{"hasNextPage":false},"nodes":[%s]}}' \
"$1" "$2" "$more_labels" "$(printf '%s' "$3" | sed 's/"\([^",]*\)"/{"name":"\1"}/g')" "$4"
"$1" "$2" "$more_labels" "$label_nodes" "$4"
}
closes() { # <pr json> <issue number> <its repository>
closes() {
printf '%s' "$1" | sed "s#\"closingIssuesReferences\":\[\]#\"closingIssuesReferences\":[{\"number\":$2,\"repository\":{\"nameWithOwner\":\"$3\"}}]#"
}
world() {
Expand All @@ -76,7 +59,6 @@ world() {
"$(ticket 2 "$t2" "" "")" "$(ticket 3 "$t3" "$t3_labels" "$p12")" > "$work/data/page1.json"
printf '{"data":{"repository":{"issue":{"subIssues":{"pageInfo":{"hasNextPage":false,"endCursor":"Mw"},"nodes":[%s]}}}}}\n' \
"$(ticket 4 OPEN "" "$p30")" > "$work/data/page2.json"
# pr list: #12 and #40 first, 198 unrelated, then #30 as the 201st.
{ printf '[%s,%s' "$(closes "$p12" 3 example-org/example-repo)" "$(closes "$p40" 2 other-org/other-repo)"
i=100; while [ $i -lt 298 ]; do printf ',%s' "$(pr $i example-org/example-repo eee0000 false "" SUCCESS 0)"; i=$((i + 1)); done
printf ',%s]\n' "$(closes "$p30" 4 example-org/example-repo)"
Expand All @@ -91,79 +73,59 @@ wake() {
code=$?
set -e
}
quiet() { # <case>: the wake printed nothing and ended 0 or 1
quiet() {
wake
if [ -n "$out" ] || [ "$code" -gt 1 ]; then
echo "FAIL $1: expected a quiet wake, got exit $code and: $out"; fails=$((fails + 1))
else echo "ok $1"; fi
}
due() { # <case> <text it must show>: the wake printed the state
due() {
wake
case "$out" in
*"$2"*) if [ "$code" -le 1 ]; then echo "ok $1"; return; fi ;;
esac
echo "FAIL $1: expected output with '$2', got exit $code and: $out"; fails=$((fails + 1))
}
shows() { # <case> <text>: the last wake's output shows it
shows() {
case "$out" in *"$2"*) echo "ok $1" ;; *) echo "FAIL $1: no '$2' in: $out"; fails=$((fails + 1)) ;; esac
}
lacks() { # <case> <text>: the last wake's output does not show it
lacks() {
case "$out" in *"$2"*) echo "FAIL $1: '$2' shown in: $out"; fails=$((fails + 1)) ;; *) echo "ok $1" ;; esac
}
failed() { # <case>: the wake failed the run (exit over 1) and printed nothing
failed() {
wake
if [ -z "$out" ] && [ "$code" -gt 1 ]; then echo "ok $1"
else echo "FAIL $1: expected a failed run, got exit $code and: $out"; fails=$((fails + 1)); fi
}
posted() { # the agent posted the line and recorded it, as the prompt says
agent_posted_the_line() {
for f in "$work/home/.wizloops/hourly-status/"*.pending; do [ -e "$f" ] || continue; mv "$f" "${f%.pending}.posted"; done
}

# catches: the first wake stays quiet, so a spec never gets its first line
due "first wake shows the state" "#12 at abc1234"
# catches: a pull request that closes another repository's #2 is counted as
# work on this spec's ticket #2
lacks "another repository's #2 is not this spec's" "#40"
# catches: a fixed window over the repository's open pull requests, or only
# the first page of sub-issues, hides the spec's pull request #30
shows "a ticket's pull request past any window is seen" "#30 at ccc3000"
# catches: the check prints on every wake (as an always-echo check does), so
# every hour starts an agent even when nothing changed
posted; quiet "nothing changed since the posted line"
# catches: a change is missed, so the status line goes stale
due "the first wake shows the state, so a spec gets its first line" "#12 at abc1234"
lacks "a pull request closing another repository's #2 is not work on this spec's ticket #2" "#40"
shows "the 201st open pull request, closing a ticket on the second page of sub-issues, is seen" "#30 at ccc3000"
agent_posted_the_line; quiet "nothing changed since the posted line: no output, so no agent starts"
t3=CLOSED
due "a ticket closed" "#3 example-org/example-repo CLOSED"
# catches: the check marks a change as posted itself, so a run that fails
# before posting loses the change for good
due "not posted yet, still due" "#3 example-org/example-repo CLOSED"
posted; quiet "posted, quiet again"
# catches: a push to the spec's pull request is not seen as progress
due "a ticket closed is a change, so the status line never goes stale" "#3 example-org/example-repo CLOSED"
due "a change not posted yet is still due, so a run failing before posting loses nothing" "#3 example-org/example-repo CLOSED"
agent_posted_the_line; quiet "posted, quiet again"
t3=OPEN h12=abc9999
due "a pull request moved" "#12 at abc9999"
posted
# catches: progress at the same head is missed: a draft marked ready, a
# review, a CI result, a verdict comment, a blocking label
draft12=true; due "same head: marked draft" "draft"; posted
draft12=false; due "same head: marked ready" "ready"; posted
due "a push to the spec's pull request is a change" "#12 at abc9999"
agent_posted_the_line
draft12=true; due "same head: marked draft" "draft"; agent_posted_the_line
draft12=false; due "same head: marked ready" "ready"; agent_posted_the_line
reviews12='{"state":"CHANGES_REQUESTED","author":{"login":"example-reviewer"}}'
due "same head: a review asks for changes" "example-reviewer=CHANGES_REQUESTED"; posted
checks12=FAILURE; due "same head: CI failed" "checks:FAILURE"; posted
comments12=2; due "same head: a new comment (a verdict)" "comments:2"; posted
due "same head: a review asks for changes" "example-reviewer=CHANGES_REQUESTED"; agent_posted_the_line
checks12=FAILURE; due "same head: CI failed" "checks:FAILURE"; agent_posted_the_line
comments12=2; due "same head: a new comment (a verdict)" "comments:2"; agent_posted_the_line
t3_labels='"ready-for-agent","needs-info"'
due "a ticket asks a question" "needs-info"; posted
due "a ticket asks a question" "needs-info"; agent_posted_the_line
quiet "all of that posted, quiet again"
# catches: another spec's or nobody's pull request wakes this spec's agent
h40=ddd9999; quiet "an unrelated pull request moved"
# catches: a list GitHub cut short is read as complete, hiding changes
more_labels=true; failed "a cut-short list fails the run"; more_labels=false
# catches: GitHub can't be read and the check exits 0 or 1 with no output,
# which reads as a quiet hour and hides the failure
touch "$work/data/fail"; failed "a failed read fails the run"
h40=ddd9999; quiet "an unrelated pull request moved: this spec's agent stays asleep"
more_labels=true; failed "a list GitHub cut short fails the run, never read as complete"; more_labels=false
touch "$work/data/fail"; failed "a failed read fails the run, never a quiet hour"
rm "$work/data/fail"

# The payloads from the review of workflow-kick's first pull request, as the
# repository. catches: a param value read as shell code, which could run
# commands with the check's GitHub access or print and wake an agent.
for repo in 'example-org/x"$(touch${IFS}marker)"' 'example-org/`touch marker`' \
"example-org/x';touch marker;'" 'release/";printf${IFS}WAKE;false${IFS}"' 'example-org/a\cb'; do
render_check "$here/../hourly-status.md" "$work/check.sh" \
Expand Down
20 changes: 5 additions & 15 deletions catalog/morning-digest/check.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#!/bin/sh
# Morning digest check. Prints one line per item for the digest, from the
# repositories of the GitHub account $WIZLOOP_PARAM_ORG: each pull request
# merged in the last 24 hours, each open pull request whose checks fail, and
# each open review request or issue waiting on $WIZLOOP_PARAM_OWNER. Prints
# nothing when there is none of these, so a quiet morning starts no agent.
# Read-only; needs a signed-in gh. Both params arrive as data, in the
# environment.
org=$WIZLOOP_PARAM_ORG
owner=$WIZLOOP_PARAM_OWNER
since=$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null ||
Expand All @@ -15,10 +8,7 @@ if [ -z "$since" ]; then
exit 0
fi

# One search: print up to 100 lines, or one line saying GitHub could not be
# read. It asks for 101, so a list cut at 100 is told apart from exactly 100:
# then it adds one line saying the list is incomplete and how to finish it.
search() {
search_up_to_100() {
label=$1
shift
if ! lines=$(gh search "$@" --limit 101 --json repository,number,title \
Expand All @@ -37,8 +27,8 @@ if ! command -v gh >/dev/null 2>&1; then
echo "check: GitHub could not be read: gh is not installed"
exit 0
fi
search merged prs --owner "$org" --merged-at ">=$since"
search failing prs --owner "$org" --state open --checks failure
search review-requested prs --owner "$org" --state open --review-requested "$owner"
search assigned issues --owner "$org" --state open --assignee "$owner"
search_up_to_100 merged prs --owner "$org" --merged-at ">=$since"
search_up_to_100 failing prs --owner "$org" --state open --checks failure
search_up_to_100 review-requested prs --owner "$org" --state open --review-requested "$owner"
search_up_to_100 assigned issues --owner "$org" --state open --assignee "$owner"
exit 0
Loading
Loading