Files
Genarrative/apps/ai-game-creator-shell/tests/AgentMessageContent.test.tsx
T
suzmii 5cd02aa8b0
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 2m44s
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m45s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 2m46s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 2m49s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m53s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 3m18s
Project CI / Frontend tests (pull_request) Failing after 4m6s
Project CI / Native shell tests (pull_request) Successful in 6m12s
Project CI / Repository checks (pull_request) Failing after 3m48s
Project CI / Backend tests (pull_request) Successful in 7m8s
Project CI / AI game creator shell web tests (pull_request) Failing after 3m59s
统一智能体对话层级并完善素材导出与文档预览
当前Agent与策划Agent共用正文和过程表现组件,统一思考及工具调用的小字号浅色样式
素材工具栏按实际动作分组,导出紧邻删除并修复空分组重复分隔线
文档与代码使用共享Markdown预览和代码高亮,复用按需读取与缓存
移除未调用的活跃回合查询命令,保留正式快照恢复链路
补充回归用例并同步技术方案和团队约定
2026-09-16 03:59:27 +08:00

112 lines
3.8 KiB
TypeScript

// @vitest-environment jsdom
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { render } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { AgentMessageContent } from '../../../packages/shared/src/components/AgentMessageContent';
import { ChatMarkdownMessage } from '../src/components/ChatMarkdownMessage';
import {
declaration,
parseStyleSheet,
resolveDeclarations,
} from './styleCascade';
const sharedCss = readFileSync(
resolve(
process.cwd(),
'packages/shared/src/components/AgentMessageContent.css',
),
'utf8',
);
const appCss = readFileSync(
resolve(process.cwd(), 'apps/ai-game-creator-shell/src/styles.css'),
'utf8',
);
const base = '.agent-message-content[data-agent-content]';
const processTone = ".agent-message-content[data-agent-content='process']";
describe('AgentMessageContent', () => {
it('正文与过程复用表现组件,保留折叠语义和宿主属性', () => {
const { container } = render(
<>
<AgentMessageContent>最终回复</AgentMessageContent>
<AgentMessageContent as="details" tone="process" aria-label="思考过程">
<summary>思考过程</summary>
<pre>先分析需求</pre>
</AgentMessageContent>
</>,
);
expect(
container.querySelector('[data-agent-content="body"]')?.textContent,
).toBe('最终回复');
const details = container.querySelector('details')!;
expect(details.getAttribute('data-agent-content')).toBe('process');
expect(details.getAttribute('aria-label')).toBe('思考过程');
expect(details.open).toBe(false);
});
it('过程的标题和表格继承层级变量,不用强制字号压回正文大小', () => {
const { container } = render(
<AgentMessageContent tone="process">
<ChatMarkdownMessage
role="assistant"
text={
'# 分析\n\n| 项目 |\n| --- |\n| 内容 |\n\n```js\nconst value = 1;\n```'
}
/>
</AgentMessageContent>,
);
expect(container.querySelector('h1')?.getAttribute('style')).toContain(
'--agent-message-heading-size',
);
expect(container.querySelector('table')?.getAttribute('style')).toContain(
'--agent-message-table-size',
);
expect(container.querySelector('pre code .hljs-keyword')).not.toBeNull();
});
it.each([sharedCss + appCss, appCss + sharedCss])(
'共享层级不受宿主 CSS 加载顺序影响',
(css) => {
const rules = parseStyleSheet(css);
const body = resolveDeclarations(rules, [base], 1024);
expect(declaration(body, 'font-size')).toBe('14px');
expect(declaration(body, 'color')).toContain('--platform-text-strong');
for (const host of [
['.design-agent-reasoning'],
['.agent-tool-call-group'],
[
'.project-supervisor-process-card',
'.game-workbench-chat .project-supervisor-process-card',
'.game-workbench-chat .project-supervisor-surface.is-direct-codex .project-supervisor-conversation > .project-supervisor-process-card',
],
]) {
const process = resolveDeclarations(
rules,
[base, processTone, ...host],
1024,
);
expect(declaration(process, 'font-size')).toBe('12px');
expect(declaration(process, 'color')).toContain('--platform-text-soft');
expect(declaration(process, '--agent-message-heading-size')).toBe(
'1em',
);
}
const failure = resolveDeclarations(
rules,
[
'.agent-tool-call-row-status',
".agent-tool-call-group-row[data-status='failed'] .agent-tool-call-row-status",
],
1024,
);
expect(declaration(failure, 'color')).toBe(
'var(--platform-button-danger-text)',
);
},
);
});