Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/tests/test_ai_current_models.py
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 18 minutes ago History
test_ai_current_models.py · 4.1 KB · 101 lines
1"""The shell's AI defaults track the current Claude models.
2
3Every place a default model is defined has to move together: the server
4constant, the shell and Talk pages' own fallbacks, and the stored
5preference's schema default. A page that still falls back to an older id
6sends that id on every turn of a user who never ran /model, whatever the
7server constant says -- so these assert each definition, not just one.
8"""
9
10import csv
11import json
12from pathlib import Path
13
14import object_server
15
16REPO = Path(__file__).resolve().parents[1]
17PACKAGES = REPO / "packages"
18CURRENT_DEFAULT = "anthropic:claude-haiku-5-5"
19
20
21def _seed_prices():
22 path = PACKAGES / "app-settings" / "seed" / "ai_prices.tsv"
23 with path.open(newline="", encoding="utf-8") as handle:
24 return list(csv.DictReader(handle, delimiter="\t"))
25
26
27def test_server_default_model_is_claude_haiku_5_5():
28 assert object_server.DEFAULT_AI_MODEL == CURRENT_DEFAULT
29
30
31def test_shell_and_talk_pages_fall_back_to_the_same_default():
32 shell = (PACKAGES / "app-shell" / "objects" / "site" / "shell.py").read_text()
33 talk = (PACKAGES / "app-shell" / "objects" / "site" / "talk.py").read_text()
34 assert f'ai_model: "{CURRENT_DEFAULT}"' in shell
35 assert f'ai_model: "{CURRENT_DEFAULT}"' in talk
36 assert f'const DEFAULT_MODEL = "{CURRENT_DEFAULT}";' in talk
37 schema = json.loads(
38 (PACKAGES / "app-shell" / "schemas" / "shell_preferences.json").read_text()
39 )
40 field = next(f for f in schema["fields"] if f["name"] == "ai_model")
41 assert field["default"] == CURRENT_DEFAULT
42
43
44def test_model_ids_never_carry_date_suffixes_in_defaults_or_prices():
45 """Current Claude ids are bare aliases; a dated id would pin a snapshot
46 the provider may retire, and a price row keyed on one never matches the
47 bare id the shell sends."""
48 import re
49
50 for row in _seed_prices():
51 if row["provider"] == "anthropic":
52 assert not re.search(r"-\d{8}$", row["model"]), row["model"]
53 assert not re.search(r"-\d{8}$", CURRENT_DEFAULT)
54
55
56def test_price_rows_exist_for_the_claude_5_5_family():
57 rows = {row["model"]: row for row in _seed_prices() if row["provider"] == "anthropic"}
58 expected = {
59 "claude-haiku-5-5": ("10", "50"),
60 "claude-sonnet-5-5": ("200", "1000"),
61 "claude-opus-5-5": ("400", "2000"),
62 }
63 for model, (cents_in, cents_out) in expected.items():
64 assert rows[model]["input_per_million_cents"] == cents_in
65 assert rows[model]["output_per_million_cents"] == cents_out
66 # Older rows stay: a stored model choice from before keeps its price.
67 for model in ("claude-haiku-4-5", "claude-sonnet-5", "claude-opus-4-8"):
68 assert model in rows
69
70
71def test_docs_name_the_current_default():
72 for doc in ("shell-and-ai.md", "http-api-contract.md", "single-vm-deployment.md"):
73 text = (REPO / "docs" / doc).read_text()
74 assert CURRENT_DEFAULT in text, doc
75 seed = (PACKAGES / "app-docs" / "seed" / "doc_pages.tsv").read_text()
76 assert "DBBASIC_AI_DEFAULT_MODEL=anthropic:claude-haiku-5-5" in seed
77
78
79def _seed_page(slug):
80 csv.field_size_limit(10**9)
81 path = PACKAGES / "app-docs" / "seed" / "doc_pages.tsv"
82 with path.open(newline="", encoding="utf-8") as handle:
83 return next(r for r in csv.DictReader(handle, delimiter="\t") if r["id"] == slug)["content"]
84
85
86def test_public_docs_site_carries_the_current_shell_and_ai_page():
87 """/docs serves seeded copies of docs/. The shell-and-ai copy differs
88 from the file only by its dropped title and site-style links, so a
89 section added to one and not the other is drift."""
90 import re
91
92 doc = (REPO / "docs" / "shell-and-ai.md").read_text()
93 body = doc.split("\n", 2)[2]
94 body = body.replace("cloud voice paths above (", "cloud voice paths below (")
95 body = re.sub(r"\]\(([a-z0-9-]+)\.md\)", r"](/docs/\1)", body)
96 assert _seed_page("shell-and-ai").strip() == body.strip()
97
98 contract = (REPO / "docs" / "http-api-contract.md").read_text()
99 start, end = "## AI Chat (The Shell's Brain)", "## Text-to-Speech"
100 section = contract[contract.index(start):contract.index(end)]
101 assert section in _seed_page("http-api-contract")