test: retire obsolete agent chat source contract

This commit is contained in:
Jesse_Chen
2026-07-20 00:19:11 +08:00
parent a9ffbd9e0a
commit 69d9654ee9
2 changed files with 41 additions and 78 deletions
@@ -291,3 +291,44 @@ matrix provided the behavior-preservation check rather than adding a new RED cas
The build continues to use repository-standard CI placeholder Supabase values and webpack because
the worktree's external dependency symlink is incompatible with default Turbopack. No new concern
was introduced by this cleanup.
## Final cleanup: remove the obsolete Python source contract
`tests/test_agent_chat_contract.py` was deleted in full. Its two tests asserted filenames,
implementation tokens, prompt prose, and source layout rather than observable outcomes. No
production logic changed and no replacement source-mirroring test was added.
### Behavioral coverage inventory
- Onboarding route ownership, generated/cache/pending responses, and compare-and-set races:
`frontend/tests/onboarding-route.test.ts` and `frontend/tests/onboarding-cache-policy.test.ts`.
- Onboarding client recovery, authentication handling, response parsing, suggestion preservation,
cancellation, and stale presentation rejection: `frontend/tests/onboarding-client.test.ts` and
`frontend/tests/onboarding-presentation.test.ts`.
- Suggestion metadata removal and visible suggestion lifetime while streaming/editing:
`frontend/tests/agent-reply.test.ts`, `frontend/tests/chat-stream-layout.test.ts`, and
`frontend/tests/starter-questions.test.ts`.
- Public model parsing/sanitization and selected-model reservation before billing:
`frontend/tests/model-catalog.test.ts`, `frontend/tests/public-models.test.ts`, and
`frontend/tests/consultation-model-selection.test.ts`.
- Owned-session model persistence and per-session write serialization:
`frontend/tests/session-model-persistence.test.ts`.
- Credit RPC outcomes plus completion/cancellation settlement of streamed consultations:
`frontend/tests/consultation-billing.test.ts` and `frontend/tests/stream-text-response.test.ts`.
### Final cleanup verification
- Focused behavioral TypeScript inventory: exit 0; 52 passed, 0 failed.
- Full frontend suite: exit 0; 454 passed, 0 failed.
- Remaining Python suite discovery: exit 0.
- Adjacent Python auth and Supabase data contracts: exit 0; 9 passed.
- ESLint across the 12 focused TypeScript test files: exit 0 with zero diagnostics.
- Webpack production build: exit 0; compiled successfully, TypeScript completed, and 22/22 pages
generated.
- `git diff --check`: exit 0.
The Ruff command over three untouched adjacent Python contract files found existing `I001`
import-order issues in all three. The same exploratory batch also found the existing
`test_session_management_entrypoints.py` expectation for the already-removed `onContextMenu`.
Neither is caused by deleting the agent-chat contract, and neither unrelated file was edited.
Because the only Python change is a deletion, there is no remaining modified Python file to lint.
-78
View File
@@ -1,78 +0,0 @@
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
PAGE = ROOT / "frontend" / "src" / "app" / "page.tsx"
AGENT = ROOT / "frontend" / "src" / "mastra" / "index.ts"
ONBOARDING_ROUTE = ROOT / "frontend" / "src" / "app" / "api" / "onboarding" / "route.ts"
ONBOARDING_CLIENT = ROOT / "frontend" / "src" / "lib" / "onboarding-client.ts"
CONSULT_ROUTE = ROOT / "frontend" / "src" / "app" / "api" / "consult" / "route.ts"
MODELS_ROUTE = ROOT / "frontend" / "src" / "app" / "api" / "models" / "route.ts"
MODEL_SELECTION = ROOT / "frontend" / "src" / "lib" / "consultation-model-selection.ts"
SESSION_MODEL_PERSISTENCE = (
ROOT / "frontend" / "src" / "lib" / "session-model-persistence.ts"
)
ONBOARDING_MIGRATION = (
ROOT
/ "frontend"
/ "supabase"
/ "migrations"
/ "20260715040000_agent_onboarding_cache.sql"
)
def test_onboarding_and_agent_suggestion_contract() -> None:
page = PAGE.read_text(encoding="utf-8")
agent = AGENT.read_text(encoding="utf-8")
route = ONBOARDING_ROUTE.read_text(encoding="utf-8")
onboarding_client = ONBOARDING_CLIENT.read_text(encoding="utf-8")
consult_route = CONSULT_ROUTE.read_text(encoding="utf-8")
migration = ONBOARDING_MIGRATION.read_text(encoding="utf-8")
assert "onboarding-card" in page
assert 'type OnboardingStep = "name" | "birth" | "place"' in page
assert "text.slice(0, length)" in page
assert "window.setInterval" in page
assert "prefers-reduced-motion: reduce" in page
assert "用于计算星盘,并安全保存到你的账号" not in page
assert "saveOnboardingName" in page
assert "saveOnboardingBirth" in page
assert "saveOnboardingPlace" in page
assert "<BirthTimeIntakeFields value={value}" in page
assert "<BirthLocationFields value={profileDraft}" in page
assert "Enter 确认称呼" in page
assert 'fetch("/api/onboarding"' in onboarding_client
assert "onboarding?.suggestions" in page
assert "parseAgentReply(answer, theme)" in page
assert "suggestions: reply.suggestions" in page
assert "activeSuggestions.map" in page
assert "export function getOnboardingAgent" in agent
assert "skills: [jyotishSkillPath]" in agent
assert "<!--AYANAM_SUGGESTIONS:" in agent
assert "supabase.auth.getUser()" in route
assert "function currentTimeContext(now = new Date())" in consult_route
assert "currentTimeContext(requestTime)," in consult_route
assert "中国标准时间(UTC+8" in consult_route
assert "onboarding_payload" in migration
assert "to service_role" in migration
assert "to authenticated" not in migration
def test_multi_model_route_and_persistence_contract() -> None:
consult_route = CONSULT_ROUTE.read_text(encoding="utf-8")
models_route = MODELS_ROUTE.read_text(encoding="utf-8")
selection = MODEL_SELECTION.read_text(encoding="utf-8")
persistence = SESSION_MODEL_PERSISTENCE.read_text(encoding="utf-8")
assert "supabase.auth.getUser()" in models_route
assert "publicLanguageModelCatalog()" in models_route
assert "reserveConsultationModel(" in consult_route
assert "resolveLanguageModel," in consult_route
assert 'runCreditRpc(accounting, "begin_consultation_credit"' in consult_route
assert "getJyotishAgent(selectedModel, workflowContext).stream" in consult_route
assert "modelSelection.usageModelId" in consult_route
assert 'if (!model) return { status: "unavailable" }' in selection
assert 'reservation: await reserveCredit()' in selection
assert 'values: { model_id: modelId }' in persistence
assert "SessionModelPersistenceQueue" in persistence