Skip to content

Commit 6192bad

Browse files
committed
fix(coverage): alias @loopover/contract to source so patch coverage attributes correctly
@loopover/contract is consumed via its package specifier everywhere, which resolves through node_modules' exports map straight to compiled dist/*.js -- unlike packages/loopover-mcp/miner's RELATIVE ../lib/foo.js imports, which fall back to a sibling .ts when nothing exists at the .js path. A package-specifier resolution that already finds a real compiled file has no such fallback, so v8 instrumented dist/ (gitignored, invisible to Codecov) instead of packages/loopover-contract/src/**/*.ts. Confirmed live: #9530 reported 0% patch coverage on fully-tested contract source. Aliased both import specifiers straight to source. The /tools subpath alias has to be declared BEFORE the bare @loopover/contract entry: Vite's string-find alias matcher treats a plain string as matching both the exact specifier and anything starting with find + "/", first-match-wins in declaration order -- with the bare entry first it silently intercepted the /tools import too and rewrote it to a bogus path, breaking resolution outright. Found by reproducing the failure with a throwaway probe test before reordering, not assumed. Verified: a scoped coverage run against contract-registry.test.ts + the pilot tool tests now shows 100% statement/branch/function/line coverage on the contract package, where before the alias it was flat 0%.
1 parent d837d1a commit 6192bad

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

vitest.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ export default defineConfig({
1010
alias: {
1111
"cloudflare:email": new URL("./test/stubs/cloudflare-email.ts", import.meta.url).pathname,
1212
"cloudflare:workers": new URL("./test/stubs/cloudflare-workers.ts", import.meta.url).pathname,
13+
// @loopover/contract is consumed everywhere by its package specifier, which resolves through
14+
// node_modules via that package's own "exports" map -- straight to dist/*.js, since (unlike
15+
// packages/loopover-{mcp,miner}'s RELATIVE "../lib/foo.js" imports) there's no missing-file
16+
// fallback to a sibling .ts for a package-specifier resolution that already found a real
17+
// compiled file. Left unaliased, v8 coverage instruments and attributes every hit to the
18+
// gitignored dist/ output instead of packages/loopover-contract/src/**/*.ts -- exactly what
19+
// coverage.include below expects -- so Codecov sees 0% patch coverage on real, tested source
20+
// (confirmed live on #9530). Aliasing straight to source is what the mcp/miner packages get
21+
// for free from their relative-import resolution; this closes the same gap for a package
22+
// that's actually installed as a workspace dependency.
23+
//
24+
// "/tools" MUST be listed before the bare "@loopover/contract" entry: Vite's string-`find`
25+
// alias matcher treats a plain string as matching BOTH the exact specifier and anything
26+
// starting with `find + "/"`, first-match-wins in declaration order -- so with the bare entry
27+
// first, it silently intercepted "@loopover/contract/tools" too and rewrote it to a bogus
28+
// "<index.ts path>/tools" that resolved nowhere. Confirmed by reproducing the failure with a
29+
// throwaway probe test before reordering, not assumed from reading Vite's docs alone.
30+
"@loopover/contract/tools": new URL("./packages/loopover-contract/src/tools/index.ts", import.meta.url).pathname,
31+
"@loopover/contract": new URL("./packages/loopover-contract/src/index.ts", import.meta.url).pathname,
1332
},
1433
},
1534
test: {

0 commit comments

Comments
 (0)