Skip to content
Open
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
75 changes: 75 additions & 0 deletions .mise/tasks/lint/mise-shiv-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
#MISE description="Check that mise.toml has shiv plugin setup when declaring shiv-managed tools"
#USAGE arg "<targets>…" help="Paths to codebases to check (one or more)"

set -euo pipefail

# shellcheck source=../../../lib/shell-files.sh
source "$MISE_CONFIG_ROOT/lib/shell-files.sh"

# Required shiv plugin setup
REQUIRED_PLUGIN_LINE='shiv = "https://github.com/KnickKnackLabs/vfox-shiv"'
REQUIRED_SETTING='experimental = true'

IFS=' ' read -ra TARGETS <<< "${usage_targets}"

if [[ ${#TARGETS[@]} -eq 0 ]]; then
echo "ERROR: at least one target is required" >&2
exit 1
fi

# Resolve relative paths against CALLER_PWD (see lib/shell-files.sh).
for i in "${!TARGETS[@]}"; do
TARGETS[i]=$(resolve_target "${TARGETS[i]}")
done

failures=0

for target in "${TARGETS[@]}"; do
if [[ ! -e "$target" ]]; then
echo "ERROR: target does not exist: $target" >&2
exit 1
fi

toml="$target/mise.toml"
name=$(basename "$target")

if [[ ! -f "$toml" ]]; then
echo "INFO $name: no mise.toml found"
continue
fi

# Check for file-level ignore
if head -20 "$toml" | grep -q 'codebase:ignore mise-shiv-plugin'; then
echo "SKIP $name (codebase:ignore)"
continue
fi

# Check if any [tools] key starts with shiv:
if ! grep -q '^\s*"shiv:' "$toml" && ! grep -q "^shiv:" "$toml"; then
echo "OK $name (no shiv tools declared)"
continue
fi

missing=()

# Check [plugins] for shiv entry
if ! grep -Eq '^\s*shiv\s*=' "$toml"; then
missing+=("$REQUIRED_PLUGIN_LINE")
fi

# Check [settings] for experimental = true
if ! grep -q "^experimental = true" "$toml"; then
missing+=("$REQUIRED_SETTING")
fi

if [[ ${#missing[@]} -eq 0 ]]; then
echo "OK $name"
continue
fi

echo "FAIL $name: missing ${missing[*]}"
failures=$((failures + 1))
done

exit "$failures"
2 changes: 0 additions & 2 deletions test/lib/shell-files.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ setup() {
source "$REPO_DIR/lib/shell-files.sh"
}

# ============================================================================
# resolve_target
# ============================================================================

@test "resolve_target: absolute path passes through unchanged" {
result=$(resolve_target "/some/absolute/path")
Expand Down
14 changes: 0 additions & 14 deletions test/lint/bats-test-helper/bats-test-helper.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ setup() {
FIXTURES="$BATS_TEST_DIRNAME/fixtures"
}

# ============================================================================
# Pass paths
# ============================================================================

@test "bats-test-helper: passes on clean wrapper-based tests" {
run codebase lint:bats-test-helper "$FIXTURES/clean"
Expand All @@ -24,9 +22,7 @@ setup() {
[[ "$output" == *"no test/ files found"* ]]
}

# ============================================================================
# Invocation signatures — each form fails
# ============================================================================

@test "bats-test-helper: flags 'bash \$TASK' (var whose name contains TASK)" {
run codebase lint:bats-test-helper "$FIXTURES/dirty-task-var"
Expand Down Expand Up @@ -84,9 +80,7 @@ setup() {
[[ "$output" == *"bash \$REPO_DIR/.mise/tasks/lint/check"* ]]
}

# ============================================================================
# False positives — none of these are actual invocations
# ============================================================================

@test "bats-test-helper: does NOT flag reading a task file as data (grep/cat)" {
# Regression guard: 'grep "$MCR/.mise/tasks/foo"' reads the script, doesn't
Expand All @@ -97,9 +91,7 @@ setup() {
[[ "$output" == *"OK"* ]]
}

# ============================================================================
# Ignore directives
# ============================================================================

@test "bats-test-helper: inline '# codebase:ignore' suppresses a single line" {
run codebase lint:bats-test-helper "$FIXTURES/ignored-inline"
Expand All @@ -113,9 +105,7 @@ setup() {
[[ "$output" == *"SKIP"*"ignored-file"* ]]
}

# ============================================================================
# Output details
# ============================================================================

@test "bats-test-helper: fail output includes file:line citations" {
run codebase lint:bats-test-helper "$FIXTURES/dirty-task-var"
Expand All @@ -130,9 +120,7 @@ setup() {
[[ "$output" == *"Call the Tool"* ]]
}

# ============================================================================
# Error handling
# ============================================================================

@test "bats-test-helper: fails when no targets given" {
run codebase lint:bats-test-helper
Expand All @@ -146,9 +134,7 @@ setup() {
[[ "$output" == *"does not exist"* ]]
}

# ============================================================================
# Multi-target
# ============================================================================

@test "bats-test-helper: accepts multiple targets and reports each" {
run codebase lint:bats-test-helper "$FIXTURES/clean" "$FIXTURES/dirty-task-var"
Expand Down
12 changes: 0 additions & 12 deletions test/lint/bats-test-task/bats-test-task.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ setup() {
FIXTURES="$BATS_TEST_DIRNAME/fixtures"
}

# ============================================================================
# Pass paths
# ============================================================================

@test "bats-test-task: passes on the canonical pattern" {
run codebase lint:bats-test-task "$FIXTURES/clean"
Expand All @@ -33,9 +31,7 @@ setup() {
[[ "$output" == *"OK"*"shimmer-variant"* ]]
}

# ============================================================================
# Failure modes
# ============================================================================

@test "bats-test-task: flags missing USAGE arg spec" {
run codebase lint:bats-test-task "$FIXTURES/missing-usage-arg"
Expand Down Expand Up @@ -80,19 +76,15 @@ setup() {
[[ "$output" != *"invocations found"* ]]
}

# ============================================================================
# Ignore directive
# ============================================================================

@test "bats-test-task: 'codebase:ignore bats-test-task' in mise.toml skips the target" {
run codebase lint:bats-test-task "$FIXTURES/ignored-file"
[ "$status" -eq 0 ]
[[ "$output" == *"SKIP"*"ignored-file"* ]]
}

# ============================================================================
# Output details
# ============================================================================

@test "bats-test-task: fail output includes the remediation hint" {
run codebase lint:bats-test-task "$FIXTURES/missing-usage-arg"
Expand All @@ -109,9 +101,7 @@ setup() {
[[ "$output" == *"invocations"* ]]
}

# ============================================================================
# Error handling
# ============================================================================

@test "bats-test-task: fails when no targets given" {
run codebase lint:bats-test-task
Expand All @@ -125,9 +115,7 @@ setup() {
[[ "$output" == *"does not exist"* ]]
}

# ============================================================================
# Multi-target
# ============================================================================

@test "bats-test-task: accepts multiple targets and reports each" {
run codebase lint:bats-test-task "$FIXTURES/clean" "$FIXTURES/missing-examples"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# codebase:ignore mise-shiv-plugin — fixture for github-actions rule, not a mise-shiv-plugin test case
[plugins]
shiv = "https://github.com/KnickKnackLabs/vfox-shiv"

Expand Down
16 changes: 0 additions & 16 deletions test/lint/gum-table/gum-table.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ setup() {
FIXTURES="$BATS_TEST_DIRNAME/fixtures"
}

# ============================================================================
# High confidence: column -t (always a true positive)
# ============================================================================

@test "column-t: detects piping to column -t" {
run codebase lint:gum-table "$FIXTURES/manual-padding/task-c"
Expand All @@ -18,9 +16,7 @@ setup() {
[[ "$output" == *"WARN"* ]]
}

# ============================================================================
# High confidence: printf padding inside a loop
# ============================================================================

@test "loop-table: detects printf %-Ns inside while-read" {
run codebase lint:gum-table "$FIXTURES/manual-padding/task-b"
Expand All @@ -45,9 +41,7 @@ setup() {
echo "$output" | grep "padding" | grep -q "INFO"
}

# ============================================================================
# Low confidence: printf padding outside loops (INFO only, not a failure)
# ============================================================================

@test "padding: printf %-Ns outside loop is INFO, not a failure" {
run codebase lint:gum-table "$FIXTURES/manual-padding/task-a"
Expand All @@ -69,9 +63,7 @@ setup() {
[[ "$output" == *"INFO"* ]]
}

# ============================================================================
# True negatives — no output at all
# ============================================================================

@test "clean: already using gum table" {
run codebase lint:gum-table "$FIXTURES/clean/task-gum"
Expand Down Expand Up @@ -103,9 +95,7 @@ setup() {
[[ "$output" == *"OK"* ]]
}

# ============================================================================
# Multi-file scanning
# ============================================================================

@test "directory scan finds high-confidence hits" {
run codebase lint:gum-table "$FIXTURES/manual-padding"
Expand All @@ -121,9 +111,7 @@ setup() {
[ "$status" -eq 0 ]
}

# ============================================================================
# Output format
# ============================================================================

@test "WARN output includes file path, category, and line number" {
run codebase lint:gum-table "$FIXTURES/manual-padding/task-b"
Expand All @@ -136,19 +124,15 @@ setup() {
[[ "$output" =~ INFO.*task-a:\[padding\].*[0-9]+: ]]
}

# ============================================================================
# Error handling
# ============================================================================

@test "fails when target does not exist" {
run codebase lint:gum-table /nonexistent
[ "$status" -ne 0 ]
[[ "$output" == *"ERROR"* ]]
}

# ============================================================================
# Relative path resolution (regression: codebase#24)
# ============================================================================

@test "relative path resolves against CODEBASE_CALLER_PWD (dirty fixture)" {
# Regression: relative targets resolved against codebase's install
Expand Down
10 changes: 0 additions & 10 deletions test/lint/mcr-scope/mcr-scope.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ setup() {
FIXTURES="$BATS_TEST_DIRNAME/fixtures"
}

# ============================================================================
# Detection
# ============================================================================

@test "mcr-scope: passes on a clean codebase" {
run codebase lint:mcr-scope "$FIXTURES/clean"
Expand Down Expand Up @@ -102,9 +100,7 @@ setup() {
[[ "$output" == *"no test/ or lib/ files found"* ]]
}

# ============================================================================
# Ignore directives
# ============================================================================

@test "mcr-scope: inline '# codebase:ignore' suppresses a single line" {
run codebase lint:mcr-scope "$FIXTURES/ignored-inline"
Expand All @@ -118,9 +114,7 @@ setup() {
[[ "$output" == *"SKIP"*"ignored-file"* ]]
}

# ============================================================================
# Output details
# ============================================================================

@test "mcr-scope: fail output includes file:line citations" {
run codebase lint:mcr-scope "$FIXTURES/dirty-lib"
Expand All @@ -136,9 +130,7 @@ setup() {
[[ "$output" == *"BASH_SOURCE"* ]]
}

# ============================================================================
# Error handling
# ============================================================================

@test "mcr-scope: fails when no targets given" {
run codebase lint:mcr-scope
Expand All @@ -153,9 +145,7 @@ setup() {
[[ "$output" == *"does not exist"* ]]
}

# ============================================================================
# Multi-target
# ============================================================================

@test "mcr-scope: accepts multiple targets and reports each" {
run codebase lint:mcr-scope "$FIXTURES/clean" "$FIXTURES/dirty-test"
Expand Down
6 changes: 0 additions & 6 deletions test/lint/mise-settings/mise-settings.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ setup() {
FIXTURES="$BATS_TEST_DIRNAME/fixtures"
}

# ============================================================================
# Detection
# ============================================================================

@test "lint: passes when all settings present" {
run codebase lint:mise-settings "$FIXTURES/complete"
Expand Down Expand Up @@ -54,9 +52,7 @@ setup() {
[[ "$output" == *"FAIL"*"missing-both"* ]]
}

# ============================================================================
# Fix mode
# ============================================================================

@test "fix: adds missing settings" {
WORK_DIR="$BATS_TEST_TMPDIR/fix-test"
Expand Down Expand Up @@ -96,9 +92,7 @@ setup() {
[[ "$output" == *"OK"* ]]
}

# ============================================================================
# Error handling
# ============================================================================

@test "lint: fails when target does not exist" {
run codebase lint:mise-settings /nonexistent
Expand Down
10 changes: 10 additions & 0 deletions test/lint/mise-shiv-plugin/fixtures/complete/mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
experimental = true
quiet = true
task_output = "interleave"

[plugins]
shiv = "https://github.com/KnickKnackLabs/vfox-shiv"

[tools]
"shiv:codebase" = "latest"
Loading