You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by gs...@apache.org on 2026/10/13 03:44:57 UTC

(tooling-llmao) 05/09: tests: test_phase1 and test_projects become test_seam

This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-llmao.git

commit 8a5af10ab418d4586379f58c5ac5f369ccd4ba49
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon Oct 12 22:32:05 2026 -0500

    tests: test_phase1 and test_projects become test_seam
    
    Both tested the seam against MockBackend, with the same two helpers copied
    into each. "phase1" said when the file was written, not what it covers.
    
    tests/test_phase1.py is renamed tests/test_seam.py, and the tests from
    tests/test_projects.py are moved into it under their own heading, ahead of
    the tier tests. The duplicate helpers go; no test is added, dropped or
    changed. 286 before and after.
    
    Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
 tests/test_projects.py                 | 193 ---------------------------------
 tests/{test_phase1.py => test_seam.py} | 153 +++++++++++++++++++++++++-
 2 files changed, 148 insertions(+), 198 deletions(-)

diff --git a/tests/test_projects.py b/tests/test_projects.py
deleted file mode 100644
index c46d37b..0000000
--- a/tests/test_projects.py
+++ /dev/null
@@ -1,193 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-"""P0.1: project list + overview seam (mock backend)."""
-
-import asyncio
-
-import pytest
-from easydict import EasyDict as edict  # noqa: N813
-
-from llmao.proxy.client import GRANTOR_FREE_TIER, BackendUnavailableError, resolve_budget_duration
-from llmao.seam import (
-    AuthzError,
-    Identity,
-    Seam,
-)
-from tests.mock_backend import MockBackend
-
-
-def _cfg():
-    return edict(
-        {
-            "litellm": {
-                "base_url": "http://127.0.0.1:4000",
-                "master_key": "sk-test",
-                "request_timeout_s": 30,
-            },
-            "budgets": {
-                "default_team_budget_usd": 100.0,
-                "duration": "30d",
-            },
-            "site_admins": ["root"],
-            "models_path": "models.yaml",
-        }
-    )
-
-
-def _seam():
-    cfg = _cfg()
-    backend = MockBackend(cfg)
-    return Seam(cfg, backend), cfg, backend
-
-
-def test_resolve_budget_duration_prefers_raw_then_cfg():
-    cfg = _cfg()
-    assert resolve_budget_duration("7d", cfg) == "7d"
-    assert resolve_budget_duration(None, cfg) == "30d"
-    assert resolve_budget_duration("  ", cfg) == "30d"
-    bad = edict({"budgets": {}})
-    with pytest.raises(BackendUnavailableError):
-        resolve_budget_duration(None, bad)
-
-
-def test_list_projects_empty_membership():
-    async def run():
-        seam, _, _ = _seam()
-        ident = Identity(uid="jdoe", projects=[], committees=[])
-        assert await seam.list_projects_for(ident) == []
-
-    asyncio.run(run())
-
-
-def test_list_projects_ensures_team_and_budget():
-    async def run():
-        seam, cfg, backend = _seam()
-        ident = Identity(uid="jdoe", projects=["airflow"], committees=[])
-        assert await backend.team_info("airflow") is None
-        rows = await seam.list_projects_for(ident)
-        assert len(rows) == 1
-        r = rows[0]
-        assert r.project == "airflow"
-        assert r.is_steward is False
-        assert r.max_budget == float(cfg.budgets.default_team_budget_usd)
-        assert r.spend == 0.0
-        assert r.remaining == r.max_budget
-        assert r.pct_used == 0.0
-        assert r.budget_duration == "30d"
-        assert r.grantor == GRANTOR_FREE_TIER
-        info = await backend.team_info("airflow")
-        assert info is not None
-        assert info.budget_duration == "30d"
-
-    asyncio.run(run())
-
-
-def test_list_projects_steward_flag():
-    async def run():
-        seam, _, _ = _seam()
-        ident = Identity(
-            uid="chair",
-            projects=["kafka"],
-            committees=["airflow"],
-        )
-        rows = await seam.list_projects_for(ident)
-        by_name = {r.project: r for r in rows}
-        assert by_name["airflow"].is_steward is True
-        assert by_name["kafka"].is_steward is False
-        assert sorted(by_name) == ["airflow", "kafka"]
-
-    asyncio.run(run())
-
-
-def test_overview_authz_outsider():
-    async def run():
-        seam, _, _ = _seam()
-        ident = Identity(uid="jdoe", projects=["airflow"], committees=[])
-        with pytest.raises(AuthzError):
-            await seam.project_overview(ident, "kafka")
-
-    asyncio.run(run())
-
-
-def test_overview_ensures_team():
-    async def run():
-        seam, cfg, backend = _seam()
-        ident = Identity(uid="jdoe", projects=["airflow"], committees=[])
-        ov = await seam.project_overview(ident, "airflow")
-        assert ov.project == "airflow"
-        assert ov.max_budget == float(cfg.budgets.default_team_budget_usd)
-        assert ov.budget_duration == "30d"
-        assert ov.grantor == GRANTOR_FREE_TIER
-        assert ov.people_spend == 0.0
-        assert ov.automation_spend == 0.0
-        assert ov.by_person == []
-        assert ov.automation_key_count == 0
-        assert await backend.team_info("airflow") is not None
-
-    asyncio.run(run())
-
-
-def test_overview_people_automation_and_by_person():
-    async def run():
-        seam, _, backend = _seam()
-        admin = Identity(uid="chair", projects=[], committees=["airflow"])
-        alice = Identity(uid="alice", projects=["airflow"], committees=[])
-        bob = Identity(uid="bob", projects=["airflow"], committees=[])
-
-        k_alice = await seam.create_personal_key(alice, "airflow", "cli")
-        k_bob1 = await seam.create_personal_key(bob, "airflow", "a")
-        k_bob2 = await seam.create_personal_key(bob, "airflow", "b")
-        k_auto = await seam.create_automation_key(admin, "airflow", "ci")
-
-        backend.set_key_spend(k_alice.info.token_id, 10.0)
-        backend.set_key_spend(k_bob1.info.token_id, 3.0)
-        backend.set_key_spend(k_bob2.info.token_id, 4.0)
-        backend.set_key_spend(k_auto.info.token_id, 2.5)
-        backend.set_team_spend("airflow", 50.0)
-
-        # Member (non-steward) sees transparency.
-        ov = await seam.project_overview(alice, "airflow")
-        assert ov.is_steward is False
-        assert ov.spend == 50.0
-        assert ov.people_spend == 17.0
-        assert ov.automation_spend == 2.5
-        assert [p.uid for p in ov.by_person] == ["alice", "bob"]
-        assert ov.by_person[0].spend == 10.0
-        assert ov.by_person[0].key_count == 1
-        assert ov.by_person[1].spend == 7.0
-        assert ov.by_person[1].key_count == 2
-        assert ov.automation_key_count == 1
-        assert ov.automation_keys[0].created_by == "chair"
-        assert ov.automation_keys[0].spend == 2.5
-        assert ov.grantor == GRANTOR_FREE_TIER
-
-    asyncio.run(run())
-
-
-def test_site_admin_overview_without_membership():
-    async def run():
-        seam, _, _ = _seam()
-        root = Identity(uid="root", projects=[], committees=[], is_site_admin=True)
-        # Not on list (all_projects empty)
-        assert await seam.list_projects_for(root) == []
-        ov = await seam.project_overview(root, "airflow")
-        assert ov.project == "airflow"
-        assert ov.is_steward is True  # site admin
-        assert ov.grantor == GRANTOR_FREE_TIER
-
-    asyncio.run(run())
diff --git a/tests/test_phase1.py b/tests/test_seam.py
similarity index 58%
rename from tests/test_phase1.py
rename to tests/test_seam.py
index 70b88d5..b6feb37 100644
--- a/tests/test_phase1.py
+++ b/tests/test_seam.py
@@ -15,12 +15,11 @@
 # specific language governing permissions and limitations
 # under the License.
 
