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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ All notable changes to this project are documented here. The format follows
is more than one line stops the start with a message naming the variable,
never the value (#77).

### Fixed
- `developer-skills-sync` no longer reports `state=current` when this pass's
fetch failed. A checkout whose fetches always fail (a 401 from GitHub) kept
comparing HEAD with a stale `origin/main` and read current with `fetched=0`.
It now writes `state=stale`, aged from `drift_since`, so `check_skills_sync.sh`
warns after an hour and goes critical after six.

## [1.15.0] - 2026-11-18

### Added
Expand Down
15 changes: 10 additions & 5 deletions rootfs/usr/local/bin/developer-skills-sync
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
#
# SKILLSSYNC written=<epoch> state=<state> head=<sha> origin=<sha> drift_since=<epoch> fetched=<epoch>
#
# state is current, behind, diverged or off-branch. drift_since is when
# HEAD was first seen differing from origin/<default>, 0 while it does
# not. fetched is the last fetch that worked: a checkout that can no
# longer reach GitHub reads as a stale fetched, never as "current".
# state is current, stale, behind, diverged or off-branch. stale is HEAD
# equal to an origin/<default> that this pass could not refresh: the fetch
# failed, so "equal" proves nothing. drift_since is when HEAD was first
# seen differing from, or unverifiable against, origin/<default>, 0 while
# it is not. fetched is the last fetch that worked.
#
# A failed step is reported on stderr and the pass goes on; the exit status
# is 0 unless the arguments are wrong. The next pass tries again.
Expand All @@ -52,12 +53,14 @@ repo=$1
url=${JOSUI_SKILLS_URL:-https://github.com/crunchtools/josui-skills}
now=$(date +%s)
fetched=
fetch_failed=

if ! [ -e "$repo/.git" ] && [ -z "$(ls -A "$repo" 2>/dev/null)" ]; then
if git clone --quiet "$url" "$repo"; then
fetched=$now
else
log "skills clone of $url into $repo failed; no skills until a pass succeeds"
fetch_failed=1
fi
elif [ -d "$repo/.git" ] && [ -w "$repo/.git" ]; then
# origin/HEAD is recorded at clone time; ask the remote what it is now.
Expand All @@ -66,6 +69,7 @@ elif [ -d "$repo/.git" ] && [ -w "$repo/.git" ]; then
fetched=$now
else
log "fetch failed in $repo, using the checkout as it is"
fetch_failed=1
fi
fi

Expand Down Expand Up @@ -128,7 +132,8 @@ origin=$(git -C "$repo" rev-parse --verify --quiet "origin/$default" 2>/dev/null
if [ "$(git -C "$repo" branch --show-current)" != "$default" ]; then
state=off-branch
elif [ "$head" = "$origin" ]; then
state=current
# The local origin ref is only as fresh as the last fetch that worked.
if [ -n "$fetch_failed" ]; then state=stale; else state=current; fi
elif [ "$origin" != none ] && git -C "$repo" merge-base --is-ancestor "$head" "$origin" 2>/dev/null; then
state=behind
else
Expand Down
35 changes: 34 additions & 1 deletion tests/test_skills_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,40 @@ def test_a_failed_fetch_keeps_the_last_good_fetch_time(self) -> None:
self.assertEqual(result.returncode, 0)
self.assertIn("fetch failed", result.stderr)
self.assertEqual(status_of(self.repo)["fetched"], fetched)
self.assertEqual(status_of(self.repo)["state"], "current")

def test_a_failed_fetch_is_stale_not_current_and_dated(self) -> None:
self.sync()
good = status_of(self.repo)
self.assertEqual(good["state"], "current")
self.assertEqual(good["drift_since"], "0")
self.git(self.repo, "remote", "set-url", "origin", str(self.root / "gone"))

# The stale origin/main still equals HEAD; that must not read as current.
self.sync()
first = status_of(self.repo)
self.sync()
second = status_of(self.repo)

self.assertEqual(first["head"], first["origin"])
self.assertEqual(first["state"], "stale")
self.assertGreater(int(first["drift_since"]), 0)
self.assertEqual(second["state"], "stale")
self.assertEqual(second["drift_since"], first["drift_since"])
self.assertEqual(second["fetched"], good["fetched"])

def test_a_fetch_that_works_again_is_current_and_clears_the_drift(self) -> None:
self.sync()
self.git(self.repo, "remote", "set-url", "origin", str(self.root / "gone"))
self.sync()
self.assertEqual(status_of(self.repo)["state"], "stale")
self.git(self.repo, "remote", "set-url", "origin", str(self.upstream))

self.sync()

after = status_of(self.repo)
self.assertEqual(after["state"], "current")
self.assertEqual(after["drift_since"], "0")
self.assertGreater(int(after["fetched"]), 0)

def test_an_empty_directory_is_cloned(self) -> None:
shutil.rmtree(self.repo)
Expand Down
Loading