Skip to content

fix(tests): a test run records its fake model calls in the workstation's spend ledger #2192

Description

@dan-petty

What happened

The workstation's spend ledger (.data/ai/spend.db, the default SpendLedger path) holds rows that only a test makes: on 2026-10-19 at 18:39 to 18:44 UTC five pydantic_ai_direct / direct_sync rows with model test (54 tokens) and fake-model (30 tokens each), and on 2026-10-21 at 23:27 UTC one gateway / chat_dispatch row with model demo-model on server example.com:4000. Found on 2026-10-24 while reading the local AI savings of 2026-10-01 to 2026-10-21. A test run (or a test helper run outside pytest) wrote its fake model calls into the real ledger, so the hermetic floor does not keep the spend ledger in the test's own directory.

What should happen

Every test that makes a model call records it in a ledger under its own tmp_path (or records nothing), and a test fails when a test run opens the workstation's real ledger path. The six rows are removed from the ledger by a documented command, or the report ignores rows whose model is a test fake.

Evidence

sqlite3 'file:.data/ai/spend.db?mode=ro' "select timestamp, provider, server, model, request_type, total_tokens from ai_spend_records where model in ('fake-model','test','demo-model')"

Acceptance criteria

  • A test (in the hermetic floor's invariants) fails when a test run writes to the default SpendLedger path.
  • The tests that make the test, fake-model and demo-model calls write to a ledger under tmp_path.

Proposed design

Problem statement

Tests that make fake model calls write rows into the workstation's real spend ledger at .data/ai/spend.db. Six rows with models test, fake-model and demo-model were found in the real ledger. The hermetic floor does not keep the spend ledger inside the test's own directory, so test data pollutes the production record.

Acceptance criteria

  • Criterion 1: A test in the hermetic floor invariants fails when a test run writes to the default SpendLedger path.
    Verification: Run the hermetic floor invariant tests. Confirm that a test asserts failure when any write targets .data/ai/spend.db.
  • Criterion 2: The tests that make the test, fake-model and demo-model calls write to a ledger under tmp_path.
    Verification: Run the affected test files. Confirm no new rows appear in .data/ai/spend.db and that the ledger file exists under the pytest tmp_path directory.

Key questions

  • Where is the hermetic floor's invariant test suite?: The invariant tests live in tests/test_architectural_invariants.py. [sources: tests/test_architectural_invariants.py]
  • Which test files are known to use SpendLedger and may write to the real path?: The five files are tests/test_ai_served_by.py, tests/test_ai_spend_dispatch.py, tests/test_ai_spend_ledger.py, tests/test_review_profile.py and tests/test_telemetry_instruments.py. [sources: CHANGELOG.md:507]
  • Should the fix redirect tests to tmp_path or should the report filter out test-fake model rows?: Redirect the tests to tmp_path and add the invariant test. Both acceptance criteria are required. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/test
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at bb46660 (see proposed design in issue body).

  4. added
    priority/p2-medium
    status/ready
    value/medium
    effort/low
    type/bug
    status/in-progress
    status/in-review
    and removed
    type/test
    status/ready
    status/in-progress
    on Oct 28, 2026
  5. removed
    status/in-review
    on Nov 1, 2026
  6. added a commit that references this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumsource/agenttype/bugvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions