Skip to content

fix(storage-reverse-image-search): stop native tfjs addon breaking tests in CI#1107

Closed
cabljac wants to merge 1 commit into
mainfrom
fix/storage-reverse-image-search-flaky-tests
Closed

fix(storage-reverse-image-search): stop native tfjs addon breaking tests in CI#1107
cabljac wants to merge 1 commit into
mainfrom
fix/storage-reverse-image-search-flaky-tests

Conversation

@cabljac

@cabljac cabljac commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #355.

Problem

storage-reverse-image-search:test fails intermittently in CI with:

The Node.js native addon module (tfjs_binding.node) can not be found ...

Suites fail to load (not fail assertions), which bails the lerna test run. Same class of bug as firestore-semantic-search.

Root cause

  1. Most suites transitively import src/common/feature_vectors.ts, which does import * as tf from '@tensorflow/tfjs-node'.
  2. @tensorflow/tfjs-node loads a platform-specific native addon at import time.
  3. CI installs with npm ci --ignore-scripts, so tfjs-node's postinstall that downloads the addon never runs. The addon is absent.
  4. Whether a run passed depended on whatever node_modules was restored from the Lerna cache, so it passed/failed at random - and only in CI.

Fix - split unit and integration tests

  • Unit run (default test script): maps @tensorflow/tfjs-node to a lightweight stub via moduleNameMapper. The many suites that mock feature_vectors or never invoke it stop crashing at import time.
  • Integration run (npm run test:integration via jest.integration.config.js): the two specs that genuinely exercise TensorFlow - feature_vectors.test.ts and feature_vectors.memory.test.ts, which load a real model over the network and assert on real tensors/memory - move here. They need the native addon built and network access, so they do not belong in the --ignore-scripts CI job. They are preserved, not deleted.

The stub lives outside a __mocks__ directory on purpose: manual mocks for node_modules packages are auto-applied by jest and cannot be disabled per-config, which would also break the integration run. Wiring it through moduleNameMapper keeps it scoped to the unit config.

Verification

Reproduced the CI failure locally by removing the native addon: 10 suites failed to load. With the fix applied and the addon still absent, the unit run (against the Firestore emulator) is green: 15 suites pass, 0 failures. The integration config resolves the real tfjs package.

Companion to the same fix for firestore-semantic-search (#1106).

…sts in CI

Test suites failed to run in CI with 'tfjs_binding.node can not be found'.
Same root cause as firestore-semantic-search: suites transitively import
feature_vectors.ts, which imports @tensorflow/tfjs-node, and that package loads
a platform-specific native addon at import time. CI installs dependencies with
'npm ci --ignore-scripts', so tfjs-node's postinstall never downloads the addon,
so any suite touching feature_vectors fails to load. Whether a run passed
depended on stale cached node_modules, making it flaky and CI-only.

Split unit and integration tests:
- Unit run (default 'test' script) maps @tensorflow/tfjs-node to a lightweight
  stub via moduleNameMapper, so the many suites that only mock or never invoke
  feature_vectors stop crashing at import time.
- The two specs that genuinely exercise TensorFlow (feature_vectors.test.ts and
  feature_vectors.memory.test.ts load a real model over the network and assert
  on real tensors) move to jest.integration.config.js, run via
  'npm run test:integration'. They need the native addon built and network
  access, so they do not belong in the --ignore-scripts CI job.

The stub lives outside a __mocks__ directory on purpose: manual mocks for
node_modules packages are auto-applied by jest and cannot be disabled per
config, which would also break the integration run. Wiring it through
moduleNameMapper keeps it scoped to the unit config.

Verified with the native addon removed and the emulator running: the unit run
previously had 10 suites fail to load; it now runs 15 suites green with 0
failures. The integration config resolves the real tfjs package.

Fixes #355.
@cabljac

cabljac commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Consolidating both tfjs test fixes into #1106. The two extensions must be fixed on the same branch for CI to pass (lerna nx-bail stops at the first failing extension), so this change is folded into that PR. #355 tracked there.

@cabljac cabljac closed this Jul 2, 2026
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.

[storage-reverse-image-search]: Fix flaky tests

1 participant