Commit 2014151
authored
fix(embed): resolve source files from DB root, not cwd (#992)
* fix(embed): resolve source files from DB root, not cwd
When `codegraph embed --db <abs-path>` is invoked without a positional
directory, the positional `rootDir` defaults to the current working
directory. The embed loop then joined every relative node file path
against cwd, causing every file read to fail and the command to exit
0 with a misleading "Stored 0 embeddings".
Fix:
- Persist the repo root (`root_dir`) in the `build_meta` table during
build (both WASM/JS finalize and the Rust native orchestrator).
- In `buildEmbeddings`, resolve relative file paths against
`build_meta.root_dir` first, falling back to the DB's parent
directory (`<root>/.codegraph/graph.db` → `<root>`) for DBs built
before this change, then finally the caller-provided rootDir.
- When every file read fails, throw `DbError` with a clear message so
the CLI exits non-zero instead of printing "Stored 0 embeddings"
and returning success.
Closes #983
Impact: 3 functions changed, 5 affected
* fix(embed): restore rootDir fallback when DB is outside .codegraph layout (#992)
The prior 'metaRoot || dbParent || rootDir' chain was unreachable past
dbParent because path.dirname always returns a non-empty string. This
silently ignored an explicit positional <dir> argument for legacy DBs
at non-standard locations.
Only use dbParent when the DB actually lives at the conventional
<root>/.codegraph/graph.db layout; otherwise fall through to the
caller-provided rootDir.
Impact: 1 functions changed, 1 affected
* fix(embed): canonicalize rootDir in JS to match Rust finalize_build (#992)
For native full builds, Rust's finalize_build writes root_dir via
std::fs::canonicalize (symlink-resolving) but the JS persistBuildMetadata
then overwrites it with path.resolve(), which does not resolve symlinks.
On systems where the project root is behind a symlink the two values
diverge and the JS write wins, reintroducing a non-canonical path.
Use fs.realpathSync to match the Rust behaviour, with a safe fallback
to path.resolve() if realpath throws.
Impact: 1 functions changed, 3 affected
* test(embed): wrap temp-dir tests in try/finally to avoid leaks (#992)
The ghostRepo and legacyRepo temp dirs were cleaned up inline in the
test body, so an unexpected throw before fs.rmSync would leak them.
Wrap each test in try/finally so cleanup always runs.1 parent 6f2cfeb commit 2014151
4 files changed
Lines changed: 177 additions & 2 deletions
File tree
- crates/codegraph-core/src
- src/domain
- graph/builder/stages
- search
- tests/search
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
706 | 713 | | |
707 | 714 | | |
708 | 715 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
91 | 105 | | |
92 | 106 | | |
93 | 107 | | |
| |||
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
| 116 | + | |
102 | 117 | | |
103 | 118 | | |
104 | 119 | | |
| |||
110 | 125 | | |
111 | 126 | | |
112 | 127 | | |
| 128 | + | |
113 | 129 | | |
114 | 130 | | |
115 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
76 | 91 | | |
77 | 92 | | |
78 | 93 | | |
| |||
98 | 113 | | |
99 | 114 | | |
100 | 115 | | |
| 116 | + | |
| 117 | + | |
101 | 118 | | |
102 | 119 | | |
103 | | - | |
| 120 | + | |
104 | 121 | | |
105 | 122 | | |
106 | 123 | | |
| 124 | + | |
107 | 125 | | |
| 126 | + | |
108 | 127 | | |
109 | 128 | | |
110 | 129 | | |
| |||
136 | 155 | | |
137 | 156 | | |
138 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
139 | 171 | | |
140 | 172 | | |
141 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
338 | 458 | | |
339 | 459 | | |
340 | 460 | | |
| |||
0 commit comments