/**
 * SET 27 — "Download prompt" helper: verbatim bytes, no reformatting.
 */
import { describe, expect, it } from 'vitest';
import { buildPromptBlob, buildPromptMdFilename } from '../web/src/downloadPrompt';

describe('downloadPromptMd helper', () => {
  it('filenames as prompt-<runId>.md', () => {
    expect(buildPromptMdFilename('abc123')).toBe('prompt-abc123.md');
    expect(buildPromptMdFilename('')).toBe('prompt-unknown.md');
    expect(buildPromptMdFilename(null)).toBe('prompt-unknown.md');
    expect(buildPromptMdFilename(undefined)).toBe('prompt-unknown.md');
  });

  it('blob content byte-equals the stored prompt — no reformatting, no metadata', async () => {
    const prompt = 'Build a URL shortener.\r\n\r\n- collision-free codes\n  - trailing spaces   \n\nEdge case: empty input.';
    const blob = buildPromptBlob(prompt);
    const text = await blob.text();
    expect(text).toBe(prompt);
    expect(blob.size).toBe(new TextEncoder().encode(prompt).length);
  });

  it('empty prompt produces an empty (but valid) blob', async () => {
    const blob = buildPromptBlob('');
    expect(blob.size).toBe(0);
    expect(await blob.text()).toBe('');
  });
});
