Skip to content

fix(search): wire SearchResult imports/exports and stabilize map hub selection#100

Merged
PatrickSys merged 2 commits intomasterfrom
fix/phase-15-5-searchresult-imports
Apr 14, 2026
Merged

fix(search): wire SearchResult imports/exports and stabilize map hub selection#100
PatrickSys merged 2 commits intomasterfrom
fix/phase-15-5-searchresult-imports

Conversation

@PatrickSys
Copy link
Copy Markdown
Owner

What / Why

This fixes 2 small but real gaps in the search and map surfaces.

Full-mode search_codebase was trying to serialize chunk-level imports and exports, but SearchResult never carried those fields through from the indexed chunk metadata. As a result, those keys were silently absent even when the data existed. This PR wires the typed fields through the search pipeline and removes the unsafe cast in the serializer.

It also makes enrichLayers() deterministic when multiple files in the same layer have the same importer count. Ties now follow the existing count-desc-then-alpha ordering instead of depending on iteration order.

Changes

  • add typed top-level imports and exports to SearchResult
  • copy chunk imports/exports through both the main and fallback search-result paths
  • serialize full-mode chunk imports/exports directly from the typed fields
  • break layer hub-file ties alphabetically via the existing shared sort path
  • add regressions for full-mode imports/exports serialization and deterministic hub-file selection

Verification

  • pnpm format:check
  • pnpm lint
  • pnpm run type-check
  • pnpm build
  • pnpm test -- tests/search-compact-mode.test.ts
  • pnpm test -- tests/codebase-map.test.ts
  • pnpm test
  • pnpm audit --prod

Release notes

This should appear in release notes as a search/map correctness fix.

  • Conventional-commits squash title is already used
  • .planning/** and Phase 16 release metadata are intentionally excluded from this PR

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR fixes two correctness gaps: SearchResult now carries typed imports and exports fields wired from CodeChunk, replacing the unsafe as unknown as cast in the serializer; and enrichLayers() uses the existing sortByCountThenAlpha utility to deterministically pick the hub file when multiple files in the same layer share the same importer count. Both fixes are covered by new regression tests.

Confidence Score: 5/5

  • Safe to merge — all changes are targeted correctness fixes with regression test coverage and no unsafe patterns introduced.
  • Both changes (typed imports/exports wiring and deterministic hub-file selection) are narrow, well-understood fixes backed by new regression tests. No P0 or P1 findings were identified.
  • No files require special attention.

Important Files Changed

Filename Overview
src/types/index.ts Adds optional imports and exports to SearchResult, aligning it with the already-typed fields in CodeChunk.
src/core/search.ts Wires chunk.imports and chunk.exports through both the main and fallback (test-chunk) search-result construction paths.
src/tools/search-codebase.ts Removes the as unknown as { imports?: string[] } unsafe cast now that the fields are typed on SearchResult.
src/core/codebase-map.ts Replaces manual iteration loop in enrichLayers with sortByCountThenAlpha, making hub-file selection deterministic on tied importer counts.
tests/codebase-map.test.ts Adds a regression test for alphabetical tie-breaking using a temp-dir fixture with two equal-importer-count files.
tests/search-compact-mode.test.ts Adds a regression test verifying full-mode serialization includes chunk-level imports (truncated to 5) and exports; also reformats two long assertion lines.

Sequence Diagram

sequenceDiagram
    participant C as search_codebase (tool)
    participant S as CodebaseSearcher
    participant SR as SearchResult

    C->>S: search(query, limit, filters)
    S->>SR: build result from CodeChunk
    note over SR: imports: chunk.imports ✅<br/>exports: chunk.exports ✅
    S-->>C: SearchResult[]

    C->>C: "r.imports?.slice(0,5)<br/>r.exports?.slice(0,5)"
    note over C: typed access, no cast ✅
    C-->>C: serialize full-mode payload
Loading

Reviews (1): Last reviewed commit: "fix(search): wire SearchResult imports/e..." | Re-trigger Greptile

@PatrickSys PatrickSys force-pushed the fix/phase-15-5-searchresult-imports branch from 08c1cb2 to 5ba2b90 Compare April 14, 2026 19:10
@PatrickSys PatrickSys merged commit 922f9fc into master Apr 14, 2026
3 checks passed
@PatrickSys PatrickSys deleted the fix/phase-15-5-searchresult-imports branch April 14, 2026 19:12
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