@devries-cameron20 / composio-1 / commits / 80f0b445f
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat(ts/e2e): restore DEBUG.log, env var validation

jkomyno committed Jan 30, 2026 at 15:18 UTC 80f0b445f0cd341591b9b1dac97e4ddd89b2eba5
1 file changed +95 -4
ts/e2e-tests/_utils/src/runner.ts
+95 -4
@@ -1,9 +1,58 @@
1 import { describe, beforeAll, it } from 'bun:test';
2 +import { appendFile } from 'node:fs/promises';
3 +import { resolve } from 'node:path';
4 import type { E2EConfig, E2ETestResult, NodeVersionMeta } from './types';
5 import { getRepoRoot, resolveNodeVersionMetaList } from './config';
6 import { ensureNodeImage, runNodeContainer } from './image-lifecycle';
7 import { WELL_KNOWN_ENV_VARS } from './const'
8
9 +/**
10 + * Debug log entry metadata.
11 + */
12 +interface DebugLogEntry {
13 + nodeVersion: string;
14 + command: string;
15 + containerName: string;
16 + result: E2ETestResult;
17 +}
18 +
19 +/**
20 + * Writes Docker run output to DEBUG.log in the test directory.
21 + * Appends to the file so multiple test runs are preserved.
22 + *
23 + * @param repoRoot - Absolute path to the repository root
24 + * @param testDirRelative - Path to test directory relative to repo root
25 + * @param entry - Debug log entry with command and result metadata
26 + */
27 +async function writeDebugLog(
28 + repoRoot: string,
29 + testDirRelative: string,
30 + entry: DebugLogEntry
31 +): Promise<void> {
32 + const logPath = resolve(repoRoot, testDirRelative, 'DEBUG.log');
33 + const timestamp = new Date().toISOString();
34 +
35 + const content = [
36 + '',
37 + `=== Docker Run: ${timestamp} ===`,
38 + `Node.js: ${entry.nodeVersion}`,
39 + `Command: ${entry.command}`,
40 + `Container: ${entry.containerName}`,
41 + `Exit Code: ${entry.result.exitCode}`,
42 + '',
43 + '--- stdout ---',
44 + entry.result.stdout || '(empty)',
45 + '',
46 + '--- stderr ---',
47 + entry.result.stderr || '(empty)',
48 + '',
49 + `=== End (Exit Code: ${entry.result.exitCode}) ===`,
50 + '',
51 + ].join('\n');
52 +
53 + await appendFile(logPath, content);
54 +}
55 +
56 /**
57 * Builds environment variables to pass to the container.
58 * Merges auto-passthrough vars with explicitly provided env vars.
@@ -26,6 +75,33 @@ function buildContainerEnv(
75 return env;
76 }
77
78 +/**
79 + * Validates that env vars passed to E2EConfig don't have undefined values.
80 + * When a test passes `process.env.SOME_VAR` and it's not set, we want to
81 + * fail fast with a clear error rather than silently passing undefined to Docker.
82 + *
83 + * @param env - Environment variables from E2EConfig
84 + * @param suiteName - Test suite name for error context
85 + * @throws Error if any env vars have undefined values
86 + */
87 +function validateRequiredEnvVars(
88 + env: Record<string, string | undefined> | undefined,
89 + suiteName: string
90 +): void {
91 + if (!env) return;
92 +
93 + const missingVars = Object.entries(env)
94 + .filter(([, value]) => value === undefined)
95 + .map(([key]) => key);
96 +
97 + if (missingVars.length > 0) {
98 + throw new Error(
99 + `[${suiteName}] Missing required environment variables: ${missingVars.join(', ')}\n` +
100 + `Set these variables before running the tests, or remove them from E2EConfig.env if not required.`
101 + );
102 + }
103 +}
104 +
105 /**
106 * Internal configuration for runE2E.
107 */
@@ -40,20 +116,31 @@ interface RunE2EInternalConfig extends E2EConfig {
116 function createDockerExecutors(
117 config: RunE2EInternalConfig,
118 nodeVersion: string,
43 - imageTag: string
119 + imageTag: string,
120 + repoRoot: string
121 ) {
122 const { cwd, suiteName, env } = config;
123 const containerEnv = buildContainerEnv(env);
124
125 const runCmd = async (command: string): Promise<E2ETestResult> => {
126 const containerName = `e2e-${suiteName}-${nodeVersion.replace(/\./g, '-')}-${Date.now()}`;
50 - return runNodeContainer({
127 + const result = await runNodeContainer({
128 imageTag,
129 cmd: command,
130 cwd,
131 env: containerEnv,
132 name: containerName,
133 });
134 +
135 + // Write output to DEBUG.log for debugging and CI troubleshooting
136 + await writeDebugLog(repoRoot, cwd, {
137 + nodeVersion,
138 + command,
139 + containerName,
140 + result,
141 + });
142 +
143 + return result;
144 };
145
146 const runFixture = async (fixturePath: string): Promise<E2ETestResult> => {
@@ -71,7 +158,11 @@ function createDockerExecutors(
158 * Each version's skipInCI state is computed by resolveNodeVersionMetaList().
159 */
160 export function runE2E(config: RunE2EInternalConfig): void {
74 - const { suiteName, defineTests } = config;
161 + const { suiteName, defineTests, env } = config;
162 +
163 + // Validate env vars early, before any Docker operations
164 + validateRequiredEnvVars(env, suiteName);
165 +
166 const nodeVersionMetaList = resolveNodeVersionMetaList(config.nodeVersions);
167 const repoRoot = getRepoRoot();
168
@@ -103,7 +194,7 @@ export function runE2E(config: RunE2EInternalConfig): void {
194 // Ensure Docker image exists before tests run
195 beforeAll(async () => {
196 const imageTag = await ensureNodeImage(nodeVersionMeta.value, { repoRoot });
106 - executors = createDockerExecutors(config, nodeVersionMeta.value, imageTag);
197 + executors = createDockerExecutors(config, nodeVersionMeta.value, imageTag, repoRoot);
198 }, 600_000); // 10 minute timeout for Docker image build
199
200 // Call user's defineTests with bun:test functions and Docker utilities