#!/usr/bin/env python3 """ Test and demo script for the task sweeper functionality. """ import tempfile from pathlib import Path import os import sys def create_test_structure(): """Create a test directory structure with scattered tasks.""" # Add the project root to path so we can import project_root = Path(__file__).parent sys.path.insert(0, str(project_root)) with tempfile.TemporaryDirectory() as temp_dir: base_dir = Path(temp_dir) print("๐Ÿ—๏ธ Creating test directory structure...") # Create year directories with markdown files (base_dir / "2024" / "projects").mkdir(parents=True) (base_dir / "2024" / "notes").mkdir(parents=True) (base_dir / "2025" / "planning").mkdir(parents=True) (base_dir / "archive").mkdir(parents=True) (base_dir / "godspeed").mkdir(parents=True) # Create test files with various tasks test_files = { "2024/projects/website.md": """# Website Redesign Project ## Overview This project aims to redesign our company website. ## Tasks - [x] Create wireframes - [ ] Design mockups Need to use new brand colors - [ ] Get client approval - [-] Old approach that was cancelled ## Notes The wireframes are complete and approved. """, "2024/notes/meeting-notes.md": """# Weekly Team Meeting - Dec 15 ## Attendees - Alice, Bob, Charlie ## Action Items - [ ] Alice: Update documentation - [x] Bob: Fix bug #456 - [ ] Charlie: Review PR #789 Needs to be done by Friday ## Discussion We discussed the quarterly goals. """, "2025/planning/goals.md": """# 2025 Goals ## Q1 Objectives - [ ] Launch new feature - [ ] Improve performance by 20% Focus on database queries ## Q2 Ideas - [ ] Consider mobile app Some general notes about the year ahead. """, "archive/old-project.md": """# Old Project (Archived) This project is mostly done but has some lingering tasks. - [x] Phase 1 complete - [-] Phase 2 cancelled - [ ] Cleanup remaining files Need to remove temp directories """, "random-notes.md": """# Random Notes Just some thoughts and incomplete todos: - [ ] Call the dentist - [ ] Buy groceries - Milk - Bread - Eggs No other tasks here, just notes. """, "godspeed/Personal.md": """# This file should be ignored by the sweeper - [ ] Existing Godspeed task """, } # Write test files for rel_path, content in test_files.items(): file_path = base_dir / rel_path with open(file_path, "w") as f: f.write(content) print(f"๐Ÿ“ Created test structure in: {base_dir}") print(f"๐Ÿ“„ Files created:") for rel_path in test_files.keys(): print(f" โ€ข {rel_path}") return base_dir def test_sweeper(): """Test the task sweeper functionality.""" print("=" * 60) print("๐Ÿงช TESTING TASK SWEEPER") print("=" * 60) # Create test directory with tempfile.TemporaryDirectory() as temp_dir: base_dir = Path(temp_dir) # Create the test structure directly here since we can't return from context manager (base_dir / "2024" / "projects").mkdir(parents=True) (base_dir / "2024" / "notes").mkdir(parents=True) (base_dir / "2025" / "planning").mkdir(parents=True) (base_dir / "archive").mkdir(parents=True) (base_dir / "godspeed").mkdir(parents=True) test_files = { "2024/projects/website.md": """# Website Redesign Project - [x] Create wireframes - [ ] Design mockups Need to use new brand colors - [ ] Get client approval - [-] Old approach that was cancelled Project notes here. """, "2024/notes/meeting-notes.md": """# Weekly Team Meeting - [ ] Alice: Update documentation - [x] Bob: Fix bug #456 - [ ] Charlie: Review PR #789 Needs to be done by Friday """, "2025/planning/goals.md": """# 2025 Goals - [ ] Launch new feature - [ ] Improve performance by 20% Focus on database queries """, "random-notes.md": """# Random Notes - [ ] Call the dentist - [ ] Buy groceries Just some notes. """, } for rel_path, content in test_files.items(): file_path = base_dir / rel_path with open(file_path, "w") as f: f.write(content) godspeed_dir = base_dir / "godspeed" print(f"\n๐Ÿ“ Test directory: {base_dir}") print(f"๐Ÿ“ฅ Godspeed directory: {godspeed_dir}") # Import and run the sweeper from sweep_tasks import TaskSweeper print(f"\n๐Ÿงน Running task sweeper (DRY RUN)...") sweeper = TaskSweeper(base_dir, godspeed_dir, dry_run=True) result = sweeper.sweep_tasks() print(f"\n๐Ÿ” DRY RUN RESULTS:") print(f" โ€ข Would sweep: {result['swept_tasks']} tasks") print(f" โ€ข From files: {len(result['processed_files'])}") if result["processed_files"]: print(f" โ€ข Files that would be modified:") for file_path in result["processed_files"]: print(f" - {file_path}") # Now run for real print(f"\n๐Ÿš€ Running task sweeper (REAL)...") sweeper_real = TaskSweeper(base_dir, godspeed_dir, dry_run=False) result_real = sweeper_real.sweep_tasks() # Check the inbox inbox_file = godspeed_dir / "Inbox.md" if inbox_file.exists(): print(f"\n๐Ÿ“ฅ Inbox.md contents:") print("-" * 40) with open(inbox_file, "r") as f: print(f.read()) print("-" * 40) # Check a cleaned file website_file = base_dir / "2024" / "projects" / "website.md" if website_file.exists(): print(f"\n๐Ÿ“„ Cleaned file (website.md) contents:") print("-" * 30) with open(website_file, "r") as f: print(f.read()) print("-" * 30) print(f"\nโœ… TEST COMPLETE!") print(f" โ€ข Swept {result_real['swept_tasks']} incomplete tasks") print(f" โ€ข Into: {result_real['inbox_file']}") if __name__ == "__main__": test_sweeper()