Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
299 lines (271 loc) · 11.1 KB
/
Copy pathjustfile
File metadata and controls
299 lines (271 loc) · 11.1 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env just --justfile
# camp CLI build and development tasks
set dotenv-load := true
# Configuration
binary_name := "camp"
bin_dir := "bin"
gobin := env_var_or_default("GOBIN", `go env GOPATH` + "/bin")
version_pkg := "github.com/Obedience-Corp/camp/internal/version"
version := env_var_or_default("VERSION", `git describe --tags --always --dirty 2>/dev/null || echo "dev"`)
commit := `git rev-parse --short HEAD 2>/dev/null || echo "unknown"`
build_date := `date -u +"%Y-%m-%dT%H:%M:%SZ"`
ldflags := "-X " + version_pkg + ".Version=" + version + " -X " + version_pkg + ".Commit=" + commit + " -X " + version_pkg + ".BuildDate=" + build_date
# Modules
[doc('Build (local, profiles, cross-platform)')]
mod build '.justfiles/build.just'
[doc('Testing (unit, coverage, benchmarks)')]
mod test '.justfiles/test.just'
[doc('Release and versioning')]
mod release '.justfiles/release.just'
[doc('Install camp to $GOBIN (stable, dev, current)')]
mod install '.justfiles/install.just'
[doc('Record terminal workflows with VHS')]
mod vhs '.justfiles/vhs.just'
[doc('Verify interactive surfaces in a terminal harness (pty checks + tapes)')]
mod tui '.justfiles/tui.just'
[private]
default:
@echo "camp CLI - Campaign Management Tool"
@echo ""
@just --list --unsorted
# Build camp binary (shortcut for `just build default-build`)
build-camp:
@go run ./internal/buildutil build
# Format Go code
fmt:
go fmt ./...
# Run go vet
vet:
go vet ./...
# Run golangci-lint against new branch issues (includes vet, staticcheck, errcheck, and more).
# The repository still has historical default-linter findings, so this gate
# blocks new regressions relative to origin/main while that backlog is migrated.
lint:
#!/usr/bin/env sh
set -eu
base="${GOLANGCI_LINT_BASE:-origin/main}"
if git rev-parse --verify "$base" >/dev/null 2>&1; then
golangci-lint run --new-from-merge-base "$base" ./...
else
echo "lint: $base not found; falling back to golangci-lint --new"
golangci-lint run --new ./...
fi
just lint-no-host-fs-tests
just lint-no-fmt-errorf
just lint-no-raw-userhomedir
go vet -tags=integration ./...
# Reject NEW host-side filesystem-mutating test patterns outside
# tests/integration/. Standing rule (feedback_docker_integration_tests.md):
# exec.Command("git", ...) and similar must run through the containerized
# harness, not host t.TempDir.
#
# Detection covers direct git exec AND helper usage (runGit, mustRunGit,
# initTestRepo, exec.Command(args[0]) wrappers, …). Files that only call
# those helpers were invisible to the old grep; that hole is the point of
# the scanner. Allowlist: internal/hostfslint/allowlist.go.
#
# A test that mutates real filesystem state is compliant when it cannot run
# on a developer's machine. There are two ways to achieve that, and the rule
# accepts both (decision D007):
#
# 1. it lives under tests/integration/ and drives the camp binary, or
# 2. it carries the container_fs build tag, so a plain `just test` does
# not compile it, and the integration lane cross-compiles it and runs
# it inside a pooled container (tests/integration/containerfs_test.go).
lint-no-host-fs-tests:
go run ./internal/hostfslint
# Reject NEW fmt.Errorf occurrences in production code outside tools/.
# This is a count ratchet against the merge-base with origin/main, so legacy
# files can be burned down incrementally but cannot accumulate new uses.
lint-no-fmt-errorf:
#!/usr/bin/env sh
set -eu
base_ref="${FMT_ERRORF_BASE:-origin/main}"
if ! base_commit=$(git merge-base HEAD "$base_ref" 2>/dev/null); then
echo "FAIL: cannot find merge-base with $base_ref for fmt.Errorf ratchet"
echo "Fetch $base_ref or set FMT_ERRORF_BASE to a reachable base ref."
exit 1
fi
files=$(find ./cmd ./internal ./pkg -name '*.go' -not -name '*_test.go' -print 2>/dev/null | sed 's#^\./##' || true)
new_violators=""
current_files=0
for file in $files; do
current_count=$(grep -o "fmt\\.Errorf" "$file" 2>/dev/null | wc -l | tr -d ' ')
if [ "$current_count" -eq 0 ]; then
continue
fi
current_files=$((current_files + 1))
if git cat-file -e "$base_commit:$file" 2>/dev/null; then
base_count=$(git show "$base_commit:$file" | grep -o "fmt\\.Errorf" | wc -l | tr -d ' ')
else
base_count=0
fi
if [ "$current_count" -gt "$base_count" ]; then
new_violators="$new_violators $file:$current_count:$base_count"
fi
done
if [ -n "$new_violators" ]; then
echo "FAIL: fmt.Errorf count regression in production code (outside tools/):"
for violation in $new_violators; do
file=$(printf "%s" "$violation" | cut -d: -f1)
current_count=$(printf "%s" "$violation" | cut -d: -f2)
base_count=$(printf "%s" "$violation" | cut -d: -f3)
echo " $file ($current_count current, $base_count at $base_ref merge-base)"
done
echo ""
echo "Use camperrors.Wrap / camperrors.Wrapf instead."
exit 1
fi
echo "lint-no-fmt-errorf: clean (no fmt.Errorf count regressions; $current_files current file(s) at/below merge-base baseline)"
# Reject os.UserHomeDir in production code outside internal/pathutil/home.go.
#
# os.UserHomeDir returns ("", err) for an unset HOME and hands back a
# whitespace-only HOME as a valid answer. Joining state paths onto either
# produces a RELATIVE path, so camp writes ~/.obey state into whatever directory
# it was invoked from and cannot find it again from anywhere else. That shipped
# as "camp create succeeded but camp list is empty".
#
# pathutil.Home is the single resolver that rejects both. Unlike the other two
# lint rules this is absolute, not a ratchet: there are zero violators and no
# allowlist, because there is no case where raw os.UserHomeDir is the right call.
lint-no-raw-userhomedir:
#!/usr/bin/env sh
set -eu
allowed="internal/pathutil/home.go"
violators=$(find ./cmd ./internal ./pkg -name '*.go' -not -name '*_test.go' -print 2>/dev/null \
| sed 's#^\./##' \
| while read -r file; do
[ "$file" = "$allowed" ] && continue
if grep -q "os\.UserHomeDir" "$file" 2>/dev/null; then
echo "$file"
fi
done)
if [ -n "$violators" ]; then
echo "FAIL: os.UserHomeDir in production code outside $allowed:"
echo "$violators" | sed 's/^/ /'
echo ""
echo "Use pathutil.Home() instead. It fails on unset AND whitespace-only"
echo "HOME, so a state path can never resolve relative to the cwd."
exit 1
fi
echo "lint-no-raw-userhomedir: clean (only $allowed resolves the home directory)"
# Verify the fmt.Errorf ratchet rejects a new production violator.
test-ratchet:
#!/usr/bin/env sh
set -eu
tmpfile=./internal/tmptest_fmt_errorf_ratchet.go
cleanup() { rm -f "$tmpfile"; }
trap cleanup EXIT INT TERM
printf 'package internal\nimport "fmt"\nfunc _tmp() error { return fmt.Errorf("bad") }\n' > "$tmpfile"
if just lint-no-fmt-errorf 2>&1 | grep -q "FAIL"; then
echo "ratchet test: PASS (correctly rejected new fmt.Errorf)"
else
echo "ratchet test: FAIL (should have rejected new fmt.Errorf)"
exit 1
fi
# Lightweight on-demand smoke check, faster than gate-fast: whitespace,
# stable/dev build, vet, lint, and the short dev-profile test subset.
# Run it for a quick signal before pushing. See also: just gate-fast, just gate.
gate-push:
#!/usr/bin/env sh
set -eu
echo "=== gate-push: whitespace ==="
git diff --check
echo "=== gate-push: stable build ==="
just build-camp
echo "=== gate-push: dev build ==="
BUILD_TAGS=dev just build-camp
echo "=== gate-push: vet stable ==="
go vet ./...
echo "=== gate-push: vet dev ==="
go vet -tags dev ./...
echo "=== gate-push: vet integration ==="
go vet -tags=integration ./...
echo "=== gate-push: lint stable ==="
just lint
echo "=== gate-push: lint dev ==="
BUILD_TAGS=dev just lint
echo "=== gate-push: dev short tests ==="
go test -short -tags dev ./...
echo "=== gate-push: PASSED ==="
# Run both-profile builds, vet (stable/dev/integration), lint both profiles,
# CLI docs freshness, and dev unit tests.
# Use this before moving a PR out of draft or when touching broad behavior. See also: just gate.
gate-fast:
#!/usr/bin/env sh
set -eu
echo "=== gate-fast: stable build ==="
just build-camp
echo "=== gate-fast: dev build ==="
BUILD_TAGS=dev just build-camp
echo "=== gate-fast: install over a running binary (ETXTBSY regression) ==="
just install test-live-overwrite
echo "=== gate-fast: vet stable ==="
go vet ./...
echo "=== gate-fast: vet dev ==="
go vet -tags dev ./...
echo "=== gate-fast: vet integration ==="
go vet -tags=integration ./...
echo "=== gate-fast: lint stable ==="
just lint
echo "=== gate-fast: lint dev ==="
BUILD_TAGS=dev just lint
echo "=== gate-fast: CLI docs ==="
just docs-check
echo "=== gate-fast: unit tests dev (the profile festival-app ships) ==="
BUILD_TAGS=dev just test unit
echo "=== gate-fast: PASSED ==="
# Run the full both-profile gate: gate-fast plus stable unit tests (C-2 matrix).
# Required by release recipes before tagging; the per-sequence closing command for sequences 05-12.
# GitHub Actions runs gate-fast on every PR and main push (.github/workflows/gate.yml);
# the stable unit pass and the containerized integration suite stay local.
gate:
#!/usr/bin/env sh
set -eu
just gate-fast
echo "=== gate: unit tests stable ==="
just test unit
echo "=== gate: PASSED ==="
# Install required development tools
install-tools:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
# Clean build artifacts
clean:
rm -rf {{bin_dir}}
rm -f coverage.out coverage.html
@echo "Cleaned build artifacts"
# Update and tidy dependencies
deps:
go get -u ./...
go mod tidy
# Tidy dependencies
tidy:
go mod tidy
# Uninstall camp from $GOBIN
uninstall:
@echo "Uninstalling camp..."
rm -f {{gobin}}/{{binary_name}}
@echo "camp uninstalled"
# Generate CLI reference docs
docs:
BUILD_TAGS='' just build-camp
./{{bin_dir}}/{{binary_name}} gendocs --output docs/cli-reference --format markdown --single
# Fail when the committed CLI reference no longer matches the code.
# Generates into a temp dir rather than the working tree, so running the gate
# never leaves modified files behind. Release recipes run this via `just gate`.
docs-check:
#!/usr/bin/env sh
set -eu
BUILD_TAGS='' just build-camp
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
./{{bin_dir}}/{{binary_name}} gendocs --output "$tmp" --format markdown --single
if ! diff -ru docs/cli-reference "$tmp" >/dev/null 2>&1; then
echo "FAIL: docs/cli-reference is stale. Run 'just docs' and commit the result." >&2
diff -ru docs/cli-reference "$tmp" | head -40 >&2
exit 1
fi
echo "docs/cli-reference is up to date"
# Run camp (for development)
run *ARGS:
go run ./cmd/camp {{ARGS}}