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
19 changes: 0 additions & 19 deletions .github/scripts/test_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,6 @@ def download(url: str, *, api: bool = False, failure: str = failure) -> bytes:
self.assertEqual((root / path).read_text(), original)
self.assertEqual(command.call_count, int(failure == "validation"))

def test_envoy_refresh_on_unchanged_upstream_release(self) -> None:
"""Replace the previous Envoy pin using the upstream-supported image tag."""

# Arrange.
old = f"docker.io/envoyproxy/envoy@sha256:{'a' * 64}"
base = {"image": "docker.io/envoyproxy/envoy:v1.37-latest"}
local = {"image": old}
remote = {"image": "docker.io/envoyproxy/envoy:v1.37-latest"}
payloads = [{"token": "token"}, {"manifests": [{"platform": {"architecture": "amd64"}}, {"platform": {"architecture": "arm64"}}]}]

# Act.
with mock.patch.object(chart, "download", side_effect=[json.dumps(payload).encode() for payload in payloads]):
chart.pin_upstream(base, local, remote)

# Assert.
self.assertEqual(base["image"], old)
self.assertNotEqual(remote["image"], old)
self.assertEqual(chart.merge(base, local, remote)["image"], remote["image"])

def test_peer_minor_line_limits_release_selection(self) -> None:
"""Do not upgrade Serving independently to an incompatible Kourier minor."""

Expand Down
3 changes: 0 additions & 3 deletions api/tests/database/models/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from longlink import CompanyDB, PlatformModel
from sqlmodel import SQLModel
from src.database import models
from src.database.models import base, companies

pytestmark = pytest.mark.no_db

Expand All @@ -12,10 +11,8 @@ def test_platform_metadata_is_isolated_from_solution_metadata() -> None:

# Assert
assert models.metadata is not SQLModel.metadata
assert base.PlatformModel is PlatformModel
assert models.metadata is PlatformModel.metadata
assert CompanyDB.__table__.metadata is PlatformModel.metadata
assert issubclass(CompanyDB, PlatformModel)
assert companies.CompanyDB is CompanyDB
assert models.metadata.tables["companies"] is CompanyDB.__table__
assert "companies" not in SQLModel.metadata.tables
2 changes: 0 additions & 2 deletions api/tests/kubernetes/test_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ def test_solution_template_constrains_workloads() -> None:

assert requests["ephemeral-storage"] == "256Mi"
assert limits["ephemeral-storage"] == "512Mi"
assert requests["cpu"] == "100m"
assert limits["cpu"] == "250m"
assert container["volumeMounts"] == [{"name": "tmp", "mountPath": "/tmp"}] # noqa: S108
assert pod_spec["volumes"] == [{"name": "tmp", "emptyDir": {"sizeLimit": "256Mi"}}]

Expand Down
63 changes: 12 additions & 51 deletions api/tests/operations/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Storage(StorageKubernetes):
async def apply(self, organization: UUID, *, quota_bytes: int) -> None:
"""Record bucket creation."""

