|
| 1 | +// Seed contract for the Home example-prompt cards and the plugin detail |
| 2 | +// modal's "Replicate this content" action (issue: the composer was seeded with |
| 3 | +// the en query's leading paragraph, which for many example plugins is a |
| 4 | +// generator-facing build spec — stack/file-layout instructions, raw HTML, or a |
| 5 | +// dangling "as described below" — instead of the curated natural-language |
| 6 | +// description). |
| 7 | + |
| 8 | +import { describe, expect, it } from 'vitest'; |
| 9 | +import type { InstalledPluginRecord } from '@open-design/contracts'; |
| 10 | +import { examplePresetSeedPrompt } from '../../src/components/plugins-home/presetSeedPrompt'; |
| 11 | + |
| 12 | +function fixture(overrides: { |
| 13 | + id: string; |
| 14 | + description?: string; |
| 15 | + query?: string | Record<string, string>; |
| 16 | + inputs?: Array<Record<string, unknown>>; |
| 17 | +}): InstalledPluginRecord { |
| 18 | + return { |
| 19 | + id: overrides.id, |
| 20 | + title: overrides.id, |
| 21 | + version: '0.1.0', |
| 22 | + sourceKind: 'bundled', |
| 23 | + source: '/tmp', |
| 24 | + trust: 'bundled', |
| 25 | + capabilitiesGranted: ['prompt:inject'], |
| 26 | + manifest: { |
| 27 | + name: overrides.id, |
| 28 | + version: '0.1.0', |
| 29 | + ...(overrides.description ? { description: overrides.description } : {}), |
| 30 | + od: { |
| 31 | + ...(overrides.query ? { useCase: { query: overrides.query } } : {}), |
| 32 | + ...(overrides.inputs ? { inputs: overrides.inputs } : {}), |
| 33 | + }, |
| 34 | + }, |
| 35 | + fsPath: '/tmp', |
| 36 | + installedAt: 0, |
| 37 | + updatedAt: 0, |
| 38 | + } as InstalledPluginRecord; |
| 39 | +} |
| 40 | + |
| 41 | +const fallback = () => 'fallback seed'; |
| 42 | + |
| 43 | +describe('examplePresetSeedPrompt', () => { |
| 44 | + it('prefers the curated description over a generator-facing build-spec query head (en)', () => { |
| 45 | + const record = fixture({ |
| 46 | + id: 'dreamcore-landing', |
| 47 | + description: |
| 48 | + 'Immersive single-page parallax landing: a sticky viewport zooms a portal image toward you on scroll.', |
| 49 | + query: { |
| 50 | + en: 'Build a single-page immersive parallax landing page in React + TypeScript + Tailwind CSS using Vite. Everything lives in a single `src/App.tsx` file.\n\nScene one: ...', |
| 51 | + }, |
| 52 | + }); |
| 53 | + const seed = examplePresetSeedPrompt(record, 'en', fallback); |
| 54 | + expect(seed.text).toBe(record.manifest.description); |
| 55 | + expect(seed.fromRenderedQuery).toBe(false); |
| 56 | + }); |
| 57 | + |
| 58 | + it('prefers the curated description over a raw-HTML query head (en)', () => { |
| 59 | + const record = fixture({ |
| 60 | + id: 'aerocore', |
| 61 | + description: 'Premium scroll-cinematic aerospace propulsion marketing site.', |
| 62 | + query: { |
| 63 | + en: '<!doctype html>\n<html lang="en">\n<head>\n<meta charset="UTF-8" />\n</head>\n\n<body>...</body>', |
| 64 | + }, |
| 65 | + }); |
| 66 | + const seed = examplePresetSeedPrompt(record, 'en', fallback); |
| 67 | + expect(seed.text).toBe(record.manifest.description); |
| 68 | + expect(seed.fromRenderedQuery).toBe(false); |
| 69 | + }); |
| 70 | + |
| 71 | + it('prefers the curated description over a query head that dangles "as described below" (en)', () => { |
| 72 | + const record = fixture({ |
| 73 | + id: 'orbis-nft', |
| 74 | + description: 'Dark space-themed NFT collection landing page with a liquid-glass UI.', |
| 75 | + query: { |
| 76 | + en: 'Create an NFT landing page called "Orbis.Nft" with 4 sections. Recreate it exactly as described below.\n\n## Sections\n...', |
| 77 | + }, |
| 78 | + }); |
| 79 | + const seed = examplePresetSeedPrompt(record, 'en', fallback); |
| 80 | + expect(seed.text).toBe(record.manifest.description); |
| 81 | + expect(seed.fromRenderedQuery).toBe(false); |
| 82 | + }); |
| 83 | + |
| 84 | + it('keeps the rendered query head for input-templated queries so placeholder write-back survives', () => { |
| 85 | + const record = fixture({ |
| 86 | + id: 'web-prototype', |
| 87 | + description: 'General-purpose desktop web prototype.', |
| 88 | + query: { |
| 89 | + en: 'Create a premium product-studio {{fidelity}} {{artifactKind}} for {{audience}}: sharp information architecture.\n\nDetails below.', |
| 90 | + }, |
| 91 | + inputs: [ |
| 92 | + { name: 'fidelity', default: 'high-fidelity' }, |
| 93 | + { name: 'artifactKind', default: 'prototype' }, |
| 94 | + { name: 'audience', default: 'designers' }, |
| 95 | + ], |
| 96 | + }); |
| 97 | + const seed = examplePresetSeedPrompt(record, 'en', fallback); |
| 98 | + expect(seed.text).toBe( |
| 99 | + 'Create a premium product-studio high-fidelity prototype for designers: sharp information architecture.', |
| 100 | + ); |
| 101 | + expect(seed.fromRenderedQuery).toBe(true); |
| 102 | + }); |
| 103 | + |
| 104 | + it('keeps the zh description-first behavior', () => { |
| 105 | + const record = fixture({ |
| 106 | + id: 'dreamcore-landing', |
| 107 | + description: '沉浸式视差落地页。', |
| 108 | + query: { 'zh-CN': '构建梦核风格的沉浸式视差落地页(详见 en 字段的完整规格说明,以 en 为准)。' }, |
| 109 | + }); |
| 110 | + const seed = examplePresetSeedPrompt(record, 'zh-CN', fallback); |
| 111 | + expect(seed.text).toBe('沉浸式视差落地页。'); |
| 112 | + expect(seed.fromRenderedQuery).toBe(false); |
| 113 | + }); |
| 114 | + |
| 115 | + it('falls back to the query head when there is no description', () => { |
| 116 | + const record = fixture({ |
| 117 | + id: 'no-description', |
| 118 | + query: { en: 'Create a moody portfolio landing page.\n\nDetails.' }, |
| 119 | + }); |
| 120 | + const seed = examplePresetSeedPrompt(record, 'en', fallback); |
| 121 | + expect(seed.text).toBe('Create a moody portfolio landing page.'); |
| 122 | + expect(seed.fromRenderedQuery).toBe(true); |
| 123 | + }); |
| 124 | + |
| 125 | + it('falls back to the caller fallback when the query is a meta-instruction and there is no description', () => { |
| 126 | + const record = fixture({ |
| 127 | + id: 'meta-only', |
| 128 | + query: { en: 'Follow the en field verbatim; start from example.html.' }, |
| 129 | + }); |
| 130 | + const seed = examplePresetSeedPrompt(record, 'en', fallback); |
| 131 | + expect(seed.text).toBe('fallback seed'); |
| 132 | + expect(seed.fromRenderedQuery).toBe(false); |
| 133 | + }); |
| 134 | +}); |
0 commit comments