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