Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tina4 Python — Agent Instructions

v3.13.155. 140 cataloged features, zero dependencies. Python 3.12+.
v3.13.156. 140 cataloged features, zero dependencies. Python 3.12+.

## AI Skills

Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ https://tina4.com/python/36-releases
This file records framework-specific changes. The release notes above remain the
authority for shipped versions.

## 3.13.156 - 2026-11-01

### Added
- Kafka queue: `Queue.push(data, raw=True)` (and `produce(..., raw=True)`) now
produces the value with NO Tina4 envelope (`{payload, priority, attempts}`) and
no injected `id`, so a non-Tina4 service consuming the topic receives the exact
top-level schema it expects (tina4-python#264). It is a Kafka-only option; the
file/rabbitmq/mongodb backends refuse `raw=True` by name (the envelope is
internal bookkeeping that pop/retries/dead-lettering depend on, so there is
nothing to omit). The default `raw=False` path is unchanged. `pop()` already
unwraps both shapes (`result.get("payload", result)`).

### Fixed
- `migrate:create` next steps named `tina4 migrate --rollback` and
`tina4 migrate --status`, flags `migrate` does not accept — a person or model
following the hint hit an error on the first command. They now name the
commands that exist: `tina4 migrate:rollback` and `tina4 migrate:status`
(tina4-python#268). Also closed two consistency gaps the report found: `migrate`
applies both `.sql` and `.py` migrations, but `migrate:status` listed only
`.sql` as pending and startup auto-migration only triggered on a `.sql` file —
so a pending `.py` migration was invisible to status and never auto-applied at
boot. `migrate()`, `get_files()`, `status()` and the startup gate now share one
discovery helper that globs `.sql` + `.py`. (Python-only: the hint and `.py`
migrations are python's.)
- Kafka queue: the confluent consumer hardcoded `auto.offset.reset: earliest`, so
every NEW consumer group replayed the entire retained backlog on first start
with no way to opt into `latest`. It now reads `TINA4_KAFKA_AUTO_OFFSET_RESET`
(then the bare `KAFKA_AUTO_OFFSET_RESET`), defaulting to `earliest` so current
behaviour is unchanged (tina4-python#263). Takes effect on the confluent-kafka
consume path; the zero-dependency raw fallback always reads from the earliest
retained offset.

## 3.13.155 - 2026-10-29

### Fixed
Expand Down
10 changes: 7 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The full discipline lives in `.claude/skills/tina4-maintainer/SKILL.md`; this bl

# Tina4 Python

Version 3.13.155 - Lightweight Python web framework. See https://tina4.com for full documentation.
Version 3.13.156 - Lightweight Python web framework. See https://tina4.com for full documentation.

## Build & Test

Expand Down Expand Up @@ -605,7 +605,11 @@ queue = Queue(topic="tasks", max_retries=3)
# consumer dies before complete()/fail() the next pop() reclaims it
# (at-least-once delivery). Default 300; env TINA4_QUEUE_VISIBILITY_TIMEOUT; <= 0 disables.
queue = Queue(topic="tasks", visibility_timeout=300)
queue.push(data: dict, priority=0, delay_seconds=0) -> int
queue.push(data: dict, priority=0, delay_seconds=0, raw=False) -> int
# raw=True is Kafka-only: produce the value with NO envelope and no injected id,
# for a non-Tina4 consumer (TINA4_KAFKA_AUTO_OFFSET_RESET controls where a new
# consumer group starts: earliest default, or latest). file/rabbitmq/mongodb
# refuse raw=True by name.
queue.pop() -> Job | None
queue.size(status="pending") -> int
# size() status vocabulary: "pending" (waiting for pop -- includes retryable-
Expand Down Expand Up @@ -944,7 +948,7 @@ uv run tina4python test # Discovers @tests in src/**/*.py
- SSE/Streaming via `response.stream()` — Server-Sent Events support for real-time data push. Pass an async generator; framework handles chunked transfer encoding, `text/event-stream` content type, and connection keep-alive
- MCP server (`tina4_python.mcp`): built-in dev tools auto-start when MCP is a capability of the deployment. Developer API: `McpServer`, `@mcp_tool`, `@mcp_resource`. JSON-RPC 2.0 over SSE. **Security is a two-layer gate (v3.13.40):** `is_enabled()` is a pure capability gate (explicit `TINA4_MCP` wins, else `TINA4_DEBUG`; host-independent), and `is_request_allowed(remote_ip, has_valid_token)` authorises each request on the RAW socket peer (`request.remote_ip`, never X-Forwarded-For): loopback always; a remote caller needs `TINA4_MCP_REMOTE=true` AND a token matching `TINA4_MCP_TOKEN` (never `TINA4_API_KEY`, ADR-0078; sent as Authorization Bearer / X-MCP-Token; no configured token means remote is always denied). Every `/__dev` request (reads too), the MCP endpoints and the `/__dev_reload` socket also require a loopback Host (`localhost`, `127.0.0.1`, `[::1]` or `TINA4_HOST`) and refuse `Sec-Fetch-Site: same-site`/`cross-site` (ADR-0078). `/health` omits `version` outside debug. All MCP surfaces (REST shim, JSON-RPC, SSE) 404 a disallowed caller. `database_query` is SELECT/WITH-only and rejects stacked statements; the file tools are sandboxed to the project root. `is_localhost()` is informational only, not the gate. **`TINA4_DEV_ALLOWED_PEERS`** (opt-in, default none) is a comma-separated IP/CIDR allow-list of RAW socket peers (v4/v6, never a forwarded header) admitted to `/__dev` - the documented way to reach the dashboard from a Docker dev box whose requests arrive from the container-network gateway, e.g. `172.16.0.0/12` (#279). `/__dev/toolbar.css` and `/__dev/toolbar.js` are static and always load; a viewer the gate would refuse gets no toolbar injected
- Tests: 6,088 passing, 0 failures, **0 skipped** — measured 2026-09-17 on the lab (Ubuntu 24.04.4 LTS x86_64, Python 3.13.13, live services, `TINA4_REQUIRE_SERVICES=1`, 604s, run as root). **Firebird is NOT excluded.** The lab provisions a live Firebird 5 (`firebirdsql/firebird:5` on :3050, `TINA4_TEST_FIREBIRD_URL`) and those tests run. What IS deliberate is Firebird's absence from the `TINA4_REQUIRE_SERVICES` keyword gate in `tests/conftest.py`: GitHub CI does not provision Firebird, so a Firebird skip has to stay green *there*. Those are two different things and this line used to conflate them into "excluded by design", which read as "the Firebird tests do not run" — they do. **Nothing skips any more.** Reaching 0 skips now also needs the graph engines (Neo4j, Memgraph, ArangoDB, Ultipa, wired via `TINA4_TEST_NEO4J_URL`/`_MEMGRAPH_URL`/`_ARANGO_URL`/`_ULTIPA_URL` + the `graph` extra) and the lab Keycloak OIDC realm (`TINA4_REQUIRE_OIDC=1`), both added after the August baseline; without them `test_graph.py` (Feature 139) and the real OIDC contract test skip. The last skip was `tests/test_session_backend_failure.py` `[needs:no-dac-override]`: the suite runs as root, root holds `CAP_DAC_OVERRIDE`, so a write went straight through a 0400 file and no real `EACCES` was reachable — and as root the second `save()` returned `True`, so that skip was hiding a FAILING assertion, not merely an unrunnable one. The test now stops being root for the length of the failing write (`os.seteuid` to `nobody`; the saved uid stays 0, so a `finally` always restores it) and the kernel raises the genuine errno-13 the test asserts. Two parts of that are load-bearing: the log directory is handed to the same uid, because dropping the uid otherwise denies `Log.error` as well and the EACCES under test goes unrecorded (`_LogWriter.write` swallows `OSError` unless `TINA4_LOG_STRICT`); and the fixture root is its own 0755 `mkdtemp` rather than `tmp_path`, whose 0700 root-owned parents make every denial a directory traversal, which would pass for the wrong reason. Re-measure with `.venv/bin/python -m pytest tests/ -q` and quote the summary line, never the exit code
- Version: 3.13.155
- Version: 3.13.156

## Links

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tina4-python"
version = "3.13.155"
version = "3.13.156"
description = "Tina4 Python v3 — Zero-dependency, lightweight web framework"
authors = [
{name = "Andre van Zuydam", email = "andrevanzuydam@gmail.com"}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_issue145_pool_transaction_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def _pg():
return url, os.environ.get("TINA4_TEST_PG_USERNAME", ""), os.environ.get("TINA4_TEST_PG_PASSWORD", "")


# This test drives real PostgreSQL across two threads; a pool/lock problem can
# leave a DB call blocked inside libpq (a C call). The suite's default
# `--timeout-method=signal` delivers SIGALRM to the main thread only and cannot
# interrupt a blocking C call, so such a block does not time out — it silently
# wedges the whole pytest-split group until the CI step is killed (observed:
# ~7 min of no output, no traceback). A per-test `method="thread"` override turns
# that into a bounded, diagnosable failure (the watchdog thread dumps every
# thread's stack and fails the test) instead of a hang. The marker overrides the
# CLI method for this test only; it never weakens what the test asserts.
@pytest.mark.timeout(120, method="thread")
def test_issue145_open_transaction_does_not_leak_to_a_concurrent_pooled_thread():
url, user, password = _pg()
db = Database(url, user, password, pool=4)
Expand Down
97 changes: 97 additions & 0 deletions tests/test_issue_268_migrate_hints_and_py_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright (c) 2026 Code Infinity
# SPDX-License-Identifier: MPL-2.0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

"""#268: migrate:create's next steps named 'tina4 migrate --rollback'/'--status',
which `migrate` refuses — the real commands are `migrate:rollback`/`migrate:status`.

And the two consistency gaps the reporter found: `migrate` applies both .sql AND
.py migrations, but `migrate:status` listed only .sql as pending and startup
auto-migration only triggered on a .sql file — so a pending .py migration was
invisible to status and never auto-applied at boot. Both now route through one
discovery helper that globs .sql + .py.

Real SQLite throughout (a real dependency — no mocks). This is python-only: the
wrong hint is python's, and .py migrations are a python feature; the other three
frameworks carry neither the hint nor the .py discovery path.
"""
from tina4_python.cli import _next_steps_for
from tina4_python.core.server import _auto_migrate_on_startup
from tina4_python.database import Database
from tina4_python.migration import Migration

PY_MIGRATION = """
from tina4_python.migration import MigrationBase


class CreateWidgets(MigrationBase):
def up(self, db):
db.execute("CREATE TABLE widgets (id INTEGER PRIMARY KEY, name TEXT)")

def down(self, db):
db.execute("DROP TABLE IF EXISTS widgets")
"""


# ── the reported bug: the next-steps hint names commands that exist ──────────

def test_migration_next_steps_name_commands_that_exist():
steps = _next_steps_for("migration", "add_widgets", {}, {})
joined = "\n".join(steps)
# The commands that actually exist:
assert "tina4 migrate:rollback" in joined, joined
assert "tina4 migrate:status" in joined, joined
# NOT the flags `migrate` refuses (what the hint used to print):
assert "migrate --rollback" not in joined, joined
assert "migrate --status" not in joined, joined


# ── .py migrations are visible to status() and get_files() (real SQLite) ─────

def test_status_lists_a_pending_py_migration(tmp_path):
d = tmp_path / "migrations"
d.mkdir()
(d / "20260101000000_create_widgets.py").write_text(PY_MIGRATION, encoding="utf-8")
db = Database(f"sqlite:///{tmp_path / 'app.db'}")
try:
status = Migration(db, str(d)).status()
pending = [m["migration_name"] for m in status["pending"]]
assert "20260101000000_create_widgets" in pending, pending
finally:
db.close()


def test_get_files_includes_py_and_excludes_dunder(tmp_path):
d = tmp_path / "migrations"
d.mkdir()
(d / "20260101000000_create_widgets.py").write_text(PY_MIGRATION, encoding="utf-8")
(d / "__init__.py").write_text("", encoding="utf-8")
db = Database(f"sqlite:///{tmp_path / 'app.db'}")
try:
files = Migration(db, str(d)).get_files()
assert "20260101000000_create_widgets.py" in files, files
assert "__init__.py" not in files, files
finally:
db.close()


# ── startup auto-migration triggers for a .py-only migrations folder ─────────

def test_startup_auto_migrate_runs_for_a_py_only_folder(tmp_path, monkeypatch):
d = tmp_path / "migrations"
d.mkdir()
(d / "20260101000000_create_widgets.py").write_text(PY_MIGRATION, encoding="utf-8")
db_path = tmp_path / "app.db"
monkeypatch.setenv("TINA4_DATABASE_URL", f"sqlite:///{db_path}")
monkeypatch.delenv("TINA4_AUTO_MIGRATE", raising=False)
monkeypatch.chdir(tmp_path)

_auto_migrate_on_startup() # must NOT early-return on a .py-only folder

db = Database(f"sqlite:///{db_path}")
try:
assert db.table_exists("widgets"), "startup auto-migrate skipped the .py-only folder"
finally:
db.close()
10 changes: 7 additions & 3 deletions tests/test_mcp_migration_create_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ def test_migration_create_returns_generate_v1_1_envelope(tmp_path):
assert isinstance(hint["line"], int) and hint["line"] > 0, hint
assert isinstance(hint["label"], str) and hint["label"], hint

# Populated next[] — three curated steps for the migration verb.
# Populated next[] — three curated steps for the migration verb. The
# rollback/status steps name the commands that EXIST — `tina4 migrate:rollback`
# and `tina4 migrate:status` — not the flags `migrate` refuses (#268).
steps = resolution["next"]
assert isinstance(steps, list) and len(steps) == 3, steps
assert any("tina4 migrate" in s and "rollback" not in s and "status" not in s
for s in steps), steps
assert any("--rollback" in s for s in steps), steps
assert any("--status" in s for s in steps), steps
assert any("tina4 migrate:rollback" in s for s in steps), steps
assert any("tina4 migrate:status" in s for s in steps), steps
# The broken flags the hint used to print must not come back.
assert not any("migrate --rollback" in s or "migrate --status" in s for s in steps), steps

# actions_taken reflects the real writes.
actions = envelope["actions_taken"]
Expand Down
Loading
Loading