feat(agent99): establish enterprise AI automation work ledger

This commit is contained in:
ogt
2026-07-10 15:20:23 +08:00
parent a8080e13b9
commit 579d12c3fa
10 changed files with 1283 additions and 2 deletions

View File

@@ -0,0 +1,109 @@
from __future__ import annotations
# ruff: noqa: E402
import json
import os
from pathlib import Path
os.environ.setdefault("DATABASE_URL", "postgresql+asyncpg://test:test@localhost/test")
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from src.api.v1.agents import router
from src.services.agent99_enterprise_ai_automation_work_items import (
build_agent99_enterprise_priority_projection,
load_latest_agent99_enterprise_ai_automation_work_items,
)
from src.services.awoooi_priority_work_order_readback import (
load_latest_awoooi_priority_work_order_readback,
)
_REPO_ROOT = Path(__file__).resolve().parents[3]
_OPERATIONS_DIR = _REPO_ROOT / "docs" / "operations"
def test_agent99_enterprise_work_items_loader_returns_complete_scope() -> None:
payload = load_latest_agent99_enterprise_ai_automation_work_items()
assert payload["schema_version"] == (
"agent99_enterprise_ai_automation_work_items_v1"
)
assert payload["scope_complete"] is False
assert payload["current_p0"]["id"] == "AG99-P0-001"
assert payload["summary"] == {
"host_count": 7,
"product_count": 12,
"public_surface_count": 23,
"work_item_count": 25,
"p0_count": 14,
"p1_count": 8,
"p2_count": 3,
"in_progress_count": 5,
"in_progress_blocked_count": 3,
"planned_count": 17,
"complete_count": 0,
"current_p0_count": 1,
}
assert payload["next_execution_order"][0] == "AG99-P0-001"
assert payload["next_execution_order"][-1] == "AG99-P0-014"
def test_agent99_enterprise_projection_is_bounded() -> None:
payload = load_latest_agent99_enterprise_ai_automation_work_items()
projection = build_agent99_enterprise_priority_projection(payload)
assert projection["current_p0"]["id"] == "AG99-P0-001"
assert projection["coverage"] == {
"host_count": 7,
"product_count": 12,
"public_surface_count": 23,
"service_domain_count": 12,
"package_domain_count": 7,
}
assert projection["work_item_counts"]["total"] == 25
assert "work_items" not in projection
assert projection["full_readback_api"] == (
"/api/v1/agents/agent99-enterprise-ai-automation-work-items"
)
def test_priority_readback_projects_agent99_enterprise_order() -> None:
payload = load_latest_awoooi_priority_work_order_readback()
projection = payload["agent99_enterprise_ai_automation"]
assert projection["current_p0"]["id"] == "AG99-P0-001"
assert projection["work_item_counts"]["p0"] == 14
assert (
payload["source_refs"]["agent99_enterprise_ai_automation_work_items_api"]
== "/api/v1/agents/agent99-enterprise-ai-automation-work-items"
)
def test_agent99_enterprise_loader_rejects_duplicate_ids(tmp_path: Path) -> None:
source = _OPERATIONS_DIR / (
"agent99-enterprise-ai-automation-work-items.snapshot.json"
)
payload = json.loads(source.read_text(encoding="utf-8"))
payload["work_items"][1]["id"] = payload["work_items"][0]["id"]
target = tmp_path / source.name
target.write_text(json.dumps(payload), encoding="utf-8")
with pytest.raises(ValueError, match="duplicate work item id"):
load_latest_agent99_enterprise_ai_automation_work_items(tmp_path)
def test_agent99_enterprise_work_items_endpoint_returns_snapshot() -> None:
app = FastAPI()
app.include_router(router, prefix="/api/v1/agents")
client = TestClient(app)
response = client.get("/api/v1/agents/agent99-enterprise-ai-automation-work-items")
assert response.status_code == 200
payload = response.json()
assert payload["current_p0"]["id"] == "AG99-P0-001"
assert payload["summary"]["host_count"] == 7
assert payload["summary"]["product_count"] == 12
assert payload["summary"]["public_surface_count"] == 23