Files
AstraBox/tests/sqlite_string_pushdown_test.py
Colton Qi f8db994652 AstraBox 0.1.0
The open-source, self-hosted alternative to Claude Managed Agents: run
Claude Code, Codex, Hermes, DeepSeek Harness and Pi as managed Agents on
your own infrastructure, with conversations that start and resume in
seconds.
2026-09-22 13:24:05 -07:00

34 lines
1.1 KiB
Python

"""String pushdown keeps scalar identity reads on their SQL indexes."""
from __future__ import annotations
from sqlalchemy.dialects import postgresql
from astrabox.persistence.repository.sqlite.collection import AsyncCollection
def _postgresql_candidate_sql(key: str) -> str:
collection = object.__new__(AsyncCollection)
collection._is_postgresql = True
expression = collection._string_equality_candidate(key, "value")
return str(
expression.compile(
dialect=postgresql.dialect(),
compile_kwargs={"literal_binds": True},
)
)
def test_scalar_identity_pushdown_has_no_array_scan_arm() -> None:
for key in ("session_id", "platform_session_id", "event_id", "id"):
sql = _postgresql_candidate_sql(key)
assert "jsonb_typeof" not in sql, (
f"{key} must remain a pure indexed equality, got {sql}"
)
def test_plural_reference_pushdown_retains_array_membership_candidates() -> None:
sql = _postgresql_candidate_sql("credential_vault_ids")
assert "jsonb_typeof" in sql, sql
assert "array" in sql, sql