Skip to content

Fix KuzuDB compatibility, DB override precedence and test determinism - #812

Merged
Shashankss1205 merged 3 commits into
CodeGraphContext:mainfrom
DhineshPonnarasan:fix/769-kuzu-compat-and-cli-hardening
May 7, 2026
Merged

Shashankss1205 merged 3 commits into
CodeGraphContext:mainfrom
DhineshPonnarasan:fix/769-kuzu-compat-and-cli-hardening

Conversation

@DhineshPonnarasan

@DhineshPonnarasan DhineshPonnarasan commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR addresses the KuzuDB compatibility and runtime-selection issues tracked in #769, and hardens test determinism across environments.

What changed

KuzuDB compatibility and stability

  • Added compatibility rewrites for Kuzu-incompatible patterns in database_kuzu.py:
    • fulltext CALL patterns rewritten/neutralized
    • deps query scoping rewritten with explicit WITH carry-over
    • ORDER BY alias compatibility adjustments
  • Added fail-fast query-type guard for repeated incompatible patterns to avoid repeated noisy failures.
  • Improved UNWIND batch normalization and deduplication to avoid struct-field and duplicate-row issues.
  • Hardened UID generation and uid-keyed MERGE semantics to avoid PK collisions.

Config/runtime precedence and logging

  • Fixed _load_credentials() precedence to preserve runtime env values over file-config merges.
  • Added source-aware database selection output and conflict visibility for DEFAULT_DATABASE.
  • Added --db alias for global DB override.

Neo4j connection handling

  • Added lightweight socket preflight reachability check.
  • Added clear, actionable Neo4jConnectionError messages with suggested fixes.
  • Improved cgc doctor with credential check, endpoint/port check, and connection test reporting.
  • Prevented implicit fallback unless explicitly enabled (CGC_ALLOW_NEO4J_FALLBACK).

Cross-platform path handling

  • Normalized path resolution before relative_to() in graph_builder.py.
  • Added os.path.relpath fallback when paths are not directly relative.

Test hardening and determinism

  • Added Kuzu compatibility regression tests:
    • tests/unit/core/test_database_kuzu_compat.py
  • Added Neo4j preflight tests in tests/unit/core/test_database.py.
  • Made FalkorDB remote unit tests independent of local falkordb installation.
  • Updated CLI integration assertions to behavior-based/source-aware output checks.
  • Fixed E2E tests to:
    • explicitly use --db kuzudb for index/list/find/delete flows
    • skip when kuzu is not installed
    • use sys.executable instead of hardcoded python3

Validation

  • pytest -q => 166 passed, 16 skipped
  • pytest -q tests/unit/core => 81 passed, 14 skipped
  • pytest -q tests/unit/core/test_database_kuzu_compat.py => 10 passed

Screenshot

image

Linked issue


Hi @Shashankss1205 ,
Please review these changes and let me know if any further modifications are needed. If you notice any issues, please leave a comment below and I will address them. Thank you!

@vercel

vercel Bot commented Apr 8, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@DhineshPonnarasan DhineshPonnarasan changed the title Fix KuzuDB compatibility, DB override precedence, and test determinism Fix KuzuDB compatibility, DB override precedenceand test determinism Apr 8, 2026
@DhineshPonnarasan DhineshPonnarasan changed the title Fix KuzuDB compatibility, DB override precedenceand test determinism Fix KuzuDB compatibility, DB override precedence and test determinism Apr 8, 2026
@Shashankss1205

Copy link
Copy Markdown
Collaborator

@DhineshPonnarasan We have a lot of merge conflicts on this because of the recent refactor we did. can you please rebase it and then make a PR?

@DhineshPonnarasan

Copy link
Copy Markdown
Contributor Author

Done bro @Shashankss1205

bhavnesh75 added a commit to hi0001234d/CodeGraphContext that referenced this pull request Apr 15, 2026
bhavnesh75 pushed a commit to hi0001234d/CodeGraphContext that referenced this pull request Apr 15, 2026
@hi0001234d

