This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
@@ -75,6 +76,57 @@ def test_step_transitions_persist_during_execution(tmp_path) -> None:
|
||||
assert [r["index"] for r in records] == [1, 2]
|
||||
|
||||
|
||||
def test_task_metadata_creation_is_idempotent_and_keeps_source_correlation(
|
||||
tmp_path,
|
||||
) -> None:
|
||||
metadata_store = TaskMetadataStore(tmp_path / "tasks.sqlite3")
|
||||
task = _make_task("task-source")
|
||||
|
||||
metadata_store.create_task(
|
||||
task,
|
||||
source_task_id="cloud-task-source",
|
||||
source_attempt=2,
|
||||
)
|
||||
metadata_store.create_task(task)
|
||||
|
||||
row = metadata_store.get_task(task.id)
|
||||
assert row is not None
|
||||
assert row["source_task_id"] == "cloud-task-source"
|
||||
assert row["source_attempt"] == 2
|
||||
|
||||
|
||||
def test_existing_task_database_gains_source_correlation_columns(tmp_path) -> None:
|
||||
db_path = tmp_path / "legacy.sqlite3"
|
||||
with sqlite3.connect(db_path) as connection:
|
||||
connection.execute(
|
||||
"""
|
||||
create table tasks (
|
||||
id text primary key,
|
||||
goal text not null,
|
||||
device_id text not null,
|
||||
status text not null,
|
||||
created_at text not null,
|
||||
updated_at text not null,
|
||||
completed_at text,
|
||||
failure_reason text
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
metadata_store = TaskMetadataStore(db_path)
|
||||
task = _make_task("task-migrated")
|
||||
metadata_store.create_task(
|
||||
task,
|
||||
source_task_id="cloud-task-migrated",
|
||||
source_attempt=1,
|
||||
)
|
||||
|
||||
row = metadata_store.get_task(task.id)
|
||||
assert row is not None
|
||||
assert row["source_task_id"] == "cloud-task-migrated"
|
||||
assert row["source_attempt"] == 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Queryable after completion (in-memory Task discarded)
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user