[chore] ci-watch/dep-update dedupe: normalize git_url + treat empty-string workflow as default (#148 #1267)

The per-repo open-task dedupe filtered ProjectTable.git_url == git_url
(exact), while the orchestrator collapses its poll set by repo_key
(lower / strip trailing '/' / drop '.git'). Two projects whose git_url
differs only by those accidentals (a monorepo's cell-projects, or a
re-registered canonical project) defeated the one-open-task-per-repo
invariant and opened duplicate fix / dep-update tasks. Extract
roboco.utils.converters.repo_key as the single source and match the
dedupe query on its SQL mirror (regexp_replace(rtrim(lower(...)))).

The ci_watch (git_url, workflow) dedupe used func.coalesce(ci_watch_workflow,
default), but SQL COALESCE only substitutes for NULL — a project saved with
ci_watch_workflow='' (reachable via panel/API) yielded coalesce('', default)
= '' != default, so the DB diverged from the engine/orchestrator (which
collapse '' to the default via Python truthiness) and opened a duplicate
fix task every red cycle. Wrap with func.nullif(..., '') so an empty string
collapses to the default too.

Tests: a ''-workflow + NULL-workflow project on one repo dedupe to one task;
git_url accidentals (.git suffix / trailing slash) dedupe across both
ci_watch and dep_update. The orchestrator _repo_key now delegates to repo_key.
This commit is contained in:
Renn F
2026-06-30 19:19:31 +02:00
parent 6907103073
commit d34bc1a7a5
5 changed files with 100 additions and 8 deletions
@@ -130,3 +130,19 @@ async def test_git_url_scoping(db_session: AsyncSession) -> None:
scoped = await svc.list_open_dep_update_tasks(git_url="https://github.com/x/a.git")
assert len(scoped) == 1
assert scoped[0].project_id == proj_a.id
@pytest.mark.asyncio
async def test_git_url_accidentals_scoping(db_session: AsyncSession) -> None:
"""#1267: a dep_update task open on ``.../a.git`` is found when scoping by a
git_url that differs only by a ``.git`` suffix / trailing slash — the dedupe
key is the normalized repo, not the exact string."""
proj_a = await _seed_project(db_session, "https://github.com/x/a.git")
await _make_task(db_session, proj_a)
svc = get_task_service(db_session)
# Same repo, accidental variants — each scope finds the one open task.
for variant in ("https://github.com/x/a", "https://github.com/x/a.git/"):
scoped = await svc.list_open_dep_update_tasks(git_url=variant)
assert len(scoped) == 1
assert scoped[0].project_id == proj_a.id