sitesmith: canvas summary serializer with unit tests

This commit is contained in:
2026-05-23 14:14:38 -07:00
parent bd15a33984
commit 14a957f57c
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { describe, test, expect } from 'vitest';
import { summarizeCanvas } from './canvas-summary';
const fixture = {
ROOT: { type: { resolvedName: 'Container' }, props: { aiName: 'Page Root', node_id: 'ai-root-1' }, nodes: ['n1','n2'], parent: null },
n1: { type: { resolvedName: 'Heading' }, props: { aiName: 'Hero Title', node_id: 'ai-hero-1', text: 'Welcome', level: 1, style: { color: '#fff' } }, nodes: [], parent: 'ROOT' },
n2: { type: { resolvedName: 'HtmlBlock' }, props: { aiName: 'Custom Embed', node_id: 'ai-html-1', code: '<div>opaque</div>' }, nodes: [], parent: 'ROOT' },
};
describe('summarizeCanvas', () => {
test('one line per node with id and aiName', () => {
const out = summarizeCanvas(fixture as any);
expect(out).toContain('Container id=ai-root-1');
expect(out).toContain('Heading id=ai-hero-1 name="Hero Title"');
});
test('excludes style props', () => {
expect(summarizeCanvas(fixture as any)).not.toContain('color=');
});
test('truncates to maxChars', () => {
const out = summarizeCanvas(fixture as any, 60);
expect(out.length).toBeLessThanOrEqual(60);
expect(out).toContain('truncated');
});
});