Files
nexu-io--open-design/apps/daemon/tests/run-html-version-snapshots.test.ts
wehub-resource-sync 070959e133
landing-page-staging / Deploy landing page to staging (push) Has been skipped
landing-page-ci / Validate landing page (push) Failing after 4s
visual-baseline / Capture visual baselines (push) Has been cancelled
bake-plugin-previews / Bake plugin previews (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:00:47 +08:00

46 lines
1.6 KiB
TypeScript

import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import {
snapshotAiHtmlVersionsForRun,
} from '../src/run-html-version-snapshots.js';
describe('AI HTML version snapshots', () => {
const roots: string[] = [];
afterEach(async () => {
await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })));
});
async function makeProject(): Promise<{ root: string; projectsRoot: string; projectId: string; projectRoot: string }> {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'od-html-version-snapshots-'));
roots.push(root);
const projectsRoot = path.join(root, 'projects');
const projectId = 'project-1';
const projectRoot = path.join(projectsRoot, projectId);
await fs.mkdir(projectRoot, { recursive: true });
return { root, projectsRoot, projectId, projectRoot };
}
it('throws an aggregate error when a touched HTML version cannot be persisted', async () => {
const { projectsRoot, projectId, projectRoot } = await makeProject();
const htmlPath = path.join(projectRoot, 'index.html');
await fs.writeFile(htmlPath, '<html><body>draft</body></html>');
await fs.writeFile(path.join(projectRoot, '.file-versions'), 'blocked');
await expect(snapshotAiHtmlVersionsForRun({
projectsRoot,
projectId,
projectRoot,
diff: { touchedPaths: [htmlPath] },
prompt: 'Make a page',
promptSource: 'message',
})).rejects.toMatchObject({
code: 'HTML_VERSION_SNAPSHOT_FAILED',
failures: [{ fileName: 'index.html' }],
});
});
});