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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ jobs:
sudo apt-get install -y --no-install-recommends zsh

- name: Run Bats tests
run: uv run bats --print-output-on-failure tests/esa/zsh.bats tests/moshi/update_moshi_hook.bats tests/codex/update_codex.bats
# Discovery keeps new files in CI; files tagged macos need a macOS host and are excluded.
run: uv run bats --recursive --filter-tags '!macos' --print-output-on-failure tests

- name: Run Python integration tests
# The installed macOS popup profile is checked locally; static TOML checks run on Linux.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ uv run --frozen pytest
nix flake check
```

Bats files that need a macOS host or builder, such as ones that build the
aarch64-darwin Home Manager configuration, carry `# bats file_tags=macos` and a
comment stating why. Put such tests in their own file (for example
`<name>_macos.bats`) so the tag applies to the whole file. CI runs
`bats --recursive --filter-tags '!macos' tests`, so an untagged file must pass on
Linux, while `bats --recursive tests` on a Mac runs everything.

CI checks shell integration with Bats and checks Python automation with Ruff, ty,
and pytest. Tests marked `integration` run in the Bats job; other pytest tests run
separately without duplicating those cases.
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
shellPkgs.actionlint
shellPkgs.bats
shellPkgs.commitlint
# Headless Neovim runs the esa and LSP Bats specs on Linux.
shellPkgs.neovim
# lefthook before 2.1.6 runs hooks under a pty, which agent sandboxes deny.
shellUnstable.lefthook
# Same uv and Python as the Home Manager profile; Nix owns the interpreter, uv owns dependencies.
Expand Down
8 changes: 5 additions & 3 deletions tests/esa/format.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bats
# Tests Markdown formatting used for esa posts.

bats_require_minimum_version 1.5.0

setup() {
load test-helper/setup
}
Expand All @@ -10,14 +12,14 @@ format_markdown() {
}

@test "Markdown formatting preserves line breaks in esa prose" {
run format_markdown < <(printf 'こんにちは.\nこんばんは.\n')
run --separate-stderr format_markdown < <(printf 'こんにちは.\nこんばんは.\n')

[ "$status" -eq 0 ]
[ "$output" = $'こんにちは.\nこんばんは.' ]
}

