Files
2026-05-21 20:22:56 +02:00

26 lines
1.6 KiB
JavaScript

import assert from 'node:assert/strict';
const base = process.env.RANK_BASE_URL || `http://127.0.0.1:${process.env.PORT || 3045}`;
const token = process.env.RANK_AGENT_TOKEN || process.env.PRIORITY_AGENT_TOKEN || '';
const headers = { 'Content-Type': 'application/json' };
if (token) headers.Authorization = `Bearer ${token}`;
async function req(path, options = {}) {
const res = await fetch(`${base}${path}`, { headers: { ...headers, ...(options.headers || {}) }, ...options, body: options.body && typeof options.body !== 'string' ? JSON.stringify(options.body) : options.body });
const text = await res.text();
const data = text ? JSON.parse(text) : null;
if (!res.ok) throw new Error(`${res.status} ${path}: ${data?.error || text}`);
return data;
}
const health = await req('/api/health');
assert.equal(health.ok, true, 'health ok');
const created = await req('/api/ideas', { method: 'POST', body: { title: `Smoke test ${new Date().toISOString()}`, description: 'Automated persistence check. Safe to archive.', source: 'agent', sourceName: 'smoke', labels: ['smoke'], impact: 3, effort: 1, confidence: 8, urgency: 1 } });
assert.ok(created.id, 'created id');
const updated = await req(`/api/ideas/${created.id}`, { method: 'PATCH', body: { milestoneId: 'later', notes: 'Verified create + update path.' } });
assert.equal(updated.milestoneId, 'later');
await req(`/api/ideas/${created.id}`, { method: 'PATCH', body: { archived: true } });
const boot = await req('/api/bootstrap');
assert.ok(Array.isArray(boot.ideas), 'ideas list');
console.log(JSON.stringify({ ok: true, created: created.id, archived: true, count: boot.ideas.length }, null, 2));