forked from openclaw/openclaw.ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic-assets.test.ts
More file actions
409 lines (352 loc) · 17.9 KB
/
Copy pathstatic-assets.test.ts
File metadata and controls
409 lines (352 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import { describe, expect, test } from 'bun:test';
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { siGmail, siGooglechrome, siX } from 'simple-icons';
import { bottomIntegrationRail } from '../src/data/homepage-integrations';
import { channels, companionNodes, featuredProviders, gatewayHosts } from '../src/data/integrations';
import { resolveAuthorProfile } from '../src/lib/authors';
import { getCachedXAvatarSrc, getInitialsAvatarSrc } from '../src/lib/avatars';
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
function repoPath(relativePath: string): string {
return path.join(repoRoot, relativePath);
}
function readText(relativePath: string): string {
return readFileSync(repoPath(relativePath), 'utf8');
}
function readJson(relativePath: string): unknown {
return JSON.parse(readText(relativePath));
}
function readBytes(relativePath: string): Buffer {
return readFileSync(repoPath(relativePath));
}
function listSourceFiles(relativeDir: string): string[] {
return readdirSync(repoPath(relativeDir), { withFileTypes: true }).flatMap((entry) => {
const relativePath = path.join(relativeDir, entry.name);
return entry.isDirectory() ? listSourceFiles(relativePath) : [relativePath];
});
}
describe('static public assets', () => {
test('renders blog descriptions as escaped text instead of raw HTML', () => {
const articlePage = readText('src/pages/blog/[...slug].astro');
const contentSchema = readText('src/content.config.ts');
const blogSources = listSourceFiles('src/content/blog').map(readText);
expect(articlePage).toContain('<p class="dek">{post.data.description}</p>');
expect(articlePage).not.toContain('set:html');
expect(contentSchema).not.toContain('descriptionHtml');
expect(blogSources.every((source) => !source.includes('descriptionHtml:'))).toBe(true);
});
test('uses the canonical OpenClaw design-system contract', () => {
const layout = readText('src/layouts/Layout.astro');
const orderedImports = [
"import '@openclaw/design-system/tokens.css'",
"import '@openclaw/design-system/themes.css'",
"import '@openclaw/design-system/typography.css'",
"import '@openclaw/design-system/components.css'",
];
const importOffsets = orderedImports.map((entry) => layout.indexOf(entry));
expect(importOffsets.every((offset) => offset >= 0)).toBe(true);
expect(importOffsets).toEqual([...importOffsets].sort((left, right) => left - right));
expect(layout).toContain('<body class="oc-app-surface">');
const migrationAliases = [
'bg-deep',
'bg-surface',
'bg-elevated',
'coral-bright',
'coral-mid',
'coral-dark',
'cyan-bright',
'cyan-mid',
'cyan-glow',
'text-primary',
'text-secondary',
'text-muted',
'on-accent',
'border-subtle',
'border-accent',
'surface-card',
'surface-card-strong',
'surface-overlay',
'surface-interactive',
'surface-interactive-hover',
'surface-coral-soft',
'surface-cyan-soft',
'surface-inset-highlight',
'chart-line',
'font-display',
'font-body',
'font-serif',
'font-mono',
];
const aliasPattern = new RegExp(`var\\(--(?:${migrationAliases.join('|')})\\)`, 'g');
const aliasUsages = listSourceFiles('src')
.filter((file) => /\.(?:astro|css|ts|tsx)$/.test(file))
.flatMap((file) => (readText(file).match(aliasPattern) ?? []).map((match) => `${file}: ${match}`));
expect(aliasUsages).toEqual([]);
expect(readText('src/pages/index.astro')).toContain('oc-action oc-action-primary');
expect(readText('src/pages/ecosystem.astro')).toContain('card oc-card');
expect(readText('src/components/SectionHeader.astro')).toContain(
'section-header oc-section-header',
);
});
test('redirects legacy docs paths to the canonical docs host', () => {
const config = readJson('vercel.json') as {
redirects?: Array<{
source?: string;
has?: Array<{ type?: string; key?: string; value?: string }>;
destination?: string;
statusCode?: number;
}>;
};
expect(config.redirects).toContainEqual({
source: '/docs',
has: [{ type: 'header', key: 'host', value: 'openclaw.ai' }],
destination: 'https://docs.openclaw.ai/',
statusCode: 308,
});
expect(config.redirects).toContainEqual({
source: '/docs/:path*',
has: [{ type: 'header', key: 'host', value: 'openclaw.ai' }],
destination: 'https://docs.openclaw.ai/:path*',
statusCode: 308,
});
expect(config.redirects).toContainEqual({
source: '/docs/',
has: [{ type: 'header', key: 'host', value: 'openclaw.ai' }],
destination: 'https://docs.openclaw.ai/',
statusCode: 308,
});
expect(config.redirects).toContainEqual({
source: '/docs/:path*/',
has: [{ type: 'header', key: 'host', value: 'openclaw.ai' }],
destination: 'https://docs.openclaw.ai/:path*/',
statusCode: 308,
});
});
test('keeps legacy root logo aliases byte-for-byte with the canonical PNG logo', () => {
const canonicalLogo = readBytes('public/openclaw-logo-text-dark.png');
const pngSignature = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
expect(canonicalLogo.subarray(0, pngSignature.length).equals(pngSignature)).toBe(true);
for (const alias of ['public/granola.png', 'public/logo.png']) {
const bytes = readBytes(alias);
expect(bytes.byteLength).toBeGreaterThan(0);
expect(bytes.subarray(0, pngSignature.length).equals(pngSignature)).toBe(true);
expect(bytes.equals(canonicalLogo)).toBe(true);
}
});
test('keeps cached X avatar assets available for rendered testimonial pages', () => {
const avatarDir = repoPath('public/avatars/x');
expect(existsSync(repoPath('public/avatars/x/steipete.jpg'))).toBe(true);
expect(existsSync(repoPath('public/avatars/x/wilcosx.jpg'))).toBe(true);
expect(readdirSync(avatarDir).filter((file) => file.endsWith('.jpg')).length).toBeGreaterThan(
200,
);
expect(statSync(avatarDir).isDirectory()).toBe(true);
});
test('keeps X avatar lookup on local cached assets before falling back', () => {
expect(getCachedXAvatarSrc('@steipete')).toBe('/avatars/x/steipete.jpg');
expect(resolveAuthorProfile({ name: 'Josh Avant' }).avatar).toBe('/avatars/x/joshavant.jpg');
expect(getCachedXAvatarSrc('not-a-cached-profile', 'Missing Profile')).toBe(
getInitialsAvatarSrc('Missing Profile'),
);
});
test('keeps Google and X simple-icon assets wired into integration surfaces', () => {
const integrationsCatalog = readText('src/data/integrations.ts');
const homepageIntegrations = new Map(
bottomIntegrationRail.map((integration) => [integration.name, integration]),
);
expect(integrationsCatalog).toContain('icon: siIcon(siGoogle)');
expect(integrationsCatalog).toContain('icon: siIcon(siX)');
expect(homepageIntegrations.get('Twitter')?.icon).toBe(siX.path);
expect(homepageIntegrations.get('Browser')?.icon).toBe(siGooglechrome.path);
expect(homepageIntegrations.get('Gmail')?.icon).toBe(siGmail.path);
});
test('keeps the integrations catalog off removed and stale capability claims', () => {
const integrationsCatalog = readText('src/data/integrations.ts');
const integrationsPage = readText('src/pages/integrations.astro');
const homepage = readText('src/pages/index.astro');
const ecosystemPage = readText('src/pages/ecosystem.astro');
expect(integrationsCatalog).toContain("{ value: '29', label: 'chat channels' }");
expect(integrationsCatalog).not.toContain('documented chat channels');
expect(integrationsCatalog).not.toContain("label: 'Catalog snapshot");
expect(integrationsCatalog).toContain("{ name: 'OpenAI'");
expect(integrationsCatalog).not.toContain('currentModelExamples');
expect(integrationsCatalog).not.toContain('BlueBubbles');
expect(integrationsCatalog).not.toContain('/providers/glm');
expect(integrationsPage).not.toContain('50+ integrations');
// The bundled/official/external taxonomy was removed on purpose
expect(integrationsCatalog).not.toContain('CatalogStatus');
expect(integrationsPage).not.toContain('statusLabels');
expect(integrationsPage).not.toContain('status-badge');
expect(integrationsPage).not.toContain('Official install');
expect(integrationsPage).not.toContain('Current catalog examples');
expect(integrationsPage).not.toContain('model-snapshot');
expect(integrationsPage).not.toContain('class="eyebrow"');
expect(integrationsPage).not.toContain('.eyebrow');
expect(homepage).not.toContain('50+ integrations');
expect(ecosystemPage).not.toContain('100+ community skills');
});
test('animates catalog snapshot values while respecting reduced motion', () => {
const integrationsPage = readText('src/pages/integrations.astro');
expect(integrationsPage).toContain('data-count-up={stat.value}');
expect(integrationsPage).toContain("matchMedia('(prefers-reduced-motion: reduce)')");
expect(integrationsPage).toContain('requestAnimationFrame');
});
test('keeps automation links clear of their grid dividers', () => {
const integrationsPage = readText('src/pages/integrations.astro');
expect(integrationsPage).toMatch(
/\.automation-links li \{[\s\S]*?padding-left: var\(--oc-space-3\);/,
);
});
test('keeps integration examples on current live destinations', () => {
const integrationsCatalog = readText('src/data/integrations.ts');
expect(integrationsCatalog).not.toContain('clawhub.ai/steipete/homeassistant');
expect(integrationsCatalog).not.toContain('clawhub.ai/steipete/bird');
expect(integrationsCatalog).not.toContain('clawhub.ai/skills?q=home%20assistant');
expect(integrationsCatalog).toContain('clawhub.ai/skills?q=home+assistant');
expect(integrationsCatalog).toContain('clawhub.ai/skills?q=twitter');
expect(integrationsCatalog).toContain('#byteplus-(international)');
expect(integrationsCatalog).toContain(
'#providers-via-models.providers-(custom%2Fbase-url)',
);
});
test('sorts channels alphabetically without a status taxonomy', () => {
const expectedOrder = [...channels].sort((left, right) =>
left.name.localeCompare(right.name),
);
expect(channels.map((channel) => channel.name)).toEqual(
expectedOrder.map((channel) => channel.name),
);
expect(channels.map((channel) => channel.name)).toContain('Raft');
expect(channels.some((channel) => 'status' in channel)).toBe(false);
});
test('collapses the channel catalog after three responsive rows', () => {
const integrationsPage = readText('src/pages/integrations.astro');
expect(integrationsPage).toContain('id="channel-catalog"');
expect(integrationsPage).toContain('aria-controls="channel-catalog"');
expect(integrationsPage).toContain('data-channel-expander');
expect(integrationsPage).toContain('See all channels');
expect(integrationsPage).toContain('Show fewer channels');
expect(integrationsPage).toContain('<span class="channel-expander-icon"');
expect(integrationsPage).toMatch(
/\.channel-expander:focus-visible \{[\s\S]*?outline: none;[\s\S]*?box-shadow: 0 0 0 1px var\(--oc-accent-secondary\);/,
);
expect(integrationsPage).toContain('nth-child(n + 13)');
expect(integrationsPage).toContain('nth-child(n + 10)');
expect(integrationsPage).toContain('nth-child(n + 7)');
expect(integrationsPage).toContain('nth-child(n + 4)');
});
test('uses real local or vector brand marks for branded integration cards', () => {
const semanticChannelIcons = new Set(['IRC', 'Raft', 'Voice Call', 'WebChat']);
const brandedItems = [
...channels.filter((item) => !semanticChannelIcons.has(item.name)),
...featuredProviders,
...gatewayHosts.filter((item) => item.name === 'Windows'),
...companionNodes.filter((item) => item.name === 'Windows Hub'),
];
expect(
brandedItems.filter((item) => item.icon.startsWith('lucide:') && !item.logo),
).toEqual([]);
for (const item of brandedItems) {
if (!item.logo) continue;
expect(item.logo.startsWith('/integrations/logos/')).toBe(true);
expect(existsSync(repoPath(`public${item.logo}`))).toBe(true);
}
});
test('keeps a local outlet icon for every press entry', () => {
const press = readJson('src/data/press.json') as Array<{ url: string }>;
expect(press.length).toBeGreaterThan(0);
for (const article of press) {
const host = new URL(article.url).hostname.replace(/^www\./, '');
expect(existsSync(repoPath(`public/press/icons/${host}.png`))).toBe(true);
}
});
test('keeps integration cards neutral at rest', () => {
const integrationsPage = readText('src/pages/integrations.astro');
expect(integrationsPage).not.toContain('.catalog-card::before');
expect(integrationsPage).not.toContain('border-top: 2px solid var(--accent)');
expect(integrationsPage).not.toContain('.status-included');
expect(integrationsPage).not.toContain('.status-official');
expect(integrationsPage).not.toContain('.status-external');
});
test('keeps the integrations hero aligned with the site page-header pattern', () => {
const integrationsPage = readText('src/pages/integrations.astro');
expect(integrationsPage).not.toContain('hero-kicker');
expect(integrationsPage).not.toContain('The OpenClaw ecosystem');
expect(integrationsPage).toContain('<p class="section-kicker">Works with everything</p>');
expect(integrationsPage).toContain('<h1 class="hero-title">Integrations</h1>');
expect(integrationsPage).toMatch(/\.hero \{[\s\S]*?text-align: left;/);
expect(integrationsPage).not.toMatch(/\.hero-title \{[\s\S]*?background: linear-gradient/);
});
test('includes integrations in the shared site navigation', () => {
const topbar = readText('src/components/SiteTopbar.astro');
const integrationsPage = readText('src/pages/integrations.astro');
expect(topbar).toContain("| 'integrations'");
expect(topbar).toContain("{ href: '/integrations', label: 'Integrations' }");
expect(topbar).toContain("if (active === 'integrations') return item.href === '/integrations'");
expect(integrationsPage).toContain("import SiteTopbar from '../components/SiteTopbar.astro'");
expect(integrationsPage).toContain('<SiteTopbar active="integrations" />');
expect(integrationsPage).not.toContain('Back to home');
expect(integrationsPage).not.toContain('.back-link');
});
test('uses a compact expandable site navigation on mobile', () => {
const topbar = readText('src/components/SiteTopbar.astro');
expect(topbar).toContain("import { FileText, Megaphone } from '@lucide/astro'");
expect(topbar).toContain('class="site-nav site-nav-desktop"');
expect(topbar).toContain('<details class="site-menu">');
expect(topbar).toContain('class="site-menu-toggle"');
expect(topbar).toContain('class="site-burger"');
expect(topbar).toContain('aria-label="Toggle main navigation"');
expect(topbar).toContain('class="site-menu-panel"');
expect(topbar).toMatch(/@media \(max-width: 720px\) \{[\s\S]*?\.site-nav\.site-nav-desktop \{[\s\S]*?display: none;/);
expect(topbar).toMatch(/@media \(max-width: 720px\) \{[\s\S]*?\.site-menu \{[\s\S]*?display: block;/);
});
test('uses a matching lobster icon and install-focused ClawHub CTA', () => {
const homePage = readText('src/pages/index.astro');
expect(homePage).toContain('data-icon="clawhub-lobster"');
expect(homePage).not.toContain('src="/ecosystem/logos/clawhub.png"');
expect(homePage).toContain('<span class="cta-sub">Install skills and plugins</span>');
expect(homePage).not.toContain('<span class="cta-sub">Download skills</span>');
});
test('keeps the homepage hero lobster eyes dark in both themes', () => {
const homePage = readText('src/pages/index.astro');
expect(homePage).toContain('<circle cx="45" cy="35" r="6" fill="#101012"/>');
expect(homePage).toContain('<circle cx="75" cy="35" r="6" fill="#101012"/>');
expect(homePage).not.toContain('<circle cx="45" cy="35" r="6" fill="var(--bg-deep)"/>');
expect(homePage).not.toContain('<circle cx="75" cy="35" r="6" fill="var(--bg-deep)"/>');
});
test('omits the redundant integrations section navigation', () => {
const integrationsPage = readText('src/pages/integrations.astro');
expect(integrationsPage).not.toContain('aria-label="Integration categories"');
expect(integrationsPage).not.toContain('class="catalog-nav"');
expect(integrationsPage).not.toContain('.catalog-nav');
});
test('keeps Vercel security headers aligned with static site resource origins', () => {
const config = readJson('vercel.json') as {
headers?: Array<{
source?: string;
headers?: Array<{ key?: string; value?: string }>;
}>;
};
const globalHeaders = config.headers?.find((entry) => entry.source === '/(.*)')?.headers ?? [];
const headerMap = new Map(globalHeaders.map((header) => [header.key, header.value]));
const csp = headerMap.get('Content-Security-Policy') ?? '';
expect(headerMap.get('X-Content-Type-Options')).toBe('nosniff');
expect(headerMap.get('X-Frame-Options')).toBe('DENY');
expect(headerMap.get('Referrer-Policy')).toBe('strict-origin-when-cross-origin');
expect(headerMap.get('Permissions-Policy')).toBe('camera=(), microphone=(), geolocation=()');
for (const requiredDirective of [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' https://va.vercel-scripts.com",
"style-src 'self' 'unsafe-inline' https://api.fontshare.com",
"font-src 'self' https://cdn.fontshare.com",
"img-src 'self' data: https://ui-avatars.com https://pbs.twimg.com",
"connect-src 'self' https://vitals.vercel-analytics.com",
"frame-ancestors 'none'",
"form-action 'self' https://buttondown.com",
"base-uri 'self'",
]) {
expect(csp).toContain(requiredDirective);
}
});
});