Files
MikrotikManager/backend/src/modules/mcp/routing-profile-authority-integration.sql-helper.ts
T

39 lines
2.7 KiB
TypeScript

import assert from "node:assert/strict"
import { randomUUID } from "node:crypto"
import { basename, dirname, resolve } from "node:path"
import type { AuthUser } from "../../lib/permissions.js"
/** Reuses the COMPLETE existing scoped/manual/recovery and management SQL/HTTP
* acceptance, plus persistent authority cases. Not a narrowed snapshot runner.
* Invoke only after migrations in the owned disposable PostgreSQL harness. */
export async function acceptRoutingProfileAuthorityIntegrationSql() {
assert.equal(process.env.MMAPP_OWN_PROBE_JOURNAL, "true")
const url = new URL(process.env.DATABASE_URL ?? "")
assert.equal(url.hostname, "127.0.0.1"); assert.equal(url.pathname, "/postgres")
assert(["postgres:", "postgresql:"].includes(url.protocol))
assert(process.env.MCP_STATE_DIR && basename(dirname(resolve(process.env.MCP_STATE_DIR))).startsWith("mm-mcp-test-"))
const { pool } = await import("../../db/index.js")
assert.equal((await pool.query("SELECT current_database() AS name")).rows[0].name, "postgres")
assert.equal((await pool.query("SELECT id FROM servers WHERE id=131")).rows.length, 0, "Existing scoped fixture ID must be unowned before this isolated run")
// Importing the action registry registers only the existing production tools;
// no test alias, new production route or collector is installed here.
await import("./actions.js")
const { acceptScopedRouteCommunitySwitch } = await import("./routing-community-scoped-acceptance.js")
const { acceptManagementTransport } = await import("./management-transport-acceptance.js")
const previousEnabled = (await pool.query("SELECT enabled FROM mcp_settings WHERE id=1")).rows[0].enabled as boolean
const now = Date.now()
const actor: AuthUser = { id: "routing-authority-integration-owner-" + randomUUID(), email: "[email protected]", name: "Synthetic routing authority owner",
apps: ["mm"], permissions: ["mm:network:admin", "mm:filters:admin", "mm:mcp:admin", "mm:mcp:approve", "mm:servers:admin"], issuedAt: now - 1000, expiresAt: now + 3600000 }
try {
await pool.query("UPDATE mcp_settings SET enabled=true WHERE id=1")
const scoped = await acceptScopedRouteCommunitySwitch(actor)
const management = await acceptManagementTransport(actor)
assert.equal(scoped.persistentAuthorityCases, 17, "Includes the six additional genuine configuration-bridge scenarios")
assert.equal(management.metadataAdmissionCases, 7)
assert.equal(management.metadataNativeRequests, 0)
return { scoped, management, realSql: true, transport: "loopback HTTP fixtures", externalNetwork: false, forwardingVerified: false, controllerEnabled: false }
} finally {
await pool.query("UPDATE mcp_settings SET enabled=$1 WHERE id=1", [previousEnabled])
}
}