open-design/apps/daemon/tests/design-system-source-context.test.ts
Eli 18b947c25f
[codex] Land design system GitHub intake handoff (#2187)
* Add Claude-style design system workflow

* Merge design system workflow into main

* Restore design system workflow UI styles

* Fix design system setup scrolling

* Fix design system setup connector button

* Preserve connector auth link after popup block

* Simplify connected GitHub setup state

* Open generated design system workspace project

* Summarize design system auto prompt in chat

* Add bounded GitHub connector design intake

* Prefer path-scoped GitHub intake tools

* Restore branch GitHub design context intake

* Restore design system review workspace

* Restore design system manager tab

* Let design system workflow routes own details

* Open editable design systems as projects

* Restore design system workspace coverage

* Fix bounded GitHub connector intake

* Hide design system review while generating

* Suppress design system generation questions

* Constrain GitHub design intake to bounded command

* Tolerate oversized GitHub metadata during intake

* Rebuild daemon CLI when sources change

* Fallback when GitHub connector snapshots are rate limited

* Allow GitHub intake without Composio

* Use native GitHub auth for design intake

* Remove design system review group heading

* Improve design system extraction evidence

* Align design system scaffold with Claude output

* Add evidence inventory for design system intake

* Add local design system evidence intake

* Add design system package audit gate

* Allow auditing Claude Design reference packages

* Audit design system package content quality

* Migrate legacy design system artifacts

* Clean migrated design system artifacts

* Require modular design system UI kits

* Reject thin design system UI kits

* Prioritize core design evidence intake

* Require role-based design system UI kits

* Clean stale design system manifest references

* Require representative preserved design assets

* Warn on generic design system visuals

* Enforce design system quality warnings

* Audit connected design system UI kits

* Require mounted design system UI kits

* Require composed design system app shells

* Require runnable JSX design system kits

* Require browser globals for design system components

* Infer design system names from source URLs

* Require source examples in design system packages

* Bind preserved fonts in design system tokens

* Require skill frontmatter in design system packages

* Preserve build icons in design system packages

* Require real assets in brand previews

* Require substantive source examples

* Require product overview in design system README

* Require reusable UI kit README

* Require reusable design system skill docs

* Seed Claude-style UI kit entry contract

* Preserve runtime build assets in design packages

* Audit design system packages after generation

* Audit design system first-run output

* Audit source-backed preview cards

* Align design system UI kit scaffolds

* Materialize design evidence package artifacts

* Show project chat during design system setup

* Hand off design system setup to project chat

* Auto-repair design system audit failures

* Harden design system evidence preservation

* Tighten design system package guidance

* Add targeted design system repair guidance

* Bound design system audit auto repair

* Use connector statuses in design system setup

* Audit design system preview manifests

* Require README preview manifests for design systems

* Fix design system GitHub intake handoff

* Fix daemon prompt CI assertions
2026-05-19 14:30:17 +08:00

103 lines
3.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
collectDesignSystemSourceContext,
mergeSourceContextIntoInput,
type FetchLike,
} from '../src/design-system-source-context.js';
describe('design system source context', () => {
it('reads GitHub metadata, README, and package context', async () => {
const fetchFn: FetchLike = async (url) => {
if (url === 'https://api.github.com/repos/acme/product') {
return jsonResponse({
description: 'Acme product UI repository.',
homepage: 'https://acme.example',
default_branch: 'trunk',
language: 'TypeScript',
stargazers_count: 42,
topics: ['design-system', 'dashboard'],
});
}
if (url === 'https://raw.githubusercontent.com/acme/product/trunk/README.md') {
return textResponse('# Acme Product\n\nDesign tokens and dense workflow components for Acme.');
}
if (url === 'https://raw.githubusercontent.com/acme/product/trunk/package.json') {
return textResponse(JSON.stringify({
name: '@acme/product',
description: 'Workspace UI package.',
}));
}
return textResponse('not found', 404);
};
const context = await collectDesignSystemSourceContext({
provenance: {
githubUrls: ['https://github.com/acme/product/tree/trunk'],
},
}, {
fetch: fetchFn,
maxReadmeChars: 160,
});
expect(context.github[0]).toMatchObject({
owner: 'acme',
repo: 'product',
description: 'Acme product UI repository.',
defaultBranch: 'trunk',
language: 'TypeScript',
stars: 42,
packageName: '@acme/product',
});
expect(context.notes).toContain('Fetched GitHub context');
expect(context.notes).toContain('Design tokens and dense workflow components');
const merged = mergeSourceContextIntoInput({
sourceNotes: 'GitHub/code: https://github.com/acme/product',
provenance: {
githubUrls: ['https://github.com/acme/product'],
sourceNotes: 'GitHub/code: https://github.com/acme/product',
},
}, context);
expect(merged.sourceNotes).toContain('GitHub/code: https://github.com/acme/product');
expect(merged.sourceNotes).toContain('Fetched GitHub context');
expect(merged.provenance?.sourceNotes).toContain('README excerpt');
expect(merged.provenance?.sourceNotes).not.toContain('GitHub/code:');
});
it('keeps generation usable when GitHub metadata is unavailable', async () => {
const context = await collectDesignSystemSourceContext({
provenance: {
githubUrls: ['git@github.com:acme/missing.git'],
},
}, {
fetch: async () => textResponse('not found', 404),
});
expect(context.github[0]).toMatchObject({
owner: 'acme',
repo: 'missing',
error: 'GitHub repository metadata unavailable (HTTP 404)',
});
expect(context.notes).toContain('GitHub repository metadata unavailable');
});
});
function jsonResponse(value: unknown, status = 200): ReturnType<FetchLike> {
return Promise.resolve({
ok: status >= 200 && status < 300,
status,
json: async () => value,
text: async () => JSON.stringify(value),
});
}
function textResponse(value: string, status = 200): ReturnType<FetchLike> {
return Promise.resolve({
ok: status >= 200 && status < 300,
status,
json: async () => JSON.parse(value),
text: async () => value,
});
}