Skip to content

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

jkomyno80f0b445f0cd
diff --git a/ts/e2e-tests/_utils/src/runner.ts b/ts/e2e-tests/_utils/src/runner.ts
index 1eaf1f4ad..f13dd5540 100644
--- a/ts/e2e-tests/_utils/src/runner.ts
+++ b/ts/e2e-tests/_utils/src/runner.ts
@@ -1,9 +1,58 @@
import { describe, beforeAll, it } from 'bun:test';
+import { appendFile } from 'node:fs/promises';
+import { resolve } from 'node:path';
import type { E2EConfig, E2ETestResult, NodeVersionMeta } from './types';
import { getRepoRoot, resolveNodeVersionMetaList } from './config';
import { ensureNodeImage, runNodeContainer } from './image-lifecycle';
import { WELL_KNOWN_ENV_VARS } from './const'
+/**
+ * Debug log entry metadata.
+ */
+interface DebugLogEntry {
+ nodeVersion: string;
+ command: string;
+ containerName: string;
+ result: E2ETestResult;
+}
+
+/**
+ * Writes Docker run output to DEBUG.log in the test directory.
+ * Appends to the file so multiple test runs are preserved.
+ *
+ * @param repoRoot - Absolute path to the repository root
+ * @param testDirRelative - Path to test directory relative to repo root
+ * @param entry - Debug log entry with command and result metadata
+ */
+async function writeDebugLog(
+ repoRoot: string,
+ testDirRelative: string,
+ entry: DebugLogEntry
+): Promise<void> {
+ const logPath = resolve(repoRoot, testDirRelative, 'DEBUG.log');
+ const timestamp = new Date().toISOString();
+
+ const content = [
+ '',
+ `=== Docker Run: ${timestamp} ===`,
+ `Node.js: ${entry.nodeVersion}`,
+ `Command: ${entry.command}`,
+ `Container: ${entry.containerName}`,
+ `Exit Code: ${entry.result.exitCode}`,
+ '',
+ '--- stdout ---',
+ entry.result.stdout || '(empty)',
+ '',
+ '--- stderr ---',
+ entry.result.stderr || '(empty)',
+ '',
+ `=== End (Exit Code: ${entry.result.exitCode}) ===`,
+ '',
+ ].join('\n');
+
+ await appendFile(logPath, content);
+}
+
/**
* Builds environment variables to pass to the container.
* Merges auto-passthrough vars with explicitly provided env vars.
@@ -26,6 +75,33 @@ function buildContainerEnv(
return env;
}
+/**
+ * Validates that env vars passed to E2EConfig don't have undefined values.
+ * When a test passes `process.env.SOME_VAR` and it's not set, we want to
+ * fail fast with a clear error rather than silently passing undefined to Docker.
+ *
+ * @param env - Environment variables from E2EConfig
+ * @param suiteName - Test suite name for error context
+ * @throws Error if any env vars have undefined values
+ */
+function validateRequiredEnvVars(
+ env: Record<string, string | undefined> | undefined,
+ suiteName: string
+): void {
+ if (!env) return;
+
+ const missingVars = Object.entries(env)
+ .filter(([, value]) => value === undefined)
+ .map(([key]) => key);
+
+ if (missingVars.length > 0) {
+ throw new Error(
+ `[${suiteName}] Missing required environment variables: ${missingVars.join(', ')}\n` +
+ `Set these variables before running the tests, or remove them from E2EConfig.env if not required.`
+ );
+ }
+}
+
/**
* Internal configuration for runE2E.
*/
@@ -40,20 +116,31 @@ interface RunE2EInternalConfig extends E2EConfig {
function createDockerExecutors(
config: RunE2EInternalConfig,
nodeVersion: string,
- imageTag: string
+ imageTag: string,
+ repoRoot: string
) {
const { cwd, suiteName, env } = config;
const containerEnv = buildContainerEnv(env);
const runCmd = async (command: string): Promise<E2ETestResult> => {
const containerName = `e2e-${suiteName}-${nodeVersion.replace(/\./g, '-')}-${Date.now()}`;
- return runNodeContainer({
+ const result = await runNodeContainer({
imageTag,
cmd: command,
cwd,
env: containerEnv,
name: containerName,
});
+
+ // Write output to DEBUG.log for debugging and CI troubleshooting
+ await writeDebugLog(repoRoot, cwd, {
+ nodeVersion,
+ command,
+ containerName,
+ result,
+ });
+
+ return result;
};
const runFixture = async (fixturePath: string): Promise<E2ETestResult> => {
@@ -71,7 +158,11 @@ function createDockerExecutors(
* Each version's skipInCI state is computed by resolveNodeVersionMetaList().
*/
export function runE2E(config: RunE2EInternalConfig): void {
- const { suiteName, defineTests } = config;
+ const { suiteName, defineTests, env } = config;
+
+ // Validate env vars early, before any Docker operations
+ validateRequiredEnvVars(env, suiteName);
+
const nodeVersionMetaList = resolveNodeVersionMetaList(config.nodeVersions);
const repoRoot = getRepoRoot();
@@ -103,7 +194,7 @@ export function runE2E(config: RunE2EInternalConfig): void {
// Ensure Docker image exists before tests run
beforeAll(async () => {
const imageTag = await ensureNodeImage(nodeVersionMeta.value, { repoRoot });
- executors = createDockerExecutors(config, nodeVersionMeta.value, imageTag);
+ executors = createDockerExecutors(config, nodeVersionMeta.value, imageTag, repoRoot);
}, 600_000); // 10 minute timeout for Docker image build
// Call user's defineTests with bun:test functions and Docker utilities