fix: cargo repo gap (CM-1305)#4332
Conversation
There was a problem hiding this comment.
Pull request overview
Adds canonical repository URL normalization to Cargo package synchronization.
Changes:
- Builds a staging map of declared URLs to canonical URLs.
- Updates package enrichment and audit tracking.
- Adds a Temporal normalization activity.
The PR title is missing the required JIRA key.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
cargo/workflows.ts |
Runs repository normalization before enrichment. |
cargo/types.ts |
Defines normalization result counts. |
cargo/normalizeRepos.ts |
Builds the canonical URL mapping. |
cargo/enrich.ts |
Updates and audits package repository URLs. |
cargo/activities.ts |
Exposes the normalization activity. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2155132. Configure here.
| homepage = COALESCE(e.homepage, p.homepage), | ||
| declared_repository_url = COALESCE(e.declared_repository_url, p.declared_repository_url), | ||
| repository_url = CASE WHEN e.declared_repository_url IS NOT NULL | ||
| THEN rn.repository_url ELSE p.repository_url END, |
There was a problem hiding this comment.
Stale repository_url after repo removal
Medium Severity
When staging has declared_repository_url NULL (empty crate repository in the dump), enrichRepos prunes all source='declared' package_repos rows, but enrichPackages keeps the prior packages.repository_url via the CASE else branch. package_repos and packages.repository_url can disagree after a crate drops its repository.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 2155132. Configure here.
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>


Summary
Fixes the cargo repo-normalization gap (CM-1305 follow-up): declared repo URLs from crates.io often arrive in shorthand (
github:owner/repo), SSH (git@github.com:owner/repo.git), or junk/homepage form instead of a canonicalhttps://<host>/<owner>/<name>URL.packages.repository_urlwas left null or wrong for these cases, andrepos/package_reposcould drift out of sync with it entirely.Adds a
normalizeReposstep that canonicalizes every distinctdeclared_repository_urlstaged in a dump intocargo_sync.repo_norm, then wires that canonical mapping into bothenrichPackages(packages.repository_url) andenrichRepos(repos.url/package_repos), so both tables always agree on the same canonical value.Changes
normalizeRepos(cargo/normalizeRepos.ts): buildscargo_sync.repo_norm(declared, repository_url, host)via the sharedcanonicalizeRepoUrl(same normalizer npm/pypi use). Only inputs reducible to an owner/name pair are stored; unparseable declared URLs are omitted, so aLEFT JOINnaturally yieldsNULL.enrichPackagesto writepackages.repository_urlfromrepo_normonly when the current dump supplies adeclared_repository_url— preserves the existing value when a dump omits the field, instead of wiping it.enrichReposto join throughrepo_norminstead of the raw declared URL, and to prune stalesource='declared'package_reposlinks before relinking (mirrors the existing pattern inmaven/backfillRepositoryUrl.ts) — covers both junk declared values (no canonical → link removed) and rewrites (declared URL now maps to a different repo).cargoNormalizeReposin the top-level activities barrel (src/activities.ts) — it was implemented but never exported, so the Temporal worker could not dispatch it.EnrichReposResultwith aprunedcount for observability.Type of change
JIRA ticket
CM-1305
Note
Medium Risk
Changes package–repo linkage and
packages.repository_urlfor all cargo sync runs; incorrect canonicalization or pruning could affect downstream consumers (e.g. security-contacts) that join viapackage_repos.Overview
Fixes cargo repo handling so canonical repository URLs stay aligned across
packages,repos, andpackage_reposinstead of using raw crates.iodeclared_repository_urlvalues (shorthand, SSH, junk, etc.).Adds a
cargoNormalizeReposstep after dump load that rebuilds staging tablerepo_normby mapping each distinct declared URL through sharedcanonicalizeRepoUrl(same as npm/pypi).enrichPackagesnow setspackages.repository_urlfrom that mapping when the dump includes a declared URL, and leaves the existing value when the field is absent.enrichReposinserts repos andpackage_reposviarepo_norm, prunes stalesource='declared'links before relinking, and on link conflict only bumps confidence (does not overwrite source). The activity is exported and wired intocargoSyncWorkflow;EnrichReposResultgains aprunedcount.Reviewed by Cursor Bugbot for commit 1b5bde2. Bugbot is set up for automated code reviews on this repo. Configure here.