translation-prompt.expected.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. /** Runnable keyless snapshot for the assembled translation request and consumed response. */
  2. import { execFile } from 'node:child_process'
  3. import { access, mkdir, writeFile } from 'node:fs/promises'
  4. import { dirname, join, resolve } from 'node:path'
  5. import { promisify } from 'node:util'
  6. import { describe, expect, it } from 'vitest'
  7. const execFileAsync = promisify(execFile)
  8. const root = resolve(import.meta.dirname, '..')
  9. const expected = join(root, 'scripts/snapshots/translation-prompt-v4/request-response.expected.json')
  10. const refreshing = process.env.DSH_SNAPSHOT === 'record' || process.env.DSH_SNAPSHOT === 'refresh'
  11. describe('translation prompt runnable snapshot', () => {
  12. it('assembles the reviewed examples and consumes a recorded new-pair response', async () => {
  13. const { stdout, stderr } = await execFileAsync(process.execPath, [
  14. join(root, 'scripts/verify-translation-prompt.ts'),
  15. '--snapshot',
  16. ], { cwd: root, maxBuffer: 4 * 1024 * 1024 })
  17. expect(stderr).toBe('')
  18. expect(() => {
  19. JSON.parse(stdout)
  20. }).not.toThrow()
  21. if (refreshing) {
  22. await mkdir(dirname(expected), { recursive: true })
  23. await writeFile(expected, stdout)
  24. } else {
  25. await access(expected)
  26. }
  27. await expect(stdout).toMatchFileSnapshot(expected)
  28. })
  29. })