Files
cutdex/test/agent_message_codec_test.dart
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

83 lines
3.2 KiB
Dart

import 'package:cutdex/features/assistant/agent_media_attachments.dart';
import 'package:cutdex/features/assistant/agent_message_codec.dart';
import 'package:cutdex/features/assistant/composer_document.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('inline references coexist with attachment cards', () {
const reference = ComposerReference(
kind: ComposerReferenceKind.timeline,
projectId: 'project',
id: 'timeline-2',
label: '另一条时间线',
);
const segments = [
ComposerSegment.text('查看 '),
ComposerSegment.reference(reference),
];
final encoded = AgentComposerMessage.encodeDocument(segments, const [
AgentMediaAttachment(id: 'media-1', name: '片段.mp4', kind: 'video'),
]);
final decoded = AgentComposerMessage.decode(encoded);
expect(decoded.text, '查看 另一条时间线');
expect(decoded.references.single.id, 'timeline-2');
expect(decoded.segments, segments);
expect(decoded.attachments.single.id, 'media-1');
expect(encoded, contains('"projectId":"project"'));
});
test('media references survive encode and decode without leaking into the chat text', () {
const attachments = [
AgentMediaAttachment(id: 'media-1', name: '画面.mp4', kind: 'video'),
AgentMediaAttachment(id: 'media-2', name: '声音.mp3', kind: 'audio'),
];
final prompt = AgentComposerMessage.encodeDocument(const [
ComposerSegment.text('剪辑这两个素材'),
], attachments);
expect(prompt, contains('media-1'));
expect(prompt, contains('media-2'));
final decoded = AgentComposerMessage.decode(prompt);
expect(decoded.text, '剪辑这两个素材');
expect(decoded.attachments.map((item) => item.name), ['画面.mp4', '声音.mp3']);
});
test('attachment-only and ordinary chat text remain displayable', () {
const attachment = AgentMediaAttachment(
id: 'a',
name: '片段.mov',
kind: 'video',
);
final decoded = AgentComposerMessage.decode(
AgentComposerMessage.encodeDocument(const [], [attachment]),
);
expect(decoded.text, isEmpty);
expect(decoded.attachments.single.id, 'a');
expect(AgentComposerMessage.decode('普通文本').text, '普通文本');
expect(
AgentComposerMessage.decode('[Cutdex composer message] broken').text,
'[Cutdex composer message] broken',
);
});
test(
'damaged message data stays visible without partial resource references',
() {
for (final data in [
'broken',
'{"text":"hello","attachments":[{"id":"a","name":"A",'
'"kind":"video"}]}',
'{"text":"hello","attachments":[{"id":"a"}]}',
'{"text":"hello","segments":[{"runtimeType":"unknown"}]}',
'{"text":"hello","segments":[{"runtimeType":"reference",'
'"value":{"kind":"unknown","projectId":"p","id":"a",'
'"label":"a"}}]}',
]) {
final message = '[Cutdex composer message] $data\n\nInstructions';
final decoded = AgentComposerMessage.decode(message);
expect(decoded.text, message);
expect(decoded.references, isEmpty);
expect(decoded.attachments, isEmpty);
}
},
);
}