0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { isMissingPackageImportError } from '../../src/util/packageImportErrors';
|
|
|
|
describe('isMissingPackageImportError', () => {
|
|
it('recognizes missing optional packages', () => {
|
|
const error = Object.assign(new Error('Cannot find package @googleapis/sheets'), {
|
|
code: 'ERR_MODULE_NOT_FOUND',
|
|
});
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(true);
|
|
});
|
|
|
|
it('recognizes CommonJS-style missing optional package errors', () => {
|
|
const error = Object.assign(new Error('Missing optional dependency @googleapis/sheets'), {
|
|
code: 'MODULE_NOT_FOUND',
|
|
});
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(true);
|
|
});
|
|
|
|
it('ignores import failures for unrelated packages', () => {
|
|
const error = new Error('Cannot find package @promptfoo/unrelated');
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(false);
|
|
});
|
|
|
|
it('preserves import-time runtime errors from present packages', () => {
|
|
const error = new Error('@googleapis/sheets failed during initialization');
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(false);
|
|
});
|
|
|
|
it('recognizes the optional package itself from a realistic ESM message', () => {
|
|
const error = Object.assign(
|
|
new Error(
|
|
"Cannot find package '@googleapis/sheets' imported from /app/dist/src/googleSheets.js",
|
|
),
|
|
{ code: 'ERR_MODULE_NOT_FOUND' },
|
|
);
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(true);
|
|
});
|
|
|
|
it('recognizes a subpath import of the optional package', () => {
|
|
const error = Object.assign(
|
|
new Error(
|
|
"Cannot find package '@googleapis/sheets/build/index' imported from /app/dist/src/googleSheets.js",
|
|
),
|
|
{ code: 'ERR_MODULE_NOT_FOUND' },
|
|
);
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(true);
|
|
});
|
|
|
|
it('does not misreport a missing transitive dependency as the optional package (ESM)', () => {
|
|
// The optional package is installed, but one of ITS dependencies is not.
|
|
// The package name appears only in the importer path, not as the failed
|
|
// specifier, so it must not be reported as the package itself being absent.
|
|
const error = Object.assign(
|
|
new Error(
|
|
"Cannot find package 'gaxios' imported from /app/node_modules/@googleapis/sheets/build/index.js",
|
|
),
|
|
{ code: 'ERR_MODULE_NOT_FOUND' },
|
|
);
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(false);
|
|
});
|
|
|
|
it('does not misreport a missing transitive dependency as the optional package (CommonJS)', () => {
|
|
const error = Object.assign(
|
|
new Error(
|
|
"Cannot find module 'gaxios'\nRequire stack:\n- /app/node_modules/@googleapis/sheets/build/index.js",
|
|
),
|
|
{ code: 'MODULE_NOT_FOUND' },
|
|
);
|
|
|
|
expect(isMissingPackageImportError(error, '@googleapis/sheets')).toBe(false);
|
|
});
|
|
});
|