test(server): seed the plugin specs through the repositories

The plugin service, instance and user settings, OAuth, audit, route
profile, host state and request context suites seeded plugin rows,
settings fields, actions, tokens and audit entries with raw statements
and read them back the same way. They now go through the ORM factories
and readers over the suite's own test ORM.

Two raw statements stay, marked: the PRAGMA table_info read that proves
the actions scope column exists, and the audit insert that reproduces
the pre-conversion appendAudit byte for byte for the hash chain parity
check. The instance settings suite's stubbed isActive now follows the
status the test flips through markActive instead of a synchronous read.
This commit is contained in:
Maurice
2026-10-08 16:03:41 +02:00
parent f73f395817
commit 57404dee17
8 changed files with 248 additions and 210 deletions
@@ -10,6 +10,7 @@ import { createSnapshotTestDb } from '../../helpers/db-mock';
import { resetTestDb } from '../../helpers/test-db';
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
import { PluginCapabilityAudit } from '../../../src/db/entities/PluginCapabilityAudit.entity';
import { updateRows } from '../../helpers/factories/rows';
import type { PluginCapabilityAuditRepository } from '../../../src/db/repositories/PluginCapabilityAudit.repository';
import { appendAudit } from '../../../src/nest/plugins/host/plugin-audit';
import { budgetFor, pluginBudgetUsage } from '../../../src/nest/plugins/host/plugin-host-state';
@@ -61,7 +62,7 @@ describe('budgetFor / pluginBudgetUsage seed read', () => {
// Backdate the row to yesterday, bypassing the repository (simulating a
// real prior day's audit history already on disk).
const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
testDb.prepare("UPDATE plugin_capability_audit SET ts = ? WHERE plugin_id = 'hs3'").run(yesterday);
await updateRows(t, PluginCapabilityAudit, { plugin_id: 'hs3' }, { ts: yesterday });
const usage = await pluginBudgetUsage('hs3', audit);
expect(usage.ai).toBe(0);