Skip to content

fix(graph): re-absolutize repo-scoped bundle paths on import (#1509) - #1627

Open
ASHMEET555 wants to merge 1 commit into
CodeGraphContext:mainfrom
ASHMEET555:fix/1509-bundle-repo-path-collision
Open

fix(graph): re-absolutize repo-scoped bundle paths on import (#1509)#1627
ASHMEET555 wants to merge 1 commit into
CodeGraphContext:mainfrom
ASHMEET555:fix/1509-bundle-repo-path-collision

Conversation

@ASHMEET555

Copy link
Copy Markdown

Summary

Fixes #1509 (GSSoC'26).

Repo-scoped export (cgc bundle export --repo) correctly rewrites absolute paths to portable . / ./… form. Import never inverted that rewrite, so every imported bundle landed with Repository.path = ".". _check_existing_repository then matched on that path, so loading a second registry bundle (for example flask, then requests) was always refused as a duplicate. --clear was the only workaround and it wiped the first bundle, which breaks the bundle-registry use case (#1180).

Even if the existence check were skipped, File MERGE keys such as ./README.md and Function/Class uids built from name + path + line_number would collide across repos.

Export is unchanged. Relative .cgc contents stay portable. Import is now the inverse of the rewrite.

Problem

  1. False duplicate: after import, metadata.repo_path and the Repository node path are ".". The path MATCH in _check_existing_repository then hits any previously imported repo-scoped bundle.
  2. File primary-key collision: _PK_MAP MERGEs File/Directory/Repository on path, so ./README.md from two repos would become one node.
  3. Function/Class identity: _UID_PARTS builds uid from name + path + line_number. Relative paths would make parse at line 1 collide across repos.

Solution

On import, rebase . / ./… onto a per-bundle destination root:

~/.codegraphcontext/bundles/<sanitized_repo>

Example: pallets/flask becomes slug pallets__flask. Tests can pass destination_root= so they never touch the real home directory.

Behaviour:

  • Rebase metadata.repo_path and all bundle-relative node/edge string properties before MERGE.
  • _check_existing_repository still matches by name (same repo twice is still a duplicate) but does not treat . / ./… as an identifying path.
  • After rebase, Function/Class uid is rebuilt from _UID_PARTS so identity includes the dest root.
  • _delete_repository refuses to delete when r.path is ., because STARTS WITH "./" would wipe every repo-scoped import.

Upstream encryption/signing (password, verify_key, payload_path) is preserved after rebase onto main.

Files changed

  • src/codegraphcontext/core/cgc_bundle.py — path helpers, import rebase, existence-check hardening, delete guard. Also threads destination_root on import_from_bundle without breaking password / verify_key.
  • tests/unit/core/test_bundle_repo_scoped_import.py — new unit tests (mocked driver, no live graph DB).

CLI and MCP call sites are unchanged. They pick up the default dest root.

Tests performed

Command:

python -m pytest tests/unit/core/test_bundle_repo_scoped_import.py tests/unit/core/test_bundle_edge_zero_id.py tests/unit/core/test_bundle_identifier_validation.py tests/unit/core/test_bundle_pk_map_coverage.py -q

Result: 87 passed.

Covered:

  • Rebase of ., ./README.md, .\src\a.py; absolute paths and os.path left alone.
  • Slug pallets/flask -> pallets__flask; empty -> unknown.
  • Path "." does not issue MATCH (r:Repository {path: $path}); real absolute paths still do; name match still runs.
  • Two File rows both ./README.md MERGE with distinct pk_val values (flask vs requests dest roots).
  • Function uid contains dest root, not ./.
  • _delete_repository no-ops when found path is ".".

Related existing bundle tests still pass: edge zero-id, identifier validation, _PK_MAP coverage.

Checklist

@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

@ASHMEET555 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog tasks

Development

Successfully merging this pull request may close these issues.

bug(graph): repo-scoped bundles export their root path as ., so importing a second bundle is always refused as a duplicate

1 participant