From 14c3dd4d0314e1e1eafb6d0cc623edda39832ba7 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:43:19 +0100 Subject: [PATCH 1/8] refactor: move sanity test to src --- {test => src}/sanity.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {test => src}/sanity.test.ts (100%) diff --git a/test/sanity.test.ts b/src/sanity.test.ts similarity index 100% rename from test/sanity.test.ts rename to src/sanity.test.ts From b1c5ac97b9fcaf9a3616d5adfba360078a2d01e5 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:43:30 +0100 Subject: [PATCH 2/8] chore: update test scripts in package.json to streamline testing process --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index ab2589f..5ea1b62 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "build:ci": "npm run build:ts && npm run build:copy", "build:dev": "pnpm run build:ts && pnpm run build:copy", "build:ts": "tsup", - "build:test": "tsup --entry 'src/**/*.ts' --entry 'test/**/*.ts'", "build:copy": "node scripts/copy-assets.js", "start": "node dist/index.js", "dev": "tsx watch src/index.ts", @@ -23,8 +22,7 @@ "check:fix": "biome check --write .", "typecheck": "tsc --noEmit", "test": "pnpm run build:dev && node --test dist/**/*.test.js", - "test:ci": "node --test $(find dist -name '*.test.js')", - "test:build": "npm run build:test && npm run test:ci", + "test:ci": "NODE_ENV=test node --test dist/**/*.test.js", "prepare": "husky", "pre-commit": "lint-staged", "sync-guides": "tsx scripts/sync-guides.js", From d57b0b526d583910c713f1ab0a0bedaa8421bf0d Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:43:37 +0100 Subject: [PATCH 3/8] feat: add support for loading test environment variables in loadEnvFile.ts --- src/loadEnvFile.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/loadEnvFile.ts b/src/loadEnvFile.ts index 793ec4f..7d1b270 100644 --- a/src/loadEnvFile.ts +++ b/src/loadEnvFile.ts @@ -46,3 +46,9 @@ if (nodeEnv === 'production') { // Required for DISCORD_TOKEN and other secrets const localEnvFile = join(process.cwd(), '.env'); loadEnvFile(localEnvFile); + +if (nodeEnv === 'test') { + console.log('๐Ÿงช Loading test environment variables'); + const testEnvFile = join(process.cwd(), '.env.test'); + loadEnvFile(testEnvFile); +} From 9e24575c67d3b4567bd5ccb650f5424fb8483ae8 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:46:36 +0100 Subject: [PATCH 4/8] chore: update GitHub Actions test workflow to use npm run test:ci instead of npm run test:build --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 147345b..8d63fe9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,5 +36,5 @@ jobs: run: npm run lint - name: Build and test - run: npm run test:build + run: npm run test:ci From 1346ec4eb251c88c9a391b448d6a3a727f00ba50 Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:47:02 +0100 Subject: [PATCH 5/8] chore: update GitHub Actions workflow to separate build and test steps for clarity --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d63fe9..dca8271 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,9 @@ jobs: - name: Lint run: npm run lint - - name: Build and test + - name: Build + run: npm run build:ci + + - name: Test run: npm run test:ci From 171efcdaacfa1838374bde3686545b35d35e8e2b Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:48:18 +0100 Subject: [PATCH 6/8] chore: add .env.test file for local environment variable configuration and update .gitignore to include it --- .env.test | 24 ++++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 25 insertions(+) create mode 100644 .env.test diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..a5d0f74 --- /dev/null +++ b/.env.test @@ -0,0 +1,24 @@ +# Local Environment Variables (Secrets) +# Copy this file to .env and fill in your actual values +# .env is gitignored and should NEVER be committed + +# Discord Bot Token & Application ID (REQUIRED) +# Get this from: https://discord.com/developers/applications +DISCORD_TOKEN=your-bot-token-here +CLIENT_ID=your-bot-application-id + +# Override any public config values for local testing + +# Discord Server ID (your dev server) +SERVER_ID=your-server-id + +# Channel IDs (from your dev server) +GUIDES_CHANNEL_ID=your-guide-channel-id +REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id + +# Role IDs (from your dev server) +REPEL_ROLE_ID=your-repel-role-id +MODERATORS_ROLE_IDS=your-moderator-role-id + +# Other +GUIDES_TRACKER_PATH=guides-tracker.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 67b2b83..34cf7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ yarn-error.log* # Public config (committed to repo) !.env.production !.env.example +!.env.test # guides tracker guides-tracker.json From 82d89ff358720ea6b806668de3485b91b378a28d Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 19:50:59 +0100 Subject: [PATCH 7/8] refactor: reorganize loadEnvFile function to ensure environment-specific configurations are loaded correctly --- src/loadEnvFile.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/loadEnvFile.ts b/src/loadEnvFile.ts index 7d1b270..5054a8c 100644 --- a/src/loadEnvFile.ts +++ b/src/loadEnvFile.ts @@ -36,19 +36,19 @@ function loadEnvFile(filePath: string) { const nodeEnv = process.env.NODE_ENV || 'development'; console.log(`๐ŸŒ Environment: ${nodeEnv}`); -// Load environment-specific config first (public values, production only) -if (nodeEnv === 'production') { - const envFile = join(process.cwd(), '.env.production'); - loadEnvFile(envFile); -} - -// Load .env file with secrets and local config (overrides public config if any) -// Required for DISCORD_TOKEN and other secrets -const localEnvFile = join(process.cwd(), '.env'); -loadEnvFile(localEnvFile); - if (nodeEnv === 'test') { console.log('๐Ÿงช Loading test environment variables'); const testEnvFile = join(process.cwd(), '.env.test'); loadEnvFile(testEnvFile); +} else { + // Load environment-specific config first (public values, production only) + if (nodeEnv === 'production') { + const envFile = join(process.cwd(), '.env.production'); + loadEnvFile(envFile); + } + + // Load .env file with secrets and local config (overrides public config if any) + // Required for DISCORD_TOKEN and other secrets + const localEnvFile = join(process.cwd(), '.env'); + loadEnvFile(localEnvFile); } From 5b44e1c8961c0deb078e19b43b757c278c4536bb Mon Sep 17 00:00:00 2001 From: Wiktoria Van Harneveldt Date: Wed, 12 Nov 2025 20:00:47 +0100 Subject: [PATCH 8/8] refactor: streamline loadEnvFile function to utilize a mapping for environment-specific files --- src/loadEnvFile.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/loadEnvFile.ts b/src/loadEnvFile.ts index 5054a8c..ffdcb85 100644 --- a/src/loadEnvFile.ts +++ b/src/loadEnvFile.ts @@ -36,19 +36,16 @@ function loadEnvFile(filePath: string) { const nodeEnv = process.env.NODE_ENV || 'development'; console.log(`๐ŸŒ Environment: ${nodeEnv}`); -if (nodeEnv === 'test') { - console.log('๐Ÿงช Loading test environment variables'); - const testEnvFile = join(process.cwd(), '.env.test'); - loadEnvFile(testEnvFile); -} else { - // Load environment-specific config first (public values, production only) - if (nodeEnv === 'production') { - const envFile = join(process.cwd(), '.env.production'); - loadEnvFile(envFile); - } +const ENV_FILES = { + test: join(process.cwd(), '.env.test'), + production: join(process.cwd(), '.env.production'), + development: join(process.cwd(), '.env'), +}; - // Load .env file with secrets and local config (overrides public config if any) - // Required for DISCORD_TOKEN and other secrets - const localEnvFile = join(process.cwd(), '.env'); - loadEnvFile(localEnvFile); +const envFile = ENV_FILES[nodeEnv as keyof typeof ENV_FILES]; +if (envFile) { + loadEnvFile(envFile); +} else { + console.error(`โŒ Environment file ${nodeEnv} not found`); + process.exit(1); }