|
| 1 | +import { ConfigIO } from '../../../lib'; |
| 2 | +import { createDefaultProjectSpec } from '../../project'; |
| 3 | +import { HarnessPrimitive } from '../HarnessPrimitive'; |
| 4 | +import { randomUUID } from 'node:crypto'; |
| 5 | +import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'; |
| 6 | +import { tmpdir } from 'node:os'; |
| 7 | +import { join } from 'node:path'; |
| 8 | +import { afterEach, describe, expect, it } from 'vitest'; |
| 9 | + |
| 10 | +describe('HarnessPrimitive', () => { |
| 11 | + const tempDirs: string[] = []; |
| 12 | + |
| 13 | + afterEach(async () => { |
| 14 | + await Promise.all(tempDirs.map(dir => rm(dir, { recursive: true, force: true }))); |
| 15 | + tempDirs.length = 0; |
| 16 | + }); |
| 17 | + |
| 18 | + it('resolves create-flow Dockerfile paths from the command working directory', async () => { |
| 19 | + const commandCwd = join(tmpdir(), `harness-dockerfile-${randomUUID()}`); |
| 20 | + tempDirs.push(commandCwd); |
| 21 | + const projectRoot = join(commandCwd, 'HarnessProject'); |
| 22 | + const configBaseDir = join(projectRoot, 'agentcore'); |
| 23 | + await mkdir(projectRoot, { recursive: true }); |
| 24 | + |
| 25 | + const configIO = new ConfigIO({ baseDir: configBaseDir }); |
| 26 | + await configIO.initializeBaseDir(); |
| 27 | + await configIO.writeAWSDeploymentTargets([]); |
| 28 | + await configIO.writeDeployedState({ targets: {} }); |
| 29 | + await configIO.writeProjectSpec(createDefaultProjectSpec('HarnessProject')); |
| 30 | + |
| 31 | + await writeFile(join(commandCwd, 'Dockerfile.custom'), 'FROM public.ecr.aws/docker/library/python:3.12\n'); |
| 32 | + |
| 33 | + const result = await new HarnessPrimitive().add({ |
| 34 | + name: 'MyHarness', |
| 35 | + modelProvider: 'bedrock', |
| 36 | + modelId: 'global.anthropic.claude-sonnet-4-6', |
| 37 | + skipMemory: true, |
| 38 | + dockerfilePath: './Dockerfile.custom', |
| 39 | + dockerfileBaseDir: commandCwd, |
| 40 | + configBaseDir, |
| 41 | + }); |
| 42 | + |
| 43 | + expect(result.success).toBe(true); |
| 44 | + const harnessDir = join(projectRoot, 'app', 'MyHarness'); |
| 45 | + await expect(readFile(join(harnessDir, 'Dockerfile.custom'), 'utf-8')).resolves.toContain('python:3.12'); |
| 46 | + |
| 47 | + const harnessSpec = JSON.parse(await readFile(join(harnessDir, 'harness.json'), 'utf-8')); |
| 48 | + expect(harnessSpec.dockerfile).toBe('Dockerfile.custom'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments