Skip to content

feat(crawler): populate phase 6-d entity and edge tables#205

Merged
YusukeHirao merged 1 commit into
feature/impl-new-dbfrom
feature/193-phase6d-populate-entities
Jul 13, 2026
Merged

feat(crawler): populate phase 6-d entity and edge tables#205
YusukeHirao merged 1 commit into
feature/impl-new-dbfrom
feature/193-phase6d-populate-entities

Conversation

@YusukeHirao

Copy link
Copy Markdown
Member

Summary

  • Adds Phase 6-D populate helpers (content_items / page_meta / resource_items / anchor_edges / resource_ref_edges / image_items) plus a standalone migration script scripts/migrate-to-phase6.mjs that runs 6-A → 6-D end-to-end against an existing .nitpicker archive.
  • Every populate helper is chunked keyset-paginated and idempotent via INSERT OR IGNORE. Correctness safeguards (blob-refs hash-list, header-sets raw_hash fallback, throw-on-missing-ref, dom-path overflow → unknown, page-by-page image iteration) applied in response to code-review / QA / PdM findings.
  • 68 new unit tests including the AC-required anchor-edge-normalization (collapse-anchor-rows.spec.ts), dom-path-derivation all-3-cases (match-images-to-dom-paths.spec.ts + derive-dom-path.spec.ts), and url-refs-population (resolve-url-refs.spec.ts). Full yarn test (3154) passes; yarn lint / lint:check clean.

Notes for reviewers

  • The plan doc (docs/write-model-refactor-plan.md) currently lives on codex/111-write-model-refactor-plan and is not yet on feature/impl-new-db; referenced here but out of scope for this PR.
  • .bak semantics differ from the plan verbiage: the migration script uses out-of-place migration (untar → workDir → new tar; input untouched), which is strictly safer than the in-place .bak the plan describes. Phase 6-B and 6-D run in separate db.transaction blocks.
  • verifyAcceptanceCounts is a 4-check subset of Phase 6-E: migration verification (8 invariant checks + .bak rollback) #194's 8-check + rollback spec — extract into runPhase6EVerification in Phase 6-E: migration verification (8 invariant checks + .bak rollback) #194.
  • AC filenames renamed under the 1-file-1-export rule: anchor-edge-normalizationcollapse-anchor-rows.spec.ts; dom-path-derivationderive-dom-path.spec.ts + match-images-to-dom-paths.spec.ts (all 3 cases in the latter); url-refs-populationresolve-url-refs.spec.ts.

Closes #193

Test plan

  • yarn build
  • yarn test
  • yarn lint:check
  • Manual dry-run: node scripts/migrate-to-phase6.mjs <fixture>.nitpicker → verify acceptance count log

🤖 Generated with Claude Code

Adds the Phase 6-D migration helpers that populate content_items,
page_meta, resource_items, anchor_edges, resource_ref_edges, and
image_items from the legacy write model, plus a standalone migration
script `scripts/migrate-to-phase6.mjs` that runs the whole 6-A → 6-D
sequence on an existing archive.

Every populate helper is chunked keyset-paginated and idempotent via
`INSERT OR IGNORE` on the natural key. `anchor_edges` collapses
duplicate `(pageId, hrefId)` rows via a single-pass JS scan whose
"first row wins" contract is guarded by a sort-order assertion.
`image_items.dom_path_text_id` is derived through an injected callback
so the crawler runtime stays jsdom-free; the migration script wires
the jsdom-backed implementation.

Correctness safeguards applied in response to review findings:
- `resolve-blob-refs` maps `hash → [raw values]` so two distinct
  data-URI strings that decode to the same payload both get the
  shared blob_refs id.
- `resolve-header-sets` falls back from `raw_json_hash` to `raw_hash`
  so a JSON variant with different key ordering still resolves to
  the shared header_sets row.
- Populate helpers throw when a non-null source value has no matching
  ref, instead of silently writing NULL — the count-based acceptance
  check would otherwise pass while individual rows lost data.
- `matchImagesToDomPaths` overflow returns `unknown/<id>` instead of
  mapping every extra row to the last DOM candidate.
- `populateImageItems` iterates by pageId, resolving each page's HTML
  and dom paths exactly once so a page whose images straddle a chunk
  cannot re-parse HTML or reset the ordinal cursor.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@YusukeHirao YusukeHirao merged commit 5342fbd into feature/impl-new-db Jul 13, 2026
9 checks passed
@YusukeHirao YusukeHirao deleted the feature/193-phase6d-populate-entities branch July 13, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant