import 'package:flutter_test/flutter_test.dart'; import 'package:openchamber/api/models.dart'; ContentPart imageTool({ String name = 'openchamber_image', String status = 'completed', String text = '', String? error, }) { return ContentPart( type: 'tool', name: name, state: ToolState( status: status, content: [ContentPart(type: 'text', text: text)], error: error, ), ); } const envelope = '{"schemaVersion":1,"ok":true,"action":"image.generate","data":' '{"model":"axonhub-image/sensenova-u1.5-lite","images":[' '{"path":"/tmp/opencode/generated-images/a.png","mime":"image/png"},' '{"path":"/tmp/opencode/generated-images/b.png","mime":"image/png"}]}}'; void main() { group('generatedImagePaths', () { test('reads every path from a finished image call', () { final part = imageTool(text: envelope); expect(generatedImagePaths(part), [ '/tmp/opencode/generated-images/a.png', '/tmp/opencode/generated-images/b.png', ]); }); test('shows nothing while the call still runs', () { expect(generatedImagePaths(imageTool(status: 'running', text: envelope)), isEmpty); }); test('shows nothing for a failed call', () { expect( generatedImagePaths( imageTool(status: 'error', text: envelope, error: 'no model')), isEmpty, ); }); test('only the openchamber_image tool is lifted out', () { expect(generatedImagePaths(imageTool(name: 'bash', text: envelope)), isEmpty); expect( generatedImagePaths(ContentPart(type: 'text', text: envelope)), isEmpty, ); }); test('a plain text result is not a picture', () { expect(generatedImagePaths(imageTool(text: '图片已生成')), isEmpty); expect( generatedImagePaths(imageTool(text: '{"ok":false,"action":"x"}')), isEmpty, ); }); }); group('relativePath', () { test('drops the session directory', () { expect( relativePath('/home/blumia/src/app/lib/main.dart', '/home/blumia/src/app'), 'lib/main.dart', ); }); test('keeps paths outside it whole', () { expect( relativePath('/tmp/opencode/generated-images/a.png', '/home/blumia/src/app'), '/tmp/opencode/generated-images/a.png', ); }); test('tolerates a trailing slash and a file elsewhere', () { expect(relativePath('/a/b/c.txt', '/a/b/'), 'c.txt'); expect(relativePath('/a/bc/c.txt', '/a/b'), '/a/bc/c.txt'); expect(relativePath('x.txt', ''), 'x.txt'); expect(relativePath('/a/b', '/a/b'), '.'); }); }); }