|
1 | | -import { DEFAULT_STRATEGY_NAMESPACES, MemoryStrategySchema, MemoryStrategyTypeSchema } from '../memory'; |
| 1 | +import { |
| 2 | + DEFAULT_STRATEGY_NAMESPACES, |
| 3 | + MemoryStrategySchema, |
| 4 | + MemoryStrategyTypeSchema, |
| 5 | + SemanticOverrideSchema, |
| 6 | +} from '../memory'; |
2 | 7 | import { describe, expect, it } from 'vitest'; |
3 | 8 |
|
4 | 9 | describe('MemoryStrategyTypeSchema', () => { |
@@ -170,3 +175,115 @@ describe('DEFAULT_STRATEGY_NAMESPACES', () => { |
170 | 175 | expect(DEFAULT_STRATEGY_NAMESPACES).not.toHaveProperty('CUSTOM'); |
171 | 176 | }); |
172 | 177 | }); |
| 178 | + |
| 179 | +describe('SemanticOverrideSchema', () => { |
| 180 | + it('accepts extraction-only override', () => { |
| 181 | + const result = SemanticOverrideSchema.safeParse({ |
| 182 | + extraction: { appendToPrompt: 'Extract key facts', modelId: 'anthropic.claude-3-sonnet-20240229-v1:0' }, |
| 183 | + }); |
| 184 | + expect(result.success).toBe(true); |
| 185 | + }); |
| 186 | + |
| 187 | + it('accepts consolidation-only override', () => { |
| 188 | + const result = SemanticOverrideSchema.safeParse({ |
| 189 | + consolidation: { appendToPrompt: 'Consolidate memories', modelId: 'anthropic.claude-3-sonnet-20240229-v1:0' }, |
| 190 | + }); |
| 191 | + expect(result.success).toBe(true); |
| 192 | + }); |
| 193 | + |
| 194 | + it('accepts both extraction and consolidation', () => { |
| 195 | + const result = SemanticOverrideSchema.safeParse({ |
| 196 | + extraction: { appendToPrompt: 'Extract', modelId: 'model-1' }, |
| 197 | + consolidation: { appendToPrompt: 'Consolidate', modelId: 'model-2' }, |
| 198 | + }); |
| 199 | + expect(result.success).toBe(true); |
| 200 | + }); |
| 201 | + |
| 202 | + it('rejects empty override (at least one required)', () => { |
| 203 | + const result = SemanticOverrideSchema.safeParse({}); |
| 204 | + expect(result.success).toBe(false); |
| 205 | + }); |
| 206 | + |
| 207 | + it('rejects extraction with empty appendToPrompt', () => { |
| 208 | + const result = SemanticOverrideSchema.safeParse({ |
| 209 | + extraction: { appendToPrompt: '', modelId: 'model-1' }, |
| 210 | + }); |
| 211 | + expect(result.success).toBe(false); |
| 212 | + }); |
| 213 | + |
| 214 | + it('rejects extraction with missing modelId', () => { |
| 215 | + const result = SemanticOverrideSchema.safeParse({ |
| 216 | + extraction: { appendToPrompt: 'test' }, |
| 217 | + }); |
| 218 | + expect(result.success).toBe(false); |
| 219 | + }); |
| 220 | +}); |
| 221 | + |
| 222 | +describe('MemoryStrategySchema with semanticOverride', () => { |
| 223 | + it('accepts SEMANTIC strategy with extraction override', () => { |
| 224 | + const result = MemoryStrategySchema.safeParse({ |
| 225 | + type: 'SEMANTIC', |
| 226 | + semanticOverride: { |
| 227 | + extraction: { appendToPrompt: 'Extract key facts', modelId: 'anthropic.claude-3-sonnet-20240229-v1:0' }, |
| 228 | + }, |
| 229 | + }); |
| 230 | + expect(result.success).toBe(true); |
| 231 | + }); |
| 232 | + |
| 233 | + it('accepts SEMANTIC strategy with both overrides', () => { |
| 234 | + const result = MemoryStrategySchema.safeParse({ |
| 235 | + type: 'SEMANTIC', |
| 236 | + semanticOverride: { |
| 237 | + extraction: { appendToPrompt: 'Extract', modelId: 'model-1' }, |
| 238 | + consolidation: { appendToPrompt: 'Consolidate', modelId: 'model-2' }, |
| 239 | + }, |
| 240 | + }); |
| 241 | + expect(result.success).toBe(true); |
| 242 | + }); |
| 243 | + |
| 244 | + it('accepts SEMANTIC strategy without override (backward compat)', () => { |
| 245 | + const result = MemoryStrategySchema.safeParse({ type: 'SEMANTIC' }); |
| 246 | + expect(result.success).toBe(true); |
| 247 | + }); |
| 248 | + |
| 249 | + it('rejects semanticOverride on SUMMARIZATION strategy', () => { |
| 250 | + const result = MemoryStrategySchema.safeParse({ |
| 251 | + type: 'SUMMARIZATION', |
| 252 | + semanticOverride: { |
| 253 | + extraction: { appendToPrompt: 'test', modelId: 'model-1' }, |
| 254 | + }, |
| 255 | + }); |
| 256 | + expect(result.success).toBe(false); |
| 257 | + if (!result.success) { |
| 258 | + expect(result.error.issues.some(i => i.message.includes('SEMANTIC'))).toBe(true); |
| 259 | + } |
| 260 | + }); |
| 261 | + |
| 262 | + it('rejects semanticOverride on USER_PREFERENCE strategy', () => { |
| 263 | + const result = MemoryStrategySchema.safeParse({ |
| 264 | + type: 'USER_PREFERENCE', |
| 265 | + semanticOverride: { |
| 266 | + extraction: { appendToPrompt: 'test', modelId: 'model-1' }, |
| 267 | + }, |
| 268 | + }); |
| 269 | + expect(result.success).toBe(false); |
| 270 | + }); |
| 271 | + |
| 272 | + it('rejects consolidation-only semanticOverride on USER_PREFERENCE strategy', () => { |
| 273 | + const result = MemoryStrategySchema.safeParse({ |
| 274 | + type: 'USER_PREFERENCE', |
| 275 | + semanticOverride: { |
| 276 | + consolidation: { appendToPrompt: 'test', modelId: 'model-1' }, |
| 277 | + }, |
| 278 | + }); |
| 279 | + expect(result.success).toBe(false); |
| 280 | + }); |
| 281 | + |
| 282 | + it('rejects SEMANTIC strategy with empty semanticOverride', () => { |
| 283 | + const result = MemoryStrategySchema.safeParse({ |
| 284 | + type: 'SEMANTIC', |
| 285 | + semanticOverride: {}, |
| 286 | + }); |
| 287 | + expect(result.success).toBe(false); |
| 288 | + }); |
| 289 | +}); |
0 commit comments