|
19 | 19 | use Symfony\AI\AiBundle\AiBundle;
|
20 | 20 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
21 | 21 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
| 22 | +use Symfony\Component\DependencyInjection\Definition; |
| 23 | +use Symfony\Component\DependencyInjection\Reference; |
22 | 24 |
|
23 | 25 | #[CoversClass(AiBundle::class)]
|
24 | 26 | #[UsesClass(ContainerBuilder::class)]
|
| 27 | +#[UsesClass(Definition::class)] |
| 28 | +#[UsesClass(Reference::class)] |
25 | 29 | class AiBundleTest extends TestCase
|
26 | 30 | {
|
27 | 31 | #[DoesNotPerformAssertions]
|
@@ -105,6 +109,89 @@ public function testAgentsAsToolsCannotDefineService()
|
105 | 109 | ]);
|
106 | 110 | }
|
107 | 111 |
|
| 112 | + public function testCacheStoreWithCustomKeyCanBeConfigured() |
| 113 | + { |
| 114 | + $container = $this->buildContainer([ |
| 115 | + 'ai' => [ |
| 116 | + 'store' => [ |
| 117 | + 'cache' => [ |
| 118 | + 'my_cache_store_with_custom_strategy' => [ |
| 119 | + 'service' => 'cache.system', |
| 120 | + 'key' => 'random', |
| 121 | + ], |
| 122 | + ], |
| 123 | + ], |
| 124 | + ], |
| 125 | + ]); |
| 126 | + |
| 127 | + $this->assertTrue($container->hasDefinition('ai.store.cache.my_cache_store_with_custom_strategy')); |
| 128 | + $this->assertFalse($container->hasDefinition('ai.store.distance_calculator.my_cache_store_with_custom_strategy')); |
| 129 | + |
| 130 | + $definition = $container->getDefinition('ai.store.cache.my_cache_store_with_custom_strategy'); |
| 131 | + |
| 132 | + $this->assertCount(2, $definition->getArguments()); |
| 133 | + $this->assertInstanceOf(Reference::class, $definition->getArgument(0)); |
| 134 | + $this->assertSame('cache.system', (string) $definition->getArgument(0)); |
| 135 | + $this->assertSame('random', $definition->getArgument(2)); |
| 136 | + } |
| 137 | + |
| 138 | + public function testCacheStoreWithCustomStrategyCanBeConfigured() |
| 139 | + { |
| 140 | + $container = $this->buildContainer([ |
| 141 | + 'ai' => [ |
| 142 | + 'store' => [ |
| 143 | + 'cache' => [ |
| 144 | + 'my_cache_store_with_custom_strategy' => [ |
| 145 | + 'service' => 'cache.system', |
| 146 | + 'strategy' => 'chebyshev', |
| 147 | + ], |
| 148 | + ], |
| 149 | + ], |
| 150 | + ], |
| 151 | + ]); |
| 152 | + |
| 153 | + $this->assertTrue($container->hasDefinition('ai.store.cache.my_cache_store_with_custom_strategy')); |
| 154 | + $this->assertTrue($container->hasDefinition('ai.store.distance_calculator.my_cache_store_with_custom_strategy')); |
| 155 | + |
| 156 | + $definition = $container->getDefinition('ai.store.cache.my_cache_store_with_custom_strategy'); |
| 157 | + |
| 158 | + $this->assertCount(3, $definition->getArguments()); |
| 159 | + $this->assertInstanceOf(Reference::class, $definition->getArgument(0)); |
| 160 | + $this->assertSame('cache.system', (string) $definition->getArgument(0)); |
| 161 | + $this->assertSame('_vectors', $definition->getArgument(2)); |
| 162 | + $this->assertInstanceOf(Reference::class, $definition->getArgument(1)); |
| 163 | + $this->assertSame('ai.store.distance_calculator.my_cache_store_with_custom_strategy', (string) $definition->getArgument(1)); |
| 164 | + } |
| 165 | + |
| 166 | + public function testCacheStoreWithCustomStrategyAndKeyCanBeConfigured() |
| 167 | + { |
| 168 | + $container = $this->buildContainer([ |
| 169 | + 'ai' => [ |
| 170 | + 'store' => [ |
| 171 | + 'cache' => [ |
| 172 | + 'my_cache_store_with_custom_strategy' => [ |
| 173 | + 'service' => 'cache.system', |
| 174 | + 'key' => 'random', |
| 175 | + 'strategy' => 'chebyshev', |
| 176 | + ], |
| 177 | + ], |
| 178 | + ], |
| 179 | + ], |
| 180 | + ]); |
| 181 | + |
| 182 | + $this->assertTrue($container->hasDefinition('ai.store.cache.my_cache_store_with_custom_strategy')); |
| 183 | + $this->assertTrue($container->hasDefinition('ai.store.distance_calculator.my_cache_store_with_custom_strategy')); |
| 184 | + |
| 185 | + $definition = $container->getDefinition('ai.store.cache.my_cache_store_with_custom_strategy'); |
| 186 | + |
| 187 | + $this->assertCount(3, $definition->getArguments()); |
| 188 | + $this->assertInstanceOf(Reference::class, $definition->getArgument(0)); |
| 189 | + $this->assertSame('cache.system', (string) $definition->getArgument(0)); |
| 190 | + $this->assertSame('random', $definition->getArgument(2)); |
| 191 | + $this->assertInstanceOf(Reference::class, $definition->getArgument(1)); |
| 192 | + $this->assertSame('ai.store.distance_calculator.my_cache_store_with_custom_strategy', (string) $definition->getArgument(1)); |
| 193 | + } |
| 194 | + |
108 | 195 | private function buildContainer(array $configuration): ContainerBuilder
|
109 | 196 | {
|
110 | 197 | $container = new ContainerBuilder();
|
@@ -205,6 +292,14 @@ private function getFullConfig(): array
|
205 | 292 | 'my_cache_store' => [
|
206 | 293 | 'service' => 'cache.system',
|
207 | 294 | ],
|
| 295 | + 'my_cache_store_with_custom_key' => [ |
| 296 | + 'service' => 'cache.system', |
| 297 | + 'key' => 'bar', |
| 298 | + ], |
| 299 | + 'my_cache_store_with_custom_strategy' => [ |
| 300 | + 'service' => 'cache.system', |
| 301 | + 'strategy' => 'chebyshev', |
| 302 | + ], |
208 | 303 | ],
|
209 | 304 | 'chroma_db' => [
|
210 | 305 | 'my_chroma_store' => [
|
|
0 commit comments