Skip to content

fix(arch): tighten test-file dirs and import-hint resolution#49

Open
Asgarrrr wants to merge 1 commit into
mainfrom
fix/arch-sense-precision
Open

fix(arch): tighten test-file dirs and import-hint resolution#49
Asgarrrr wants to merge 1 commit into
mainfrom
fix/arch-sense-precision

Conversation

@Asgarrrr

@Asgarrrr Asgarrrr commented May 8, 2026

Copy link
Copy Markdown
Owner

Summary

Three correctness fixes in senseArchitecture (V0.2 architecture sensing). All stay inside ADR 0005's filesystem-only envelope — no AST, no import graph, no new dependencies.

What changed

# Heuristic Before After
1 test-file Only ${dir}/<stem>... and ${dir}/tests/<stem>... Adds co-located __tests__/ and repo-root tests/ / __tests__/
2 import-hint basename(spec) === basename(changed) Resolve spec against importer dir (POSIX), match resolved path with .ts/.tsx and /index.ts(x) suffix recovery
3 import-hint Any from "..." regex match Skip bare specifiers (from "react") and tsconfig-paths aliases (from "@/x")

Why now

A deep read of src/architecture/sense.ts surfaced two real correctness gaps and one real coverage gap:

  • The previous ${dir}/tests/-only rule never fires on Mira's own repo — all tests live at top-level tests/. Same for any project using Bun-style top-level tests, Jest's __tests__/, or Python-style top-level tests/.
  • Basename-only matching cross-reports collisions: changing src/utils/foo.ts flagged any file importing an unrelated src/auth/foo. Path-resolved comparison eliminates this without leaving filesystem-only scope.
  • A changed file named react.ts matched from "react" purely by basename. Same fix.

tsconfig paths aliases are intentionally skipped — false negatives are preferred over false positives per ADR 0005's invariant. Documented as a deliberate non-coverage in a test case and in the ADR amendment.

ADR

Amended docs/adr/0005-architecture-sensing-v0-2-scope.md (V0.2.1):

  • Bullet 3 (test-file): expanded directory list.
  • Bullet 4 (import-hint): replaced basename matching with resolved-path matching.
  • Added an Amendments section recording the change.

Test plan

  • bun test tests/architecture-signal.test.ts — 27 pass / 0 fail (20 existing + 7 new)
  • bun test — 316 pass / 0 fail / 23 files
  • All existing import-hint and test-file tests pass unchanged under the new resolver — verified by tracing each case
  • New cases prove F1 / F2 / F5 are fixed: they fail before the patch, pass after

Out of scope (deferred follow-ups)

  • Pre-indexing source-file content once instead of re-reading per changed file (perf — O(n×m) → O(n+m)). Not a correctness issue.
  • Side-effect (import "./x") and require() recognition. Would expand ADR scope.
  • stemOf collapsing on first dot. Documented design choice.

Risk / rollback

The new import-hint matcher is stricter — projects that relied on basename-only matching for tsconfig-aliased imports will lose those signals. The ADR amendment makes this explicit; the V0.2 invariant "prefer false negatives" justifies the trade-off. Single commit, clean git revert.

Three correctness fixes in `senseArchitecture` (V0.2 architecture sensing,
ADR 0005), all within the filesystem-only envelope:

- test-file: also check co-located `__tests__/` and the repo-root
  `tests/` / `__tests__/` directories. The previous `${dir}/tests/`-only
  rule produced zero test-file signals on Mira's own repo, where all
  tests live at top-level `tests/`.
- import-hint: switch from basename-only matching to deterministic
  POSIX path resolution against the importer's directory, with
  `.ts/.tsx` and `/index.ts(x)` suffix recovery. Eliminates the
  cross-directory basename-collision false positives
  (`src/utils/foo.ts` ↔ unrelated `src/auth/foo`).
- import-hint: skip bare specifiers (`from "react"`) and tsconfig-paths
  aliases (`from "@/x"`); fixes the false match on a changed file
  whose basename happens to collide with a package name.

ADR 0005 amended (V0.2.1) to record the tightened semantics.

7 new test cases added: 3 for the new test-file dirs, 4 for the
import-hint hardening (collision, bare specifier, index.ts
directory imports, tsconfig alias as documented false negative).
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