import 'package:halkyon_llm/halkyon_llm.dart'; import 'package:test/test.dart'; LlmEndpoint _at(String baseUrl) => LlmEndpoint( protocol: LlmProtocol.openai, model: 'm', apiKey: '', baseUrl: baseUrl, ); void main() { test("takes the protocol's own address where none is given", () { final endpoint = LlmEndpoint( protocol: LlmProtocol.anthropic, model: 'm', apiKey: 'k', ); expect(endpoint.host, 'api.anthropic.com'); expect(endpoint.onThisMachine, isFalse); }); test('refuses http beyond the same machine or network', () { expect(() => _at('http://example.com/v1'), throwsFormatException); expect(_at('http://192.168.1.20:11434/v1').host, '192.168.1.20'); }); test('knows a model on this machine: a loopback address or localhost ' '(ADR 0021, D9)', () { for (final url in [ 'http://127.0.0.1:11434/v1', 'http://127.8.0.1/v1', 'http://[::1]:8080/v1', 'http://localhost:11434/v1', 'http://ollama.localhost/v1', 'https://LOCALHOST/v1', ]) { expect(_at(url).onThisMachine, isTrue, reason: url); } }); test('takes nothing else for this machine: the network may be shared', () { for (final url in [ 'http://192.168.1.20:11434/v1', 'http://10.0.0.2/v1', 'http://[fd00::2]/v1', 'http://ollama/v1', 'http://gpu.local/v1', 'https://localhost.example.com/v1', 'https://api.openai.com/v1', ]) { expect(_at(url).onThisMachine, isFalse, reason: url); } }); }