-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-semantic-api.js
More file actions
38 lines (31 loc) · 1.3 KB
/
test-semantic-api.js
File metadata and controls
38 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const pg = require('pg');
async function run() {
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
try {
const res = await pool.query('SELECT current_user, current_schema;');
console.log('Connected as:', res.rows[0]);
// Test heartbeat
await pool.query(
`INSERT INTO shared.agent_heartbeats (db_username, status, current_task_id, last_seen_at)
VALUES ($1, $2, $3, CURRENT_TIMESTAMP)
ON CONFLICT (db_username) DO UPDATE SET status = EXCLUDED.status, last_seen_at = CURRENT_TIMESTAMP`,
['orchestrator_user', 'online', null]
);
console.log('Heartbeat recorded.');
// Test lookup
const depts = await pool.query('SELECT * FROM shared.department_registry WHERE code = $1', ['dev']);
console.log('Dev department found:', depts.rows[0].db_username);
// Test create task
const taskRes = await pool.query(
`INSERT INTO shared.tasks (title, description, assignee, requester, priority, tags)
VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, status`,
['Test semantic APIs', 'Testing the DB rewrite', 'dev_user', 'orchestrator_user', 'P1', ['test', 'db']]
);
console.log('Task created:', taskRes.rows[0]);
} catch(e) {
console.error('Test error:', e);
} finally {
await pool.end();
}
}
run();