Copy link
Copy Markdown
Collaborator

PR #812 — Testing Complete

Overview

PR #812 adds KuzuDB compatibility to CodeGraphContext. Previously only Neo4j was supported, now users can use KuzuDB as the graph database backend.

Key Changes Made:

  • Fulltext query rewrite (Kuzu has no fulltext index)
  • UNWIND batch normalization (handles missing keys)
  • ORDER BY alias fix for Kuzu
  • Fail-fast guard (disables problematic query types)
  • UID fingerprint (collision resistance)
  • Neo4j TCP preflight check + actionable errors
  • CLI --db flag fix (precedence over context)

17 Tests Added (File-wise)

tests/unit/core/test_database_kuzu_compat.py (10)

# Test What it verifies
1 test_rewrites_module_deps_query_for_kuzu_scope_and_ordering WITH carry-over, ORDER BY alias
2 test_rewrites_coimports_order_by_alias ORDER BY other_module.name → imported_module
3 test_fulltext_index_procedure_becomes_noop createNodeIndex → RETURN 1
4 test_fulltext_query_rewrites_to_substring_search queryNodes → CONTAINS rewrite
5 test_fail_fast_disables_query_type_after_first_known_compat_error Query type disabled after error
6 test_sanitize_value_normalizes_list_of_dict_keys_for_unwind_batches Missing keys normalized
7 test_sanitize_value_deduplicates_identical_batch_rows Duplicate rows removed
8 test_import_batch_rewrite_sets_missing_full_import_name Missing fields get sentinel -1
9 test_unwind_uid_injection_uses_fallback_for_missing_pk_fields UID with missing PK fields
10 test_inheritance_queries_are_classified_for_fail_fast_guard INHERITS/IMPLEMENTS classified

tests/unit/core/test_database.py (4)

# Test What it verifies
11 test_check_port_reachable_success TCP port reachable
12 test_check_port_reachable_failure TCP port unreachable error
13 test_missing_credentials_message_contains_config_commands Actionable error msg
14 test_get_driver_fails_fast_when_port_unreachable Neo4jConnectionError raised

tests/integration/cli/test_cli_commands.py (1)

# Test What it verifies
15 test_db_flag_kuzudb_not_overwritten_by_context_database --db flag wins over context

tests/e2e/test_user_journeys.py (2)

# Test What it verifies
16 test_first_time_user_workflow index → list → find workflow
17 test_clean_up index → delete workflow

Test Results

Suite Result
Full Test Suite ✅ 176 passed, 14 skipped
PR #812 New Tests (17) ✅ All 17 passed

Status: ✅ PR #812 Verified


Verification Date: 2026-04-15

All 17 tests verified on branch review/pr-812:

  • ✅ KuzuDB compatibility tests (10/10 passed)
  • ✅ Neo4j preflight tests (4/4 passed)
  • ✅ CLI --db flag test (1/1 passed)
  • ✅ E2E user journey tests (2/2 passed)

Additional Notes

  • Additional 17 test cases have been added, commit link.
  • I confirm that if you merge this pull request, no errors should occur. You can safely proceed with the merge.

@Shashankss1205
Shashankss1205 merged commit e714f6f into CodeGraphContext:main May 7, 2026
8 of 9 checks passed
macunha1 pushed a commit to macunha1/CodeGraphContext that referenced this pull request Jun 21, 2026
…9-kuzu-compat-and-cli-hardening

Fix KuzuDB compatibility, DB override precedence and test determinism
@Shashankss1205 Shashankss1205 added gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:exceptional GSSoC quality: x1.5 contributor / +10 mentor type:bug GSSoC type bonus: bug labels Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:exceptional GSSoC quality: x1.5 contributor / +10 mentor type:bug GSSoC type bonus: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] KuzuDB 0.11.3 backend: systemic query incompatibilities break call-graph, deps, and resolution phase

3 participants