From 56cf2a44c2197f6d5813619aa88d27cec6d53fe3 Mon Sep 17 00:00:00 2001 From: Davood Tofighi Date: Wed, 23 Sep 2026 12:15:17 -0600 Subject: [PATCH] fix(claude-sync): skip only flow-test-sandbox memory, not all $TMPDIR projects #530 skipped every -private-var-folders-* project, but a session whose cwd was $TMPDIR itself (-private-var-folders-...-T) can hold real memory: two such projects here have 5 memory files, one edited 2026-09-21. Narrow both the chezmoi-add filter and the commit-time exclude to *-flow-test-sandbox-*, the mktemp name run-all.sh uses. Real dirs: 71 total, 11 skipped, both real TMPDIR projects kept. Co-Authored-By: Claude Opus 5.5 --- tests/test-claude-sync.zsh | 17 +++++++++++++++-- zsh/functions/claude-sync.zsh | 13 +++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/test-claude-sync.zsh b/tests/test-claude-sync.zsh index e7edfc754..3ad5db428 100644 --- a/tests/test-claude-sync.zsh +++ b/tests/test-claude-sync.zsh @@ -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" @@ -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" @@ -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 # ────────────────────────────────────────────────────────────────────────────── @@ -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 $? diff --git a/zsh/functions/claude-sync.zsh b/zsh/functions/claude-sync.zsh index c78e283fd..4419145a8 100644 --- a/zsh/functions/claude-sync.zsh +++ b/zsh/functions/claude-sync.zsh @@ -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[@]}" @@ -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