Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions apps/framework-cli-e2e/test/s3-engine.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/// <reference types="node" />
/// <reference types="mocha" />
/// <reference types="chai" />
/**
* End-to-end tests for S3 engine runtime environment variable resolution
*
* These tests verify that:
* 1. mooseRuntimeEnv markers are correctly generated by TypeScript/Python libraries for S3 engine
* 2. Rust CLI correctly resolves the markers from environment variables at startup
* 3. Error messages include field names when environment variables are missing
* 4. Tables without credentials (public buckets with noSign) work correctly
* 5. System fails startup with clear error messages when env vars are missing
* 6. Resolved environment variable values are correctly used in infrastructure
*/

import { spawn, ChildProcess } from "child_process";
import { expect } from "chai";
import * as path from "path";

// Import test utilities
import { TIMEOUTS, TEMPLATE_NAMES, APP_NAMES } from "./constants";

import {
stopDevProcess,
waitForServerStart,
createTempTestDirectory,
setupTypeScriptProject,
setupPythonProject,
removeTestProject,
} from "./utils";

const CLI_PATH = path.resolve(__dirname, "../../../target/debug/moose-cli");
const MOOSE_LIB_PATH = path.resolve(
__dirname,
"../../../packages/ts-moose-lib",
);
const MOOSE_PY_LIB_PATH = path.resolve(
__dirname,
"../../../packages/py-moose-lib",
);

describe("typescript template tests - S3 Engine Runtime Environment Variable Resolution", () => {
describe("With Environment Variables", () => {
let devProcess: ChildProcess | null = null;
let TEST_PROJECT_DIR: string;

before(async function () {
this.timeout(TIMEOUTS.TEST_SETUP_MS);

// Create temporary directory
TEST_PROJECT_DIR = createTempTestDirectory("ts-s3-engine-set");

// Setup TypeScript project
await setupTypeScriptProject(
TEST_PROJECT_DIR,
TEMPLATE_NAMES.TYPESCRIPT_TESTS,
CLI_PATH,
MOOSE_LIB_PATH,
APP_NAMES.TYPESCRIPT_TESTS,
"npm",
);

// Start dev server WITH the required environment variables set
devProcess = spawn(CLI_PATH, ["dev"], {
stdio: "pipe",
cwd: TEST_PROJECT_DIR,
env: {
...process.env,
// Set dummy credentials for both S3 engine and S3Queue testing
// Both use the same env vars for consistency
TEST_AWS_ACCESS_KEY_ID: "test-access-key-id",
TEST_AWS_SECRET_ACCESS_KEY: "test-secret-access-key",
},
});

await waitForServerStart(
devProcess,
TIMEOUTS.SERVER_STARTUP_MS,
"started successfully",
"http://localhost:4000",
);
});

after(async function () {
this.timeout(TIMEOUTS.CLEANUP_MS);
await stopDevProcess(devProcess);
removeTestProject(TEST_PROJECT_DIR);
});

it("should start successfully and resolve S3 engine environment variables correctly", async function () {
this.timeout(TIMEOUTS.TEST_SETUP_MS);

// If we got here, the server started successfully with the environment variables set
// This verifies that:
// 1. mooseRuntimeEnv.get() markers were correctly generated by the TypeScript library
// 2. The Rust CLI successfully resolved the markers from environment variables
// 3. The resolved values were used to create the S3 engine table without errors
//
// If the environment variables were not resolved correctly, the server would have
// failed to start with an error message containing the table name and field name.
expect(devProcess?.killed).to.be.false;
});
});
});

