Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -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" }}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 . -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down
11 changes: 11 additions & 0 deletions home/.chezmoitemplates/lib/chezmoi/active-group-values.json.tmpl
Original file line number Diff line number Diff line change
@@ -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 -}}
4 changes: 4 additions & 0 deletions home/.chezmoitemplates/lib/chezmoi/active-groups.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- $groups := list "shared" -}}
{{- if .personal }}{{ $groups = append $groups "personal" }}{{ end -}}
{{- if .work }}{{ $groups = append $groups "work" }}{{ end -}}
{{- $groups | toJson -}}
4 changes: 1 addition & 3 deletions home/dot_apm/apm.yml.tmpl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions home/dot_config/mise/config.toml.tmpl
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand Down
92 changes: 92 additions & 0 deletions tests/template/chezmoi-helpers.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/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}'
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"
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 '["graphify","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 '["graphify","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 '["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"]'
}
Loading