coalesce safe identifier task duplicates
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a053ff-1d6f-7fe2-ac1c-a6eb40a42a0c
This commit is contained in:
parent
142c94287e
commit
a7c91a6d65
2 changed files with 206 additions and 3 deletions
|
|
@ -318,6 +318,111 @@ async def test_repository_migration_accepts_mixed_legacy_and_derived_projection(
|
|||
assert retried.already_derived == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_repository_migration_coalesces_identical_unreferenced_task_duplicate(
|
||||
test_engine,
|
||||
):
|
||||
factory = async_sessionmaker(test_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
ids = await _seed_projection(factory, "duplicate-repo")
|
||||
plan = _sealed_plan("duplicate-repo", ids["workplan"], ids["task"])
|
||||
task_new = _derived("TEST-WP-0001-T01")
|
||||
workplan_new = _derived("TEST-WP-0001")
|
||||
|
||||
async with factory() as session:
|
||||
await session.execute(
|
||||
text("DELETE FROM workplan_dependencies WHERE to_task_id = :task_id"),
|
||||
{"task_id": ids["task"]},
|
||||
)
|
||||
await session.execute(
|
||||
text("DELETE FROM progress_events WHERE task_id = :task_id"),
|
||||
{"task_id": ids["task"]},
|
||||
)
|
||||
await session.execute(
|
||||
text("DELETE FROM token_events WHERE task_id = :task_id"),
|
||||
{"task_id": ids["task"]},
|
||||
)
|
||||
await session.execute(
|
||||
text("DELETE FROM tasks WHERE parent_task_id = :task_id"),
|
||||
{"task_id": ids["task"]},
|
||||
)
|
||||
legacy = await session.get(Task, ids["task"])
|
||||
session.add(
|
||||
Task(
|
||||
id=task_new,
|
||||
workplan_id=legacy.workplan_id,
|
||||
record_id="TEST-WP-0001-T01",
|
||||
title=legacy.title,
|
||||
description=legacy.description,
|
||||
status=legacy.status,
|
||||
priority=legacy.priority,
|
||||
assignee=legacy.assignee,
|
||||
due_date=legacy.due_date,
|
||||
blocking_reason=legacy.blocking_reason,
|
||||
needs_human=legacy.needs_human,
|
||||
intervention_note=legacy.intervention_note,
|
||||
parent_task_id=legacy.parent_task_id,
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
async with factory() as session:
|
||||
result = await apply_repository_identifier_migration(
|
||||
session, plan, "duplicate-repo"
|
||||
)
|
||||
assert result.migrated == 2
|
||||
assert result.already_derived == 0
|
||||
|
||||
async with factory() as session:
|
||||
assert await session.get(Task, ids["task"]) is None
|
||||
task = await session.get(Task, task_new)
|
||||
assert task is not None
|
||||
assert task.workplan_id == workplan_new
|
||||
assert task.record_id == "TEST-WP-0001-T01"
|
||||
|
||||
async with factory() as session:
|
||||
await reverse_repository_identifier_migration(session, plan, "duplicate-repo")
|
||||
async with factory() as session:
|
||||
task = await session.get(Task, ids["task"])
|
||||
assert task is not None
|
||||
assert task.record_id == "TEST-WP-0001-T01"
|
||||
assert await session.get(Task, task_new) is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_repository_migration_rejects_referenced_task_duplicate(test_engine):
|
||||
factory = async_sessionmaker(test_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
ids = await _seed_projection(factory, "referenced-duplicate-repo")
|
||||
plan = _sealed_plan(
|
||||
"referenced-duplicate-repo", ids["workplan"], ids["task"]
|
||||
)
|
||||
async with factory() as session:
|
||||
legacy = await session.get(Task, ids["task"])
|
||||
session.add(
|
||||
Task(
|
||||
id=_derived("TEST-WP-0001-T01"),
|
||||
workplan_id=legacy.workplan_id,
|
||||
record_id="TEST-WP-0001-T01",
|
||||
title=legacy.title,
|
||||
description=legacy.description,
|
||||
status=legacy.status,
|
||||
priority=legacy.priority,
|
||||
assignee=legacy.assignee,
|
||||
due_date=legacy.due_date,
|
||||
blocking_reason=legacy.blocking_reason,
|
||||
needs_human=legacy.needs_human,
|
||||
intervention_note=legacy.intervention_note,
|
||||
parent_task_id=legacy.parent_task_id,
|
||||
)
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
async with factory() as session:
|
||||
with pytest.raises(IdentifierMigrationError, match="inbound references"):
|
||||
await apply_repository_identifier_migration(
|
||||
session, plan, "referenced-duplicate-repo"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_repository_migration_rejects_neither_legacy_nor_derived(test_engine):
|
||||
factory = async_sessionmaker(test_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue