Download tests/gold_preview.test.mjs from htaf/distill-pipeline: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/htaf/distill-pipeline/resolve/main/tests/gold_preview.test.mjs
- Command line
-
hf download hf://htaf/distill-pipeline/tests/gold_preview.test.mjs
-
curl -L -o gold_preview.test.mjs https://huggingface.co/htaf/distill-pipeline/resolve/main/tests/gold_preview.test.mjs
2.3 kB
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | |
| import fs from 'fs/promises'; | |
| import path from 'path'; | |
| import os from 'os'; | |
| import { fileURLToPath } from 'url'; | |
| const __filename = fileURLToPath(import.meta.url); | |
| const __dirname = path.dirname(__filename); | |
| const PROJECT_ROOT = path.join(__dirname, '..'); | |
| const sampleGold = [ | |
| JSON.stringify({ | |
| question: 'What is the meaning of life?', | |
| sample: { answer: '42', raw: '42' }, | |
| context: [{ id: 'c1', content: 'ctx content' }], | |
| verifier: { ok: true, score: 0.9 }, | |
| reward: { score: 0.8 }, | |
| }), | |
| JSON.stringify({ | |
| question: 'Q1?', | |
| sample: { answer: 'a'.repeat(50) }, | |
| context: [{ id: 'c2', content: 'ctx content 2' }], | |
| }), | |
| ].join('\n'); | |
| describe('scripts/gold_preview.mjs', () => { | |
| let tmpFile; | |
| const origArgv = process.argv.slice(); | |
| beforeEach(async () => { | |
| const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'gold-prev-')); | |
| tmpFile = path.join(tmpDir, 'gold.jsonl'); | |
| await fs.writeFile(tmpFile, sampleGold, 'utf8'); | |
| }); | |
| afterEach(async () => { | |
| process.argv = origArgv.slice(); | |
| if (tmpFile) { | |
| await fs.rm(path.dirname(tmpFile), { recursive: true, force: true }).catch(() => {}); | |
| } | |
| }); | |
| it('respects --limit', async () => { | |
| process.argv = ['node', 'gold_preview.mjs', '--file', tmpFile, '--limit', '1']; | |
| const { capturePreview } = await import('../scripts/gold_preview.mjs'); | |
| const output = await capturePreview(); | |
| const lines = output.split('\n').filter(Boolean); | |
| expect(lines.some((l) => l.startsWith('#2'))).toBe(false); | |
| }); | |
| it('respects --max-answer truncation', async () => { | |
| process.argv = ['node', 'gold_preview.mjs', '--file', tmpFile, '--max-answer', '10']; | |
| const { capturePreview } = await import('../scripts/gold_preview.mjs'); | |
| const output = await capturePreview(); | |
| expect(output).toMatch(/A: a{10}… \[\+40 chars\]/); | |
| }); | |
| it('shows full when --full is set', async () => { | |
| process.argv = ['node', 'gold_preview.mjs', '--file', tmpFile, '--full', '--limit', '1']; | |
| const { capturePreview } = await import('../scripts/gold_preview.mjs'); | |
| const output = await capturePreview(); | |
| expect(output).toMatch(/A: 42/); | |
| expect(output).not.toMatch(/\[\+\d+ chars\]/); | |
| }); | |
| }); | |