|
| 1 | +import { createTestProject, readProjectConfig, runCLI } from '../src/test-utils/index.js'; |
| 2 | +import type { TestProject } from '../src/test-utils/index.js'; |
| 3 | +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
| 4 | + |
| 5 | +describe('integration: add and remove resources', () => { |
| 6 | + let project: TestProject; |
| 7 | + |
| 8 | + beforeAll(async () => { |
| 9 | + project = await createTestProject({ |
| 10 | + language: 'Python', |
| 11 | + framework: 'Strands', |
| 12 | + modelProvider: 'Bedrock', |
| 13 | + memory: 'none', |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + afterAll(async () => { |
| 18 | + await project.cleanup(); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('memory lifecycle', () => { |
| 22 | + const memoryName = `IntegMem${Date.now().toString().slice(-6)}`; |
| 23 | + |
| 24 | + it('adds a memory resource', async () => { |
| 25 | + const result = await runCLI(['add', 'memory', '--name', memoryName, '--json'], project.projectPath); |
| 26 | + |
| 27 | + expect(result.exitCode, `stdout: ${result.stdout}, stderr: ${result.stderr}`).toBe(0); |
| 28 | + const json = JSON.parse(result.stdout); |
| 29 | + expect(json.success).toBe(true); |
| 30 | + |
| 31 | + // Verify config updated |
| 32 | + const config = await readProjectConfig(project.projectPath); |
| 33 | + const memories = config.memories as Record<string, unknown>[] | undefined; |
| 34 | + expect(memories, 'memories should exist').toBeDefined(); |
| 35 | + const found = memories!.some((m: Record<string, unknown>) => m.name === memoryName); |
| 36 | + expect(found, `Memory "${memoryName}" should be in config`).toBe(true); |
| 37 | + }); |
| 38 | + |
| 39 | + it('removes the memory resource', async () => { |
| 40 | + const result = await runCLI(['remove', 'memory', '--name', memoryName, '--json'], project.projectPath); |
| 41 | + |
| 42 | + expect(result.exitCode, `stdout: ${result.stdout}, stderr: ${result.stderr}`).toBe(0); |
| 43 | + const json = JSON.parse(result.stdout); |
| 44 | + expect(json.success).toBe(true); |
| 45 | + |
| 46 | + // Verify config updated |
| 47 | + const config = await readProjectConfig(project.projectPath); |
| 48 | + const memories = (config.memories as Record<string, unknown>[] | undefined) ?? []; |
| 49 | + const found = memories.some((m: Record<string, unknown>) => m.name === memoryName); |
| 50 | + expect(found, `Memory "${memoryName}" should be removed from config`).toBe(false); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('identity lifecycle', () => { |
| 55 | + const identityName = `IntegId${Date.now().toString().slice(-6)}`; |
| 56 | + |
| 57 | + it('adds an identity resource', async () => { |
| 58 | + const result = await runCLI( |
| 59 | + ['add', 'identity', '--name', identityName, '--api-key', 'test-key-integ-123', '--json'], |
| 60 | + project.projectPath |
| 61 | + ); |
| 62 | + |
| 63 | + expect(result.exitCode, `stdout: ${result.stdout}, stderr: ${result.stderr}`).toBe(0); |
| 64 | + const json = JSON.parse(result.stdout); |
| 65 | + expect(json.success).toBe(true); |
| 66 | + |
| 67 | + // Verify config updated |
| 68 | + const config = await readProjectConfig(project.projectPath); |
| 69 | + const credentials = config.credentials as Record<string, unknown>[] | undefined; |
| 70 | + expect(credentials, 'credentials should exist').toBeDefined(); |
| 71 | + const found = credentials!.some((c: Record<string, unknown>) => c.name === identityName); |
| 72 | + expect(found, `Identity "${identityName}" should be in config`).toBe(true); |
| 73 | + }); |
| 74 | + |
| 75 | + it('removes the identity resource', async () => { |
| 76 | + const result = await runCLI(['remove', 'identity', '--name', identityName, '--json'], project.projectPath); |
| 77 | + |
| 78 | + expect(result.exitCode, `stdout: ${result.stdout}, stderr: ${result.stderr}`).toBe(0); |
| 79 | + const json = JSON.parse(result.stdout); |
| 80 | + expect(json.success).toBe(true); |
| 81 | + |
| 82 | + // Verify config updated |
| 83 | + const config = await readProjectConfig(project.projectPath); |
| 84 | + const credentials = (config.credentials as Record<string, unknown>[] | undefined) ?? []; |
| 85 | + const found = credentials.some((c: Record<string, unknown>) => c.name === identityName); |
| 86 | + expect(found, `Identity "${identityName}" should be removed from config`).toBe(false); |
| 87 | + }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments