From 2f46e5cb93634773a1050b41cf2f2138820acdb4 Mon Sep 17 00:00:00 2001 From: AlexanderLevenskikh Date: Sun, 22 Nov 2026 19:38:43 +0500 Subject: [PATCH 1/2] test(core): reproduce false verified root conditional exports from pinned packages Source-backed TanStack Form and React Hook Form published dist-only exports must not silently become verified src/index.ts edges; explicit blocked import and type-only cases stay unknown. Preserve source-exact positive cases. Test-only RED before any resolver changes. --- tests/p2-conditional-root-exports.test.mjs | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/p2-conditional-root-exports.test.mjs diff --git a/tests/p2-conditional-root-exports.test.mjs b/tests/p2-conditional-root-exports.test.mjs new file mode 100644 index 0000000..39be4b0 --- /dev/null +++ b/tests/p2-conditional-root-exports.test.mjs @@ -0,0 +1,76 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import {buildGraph} from '../dist/packages/core/src/index.js'; + +// Source-grounded: TanStack Form react-form package@5de1a8de01e3d63a0e5225a7e659a384f3a0effb +// declares "." as import:{types:"./dist/esm/index.d.ts",default:"./dist/esm/index.js"} +// and require:{types:"./dist/cjs/index.d.cts",default:"./dist/cjs/index.cjs"}. +// There is a local src/index.ts but no proven dist->src equivalence. +// React Hook Form@8d7bd6c... likewise exports dist-only public entry points. +// Resolver must NOT fabricate a verified root import via ./src/index.ts fallback. +const consumer='apps/site/src/main.tsx'; +const target='packages/react-form/src/index.ts'; +function scenario(t,manifest){ + const root=fs.mkdtempSync(path.join(os.tmpdir(),'br-p2-conditional-')); + t.after(()=>fs.rmSync(root,{recursive:true,force:true,maxRetries:5,retryDelay:100})); + const files=new Map([ + ['package.json',JSON.stringify({private:true,workspaces:['packages/*']})], + ['packages/react-form/package.json',JSON.stringify({name:'@tanstack/react-form',...manifest})], + [target,"export const useForm=()=>({valid:true});"], + [consumer,"import {useForm} from '@tanstack/react-form'; export const value=useForm();"] + ]); + return buildGraph({root,files}); +} +const edge=g=>g.edges.some(e=>e.sourceFile===consumer&&e.to==='export:'+target+'#useForm'&& + ['references','renders','type_references'].includes(e.kind)&&e.certainty==='verified'); + +test('real TanStack Form dist-only conditional exports never prove local source equivalence',t=>{ + const g=scenario(t,{ + module:'./dist/esm/index.js',main:'./dist/cjs/index.cjs',types:'./dist/esm/index.d.ts', + exports:{'.':{ + import:{types:'./dist/esm/index.d.ts',default:'./dist/esm/index.js'}, + require:{types:'./dist/cjs/index.d.cts',default:'./dist/cjs/index.cjs'} + }} + }); + assert.equal(edge(g),false,'unproven dist->src mapping must remain UNKNOWN, not a verified static edge'); + assert.ok(g.diagnostics.some(d=>d.code==='MODULE_RESOLUTION_FAILED'),'source mapping unavailable must be diagnosed'); +}); + +test('real React Hook Form dist-only exports must not fall through to local source barrel',t=>{ + const g=scenario(t,{ + main:'./dist/index.cjs.js',module:'./dist/index.esm.mjs',types:'./dist/index.d.ts', + exports:{'.':{types:'./dist/index.d.ts','react-server':'./dist/react-server.esm.mjs', + import:'./dist/index.esm.mjs',require:'./dist/index.cjs.js'}} + }); + assert.equal(edge(g),false); + assert.ok(g.diagnostics.some(d=>d.code==='MODULE_RESOLUTION_FAILED')); +}); + +test('negative: import:null condition blocks verified fallback to default source',t=>{ + const g=scenario(t,{ + exports:{'.':{import:null,default:'./src/index.ts'}} + }); + assert.equal(edge(g),false,'explicit blocked import condition must not choose default'); + assert.ok(g.diagnostics.some(d=>d.code==='MODULE_RESOLUTION_FAILED')); +}); + +test('negative: type-only export does not authorize a runtime import edge',t=>{ + const g=scenario(t,{ + exports:{'.':{types:'./src/index.ts',import:null}} + }); + assert.equal(edge(g),false); + assert.ok(g.diagnostics.some(d=>d.code==='MODULE_RESOLUTION_FAILED')); +}); + +test('positive: explicit root import condition pointing to exact existing source remains proven',t=>{ + const g=scenario(t,{exports:{'.':{import:{default:'./src/index.ts'}}}}); + assert.equal(edge(g),true); +}); + +test('positive: legacy package with no exports map retains old source main fallback',t=>{ + const g=scenario(t,{main:'./src/index.ts'}); + assert.equal(edge(g),true); +}); From 0977294c78018ecdd57b61c9731729c4a098c2c0 Mon Sep 17 00:00:00 2001 From: AlexanderLevenskikh Date: Sun, 22 Nov 2026 19:41:52 +0500 Subject: [PATCH 2/2] fix(core): reject unproven dist-only root conditional exports Preserve original four red source-backed regressions plus positive/negative controls. Explicit export roots and subpaths are authoritative; no dist-to-src fallback, blocked import/null stays UNKNOWN, type-only not runtime. Bump graph cache version; no holdout or release edits. --- docs/evidence/P2_CONDITIONAL_EXPORTS.md | 11 +++++++ packages/core/src/graph.ts | 43 ++++++++++++++++--------- packages/core/src/types.ts | 2 +- 3 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 docs/evidence/P2_CONDITIONAL_EXPORTS.md diff --git a/docs/evidence/P2_CONDITIONAL_EXPORTS.md b/docs/evidence/P2_CONDITIONAL_EXPORTS.md new file mode 100644 index 0000000..fc48c8e --- /dev/null +++ b/docs/evidence/P2_CONDITIONAL_EXPORTS.md @@ -0,0 +1,11 @@ +# P2 — conditional package root exports: source-proven or UNKNOWN + +Upstream evidence (existing previously exposed corpus; P7 remains untouched): +- TanStack Form exact source SHA 5de1a8de01e3d63a0e5225a7e659a384f3a0effb; packages/react-form/package.json exports root dist/esm and dist/cjs, not source index. +- React Hook Form exact source SHA 8d7bd6c2c774fd9b4310e8cbc07d36ce1cacf736; package.json exports dist-only root import/require/type targets. + +Pre-fix source-reduced test-only PR #21 SHA 2f46e5cb93634773a1050b41cf2f2138820acdb4 reproduced four distinct FAIL in [original Ubuntu Node22 push job](https://github.com/levencode-labs/blastradius/actions/runs/45033942120) 137243402333: TanStack Form dist-only root, React Hook Form dist-only root, import:null versus default, and types-only source pretending to be runtime. Of 174 tests, 170 PASS, 4 FAIL. Two source-exact/legacy positive controls passed. Original CI logs preserved. + +Bounded fix: explicit exports map is authoritative for root and subpath; require source-exact import/default runtime branch. Explicit import:null blocks fallback; types alone cannot prove runtime binding. The legacy root source index fallback is kept only if there is no exports map. Never guess dist-to-src or package condition environments; unsupported type-only/runtime distinctions remain UNKNOWN. Cache engine model version advanced; npm 0.0.1-dev remains private. + +Acceptance requires all eight original OS/Node 22/24 CI cells, tarball byte parity, original nine independent pinned source TypeChecker/Knip, and actual merge SHA. No release/tag/publish/auto-delete. diff --git a/packages/core/src/graph.ts b/packages/core/src/graph.ts index f23ac84..178cd69 100644 --- a/packages/core/src/graph.ts +++ b/packages/core/src/graph.ts @@ -83,25 +83,36 @@ export function buildGraph({root,files,config={},reuseFacts,saveFacts,extraDiagn const name=[...workspacePackages.keys()].sort((a,b)=>b.length-a.length).find(n=>specifier===n||specifier.startsWith(n+'/')); if(name){ const pkg=workspacePackages.get(name)!;const sub=specifier===name?'.':'./'+specifier.slice(name.length+1); - const exports=pkg.manifest.exports;let entry:unknown; + const exports=pkg.manifest.exports,hasExportMap=exports!==undefined; + let entry:unknown; if(sub==='.'&&typeof exports==='string')entry=exports; - else if(exports&&typeof exports==='object')entry=(exports as Record)[sub]; - const prefer=(e:unknown):string|undefined=>typeof e==='string'?e:e&&typeof e==='object'?(prefer((e as Record).import)||prefer((e as Record).default)||prefer((e as Record).types)):undefined; - // An explicit package "exports" map is authoritative for subpaths. - // Never turn an unlisted/blocked private import into a *verified* - // edge just because ./src/private.ts or ./private.ts exists in the - // workspace (TanStack Table). Do not guess dist->src equivalence. - const hasExportMap=exports!==undefined; - const rejectedSubpath=sub!=='.'&&hasExportMap&&(entry===undefined||entry===null); - if(rejectedSubpath){ - diag('MODULE_RESOLUTION_FAILED',source,1,1,'Workspace package subpath lacks a proven supported export: '+specifier); + else if(exports&&typeof exports==='object'&&!Array.isArray(exports)){ + const map=exports as Record; + if(Object.prototype.hasOwnProperty.call(map,sub))entry=map[sub]; + // A root-only conditional export map is also legal. + else if(sub==='.'&&Object.keys(map).every(k=>!k.startsWith('.')))entry=map; + } + // Import/default runtime conditions alone can authorize a verified + // source mapping. A present null import condition is a hard block. + // Declaration-only types never prove a runtime import. + const prefer=(e:unknown):string|undefined=>{ + if(typeof e==='string')return e; + if(!e||typeof e!=='object'||Array.isArray(e))return undefined; + const c=e as Record; + if(Object.prototype.hasOwnProperty.call(c,'import'))return prefer(c.import); + if(Object.prototype.hasOwnProperty.call(c,'default'))return prefer(c.default); + return undefined; + }; + // Explicit package exports are authoritative for root and subpaths. + // Never infer dist-to-src, nor fall back from blocked paths. + const blocked=hasExportMap&&(entry===undefined||entry===null||!prefer(entry)); + if(blocked){ + diag('MODULE_RESOLUTION_FAILED',source,1,1,'Workspace package has no proven runtime source export: '+specifier); }else{ - // Legacy deep-source fallback is allowed only when the package has - // no explicit export map. An explicitly exported source subpath - // still resolves when its exact exported target is in the snapshot. - const fallback=sub==='.' + // Legacy source fallback exists only without an explicit exports map. + const fallback=hasExportMap?[]:sub==='.' ?[pkg.manifest.module,pkg.manifest.main,pkg.manifest.types,'./src/index.ts','./index.ts'] - :hasExportMap?[]:[sub]; + :[sub]; const candidates=[prefer(entry),...fallback].filter((x):x is string=>typeof x==='string'); for(const candidate of candidates){const base=path.posix.normalize(path.posix.join(pkg.dir,candidate)); const possibilities=[base,base+'.ts',base+'.tsx',base+'.js',base+'.jsx',base+'/index.ts',base+'/index.tsx']; diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index c45b672..a42018f 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1,4 +1,4 @@ -export const ENGINE_VERSION = '0.0.12-dev'; +export const ENGINE_VERSION = '0.0.13-dev'; export type NodeKind = 'FILE' | 'MODULE_EVAL' | 'SYMBOL' | 'EXPORT_BINDING' | 'ROUTE' | 'TEST_ENTRY' | 'STORY_ENTRY' | 'PACKAGE_API' | 'UNKNOWN_ENTRY' | 'EXTERNAL'; export type RootKind = 'production' | 'test' | 'story' | 'publicApi'; export type EdgeKind = 'imports' | 'references' | 'calls' | 'renders' | 'reexports' | 'type_references' | 'dynamic_import' | 'side_effect_import' | 'prop_access' | 'prop_pass' | 'route_entry' | 'test_dependency' | 'public_export' | 'possible_dynamic';