← back to Dw Signup Fulfillment

scripts/george-verify.js

39 lines

#!/usr/bin/env node
'use strict';
// One-shot verification that George's external-send path is healthy.
// Reads the static GEORGE_EXTERNAL_SEND_TOKEN + basic auth straight from
// ~/Projects/george-gmail/.env (never printed), then does ONE external send to
// claude@agentabrams.com (external → exercises the X-Send-Approval guard; lands
// in Steve's agent inbox, bothers no customer). Prints HTTP status + response.
//   Expected: HTTP 200 and no "blocked" field  → token path healthy.
//   HTTP 403 blocked                            → token mismatch (would need a fix).
// Run:  node ~/Projects/dw-signup-fulfillment/scripts/george-verify.js
// Use the project's own config so this test exercises the EXACT credential path the real
// sends use (config.GEORGE_BASIC_AUTH now resolves from secrets-manager GEORGE_AUTH and
// normalizes to user:pass; config.GEORGE_EXTERNAL_SEND_TOKEN is the static approval token).
const config = require('../lib/config');

const token = config.GEORGE_EXTERNAL_SEND_TOKEN;
const auth = config.GEORGE_BASIC_AUTH || 'admin:';
const basic = auth.startsWith('Basic ') ? auth : 'Basic ' + Buffer.from(auth.includes(':') ? auth : 'admin:' + auth).toString('base64');

console.log('token:', token ? 'SET (last4 ...' + token.slice(-4) + ')' : 'EMPTY');
console.log('basic-auth user:', auth.split(':')[0], '(pass-len ' + ((auth.split(':')[1] || '').length) + ')');

fetch((config.GEORGE_URL || 'http://127.0.0.1:9850') + '/api/send', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: basic, 'X-Send-Approval': token },
  body: JSON.stringify({
    account: 'steve-office',
    from: 'info@designerwallcoverings.com',
    to: 'claude@agentabrams.com',
    subject: '[George guard test] external-send verification',
    body: '<p>George external-send guard verification. If this lands, the GEORGE_EXTERNAL_SEND_TOKEN path is healthy and dw-signup welcome emails can flow.</p>',
  }),
  signal: AbortSignal.timeout(30000),
}).then((r) => r.json().catch(() => ({})).then((j) => {
  console.log('HTTP', r.status);
  console.log('resp', JSON.stringify(j).slice(0, 400));
  console.log(r.ok && !j.blocked && !j.error ? '\n✅ George external-send path is HEALTHY — no token fix needed.' : '\n❌ Send did not go through — see resp above.');
})).catch((e) => console.log('ERROR', e.message));