Files
promptfoo--promptfoo/test/runtimeCompatibility.test.ts
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

96 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
getRuntimeCompatibilityNotice,
getRuntimeNoticeReminderIntervalMs,
isLatestUpdateBlockedByRuntime,
isUpdateBlockedByRuntime,
parseNodeMajor,
shouldShowRuntimeNotice,
} from '../src/runtimeCompatibility';
const DAY_MS = 24 * 60 * 60 * 1000;
describe('runtime compatibility policy', () => {
it('detects Node.js 20 and returns the dated compatibility notice', () => {
expect(
getRuntimeCompatibilityNotice('v20.20.2', {
isBun: false,
isDeno: false,
}),
).toEqual(
expect.objectContaining({
id: 'node20-removal-2026-07-30',
currentVersion: 'v20.20.2',
currentMajor: 20,
removalDate: '2026-07-30',
minimumVersion: '22.22.0',
recommendedVersion: '24 LTS',
}),
);
});
it('does not return a Node.js notice for supported newer or alternative runtimes', () => {
expect(getRuntimeCompatibilityNotice('v22.22.0', { isBun: false, isDeno: false })).toBeNull();
expect(getRuntimeCompatibilityNotice('v24.1.0', { isBun: false, isDeno: false })).toBeNull();
expect(getRuntimeCompatibilityNotice('v20.20.2', { isBun: true, isDeno: false })).toBeNull();
expect(getRuntimeCompatibilityNotice('v20.20.2', { isBun: false, isDeno: true })).toBeNull();
});
it('parses Node.js major versions without accepting unrelated strings', () => {
expect(parseNodeMajor('v20.20.2')).toBe(20);
expect(parseNodeMajor('24.0.0')).toBe(24);
expect(parseNodeMajor('node-20.20.2')).toBeNull();
});
it('blocks latest-version advice for Node.js 20 at the support cutoff', () => {
expect(isLatestUpdateBlockedByRuntime('v20.20.2', new Date('2026-07-29T23:59:59.999Z'))).toBe(
false,
);
expect(isLatestUpdateBlockedByRuntime('v20.20.2', new Date('2026-07-30T00:00:00.000Z'))).toBe(
true,
);
expect(isLatestUpdateBlockedByRuntime('v24.0.0', new Date('2026-08-01T00:00:00.000Z'))).toBe(
false,
);
});
it('keeps only official Docker image updates available after the host runtime cutoff', () => {
const cutoff = new Date('2026-07-30T00:00:00.000Z');
expect(isUpdateBlockedByRuntime('docker', 'v20.20.2', cutoff)).toBe(false);
expect(isUpdateBlockedByRuntime('npm', 'v20.20.2', cutoff)).toBe(true);
expect(isUpdateBlockedByRuntime('npx', 'v20.20.2', cutoff)).toBe(true);
});
it('reminds weekly before the final phase and daily starting exactly 14 days before cutoff', () => {
expect(getRuntimeNoticeReminderIntervalMs(new Date('2026-07-01T00:00:00.000Z'))).toBe(
7 * DAY_MS,
);
expect(getRuntimeNoticeReminderIntervalMs(new Date('2026-07-15T23:59:59.999Z'))).toBe(
7 * DAY_MS,
);
expect(getRuntimeNoticeReminderIntervalMs(new Date('2026-07-16T00:00:00.000Z'))).toBe(DAY_MS);
expect(getRuntimeNoticeReminderIntervalMs(new Date('2026-08-01T00:00:00.000Z'))).toBe(DAY_MS);
});
it('shows again at the active cadence boundary and fails open for malformed or future state', () => {
const weeklyBoundary = new Date('2026-07-02T00:00:00.000Z');
expect(
shouldShowRuntimeNotice('2026-06-25T00:00:00.000Z', new Date(weeklyBoundary.getTime() - 1)),
).toBe(false);
expect(shouldShowRuntimeNotice('2026-06-25T00:00:00.000Z', weeklyBoundary)).toBe(true);
expect(shouldShowRuntimeNotice('invalid', weeklyBoundary)).toBe(true);
expect(shouldShowRuntimeNotice('2026-08-01T00:00:00.000Z', weeklyBoundary)).toBe(true);
});
it('lets the daily final-phase cadence shorten an in-flight weekly snooze', () => {
expect(
shouldShowRuntimeNotice('2026-07-13T00:00:00.000Z', new Date('2026-07-15T23:59:59.999Z')),
).toBe(false);
expect(
shouldShowRuntimeNotice('2026-07-13T00:00:00.000Z', new Date('2026-07-16T00:00:00.000Z')),
).toBe(true);
});
});