@test "Markdown formatting indents nested lists by four spaces" {
run format_markdown < <(printf -- '- parent\n - child\n')
run --separate-stderr format_markdown < <(printf -- '- parent\n - child\n')

[ "$status" -eq 0 ]
[ "$output" = $'- parent\n - child' ]
Expand All @@ -27,7 +29,7 @@ format_markdown() {
local _outside="$BATS_TEST_TMPDIR/outside/post.md"
mkdir -p "${_outside%/*}"

run dprint fmt --config "$REPO_ROOT/dprint/dprint.json" --stdin "$_outside" < <(printf -- '- parent\n - child\n')
run --separate-stderr dprint fmt --config "$REPO_ROOT/dprint/dprint.json" --stdin "$_outside" < <(printf -- '- parent\n - child\n')

[ "$status" -eq 0 ]
[ "$output" = $'- parent\n - child' ]
Expand Down
4 changes: 2 additions & 2 deletions tests/esa/nvim.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setup() {
ESA_EDIT_POST_NUMBER=1515 \
ESA_EDIT_FILE="$ARTICLE_FILE" \
XDG_DATA_HOME="$NVIM_DATA_HOME" \
nvim --headless -u "$REPO_ROOT/nvim/init.lua" \
nvim --headless --cmd "set runtimepath^=$REPO_ROOT/nvim,$NVIM_DATA_HOME/nvim/lazy/lazy.nvim" -u "$REPO_ROOT/nvim/init.lua" \
"$ARTICLE_FILE" \
-c "call setline(1, '# After')" \
-c write \
Expand All @@ -32,7 +32,7 @@ setup() {
ESA_EDIT_POST_NUMBER=1515 \
ESA_EDIT_FILE="$ARTICLE_FILE" \
XDG_DATA_HOME="$NVIM_DATA_HOME" \
nvim --headless -u "$REPO_ROOT/nvim/init.lua" \
nvim --headless --cmd "set runtimepath^=$REPO_ROOT/nvim,$NVIM_DATA_HOME/nvim/lazy/lazy.nvim" -u "$REPO_ROOT/nvim/init.lua" \
"$other_file" \
-c "call setline(1, '# Changed')" \
-c write \
Expand Down
3 changes: 3 additions & 0 deletions tests/herdr/herdr_command.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bats
# Executable specifications for Nix-managed Herdr command helpers.
# macOS only: builds the aarch64-darwin Home Manager configuration, which needs a macOS host or builder.
# bats file_tags=macos


bats_require_minimum_version 1.5.0

Expand Down
3 changes: 3 additions & 0 deletions tests/nix/agent_hook.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bats
# Executable specifications for external agent hook composition.
# macOS only: builds the aarch64-darwin Home Manager activation package, which needs a macOS host or builder.
# bats file_tags=macos


bats_require_minimum_version 1.5.0

Expand Down
3 changes: 3 additions & 0 deletions tests/nix/codex_notification.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Codex delegates terminal notifications only when launched inside Herdr.
# Bats isolates each test's environment.
# shellcheck disable=SC2030,SC2031
# macOS only: builds the codex package for aarch64-darwin, which needs a macOS host or builder.
# bats file_tags=macos


setup_file() {
local _repo_root _derivation _package
Expand Down
3 changes: 3 additions & 0 deletions tests/nix/configuration.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bats
# The hook's Bats entry point delegates declarative contracts to native flake checks.
# macOS only: builds the aarch64-darwin flake checks, which need a macOS host or builder.
# bats file_tags=macos


bats_require_minimum_version 1.5.0

Expand Down
4 changes: 2 additions & 2 deletions tests/ssh-agent/load_identity.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ evaluate_ssh_directory_permissions() {
[ "$status" -eq 0 ]
[ -f "$BATS_TEST_TMPDIR/home/.ssh/existing-file" ]

run /usr/bin/stat -f "%Lp" "$BATS_TEST_TMPDIR/home/.ssh"
run find "$BATS_TEST_TMPDIR/home/.ssh" -maxdepth 0 -perm 0700

[ "$status" -eq 0 ]
[ "$output" = "700" ]
[ "$output" = "$BATS_TEST_TMPDIR/home/.ssh" ]
}

@test "home activation reports a missing SSH public key" {
Expand Down
3 changes: 3 additions & 0 deletions tests/terminal-browser/terminal_browser.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bats
# Executable specifications for the terminal-browser package.
# macOS only: runs the darwin-arm64 terminal-browser binary.
# bats file_tags=macos


bats_require_minimum_version 1.5.0

Expand Down
3 changes: 3 additions & 0 deletions tests/zsh/ssh_agent.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bats
# Interactive Zsh points SSH_AUTH_SOCK at the user's 1Password agent, never at another local agent.
# macOS only: zsh/.zshrc attaches the 1Password agent and validates its socket only when OSTYPE is darwin,
# so every case here would pass vacuously on Linux.
# bats file_tags=macos

setup() {
REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
Expand Down
17 changes: 0 additions & 17 deletions tests/zsh/startup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,3 @@ run_startup_path() {
print -rl -- "${path[@]}"
'
}

@test "Home Manager activation invokes the packaged Zsh cache builder" {
run --separate-stderr nix build --no-link --print-out-paths \
"$TEST_FLAKE#homeConfigurations.\"kaito@mbp\".activationPackage"

if [ "$status" -ne 0 ]; then
printf '%s\n' "$stderr" >&2
fi
[ "$status" -eq 0 ]

local _activation_package="$output"
[ -f "$_activation_package/activate" ]
local _builder
_builder="$(grep -Eo '/nix/store/[^"[:space:]]+-build_cache[.]zsh' "$_activation_package/activate" | head -n 1)"
[ -f "$_builder" ]
cmp --silent "$REPO_ROOT/zsh/build_cache.zsh" "$_builder"
}
28 changes: 28 additions & 0 deletions tests/zsh/startup_macos.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bats
# Executable specifications for Zsh startup behavior that needs the darwin Home Manager build.
# macOS only: builds the aarch64-darwin Home Manager activation package, which needs a macOS host or builder.
# bats file_tags=macos

bats_require_minimum_version 1.5.0

setup() {
REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
TEST_FLAKE="${DOTFILES_TEST_FLAKE:-$REPO_ROOT}"
}

@test "Home Manager activation invokes the packaged Zsh cache builder" {
run --separate-stderr nix build --no-link --print-out-paths \
"$TEST_FLAKE#homeConfigurations.\"kaito@mbp\".activationPackage"

if [ "$status" -ne 0 ]; then
printf '%s\n' "$stderr" >&2
fi
[ "$status" -eq 0 ]

local _activation_package="$output"
[ -f "$_activation_package/activate" ]
local _builder
_builder="$(grep -Eo '/nix/store/[^"[:space:]]+-build_cache[.]zsh' "$_activation_package/activate" | head -n 1)"
[ -f "$_builder" ]
cmp --silent "$REPO_ROOT/zsh/build_cache.zsh" "$_builder"
}
Loading