AtlatestRepositoryslate

slate / tree / scriptscheck-git-hunk-mutations

1#!/usr/bin/env bash
2set -euo pipefail
3root=$(cd "$(dirname "$0")/.." && pwd)
4dispatch="$root/packages/slate-cli/src/slate-cli/dispatch.sgl"
5node="$root/packages/slate-cli/src/slate-cli/git/mutation.sgl"
6commands="$root/packages/slate/src/slate/commands/git.sgl"
7mode="$root/packages/slate/src/slate/modes/git-status.sgl"
8model="$root/packages/slate/src/slate/git/model.sgl"
9node_test="$root/packages/slate-cli/test/test-git-hunk-mutations.sgl"
10for file in "$dispatch" "$node" "$commands" "$mode" "$model" "$node_test"; do
11 [ -f "$file" ] || { echo "SETUP-FAILED git-hunk-mutations: missing $file" >&2; exit 2; }
12done
13for verb in git/stage-hunk git/unstage-hunk; do
14 rg -qF "\"$verb\"" "$dispatch" || { echo "git-hunk-mutations: missing dispatch $verb" >&2; exit 1; }
15 rg -qF "\"$verb\"" "$commands" || { echo "git-hunk-mutations: missing client $verb" >&2; exit 1; }
16done
17rg -qF '(patch-hunks text side file-id)' "$node" || { echo 'git-hunk-mutations: node reconstruction missing' >&2; exit 1; }
18rg -qF '(snapshot=? expected latest)' "$node" || { echo 'mutation accepted stale snapshot' >&2; exit 1; }
19rg -qF 'GIT_INDEX_FILE=' "$node" || { echo 'git-hunk-mutations: isolated candidate index missing' >&2; exit 1; }
20rg -qF 'hunk-id: hunk-id' "$model" || { echo 'git-hunk-mutations: structured hunk request missing' >&2; exit 1; }
21if rg -qF 'patch: patch' "$model" "$commands"; then
22 echo 'git-hunk-mutations: rendered patch crossed client boundary' >&2; exit 1
23fi
24for family in git-select-stage: git-select-unstage:; do
25 rg -qF "$family" "$mode" || { echo "git-hunk-mutations: pointer family missing $family" >&2; exit 1; }
26done
27cache=$(mktemp -d)
28log=$(mktemp)
29source "$root/scripts/lib/slate-harness.sh"
30trap 'rm -rf "$cache"; rm -f "$log"' EXIT
31if ! XDG_CACHE_HOME="$cache" sigil test slate-cli --sgl --no-color "$node_test" >"$log" 2>&1; then
32 if rg -qF 'stage the exact non-first worktree hunk and unstage its exact index hunk' "$log"; then
33 echo 'wrong hunk staged' >&2
34 fi
35 cat "$log" >&2; exit 1
36fi
37harness_verdict "$log" 1
38if ! XDG_CACHE_HOME="$cache" sigil test slate --sgl --no-color \
39 "$root/packages/slate/test/git-status-view-test.sgl" \
40 "$root/packages/slate/test/git-status-model-test.sgl" \
41 "$root/packages/slate/test/diff-control-test.sgl" >"$log" 2>&1; then
42 cat "$log" >&2; exit 1
43fi
44harness_verdict "$log" 3
45echo 'PASS git-hunk-mutations: node reconstruction; atomic partial index; keyboard/pointer parity'