aboutsummaryrefslogtreecommitdiff
path: root/scripts/tests/roam-sync.bats
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-10 18:13:03 -0500
committerCraig Jennings <c@cjennings.net>2026-06-10 18:13:03 -0500
commitfcf554a6be8b02aeb9c521ea5d7b7d86465aea0f (patch)
tree869fbe141ce36693325531651a8a4120c1de506d /scripts/tests/roam-sync.bats
parenta059be8650080864505b3d9274c6b3555419b9b2 (diff)
downloadrulesets-fcf554a6be8b02aeb9c521ea5d7b7d86465aea0f.tar.gz
rulesets-fcf554a6be8b02aeb9c521ea5d7b7d86465aea0f.zip
feat(kb): roam-sync script + timer units, old roam path repointed
Phase 0 of the agent KB spec: the org-roam KB now lives at ~/org/roam as a git repo on cjennings.net. roam-sync.sh (bats-tested: commit, rebase, push, conflict-abort) runs from a 15-minute systemd user timer; canonical unit files live in scripts/systemd/. Live references to the old ~/sync/org/roam path (the task-list pointer, the journal workflow, the notes template) repoint to ~/org/roam, and a transition symlink at the old location covers stragglers.
Diffstat (limited to 'scripts/tests/roam-sync.bats')
-rw-r--r--scripts/tests/roam-sync.bats71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/tests/roam-sync.bats b/scripts/tests/roam-sync.bats
new file mode 100644
index 0000000..017a92c
--- /dev/null
+++ b/scripts/tests/roam-sync.bats
@@ -0,0 +1,71 @@
+#!/usr/bin/env bats
+# Tests for scripts/roam-sync.sh — the git auto-sync loop the roam KB timer runs.
+# Each test builds a throwaway clone + bare remote pair under $BATS_TEST_TMPDIR.
+
+setup() {
+ SCRIPT="$BATS_TEST_DIRNAME/../roam-sync.sh"
+ export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null
+ export GIT_AUTHOR_NAME=test GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=test GIT_COMMITTER_EMAIL=t@t
+ REMOTE="$BATS_TEST_TMPDIR/remote.git"
+ REPO="$BATS_TEST_TMPDIR/repo"
+ OTHER="$BATS_TEST_TMPDIR/other"
+ git init -q --bare -b main "$REMOTE"
+ git init -q -b main "$REPO"
+ (cd "$REPO" && echo seed > seed.org && git add -A && git commit -qm seed \
+ && git remote add origin "$REMOTE" && git push -qu origin main)
+}
+
+clone_other() {
+ git clone -q "$REMOTE" "$OTHER" 2>/dev/null
+}
+
+@test "clean tree, current remote: exits 0 with no new commit" {
+ before=$(git -C "$REPO" rev-parse HEAD)
+ run "$SCRIPT" "$REPO"
+ [ "$status" -eq 0 ]
+ [ "$(git -C "$REPO" rev-parse HEAD)" = "$before" ]
+}
+
+@test "dirty tree: commits and pushes to the remote" {
+ echo "new fact" > "$REPO/fact.org"
+ run "$SCRIPT" "$REPO"
+ [ "$status" -eq 0 ]
+ [ -z "$(git -C "$REPO" status --porcelain)" ]
+ git -C "$REMOTE" log --format=%s main | grep -q "auto-sync"
+}
+
+@test "remote ahead: pulls the remote commit" {
+ clone_other
+ (cd "$OTHER" && echo upstream > up.org && git add -A && git commit -qm upstream && git push -q)
+ run "$SCRIPT" "$REPO"
+ [ "$status" -eq 0 ]
+ [ -f "$REPO/up.org" ]
+}
+
+@test "local dirty and remote ahead, disjoint files: both land" {
+ clone_other
+ (cd "$OTHER" && echo upstream > up.org && git add -A && git commit -qm upstream && git push -q)
+ echo "local fact" > "$REPO/local.org"
+ run "$SCRIPT" "$REPO"
+ [ "$status" -eq 0 ]
+ [ -f "$REPO/up.org" ]
+ git -C "$REMOTE" log --format=%s main | grep -q "auto-sync"
+}
+
+@test "conflicting rebase: exits nonzero and leaves no rebase in progress" {
+ clone_other
+ (cd "$OTHER" && echo theirs > seed.org && git add -A && git commit -qm theirs && git push -q)
+ echo mine > "$REPO/seed.org"
+ run "$SCRIPT" "$REPO"
+ [ "$status" -ne 0 ]
+ [ ! -d "$REPO/.git/rebase-merge" ]
+ [ ! -d "$REPO/.git/rebase-apply" ]
+ # the local change survives as a commit for the human to resolve later
+ git -C "$REPO" log --format=%s | grep -q "auto-sync"
+}
+
+@test "missing repo path: exits nonzero with a message" {
+ run "$SCRIPT" "$BATS_TEST_TMPDIR/nonexistent"
+ [ "$status" -ne 0 ]
+ [[ "$output" == *"not a git repo"* ]]
+}