|
| 1 | +/** |
| 2 | + * Does @jamjet/cloud actually work on the Bun runtime? |
| 3 | + * |
| 4 | + * Imports the BUILT bundle — what a user installs — rather than the sources, and |
| 5 | + * exercises real behaviour rather than only checking that the module loads. |
| 6 | + * |
| 7 | + * A plain script, not a test-runner file, on purpose. This job used to run |
| 8 | + * `vitest` under `--bun`; vitest drives its own module runner, and its |
| 9 | + * interop with Bun is a property of vitest, not of this SDK. A failure there |
| 10 | + * says nothing about whether the package works for a Bun user, which is the |
| 11 | + * only question this job exists to answer. |
| 12 | + * |
| 13 | + * Merely importing the bundle is itself a real check: `config.ts` builds its |
| 14 | + * zod schemas at module scope, so a broken ESM/CJS interop fails here. |
| 15 | + */ |
| 16 | +import assert from 'node:assert/strict' |
| 17 | + |
| 18 | +import { VERSION, redact, estimateCost, ConfigError, PolicyEvaluator } from '../dist/index.js' |
| 19 | + |
| 20 | +const checks: [string, () => void][] = [ |
| 21 | + ['VERSION is published', () => { |
| 22 | + assert.equal(typeof VERSION, 'string') |
| 23 | + assert.match(VERSION, /^\d+\.\d+\.\d+/) |
| 24 | + }], |
| 25 | + ['zod-backed config module loaded', () => { |
| 26 | + // ConfigError comes from config.ts, whose zod schemas are built at module |
| 27 | + // scope. If zod's named export did not resolve under Bun, the import above |
| 28 | + // has already thrown; this pins the symbol as well. |
| 29 | + assert.equal(typeof ConfigError, 'function') |
| 30 | + assert.ok(new ConfigError('x') instanceof Error) |
| 31 | + }], |
| 32 | + ['redaction behaves', () => { |
| 33 | + assert.equal(redact('contact alice@example.com please'), 'contact [EMAIL_ADDRESS] please') |
| 34 | + assert.equal(redact('call 555-123-4567'), 'call [PHONE_NUMBER]') |
| 35 | + }], |
| 36 | + ['cost estimation behaves', () => { |
| 37 | + const c = estimateCost('gpt-4o', 100, 50) |
| 38 | + assert.ok(Math.abs(c - 0.00075) < 1e-8, `expected ~0.00075, got ${c}`) |
| 39 | + }], |
| 40 | + ['classes construct', () => { |
| 41 | + assert.equal(typeof PolicyEvaluator, 'function') |
| 42 | + }], |
| 43 | +] |
| 44 | + |
| 45 | +let failed = 0 |
| 46 | +for (const [name, run] of checks) { |
| 47 | + try { |
| 48 | + run() |
| 49 | + console.log(`ok - ${name}`) |
| 50 | + } catch (err) { |
| 51 | + failed++ |
| 52 | + console.error(`not ok - ${name}`) |
| 53 | + console.error(err instanceof Error ? err.stack : String(err)) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +const bun = (globalThis as { Bun?: { version: string } }).Bun |
| 58 | +console.log(`\n${checks.length - failed}/${checks.length} passed on ${bun ? `Bun ${bun.version}` : process.version}`) |
| 59 | +if (failed > 0) process.exit(1) |
0 commit comments