mirror of
https://github.com/computerim/impactflow-discovery.git
synced 2026-08-27 06:20:36 +00:00
c4fc1cccd7
Build the boundary the ImpactFlow core time-tracker plugs into. A task maps to a foundation — one of the six stable profile elements (love, strength, mission, vocation, short_term, long_term) — so the tracker can ask "which goal does this build toward?" and post the answer back to Vision. - Models + migration 006: task_mapping (one row per logged time entry). - app/services/foundations.py: the six foundations + a pure, testable work-pattern aggregator (rollup) and a plain-language summary. - app/routers/integration.py (user-scoped; tracker calls as the user or via X-API-Key): GET /foundations, POST/GET /task-mappings, GET /work-patterns?days=N (per-foundation minutes/share/neglected). - Reminder engine now pulls from real work patterns: CheckinCoach takes an optional work-pattern summary (last 14 days) and reflects where time has gone against the person's own words — an observation, never a verdict. - Frontend: dashboard.html (time per foundation + neglected); linked from profile.html. Documented the core-tracker integration contract in the README. Phase 4 completes the Vision module's roadmap on the Discovery side; the core tracker integrates by calling these endpoints. Tests: 86 passing (added pure-aggregator, integration-endpoint, and work-pattern-into-check-in tests; run in-container). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Unit tests for the pure work-pattern aggregator."""
|
|
from datetime import datetime, timezone
|
|
|
|
from app.services.foundations import FOUNDATIONS, rollup, work_pattern_text
|
|
|
|
|
|
def _dt(day):
|
|
return datetime(2026, 6, day, tzinfo=timezone.utc)
|
|
|
|
|
|
def test_rollup_sums_minutes_and_counts_per_foundation():
|
|
entries = [
|
|
{"foundation": "short_term", "minutes": 120, "occurred_at": _dt(10)},
|
|
{"foundation": "short_term", "minutes": 60, "occurred_at": _dt(12)},
|
|
{"foundation": "vocation", "minutes": 60, "occurred_at": _dt(11)},
|
|
]
|
|
out = rollup(entries)
|
|
assert out["total_minutes"] == 240
|
|
top = out["by_foundation"][0]
|
|
assert top["foundation"] == "short_term"
|
|
assert top["minutes"] == 180
|
|
assert top["task_count"] == 2
|
|
assert top["last_at"] == _dt(12)
|
|
assert round(top["share"], 2) == 0.75
|
|
|
|
|
|
def test_rollup_covers_all_foundations_and_lists_neglected():
|
|
out = rollup([{"foundation": "love", "minutes": 30, "occurred_at": _dt(9)}])
|
|
assert len(out["by_foundation"]) == len(FOUNDATIONS)
|
|
# Every foundation except 'love' has zero minutes.
|
|
assert set(out["neglected"]) == set(FOUNDATIONS) - {"love"}
|
|
|
|
|
|
def test_rollup_empty_is_zero_and_all_neglected():
|
|
out = rollup([])
|
|
assert out["total_minutes"] == 0
|
|
assert all(f["minutes"] == 0 for f in out["by_foundation"])
|
|
assert set(out["neglected"]) == set(FOUNDATIONS)
|
|
|
|
|
|
def test_rollup_ignores_unknown_foundation():
|
|
out = rollup([{"foundation": "nonsense", "minutes": 99, "occurred_at": _dt(9)}])
|
|
assert out["total_minutes"] == 0
|
|
|
|
|
|
def test_work_pattern_text_summarizes_activity():
|
|
out = rollup([
|
|
{"foundation": "short_term", "minutes": 100, "occurred_at": _dt(10)},
|
|
])
|
|
text = work_pattern_text(out, 14)
|
|
assert "last 14 days" in text
|
|
assert "Near-term goals" in text
|
|
assert "Nothing was logged toward" in text
|
|
|
|
|
|
def test_work_pattern_text_none_when_no_activity():
|
|
assert work_pattern_text(rollup([]), 14) is None
|