aboutsummaryrefslogtreecommitdiff
path: root/scripts/tests/install-lang-completeness.bats
blob: 42832dc5d3dc148bff6b04528ccffe297a712431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bats
#
# Tests for install-lang.sh's bundle-completeness warning.
#
# Background: the python and typescript bundles shipped for nearly two months
# with no githooks/pre-commit, so any project installing them got no
# credential scan on commit. install-lang guarded each component copy with a
# plain `[ -d ... ]`, so a missing component was indistinguishable from a
# complete install — it printed nothing and exited 0.
#
# The fix is not "never miss a component" (a person will), it's "say so when
# you do". These tests pin that: a complete bundle installs quietly, an
# incomplete one names exactly what's absent, and neither case fails the
# install — a warning must not become a new way to block work.

REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
INSTALL="$REPO_ROOT/scripts/install-lang.sh"

setup() {
  TEST_DIR="$(mktemp -d -t install-lang-bats.XXXXXX)"
  PROJECT="$TEST_DIR/proj"
  mkdir -p "$PROJECT"
  git init -q "$PROJECT"
}

teardown() {
  rm -rf "$TEST_DIR"
}

# ---- Normal: a complete bundle is quiet ------------------------------

@test "install-lang: a complete bundle warns about nothing" {
  run env LANG_ARG=bash bash "$INSTALL" bash "$PROJECT"
  [ "$status" -eq 0 ]
  [[ "$output" != *"incomplete"* ]]
}

@test "install-lang: python is now a complete bundle" {
  run bash "$INSTALL" python "$PROJECT"
  [ "$status" -eq 0 ]
  [[ "$output" != *"incomplete"* ]]
  [ -f "$PROJECT/githooks/pre-commit" ]
  [ -f "$PROJECT/.claude/settings.json" ]
  [ -f "$PROJECT/.claude/hooks/validate-python.sh" ]
}

@test "install-lang: typescript is now a complete bundle" {
  run bash "$INSTALL" typescript "$PROJECT"
  [ "$status" -eq 0 ]
  [[ "$output" != *"incomplete"* ]]
  [ -f "$PROJECT/githooks/pre-commit" ]
  [ -f "$PROJECT/.claude/settings.json" ]
  [ -f "$PROJECT/.claude/hooks/validate-typescript.sh" ]
}

@test "install-lang: the installed pre-commit is executable" {
  run bash "$INSTALL" python "$PROJECT"
  [ "$status" -eq 0 ]
  [ -x "$PROJECT/githooks/pre-commit" ]
}

# ---- Error: an incomplete bundle announces itself --------------------

@test "install-lang: a bundle missing githooks/ warns and names it" {
  fake="$REPO_ROOT/languages/zz-test-partial"
  mkdir -p "$fake/claude/rules"
  printf '# rule\n' > "$fake/claude/rules/zz.md"
  run bash "$INSTALL" zz-test-partial "$PROJECT"
  rm -rf "$fake"
  [ "$status" -eq 0 ]
  [[ "$output" == *"incomplete"* ]]
  [[ "$output" == *"githooks/pre-commit"* ]]
}

@test "install-lang: the warning names every missing component, not just the first" {
  fake="$REPO_ROOT/languages/zz-test-partial"
  mkdir -p "$fake/claude/rules"
  printf '# rule\n' > "$fake/claude/rules/zz.md"
  run bash "$INSTALL" zz-test-partial "$PROJECT"
  rm -rf "$fake"
  [[ "$output" == *"githooks/pre-commit"* ]]
  [[ "$output" == *"settings.json"* ]]
}

@test "install-lang: an incomplete bundle still installs (warn, never block)" {
  fake="$REPO_ROOT/languages/zz-test-partial"
  mkdir -p "$fake/claude/rules"
  printf '# rule\n' > "$fake/claude/rules/zz.md"
  run bash "$INSTALL" zz-test-partial "$PROJECT"
  rm -rf "$fake"
  [ "$status" -eq 0 ]
  [ -f "$PROJECT/.claude/rules/zz.md" ]
}