Files
DECNET/tests/api/fleet/test_lifecycle_endpoint.py
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
Replaces LICENSE (GPLv3 -> AGPLv3) and prepends
`SPDX-License-Identifier: AGPL-3.0-or-later` to every source file
across decnet/, decnet_web/, tests/, scripts/, and tools/.

Rationale: closes the GPLv3 ASP loophole so any party operating a
modified DECNET as a network service must offer their modified
source. Personal copyright (Samuel Paschuan) + inbound=outbound
contributions make a future unilateral relicense infeasible.

- LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt)
- COPYRIGHT: project copyright notice
- tools/add_spdx_headers.py: idempotent header injector
  (shebang- and PEP 263-aware)

Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh).
No behavior change; comments only.
2026-05-22 21:04:16 -04:00

87 lines
3.0 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""GET /deckies/lifecycle?ids=… — poll endpoint for the wizard."""
from __future__ import annotations
import httpx
import pytest
from decnet.web.dependencies import repo
@pytest.mark.anyio
async def test_get_lifecycle_unauthenticated_returns_401(client: httpx.AsyncClient):
resp = await client.get("/api/v1/deckies/lifecycle", params={"ids": "x"})
assert resp.status_code == 401
@pytest.mark.anyio
async def test_get_lifecycle_missing_ids_returns_validation_error(
client: httpx.AsyncClient, auth_token: str,
):
"""No ?ids= → validation rejection (Starlette short-circuits with 400
for the body-parse path; either 400 or 422 is acceptable contract)."""
resp = await client.get(
"/api/v1/deckies/lifecycle",
headers={"Authorization": f"Bearer {auth_token}"},
)
assert resp.status_code in (400, 422)
@pytest.mark.anyio
async def test_get_lifecycle_returns_matching_rows(
client: httpx.AsyncClient, auth_token: str,
):
a = await repo.create_lifecycle({"decky_name": "d1", "operation": "deploy"})
b = await repo.create_lifecycle({"decky_name": "d2", "operation": "mutate"})
await repo.update_lifecycle(a, {"status": "running"})
resp = await client.get(
"/api/v1/deckies/lifecycle",
params=[("ids", a), ("ids", b)],
headers={"Authorization": f"Bearer {auth_token}"},
)
assert resp.status_code == 200, resp.text
rows = resp.json()["rows"]
assert len(rows) == 2
by_id = {r["id"]: r for r in rows}
assert by_id[a]["status"] == "running"
assert by_id[a]["operation"] == "deploy"
assert by_id[b]["status"] == "pending"
assert by_id[b]["operation"] == "mutate"
@pytest.mark.anyio
async def test_get_lifecycle_unknown_id_silently_omitted(
client: httpx.AsyncClient, auth_token: str,
):
a = await repo.create_lifecycle({"decky_name": "d1", "operation": "deploy"})
resp = await client.get(
"/api/v1/deckies/lifecycle",
params=[("ids", a), ("ids", "no-such-id")],
headers={"Authorization": f"Bearer {auth_token}"},
)
assert resp.status_code == 200
rows = resp.json()["rows"]
assert len(rows) == 1
assert rows[0]["id"] == a
@pytest.mark.anyio
async def test_startup_sweep_marks_stale_rows_failed():
"""The sweep stamps reason='master restarted during operation' on
any non-terminal row older than the cutoff."""
from datetime import datetime, timedelta, timezone
lid = await repo.create_lifecycle({"decky_name": "stale", "operation": "deploy"})
# Backdate started_at into the past so the sweep picks it up.
await repo.update_lifecycle(
lid, {"started_at": datetime.now(timezone.utc) - timedelta(hours=2)},
)
swept = await repo.sweep_stale_lifecycle(
datetime.now(timezone.utc) - timedelta(hours=1),
reason="master restarted during operation",
)
assert swept >= 1
rows = await repo.get_lifecycle_by_ids([lid])
assert rows[0]["status"] == "failed"
assert rows[0]["error"] == "master restarted during operation"