#!/usr/bin/env node // Phase 5C §24 — the OPTIONAL, opt-in Google Workspace live-delivery test. Does NOTHING unless // explicitly enabled — no test/regression run ever sends real email by accident. // // Usage (only when you actually have real Workspace credentials configured): // RUN_GWS_EMAIL_TEST=true \ // TEST_EMAIL_RECIPIENT=you@example.com \ // GOOGLE_SERVICE_ACCOUNT_JSON='{"client_email":"...","private_key":"..."}' \ // EMAIL_FROM_ADDRESS=noreply@rootnodeacademy.com \ // EMAIL_FROM_NAME="RootNode Academy" \ // node infra/scripts/gws-email-test.js // // Sends exactly ONE clearly-marked test message to TEST_EMAIL_RECIPIENT — never a // production/student address, never inferred from anything in the database. Run it once after // setting up domain-wide delegation to confirm the adapter actually works against the real // Gmail API, not as part of any regular regression pass (see docs/RUNBOOK_GOOGLE_WORKSPACE_EMAIL.md). if (process.env.RUN_GWS_EMAIL_TEST !== 'true') { console.log('Skipped: set RUN_GWS_EMAIL_TEST=true to actually send a live test email. Nothing was sent.'); process.exit(0); } const recipient = process.env.TEST_EMAIL_RECIPIENT; if (!recipient) { console.error('Set TEST_EMAIL_RECIPIENT to the ONE address this test should send to — it is never inferred from anything else.'); process.exit(1); } const provider = require('../../platform/api/src/email/gws-provider'); async function main() { console.log(`Sending one live test message via the Gmail API adapter to ${recipient}...`); const result = await provider.send({ to: recipient, fromName: process.env.EMAIL_FROM_NAME || 'RootNode Academy', fromAddress: process.env.EMAIL_FROM_ADDRESS, replyTo: process.env.EMAIL_REPLY_TO, subject: '[RootNode Academy] Google Workspace adapter test', text: `This is a one-off test of RootNode Academy's Google Workspace email adapter (Gmail API, service account domain-wide delegation). If you received this, live delivery is working. Sent at ${new Date().toISOString()}.`, html: `
This is a one-off test of RootNode Academy's Google Workspace email adapter (Gmail API, service account domain-wide delegation).
If you received this, live delivery is working. Sent at ${new Date().toISOString()}.
`, }); console.log('Provider accepted the message.'); console.log('Provider message ID:', result.providerMessageId); console.log('\nGWS LIVE DELIVERY TEST: PASSED'); } main().catch((e) => { console.error('GWS LIVE DELIVERY TEST: FAILED'); console.error(` ${e.errorCode || 'error'}: ${e.message}`); process.exit(1); });