Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (90 loc) · 4.61 KB
/
Copy pathMakefile
File metadata and controls
110 lines (90 loc) · 4.61 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
SHELL := /bin/bash
.DEFAULT_GOAL := help
FEATURE := agentified
UNIT_IMAGE := agentified-unit
DEVCONTAINER := npx --yes @devcontainers/cli@latest
SCENARIO ?=
SHELL_SOURCES := src/$(FEATURE)/install.sh \
src/$(FEATURE)/files/bin/agentified \
$(wildcard src/$(FEATURE)/files/lib/*.sh) \
$(wildcard test/$(FEATURE)/*.sh) \
test/unit/helper.bash \
example/demo.sh \
example/.devcontainer/welcome.sh
## help: list targets
help:
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/^## / /'
## unit-image: build the (cached) container the unit tests and linters run in
unit-image:
@docker build -q -t $(UNIT_IMAGE) -f test/unit/Dockerfile test/unit >/dev/null
@echo "built $(UNIT_IMAGE)"
## unit: fast pure-bash tests — no root, no network, no container build
unit: unit-image
docker run --rm -v "$(CURDIR):/code" $(UNIT_IMAGE)
JSON_SOURCES := src/$(FEATURE)/devcontainer-feature.json \
src/$(FEATURE)/files/policy/claude-managed-settings.json \
test/$(FEATURE)/scenarios.json \
example/.devcontainer/devcontainer.json
## lint: shellcheck every shell source, plus JSON well-formedness
lint: unit-image
docker run --rm -v "$(CURDIR):/code" -w /code --entrypoint shellcheck $(UNIT_IMAGE) \
-x -S style $(SHELL_SOURCES)
@# These files are JSONC, not JSON: the devcontainer tooling parses them with
@# a comment-tolerant parser, so plain JSON.parse would reject valid files and
@# push you into writing fake "//key" entries instead of real comments.
@for f in $(JSON_SOURCES); do \
npx --yes strip-json-comments-cli < "$$f" \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>JSON.parse(s))' \
|| { echo "INVALID $$f"; exit 1; }; \
echo "ok $$f"; \
done
## check: lint + unit. What you run before pushing.
check: lint unit
# The autogenerated test.sh runs against `--base-image`, which defaults to
# ubuntu:focal — no sudo, no non-root user, and package names that no longer
# exist. Point it at a real devcontainer base instead.
AUTOGEN_BASE := mcr.microsoft.com/devcontainers/base:bookworm
AUTOGEN_USER := vscode
## test-feature: full integration suite (builds real containers; slow)
test-feature:
$(DEVCONTAINER) features test --project-folder . --features $(FEATURE) \
--base-image $(AUTOGEN_BASE) --remote-user $(AUTOGEN_USER)
## test-one: single scenario, e.g. make test-one SCENARIO=learn_mode
test-one:
@test -n "$(SCENARIO)" || { echo "usage: make test-one SCENARIO=<name>"; exit 2; }
$(DEVCONTAINER) features test --project-folder . --features $(FEATURE) \
--filter "$(SCENARIO)" --skip-autogenerated
## test-scenarios: every scenario, skipping the autogenerated default test
test-scenarios:
$(DEVCONTAINER) features test --project-folder . --features $(FEATURE) --skip-autogenerated
EXAMPLE_FEATURE := example/.devcontainer/agentified
# The devcontainer CLI only accepts a local Feature whose path resolves inside
# .devcontainer/, and it cannot read one through a symlink. So the source is
# copied in, fresh, before every run — never edit the copy.
sync-example:
@rm -rf "$(EXAMPLE_FEATURE)"
@cp -R "src/$(FEATURE)" "$(EXAMPLE_FEATURE)"
## up: rebuild the example devcontainer from scratch against the local source
up: sync-example
$(DEVCONTAINER) up --workspace-folder example --remove-existing-container
# `devcontainer exec` attaches to a container that is already running — it never
# creates one, and its error when there isn't one ("Dev container not found")
# does not say so. Without --remove-existing-container, `up` is idempotent: it
# reuses the existing container, starts it if stopped, and builds one if there
# is none. So the exec targets depend on this rather than failing cryptically.
ensure-up: sync-example
@echo "==> ensuring the example dev container is up (the first run builds it)"
@$(DEVCONTAINER) up --workspace-folder example
## verify: run the assertion suite inside the example devcontainer
verify: ensure-up
$(DEVCONTAINER) exec --workspace-folder example sudo agentified verify
## shell: open a shell in the example devcontainer
shell: ensure-up
$(DEVCONTAINER) exec --workspace-folder example bash
## clean: remove the example container and its state volume
clean:
-$(DEVCONTAINER) exec --workspace-folder example true >/dev/null 2>&1
-docker ps -aq --filter "label=devcontainer.local_folder=$(CURDIR)/example" | xargs -r docker rm -f
-docker volume ls -q --filter "name=agentified-state-" | xargs -r docker volume rm
.PHONY: help unit-image unit lint check test-feature test-one test-scenarios \
sync-example up ensure-up verify shell clean