fix: address track1-worker-compromise verify findings
- restore a verified row by fact: three variants give ready, otherwise failed with a known code instead of ready without content - check trigger functions are not SECURITY DEFINER and pin search_path - record the working stand comparison, the permanent drill lock file and the remaining SeaweedFS details Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,14 @@ from collections.abc import AsyncIterator
|
||||
|
||||
import asyncpg
|
||||
import pytest
|
||||
from incident_rows import VARIANTS, add_attachment, add_world
|
||||
from incident_rows import (
|
||||
INSERT_VARIANT_SQL,
|
||||
VARIANTS,
|
||||
add_attachment,
|
||||
add_world,
|
||||
connect_as,
|
||||
variant_key,
|
||||
)
|
||||
|
||||
from conftest import ROOT, admin, truncate_all
|
||||
|
||||
@@ -358,6 +365,92 @@ async def test_requeued_row_is_processable(
|
||||
assert tuple(row) == ("ready", None, "succeeded", 3)
|
||||
|
||||
|
||||
async def _result(
|
||||
connection: asyncpg.Connection,
|
||||
attachment: uuid.UUID,
|
||||
) -> tuple[object, ...]:
|
||||
row = await connection.fetchrow(
|
||||
"SELECT a.status, a.error_code, j.state, (SELECT count(*) FROM "
|
||||
"attachment_variants v WHERE v.attachment_id = a.id) FROM "
|
||||
"attachments a LEFT JOIN attachment_jobs j ON j.attachment_id = a.id "
|
||||
"WHERE a.id = $1",
|
||||
attachment,
|
||||
)
|
||||
return tuple(row)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("start", "variants", "expected"),
|
||||
[
|
||||
(
|
||||
("failed", "failed", ()),
|
||||
(),
|
||||
("failed", "processing_failed", "failed", 0),
|
||||
),
|
||||
# строка варианта своим ключом — право worker, результата нет
|
||||
(
|
||||
("failed", "failed", ()),
|
||||
("thumbnail",),
|
||||
("failed", "processing_failed", "failed", 0),
|
||||
),
|
||||
(
|
||||
("ready", "succeeded", VARIANTS),
|
||||
(),
|
||||
("ready", None, "succeeded", 3),
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_verified_restored_by_fact(
|
||||
connection: asyncpg.Connection,
|
||||
start: tuple[str, str, tuple[str, ...]],
|
||||
variants: tuple[str, ...],
|
||||
expected: tuple[object, ...],
|
||||
) -> None:
|
||||
"""Сверенное уборщиком: законный `failed` после срока хранения (исходник,
|
||||
оригинал и варианты убраны) и сверенное готовое. Роль worker возвращает
|
||||
его в `queued` — сверка называет порчу сверенного, возврат
|
||||
восстанавливает по факту: три варианта — готовое, иначе снова `failed` с
|
||||
известным кодом, а не `ready` без содержимого (verify W1)."""
|
||||
status, state, legal_variants = start
|
||||
world = await add_world(connection)
|
||||
row = await add_attachment(
|
||||
connection,
|
||||
world,
|
||||
status=status,
|
||||
state=state,
|
||||
staging=False,
|
||||
variants=legal_variants,
|
||||
)
|
||||
worker = await connect_as("worker")
|
||||
try:
|
||||
await worker.execute(
|
||||
"UPDATE attachments SET status = 'queued', error_code = NULL "
|
||||
"WHERE id = $1",
|
||||
row,
|
||||
)
|
||||
await worker.execute(
|
||||
"UPDATE attachment_jobs SET state = 'queued' "
|
||||
"WHERE attachment_id = $1",
|
||||
row,
|
||||
)
|
||||
for name in variants:
|
||||
await worker.execute(
|
||||
INSERT_VARIANT_SQL,
|
||||
row,
|
||||
name,
|
||||
variant_key(row, name),
|
||||
)
|
||||
finally:
|
||||
await worker.close()
|
||||
assert await _found(connection) == {row: {"verified_damaged"}}
|
||||
await _repair(connection)
|
||||
assert await _result(connection, row) == expected
|
||||
assert await _found(connection) == {}
|
||||
after = await _snapshot(connection)
|
||||
await _repair(connection)
|
||||
assert await _snapshot(connection) == after
|
||||
|
||||
|
||||
async def test_job_created_for_accepted_without_job(
|
||||
connection: asyncpg.Connection,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user