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
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import { spawnSync } from 'child_process';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
|
|
const CLI_PATH = path.resolve(__dirname, '../../dist/src/main.js');
|
|
const ROOT_DIR = path.resolve(__dirname, '../..');
|
|
const CONFIG_PATH = path.resolve(__dirname, 'fixtures/configs/not-script-assertions.yaml');
|
|
const OUTPUT_DIR = path.resolve(__dirname, '.temp-output-not-script-assertions');
|
|
|
|
function runCli(args: string[]): { stdout: string; stderr: string; exitCode: number } {
|
|
const result = spawnSync('node', [CLI_PATH, ...args], {
|
|
cwd: ROOT_DIR,
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, NO_COLOR: '1' },
|
|
timeout: 60000,
|
|
});
|
|
|
|
return {
|
|
stdout: result.stdout || '',
|
|
stderr: result.stderr || '',
|
|
exitCode: result.status ?? 1,
|
|
};
|
|
}
|
|
|
|
function expectComponentResult(
|
|
result: {
|
|
success: boolean;
|
|
score: number;
|
|
gradingResult: {
|
|
componentResults: Array<{
|
|
pass: boolean;
|
|
score: number;
|
|
reason: string;
|
|
}>;
|
|
};
|
|
},
|
|
expectedScore: number,
|
|
) {
|
|
expect(result.success).toBe(true);
|
|
expect(result.score).toBeCloseTo(expectedScore, 4);
|
|
expect(result.gradingResult.componentResults).toHaveLength(1);
|
|
expect(result.gradingResult.componentResults[0]).toMatchObject({
|
|
pass: true,
|
|
score: expectedScore,
|
|
reason: 'Assertion passed',
|
|
});
|
|
}
|
|
|
|
describe('Negated script assertion smoke tests', () => {
|
|
beforeAll(() => {
|
|
if (!fs.existsSync(CLI_PATH)) {
|
|
throw new Error(`Built CLI not found at ${CLI_PATH}. Run 'npm run build' first.`);
|
|
}
|
|
|
|
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
|
});
|
|
|
|
afterAll(() => {
|
|
fs.rmSync(OUTPUT_DIR, { recursive: true, force: true });
|
|
});
|
|
|
|
it('inverts not-javascript, not-python, and not-ruby assertions through the built CLI', () => {
|
|
const outputPath = path.join(OUTPUT_DIR, 'not-script-assertions-output.json');
|
|
|
|
const { exitCode, stderr } = runCli([
|
|
'eval',
|
|
'-c',
|
|
CONFIG_PATH,
|
|
'-o',
|
|
outputPath,
|
|
'--no-cache',
|
|
]);
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(stderr.toLowerCase()).not.toMatch(/\b(error|failed)\b/);
|
|
|
|
const parsed = JSON.parse(fs.readFileSync(outputPath, 'utf-8'));
|
|
const results = parsed.results.results;
|
|
|
|
expect(results).toHaveLength(5);
|
|
[1, 0.25, 0.25, 0.4, 0.4].forEach((expectedScore, index) => {
|
|
expectComponentResult(results[index], expectedScore);
|
|
});
|
|
});
|
|
});
|