219 lines
6.6 KiB
Python
219 lines
6.6 KiB
Python
#!/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 <!-- id:wire123 -->
|
|
- [ ] Design mockups <!-- id:mock456 -->
|
|
Need to use new brand colors
|
|
- [ ] Get client approval <!-- id:appr789 -->
|
|
- [-] Old approach that was cancelled <!-- id:old999 -->
|
|
|
|
## 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 <!-- id:doc123 -->
|
|
- [x] Bob: Fix bug #456 <!-- id:bug456 -->
|
|
- [ ] Charlie: Review PR #789 <!-- id:pr789 -->
|
|
Needs to be done by Friday
|
|
|
|
## Discussion
|
|
We discussed the quarterly goals.
|
|
""",
|
|
"2025/planning/goals.md": """# 2025 Goals
|
|
|
|
## Q1 Objectives
|
|
- [ ] Launch new feature <!-- id:feat2025 -->
|
|
- [ ] Improve performance by 20% <!-- id:perf2025 -->
|
|
Focus on database queries
|
|
|
|
## Q2 Ideas
|
|
- [ ] Consider mobile app <!-- id:mobile2025 -->
|
|
|
|
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 <!-- id:p1done -->
|
|
- [-] Phase 2 cancelled <!-- id:p2cancel -->
|
|
- [ ] Cleanup remaining files <!-- id:cleanup123 -->
|
|
Need to remove temp directories
|
|
""",
|
|
"random-notes.md": """# Random Notes
|
|
|
|
Just some thoughts and incomplete todos:
|
|
|
|
- [ ] Call the dentist <!-- id:dentist99 -->
|
|
- [ ] Buy groceries <!-- id:grocery99 -->
|
|
- Milk
|
|
- Bread
|
|
- Eggs
|
|
|
|
No other tasks here, just notes.
|
|
""",
|
|
"godspeed/Personal.md": """# This file should be ignored by the sweeper
|
|
- [ ] Existing Godspeed task <!-- id:existing1 -->
|
|
""",
|
|
}
|
|
|
|
# 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 <!-- id:wire123 -->
|
|
- [ ] Design mockups <!-- id:mock456 -->
|
|
Need to use new brand colors
|
|
- [ ] Get client approval <!-- id:appr789 -->
|
|
- [-] Old approach that was cancelled <!-- id:old999 -->
|
|
|
|
Project notes here.
|
|
""",
|
|
"2024/notes/meeting-notes.md": """# Weekly Team Meeting
|
|
|
|
- [ ] Alice: Update documentation <!-- id:doc123 -->
|
|
- [x] Bob: Fix bug #456 <!-- id:bug456 -->
|
|
- [ ] Charlie: Review PR #789 <!-- id:pr789 -->
|
|
Needs to be done by Friday
|
|
""",
|
|
"2025/planning/goals.md": """# 2025 Goals
|
|
|
|
- [ ] Launch new feature <!-- id:feat2025 -->
|
|
- [ ] Improve performance by 20% <!-- id:perf2025 -->
|
|
Focus on database queries
|
|
""",
|
|
"random-notes.md": """# Random Notes
|
|
|
|
- [ ] Call the dentist <!-- id:dentist99 -->
|
|
- [ ] Buy groceries <!-- id:grocery99 -->
|
|
|
|
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()
|