-"""Offline tests: mock backend + seam authz.
+"""The seam, against the in-memory stand-in for LiteLLM (tests/mock_backend.py).
 
-Authenticated HTTP endpoints require a real asfquart session (OAuth). Those
-paths are not automated while the stack is in flux; expand later if needed.
-Model inventory tests live in test_models.py.
-Run with: pytest -q
+Who may do what, and how the seam puts together what the managers give it:
+keys, the project list and a project's overview. Nothing here reaches
+LiteLLM or needs a signed-in session.
 """
 
 import asyncio
@@ -29,6 +28,7 @@ import time
 import pytest
 from easydict import EasyDict as edict  # noqa: N813
 
+from llmao.proxy.client import GRANTOR_FREE_TIER, BackendUnavailableError, resolve_budget_duration
 from llmao.seam import AuthzError, Identity, Seam
 from tests.mock_backend import MockBackend
 
@@ -179,6 +179,149 @@ def test_site_admin_sees_any_project():
     asyncio.run(run())
 
 
+# ---------------------------------------------------------------------------
+# The project list, and one project's overview
+# ---------------------------------------------------------------------------
+
+
+def test_resolve_budget_duration_prefers_raw_then_cfg():
+    cfg = _cfg()
+    assert resolve_budget_duration("7d", cfg) == "7d"
+    assert resolve_budget_duration(None, cfg) == "30d"
+    assert resolve_budget_duration("  ", cfg) == "30d"
+    bad = edict({"budgets": {}})
+    with pytest.raises(BackendUnavailableError):
+        resolve_budget_duration(None, bad)
+
+
+def test_list_projects_empty_membership():
+    async def run():
+        seam, _, _ = _seam()
+        ident = Identity(uid="jdoe", projects=[], committees=[])
+        assert await seam.list_projects_for(ident) == []
+
+    asyncio.run(run())
+
+
+def test_list_projects_ensures_team_and_budget():
+    async def run():
+        seam, cfg, backend = _seam()
+        ident = Identity(uid="jdoe", projects=["airflow"], committees=[])
+        assert await backend.team_info("airflow") is None
+        rows = await seam.list_projects_for(ident)
+        assert len(rows) == 1
+        r = rows[0]
+        assert r.project == "airflow"
+        assert r.is_steward is False
+        assert r.max_budget == float(cfg.budgets.default_team_budget_usd)
+        assert r.spend == 0.0
+        assert r.remaining == r.max_budget
+        assert r.pct_used == 0.0
+        assert r.budget_duration == "30d"
+        assert r.grantor == GRANTOR_FREE_TIER
+        info = await backend.team_info("airflow")
+        assert info is not None
+        assert info.budget_duration == "30d"
+
+    asyncio.run(run())
+
+
+def test_list_projects_steward_flag():
+    async def run():
+        seam, _, _ = _seam()
+        ident = Identity(
+            uid="chair",
+            projects=["kafka"],
+            committees=["airflow"],
+        )
+        rows = await seam.list_projects_for(ident)
+        by_name = {r.project: r for r in rows}
+        assert by_name["airflow"].is_steward is True
+        assert by_name["kafka"].is_steward is False
+        assert sorted(by_name) == ["airflow", "kafka"]
+
+    asyncio.run(run())
+
+
+def test_overview_authz_outsider():
+    async def run():
+        seam, _, _ = _seam()
+        ident = Identity(uid="jdoe", projects=["airflow"], committees=[])
+        with pytest.raises(AuthzError):
+            await seam.project_overview(ident, "kafka")
+
+    asyncio.run(run())
+
+
+def test_overview_ensures_team():
+    async def run():
+        seam, cfg, backend = _seam()
+        ident = Identity(uid="jdoe", projects=["airflow"], committees=[])
+        ov = await seam.project_overview(ident, "airflow")
+        assert ov.project == "airflow"
+        assert ov.max_budget == float(cfg.budgets.default_team_budget_usd)
+        assert ov.budget_duration == "30d"
+        assert ov.grantor == GRANTOR_FREE_TIER
+        assert ov.people_spend == 0.0
+        assert ov.automation_spend == 0.0
+        assert ov.by_person == []
+        assert ov.automation_key_count == 0
+        assert await backend.team_info("airflow") is not None
+
+    asyncio.run(run())
+
+
+def test_overview_people_automation_and_by_person():
+    async def run():
+        seam, _, backend = _seam()
+        admin = Identity(uid="chair", projects=[], committees=["airflow"])
+        alice = Identity(uid="alice", projects=["airflow"], committees=[])
+        bob = Identity(uid="bob", projects=["airflow"], committees=[])
+
+        k_alice = await seam.create_personal_key(alice, "airflow", "cli")
+        k_bob1 = await seam.create_personal_key(bob, "airflow", "a")
+        k_bob2 = await seam.create_personal_key(bob, "airflow", "b")
+        k_auto = await seam.create_automation_key(admin, "airflow", "ci")
+
+        backend.set_key_spend(k_alice.info.token_id, 10.0)
+        backend.set_key_spend(k_bob1.info.token_id, 3.0)
+        backend.set_key_spend(k_bob2.info.token_id, 4.0)
+        backend.set_key_spend(k_auto.info.token_id, 2.5)
+        backend.set_team_spend("airflow", 50.0)
+
+        # Member (non-steward) sees transparency.
+        ov = await seam.project_overview(alice, "airflow")
+        assert ov.is_steward is False
+        assert ov.spend == 50.0
+        assert ov.people_spend == 17.0
+        assert ov.automation_spend == 2.5
+        assert [p.uid for p in ov.by_person] == ["alice", "bob"]
+        assert ov.by_person[0].spend == 10.0
+        assert ov.by_person[0].key_count == 1
+        assert ov.by_person[1].spend == 7.0
+        assert ov.by_person[1].key_count == 2
+        assert ov.automation_key_count == 1
+        assert ov.automation_keys[0].created_by == "chair"
+        assert ov.automation_keys[0].spend == 2.5
+        assert ov.grantor == GRANTOR_FREE_TIER
+
+    asyncio.run(run())
+
+
+def test_site_admin_overview_without_membership():
+    async def run():
+        seam, _, _ = _seam()
+        root = Identity(uid="root", projects=[], committees=[], is_site_admin=True)
+        # Not on list (all_projects empty)
+        assert await seam.list_projects_for(root) == []
+        ov = await seam.project_overview(root, "airflow")
+        assert ov.project == "airflow"
+        assert ov.is_steward is True  # site admin
+        assert ov.grantor == GRANTOR_FREE_TIER
+
+    asyncio.run(run())
+
+
 # ---------------------------------------------------------------------------
 # Which tier a key is minted on
 #


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org