open-design/apps/web/tests/artifacts/manifest.test.ts
marco 5dd70b5016
Some checks failed
ci / Validate workspace (push) Successful in 12m32s
landing-page-ci / Validate landing page (push) Successful in 9m41s
landing-page-deploy / Deploy landing page (push) Failing after 5m23s
github-metrics / Generate repository metrics SVG (push) Failing after 2m3s
refresh-contributors-wall / Refresh contributors wall cache bust (push) Failing after 11s
Initial import: open-design source for helix-mind.ai distribution
This repository contains the open-design daemon CLI source code, built
and packaged at https://helix-mind.ai/cli/open-design/latest.tgz for use
by the HelixMind /design slash command.

Licenses: Apache-2.0 (root) + MIT (skills/*)
2026-05-06 20:50:24 +02:00

121 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
artifactManifestNameFor,
createHtmlArtifactManifest,
inferLegacyManifest,
parseArtifactManifest,
} from '../../src/artifacts/manifest';
describe('parseArtifactManifest', () => {
it('returns null for malformed json', () => {
expect(parseArtifactManifest('{"version":1')).toBeNull();
});
it('returns null when required fields are missing', () => {
expect(parseArtifactManifest(JSON.stringify({ version: 1, kind: 'html' }))).toBeNull();
});
it('returns null for wrong version', () => {
const raw = JSON.stringify({
version: 2,
kind: 'html',
title: 'x',
entry: 'index.html',
renderer: 'html',
exports: ['html'],
});
expect(parseArtifactManifest(raw)).toBeNull();
});
it('defaults status to complete when missing', () => {
const raw = JSON.stringify({
version: 1,
kind: 'html',
title: 'x',
entry: 'index.html',
renderer: 'html',
exports: ['html'],
});
const out = parseArtifactManifest(raw);
expect(out?.status).toBe('complete');
});
it('preserves valid status when provided', () => {
const raw = JSON.stringify({
version: 1,
kind: 'html',
title: 'x',
entry: 'index.html',
renderer: 'html',
status: 'streaming',
exports: ['html'],
});
const out = parseArtifactManifest(raw);
expect(out?.status).toBe('streaming');
});
});
describe('inferLegacyManifest', () => {
it('infers markdown manifests for .md files', () => {
const out = inferLegacyManifest({ entry: 'README.md' });
expect(out?.kind).toBe('markdown-document');
expect(out?.renderer).toBe('markdown');
expect(out?.status).toBe('complete');
});
it('infers svg manifests for .svg files', () => {
const out = inferLegacyManifest({ entry: 'logo.svg' });
expect(out?.kind).toBe('svg');
expect(out?.renderer).toBe('svg');
expect(out?.status).toBe('complete');
});
it('returns null for non-artifact file types', () => {
expect(inferLegacyManifest({ entry: 'photo.png' })).toBeNull();
expect(inferLegacyManifest({ entry: 'archive.bin' })).toBeNull();
});
it('infers React component artifacts from JSX and TSX entries', () => {
expect(inferLegacyManifest({ entry: 'Card.jsx' })).toMatchObject({
kind: 'react-component',
renderer: 'react-component',
exports: ['jsx', 'html', 'zip'],
});
expect(inferLegacyManifest({ entry: 'Card.tsx' })).toMatchObject({
kind: 'react-component',
renderer: 'react-component',
exports: ['jsx', 'html', 'zip'],
});
});
});
describe('artifactManifestNameFor', () => {
it('handles names without extension', () => {
expect(artifactManifestNameFor('README')).toBe('README.artifact.json');
});
it('handles names with multiple dots', () => {
expect(artifactManifestNameFor('page.v2.final.html')).toBe('page.v2.final.html.artifact.json');
});
it('avoids collisions between different extensions', () => {
expect(artifactManifestNameFor('foo.html')).not.toBe(artifactManifestNameFor('foo.md'));
});
});
describe('createHtmlArtifactManifest', () => {
it('creates expected default html manifest shape', () => {
const out = createHtmlArtifactManifest({ entry: 'index.html', title: 'Landing' });
expect(out.version).toBe(1);
expect(out.kind).toBe('html');
expect(out.renderer).toBe('html');
expect(out.status).toBe('complete');
expect(out.exports).toEqual(['html', 'pdf', 'zip']);
expect(out.entry).toBe('index.html');
expect(out.title).toBe('Landing');
expect(typeof out.createdAt).toBe('string');
expect(typeof out.updatedAt).toBe('string');
});
});