ollama = $this->createMock(OllamaClientInterface::class); $repo = $this->createMock(PromptTemplateRepositoryInterface::class); $repo->method('findByKey')->willReturn(new PromptTemplate('vision_analyze', 'prompt')); $prompts = new PromptTemplateService($repo); $this->agent = new OllamaVisionAgent($this->ollama, $prompts, 'llava'); } public function test_parses_all_fields(): void { $this->ollama->method('generateWithImage')->willReturn( "MANUFACTURER: Lenovo\nMODEL_NAME: ThinkBook 14 G6 IRL\nMODEL_NUMBER: 21KG00NQGE\nSERIAL: PNV09SJZ" ); $result = $this->agent->analyze('/tmp/photo.jpg'); $this->assertSame('Lenovo', $result['manufacturer']); $this->assertSame('ThinkBook 14 G6 IRL', $result['modelName']); $this->assertSame('21KG00NQGE', $result['modelNumber']); $this->assertSame('PNV09SJZ', $result['serial']); } public function test_strips_serial_bleed_into_model_number_leading(): void { // LLM outputs "SERIAL: xyz" as the entire value for MODEL_NUMBER $this->ollama->method('generateWithImage')->willReturn( "MANUFACTURER: ELPIDA\nMODEL_NAME: 2GB 2Rx8 PC3-10600S-9-10-F1\nMODEL_NUMBER: SERIAL: 1005NK677594\nSERIAL: 1005NK677594" ); $result = $this->agent->analyze('/tmp/photo.jpg'); $this->assertSame('', $result['modelNumber']); $this->assertSame('1005NK677594', $result['serial']); } public function test_strips_serial_bleed_into_model_name_mid_value(): void { // LLM appends serial after the model name $this->ollama->method('generateWithImage')->willReturn( "MANUFACTURER: Lenovo\nMODEL_NAME: ThinkBook 14 G6 IRL SERIAL: PNV09SJZ\nMODEL_NUMBER: 21KG00NQGE\nSERIAL: PNV09SJZ" ); $result = $this->agent->analyze('/tmp/photo.jpg'); $this->assertSame('ThinkBook 14 G6 IRL', $result['modelName']); $this->assertSame('PNV09SJZ', $result['serial']); } public function test_returns_empty_strings_when_fields_missing(): void { $this->ollama->method('generateWithImage')->willReturn('I cannot read the nameplate.'); $result = $this->agent->analyze('/tmp/photo.jpg'); $this->assertSame('', $result['manufacturer']); $this->assertSame('', $result['modelName']); $this->assertSame('', $result['modelNumber']); $this->assertSame('', $result['serial']); } }