> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# tests/test_ai_usage.py

> The AI usage logs (AGENTS.md rule 7) stay in step with the work.

`tests/test_ai_usage.py` · chapter [Tests and team tooling](https://calendar-effects.mintlify.site/tour/10-tests-and-tooling.md), file 14 · 58 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ai_usage.py)

## What it does

The AI usage logs (AGENTS.md rule 7) stay in step with the work.

The course's AI Usage Report is written from these logs, so: every member has one, every handoff
note has an entry for its date in its author's log (`/handoff` writes both), and every entry says
which tool was used, what the AI did and what the member did. If a test fails, add the entry to
docs/ai-usage/\<name>.md in the format of docs/ai-usage/README.md.

## What is inside

* **`LOGS`** · [line 12](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ai_usage.py#L12)
* **`HANDOFFS`** · [line 13](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ai_usage.py#L13)
* **`DATE`** · [line 14](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ai_usage.py#L14)
* **`members()`** · [line 17](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ai_usage.py#L17): First names in AGENTS.md's team table, in lower case (the log file names).
* **`entries(text)`** · [line 23](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_ai_usage.py#L23): (date, body) for each dated entry of a log.

## What it checks

* the team table is read (line 29)
* every member has a log (line 33)
* every handoff note has an ai usage entry for its date (line 38)
* every entry says the tool what the ai did and what the member did (line 48)

## Connections

**Uses:** [`src/common/settings.py`](https://calendar-effects.mintlify.site/reference/src/common/settings)

## Source

```python title="tests/test_ai_usage.py" lines expandable theme={null}
"""The AI usage logs (AGENTS.md rule 7) stay in step with the work.

The course's AI Usage Report is written from these logs, so: every member has one, every handoff
note has an entry for its date in its author's log (`/handoff` writes both), and every entry says
which tool was used, what the AI did and what the member did. If a test fails, add the entry to
docs/ai-usage/<name>.md in the format of docs/ai-usage/README.md.
"""
import re

from common.settings import DOCS_DIR, REPO_ROOT

LOGS = DOCS_DIR / "ai-usage"
HANDOFFS = DOCS_DIR / "handoffs"
DATE = re.compile(r"^## (\d{4}-\d{2}-\d{2})", re.M)


def members() -> list[str]:
    """First names in AGENTS.md's team table, in lower case (the log file names)."""
    team = (REPO_ROOT / "AGENTS.md").read_text().split("## Team", 1)[1].split("\n## ", 1)[0]
    return [m.lower() for m in re.findall(r"^\| ([A-Z][a-z]+) \|", team, re.M) if m != "Name"]


def entries(text: str) -> list[tuple[str, str]]:
    """(date, body) for each dated entry of a log."""
    parts = DATE.split(text)
    return list(zip(parts[1::2], parts[2::2]))


def test_the_team_table_is_read():
    assert len(members()) >= 4


def test_every_member_has_a_log():
    missing = [m for m in members() if not (LOGS / f"{m}.md").exists()]
    assert not missing, f"no AI usage log for {missing}: copy the format in docs/ai-usage/README.md"


def test_every_handoff_note_has_an_ai_usage_entry_for_its_date():
    problems = []
    for note in sorted(HANDOFFS.glob("20??-??-??-*.md")):
        date, name = note.name[:10], note.name[11:].split("-")[0]
        log = LOGS / f"{name}.md"
        if not log.exists() or date not in {d for d, _ in entries(log.read_text())}:
            problems.append(f"{note.name}: add a '## {date}' entry to docs/ai-usage/{name}.md")
    assert not problems, "\n".join(problems)


def test_every_entry_says_the_tool_what_the_ai_did_and_what_the_member_did():
    problems = []
    for log in sorted(LOGS.glob("*.md")):
        if log.name == "README.md":
            continue
        for date, body in entries(log.read_text()):
            has = {"tool": "**Tool:**" in body,
                   "AI part": "**AI did:**" in body or "**How I used AI:**" in body,
                   "own part": "**I did:**" in body or "**What I did:**" in body}
            problems += [f"{log.name} {date}: no {k}" for k, ok in has.items() if not ok]
    assert not problems, "\n".join(problems)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.