| 1 | import { createTestContext, cleanupTestContext, runCLI, createTestConfig } from "../test-helpers/cli-helpers.js"; |
| 2 | |
| 3 | describe("E2E: Headless Mode (Simple)", () => { |
| 4 | let context: any; |
| 5 | |
| 6 | const testConfig = `name: Test Assistant |
| 7 | version: 1.0.0 |
| 8 | schema: v1 |
| 9 | models: |
| 10 | - model: gpt-4 |
| 11 | provider: openai |
| 12 | apiKey: test-key |
| 13 | roles: |
| 14 | - chat`; |
| 15 | |
| 16 | const testEnv = { OPENAI_API_KEY: "test-key" }; |
| 17 | |
| 18 | beforeEach(async () => { |
| 19 | context = await createTestContext(); |
| 20 | }); |
| 21 | |
| 22 | afterEach(async () => { |
| 23 | await cleanupTestContext(context); |
| 24 | }); |
| 25 | |
| 26 | describe("basic headless functionality", () => { |
| 27 | it.skip("should output response and exit with -p flag", async () => { |
| 28 | // Skip this test as it requires mocking the LLM which doesn't work in subprocess |
| 29 | // This functionality is better tested with integration tests |
| 30 | }); |
| 31 | |
| 32 | it.skip("should handle streaming responses in headless mode", async () => { |
| 33 | // Skip this test as it requires mocking the LLM which doesn't work in subprocess |
| 34 | }); |
| 35 | |
| 36 | it("should fail gracefully when config is invalid", async () => { |
| 37 | // Test with invalid config |
| 38 | await createTestConfig(context, `invalid: yaml |
| 39 | no models here`); |
| 40 | |
| 41 | const result = await runCLI(context, { |
| 42 | args: ["-p", "--config", context.configPath, "Test"], |
| 43 | expectError: true, |
| 44 | }); |
| 45 | |
| 46 | expect(result.exitCode).not.toBe(0); |
| 47 | }); |
| 48 | |
| 49 | it.skip("should work with minimal config", async () => { |
| 50 | // Skip this test as it requires mocking the LLM which doesn't work in subprocess |
| 51 | }); |
| 52 | |
| 53 | it("should handle missing prompt in headless mode", async () => { |
| 54 | await createTestConfig(context, testConfig); |
| 55 | |
| 56 | const result = await runCLI(context, { |
| 57 | args: ["-p", "--config", context.configPath], |
| 58 | env: testEnv, |
| 59 | expectError: true, |
| 60 | }); |
| 61 | |
| 62 | expect(result.exitCode).not.toBe(0); |
| 63 | }); |
| 64 | |
| 65 | it("should accept piped input with -p flag", async () => { |
| 66 | await createTestConfig(context, testConfig); |
| 67 | |
| 68 | const result = await runCLI(context, { |
| 69 | args: ["-p", "--config", context.configPath], |
| 70 | env: testEnv, |
| 71 | input: "Hello from piped input", |
| 72 | expectError: true, |
| 73 | }); |
| 74 | |
| 75 | expect(result.stderr).not.toContain("You:"); |
| 76 | expect(result.stdout).not.toContain("You:"); |
| 77 | expect(result.exitCode).not.toBe(0); |
| 78 | }); |
| 79 | |
| 80 | it("should combine piped input with prompt argument", async () => { |
| 81 | await createTestConfig(context, testConfig); |
| 82 | |
| 83 | const result = await runCLI(context, { |
| 84 | args: ["-p", "--config", context.configPath, "Command line argument"], |
| 85 | env: testEnv, |
| 86 | input: "Piped input to be combined", |
| 87 | expectError: true, |
| 88 | }); |
| 89 | |
| 90 | expect(result.stderr).not.toContain("You:"); |
| 91 | expect(result.stdout).not.toContain("You:"); |
| 92 | expect(result.exitCode).not.toBe(0); |
| 93 | }); |
| 94 | |
| 95 | it("should work with only prompt argument", async () => { |
| 96 | await createTestConfig(context, testConfig); |
| 97 | |
| 98 | const result = await runCLI(context, { |
| 99 | args: ["-p", "--config", context.configPath, "Only command line argument"], |
| 100 | env: testEnv, |
| 101 | expectError: true, |
| 102 | }); |
| 103 | |
| 104 | expect(result.stderr).not.toContain("You:"); |
| 105 | expect(result.stdout).not.toContain("You:"); |
| 106 | expect(result.exitCode).not.toBe(0); |
| 107 | }); |
| 108 | }); |
| 109 | }); |