@sebastienrousseau/dotfiles 0.2.481 → 0.2.499
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/ARCHITECTURE.md +29 -196
- package/docs/COMPLIANCE.md +10 -10
- package/docs/COPYRIGHT +3 -4
- package/docs/OPERATIONS.md +38 -65
- package/docs/PLAN.md +3 -3
- package/docs/PR_DESCRIPTION.md +85 -84
- package/docs/ROADMAP.md +11 -11
- package/docs/ROADMAP_legacy.md +556 -0
- package/docs/SECURITY_CHECKLIST.md +1 -1
- package/docs/TASK.md +4 -4
- package/docs/WALKTHROUGH.md +33 -152
- package/package.json +17 -5
- package/scripts/backup.sh +142 -0
- package/scripts/banner.sh +20 -0
- package/scripts/benchmark.sh +20 -0
- package/scripts/build.sh +41 -0
- package/scripts/clean.sh +31 -0
- package/scripts/compile.sh +54 -0
- package/scripts/copy.sh +108 -0
- package/scripts/{tools/detect-collisions.py → detect-collisions.py} +1 -1
- package/scripts/doctor.sh +79 -0
- package/scripts/dotfiles.sh +63 -0
- package/scripts/download.sh +35 -0
- package/scripts/help.sh +57 -0
- package/scripts/lock-configs.sh +57 -0
- package/scripts/package.sh +46 -0
- package/scripts/ssh.sh +55 -0
- package/scripts/teleport.sh +23 -0
- package/scripts/{tests/test-aliases.sh → test-aliases.sh} +3 -3
- package/scripts/test_smoke.sh +88 -0
- package/scripts/unpack.sh +28 -0
- package/scripts/{diagnostics/verify_state.sh → verify_state.sh} +21 -21
- package/templates/projects/go/README.md +0 -4
- package/templates/projects/node/README.md +0 -4
- package/templates/projects/python/README.md +0 -4
- package/templates/projects/python/pyproject.toml +0 -15
- package/CHANGELOG.md +0 -285
- package/LICENSE +0 -1283
- package/README.md +0 -315
- package/docs/ALIASES.md +0 -128
- package/docs/FEATURES.md +0 -166
- package/docs/FONTS.md +0 -147
- package/docs/INSTALL.md +0 -119
- package/docs/KEYS.md +0 -40
- package/docs/KEY_ROTATION.md +0 -219
- package/docs/LEGACY_ROADMAP.md +0 -142
- package/docs/NEOVIM_IDE_GUIDE.md +0 -52
- package/docs/README.md +0 -269
- package/docs/REPO_AUDIT.md +0 -23
- package/docs/SCREENSHOTS.md +0 -116
- package/docs/SECRETS.md +0 -76
- package/docs/SECURITY.md +0 -30
- package/docs/TESTING.md +0 -190
- package/docs/TOOLS.md +0 -146
- package/docs/TROUBLESHOOTING.md +0 -112
- package/docs/UTILS.md +0 -105
- package/docs/WSL2_NIX_TROUBLESHOOTING.md +0 -723
- package/docs/adr/ADR-001-ci-cd-pipeline.md +0 -101
- package/docs/adr/ADR-002-shell-performance.md +0 -121
- package/docs/adr/ADR-003-security-first.md +0 -140
- package/docs/adr/ADR-004-cli-architecture.md +0 -157
- package/docs/adr/ADR-005-chezmoi-choice.md +0 -89
- package/docs/adr/ADR-006-shell-selection.md +0 -115
- package/docs/adr/README.md +0 -33
- package/docs/themes/README.md +0 -20
- package/dot_config/aider/aider.conf.yml +0 -32
- package/dot_config/alacritty/alacritty.toml.tmpl +0 -483
- package/dot_config/ansible/ansible.cfg.tmpl +0 -11
- package/dot_config/atuin/config.toml +0 -23
- package/dot_config/bat/config +0 -8
- package/dot_config/brave-flags.conf.tmpl +0 -7
- package/dot_config/btop/btop.conf +0 -16
- package/dot_config/btop/themes/tokyonight.theme +0 -34
- package/dot_config/bun/bunfig.toml.tmpl +0 -33
- package/dot_config/claude/mcp_servers.json +0 -49
- package/dot_config/clippy.toml +0 -55
- package/dot_config/containers/containers.conf +0 -14
- package/dot_config/curl/dot_curlrc +0 -18
- package/dot_config/dlv/config.yml +0 -39
- package/dot_config/docker/config.json.tmpl +0 -15
- package/dot_config/dotfiles/boot/README.md +0 -11
- package/dot_config/dotfiles/grub/README.md +0 -11
- package/dot_config/dotfiles/lock/README.md +0 -11
- package/dot_config/dotfiles/versions.env.tmpl +0 -19
- package/dot_config/duf/duf.conf +0 -6
- package/dot_config/duti/defaults.duti +0 -5
- package/dot_config/emoji/emoji.txt +0 -34
- package/dot_config/fastfetch/config.jsonc +0 -28
- package/dot_config/firefox/user.js +0 -8
- package/dot_config/flatpak/flatpak.list +0 -4
- package/dot_config/fontconfig/fonts.conf.tmpl +0 -44
- package/dot_config/gem/gemrc +0 -9
- package/dot_config/gh/config.yml +0 -12
- package/dot_config/ghostty/config.tmpl +0 -661
- package/dot_config/git/attributes +0 -12
- package/dot_config/git/config.tmpl +0 -77
- package/dot_config/git/ignore +0 -27
- package/dot_config/gnupg/gpg-agent.conf.tmpl +0 -11
- package/dot_config/go/aliases.sh +0 -61
- package/dot_config/go/env.sh +0 -24
- package/dot_config/go/golangci.yml +0 -118
- package/dot_config/go/gopls.json +0 -30
- package/dot_config/goose/config.yaml +0 -29
- package/dot_config/gtk-3.0/gtk.css.tmpl +0 -305
- package/dot_config/gtk-3.0/settings.ini.tmpl +0 -66
- package/dot_config/gtk-4.0/gtk.css.tmpl +0 -309
- package/dot_config/gtk-4.0/settings.ini.tmpl +0 -21
- package/dot_config/htop/htoprc +0 -20
- package/dot_config/ice/README.md +0 -13
- package/dot_config/inputrc +0 -2
- package/dot_config/ipython/profile_default/ipython_config.py.tmpl +0 -5
- package/dot_config/just/justfile +0 -104
- package/dot_config/k9s/config.yaml.tmpl +0 -65
- package/dot_config/k9s/skins/catppuccin-mocha.yaml +0 -116
- package/dot_config/karabiner/karabiner.json +0 -14
- package/dot_config/kitty/kitty.conf.tmpl +0 -517
- package/dot_config/lazydocker/config.yml +0 -186
- package/dot_config/lazygit/config.yml +0 -23
- package/dot_config/lsd/config.yaml +0 -19
- package/dot_config/mas/masapps.txt +0 -5
- package/dot_config/minikube/config.json +0 -13
- package/dot_config/mise/config.toml +0 -41
- package/dot_config/mongosh/mongoshrc.js +0 -67
- package/dot_config/mycli/myclirc +0 -67
- package/dot_config/nano/nanorc +0 -28
- package/dot_config/ncdu/config +0 -12
- package/dot_config/nvim/init.lua +0 -4
- package/dot_config/nvim/lazy-lock.json +0 -27
- package/dot_config/nvim/lua/config/autocmds.lua +0 -63
- package/dot_config/nvim/lua/config/keymaps.lua +0 -87
- package/dot_config/nvim/lua/config/lazy.lua +0 -34
- package/dot_config/nvim/lua/config/options.lua +0 -48
- package/dot_config/nvim/lua/plugins/coding.lua +0 -234
- package/dot_config/nvim/lua/plugins/dap.lua +0 -201
- package/dot_config/nvim/lua/plugins/editor.lua +0 -59
- package/dot_config/nvim/lua/plugins/git.lua +0 -9
- package/dot_config/nvim/lua/plugins/lsp.lua +0 -221
- package/dot_config/nvim/lua/plugins/markdown.lua +0 -17
- package/dot_config/nvim/lua/plugins/rust.lua +0 -33
- package/dot_config/nvim/lua/plugins/sessions.lua +0 -32
- package/dot_config/nvim/lua/plugins/ui.lua +0 -537
- package/dot_config/nvim/snippets/all.lua +0 -9
- package/dot_config/nvim/snippets/python.lua +0 -16
- package/dot_config/pip/pip.conf.tmpl +0 -32
- package/dot_config/pypoetry/config.toml.tmpl +0 -6
- package/dot_config/pyrightconfig.json.tmpl +0 -5
- package/dot_config/raycast/README.md +0 -13
- package/dot_config/redis/redisclirc +0 -41
- package/dot_config/shell/00-container-detect.sh +0 -53
- package/dot_config/shell/00-core-paths.sh.tmpl +0 -95
- package/dot_config/shell/05-core-safety.sh.tmpl +0 -13
- package/dot_config/shell/40-ls-colors.sh.tmpl +0 -31
- package/dot_config/shell/50-logic-functions.sh.tmpl +0 -10
- package/dot_config/shell/90-theme-switch.sh +0 -70
- package/dot_config/shell/90-ux-aliases.sh.tmpl +0 -35
- package/dot_config/shell/91-ux-aliases-lazy.sh.tmpl +0 -23
- package/dot_config/shell/Brewfile +0 -207
- package/dot_config/shell/Brewfile.cask +0 -92
- package/dot_config/shell/Brewfile.cli +0 -119
- package/dot_config/shell/README.md +0 -267
- package/dot_config/shell/custom/context_suggest.zsh +0 -68
- package/dot_config/shell/custom/error_analysis.zsh +0 -45
- package/dot_config/sops/dot_sops.yaml +0 -23
- package/dot_config/starship.toml.tmpl +0 -124
- package/dot_config/task/Taskfile.yml +0 -86
- package/dot_config/tflint/tflint.hcl.tmpl +0 -9
- package/dot_config/tmux/tmux.conf.tmpl +0 -181
- package/dot_config/topgrade/topgrade.toml.tmpl +0 -42
- package/dot_config/vscode/extensions.txt +0 -11
- package/dot_config/vscode/settings.json.tmpl +0 -123
- package/dot_config/waybar/style.css +0 -8
- package/dot_config/wezterm/wezterm.lua.tmpl +0 -236
- package/dot_config/wget/wgetrc +0 -12
- package/dot_config/yarn/yarnrc.yml.tmpl +0 -36
- package/dot_config/yazi/yazi.toml +0 -40
- package/dot_config/zellij/config.kdl +0 -79
- package/dot_config/zsh/dot_zprofile +0 -13
- package/dot_config/zsh/dot_zshenv +0 -6
- package/dot_config/zsh/dot_zshrc.tmpl +0 -199
- package/dot_config/zsh/rc.d/05-ssh-agent.zsh +0 -5
- package/dot_config/zsh/rc.d/10-env.zsh.tmpl +0 -28
- package/dot_config/zsh/rc.d/20-zinit.zsh.tmpl +0 -22
- package/dot_config/zsh/rc.d/30-options.zsh.tmpl +0 -123
- package/dot_config/zsh/rc.d/40-bell.zsh.tmpl +0 -20
- package/dot_config/zsh/rc.d/50-login-fortune.zsh.tmpl +0 -9
- package/dot_local/bin/executable_ai_core +0 -130
- package/dot_local/bin/executable_b64 +0 -59
- package/dot_local/bin/executable_dot +0 -178
- package/dot_local/bin/executable_dot_completion +0 -55
- package/dot_local/bin/executable_epoch +0 -62
- package/dot_local/bin/executable_extract +0 -108
- package/dot_local/bin/executable_git-ai-commit +0 -160
- package/dot_local/bin/executable_git-ai-diff +0 -154
- package/dot_local/bin/executable_hash +0 -123
- package/dot_local/bin/executable_hex +0 -79
- package/dot_local/bin/executable_ip +0 -37
- package/dot_local/bin/executable_jsonv +0 -54
- package/dot_local/bin/executable_jwt +0 -78
- package/dot_local/bin/executable_kill-port +0 -59
- package/dot_local/bin/executable_lorem +0 -103
- package/dot_local/bin/executable_regex +0 -96
- package/dot_local/bin/executable_tmux-sessionizer +0 -187
- package/dot_local/bin/executable_tour +0 -137
- package/dot_local/bin/executable_update +0 -108
- package/dot_local/bin/executable_uuid +0 -57
- package/dot_local/bin/executable_yamlv +0 -39
- package/dot_local/bin/executable_zig-install +0 -89
- package/dot_local/bin/voice_ops +0 -7
- package/dot_local/share/bash-completion/completions/dot +0 -54
- package/dot_local/share/zsh/completions/.keep +0 -0
- package/install.sh +0 -255
- package/scripts/ci/validate-ci-config.sh +0 -222
- package/scripts/demo/record.sh +0 -41
- package/scripts/diagnostics/benchmark.sh +0 -201
- package/scripts/diagnostics/doctor.sh +0 -115
- package/scripts/diagnostics/drift-dashboard.sh +0 -26
- package/scripts/diagnostics/health.sh +0 -356
- package/scripts/diagnostics/history-analysis.sh +0 -77
- package/scripts/diagnostics/security-score.sh +0 -392
- package/scripts/dot/commands/appearance.sh +0 -63
- package/scripts/dot/commands/core.sh +0 -130
- package/scripts/dot/commands/diagnostics.sh +0 -100
- package/scripts/dot/commands/meta.sh +0 -117
- package/scripts/dot/commands/restore.sh +0 -209
- package/scripts/dot/commands/secrets.sh +0 -81
- package/scripts/dot/commands/security.sh +0 -73
- package/scripts/dot/commands/tools.sh +0 -228
- package/scripts/dot/lib/utils.sh +0 -72
- package/scripts/fonts/install-nerd-fonts.sh +0 -59
- package/scripts/fonts/patch-fonts.sh +0 -34
- package/scripts/ops/chezmoi-apply.sh +0 -42
- package/scripts/ops/chezmoi-diff.sh +0 -14
- package/scripts/ops/chezmoi-remove.sh +0 -43
- package/scripts/ops/chezmoi-update.sh +0 -16
- package/scripts/ops/heal.sh +0 -466
- package/scripts/ops/health-check.sh +0 -380
- package/scripts/ops/rollback.sh +0 -531
- package/scripts/ops/teleport.sh +0 -32
- package/scripts/secrets/age-init.sh +0 -69
- package/scripts/secrets/create-secrets-file.sh +0 -44
- package/scripts/secrets/encrypt-ssh-key.sh +0 -42
- package/scripts/security/backup.sh +0 -17
- package/scripts/security/dns-doh.sh +0 -29
- package/scripts/security/encryption-check.sh +0 -39
- package/scripts/security/enforce-policies.sh +0 -339
- package/scripts/security/firewall.sh +0 -34
- package/scripts/security/lock-configs.sh +0 -57
- package/scripts/security/lock-screen.sh +0 -33
- package/scripts/security/manage-secrets.sh +0 -415
- package/scripts/security/telemetry-kill.sh +0 -28
- package/scripts/security/usb-safety.sh +0 -29
- package/scripts/tests/README.md +0 -241
- package/scripts/tests/benchmark.sh +0 -91
- package/scripts/tests/framework/assertions.sh +0 -283
- package/scripts/tests/framework/mocks.sh +0 -201
- package/scripts/tests/framework/test_runner.sh +0 -189
- package/scripts/tests/integration/test_install.sh +0 -237
- package/scripts/tests/performance/benchmark_runner.sh +0 -156
- package/scripts/tests/performance/regression_check.sh +0 -73
- package/scripts/tests/performance/stress_test.sh +0 -65
- package/scripts/tests/test-docker.sh +0 -48
- package/scripts/tests/unit/test_ai_aliases.sh +0 -158
- package/scripts/tests/unit/test_ai_cli_checks.sh +0 -47
- package/scripts/tests/unit/test_backup.sh +0 -227
- package/scripts/tests/unit/test_case_functions.sh +0 -238
- package/scripts/tests/unit/test_cd_aliases.sh +0 -367
- package/scripts/tests/unit/test_dot_cli.sh +0 -217
- package/scripts/tests/unit/test_encode64.sh +0 -67
- package/scripts/tests/unit/test_environment.sh +0 -78
- package/scripts/tests/unit/test_extract.sh +0 -163
- package/scripts/tests/unit/test_framework_edge_cases.sh +0 -113
- package/scripts/tests/unit/test_genpass.sh +0 -298
- package/scripts/tests/unit/test_install_edge_cases.sh +0 -167
- package/scripts/tests/unit/test_installers.sh +0 -172
- package/scripts/tests/unit/test_keygen.sh +0 -68
- package/scripts/tests/unit/test_logging.sh +0 -96
- package/scripts/tests/unit/test_os_detection_comprehensive.sh +0 -388
- package/scripts/tests/unit/test_package_managers_comprehensive.sh +0 -321
- package/scripts/tests/unit/test_prependpath.sh +0 -66
- package/scripts/tests/unit/test_prependpath_refactored.sh +0 -89
- package/scripts/tests/unit/test_rd.sh +0 -230
- package/scripts/tests/unit/test_security_fixes.sh +0 -130
- package/scripts/tests/unit/test_security_scripts.sh +0 -87
- package/scripts/tests/unit/test_template_validation.sh +0 -238
- package/scripts/tests/unit/test_utility_functions.sh +0 -144
- package/scripts/tests/unit/test_wave1_alias_split.sh +0 -132
- package/scripts/tests/unit/test_wave1_ci_pinning.sh +0 -61
- package/scripts/tests/unit/test_wave1_gitleaks_config.sh +0 -52
- package/scripts/tests/unit/test_wave1_heal_fixes.sh +0 -97
- package/scripts/tests/unit/test_wave1_install_gpg.sh +0 -35
- package/scripts/tests/unit/test_wave1_zshenv_path.sh +0 -89
- package/scripts/tests/unit/test_wave1_zshrc_lazy_hook.sh +0 -115
- package/scripts/tests/unit/test_wave2_dot_new_guard.sh +0 -75
- package/scripts/tests/unit/test_zipf.sh +0 -76
- package/scripts/theme/apply-gnome-theme.sh +0 -297
- package/scripts/theme/install-boot-logo.sh +0 -61
- package/scripts/theme/install-catppuccin-themes.sh +0 -346
- package/scripts/theme/install-cursors.sh +0 -24
- package/scripts/theme/install-file-icons.sh +0 -25
- package/scripts/theme/install-grub-theme.sh +0 -51
- package/scripts/theme/install-lock-icon.sh +0 -29
- package/scripts/theme/switch.sh +0 -250
- package/scripts/theme/wallpaper-rotate.sh +0 -82
- package/scripts/theme/wallpaper-sync.sh +0 -42
- package/scripts/tools/cmatrix.sh +0 -20
- package/scripts/tools/emoji-picker.sh +0 -45
- package/scripts/tools/figlet-banner.sh +0 -17
- package/scripts/tools/log-rotate.sh +0 -29
- package/scripts/tools/lolcat-wrap.sh +0 -18
- package/scripts/tools/pipes.sh +0 -47
- package/scripts/tuning/linux.sh +0 -175
- package/scripts/tuning/macos.sh +0 -46
- package/templates/projects/molecule/README.md +0 -7
- package/templates/projects/molecule/converge.yml +0 -7
- package/templates/projects/molecule/molecule.yml +0 -16
- package/templates/projects/packer/README.md +0 -15
- package/templates/projects/packer/main.pkr.hcl +0 -15
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# shellcheck disable=SC1090,SC1091,SC2164
|
|
3
|
-
# Unit tests for the rd (remove directory) function
|
|
4
|
-
# Tests for security safeguards against dangerous paths
|
|
5
|
-
|
|
6
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
7
|
-
REPO_ROOT="${REPO_ROOT:-$(cd "$SCRIPT_DIR/../../.." && pwd)}"
|
|
8
|
-
source "$SCRIPT_DIR/../framework/assertions.sh"
|
|
9
|
-
source "$SCRIPT_DIR/../framework/mocks.sh"
|
|
10
|
-
|
|
11
|
-
# Source the function being tested
|
|
12
|
-
FUNC_FILE="$REPO_ROOT/.chezmoitemplates/functions/rd.sh"
|
|
13
|
-
if [[ -f "$FUNC_FILE" ]]; then
|
|
14
|
-
source "$FUNC_FILE"
|
|
15
|
-
else
|
|
16
|
-
echo "Warning: rd.sh not found at $FUNC_FILE"
|
|
17
|
-
fi
|
|
18
|
-
|
|
19
|
-
# Test: rd with no arguments shows error
|
|
20
|
-
test_start "rd_no_args"
|
|
21
|
-
output=$(rd 2>&1)
|
|
22
|
-
exit_code=$?
|
|
23
|
-
assert_equals "1" "$exit_code" "exit code should be 1 for no args"
|
|
24
|
-
|
|
25
|
-
# Test: rd with no arguments shows error message
|
|
26
|
-
test_start "rd_no_args_message"
|
|
27
|
-
output=$(rd 2>&1)
|
|
28
|
-
if [[ "$output" == *"ERROR"* || "$output" == *"argument"* ]]; then
|
|
29
|
-
((TESTS_PASSED++))
|
|
30
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: shows error message for no arguments"
|
|
31
|
-
else
|
|
32
|
-
((TESTS_FAILED++))
|
|
33
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should show error message for no arguments"
|
|
34
|
-
echo -e " Output: $output"
|
|
35
|
-
fi
|
|
36
|
-
|
|
37
|
-
# Test: rd with too many arguments shows error
|
|
38
|
-
test_start "rd_too_many_args"
|
|
39
|
-
output=$(rd "dir1" "dir2" 2>&1)
|
|
40
|
-
exit_code=$?
|
|
41
|
-
assert_equals "1" "$exit_code" "exit code should be 1 for too many arguments"
|
|
42
|
-
|
|
43
|
-
# Test: rd with valid directory removes it
|
|
44
|
-
test_start "rd_valid_directory"
|
|
45
|
-
test_dir=$(mock_dir "rd_test")
|
|
46
|
-
target_dir="$test_dir/to_remove"
|
|
47
|
-
mkdir -p "$target_dir"
|
|
48
|
-
echo "test" >"$target_dir/file.txt"
|
|
49
|
-
|
|
50
|
-
# Save current directory and change to test_dir
|
|
51
|
-
original_dir=$(pwd)
|
|
52
|
-
cd "$test_dir"
|
|
53
|
-
|
|
54
|
-
output=$(rd "to_remove" 2>&1)
|
|
55
|
-
exit_code=$?
|
|
56
|
-
|
|
57
|
-
cd "$original_dir"
|
|
58
|
-
|
|
59
|
-
if [[ ! -d "$target_dir" ]]; then
|
|
60
|
-
((TESTS_PASSED++))
|
|
61
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: directory was removed"
|
|
62
|
-
else
|
|
63
|
-
((TESTS_FAILED++))
|
|
64
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: directory should be removed"
|
|
65
|
-
fi
|
|
66
|
-
rm -rf "$test_dir"
|
|
67
|
-
|
|
68
|
-
# Test: rd shows INFO message
|
|
69
|
-
test_start "rd_info_message"
|
|
70
|
-
test_dir=$(mock_dir "rd_test")
|
|
71
|
-
target_dir="$test_dir/to_remove"
|
|
72
|
-
mkdir -p "$target_dir"
|
|
73
|
-
|
|
74
|
-
original_dir=$(pwd)
|
|
75
|
-
cd "$test_dir"
|
|
76
|
-
|
|
77
|
-
output=$(rd "to_remove" 2>&1)
|
|
78
|
-
|
|
79
|
-
cd "$original_dir"
|
|
80
|
-
|
|
81
|
-
if [[ "$output" == *"INFO"* ]]; then
|
|
82
|
-
((TESTS_PASSED++))
|
|
83
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: shows INFO message"
|
|
84
|
-
else
|
|
85
|
-
((TESTS_FAILED++))
|
|
86
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should show INFO message"
|
|
87
|
-
echo -e " Output: $output"
|
|
88
|
-
fi
|
|
89
|
-
rm -rf "$test_dir"
|
|
90
|
-
|
|
91
|
-
# SECURITY TESTS: These test for rejection of dangerous paths
|
|
92
|
-
# Note: The current rd function does NOT have these safety checks
|
|
93
|
-
# These tests document what SHOULD be tested after security improvements
|
|
94
|
-
|
|
95
|
-
# Test: rd should reject root path (SECURITY)
|
|
96
|
-
test_start "rd_reject_root"
|
|
97
|
-
output=$(rd "/" 2>&1) || true
|
|
98
|
-
if [[ "$output" == *"ERROR"* ]] && [[ "$output" == *"protected"* || "$output" == *"Refusing"* ]]; then
|
|
99
|
-
((TESTS_PASSED++))
|
|
100
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: root path rejected (security)"
|
|
101
|
-
else
|
|
102
|
-
((TESTS_FAILED++))
|
|
103
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: root path should be rejected as protected"
|
|
104
|
-
echo -e " Output: $output"
|
|
105
|
-
fi
|
|
106
|
-
|
|
107
|
-
# Test: rd should reject home directory (SECURITY)
|
|
108
|
-
test_start "rd_reject_home"
|
|
109
|
-
output=$(rd "$HOME" 2>&1) || true
|
|
110
|
-
if [[ "$output" == *"ERROR"* ]] && [[ "$output" == *"protected"* || "$output" == *"Refusing"* ]]; then
|
|
111
|
-
((TESTS_PASSED++))
|
|
112
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: home directory rejected (security)"
|
|
113
|
-
else
|
|
114
|
-
((TESTS_FAILED++))
|
|
115
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: home directory should be rejected as protected"
|
|
116
|
-
echo -e " Output: $output"
|
|
117
|
-
fi
|
|
118
|
-
|
|
119
|
-
# Test: rd should reject /etc (SECURITY)
|
|
120
|
-
test_start "rd_reject_etc"
|
|
121
|
-
output=$(rd "/etc" 2>&1) || true
|
|
122
|
-
if [[ "$output" == *"ERROR"* ]] && [[ "$output" == *"protected"* || "$output" == *"Refusing"* ]]; then
|
|
123
|
-
((TESTS_PASSED++))
|
|
124
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: /etc rejected (security)"
|
|
125
|
-
else
|
|
126
|
-
((TESTS_FAILED++))
|
|
127
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: /etc should be rejected as protected"
|
|
128
|
-
echo -e " Output: $output"
|
|
129
|
-
fi
|
|
130
|
-
|
|
131
|
-
# Test: rd should reject /usr (SECURITY)
|
|
132
|
-
test_start "rd_reject_usr"
|
|
133
|
-
output=$(rd "/usr" 2>&1) || true
|
|
134
|
-
if [[ "$output" == *"ERROR"* ]] && [[ "$output" == *"protected"* || "$output" == *"Refusing"* ]]; then
|
|
135
|
-
((TESTS_PASSED++))
|
|
136
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: /usr rejected (security)"
|
|
137
|
-
else
|
|
138
|
-
((TESTS_FAILED++))
|
|
139
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: /usr should be rejected as protected"
|
|
140
|
-
echo -e " Output: $output"
|
|
141
|
-
fi
|
|
142
|
-
|
|
143
|
-
# Test: rd should reject /var (SECURITY)
|
|
144
|
-
test_start "rd_reject_var"
|
|
145
|
-
output=$(rd "/var" 2>&1) || true
|
|
146
|
-
if [[ "$output" == *"ERROR"* ]] && [[ "$output" == *"protected"* || "$output" == *"Refusing"* ]]; then
|
|
147
|
-
((TESTS_PASSED++))
|
|
148
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: /var rejected (security)"
|
|
149
|
-
else
|
|
150
|
-
((TESTS_FAILED++))
|
|
151
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: /var should be rejected as protected"
|
|
152
|
-
echo -e " Output: $output"
|
|
153
|
-
fi
|
|
154
|
-
|
|
155
|
-
# Test: rd should reject paths with .. traversal (SECURITY)
|
|
156
|
-
test_start "rd_reject_traversal"
|
|
157
|
-
test_dir=$(mock_dir "rd_test")
|
|
158
|
-
mkdir -p "$test_dir/safe/nested"
|
|
159
|
-
|
|
160
|
-
original_dir=$(pwd)
|
|
161
|
-
cd "$test_dir/safe/nested"
|
|
162
|
-
|
|
163
|
-
# Try to use .. traversal
|
|
164
|
-
output=$(rd "../../.." 2>&1) || true
|
|
165
|
-
|
|
166
|
-
cd "$original_dir"
|
|
167
|
-
|
|
168
|
-
if [[ "$output" == *"ERROR"* || "$output" == *"dangerous"* || -d "$test_dir" ]]; then
|
|
169
|
-
((TESTS_PASSED++))
|
|
170
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: path traversal handled"
|
|
171
|
-
else
|
|
172
|
-
((TESTS_PASSED++))
|
|
173
|
-
echo -e " ${YELLOW}~${NC} $CURRENT_TEST: path traversal behavior documented"
|
|
174
|
-
fi
|
|
175
|
-
rm -rf "$test_dir" 2>/dev/null || true
|
|
176
|
-
|
|
177
|
-
# Test: rd with nonexistent directory
|
|
178
|
-
test_start "rd_nonexistent"
|
|
179
|
-
output=$(rd "/nonexistent/path/that/does/not/exist" 2>&1)
|
|
180
|
-
# Function behavior with nonexistent paths
|
|
181
|
-
if [[ "$output" == *"INFO"* ]] || [[ "$output" == *"ERROR"* ]]; then
|
|
182
|
-
((TESTS_PASSED++))
|
|
183
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: nonexistent path handled"
|
|
184
|
-
else
|
|
185
|
-
((TESTS_PASSED++))
|
|
186
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: nonexistent path processed"
|
|
187
|
-
fi
|
|
188
|
-
|
|
189
|
-
# Test: rd with empty string
|
|
190
|
-
test_start "rd_empty_string"
|
|
191
|
-
output=$(rd "" 2>&1)
|
|
192
|
-
exit_code=$?
|
|
193
|
-
# Should treat empty string as error
|
|
194
|
-
if [[ "$exit_code" -ne 0 ]] || [[ "$output" == *"ERROR"* ]]; then
|
|
195
|
-
((TESTS_PASSED++))
|
|
196
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: empty string handled as error"
|
|
197
|
-
else
|
|
198
|
-
((TESTS_PASSED++))
|
|
199
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: empty string processed"
|
|
200
|
-
fi
|
|
201
|
-
|
|
202
|
-
# Test: rd with file instead of directory
|
|
203
|
-
test_start "rd_file_instead_of_dir"
|
|
204
|
-
test_dir=$(mock_dir "rd_test")
|
|
205
|
-
test_file="$test_dir/file.txt"
|
|
206
|
-
echo "test" >"$test_file"
|
|
207
|
-
|
|
208
|
-
original_dir=$(pwd)
|
|
209
|
-
cd "$test_dir"
|
|
210
|
-
|
|
211
|
-
output=$(rd "file.txt" 2>&1)
|
|
212
|
-
|
|
213
|
-
cd "$original_dir"
|
|
214
|
-
|
|
215
|
-
# rd uses rm -rf which handles files too
|
|
216
|
-
if [[ ! -f "$test_file" ]]; then
|
|
217
|
-
((TESTS_PASSED++))
|
|
218
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: file was removed (rm -rf handles files)"
|
|
219
|
-
else
|
|
220
|
-
((TESTS_PASSED++))
|
|
221
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: file handling documented"
|
|
222
|
-
fi
|
|
223
|
-
rm -rf "$test_dir"
|
|
224
|
-
|
|
225
|
-
echo ""
|
|
226
|
-
echo "rd function tests completed."
|
|
227
|
-
echo ""
|
|
228
|
-
echo "NOTE: Security tests marked with ~ indicate areas where"
|
|
229
|
-
echo "the rd function could be improved to reject dangerous paths."
|
|
230
|
-
echo "RESULTS:$TESTS_RUN:$TESTS_PASSED:$TESTS_FAILED"
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# shellcheck disable=SC1090,SC1091
|
|
3
|
-
# Unit tests for security fixes
|
|
4
|
-
|
|
5
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
6
|
-
REPO_ROOT="${REPO_ROOT:-$(cd "$SCRIPT_DIR/../../.." && pwd)}"
|
|
7
|
-
source "$SCRIPT_DIR/../framework/assertions.sh"
|
|
8
|
-
|
|
9
|
-
echo "Testing security fixes..."
|
|
10
|
-
|
|
11
|
-
# Test: mount_read_only.sh validates input
|
|
12
|
-
test_start "mount_read_only_validates_input"
|
|
13
|
-
FUNC_FILE="$REPO_ROOT/.chezmoitemplates/functions/mount_read_only.sh"
|
|
14
|
-
assert_file_exists "$FUNC_FILE" "mount_read_only.sh should exist"
|
|
15
|
-
|
|
16
|
-
# Test: mount_read_only requires argument
|
|
17
|
-
test_start "mount_read_only_requires_arg"
|
|
18
|
-
result=$(bash -c '
|
|
19
|
-
source "'"$FUNC_FILE"'"
|
|
20
|
-
mount_read_only 2>&1
|
|
21
|
-
')
|
|
22
|
-
if [[ "$result" == *"No disk image specified"* ]]; then
|
|
23
|
-
((TESTS_PASSED++)) || true
|
|
24
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: rejects empty argument"
|
|
25
|
-
else
|
|
26
|
-
((TESTS_FAILED++)) || true
|
|
27
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should reject empty argument"
|
|
28
|
-
echo -e " Actual: $result"
|
|
29
|
-
fi
|
|
30
|
-
|
|
31
|
-
# Test: mount_read_only rejects missing file
|
|
32
|
-
test_start "mount_read_only_rejects_missing"
|
|
33
|
-
result=$(bash -c '
|
|
34
|
-
source "'"$FUNC_FILE"'"
|
|
35
|
-
mount_read_only "/nonexistent/file.dmg" 2>&1
|
|
36
|
-
')
|
|
37
|
-
if [[ "$result" == *"Disk image not found"* ]]; then
|
|
38
|
-
((TESTS_PASSED++)) || true
|
|
39
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: rejects missing file"
|
|
40
|
-
else
|
|
41
|
-
((TESTS_FAILED++)) || true
|
|
42
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should reject missing file"
|
|
43
|
-
echo -e " Actual: $result"
|
|
44
|
-
fi
|
|
45
|
-
|
|
46
|
-
# Test: genpass validates numeric input
|
|
47
|
-
test_start "genpass_validates_numeric"
|
|
48
|
-
GENPASS_FILE="$REPO_ROOT/.chezmoitemplates/functions/genpass.sh"
|
|
49
|
-
result=$(bash -c '
|
|
50
|
-
source "'"$GENPASS_FILE"'"
|
|
51
|
-
genpass "abc" 2>&1
|
|
52
|
-
' 2>&1)
|
|
53
|
-
if [[ "$result" == *"must be a number"* ]]; then
|
|
54
|
-
((TESTS_PASSED++)) || true
|
|
55
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: rejects non-numeric input"
|
|
56
|
-
else
|
|
57
|
-
((TESTS_FAILED++)) || true
|
|
58
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should reject non-numeric input"
|
|
59
|
-
echo -e " Actual: $result"
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
# Test: genpass rejects out-of-range values
|
|
63
|
-
test_start "genpass_rejects_out_of_range"
|
|
64
|
-
result=$(bash -c '
|
|
65
|
-
source "'"$GENPASS_FILE"'"
|
|
66
|
-
genpass 101 2>&1
|
|
67
|
-
' 2>&1)
|
|
68
|
-
if [[ "$result" == *"must be a number between 1 and 100"* ]]; then
|
|
69
|
-
((TESTS_PASSED++)) || true
|
|
70
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: rejects out of range input"
|
|
71
|
-
else
|
|
72
|
-
((TESTS_FAILED++)) || true
|
|
73
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should reject out of range input"
|
|
74
|
-
echo -e " Actual: $result"
|
|
75
|
-
fi
|
|
76
|
-
|
|
77
|
-
# Test: genpass accepts valid input
|
|
78
|
-
test_start "genpass_accepts_valid"
|
|
79
|
-
result=$(bash -c '
|
|
80
|
-
source "'"$GENPASS_FILE"'"
|
|
81
|
-
genpass 2 2>&1
|
|
82
|
-
' 2>&1)
|
|
83
|
-
if [[ "$result" == *"Generated password"* ]]; then
|
|
84
|
-
((TESTS_PASSED++)) || true
|
|
85
|
-
echo -e " ${GREEN}✓${NC} $CURRENT_TEST: accepts valid numeric input"
|
|
86
|
-
else
|
|
87
|
-
((TESTS_FAILED++)) || true
|
|
88
|
-
echo -e " ${RED}✗${NC} $CURRENT_TEST: should accept valid numeric input"
|
|
89
|
-
echo -e " Actual: $result"
|
|
90
|
-
fi
|
|
91
|
-
|
|
92
|
-
# Test: chezmoi-apply.sh uses read for safe parsing
|
|
93
|
-
test_start "chezmoi_apply_safe_parsing"
|
|
94
|
-
APPLY_FILE="$REPO_ROOT/scripts/ops/chezmoi-apply.sh"
|
|
95
|
-
assert_file_contains "$APPLY_FILE" 'read -ra flag_array' "should use read for safe parsing"
|
|
96
|
-
|
|
97
|
-
# Test: chezmoi-update.sh uses read for safe parsing
|
|
98
|
-
test_start "chezmoi_update_safe_parsing"
|
|
99
|
-
UPDATE_FILE="$REPO_ROOT/scripts/ops/chezmoi-update.sh"
|
|
100
|
-
assert_file_contains "$UPDATE_FILE" 'read -ra flag_array' "should use read for safe parsing"
|
|
101
|
-
|
|
102
|
-
# Test: tmux-sessionizer sanitizes session names
|
|
103
|
-
test_start "tmux_sessionizer_sanitizes"
|
|
104
|
-
SESSION_FILE="$REPO_ROOT/dot_local/bin/executable_tmux-sessionizer"
|
|
105
|
-
assert_file_contains "$SESSION_FILE" "tr -cd '[:alnum:]._-'" "should sanitize session names"
|
|
106
|
-
|
|
107
|
-
# Test: install.sh uses printf instead of sed for config generation
|
|
108
|
-
test_start "install_uses_printf_config"
|
|
109
|
-
INSTALL_FILE="$REPO_ROOT/install.sh"
|
|
110
|
-
assert_file_contains "$INSTALL_FILE" "printf" "should use printf for safe config generation"
|
|
111
|
-
|
|
112
|
-
# Test: permission aliases warn about dangerous modes
|
|
113
|
-
test_start "permission_warns_666"
|
|
114
|
-
PERM_FILE="$REPO_ROOT/.chezmoitemplates/aliases/permission/permission.aliases.sh"
|
|
115
|
-
assert_file_contains "$PERM_FILE" "WARNING: 666" "should warn about 666 permissions"
|
|
116
|
-
|
|
117
|
-
test_start "permission_warns_777"
|
|
118
|
-
assert_file_contains "$PERM_FILE" "WARNING: 777" "should warn about 777 permissions"
|
|
119
|
-
|
|
120
|
-
# Test: backup.sh has error handling
|
|
121
|
-
test_start "backup_error_handling"
|
|
122
|
-
BACKUP_FILE="$REPO_ROOT/scripts/security/backup.sh"
|
|
123
|
-
assert_file_contains "$BACKUP_FILE" "Backup failed" "should have error handling"
|
|
124
|
-
|
|
125
|
-
# Test: age-init.sh uses json.dumps for escaping
|
|
126
|
-
test_start "age_init_json_escaping"
|
|
127
|
-
AGE_FILE="$REPO_ROOT/scripts/secrets/age-init.sh"
|
|
128
|
-
assert_file_contains "$AGE_FILE" "json.dumps" "should use json.dumps for escaping"
|
|
129
|
-
|
|
130
|
-
print_summary
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# shellcheck disable=SC1090,SC1091
|
|
3
|
-
# Unit tests for security scripts
|
|
4
|
-
|
|
5
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
6
|
-
REPO_ROOT="${REPO_ROOT:-$(cd "$SCRIPT_DIR/../../.." && pwd)}"
|
|
7
|
-
source "$SCRIPT_DIR/../framework/assertions.sh"
|
|
8
|
-
|
|
9
|
-
SECURITY_DIR="$REPO_ROOT/scripts/security"
|
|
10
|
-
|
|
11
|
-
echo "Testing security scripts..."
|
|
12
|
-
|
|
13
|
-
# Test firewall.sh exists and has valid syntax
|
|
14
|
-
test_start "firewall_script_syntax"
|
|
15
|
-
if [[ -f "$SECURITY_DIR/firewall.sh" ]]; then
|
|
16
|
-
assert_exit_code 0 "bash -n '$SECURITY_DIR/firewall.sh'"
|
|
17
|
-
else
|
|
18
|
-
assert_true "true" "firewall.sh not found (optional)"
|
|
19
|
-
fi
|
|
20
|
-
|
|
21
|
-
# Test lock-configs.sh exists and has valid syntax
|
|
22
|
-
test_start "lock_configs_script_syntax"
|
|
23
|
-
if [[ -f "$SECURITY_DIR/lock-configs.sh" ]]; then
|
|
24
|
-
assert_exit_code 0 "bash -n '$SECURITY_DIR/lock-configs.sh'"
|
|
25
|
-
else
|
|
26
|
-
assert_true "true" "lock-configs.sh not found (optional)"
|
|
27
|
-
fi
|
|
28
|
-
|
|
29
|
-
# Test encryption-check.sh exists and has valid syntax
|
|
30
|
-
test_start "encryption_check_script_syntax"
|
|
31
|
-
if [[ -f "$SECURITY_DIR/encryption-check.sh" ]]; then
|
|
32
|
-
assert_exit_code 0 "bash -n '$SECURITY_DIR/encryption-check.sh'"
|
|
33
|
-
else
|
|
34
|
-
assert_true "true" "encryption-check.sh not found (optional)"
|
|
35
|
-
fi
|
|
36
|
-
|
|
37
|
-
# Test usb-safety.sh exists and has valid syntax
|
|
38
|
-
test_start "usb_safety_script_syntax"
|
|
39
|
-
if [[ -f "$SECURITY_DIR/usb-safety.sh" ]]; then
|
|
40
|
-
assert_exit_code 0 "bash -n '$SECURITY_DIR/usb-safety.sh'"
|
|
41
|
-
else
|
|
42
|
-
assert_true "true" "usb-safety.sh not found (optional)"
|
|
43
|
-
fi
|
|
44
|
-
|
|
45
|
-
# Test telemetry-disable.sh exists and has valid syntax
|
|
46
|
-
test_start "telemetry_disable_script_syntax"
|
|
47
|
-
if [[ -f "$SECURITY_DIR/telemetry-disable.sh" ]]; then
|
|
48
|
-
assert_exit_code 0 "bash -n '$SECURITY_DIR/telemetry-disable.sh'"
|
|
49
|
-
else
|
|
50
|
-
assert_true "true" "telemetry-disable.sh not found (optional)"
|
|
51
|
-
fi
|
|
52
|
-
|
|
53
|
-
# Test dns-doh.sh exists and has valid syntax
|
|
54
|
-
test_start "dns_doh_script_syntax"
|
|
55
|
-
if [[ -f "$SECURITY_DIR/dns-doh.sh" ]]; then
|
|
56
|
-
assert_exit_code 0 "bash -n '$SECURITY_DIR/dns-doh.sh'"
|
|
57
|
-
else
|
|
58
|
-
assert_true "true" "dns-doh.sh not found (optional)"
|
|
59
|
-
fi
|
|
60
|
-
|
|
61
|
-
# Test all security scripts have shebang
|
|
62
|
-
test_start "security_scripts_have_shebang"
|
|
63
|
-
for script in "$SECURITY_DIR"/*.sh; do
|
|
64
|
-
if [[ -f "$script" ]]; then
|
|
65
|
-
first_line=$(head -1 "$script")
|
|
66
|
-
if [[ "$first_line" != "#!/"* ]]; then
|
|
67
|
-
echo "Missing shebang: $script"
|
|
68
|
-
fi
|
|
69
|
-
fi
|
|
70
|
-
done
|
|
71
|
-
assert_true "true" "shebang check completed"
|
|
72
|
-
|
|
73
|
-
# Test security scripts are not world-writable
|
|
74
|
-
test_start "security_scripts_permissions"
|
|
75
|
-
for script in "$SECURITY_DIR"/*.sh; do
|
|
76
|
-
if [[ -f "$script" ]]; then
|
|
77
|
-
perms=$(stat -f "%Lp" "$script" 2>/dev/null || stat -c "%a" "$script" 2>/dev/null || echo "644")
|
|
78
|
-
# Should not be world-writable (no 2 in last digit)
|
|
79
|
-
last_digit="${perms: -1}"
|
|
80
|
-
if [[ "$last_digit" == "2" || "$last_digit" == "3" || "$last_digit" == "6" || "$last_digit" == "7" ]]; then
|
|
81
|
-
echo "World-writable: $script"
|
|
82
|
-
fi
|
|
83
|
-
fi
|
|
84
|
-
done
|
|
85
|
-
assert_true "true" "permissions check completed"
|
|
86
|
-
|
|
87
|
-
print_summary
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Template Validation Tests
|
|
3
|
-
# Validates chezmoi template output correctness and required variables
|
|
4
|
-
|
|
5
|
-
set -euo pipefail
|
|
6
|
-
|
|
7
|
-
# Colors
|
|
8
|
-
RED='\033[0;31m'
|
|
9
|
-
GREEN='\033[0;32m'
|
|
10
|
-
YELLOW='\033[0;33m'
|
|
11
|
-
NC='\033[0m'
|
|
12
|
-
|
|
13
|
-
# Counters
|
|
14
|
-
TESTS_RUN=0
|
|
15
|
-
TESTS_PASSED=0
|
|
16
|
-
TESTS_FAILED=0
|
|
17
|
-
|
|
18
|
-
# Test utilities
|
|
19
|
-
pass() {
|
|
20
|
-
TESTS_PASSED=$((TESTS_PASSED + 1))
|
|
21
|
-
echo -e "${GREEN}✓${NC} $1"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
fail() {
|
|
25
|
-
TESTS_FAILED=$((TESTS_FAILED + 1))
|
|
26
|
-
echo -e "${RED}✗${NC} $1"
|
|
27
|
-
[ -n "${2:-}" ] && echo " ${2}"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
skip() {
|
|
31
|
-
echo -e "${YELLOW}○${NC} $1 (skipped)"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
run_test() {
|
|
35
|
-
TESTS_RUN=$((TESTS_RUN + 1))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
# =============================================================================
|
|
39
|
-
# Template Syntax Validation
|
|
40
|
-
# =============================================================================
|
|
41
|
-
|
|
42
|
-
test_template_syntax() {
|
|
43
|
-
echo ""
|
|
44
|
-
echo "=== Template Syntax Validation ==="
|
|
45
|
-
|
|
46
|
-
local source_dir="${CHEZMOI_SOURCE_DIR:-$HOME/.dotfiles}"
|
|
47
|
-
local templates
|
|
48
|
-
templates=$(find "$source_dir" -name "*.tmpl" -type f 2>/dev/null | head -50 || true)
|
|
49
|
-
|
|
50
|
-
if [ -z "$templates" ]; then
|
|
51
|
-
skip "No templates found"
|
|
52
|
-
return
|
|
53
|
-
fi
|
|
54
|
-
|
|
55
|
-
for tmpl in $templates; do
|
|
56
|
-
run_test
|
|
57
|
-
local name="${tmpl#"$source_dir"/}"
|
|
58
|
-
|
|
59
|
-
# Check for unbalanced template delimiters
|
|
60
|
-
local open_count close_count
|
|
61
|
-
open_count=$(grep -o '{{' "$tmpl" 2>/dev/null | wc -l)
|
|
62
|
-
close_count=$(grep -o '}}' "$tmpl" 2>/dev/null | wc -l)
|
|
63
|
-
|
|
64
|
-
if [ "$open_count" -ne "$close_count" ]; then
|
|
65
|
-
fail "Template $name: unbalanced delimiters ({{ = $open_count, }} = $close_count)"
|
|
66
|
-
else
|
|
67
|
-
pass "Template $name: balanced delimiters"
|
|
68
|
-
fi
|
|
69
|
-
done
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
# =============================================================================
|
|
73
|
-
# Required Variables Validation
|
|
74
|
-
# =============================================================================
|
|
75
|
-
|
|
76
|
-
test_required_variables() {
|
|
77
|
-
echo ""
|
|
78
|
-
echo "=== Required Variables Validation ==="
|
|
79
|
-
|
|
80
|
-
# Check if chezmoi is available
|
|
81
|
-
if ! command -v chezmoi >/dev/null 2>&1; then
|
|
82
|
-
skip "chezmoi not installed"
|
|
83
|
-
return
|
|
84
|
-
fi
|
|
85
|
-
|
|
86
|
-
run_test
|
|
87
|
-
# Check that chezmoi data is accessible
|
|
88
|
-
if chezmoi data >/dev/null 2>&1; then
|
|
89
|
-
pass "chezmoi data accessible"
|
|
90
|
-
else
|
|
91
|
-
fail "chezmoi data not accessible"
|
|
92
|
-
fi
|
|
93
|
-
|
|
94
|
-
run_test
|
|
95
|
-
# Check for required OS variables
|
|
96
|
-
local os_value
|
|
97
|
-
os_value=$(chezmoi data --format json 2>/dev/null | grep -o '"os":"[^"]*"' | head -1 || echo "")
|
|
98
|
-
if [ -n "$os_value" ]; then
|
|
99
|
-
pass "chezmoi.os is set: $os_value"
|
|
100
|
-
else
|
|
101
|
-
fail "chezmoi.os not available"
|
|
102
|
-
fi
|
|
103
|
-
|
|
104
|
-
run_test
|
|
105
|
-
# Check for homeDir
|
|
106
|
-
local home_value
|
|
107
|
-
home_value=$(chezmoi data --format json 2>/dev/null | grep -o '"homeDir":"[^"]*"' | head -1 || echo "")
|
|
108
|
-
if [ -n "$home_value" ]; then
|
|
109
|
-
pass "chezmoi.homeDir is set"
|
|
110
|
-
else
|
|
111
|
-
fail "chezmoi.homeDir not available"
|
|
112
|
-
fi
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
# =============================================================================
|
|
116
|
-
# Template Output Validation
|
|
117
|
-
# =============================================================================
|
|
118
|
-
|
|
119
|
-
test_template_output() {
|
|
120
|
-
echo ""
|
|
121
|
-
echo "=== Template Output Validation ==="
|
|
122
|
-
|
|
123
|
-
if ! command -v chezmoi >/dev/null 2>&1; then
|
|
124
|
-
skip "chezmoi not installed"
|
|
125
|
-
return
|
|
126
|
-
fi
|
|
127
|
-
|
|
128
|
-
local source_dir="${CHEZMOI_SOURCE_DIR:-$HOME/.dotfiles}"
|
|
129
|
-
|
|
130
|
-
# Test critical templates
|
|
131
|
-
local critical_templates=(
|
|
132
|
-
"dot_gitconfig.tmpl"
|
|
133
|
-
"dot_zshrc.tmpl"
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
for tmpl_name in "${critical_templates[@]}"; do
|
|
137
|
-
run_test
|
|
138
|
-
local tmpl_path
|
|
139
|
-
tmpl_path=$(find "$source_dir" -name "$tmpl_name" -type f 2>/dev/null | head -1)
|
|
140
|
-
|
|
141
|
-
if [ -z "$tmpl_path" ]; then
|
|
142
|
-
skip "Template $tmpl_name not found"
|
|
143
|
-
continue
|
|
144
|
-
fi
|
|
145
|
-
|
|
146
|
-
# Try to execute the template
|
|
147
|
-
if chezmoi execute-template <"$tmpl_path" >/dev/null 2>&1; then
|
|
148
|
-
pass "Template $tmpl_name renders successfully"
|
|
149
|
-
else
|
|
150
|
-
fail "Template $tmpl_name failed to render"
|
|
151
|
-
fi
|
|
152
|
-
done
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
# =============================================================================
|
|
156
|
-
# Helper Template Validation
|
|
157
|
-
# =============================================================================
|
|
158
|
-
|
|
159
|
-
test_helper_templates() {
|
|
160
|
-
echo ""
|
|
161
|
-
echo "=== Helper Template Validation ==="
|
|
162
|
-
|
|
163
|
-
local source_dir="${CHEZMOI_SOURCE_DIR:-$HOME/.dotfiles}"
|
|
164
|
-
local helpers_dir="$source_dir/.chezmoitemplates/functions/helpers"
|
|
165
|
-
|
|
166
|
-
if [ ! -d "$helpers_dir" ]; then
|
|
167
|
-
skip "Helpers directory not found"
|
|
168
|
-
return
|
|
169
|
-
fi
|
|
170
|
-
|
|
171
|
-
for helper in "$helpers_dir"/*.tmpl; do
|
|
172
|
-
run_test
|
|
173
|
-
local name
|
|
174
|
-
name=$(basename "$helper")
|
|
175
|
-
|
|
176
|
-
# Check helper has documentation comment
|
|
177
|
-
if head -5 "$helper" | grep -q '{{-\s*/\*'; then
|
|
178
|
-
pass "Helper $name has documentation"
|
|
179
|
-
else
|
|
180
|
-
fail "Helper $name missing documentation header"
|
|
181
|
-
fi
|
|
182
|
-
done
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
# =============================================================================
|
|
186
|
-
# Chezmoi Verify
|
|
187
|
-
# =============================================================================
|
|
188
|
-
|
|
189
|
-
test_chezmoi_verify() {
|
|
190
|
-
echo ""
|
|
191
|
-
echo "=== Chezmoi Verification ==="
|
|
192
|
-
|
|
193
|
-
if ! command -v chezmoi >/dev/null 2>&1; then
|
|
194
|
-
skip "chezmoi not installed"
|
|
195
|
-
return
|
|
196
|
-
fi
|
|
197
|
-
|
|
198
|
-
run_test
|
|
199
|
-
if chezmoi verify 2>/dev/null; then
|
|
200
|
-
pass "chezmoi verify passed"
|
|
201
|
-
else
|
|
202
|
-
# verify returns non-zero if there are differences, which is expected
|
|
203
|
-
pass "chezmoi verify completed (differences may exist)"
|
|
204
|
-
fi
|
|
205
|
-
|
|
206
|
-
run_test
|
|
207
|
-
# Check that doctor passes
|
|
208
|
-
if chezmoi doctor 2>/dev/null | grep -q "ok"; then
|
|
209
|
-
pass "chezmoi doctor has passing checks"
|
|
210
|
-
else
|
|
211
|
-
skip "chezmoi doctor output unclear"
|
|
212
|
-
fi
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
# =============================================================================
|
|
216
|
-
# Main
|
|
217
|
-
# =============================================================================
|
|
218
|
-
|
|
219
|
-
main() {
|
|
220
|
-
echo "Template Validation Tests"
|
|
221
|
-
echo "========================="
|
|
222
|
-
|
|
223
|
-
test_template_syntax
|
|
224
|
-
test_required_variables
|
|
225
|
-
test_template_output
|
|
226
|
-
test_helper_templates
|
|
227
|
-
test_chezmoi_verify
|
|
228
|
-
|
|
229
|
-
echo ""
|
|
230
|
-
echo "========================="
|
|
231
|
-
echo "Results: $TESTS_PASSED passed, $TESTS_FAILED failed, $TESTS_RUN total"
|
|
232
|
-
|
|
233
|
-
if [ "$TESTS_FAILED" -gt 0 ]; then
|
|
234
|
-
exit 1
|
|
235
|
-
fi
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
main "$@"
|