describe("python template tests - S3 Engine Runtime Environment Variable Resolution", () => {
describe("With Environment Variables", () => {
let devProcess: ChildProcess | null = null;
let TEST_PROJECT_DIR: string;

before(async function () {
this.timeout(TIMEOUTS.TEST_SETUP_MS);

// Create temporary directory
TEST_PROJECT_DIR = createTempTestDirectory("py-s3-engine-set");

// Setup Python project
await setupPythonProject(
TEST_PROJECT_DIR,
TEMPLATE_NAMES.PYTHON_TESTS,
CLI_PATH,
MOOSE_PY_LIB_PATH,
APP_NAMES.PYTHON_TESTS,
);

// Start dev server WITH the required environment variables set
devProcess = spawn(CLI_PATH, ["dev"], {
stdio: "pipe",
cwd: TEST_PROJECT_DIR,
env: {
...process.env,
VIRTUAL_ENV: path.join(TEST_PROJECT_DIR, ".venv"),
PATH: `${path.join(TEST_PROJECT_DIR, ".venv", "bin")}:${process.env.PATH}`,
// Set dummy credentials for both S3 engine and S3Queue testing
// Both use the same env vars for consistency
TEST_AWS_ACCESS_KEY_ID: "test-access-key-id",
TEST_AWS_SECRET_ACCESS_KEY: "test-secret-access-key",
},
});

await waitForServerStart(
devProcess,
TIMEOUTS.SERVER_STARTUP_MS,
"started successfully",
"http://localhost:4000",
);
});

after(async function () {
this.timeout(TIMEOUTS.CLEANUP_MS);
await stopDevProcess(devProcess);
removeTestProject(TEST_PROJECT_DIR);
});

it("should start successfully and resolve S3 engine environment variables correctly", async function () {
this.timeout(TIMEOUTS.TEST_SETUP_MS);

// If we got here, the server started successfully with the environment variables set
// This verifies that:
// 1. moose_runtime_env.get() markers were correctly generated by the Python library
// 2. The Rust CLI successfully resolved the markers from environment variables
// 3. The resolved values were used to create the S3 engine table without errors
expect(devProcess?.killed).to.be.false;
});
});
});
12 changes: 8 additions & 4 deletions apps/framework-cli-e2e/test/s3-secrets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ describe("typescript template tests - S3Queue Runtime Environment Variable Resol
cwd: TEST_PROJECT_DIR,
env: {
...process.env,
// Set dummy credentials for testing
// Set dummy credentials for both S3Queue and S3 engine testing
// Both use the same env vars for consistency
TEST_AWS_ACCESS_KEY_ID: "test-access-key-id",
TEST_AWS_SECRET_ACCESS_KEY: "test-secret-access-key",
},
Expand Down Expand Up @@ -127,7 +128,8 @@ describe("typescript template tests - S3Queue Runtime Environment Variable Resol
cwd: TEST_PROJECT_DIR,
env: {
...process.env,
// Explicitly unset the environment variables
// Explicitly unset S3 credentials
// Both S3Queue and S3 engine use the same env vars
TEST_AWS_ACCESS_KEY_ID: undefined,
TEST_AWS_SECRET_ACCESS_KEY: undefined,
},
Expand Down Expand Up @@ -227,7 +229,8 @@ describe("python template tests - S3Queue Runtime Environment Variable Resolutio
...process.env,
VIRTUAL_ENV: path.join(TEST_PROJECT_DIR, ".venv"),
PATH: `${path.join(TEST_PROJECT_DIR, ".venv", "bin")}:${process.env.PATH}`,
// Set dummy credentials for testing
// Set dummy credentials for both S3Queue and S3 engine testing
// Both use the same env vars for consistency
TEST_AWS_ACCESS_KEY_ID: "test-access-key-id",
TEST_AWS_SECRET_ACCESS_KEY: "test-secret-access-key",
},
Expand Down Expand Up @@ -289,7 +292,8 @@ describe("python template tests - S3Queue Runtime Environment Variable Resolutio
...process.env,
VIRTUAL_ENV: path.join(TEST_PROJECT_DIR, ".venv"),
PATH: `${path.join(TEST_PROJECT_DIR, ".venv", "bin")}:${process.env.PATH}`,
// Explicitly unset the environment variables
// Explicitly unset S3 credentials
// Both S3Queue and S3 engine use the same env vars
TEST_AWS_ACCESS_KEY_ID: undefined,
TEST_AWS_SECRET_ACCESS_KEY: undefined,
},
Expand Down
48 changes: 48 additions & 0 deletions apps/framework-cli-e2e/test/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,54 @@ const createTemplateTestSuite = (config: TemplateTestConfig) => {
);
});

it("should create Buffer engine table correctly", async function () {
this.timeout(TIMEOUTS.TEST_SETUP_MS);

// Verify the destination table exists first
const destinationDDL = await getTableDDL(
"BufferDestinationTest",
"local",
);
console.log(`Destination table DDL: ${destinationDDL}`);

if (!destinationDDL.includes("ENGINE = MergeTree")) {
throw new Error(
`BufferDestinationTest should use MergeTree engine. DDL: ${destinationDDL}`,
);
}

// Verify the Buffer table exists and has correct configuration
const bufferDDL = await getTableDDL("BufferTest", "local");
console.log(`Buffer table DDL: ${bufferDDL}`);

// Check that it uses Buffer engine with correct parameters
if (!bufferDDL.includes("ENGINE = Buffer")) {
throw new Error(
`BufferTest should use Buffer engine. DDL: ${bufferDDL}`,
);
}

// Verify it points to the correct destination table
if (!bufferDDL.includes("BufferDestinationTest")) {
throw new Error(
`BufferTest should reference BufferDestinationTest. DDL: ${bufferDDL}`,
);
}

// Verify buffer parameters are present
if (
!bufferDDL.includes("16") ||
!bufferDDL.includes("10") ||
!bufferDDL.includes("100")
) {
throw new Error(
`BufferTest should have correct buffer parameters. DDL: ${bufferDDL}`,
);
}

console.log("✅ Buffer engine table created successfully");
});

it("should plan/apply TTL modifications on existing tables", async function () {
this.timeout(TIMEOUTS.TEST_SETUP_MS);

Expand Down
Loading
Loading