test: coverage for store protections self-heal (hook on push/rekey, no-op, gitignore content)

This commit is contained in:
Brian Majewski 2026-06-05 09:52:51 -07:00
parent 53350853d9
commit 5865c40d77

View file

@ -1552,3 +1552,48 @@ gradle_project() {
[ "$(cat .env)" = "SECRET_KEY=abc123" ]
[ "$(cat .env.staging)" = "DB_HOST=staging.db.example.com" ]
}
@test "push reinstalls missing pre-commit hook" {
init_with_remote
rm "$SECRETS_DIR/.git/hooks/pre-commit"
create_project_dir
run "$SECRETS_BIN" push
[ "$status" -eq 0 ]
[ -x "$SECRETS_DIR/.git/hooks/pre-commit" ]
}
@test "rekey reinstalls missing pre-commit hook" {
init_with_remote
create_project_dir
"$SECRETS_BIN" push >/dev/null 2>&1
rm "$SECRETS_DIR/.git/hooks/pre-commit"
run "$SECRETS_BIN" rekey
[ "$status" -eq 0 ]
[ -x "$SECRETS_DIR/.git/hooks/pre-commit" ]
}
@test "store protections heal is a silent no-op when nothing is missing" {
init_with_remote
create_project_dir
run "$SECRETS_BIN" push
[ "$status" -eq 0 ]
[[ "$output" != *"Restored store .gitignore"* ]]
[[ "$output" != *"Reinstalled pre-commit hook"* ]]
}
@test "restored store .gitignore carries the full block/allow globs" {
init_with_remote
rm "$SECRETS_DIR/.gitignore"
create_project_dir
"$SECRETS_BIN" push >/dev/null 2>&1
grep -q "^key.txt$" "$SECRETS_DIR/.gitignore"
grep -qF '**/.env' "$SECRETS_DIR/.gitignore"
grep -qF '**/.dev.vars' "$SECRETS_DIR/.gitignore"
grep -qF '!**/.env.age' "$SECRETS_DIR/.gitignore"
grep -qF '!**/.env.*.age' "$SECRETS_DIR/.gitignore"
grep -qF '!**/.dev.vars.age' "$SECRETS_DIR/.gitignore"
}