CodeBench: --compact tiivistää golden examplen templaatiksi

Python: 1340 → 335 tokenia (−75%)
Rust: 3383 → 445 tokenia (−87%)
Käyttö: node benchmark.mjs --compact --models qwen3:4b
This commit is contained in:
2026-04-14 10:59:39 +03:00
parent e7b33b7d6f
commit 01b4fb8e22
3 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
REFERENCE PATTERNS (follow exactly):
STACK: SQLAlchemy 2.0 + Pydantic v2 + FastAPI + SQLite
models.py:
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase): pass
Fields: Mapped[type] = mapped_column(SqlType, default=...)
Nullable: Mapped[str | None] = mapped_column(Text, default=None)
Status: Mapped[str] = mapped_column(String(20), default="pending")
FK: Mapped[int] = mapped_column(ForeignKey("table.id"))
End: Base.metadata.create_all(bind=engine)
schemas.py:
class EntityCreate(BaseModel): fields with defaults
class EntityResponse(EntityCreate):
id: int
model_config = ConfigDict(from_attributes=True)
main.py:
def get_db(): yield SessionLocal(); finally close
POST /{table}/ → 201, model_dump()
GET /{table}/ → list
GET /{table}/{id} → 404 if not found
PUT /{table}/{id} → model_dump(), setattr loop
DELETE /{table}/{id} → 204
test_main.py:
test.db + override_get_db + TestClient
Unique Finnish data per test ("Osta maitoa", "Haettava tehtävä"...)
test_create → 201 + assert "id" in json
test_list → post first, get, assert len >= 1
test_get_by_id → post, get by id, assert id matches
test_not_found → get /99999 → 404
test_update → post, put with ALL required fields, assert 200
test_delete → post, delete 204, get again → 404