From 2b9ead8c94043ae6389a7c6f903f2956dacdd198 Mon Sep 17 00:00:00 2001 From: Edwin Hernandez Date: Thu, 25 Jun 2026 20:08:48 -0500 Subject: [PATCH 1/3] feat: DOT-30 add chezmoi group helpers and integrate across templates --- .../run_onchange_02_install-packages.sh.tmpl | 4 +- .../run_onchange_03_install-uv-tools.sh.tmpl | 4 +- ...nchange_08_install-graphify-skills.sh.tmpl | 8 +- .../lib/chezmoi/active-group-values.json.tmpl | 11 +++ .../lib/chezmoi/active-groups.json.tmpl | 4 + home/dot_apm/apm.yml.tmpl | 4 +- home/dot_config/mise/config.toml.tmpl | 4 +- tests/template/chezmoi-helpers.bats | 73 +++++++++++++++++++ 8 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 home/.chezmoitemplates/lib/chezmoi/active-group-values.json.tmpl create mode 100644 home/.chezmoitemplates/lib/chezmoi/active-groups.json.tmpl create mode 100644 tests/template/chezmoi-helpers.bats diff --git a/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl b/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl index af79967..29d05d3 100644 --- a/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl +++ b/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl @@ -1,7 +1,5 @@ #!/usr/bin/env bash -{{ $groups := list "shared" }} -{{ if .personal }}{{ $groups = append $groups "personal" }}{{ end }} -{{ if .work }}{{ $groups = append $groups "work" }}{{ end }} +{{ $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson }} # packages.yaml hash: {{ include ".chezmoidata/packages.yaml" | sha256sum }} {{ if eq .chezmoi.os "darwin" }} diff --git a/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl b/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl index 65f455a..5e8b607 100644 --- a/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl +++ b/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl @@ -1,8 +1,6 @@ #!/usr/bin/env bash # uv tools data hash: {{ include ".chezmoidata/uv.yaml" | sha256sum }} -{{- $groups := list "shared" -}} -{{- if .personal }}{{ $groups = append $groups "personal" }}{{ end -}} -{{- if .work }}{{ $groups = append $groups "work" }}{{ end -}} +{{- $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} {{- $hasTools := false -}} {{- range $groups -}} {{- $tools := index $.uv.tools . -}} diff --git a/home/.chezmoiscripts/darwin/run_onchange_08_install-graphify-skills.sh.tmpl b/home/.chezmoiscripts/darwin/run_onchange_08_install-graphify-skills.sh.tmpl index aba82d4..89a579e 100644 --- a/home/.chezmoiscripts/darwin/run_onchange_08_install-graphify-skills.sh.tmpl +++ b/home/.chezmoiscripts/darwin/run_onchange_08_install-graphify-skills.sh.tmpl @@ -2,15 +2,11 @@ # @file run_onchange_08_install-graphify-skills.sh # @brief Install Graphify agent skills. # @description APM data hash: {{ include ".chezmoidata/apm.yaml" | sha256sum }} +{{- $activeTargets := includeTemplate "lib/chezmoi/active-group-values.json.tmpl" (dict "ctx" . "valuesByGroup" .apm.targets) | fromJson -}} {{- $platforms := list -}} -{{- if .personal -}} -{{- range (index .apm.targets "shared") -}} +{{- range $activeTargets -}} {{- if eq . "agent-skills" }}{{ $platforms = append $platforms "agents" }}{{- else if eq . "claude" }}{{ $platforms = append $platforms "claude" }}{{- end -}} {{- end -}} -{{- range (index .apm.targets "personal") -}} -{{- if eq . "agent-skills" }}{{ $platforms = append $platforms "agents" }}{{- else if eq . "claude" }}{{ $platforms = append $platforms "claude" }}{{- end -}} -{{- end -}} -{{- end }} {{ if and (eq .chezmoi.os "darwin") (gt (len $platforms) 0) }} {{ template "lib/common/log.sh" . }} diff --git a/home/.chezmoitemplates/lib/chezmoi/active-group-values.json.tmpl b/home/.chezmoitemplates/lib/chezmoi/active-group-values.json.tmpl new file mode 100644 index 0000000..4e3e5fb --- /dev/null +++ b/home/.chezmoitemplates/lib/chezmoi/active-group-values.json.tmpl @@ -0,0 +1,11 @@ +{{- $ctx := .ctx -}} +{{- $valuesByGroup := .valuesByGroup -}} +{{- $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" $ctx | fromJson -}} +{{- $values := list -}} +{{- range $groups -}} +{{- $groupValues := index $valuesByGroup . -}} +{{- range $groupValues -}} +{{- $values = append $values . -}} +{{- end -}} +{{- end -}} +{{- $values | toJson -}} diff --git a/home/.chezmoitemplates/lib/chezmoi/active-groups.json.tmpl b/home/.chezmoitemplates/lib/chezmoi/active-groups.json.tmpl new file mode 100644 index 0000000..178c6c0 --- /dev/null +++ b/home/.chezmoitemplates/lib/chezmoi/active-groups.json.tmpl @@ -0,0 +1,4 @@ +{{- $groups := list "shared" -}} +{{- if .personal }}{{ $groups = append $groups "personal" }}{{ end -}} +{{- if .work }}{{ $groups = append $groups "work" }}{{ end -}} +{{- $groups | toJson -}} diff --git a/home/dot_apm/apm.yml.tmpl b/home/dot_apm/apm.yml.tmpl index 9b6d044..fa4e66b 100644 --- a/home/dot_apm/apm.yml.tmpl +++ b/home/dot_apm/apm.yml.tmpl @@ -1,6 +1,4 @@ -{{- $groups := list "shared" -}} -{{- if .personal }}{{ $groups = append $groups "personal" }}{{ end -}} -{{- if .work }}{{ $groups = append $groups "work" }}{{ end -}} +{{- $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} name: development version: 1.0.0 description: APM project for development diff --git a/home/dot_config/mise/config.toml.tmpl b/home/dot_config/mise/config.toml.tmpl index a76b2ff..88b2267 100644 --- a/home/dot_config/mise/config.toml.tmpl +++ b/home/dot_config/mise/config.toml.tmpl @@ -1,7 +1,5 @@ [tools] -{{ $groups := list "shared" -}} -{{ if .personal }}{{ $groups = append $groups "personal" }}{{ end -}} -{{ if .work }}{{ $groups = append $groups "work" }}{{ end -}} +{{ $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} {{ range $groups -}} {{ $tools := index $.mise.tools . -}} {{ range $tools -}} diff --git a/tests/template/chezmoi-helpers.bats b/tests/template/chezmoi-helpers.bats new file mode 100644 index 0000000..3f90b48 --- /dev/null +++ b/tests/template/chezmoi-helpers.bats @@ -0,0 +1,73 @@ +#!/usr/bin/env bats +# @file tests/template/chezmoi-helpers.bats +# @brief Template rendering tests for chezmoi helper templates. + +load '../test_helpers/load.bash' + +SOURCE_DIR="$DOTFILES_ROOT/home" +ACTIVE_GROUPS_TMPL="$DOTFILES_ROOT/home/.chezmoitemplates/lib/chezmoi/active-groups.json.tmpl" +ACTIVE_GROUP_VALUES_TMPL="$DOTFILES_ROOT/home/.chezmoitemplates/lib/chezmoi/active-group-values.json.tmpl" + +DARWIN_DATA='{"chezmoi":{"os":"darwin"},"personal":true,"work":false}' +WORK_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":true}' +SHARED_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":false}' + +APM_VALUES_BY_GROUP='{"shared":[],"personal":["claude","agent-skills"],"work":["copilot"]}' + +render_helper() { + local template="$1" + local data="$2" + + mise exec -- chezmoi execute-template --source "$SOURCE_DIR" --override-data "$data" <"$template" +} + +@test "active-groups returns shared and personal for personal context" { + run render_helper "$ACTIVE_GROUPS_TMPL" "$DARWIN_DATA" + + assert_success + assert_output '["shared","personal"]' +} + +@test "active-groups returns shared and work for work context" { + run render_helper "$ACTIVE_GROUPS_TMPL" "$WORK_DATA" + + assert_success + assert_output '["shared","work"]' +} + +@test "active-groups returns only shared when neither personal nor work" { + run render_helper "$ACTIVE_GROUPS_TMPL" "$SHARED_DATA" + + assert_success + assert_output '["shared"]' +} + +@test "active-group-values merges shared and personal apm targets for personal context" { + local data + data=$(printf '{"ctx":{"personal":true,"work":false},"valuesByGroup":%s}' "$APM_VALUES_BY_GROUP") + + run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" + + assert_success + assert_output '["claude","agent-skills"]' +} + +@test "active-group-values merges shared and work apm targets for work context" { + local data + data=$(printf '{"ctx":{"personal":false,"work":true},"valuesByGroup":%s}' "$APM_VALUES_BY_GROUP") + + run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" + + assert_success + assert_output '["copilot"]' +} + +@test "active-group-values returns only shared apm targets when neither personal nor work" { + local data + data=$(printf '{"ctx":{"personal":false,"work":false},"valuesByGroup":%s}' "$APM_VALUES_BY_GROUP") + + run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" + + assert_success + assert_output '[]' +} From c859cc0925f3a8a3069950de3d9ba6eed85c882b Mon Sep 17 00:00:00 2001 From: Edwin Hernandez Date: Thu, 25 Jun 2026 21:02:22 -0500 Subject: [PATCH 2/3] fix: DOT-30 standardize helper invocation and fix shared fixture Use {{ ... -}} uniformly across all 4 active-groups callers. Fix APM_VALUES_BY_GROUP shared fixture to ["graphify"] so the merge path is exercised; update assertions for personal, work, and shared-only. --- .../darwin/run_onchange_02_install-packages.sh.tmpl | 2 +- .../darwin/run_onchange_03_install-uv-tools.sh.tmpl | 2 +- home/dot_apm/apm.yml.tmpl | 2 +- tests/template/chezmoi-helpers.bats | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl b/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl index 29d05d3..fcd636c 100644 --- a/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl +++ b/home/.chezmoiscripts/darwin/run_onchange_02_install-packages.sh.tmpl @@ -1,5 +1,5 @@ #!/usr/bin/env bash -{{ $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson }} +{{ $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} # packages.yaml hash: {{ include ".chezmoidata/packages.yaml" | sha256sum }} {{ if eq .chezmoi.os "darwin" }} diff --git a/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl b/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl index 5e8b607..e69c052 100644 --- a/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl +++ b/home/.chezmoiscripts/darwin/run_onchange_03_install-uv-tools.sh.tmpl @@ -1,6 +1,6 @@ #!/usr/bin/env bash # uv tools data hash: {{ include ".chezmoidata/uv.yaml" | sha256sum }} -{{- $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} +{{ $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} {{- $hasTools := false -}} {{- range $groups -}} {{- $tools := index $.uv.tools . -}} diff --git a/home/dot_apm/apm.yml.tmpl b/home/dot_apm/apm.yml.tmpl index fa4e66b..d178edc 100644 --- a/home/dot_apm/apm.yml.tmpl +++ b/home/dot_apm/apm.yml.tmpl @@ -1,4 +1,4 @@ -{{- $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} +{{ $groups := includeTemplate "lib/chezmoi/active-groups.json.tmpl" . | fromJson -}} name: development version: 1.0.0 description: APM project for development diff --git a/tests/template/chezmoi-helpers.bats b/tests/template/chezmoi-helpers.bats index 3f90b48..f1ad9ab 100644 --- a/tests/template/chezmoi-helpers.bats +++ b/tests/template/chezmoi-helpers.bats @@ -12,7 +12,7 @@ DARWIN_DATA='{"chezmoi":{"os":"darwin"},"personal":true,"work":false}' WORK_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":true}' SHARED_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":false}' -APM_VALUES_BY_GROUP='{"shared":[],"personal":["claude","agent-skills"],"work":["copilot"]}' +APM_VALUES_BY_GROUP='{"shared":["graphify"],"personal":["claude","agent-skills"],"work":["copilot"]}' render_helper() { local template="$1" @@ -49,7 +49,7 @@ render_helper() { run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" assert_success - assert_output '["claude","agent-skills"]' + assert_output '["graphify","claude","agent-skills"]' } @test "active-group-values merges shared and work apm targets for work context" { @@ -59,7 +59,7 @@ render_helper() { run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" assert_success - assert_output '["copilot"]' + assert_output '["graphify","copilot"]' } @test "active-group-values returns only shared apm targets when neither personal nor work" { @@ -69,5 +69,5 @@ render_helper() { run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" assert_success - assert_output '[]' + assert_output '["graphify"]' } From 8fe284c91325b10152a40a8b3a53b03edf116b8f Mon Sep 17 00:00:00 2001 From: Edwin Hernandez Date: Thu, 25 Jun 2026 21:20:04 -0500 Subject: [PATCH 3/3] test: DOT-30 add edge case tests for chezmoi group helpers --- tests/template/chezmoi-helpers.bats | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/template/chezmoi-helpers.bats b/tests/template/chezmoi-helpers.bats index f1ad9ab..96759b9 100644 --- a/tests/template/chezmoi-helpers.bats +++ b/tests/template/chezmoi-helpers.bats @@ -11,8 +11,10 @@ ACTIVE_GROUP_VALUES_TMPL="$DOTFILES_ROOT/home/.chezmoitemplates/lib/chezmoi/acti DARWIN_DATA='{"chezmoi":{"os":"darwin"},"personal":true,"work":false}' WORK_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":true}' SHARED_DATA='{"chezmoi":{"os":"darwin"},"personal":false,"work":false}' +BOTH_DATA='{"chezmoi":{"os":"darwin"},"personal":true,"work":true}' APM_VALUES_BY_GROUP='{"shared":["graphify"],"personal":["claude","agent-skills"],"work":["copilot"]}' +APM_VALUES_SPARSE='{"shared":["graphify"]}' render_helper() { local template="$1" @@ -71,3 +73,20 @@ render_helper() { assert_success assert_output '["graphify"]' } + +@test "active-groups returns shared, personal, and work when both are true" { + run render_helper "$ACTIVE_GROUPS_TMPL" "$BOTH_DATA" + + assert_success + assert_output '["shared","personal","work"]' +} + +@test "active-group-values silently skips groups absent from valuesByGroup" { + local data + data=$(printf '{"ctx":{"personal":true,"work":false},"valuesByGroup":%s}' "$APM_VALUES_SPARSE") + + run render_helper "$ACTIVE_GROUP_VALUES_TMPL" "$data" + + assert_success + assert_output '["graphify"]' +}