From 158849262cbe2bac3b20c099be47e0e3f21fa2a0 Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Mon, 23 Nov 2026 13:13:05 -0800 Subject: [PATCH 1/2] fix(companion-freshness): compare against htpx's latest release, not main The companion advances on htpx release tags (#296, #297, #359), but the scheduled freshness check compared companion_sha with htpx main. main takes CI-only bot commits between releases that never reach the corpus, so the check sat red for eight weeks after v3.3.0 over two of them and would have gone red again after every sync. "Current" now means the newest vX.Y.Z release commit is the vendored commit or an ancestor of it. Ancestry needs history, so the check fetches htpx's commits only (--filter=tree:0) into a throwaway bare repo; a lock synced past the release, like #375's, stays current. Pre-release tags are ignored, a companion_sha upstream does not have is a hard failure (exit 1) instead of a false "behind", and with no release tags upstream the check falls back to the branch tip. A behind result names the exact `scripts/sync-companion.sh --ref ` to run, and the workflow summary and Makefile help say "latest release". Co-Authored-By: Claude Opus 5.5 --- .github/workflows/companion-freshness.yml | 6 +- CHANGELOG.md | 14 +++ Makefile | 2 +- test/check-companion-freshness.sh | 110 +++++++++++++++++----- 4 files changed, 106 insertions(+), 26 deletions(-) diff --git a/.github/workflows/companion-freshness.yml b/.github/workflows/companion-freshness.yml index 05f51137..6239f945 100644 --- a/.github/workflows/companion-freshness.yml +++ b/.github/workflows/companion-freshness.yml @@ -53,16 +53,16 @@ jobs: ;; 2) { - echo "### ⚠️ vendored offensive/companion/ is behind upstream htpx" + echo "### ⚠️ vendored offensive/companion/ is behind the latest htpx release" echo "" echo '```' printf '%s\n' "$out" echo '```' echo "" - echo "Pull the companion, then review + drift-check the generated views:" + echo "Pull the companion at that release (the exact command is in the output above), then review + drift-check the generated views:" echo "" echo '```' - echo "scripts/sync-companion.sh" + echo "scripts/sync-companion.sh --ref " echo "offensive/companion/gen-views.sh --check" echo '```' } >> "$GITHUB_STEP_SUMMARY" diff --git a/CHANGELOG.md b/CHANGELOG.md index 41281e60..84d45960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,20 @@ release line. ## [Unreleased] +### Changed + +- **`companion-freshness` measures the vendored companion against htpx's latest release, + not its `main` tip.** The companion advances on htpx release tags, but the scheduled + check compared against `main`, which takes CI-only bot commits between releases that + never reach the corpus. It stayed red for eight weeks after v3.3.0 over two of them, + and would have gone red again after every sync. "Current" now means the newest `vX.Y.Z` + release commit is the vendored commit or an ancestor of it, so a lock synced past the + release (as #375 did) is current too. Ancestry comes from a commits-only + (`--filter=tree:0`) fetch into a throwaway bare repo. A behind result names the exact + `scripts/sync-companion.sh --ref ` to run. A `companion_sha` upstream does not have + is now a hard failure rather than "behind", and with no release tags upstream the check + falls back to the branch tip. + ### Security - **Engagement-data write guard.** `note`, `logshell`, `bhce` and `nmapsweep` used diff --git a/Makefile b/Makefile index b91a3208..13debe6f 100644 --- a/Makefile +++ b/Makefile @@ -192,7 +192,7 @@ core-lock: ## core.lock is written by Core's fan-out, not here — explains how ## ── vendored offensive/companion/ (subtree of htpx) ────────────────────────── -companion-check: ## Is the vendored companion behind upstream htpx? +companion-check: ## Is the vendored companion behind htpx's latest release? @./test/check-companion-freshness.sh companion-integrity: ## Was the vendored companion hand-edited? (tree vs companion.lock) diff --git a/test/check-companion-freshness.sh b/test/check-companion-freshness.sh index 1f9dee47..8702ae6a 100755 --- a/test/check-companion-freshness.sh +++ b/test/check-companion-freshness.sh @@ -1,27 +1,42 @@ #!/usr/bin/env bash -# test/check-companion-freshness.sh — is the vendored offensive/companion/ subtree BEHIND upstream? +# test/check-companion-freshness.sh — is the vendored offensive/companion/ subtree BEHIND htpx's latest release? # ────────────────────────────────────────────────────────────────────────────── # The vendored offensive/companion/ here is a git-subtree copy of dotgibson/htpx (the # standalone red<->blue pentest companion; provenance in companion.lock). Nothing on # THIS side tracked whether that copy had fallen behind upstream — so a fix landing in # htpx could sit un-pulled here indefinitely. This is the consumer-side freshness -# watcher: it asks whether the vendored commit (companion.lock's companion_sha) is now -# BEHIND upstream's tip, i.e. there are companion updates this repo hasn't pulled. A +# watcher: it asks whether htpx has published a RELEASE this repo has not pulled. A # behind result is the NUDGE to run scripts/sync-companion.sh, not a hard error in # normal development — so it lives in a SCHEDULED workflow. # +# RELEASES, NOT THE BRANCH TIP. The companion advances on htpx release tags (htpx's +# fan-out syncs this repo on each tag; #296/#297/#359 were all tag syncs), but this +# watcher used to compare companion_sha against htpx `main`. htpx's main takes CI-only +# bot commits between releases (Renovate action bumps, workflow rules) that never reach +# the corpus, so the scheduled run stayed red for eight weeks after v3.3.0 over two such +# commits (cleared by a sync to main in #375), and would go red again after every sync. +# Now "current" means the newest v* release commit is the vendored commit OR an ancestor +# of it: a lock synced past the release by hand (scripts/sync-companion.sh with no --ref +# pulls main) is current too. Ancestry needs history, so the check fetches htpx's +# commits only (--filter=tree:0, no trees or blobs) into a throwaway bare repo; equality +# alone, which is all test/check-core-freshness.sh needs for core's exact release pins, +# would call such a lock behind. With no release tags upstream it falls back to the +# branch tip, the old behaviour. +# # This mirrors test/check-core-freshness.sh (the watcher for the vendored core/ -# subtree); the only differences are the lock file (companion.lock), its field names -# (companion_repo / companion_branch / companion_sha), and the remediation -# (scripts/sync-companion.sh, not a raw `git subtree pull`). +# subtree) and its newest-v*-tag lookup, but differs in the lock file (companion.lock), +# its field names (companion_repo / companion_branch / companion_sha), the ancestry test +# above, and the remediation (scripts/sync-companion.sh --ref , not a raw +# `git subtree pull`). # # Exit codes (matching dotfiles-core's drift-check convention — see # core/scripts/update-plugins.sh --check, and test/check-core-freshness.sh): # 0 current, OR a graceful skip (no git, offline/restricted, not a subtree checkout) -# 2 vendored offensive/companion/ is BEHIND upstream (drift — the nudge to sync) +# 2 vendored offensive/companion/ is BEHIND htpx's latest release (the nudge to sync) # 1 a genuine hard failure (e.g. a malformed companion.lock) # The workflow branches on these so a skip, a drift, and a real error each render the -# right step summary. Override the upstream/branch with COMPANION_UPSTREAM / COMPANION_BRANCH. +# right step summary. Override the upstream/branch with COMPANION_UPSTREAM / COMPANION_BRANCH +# (the branch is what the ancestry fetch reads, and the comparison when no release exists). # ────────────────────────────────────────────────────────────────────────────── set -uo pipefail @@ -90,27 +105,78 @@ case "$BRANCH" in refs/*) ref="$BRANCH" ;; *) ref="refs/heads/$BRANCH" ;; esac -# The upstream tip we'd be pulling. ls-remote needs no clone; GIT_TERMINAL_PROMPT=0 keeps it -# non-interactive (never block a scheduled run waiting on a credential prompt). -# `--` forces end-of-options: UPSTREAM is overridable (COMPANION_UPSTREAM), and -# ls-remote would treat a leading-dash value as an option (option-injection guard). -TIP="$(GIT_TERMINAL_PROMPT=0 git ls-remote -- "$UPSTREAM" "$ref" 2>/dev/null | awk 'NR==1{print $1}')" +# GIT_TERMINAL_PROMPT=0 keeps every network call non-interactive (never block a scheduled +# run on a credential prompt). `--` forces end-of-options: UPSTREAM is overridable +# (COMPANION_UPSTREAM), and git would treat a leading-dash value as an option. +GLR() { GIT_TERMINAL_PROMPT=0 git ls-remote "$@" 2>/dev/null; } + +# The branch tip doubles as the connectivity probe: empty means unreachable (or a branch +# that does not exist), which stays a graceful skip, as before. +TIP="$(GLR -- "$UPSTREAM" "$ref" | awk 'NR==1{print $1}')" [[ -n "$TIP" ]] || skip "check-companion-freshness: cannot reach $UPSTREAM ($BRANCH) — offline/restricted?" -if [[ "$TIP" == "$SPLIT" ]]; then - printf '%s%s%s vendored offensive/companion/ is current with %s@%s (%s)\n' "$c_g" "$UX_OK" "$c_0" "$UPSTREAM" "$BRANCH" "${SPLIT:0:12}" +# Newest RELEASE: plain vX.Y.Z tags only. A pre-release (v3.4.0-rc1) is not a release, and +# `sort -V` would rank it above v3.4.0's final anyway. Peel an annotated tag to its commit +# (^{}); a lightweight tag has no peeled line, so fall back to the raw object. +REL_TAG="$(GLR --tags --refs -- "$UPSTREAM" 'v*' | sed -n 's#.*refs/tags/##p' | + grep -E '^v[0-9]+(\.[0-9]+)*$' | sort -V | tail -n1)" + +current() { + printf '%s%s%s vendored offensive/companion/ is current %s (%s)\n' "$c_g" "$UX_OK" "$c_0" "$1" "${SPLIT:0:12}" exit 0 +} + +if [[ -z "$REL_TAG" ]]; then + # No releases upstream: the branch tip is all there is to compare against. + CMP_NAME="$BRANCH (no v* release tags found)" + CMP_SHA="$TIP" + [[ "$CMP_SHA" != "$SPLIT" ]] || current "with $UPSTREAM@$BRANCH" +else + CMP_NAME="$REL_TAG" + CMP_SHA="$(GLR --tags -- "$UPSTREAM" "refs/tags/$REL_TAG^{}" | awk 'NR==1{print $1}')" + [[ -n "$CMP_SHA" ]] || CMP_SHA="$(GLR --tags -- "$UPSTREAM" "refs/tags/$REL_TAG" | awk 'NR==1{print $1}')" + if [[ -z "$CMP_SHA" ]]; then + printf '%s%s%s check-companion-freshness: could not resolve %s in %s despite listing it\n' \ + "$c_r" "$UX_ERR" "$c_0" "$REL_TAG" "$UPSTREAM" >&2 + exit 1 + fi + [[ "$CMP_SHA" != "$SPLIT" ]] || current "with $UPSTREAM@$REL_TAG" + + # Not the release commit itself: current only if the release is an ANCESTOR of what is + # vendored (a sync past the tag). Commits only, into a throwaway bare repo — the branch + # plus every tag, since a lock can sit on either. + TMPGIT="$(mktemp -d)" || { + printf '%s%s%s check-companion-freshness: mktemp failed\n' "$c_r" "$UX_ERR" "$c_0" >&2 + exit 1 + } + trap 'rm -rf "$TMPGIT"' EXIT + git init -q --bare "$TMPGIT" || exit 1 + if ! GIT_TERMINAL_PROMPT=0 git -C "$TMPGIT" fetch -q --filter=tree:0 --tags -- "$UPSTREAM" "+$ref:refs/heads/upstream" 2>/dev/null; then + skip "check-companion-freshness: could not fetch $UPSTREAM history to compare against $REL_TAG — offline/restricted?" + fi + if ! git -C "$TMPGIT" cat-file -e "$SPLIT^{commit}" 2>/dev/null; then + # The vendored commit is on neither the branch nor any tag: the lock names something + # upstream does not have (force-pushed away, or a typo). Not drift — a broken lock. + printf '%s%s%s check-companion-freshness: companion_sha %s is not on %s@%s or any tag — companion.lock points at a commit upstream does not have\n' \ + "$c_r" "$UX_ERR" "$c_0" "${SPLIT:0:12}" "$UPSTREAM" "$BRANCH" >&2 + exit 1 + fi + if git -C "$TMPGIT" merge-base --is-ancestor "$CMP_SHA" "$SPLIT"; then + current "— $(git -C "$TMPGIT" rev-list --count "$CMP_SHA..$SPLIT") commit(s) past $REL_TAG, the latest htpx release" + fi fi -# Behind (or diverged). Report the SHAs and how to update, then exit 2 (drift) so a -# scheduled run surfaces it as a nudge — distinct from the exit-1 hard failures above. -# The remediation is scripts/sync-companion.sh (which pulls htpx + bumps companion.lock), -# then the two manual follow-ups it can't do: eyeball the diff and drift-check the views. +# Behind. Report the SHAs and how to update, then exit 2 (drift) so a scheduled run +# surfaces it as a nudge — distinct from the exit-1 hard failures above. The remediation +# is scripts/sync-companion.sh pinned to the release (which pulls htpx + bumps +# companion.lock), then the two manual follow-ups it can't do: eyeball the diff and +# drift-check the views. +if [[ -n "$REL_TAG" ]]; then SYNC="scripts/sync-companion.sh --ref $REL_TAG"; else SYNC="scripts/sync-companion.sh"; fi { - printf '%s%s%s vendored offensive/companion/ is behind upstream %s@%s\n' "$c_y" "$UX_WARN" "$c_0" "$UPSTREAM" "$BRANCH" - printf ' vendored: %s\n upstream: %s\n' "${SPLIT:0:12}" "${TIP:0:12}" + printf '%s%s%s vendored offensive/companion/ is behind %s@%s\n' "$c_y" "$UX_WARN" "$c_0" "$UPSTREAM" "$CMP_NAME" + printf ' vendored: %s\n upstream: %s\n' "${SPLIT:0:12}" "${CMP_SHA:0:12}" printf ' update:\n' - printf ' scripts/sync-companion.sh\n' + printf ' %s\n' "$SYNC" printf ' git diff %s -- offensive/companion # review the pulled change\n' "${SPLIT:0:12}" printf ' offensive/companion/gen-views.sh --check # regenerate + commit if it reports drift\n' } >&2 From 81ff0496af1b544fcd7687f0661d61559c4fdfce Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Mon, 23 Nov 2026 13:28:38 -0800 Subject: [PATCH 2/2] fix(companion-freshness): skip on a failed tag listing, fetch every branch, one Changed heading A failed `ls-remote --tags` used to leave REL_TAG empty exactly like an upstream with no releases, and fall back to comparing with main: the false drift this check exists to stop reporting. The listing's status is now checked on its own, and only a successful empty listing falls back. The ancestry fetch took only companion_branch, but `sync-companion.sh --ref ` can lock a commit on another branch without changing that field, which the check would then call broken. It now fetches every branch head plus all tags. CHANGELOG: the entry moves into the existing `### Changed` section; a second one under [Unreleased] failed markdownlint MD024. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 26 ++++++++++++-------------- test/check-companion-freshness.sh | 26 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84d45960..7921b56a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,20 +17,6 @@ release line. ## [Unreleased] -### Changed - -- **`companion-freshness` measures the vendored companion against htpx's latest release, - not its `main` tip.** The companion advances on htpx release tags, but the scheduled - check compared against `main`, which takes CI-only bot commits between releases that - never reach the corpus. It stayed red for eight weeks after v3.3.0 over two of them, - and would have gone red again after every sync. "Current" now means the newest `vX.Y.Z` - release commit is the vendored commit or an ancestor of it, so a lock synced past the - release (as #375 did) is current too. Ancestry comes from a commits-only - (`--filter=tree:0`) fetch into a throwaway bare repo. A behind result names the exact - `scripts/sync-companion.sh --ref ` to run. A `companion_sha` upstream does not have - is now a hard failure rather than "behind", and with no release tags upstream the check - falls back to the branch tip. - ### Security - **Engagement-data write guard.** `note`, `logshell`, `bhce` and `nmapsweep` used @@ -800,6 +786,18 @@ on every `companion-sync`, and the corpus is authoritative when they disagree. ### Changed +- **`companion-freshness` measures the vendored companion against htpx's latest release, + not its `main` tip.** The companion advances on htpx release tags, but the scheduled + check compared against `main`, which takes CI-only bot commits between releases that + never reach the corpus. It stayed red for eight weeks after v3.3.0 over two of them, + and would have gone red again after every sync. "Current" now means the newest `vX.Y.Z` + release commit is the vendored commit or an ancestor of it, so a lock synced past the + release (as #375 did) is current too. Ancestry comes from a commits-only + (`--filter=tree:0`) fetch into a throwaway bare repo. A behind result names the exact + `scripts/sync-companion.sh --ref ` to run. A `companion_sha` upstream does not have + is now a hard failure rather than "behind", and with no release tags upstream the check + falls back to the branch tip. + - **`bootstrap.sh` runs on Core's bootstrap driver, `blib_main`** (dotgibson/dotfiles-core#986). The shared half — the flag loop, the Core symlink surface, the band-85 role stage, the managed `~/.zshrc`, the closing report — now runs from one definition in diff --git a/test/check-companion-freshness.sh b/test/check-companion-freshness.sh index 8702ae6a..3f1ba1eb 100755 --- a/test/check-companion-freshness.sh +++ b/test/check-companion-freshness.sh @@ -118,7 +118,15 @@ TIP="$(GLR -- "$UPSTREAM" "$ref" | awk 'NR==1{print $1}')" # Newest RELEASE: plain vX.Y.Z tags only. A pre-release (v3.4.0-rc1) is not a release, and # `sort -V` would rank it above v3.4.0's final anyway. Peel an annotated tag to its commit # (^{}); a lightweight tag has no peeled line, so fall back to the raw object. -REL_TAG="$(GLR --tags --refs -- "$UPSTREAM" 'v*' | sed -n 's#.*refs/tags/##p' | +# +# The listing's own status is checked SEPARATELY from the parse. A failed request and an +# upstream with no releases both leave REL_TAG empty, but only the second may fall back +# to the branch tip: falling back on a transient failure would report the very +# main-vs-lock drift this check exists to stop reporting. (ls-remote without --exit-code +# exits 0 when the pattern simply matches nothing.) +TAGS="$(GLR --tags --refs -- "$UPSTREAM" 'v*')" || + skip "check-companion-freshness: could not list $UPSTREAM release tags — offline/restricted?" +REL_TAG="$(printf '%s\n' "$TAGS" | sed -n 's#.*refs/tags/##p' | grep -E '^v[0-9]+(\.[0-9]+)*$' | sort -V | tail -n1)" current() { @@ -143,22 +151,24 @@ else [[ "$CMP_SHA" != "$SPLIT" ]] || current "with $UPSTREAM@$REL_TAG" # Not the release commit itself: current only if the release is an ANCESTOR of what is - # vendored (a sync past the tag). Commits only, into a throwaway bare repo — the branch - # plus every tag, since a lock can sit on either. + # vendored (a sync past the tag). Commits only, into a throwaway bare repo — EVERY branch + # head plus every tag, since a lock can sit on any of them: `sync-companion.sh --ref + # ` syncs a non-default branch without changing companion_branch, so fetching + # only that field's branch would call such a lock broken. TMPGIT="$(mktemp -d)" || { printf '%s%s%s check-companion-freshness: mktemp failed\n' "$c_r" "$UX_ERR" "$c_0" >&2 exit 1 } trap 'rm -rf "$TMPGIT"' EXIT git init -q --bare "$TMPGIT" || exit 1 - if ! GIT_TERMINAL_PROMPT=0 git -C "$TMPGIT" fetch -q --filter=tree:0 --tags -- "$UPSTREAM" "+$ref:refs/heads/upstream" 2>/dev/null; then + if ! GIT_TERMINAL_PROMPT=0 git -C "$TMPGIT" fetch -q --filter=tree:0 --tags -- "$UPSTREAM" '+refs/heads/*:refs/heads/*' 2>/dev/null; then skip "check-companion-freshness: could not fetch $UPSTREAM history to compare against $REL_TAG — offline/restricted?" fi if ! git -C "$TMPGIT" cat-file -e "$SPLIT^{commit}" 2>/dev/null; then - # The vendored commit is on neither the branch nor any tag: the lock names something - # upstream does not have (force-pushed away, or a typo). Not drift — a broken lock. - printf '%s%s%s check-companion-freshness: companion_sha %s is not on %s@%s or any tag — companion.lock points at a commit upstream does not have\n' \ - "$c_r" "$UX_ERR" "$c_0" "${SPLIT:0:12}" "$UPSTREAM" "$BRANCH" >&2 + # The vendored commit is on no branch and no tag: the lock names something upstream + # does not have (force-pushed away, or a typo). Not drift — a broken lock. + printf '%s%s%s check-companion-freshness: companion_sha %s is not on any branch or tag of %s — companion.lock points at a commit upstream does not have\n' \ + "$c_r" "$UX_ERR" "$c_0" "${SPLIT:0:12}" "$UPSTREAM" >&2 exit 1 fi if git -C "$TMPGIT" merge-base --is-ancestor "$CMP_SHA" "$SPLIT"; then