- pool.js: add pool.on('error') handler — an idle-client error (DB restart /
.215 failover) previously crashed the process (no 'error' listener → throw)
- context tool: project a SAFE_COLUMNS allow-list for resources (never the
monitoring/metadata JSON blobs); also add 'resource' to TABLE (was unhandled)
- applyPendingChange: guard the 'upsert' arm so a non-upsertable entity_type
fails with a clear ValidationError instead of a bare TypeError
Tests: pool_error, context (resource case), pending_extended_actions (guard).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.8 KiB
JavaScript
39 lines
1.8 KiB
JavaScript
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import { pool } from '../../../../lib/db/pool.js';
|
|
import { resetDb } from '../../../helpers/db.js';
|
|
import { migrateUp } from '../../../../lib/db/migrate.js';
|
|
import { contextTool } from '../../../../lib/ai/agent/tools/context.js';
|
|
|
|
let spaceId, taskId;
|
|
beforeAll(async () => {
|
|
await resetDb(); await migrateUp();
|
|
({ rows: [{ id: spaceId }] } = await pool.query(
|
|
`INSERT INTO spaces(slug,name) VALUES('s','S') RETURNING id`));
|
|
({ rows: [{ id: taskId }] } = await pool.query(
|
|
`INSERT INTO tasks(space_id,title) VALUES($1,'Wire telemetry') RETURNING id`, [spaceId]));
|
|
});
|
|
|
|
describe('context tool', () => {
|
|
it('summarises the current view entity', async () => {
|
|
const out = await contextTool.handler({}, { space_id: spaceId, view: { entityType: 'task', entityId: taskId } });
|
|
expect(out.entityType).toBe('task');
|
|
expect(out.title).toBe('Wire telemetry');
|
|
});
|
|
it('handles no active view', async () => {
|
|
const out = await contextTool.handler({}, { space_id: spaceId, view: null });
|
|
expect(out.note).toMatch(/no specific entity/i);
|
|
});
|
|
|
|
it('omits sensitive JSON blobs (monitoring/metadata) when grounding on a resource', async () => {
|
|
const { rows: [{ id: resId }] } = await pool.query(
|
|
`INSERT INTO resources(space_id, slug, name, runtime_type, monitoring, metadata)
|
|
VALUES($1,'db','DB','lxc','{"endpoint":"secret"}'::jsonb,'{"vault_path":"env:DB_PASS"}'::jsonb)
|
|
RETURNING id`, [spaceId]);
|
|
const out = await contextTool.handler({}, { space_id: spaceId, view: { entityType: 'resource', entityId: resId } });
|
|
expect(out.name).toBe('DB');
|
|
expect(out.status).toBe('unknown');
|
|
expect(out).not.toHaveProperty('monitoring');
|
|
expect(out).not.toHaveProperty('metadata');
|
|
});
|
|
});
|