assert quota_bytes == allocation.storage_bytes
calls.append("storage")
async with session_scope() as session:
assert await session.get(OrganizationActivity, organization) is not None
Expand All @@ -73,6 +74,15 @@ async def apply(_client: object, organization_id: UUID, *, cpu_millicores: int,
assert ram_bytes == organization.compute_ram_bytes
calls.append("namespace")

async def resize(_client: object, organization_id: UUID, *, storage_bytes: int, cpu_millicores: int, ram_bytes: int) -> None:
"""Record database capacity reconciliation."""

assert organization_id == organization.id
assert storage_bytes == allocation.database_storage_bytes
assert cpu_millicores == allocation.database_cpu_millicores
assert ram_bytes == allocation.database_ram_bytes
calls.append("resize")

async def synchronize(_client: object, organization_id: UUID) -> None:
"""Record pull-secret reconciliation at the external-system boundary."""

Expand All @@ -81,6 +91,7 @@ async def synchronize(_client: object, organization_id: UUID) -> None:

monkeypatch.setattr(organization_operations.database_resources.postgres, "Postgres", Database)
monkeypatch.setattr(organization_operations.database_resources, "wait_ready", wait_ready)
monkeypatch.setattr(organization_operations.database_resources, "resize", resize)
monkeypatch.setattr(organization_operations, "Kubernetes", DatabaseKubernetes)
monkeypatch.setattr(organization_operations, "Storage", Storage)
monkeypatch.setattr(organization_operations.organizations, "apply", apply)
Expand All @@ -93,7 +104,7 @@ async def synchronize(_client: object, organization_id: UUID) -> None:
assert await session.get(OrganizationActivity, organization.id) is None

# Every boundary completes before status publication.
assert calls == ["ready", "database", "namespace", "storage", "ready", "registries"]
assert calls == ["ready", "database", "namespace", "storage", "resize", "ready", "registries"]
assert refreshed is not None
assert refreshed.status == Status.running
assert refreshed.provisioned_at is not None
Expand Down Expand Up @@ -239,56 +250,6 @@ async def synchronize(_client: object, _organization_id: UUID) -> None:
assert current.provisioned_at is None


@pytest.mark.usefixtures("database_runtime")
async def test_reconcile_applies_independent_pools_without_quota_transfers(
users: tuple[User, User, User], monkeypatch: pytest.MonkeyPatch
) -> None:
"""Apply app, file, and database capacity without cross-pool deductions."""

# Arrange
organization = await create_organization(users[0])
allocation = OrganizationUsageUpdate.model_validate(organization, from_attributes=True)
await queue_operation(target_id=organization.id, allocation=allocation.model_dump())
operation = await claim_operation()
assert operation is not None
events: list[tuple[str, int, int]] = []

async def boundary(_client: object, _organization: UUID, *, cpu_millicores: int, ram_bytes: int) -> None:
"""Record the staged and final namespace admission."""

events.append(("apps", cpu_millicores, ram_bytes))

async def resize(_client: object, _organization: UUID, *, storage_bytes: int, cpu_millicores: int, ram_bytes: int) -> None:
"""Record the live DB resize."""

assert storage_bytes == organization.database_storage_bytes
events.append(("database", cpu_millicores, ram_bytes))

class Storage(StorageKubernetes):
async def apply(self, _organization: UUID, *, quota_bytes: int) -> None:
"""Record releasing file capacity before growing the DB disk."""

assert quota_bytes == organization.storage_bytes
events.append(("files", quota_bytes, 0))

async def synchronize(_client: object, _organization: UUID) -> None:
"""Accept external registry synchronization."""

monkeypatch.setattr(organization_operations, "Kubernetes", DatabaseKubernetes)
monkeypatch.setattr(organization_operations, "Storage", Storage)
monkeypatch.setattr(organization_operations.organizations, "apply", boundary)
monkeypatch.setattr(organization_operations.database_resources, "resize", resize)
monkeypatch.setattr(organization_operations.registries, "synchronize", synchronize)

# Act
await organization_operations.reconcile(operation)

# Assert
assert [event[0] for event in events] == ["apps", "files", "database"]
assert events[0][1:] == (organization.compute_cpu_millicores, organization.compute_ram_bytes)
assert events[2][1:] == (organization.database_cpu_millicores, organization.database_ram_bytes)


async def test_reconcile_skips_missing_organization_without_constructing_providers(monkeypatch: pytest.MonkeyPatch) -> None:
"""Treat a missing Organization as an already completed reconciliation target."""

Expand Down
2 changes: 0 additions & 2 deletions api/tests/routes/v1/test_registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ async def username(token: SecretStr) -> str:
assert len(current_operations) == 2
assert previous_operations[0].id in {operation.id for operation in current_operations}
new_operations = [operation for operation in current_operations if operation.id != previous_operations[0].id]
assert len(new_operations) == 1
assert new_operations[0].kind == OperationKind.organization_create
assert new_operations[0].target_id == organization.id
assert new_operations[0].finished_at is None
Expand Down Expand Up @@ -275,7 +274,6 @@ async def test_registry_delete_commits_removal_and_fresh_reconciliation(
assert len(current_operations) == 2
assert previous_operations[0].id in {operation.id for operation in current_operations}
new_operations = [operation for operation in current_operations if operation.id != previous_operations[0].id]
assert len(new_operations) == 1

# Reconciliation targets the owning Organization rather than an individual release.
assert new_operations[0].kind == OperationKind.organization_create
Expand Down
6 changes: 1 addition & 5 deletions api/tests/utils/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ async def test_github_rejects_invalid_credentials_before_transport(token: str) -
"""Reject malformed bearer credentials with the stable format error before HTTP access."""

# Arrange
requests: list[httpx2.Request] = []

async def send(request: httpx2.Request) -> httpx2.Response:
async def send(_request: httpx2.Request) -> httpx2.Response:
"""Reject any attempt to send malformed credentials to the provider."""

requests.append(request)
pytest.fail("Invalid credentials must not reach the transport")

transport = httpx2.MockTransport(send)
Expand All @@ -61,7 +58,6 @@ async def send(request: httpx2.Request) -> httpx2.Response:
# Assert
assert raised.value.status_code == 422
assert raised.value.detail == "GitHub token has an invalid format"
assert requests == []


@pytest.mark.parametrize(("status", "payload", "error_status", "message"), PROVIDER_FAILURES)
Expand Down
3 changes: 0 additions & 3 deletions sdk/tests/cli/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,6 @@ def test_build_keeps_project_metadata_and_embedded_version_independent(
# Arrange
project_file = chdir_project / "pyproject.toml"
original_project = project_file.read_bytes()
project = build.read_pyproject(chdir_project)["project"]
assert isinstance(project, dict)
assert project["version"] == "0.1.0"
capture = docker_commands(None)

# Act
Expand Down
40 changes: 0 additions & 40 deletions sdk/tests/database/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ class AuditLifecycleItem(database_base.Audit, table=True):
async with audit_engine.session() as session:
item = await session.get(AuditLifecycleItem, item_id)
assert item is not None
assert item.created_at is not None
assert item.updated_at is not None
assert item.created_at.tzinfo is UTC
assert item.updated_at.tzinfo is UTC
created_at = item.created_at
Expand Down Expand Up @@ -163,44 +161,6 @@ class ExplicitAuditItem(database_base.Audit, table=True):
assert (item.created_at, item.updated_at, item.created_id, item.updated_id) == (created_at, updated_at, creator_id, updater_id)


async def test_audit_hook_preserves_ordinary_model_inserts_and_updates(audit_engine: database_base.Database) -> None:
"""Leave ordinary SQLModel inserts and updates unchanged."""

# Arrange
class PlainLifecycleItem(SQLModel, table=True):
"""Temporary ordinary table used to verify audit listener scope."""

# Table metadata
__tablename__: ClassVar[str] = "plain_lifecycle_items"

# Item fields
id: int | None = Field(default=None, primary_key=True)
name: str

# Act
async with audit_engine.session() as session:
item = PlainLifecycleItem(name="draft")
session.add(item)
await session.commit()
assert item.id is not None
item_id = item.id

async with audit_engine.session() as session:
# Plain lifecycle models do not opt into actor-attribution updates.
item = await session.get(PlainLifecycleItem, item_id)
assert item is not None

# Exercise a normal update without opting the model into audit behavior.
item.name = "published"
await session.commit()

# Assert
async with audit_engine.session() as session:
item = await session.get(PlainLifecycleItem, item_id)
assert item is not None
assert item.name == "published"


async def test_audit_hook_attributes_custom_soft_deletes(audit_engine: database_base.Database) -> None:
"""Attribute custom soft deletes without replacing an explicit deletion actor."""

Expand Down
37 changes: 1 addition & 36 deletions sdk/tests/database/test_base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import ssl
import pytest
import asyncio
import sqlite3
from typing import Literal
from pathlib import Path
from longlink import Company, CompanyDB, LegalForm, PlatformModel
from pydantic import BaseModel, ValidationError
from sqlmodel import SQLModel, select
from sqlalchemy import text, event, literal
from sqlalchemy.exc import OperationalError
from longlink.database import base as database_base
from sqlalchemy.engine import URL, make_url
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncConnection, create_async_engine
Expand Down Expand Up @@ -534,38 +531,6 @@ async def open_session() -> AsyncEngine | AsyncConnection | None:
await database.dispose()


async def test_session_connects_lazily_and_retries_after_database_connection_failure(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, production_settings: dict[str, str | int]
) -> None:
"""Defer connection failures until the first query and allow a later session to retry."""

# Arrange
database_path = tmp_path / "database" / "runtime.db"
engine = create_async_engine(URL.create("sqlite+aiosqlite", database=str(database_path)))
database = database_base.Database(Envs.model_validate(production_settings))
monkeypatch.setattr(database_base, "create_engine", lambda _env: engine)

try:
# Opening a non-testing session does not require a working database connection.
async with database.session() as database_session:
assert database_session.bind is engine
with pytest.raises(OperationalError, match="unable to open database file") as error:
await database_session.scalar(text("SELECT 1"))

# Preserve the real connection error without discarding the lazy engine.
assert isinstance(error.value.orig, sqlite3.OperationalError)
assert error.value.orig.args == ("unable to open database file",)

# Restore availability and retry through the same Solution-owned engine.
database_path.parent.mkdir()
async with database.session() as database_session:
assert database_session.bind is engine
assert await database_session.scalar(text("SELECT 1")) == 1
finally:
# Release the engine even if a connection or retry assertion fails.
await database.dispose()


async def test_session_disposes_sqlite_engine_after_schema_initialization_failure(monkeypatch: pytest.MonkeyPatch) -> None:
"""Release SQLite resources when automatic schema creation fails."""

Expand Down Expand Up @@ -594,7 +559,7 @@ def record_connection_close(connection: object, _record: object) -> None:

try:
# Act and assert
with pytest.raises(RuntimeError, match="schema unavailable") as error:
with pytest.raises(RuntimeError) as error:
async with database.session():
pass
assert error.value is failure
Expand Down
2 changes: 0 additions & 2 deletions sdk/tests/database/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def test_migration_environment_emits_offline_sql_without_creating_database(monke

# Assert
sql = output.getvalue()
assert "CREATE TABLE IF NOT EXISTS users (" in sql
assert sql.index("CREATE TABLE IF NOT EXISTS users (") < sql.index("CREATE TABLE task (")
assert "CREATE TABLE task (" in sql
assert "INSERT INTO alembic_version" in sql
assert not (tmp_path / "dev.db").exists()

Expand Down
29 changes: 0 additions & 29 deletions sdk/tests/database/test_migrations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from pathlib import Path
from alembic.config import Config
from longlink.database import migrations as database_migrations


Expand All @@ -17,31 +16,3 @@ def test_production_migrations_rejects_missing_revisions_before_upgrade(tmp_path
# Act and assert
with pytest.raises(RuntimeError, match="require migrations"):
database_migrations.apply_migrations()


@pytest.mark.usefixtures("production_environment")
def test_production_migrations_upgrade_head_with_committed_revision(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""Apply committed Solution revisions in production."""

# Arrange
migrations_path = tmp_path / "migrations"
migrations_path.mkdir()
migrations_path.joinpath("001_initial.py").write_text("", encoding="utf-8")
captured: list[tuple[Config, str]] = []
monkeypatch.chdir(tmp_path)

def upgrade(config: Config, target: str) -> None:
"""Capture the Alembic configuration and revision target."""

captured.append((config, target))

monkeypatch.setattr(database_migrations.command, "upgrade", upgrade)

# Act
database_migrations.apply_migrations()

# Assert
[(config, target)] = captured
assert target == "head"
assert config.get_main_option("script_location") == str(database_migrations.CURRENT_FILE.parent)
assert config.get_main_option("version_locations") == str(migrations_path)
1 change: 0 additions & 1 deletion web/tests/components/foundation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ it('exposes each row once and lets keyboard users focus the described pause regi
expect(rowLists.filter((rowList) => rowList.getAttribute('aria-hidden') !== 'true')).toEqual([list]);

for (const duplicate of rowLists.filter((rowList) => rowList !== list)) {
expect(duplicate.getAttribute('aria-hidden')).toBe('true');
expect(duplicate.hasAttribute('aria-label')).toBe(false);
expect(duplicate.hasAttribute('aria-labelledby')).toBe(false);
}
Expand Down
Loading