Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 6 | VCS=${1:-$(cd "$(dirname "$0")/.." && pwd)/target/debug/vcs} |
| 7 | WORK=$(mktemp -d) |
| 8 | export VCS_HOME="$WORK/home" VCS_NAME="Test Person" VCS_EMAIL="test@example.com" VCS_SAVER=0 |
| 9 | trap 'rm -rf "$WORK"' EXIT |
| 10 | cd "$WORK" |
| 11 |
| 12 | pass=0 |
| 13 | fail=0 |
| 14 | check() { # name, command... |
| 15 | local name=$1 |
| 16 | shift |
| 17 | if "$@" >/dev/null 2>&1; then pass=$((pass + 1)); else fail=$((fail + 1)); echo "FAIL: $name"; fi |
| 18 | } |
| 19 | code() { # expected exit code, command... |
| 20 | local want=$1 |
| 21 | shift |
| 22 | "$@" >/dev/null 2>&1 |
| 23 | [ "$?" = "$want" ] |
| 24 | } |
| 25 | json() { "$VCS" --json "$@" 2>/dev/null; } |
| 26 |
| 27 | # A new project with a first version. |
| 28 | mkdir app && cd app |
| 29 | printf 'hello\n' > README.md |
| 30 | mkdir src && printf 'a\nb\nc\nd\ne\nf\ng\n' > src/lib.txt |
| 31 | printf '{\n "name": "app"\n}\n' > package.json |
| 32 | printf 'SECRET=1\n' > .env |
| 33 | check "init" "$VCS" init |
| 34 | check "land first version" "$VCS" land -m "First version" |
| 35 | check "main is version 1" test "$(json log | python3 -c 'import json,sys; print(json.load(sys.stdin)["versions"][0]["n"])')" = 1 |
| 36 | check ".env never landed" test -z "$(json log 1 | python3 -c 'import json,sys; print([f for f in json.load(sys.stdin)["files"] if ".env" in f] or "")')" |
| 37 | check "empty land refused (exit 1)" code 1 "$VCS" land -m "Nothing" |
| 38 |
| 39 | # A second workspace gets the files and the .env. |
| 40 | cd "$WORK" |
| 41 | check "get second workspace" "$VCS" get ./app app2 |
| 42 | check "files arrived" test "$(cat app2/src/lib.txt | head -1)" = a |
| 43 | check ".env came along" test "$(cat app2/.env)" = "SECRET=1" |
| 44 |
| 45 | # Parallel edits to different files both land, in any order. |
| 46 | printf 'hello there\n' > app/README.md |
| 47 | printf 'a\nb\nc\nd\ne\nf\nG\n' > app2/src/lib.txt |
| 48 | check "land from app" "$VCS" -C app land -m "Greet better" |
| 49 | check "land from app2 without syncing" "$VCS" -C app2 land -m "Capital G" |
| 50 | check "main is version 3" test "$(json -C app log | python3 -c 'import json,sys; print(json.load(sys.stdin)["versions"][0]["n"])')" = 3 |
| 51 |
| 52 | # JSON files merge by key. |
| 53 | cd "$WORK" && "$VCS" -C app sync >/dev/null 2>&1 && "$VCS" -C app2 sync >/dev/null 2>&1 |
| 54 | printf '{\n "name": "app",\n "version": "1.0.0"\n}\n' > app/package.json |
| 55 | printf '{\n "name": "app",\n "license": "MIT"\n}\n' > app2/package.json |
| 56 | check "land json key A" "$VCS" -C app land -m "Add version" |
| 57 | check "land json key B (merged by key)" "$VCS" -C app2 land -m "Add license" |
| 58 | "$VCS" -C app sync >/dev/null 2>&1 |
| 59 | check "both keys on main" python3 -c 'import json; d=json.load(open("app/package.json")); assert d["version"]=="1.0.0" and d["license"]=="MIT"' |
| 60 |
| 61 | # A real conflict: land refuses, sync marks it, fixing it lands. |
| 62 | "$VCS" -C app2 sync >/dev/null 2>&1 |
| 63 | perl -pi -e 's/^b$/B from app/' app/src/lib.txt |
| 64 | perl -pi -e 's/^b$/B from app2/' app2/src/lib.txt |
| 65 | check "land A" "$VCS" -C app land -m "B from app" |
| 66 | check "land B conflicts (exit 3)" code 3 "$VCS" -C app2 land -m "B from app2" |
| 67 | check "sync leaves markers (exit 3)" code 3 "$VCS" -C app2 sync |
| 68 | check "markers in file" grep -q '<<<<<<< main' app2/src/lib.txt |
| 69 | check "land refused while markers remain" code 3 "$VCS" -C app2 land |
| 70 | python3 - "$WORK/app2/src/lib.txt" <<'EOF' |
| 71 | import sys, re |
| 72 | p = sys.argv[1] |
| 73 | t = open(p).read() |
| 74 | t = re.sub(r"<<<<<<< [^\n]*\n(.*?)=======\n(.*?)>>>>>>> [^\n]*\n", lambda m: "B from both\n", t, flags=re.S) |
| 75 | open(p, "w").write(t) |
| 76 | EOF |
| 77 | check "land after fixing (reuses description)" "$VCS" -C app2 land |
| 78 | check "status clean after land" test "$(json -C app2 status | python3 -c 'import json,sys; print(len(json.load(sys.stdin)["files"]))')" = 0 |
| 79 |
| 80 | # Undo a land: main gets a version that takes it back out. |
| 81 | cd "$WORK/app" |
| 82 | "$VCS" sync >/dev/null 2>&1 |
| 83 | printf 'oops\n' > oops.txt |
| 84 | check "land oops" "$VCS" land -m "Oops" |
| 85 | check "undo the land" "$VCS" undo |
| 86 | check "oops is open again" test "$(json status | python3 -c 'import json,sys; print(json.load(sys.stdin)["change"]["state"])')" = open |
| 87 | check "main took it back" test "$(json log -n 1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["versions"][0]["title"][:13])')" = "Take back mai" |
| 88 | check "drop it" "$VCS" drop |
| 89 | check "undo the drop" "$VCS" undo |
| 90 | check "drop again" "$VCS" drop |
| 91 |
| 92 | # Restore a file from an earlier save. |
| 93 | printf 'v1\n' > notes.txt |
| 94 | "$VCS" status >/dev/null 2>&1 |
| 95 | sleep 3 |
| 96 | printf 'broken\n' > notes.txt |
| 97 | "$VCS" status >/dev/null 2>&1 |
| 98 | check "restore --at" "$VCS" restore notes.txt --at "2s ago" |
| 99 | check "notes is v1" test "$(cat notes.txt)" = v1 |
| 100 | check "undo the restore" "$VCS" undo |
| 101 | check "notes is broken again" test "$(cat notes.txt)" = broken |
| 102 | check "restore to base (removes the new file)" "$VCS" restore notes.txt |
| 103 | check "notes gone" test ! -e notes.txt |
| 104 |
| 105 | # New, switch, stacks. |
| 106 | printf 'feature a\n' > a.txt |
| 107 | check "describe" "$VCS" describe "Feature A" |
| 108 | A=$(json status | python3 -c 'import json,sys; print(json.load(sys.stdin)["change"]["id"])') |
| 109 | check "new stacked on A" "$VCS" new "Feature B" --on "$A" |
| 110 | printf 'feature b\n' > b.txt |
| 111 | check "a.txt visible in B" test -e a.txt |
| 112 | check "switch back to A" "$VCS" switch "${A:0:6}" |
| 113 | check "b.txt gone in A" test ! -e b.txt |
| 114 | check "undo switch" "$VCS" undo |
| 115 | check "b.txt back" test -e b.txt |
| 116 | check "land B lands A then B" "$VCS" land |
| 117 | check "main has both" test "$(json log -n 2 | python3 -c 'import json,sys; print(",".join(v["title"] for v in json.load(sys.stdin)["versions"]))')" = "Feature B,Feature A" |
| 118 |
| 119 | # Secrets don't land. |
| 120 | printf 'const key = "sk_live_%s";\n' "$(printf 'x%.0s' {1..24})" > pay.js |
| 121 | check "secret refused (exit 8)" code 8 "$VCS" land -m "Payments" |
| 122 | rm pay.js |
| 123 | printf 'const key = process.env.STRIPE_KEY;\n' > pay.js |
| 124 | check "lands without the secret" "$VCS" land -m "Payments" |
| 125 |
| 126 | # No description. |
| 127 | printf 'x\n' > x.txt |
| 128 | check "no description (exit 2)" code 2 "$VCS" land |
| 129 | check "describe then land" "$VCS" land -m "Add x" |
| 130 |
| 131 | # Diff and log output. |
| 132 | printf 'y\n' > x.txt |
| 133 | check "diff shows the edit" sh -c "\"$VCS\" diff | grep -q '^+y'" |
| 134 | check "log --saves" "$VCS" log --saves |
| 135 | check "log --ops" "$VCS" log --ops |
| 136 | check "log --changes" "$VCS" log --changes |
| 137 | check "guide" sh -c "\"$VCS\" guide | grep -q 'vcs land'" |
| 138 |
| 139 | # Deleting a workspace is deleting its folder; a new one can take its place. |
| 140 | cd "$WORK" |
| 141 | check "get a third workspace" "$VCS" get ./app app3 |
| 142 | rm -rf app3 |
| 143 | check "get again at the same path" "$VCS" get ./app app3 |
| 144 | cd "$WORK/app" |
| 145 |
| 146 | # Mine: vcs access <path> me. |
| 147 | printf 'token\n' > secrets.local |
| 148 | check "access me" "$VCS" access secrets.local me |
| 149 | check "mine stays out of the change" sh -c "! \"$VCS\" --json status | grep -q secrets.local" |
| 150 |
| 151 | # An agent each: workspaces added next to this one, and cleaned up once done. |
| 152 | check "add a workspace" "$VCS" workspaces add ../agent1 |
| 153 | check "it has main's files" test -f ../agent1/README.md |
| 154 | printf 'parent work\n' > parent.txt |
| 155 | check "add one on this change" "$VCS" workspaces add ../sub1 --on . |
| 156 | check "it starts from this change's work" test -f ../sub1/parent.txt |
| 157 | check "the list has them" sh -c "'$VCS' workspaces | grep -q agent1 && '$VCS' workspaces | grep -q sub1" |
| 158 | printf 'agent work\n' > ../agent1/agent.txt && printf 'sub work\n' > ../sub1/sub.txt |
| 159 | check "clean (nothing idle long enough)" "$VCS" workspaces clean |
| 160 | check "keeps them all" test -d ../agent1 -a -d ../sub1 -a -d ../app2 |
| 161 | check "clean, no idle time" "$VCS" workspaces clean --idle 0s |
| 162 | check "keeps work that hasn't landed" test -f ../agent1/agent.txt -a -f ../sub1/sub.txt |
| 163 | check "removes a workspace whose change was empty" test ! -e ../app3 |
| 164 | check "never this one" test -d .vcs |
| 165 | check "agent1 lands" "$VCS" -C ../agent1 land -m "Agent work" |
| 166 | check "clean again" "$VCS" workspaces clean --idle 0s |
| 167 | check "removes it once its work landed" test ! -e ../agent1 |
| 168 | check "and forgets it" sh -c "! '$VCS' workspaces | grep -q agent1" |
| 169 | check "main has its work" sh -c "'$VCS' sync >/dev/null && test -f agent.txt" |
| 170 |
| 171 | echo "local: $pass passed, $fail failed" |
| 172 | [ "$fail" = 0 ] |
| 173 |