Files

32 lines
1.2 KiB
JavaScript

/* Exercise every attribution tool against the live database. */
import { connectMongo } from '../src/data/mongo.js';
import { attributionTools } from '../src/tools/crm/attribution.tools.js';
await connectMongo();
const cfg = { configurable: { user: { id: 'x', name: 'Test', role: 'admin' }, runtime: { toolCallCount: 0 } } };
const cases = [
['capi_health', { date_range: 'this_month' }],
['capi_funnel', { date_range: 'this_month' }],
['ad_form_leads', { date_range: 'all_time', group_by: 'campaign_name' }],
['template_responses', { date_range: 'last_90_days' }],
['comment_leads', { date_range: 'last_90_days' }],
];
let pass = 0;
for (const [name, args] of cases) {
const tool = attributionTools.find((t) => t.name === name);
try {
const raw = await tool.invoke(args, cfg);
const res = typeof raw === 'string' ? JSON.parse(raw) : raw;
if (res.ok === false) { console.log(`FAIL ${name}: ${res.error}`); continue; }
pass++;
console.log(`\nPASS ${name}`);
console.log(JSON.stringify(res.data ?? res, null, 1).slice(0, 800));
} catch (e) {
console.log(`FAIL ${name}: ${e.message.slice(0, 200)}`);
}
}
console.log(`\n${pass}/${cases.length} attribution tools passing`);
process.exit(0);