Skip to content

Audit spotlight: add unit tests and fix stash safety bug#524

Merged
bborn merged 1 commit intomainfrom
task/2096-audit-and-evaluate-spotlight-function-ne
Mar 22, 2026
Merged

Audit spotlight: add unit tests and fix stash safety bug#524
bborn merged 1 commit intomainfrom
task/2096-audit-and-evaluate-spotlight-function-ne

Conversation

@bborn
Copy link
Owner

@bborn bborn commented Mar 22, 2026

Summary

  • Audited the spotlight function — it's a valid feature for users whose projects can't run from worktree directories (docker mounts, IDE settings, CI tooling, etc.)
  • Added 21 unit tests for the spotlight package covering: sync logic, start/stop lifecycle, stash backup/restore, path traversal protection, file permissions, deleted file handling, edge cases, and destructive operation safety
  • Fixed a safety bug: Start() silently swallowed git stash push failures. If the stash failed but the main repo had uncommitted changes, Stop() would later run git checkout . + git clean -fd and destroy that work. Now Start() returns an error if stashing fails.
  • Documented a known trade-off: Stop() uses git clean -fd which deletes ALL untracked files in the main repo, including ones the user may have created while spotlight was active (test documents this behavior)

Audit findings

Area Status
Core sync logic Solid — incremental copy, skips unchanged files, handles deletions
Path traversal protection Present and correct
File permissions Preserved during sync
Stash management Fixed — was silently swallowing failures
git clean -fd in Stop() Known trade-off — documented in tests
MCP integration Well-tested (6 existing tests)
TUI integration Keybindings work (f/F)
Unit test coverage Added — was zero, now 21 tests

Test plan

  • All 21 new spotlight unit tests pass
  • All 6 existing MCP spotlight integration tests pass
  • Full start → sync → stop lifecycle verified
  • Stash backup and restore verified
  • Destructive operation behavior documented

🤖 Generated with Claude Code

Add comprehensive unit tests for the spotlight package covering sync,
start/stop lifecycle, stash management, path traversal protection,
file permissions, and destructive operation safety.

Fix a bug where Start() silently swallowed git stash failures — if the
stash failed, Stop() would later run git checkout . and destroy the
user's uncommitted changes. Start() now returns an error if stashing
fails, protecting uncommitted work.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bborn bborn merged commit 6b9d31b into main Mar 22, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant