96 lines
3.3 KiB
Python
96 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for Godspeed cancelled task functionality.
|
|
"""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
|
|
def test_cancelled_task_parsing():
|
|
print("=== Testing Cancelled Task Support ===\n")
|
|
|
|
from src.services.godspeed.sync import GodspeedSync
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
sync_dir = Path(temp_dir)
|
|
sync_engine = GodspeedSync(None, sync_dir)
|
|
|
|
print("1. Testing task status parsing:")
|
|
print("-" * 40)
|
|
|
|
test_lines = [
|
|
"- [ ] Incomplete task <!-- id:abc123 -->",
|
|
"- [x] Completed task <!-- id:def456 -->",
|
|
"- [X] Also completed <!-- id:ghi789 -->",
|
|
"- [-] Cancelled task <!-- id:jkl012 -->",
|
|
]
|
|
|
|
for line in test_lines:
|
|
parsed = sync_engine._parse_task_line(line)
|
|
if parsed:
|
|
local_id, status, title, notes = parsed
|
|
icon = {"incomplete": "⏳", "complete": "✅", "cleared": "❌"}[status]
|
|
print(f" {icon} {status.upper()}: {title} (ID: {local_id})")
|
|
else:
|
|
print(f" ❌ Failed to parse: {line}")
|
|
|
|
print("\n2. Testing task formatting:")
|
|
print("-" * 30)
|
|
|
|
tasks = [
|
|
("task1", "incomplete", "Buy groceries", ""),
|
|
("task2", "complete", "Call dentist", ""),
|
|
("task3", "cleared", "Old project", "No longer needed"),
|
|
]
|
|
|
|
for local_id, status, title, notes in tasks:
|
|
formatted = sync_engine._format_task_line(local_id, status, title, notes)
|
|
print(f" {formatted}")
|
|
|
|
print("\n3. Testing roundtrip with all statuses:")
|
|
print("-" * 42)
|
|
|
|
# Write to file
|
|
test_file = sync_dir / "test_statuses.md"
|
|
sync_engine._write_list_file(test_file, tasks)
|
|
|
|
# Read back
|
|
read_tasks = sync_engine._read_list_file(test_file)
|
|
|
|
print(f" Original: {len(tasks)} tasks")
|
|
print(f" Read back: {len(read_tasks)} tasks")
|
|
|
|
for original, read_back in zip(tasks, read_tasks):
|
|
orig_id, orig_status, orig_title, orig_notes = original
|
|
read_id, read_status, read_title, read_notes = read_back
|
|
|
|
if orig_status == read_status and orig_title == read_title:
|
|
icon = {"incomplete": "⏳", "complete": "✅", "cleared": "❌"}[
|
|
orig_status
|
|
]
|
|
print(f" {icon} {orig_status.upper()}: {orig_title} - ✓ Match")
|
|
else:
|
|
print(f" ❌ Mismatch:")
|
|
print(f" Original: {orig_status}, '{orig_title}'")
|
|
print(f" Read: {read_status}, '{read_title}'")
|
|
|
|
print("\n4. File content generated:")
|
|
print("-" * 25)
|
|
with open(test_file, "r") as f:
|
|
content = f.read()
|
|
print(content)
|
|
|
|
print("5. API update simulation:")
|
|
print("-" * 27)
|
|
print("For cancelled task ([-]), would send:")
|
|
print(" PATCH /tasks/xyz {'is_complete': True, 'is_cleared': True}")
|
|
print("\nFor completed task ([x]), would send:")
|
|
print(" PATCH /tasks/abc {'is_complete': True, 'is_cleared': False}")
|
|
print("\nFor incomplete task ([ ]), would send:")
|
|
print(" PATCH /tasks/def {'is_complete': False, 'is_cleared': False}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_cancelled_task_parsing()
|