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
17 changes: 15 additions & 2 deletions tests/test-claude-sync.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ test_add_outside_claude_commits_that_path() {
}

test_skips_tmpdir_project_memory() {
test_case "memory dirs of \$TMPDIR projects (-private-var-folders-*) are not synced"
test_case "memory dirs of flow-cli test sandboxes (*-flow-test-sandbox-*) are not synced"
make_sandbox
local tmp_proj="$HOME/.claude/projects/-private-var-folders-xn-abc-T-flow-test-sandbox-1a2b3c"
mkdir -p "$tmp_proj/memory" && : > "$tmp_proj/memory/.keep"
Expand All @@ -182,7 +182,7 @@ test_skips_tmpdir_project_memory() {
}

test_does_not_commit_stale_tmpdir_copies_in_source() {
test_case "copies of \$TMPDIR project memory already in the source dir are not committed"
test_case "copies of test-sandbox memory already in the source dir are not committed"
make_sandbox
local stale="$SRC/dot_claude/projects/private_-private-var-folders-xn-abc-T-flow-test-sandbox-9z8y7x/memory"
mkdir -p "$stale" && : > "$stale/.keep"
Expand All @@ -194,6 +194,18 @@ test_does_not_commit_stale_tmpdir_copies_in_source() {
test_pass
}

test_syncs_real_memory_of_tmpdir_rooted_project() {
test_case "a \$TMPDIR-rooted project that is not a test sandbox still syncs"
make_sandbox
local tmp_root="$HOME/.claude/projects/-private-var-folders-xn-abc-T"
mkdir -p "$tmp_root/memory" && print -r -- "real" > "$tmp_root/memory/note.md"
claude-sync >/dev/null 2>&1
local remote_files; remote_files=$(git -C "$ORIGIN" ls-tree -r --name-only main)
teardown_sandbox
assert_contains "$remote_files" "dot_claude/projects/-private-var-folders-xn-abc-T/memory/note.md" || return
test_pass
}

# ──────────────────────────────────────────────────────────────────────────────
# MAIN
# ──────────────────────────────────────────────────────────────────────────────
Expand All @@ -211,6 +223,7 @@ main() {
test_add_outside_claude_commits_that_path
test_skips_tmpdir_project_memory
test_does_not_commit_stale_tmpdir_copies_in_source
test_syncs_real_memory_of_tmpdir_rooted_project

test_suite_end
exit $?
Expand Down
13 changes: 7 additions & 6 deletions zsh/functions/claude-sync.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ _claude_sync_commit() {
local src="$1" target="${2:-$HOME/.claude}" target_src
target_src=$(chezmoi source-path "$target" 2>/dev/null)
[[ -n "$target_src" ]] || return 1
# Also exclude $TMPDIR-project memory already copied into the source dir by
# an earlier run: skipping it at `chezmoi add` time alone would not stop it.
local -a spec=( "$target_src" ':(exclude,glob)**/*-private-var-folders-*/**' )
# Also exclude test-sandbox memory already copied into the source dir by an
# earlier run: skipping it at `chezmoi add` time alone would not stop it.
local -a spec=( "$target_src" ':(exclude,glob)**/*-flow-test-sandbox-*/**' )
git -C "$src" add -A -- "${spec[@]}" || return 1
git -C "$src" diff --cached --quiet -- "${spec[@]}" && return 0
git -C "$src" commit -q -m "chore(claude): claude-sync $(date +%Y-%m-%d)" -- "${spec[@]}"
Expand Down Expand Up @@ -72,9 +72,10 @@ claude-sync() {
# Default: sync tracked ~/.claude paths, commit (auto), push (unless --no-push)
local file_targets=( ~/.claude/CLAUDE.md(N) )
local dir_targets=( ~/.claude/projects/*/memory(N/) )
# Skip projects rooted in macOS $TMPDIR (/private/var/folders/...): test
# sandboxes and throwaway sessions, whose memory is never worth keeping.
dir_targets=( ${dir_targets:#*/projects/-private-var-folders-*} )
# Skip flow-cli test sandboxes (run-all.sh: mktemp -d .../flow-test-sandbox.XXXXXX),
# whose memory dirs are empty. Not every $TMPDIR-rooted project: a session whose
# cwd was $TMPDIR itself (-private-var-folders-...-T) can hold real memory.
dir_targets=( ${dir_targets:#*/projects/*-flow-test-sandbox-*} )

# Skip if nothing tracked yet
local tracked
Expand Down
Loading