@@ -129,11 +129,13 @@ setup() {
129129 export HOME=" $WORK /home"
130130 export XDG_STATE_HOME=" $WORK /state"
131131 export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null
132+ export GIT_ALLOW_PROTOCOL=file GIT_TERMINAL_PROMPT=0
132133 export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
133134 mkdir -p " $HOME " " $WORK /src" " $WORK /stub"
134135 # The EXIT trap starts timers; keep it off the host's systemd user manager.
135136 printf ' #!/usr/bin/env bash\nexit 0\n' > " $WORK /stub/systemctl"
136- chmod +x " $WORK /stub/systemctl"
137+ printf ' #!/usr/bin/env bash\necho "Filesystem 1024-blocks Used Available Capacity Mounted on"\necho "/dev/sda1 400000000 300000000 70000000 80%% /"\n' > " $WORK /stub/df"
138+ chmod +x " $WORK /stub/systemctl" " $WORK /stub/df"
137139 export PATH=" $WORK /stub:$PATH "
138140 git -C " $WORK /src" init -q -b main
139141 mkdir -p " $WORK /src/home-manager/activation"
@@ -314,6 +316,108 @@ The output should include 'Changes detected'
314316The error should include ' Checkout changed during installation'
315317The file " $XDG_STATE_HOME /dotfiles-updater/installed-commit" should not be exist
316318End
319+
320+ Describe ' automated Kamino disk headroom'
321+ It ' defers a local activation build below the required headroom without advancing the marker'
322+ printf ' #!/usr/bin/env bash\necho "Filesystem 1024-blocks Used Available Capacity Mounted on"\necho "/dev/sda1 400000000 350000000 55000000 88%% /"\n' > " $WORK /stub/df"
323+ cat > " $WORK /stub/nix" << 'NIX '
324+ #!/usr/bin/env bash
325+ expected='--offline --extra-experimental-features nix-command flakes path-info --recursive --impure --no-update-lock-file .#homeConfigurations.kamino4.activationPackage'
326+ if [[ "$*" != "$expected" ]]; then
327+ echo "unexpected nix arguments: $*" >&2
328+ exit 2
329+ fi
330+ exit 1
331+ NIX
332+ printf ' #!/usr/bin/env bash\ntouch "$HOME/make-called"\n' > " $WORK /stub/make"
333+ chmod +x " $WORK /stub/df" " $WORK /stub/nix"
334+ chmod +x " $WORK /stub/make"
335+ cat > " $WORK /retry.sh" << 'RETRY '
336+ #!/usr/bin/env bash
337+ set -euo pipefail
338+ script_path=$1
339+ workspace=$2
340+ export PATH="$workspace/stub:$PATH"
341+ export AUTOMATED_UPDATE=true HOST=kamino4
342+ bash "$script_path" >"$workspace/deferred.log" 2>&1
343+ test ! -f "$XDG_STATE_HOME/dotfiles-updater/installed-commit"
344+ test ! -f "$HOME/make-called"
345+ expected_commit=$(git -C "$HOME/dotfiles" rev-parse HEAD)
346+ printf '#!/usr/bin/env bash\necho "Filesystem 1024-blocks Used Available Capacity Mounted on"\necho "/dev/sda1 400000000 300000000 70000000 80%% /"\n' >"$workspace/stub/df"
347+ bash "$script_path" >"$workspace/retried.log" 2>&1
348+ test "$(cat "$XDG_STATE_HOME/dotfiles-updater/installed-commit")" = "$expected_commit"
349+ cat "$workspace/deferred.log" "$workspace/retried.log"
350+ echo retried-same-commit
351+ RETRY
352+ chmod +x " $WORK /retry.sh"
353+ When run bash " $WORK /retry.sh" " $SCRIPT " " $WORK "
354+ The status should be success
355+ The output should include ' Deferring automated Kamino install'
356+ The output should include ' Changes detected'
357+ The output should include ' retried-same-commit'
358+ End
359+
360+ It ' defers below the executor reserve without querying or installing Nix paths'
361+ printf ' #!/usr/bin/env bash\necho "Filesystem 1024-blocks Used Available Capacity Mounted on"\necho "/dev/sda1 400000000 360000000 40000000 90%% /"\n' > " $WORK /stub/df"
362+ printf ' #!/usr/bin/env bash\ntouch "$HOME/nix-called"\nexit 0\n' > " $WORK /stub/nix"
363+ printf ' #!/usr/bin/env bash\ntouch "$HOME/make-called"\n' > " $WORK /stub/make"
364+ chmod +x " $WORK /stub/df" " $WORK /stub/nix" " $WORK /stub/make"
365+ When run env PATH=" $WORK /stub:$PATH " AUTOMATED_UPDATE=true HOST=kamino4 bash " $SCRIPT "
366+ The status should be success
367+ The output should include ' Changes detected'
368+ The error should include ' From '
369+ The error should include ' 38 GiB free is below the 42 GiB executor reserve'
370+ The file " $HOME /nix-called" should not be exist
371+ The file " $HOME /make-called" should not be exist
372+ The file " $XDG_STATE_HOME /dotfiles-updater/installed-commit" should not be exist
373+ End
374+
375+ It ' applies a store-resident activation with local Nix builds disabled below the build threshold'
376+ printf ' #!/usr/bin/env bash\necho "Filesystem 1024-blocks Used Available Capacity Mounted on"\necho "/dev/sda1 400000000 350000000 55000000 88%% /"\n' > " $WORK /stub/df"
377+ cat > " $WORK /stub/nix" << 'NIX '
378+ #!/usr/bin/env bash
379+ expected='--offline --extra-experimental-features nix-command flakes path-info --recursive --impure --no-update-lock-file .#homeConfigurations.kamino4.activationPackage'
380+ if [[ "$*" != "$expected" ]]; then
381+ echo "unexpected nix arguments: $*" >&2
382+ exit 2
383+ fi
384+ NIX
385+ cat > " $WORK /stub/make" << 'MAKE '
386+ #!/usr/bin/env bash
387+ if [ "$1" = install ]; then
388+ last_config_line=${NIX_CONFIG##*$'\n'}
389+ if [[ "$NIX_CONFIG" != *"trusted-users = root"* || "$last_config_line" != "max-jobs = 0" ]]; then
390+ echo "expected cache-only build setting" >&2
391+ exit 1
392+ fi
393+ touch "$HOME/installed"
394+ fi
395+ MAKE
396+ chmod +x " $WORK /stub/df" " $WORK /stub/nix" " $WORK /stub/make"
397+ When run env PATH=" $WORK /stub:$PATH " AUTOMATED_UPDATE=true HOST=kamino4 NIX_CONFIG=" $( printf ' trusted-users = root\nmax-jobs = 8' ) " bash " $SCRIPT "
398+ The status should be success
399+ The output should include ' Changes detected'
400+ The output should include ' Applying the store-resident Kamino activation with local Nix builds disabled'
401+ The error should include ' From '
402+ The file " $HOME /installed" should be exist
403+ The file " $XDG_STATE_HOME /dotfiles-updater/installed-commit" should be exist
404+ End
405+
406+ It ' allows a manual updater run to build below the automated headroom threshold'
407+ printf ' #!/usr/bin/env bash\necho "Filesystem 1024-blocks Used Available Capacity Mounted on"\necho "/dev/sda1 400000000 350000000 50000000 89%% /"\n' > " $WORK /stub/df"
408+ cat > " $WORK /stub/make" << 'MAKE '
409+ #!/usr/bin/env bash
410+ if [ "$1" = install ]; then touch "$HOME/installed"; fi
411+ MAKE
412+ chmod +x " $WORK /stub/df" " $WORK /stub/make"
413+ When run env PATH=" $WORK /stub:$PATH " HOST=kamino4 bash " $SCRIPT "
414+ The status should be success
415+ The output should include ' Changes detected'
416+ The error should include ' From '
417+ The file " $HOME /installed" should be exist
418+ The file " $XDG_STATE_HOME /dotfiles-updater/installed-commit" should be exist
419+ End
420+ End
317421End
318422
319423Describe ' cliproxy service PATH'
0 commit comments