verify-automation-ingest-smoke.mjs
85 lines 3.2 KB
Raw
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6 docs: record AIP-b SD-21 land (KN #308) Human 10 days ago
1 #!/usr/bin/env node
2 /**
3 * Local/test default smoke for AIP ingest.
4 * Does not print credentials or JWTs. Production URL is Operator T2 — this script
5 * must not be cited as production smoke.
6 *
7 * Usage:
8 * KNOWTATION_HUB_URL=http://127.0.0.1:3340 \
9 * KNOWTATION_HUB_SESSION_JWT=… \
10 * node scripts/verify-automation-ingest-smoke.mjs
11 */
12
13 const apiBase = (process.env.KNOWTATION_HUB_URL || 'http://127.0.0.1:3340').replace(/\/$/, '');
14 const vaultId = process.env.KNOWTATION_HUB_VAULT_ID || 'default';
15
16 function fail(step, detail) {
17 console.log(`FAIL ${step}: ${detail}`);
18 process.exit(1);
19 }
20
21 function redact(value) {
22 const s = String(value || '');
23 if (!s) return '(empty)';
24 return `${s.slice(0, 8)}… len=${s.length}`;
25 }
26
27 const session = (process.env.KNOWTATION_HUB_SESSION_JWT || '').trim();
28 const agentJwt = (process.env.KNOWTATION_HUB_AGENT_ACCESS_JWT || '').trim();
29 if (session) console.log(`session=${redact(session)}`);
30 if (agentJwt) console.log(`agent_access=${redact(agentJwt)}`);
31 if (session.toLowerCase().includes('kt_agent_') || agentJwt.toLowerCase().includes('kt_agent_')) {
32 fail('setup', 'refusing to continue: do not pass opaque kt_agent_ credentials on the command line of this script');
33 }
34
35 console.log(`api=${apiBase} (local/test default; not a production-smoke claim)`);
36 console.log(`vault=${vaultId}`);
37
38 const health = await fetch(`${apiBase}/health`);
39 console.log(`health status=${health.status}`);
40 if (!health.ok) fail('health', `HTTP ${health.status}`);
41
42 if (!session && !agentJwt) {
43 console.log('PASS health-only (no session/agent JWT supplied; CRUD/ingest skipped)');
44 process.exit(0);
45 }
46
47 if (session) {
48 const rules = await fetch(`${apiBase}/api/v1/automation/ingest-rules`, {
49 headers: { Authorization: `Bearer ${session}`, Accept: 'application/json' },
50 });
51 const text = await rules.text();
52 let json = {};
53 try { json = JSON.parse(text); } catch { json = { parse: 'failed' }; }
54 console.log(`ingest-rules status=${rules.status} code=${json.code || 'ok'} templates=${Array.isArray(json.templates) ? json.templates.length : 0}`);
55 if (rules.status !== 200) fail('ingest-rules', `HTTP ${rules.status} code=${json.code || ''}`);
56 const enabledPack = Array.isArray(json.templates) && json.templates.some((t) => t && t.enabled === true);
57 if (enabledPack) fail('pack', 'packaged templates must stay disabled');
58 }
59
60 if (agentJwt) {
61 const ingest = await fetch(`${apiBase}/api/v1/automation/ingest`, {
62 method: 'POST',
63 headers: {
64 Authorization: `Bearer ${agentJwt}`,
65 Accept: 'application/json',
66 'Content-Type': 'application/json',
67 'X-Vault-Id': vaultId,
68 },
69 body: JSON.stringify({
70 path: 'inbox/trends/smoke-local.md',
71 body: 'local smoke',
72 source_fingerprint: 'local-smoke-01',
73 content_class: 'research',
74 }),
75 });
76 const text = await ingest.text();
77 let json = {};
78 try { json = JSON.parse(text); } catch { json = { parse: 'failed' }; }
79 console.log(`ingest status=${ingest.status} code=${json.code || 'ok'} disposition=${json.disposition || ''}`);
80 if (ingest.status !== 200 && ingest.status !== 201) {
81 fail('ingest', `HTTP ${ingest.status} code=${json.code || ''}`);
82 }
83 }
84
85 console.log('PASS local/test ingest smoke');
File History 1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6 docs: record AIP-b SD-21 land (KN #308) Human 10 days ago