Commit 5f5864c
Add path normalization for consistent cache comparison (#112)
* fix(cache): add path normalization for consistent cache comparison
This addresses issue #95 where content might not be updated correctly
during incremental fetches due to path comparison inconsistencies.
Changes:
- Add normalizePath() helper that resolves all paths to absolute paths
relative to PROJECT_ROOT for consistent comparison
- Update hasMissingOutputs() to use normalizePath when checking file existence
- Update updatePageInCache() to normalize paths before storage
- Fix hasMissingOutputs() to return true for empty outputPaths arrays,
ensuring pages with no outputs get regenerated
- Add comprehensive test coverage in pathNormalization.test.ts
- Update existing tests to expect normalized absolute paths
* fix(cache): normalize existing paths during merge for proper deduplication
When merging existing paths with new paths in updatePageInCache,
existing paths from older caches (stored in non-normalized format)
were being added without normalization. This caused duplicate entries
when the same file was represented in different formats.
Changes:
- Normalize existing paths in updatePageInCache before merging
- Add test case verifying old-format paths are properly deduplicated
- Comment clarifies this handles migration from older cache formats
* feat(cache): add PROJECT_ROOT import and integration tests for path handling
Phase 5-6 of issue #95 fix:
- Import PROJECT_ROOT in generateBlocks.ts for consistent path resolution
- Replace process.cwd() with PROJECT_ROOT for S3 URL path detection
- Add integration tests for path normalization edge cases:
- Mixed path formats in cache (migration scenario)
- Missing outputs detection regardless of format
- Path deduplication across updates
- Multi-language path consistency
* docs(cache): update outputPaths comment to reflect absolute path storage
The interface comment incorrectly stated paths were "relative to project root"
but they are now stored as absolute paths for consistency. This documentation
fix aligns the comment with the actual implementation.
* fix(cache): normalize filePath before comparing with cached paths
Ensures consistent path comparison in the needsProcessing check by
normalizing filePath before comparing with cached outputPaths. This
prevents edge cases where path format differences could cause
incorrect skip/process decisions.
* fix(cache): improve normalizePath to handle genuine system paths
The normalizePath function now correctly distinguishes between:
1. Project-relative paths like /docs/intro.md (where /docs doesn't exist)
2. Genuine system paths like /tmp/foo or /etc/config (where parent exists)
Uses filesystem check (fs.existsSync on parent directory) to determine
if an absolute path outside PROJECT_ROOT should be preserved as-is or
treated as project-relative.
Fixes external feedback about /tmp/foo being incorrectly rewritten to
PROJECT_ROOT/tmp/foo.
* fix(cache): handle root-level paths correctly in normalizePath
Paths like /a where the parent is "/" should be treated as project-relative,
not system paths. The root directory always exists, so we can't use its
existence as an indicator of a genuine system path.
Added check: if parent directory IS the root (path.parse(parentDir).root === parentDir),
don't trust fs.existsSync and treat as project-relative instead.
Added tests for:
- /a (single directory at root level)
- /foo/bar/baz.txt (nested paths where only root exists)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 264e2dd commit 5f5864c
File tree
5 files changed
+955
-25
lines changed- scripts/notion-fetch
- __tests__
5 files changed
+955
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
97 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
98 | 103 | | |
99 | 104 | | |
100 | 105 | | |
| |||
226 | 231 | | |
227 | 232 | | |
228 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 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 | + | |
229 | 390 | | |
230 | 391 | | |
231 | 392 | | |
| |||
Lines changed: 102 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
228 | 230 | | |
229 | 231 | | |
230 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
| |||
239 | 244 | | |
240 | 245 | | |
241 | 246 | | |
242 | | - | |
| 247 | + | |
243 | 248 | | |
244 | 249 | | |
245 | 250 | | |
246 | 251 | | |
247 | | - | |
| 252 | + | |
248 | 253 | | |
249 | 254 | | |
250 | 255 | | |
| |||
258 | 263 | | |
259 | 264 | | |
260 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
261 | 269 | | |
262 | 270 | | |
263 | 271 | | |
| |||
267 | 275 | | |
268 | 276 | | |
269 | 277 | | |
270 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
271 | 283 | | |
272 | 284 | | |
273 | 285 | | |
| |||
325 | 337 | | |
326 | 338 | | |
327 | 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 | + | |
328 | 409 | | |
329 | 410 | | |
330 | 411 | | |
| |||
379 | 460 | | |
380 | 461 | | |
381 | 462 | | |
382 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
383 | 467 | | |
384 | 468 | | |
385 | 469 | | |
386 | 470 | | |
| 471 | + | |
| 472 | + | |
387 | 473 | | |
388 | 474 | | |
389 | | - | |
| 475 | + | |
390 | 476 | | |
391 | 477 | | |
392 | 478 | | |
393 | 479 | | |
394 | 480 | | |
395 | 481 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
400 | 485 | | |
401 | 486 | | |
402 | 487 | | |
| |||
417 | 502 | | |
418 | 503 | | |
419 | 504 | | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
425 | 513 | | |
426 | 514 | | |
427 | 515 | | |
| |||
0 commit comments