CHECKPOINT ONLY — not a deliverable, not reviewed, not complete.
Committed by mos-remediation as TRANSPORT after the authoring seat (coder-mos1) became
unable to act: its context window was exceeded at 102.6%/372k AND its overflow-recovery
path failed ("Turn prefix summarization failed: servers overloaded"). The seat could not
process instructions or commit its own work, leaving 28 modified files durable only on
local disk.
Authorship preserved as coder-mos1 — this is transport, not authorship. The work is the
seat's; committing it is the only way to make it survive the rotation that must follow.
Scope note, unresolved: this diff spans the queue-guard tools (9 files under
framework/tools/git) AND 5 framework guides plus 11 agent templates. RM-03 was scoped to
ci-queue-wait.sh and its tests. Whether the doc/template edits are consequential to the
tri-state change or drive-by was queried and never answered — the seat was bricked before
it could reply. That question stays open and must be resolved before any of this is
reviewed; the wider edits may need splitting out.
Direct instance of D-31: commit-then-rotate works, rotate-without-commit loses everything.
115 lines
3.8 KiB
Bash
115 lines
3.8 KiB
Bash
#!/usr/bin/env bash
|
|
# shellcheck disable=SC2030,SC2031 # Provider arms isolate PATH/credentials in subshells.
|
|
# The commit whose CI was guarded must be the commit the provider atomically merges.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
WORK_DIR="${MOSAIC_TEST_WORK_DIR:-$PWD/.mosaic-test-work/pr-merge-head-pin}"
|
|
SHA=0123456789abcdef0123456789abcdef01234567
|
|
|
|
make_fixture() {
|
|
local name="$1" remote="$2"
|
|
local root="$WORK_DIR/$name"
|
|
local tools="$root/tools/git"
|
|
mkdir -p "$tools" "$root/repo"
|
|
cp "$SCRIPT_DIR/pr-merge.sh" "$tools/pr-merge.sh"
|
|
cp "$SCRIPT_DIR/detect-platform.sh" "$tools/detect-platform.sh"
|
|
git -C "$root/repo" init -q
|
|
git -C "$root/repo" remote add origin "$remote"
|
|
cat > "$tools/pr-metadata.sh" <<SH
|
|
#!/usr/bin/env bash
|
|
printf '%s\n' '{"baseRefName":"main","headRefName":"fix/pinned","headRefOid":"$SHA","headRepository":"contributor/widgets-fork"}'
|
|
SH
|
|
cat > "$tools/ci-queue-wait.sh" <<'SH'
|
|
#!/usr/bin/env bash
|
|
exit 0
|
|
SH
|
|
chmod +x "$tools"/*.sh
|
|
}
|
|
|
|
rm -rf "$WORK_DIR"
|
|
make_fixture gitea https://git.example.test/acme/widgets.git
|
|
make_fixture github https://github.com/acme/widgets.git
|
|
|
|
cat > "$WORK_DIR/gitea/curl" <<'SH'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
payload=""
|
|
for ((i=1; i<=$#; i++)); do
|
|
if [[ "${!i}" == "-d" ]]; then
|
|
j=$((i + 1))
|
|
payload="${!j}"
|
|
fi
|
|
done
|
|
printf '%s' "$payload" > "${MOSAIC_MERGE_PAYLOAD_LOG:?}"
|
|
printf '200'
|
|
SH
|
|
chmod +x "$WORK_DIR/gitea/curl"
|
|
|
|
set +e
|
|
(
|
|
cd "$WORK_DIR/gitea/repo"
|
|
export PATH="$WORK_DIR/gitea:$PATH"
|
|
export GITEA_TOKEN=stub-token
|
|
export GITEA_URL=https://git.example.test
|
|
export MOSAIC_CREDENTIALS_FILE="$WORK_DIR/no-credentials.json"
|
|
export MOSAIC_MERGE_PAYLOAD_LOG="$WORK_DIR/gitea-payload.json"
|
|
env -u MOSAIC_GIT_IDENTITY "$WORK_DIR/gitea/tools/git/pr-merge.sh" -n 123
|
|
) >"$WORK_DIR/gitea.out" 2>&1
|
|
gitea_rc=$?
|
|
set -e
|
|
if [[ "$gitea_rc" -ne 0 ]]; then
|
|
echo "FAIL gitea-pin: merge fixture returned $gitea_rc" >&2
|
|
cat "$WORK_DIR/gitea.out" >&2
|
|
exit 1
|
|
fi
|
|
python3 - "$WORK_DIR/gitea-payload.json" "$SHA" <<'PY'
|
|
import json
|
|
import sys
|
|
payload = json.load(open(sys.argv[1], encoding="utf-8"))
|
|
assert set(payload) <= {"Do", "head_commit_id", "delete_branch_after_merge"}, payload
|
|
assert payload.get("Do") == "squash", payload
|
|
assert payload.get("head_commit_id") == sys.argv[2], payload
|
|
PY
|
|
|
|
# A merge-gate verdict is commit-bound. A stale expected head must fail before merge.
|
|
wrong_sha=ffffffffffffffffffffffffffffffffffffffff
|
|
rm -f "$WORK_DIR/gitea-payload-stale.json"
|
|
set +e
|
|
(
|
|
cd "$WORK_DIR/gitea/repo"
|
|
export PATH="$WORK_DIR/gitea:$PATH"
|
|
export GITEA_TOKEN=stub-token
|
|
export GITEA_URL=https://git.example.test
|
|
export MOSAIC_CREDENTIALS_FILE="$WORK_DIR/no-credentials.json"
|
|
export MOSAIC_MERGE_PAYLOAD_LOG="$WORK_DIR/gitea-payload-stale.json"
|
|
env -u MOSAIC_GIT_IDENTITY "$WORK_DIR/gitea/tools/git/pr-merge.sh" -n 123 --expect-head "$wrong_sha"
|
|
) >"$WORK_DIR/gitea-stale.out" 2>&1
|
|
stale_rc=$?
|
|
set -e
|
|
if [[ "$stale_rc" -eq 0 ]] || [[ -e "$WORK_DIR/gitea-payload-stale.json" ]]; then
|
|
echo "FAIL stale-verdict: moved head was not refused before provider merge" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cat > "$WORK_DIR/github/gh" <<'SH'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
printf '%s\n' "$*" > "${MOSAIC_GH_MERGE_LOG:?}"
|
|
SH
|
|
chmod +x "$WORK_DIR/github/gh"
|
|
(
|
|
cd "$WORK_DIR/github/repo"
|
|
export PATH="$WORK_DIR/github:$PATH"
|
|
export MOSAIC_GH_MERGE_LOG="$WORK_DIR/github-call.log"
|
|
"$WORK_DIR/github/tools/git/pr-merge.sh" -n 123
|
|
) >"$WORK_DIR/github.out" 2>&1
|
|
if ! grep -q -- "--match-head-commit $SHA" "$WORK_DIR/github-call.log"; then
|
|
echo "FAIL github-pin: merge command omitted --match-head-commit $SHA" >&2
|
|
cat "$WORK_DIR/github-call.log" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "PR merge exact-head pin regression passed (Gitea + GitHub)"
|