first-commit
ci / Validate workspace (push) Has been cancelled
landing-page-ci / Validate landing page (push) Has been cancelled
landing-page-deploy / Deploy landing page (push) Has been cancelled
github-metrics / Generate repository metrics SVG (push) Has been cancelled
refresh-contributors-wall / Refresh contributors wall cache bust (push) Waiting to run
ci / Validate workspace (push) Has been cancelled
landing-page-ci / Validate landing page (push) Has been cancelled
landing-page-deploy / Deploy landing page (push) Has been cancelled
github-metrics / Generate repository metrics SVG (push) Has been cancelled
refresh-contributors-wall / Refresh contributors wall cache bust (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { inferLegacyManifest, validateArtifactManifestInput } from '../src/artifact-manifest.js';
|
||||
|
||||
function validBase() {
|
||||
return {
|
||||
kind: 'html',
|
||||
renderer: 'html',
|
||||
title: 'Test',
|
||||
exports: ['html'],
|
||||
};
|
||||
}
|
||||
|
||||
describe('validateArtifactManifestInput', () => {
|
||||
it('rejects empty exports', () => {
|
||||
const res = validateArtifactManifestInput({ ...validBase(), exports: [] }, 'index.html');
|
||||
expect(res.ok).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects invalid kind and renderer and export', () => {
|
||||
expect(
|
||||
validateArtifactManifestInput(
|
||||
{ ...validBase(), kind: 'evil-kind', renderer: 'html', exports: ['html'] },
|
||||
'index.html',
|
||||
).ok,
|
||||
).toBe(false);
|
||||
expect(
|
||||
validateArtifactManifestInput(
|
||||
{ ...validBase(), kind: 'html', renderer: 'evil-renderer', exports: ['html'] },
|
||||
'index.html',
|
||||
).ok,
|
||||
).toBe(false);
|
||||
expect(
|
||||
validateArtifactManifestInput(
|
||||
{ ...validBase(), kind: 'html', renderer: 'html', exports: ['exe'] },
|
||||
'index.html',
|
||||
).ok,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects traversal in supportingFiles', () => {
|
||||
const res = validateArtifactManifestInput(
|
||||
{ ...validBase(), supportingFiles: ['../secret.txt'] },
|
||||
'index.html',
|
||||
);
|
||||
expect(res.ok).toBe(false);
|
||||
});
|
||||
|
||||
it('defaults status to complete when missing', () => {
|
||||
const res = validateArtifactManifestInput(validBase(), 'index.html');
|
||||
expect(res.ok).toBe(true);
|
||||
if (res.ok) expect(res.value?.status).toBe('complete');
|
||||
});
|
||||
|
||||
it('preserves valid status values', () => {
|
||||
const res = validateArtifactManifestInput({ ...validBase(), status: 'streaming' }, 'index.html');
|
||||
expect(res.ok).toBe(true);
|
||||
if (res.ok) expect(res.value?.status).toBe('streaming');
|
||||
});
|
||||
});
|
||||
|
||||
describe('inferLegacyManifest', () => {
|
||||
it('infers markdown manifest for .md files', () => {
|
||||
const out = inferLegacyManifest('README.md');
|
||||
expect(out?.kind).toBe('markdown-document');
|
||||
expect(out?.renderer).toBe('markdown');
|
||||
expect(out?.status).toBe('complete');
|
||||
expect(out?.exports).toEqual(['md', 'html', 'pdf', 'zip']);
|
||||
});
|
||||
|
||||
it('infers svg manifest for .svg files', () => {
|
||||
const out = inferLegacyManifest('logo.svg');
|
||||
expect(out?.kind).toBe('svg');
|
||||
expect(out?.renderer).toBe('svg');
|
||||
expect(out?.status).toBe('complete');
|
||||
expect(out?.exports).toEqual(['svg', 'zip']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user