Skip to content

Studio: make the mmproj fallback import resolvable under node's type stripping - #9181

Closed
danielhanchen wants to merge 1 commit into
mainfrom
fix-mmproj-fallback-node-resolution
Closed

danielhanchen wants to merge 1 commit into
mainfrom
fix-mmproj-fallback-node-resolution

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

npm test is red on main right now. tests/queued-model-capabilities.test.ts does not fail an assertion, it dies on module resolution, so the whole file's 4 tests never run.

Error [ERR_MODULE_NOT_FOUND]: Cannot find module
  '.../src/features/chat/utils/mmproj-fallback'
  imported from .../src/features/chat/utils/image-input-support.ts

The file it cannot find is there. The problem is the extension: image-input-support.ts imports ./mmproj-fallback with none, and Node's --experimental-strip-types does not do extension resolution, so it looks for a file called exactly mmproj-fallback and gives up.

That import has been extensionless for a while without anyone noticing, because nothing reached it from a Node test. It became reachable when getImageInputUnavailableReason was added to tests/queued-model-capabilities.test.ts's imports in #9173, which is why it surfaces only now.

Reproduced on a clean checkout of main at 077593612 with nothing else applied:

  • before: npm test reports ✖ tests/queued-model-capabilities.test.ts, and running that file alone gives the ERR_MODULE_NOT_FOUND above.
  • after: the same file reports tests 4, pass 4, fail 0.

The fix is the extension. There are already 46 imports under src/ carrying an explicit .ts for exactly this reason, so this follows what is there rather than introducing a new convention. The alternative, making the test import the module dynamically the way tests/delete-chat-files-preference.test.ts does, would work too but changes a test to accommodate a source file rather than the other way round.

No new test is needed here: tests/queued-model-capabilities.test.ts is itself the guard. It is red without this change and green with it, which is how I verified the fix rather than assuming it.

Found while resolving #9058 against main. It is not that PR's, so it is not being fixed inside it.

…stripping

tests/queued-model-capabilities.test.ts imports image-input-support.ts
directly, and that file imports ./mmproj-fallback without an extension. Node's
--experimental-strip-types does not do extension resolution, so the whole test
file dies with ERR_MODULE_NOT_FOUND rather than failing an assertion.

The import only became reachable from a node test when getImageInputUnavailableReason
was added to that test's imports, which is why it surfaced now. 46 imports under
src/ already carry an explicit .ts for the same reason.
@danielhanchen

Copy link
Copy Markdown
Member Author

Closing this one as subsumed, and I want to be clear that it is not a rejection on substance: your fix is correct and it is the fix that is landing.

Four of us arrived at this independently, and #9181, #9192, #9200 and #9220 all carry the same change, byte for byte:

-import { isTextOnlyMmprojFallback } from "./mmproj-fallback";
+import { isTextOnlyMmprojFallback } from "./mmproj-fallback.ts";

Your diagnosis was right too. I reproduced it on a clean origin/main before touching anything: node --experimental-strip-types does not guess extensions the way vite does, so tests/queued-model-capabilities.test.ts dies with ERR_MODULE_NOT_FOUND on src/features/chat/utils/mmproj-fallback.

The reason the vehicle is #9220 rather than this PR is only scope. main is red in five distinct ways, not one, and #9220 is the only branch that fixes all of them: this import, a stale grep-based assertion in test_tp_vision_regression.py that #9173 broke by renaming a variable, three separate failures in Repo tests (CPU), the Windows job (which is this same failure on another OS), and a heavy-thread browser smoke that was masked behind this very import failure. That last one is worth knowing: the Frontend build + bundle sanity job aborts at Unit tests, so fixing the import is what made the next failure visible at all. Your one-line fix is load-bearing for finding the rest.

One thing worth recording for the future, since it argues mildly against the fix we are both shipping. src/ contains 2319 extensionless relative imports against 55 with a .ts extension, and the test suite already has a sanctioned mechanism for this exact situation, registerBundlerResolver(), used by 61 of its 392 test files. So the extensionless style is the convention here and the .ts extension is the minority. #9189 fixes this by registering the resolver in the test instead, which is arguably the more idiomatic answer. I chose the one-line version for #9220 because it is the smaller blast radius while main is red, but that was a call about risk rather than correctness, and a fuller fix for the class is still worth doing later.

Thanks for catching it and for the clean reproduction. Please reopen if you think the scope argument is wrong.

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