Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(control-api): add publisherUiEnabled flag (default off for self-hosted)

Jose Ramirez78804ea69b3d
diff --git a/control-api/src/config.ts b/control-api/src/config.ts
index a76fec2ab..1965f37b4 100644
--- a/control-api/src/config.ts
+++ b/control-api/src/config.ts
@@ -75,6 +75,12 @@ type Config = {
// absence-based: managed = env/Secret, self-hosted = the registry_connection
// DB row. Required when registryAuthEnabled; logged at boot.
registryConnectionMode: 'managed' | 'self-hosted'
+ // Publisher UI surface (Sidebar entry + /publisher route) toggle, surfaced
+ // to control-ui on the publish-scope response. Static config value — not
+ // part of resolvePublishScope()'s cached registry-derived fields. Default
+ // OFF for self-hosted deploys, ON for managed; CONTROL_API_PUBLISHER_UI_ENABLED
+ // overrides the default either way.
+ publisherUiEnabled: boolean
adminAuthMaxFailures: number
adminAuthLockMinutes: number
adminBootstrapUsername: string
@@ -435,6 +441,11 @@ if (memberRegistrationMode === 'hosted') {
}
}
+// Computed once so registryConnectionMode and publisherUiEnabled's mode-based
+// default read the exact same resolved value below (rather than re-parsing
+// REGISTRY_CONNECTION_MODE a second time).
+const registryConnectionMode: 'managed' | 'self-hosted' = parseRegistryConnectionMode()
+
export const config: Config = {
port: Number(process.env.CONTROL_API_PORT || 8090),
jsonBodyLimit: process.env.CONTROL_API_JSON_BODY_LIMIT || '150mb',
@@ -534,7 +545,16 @@ export const config: Config = {
registryClientId: process.env.CLERUM_REGISTRY_CLIENT_ID ?? '',
registryClientSecret: process.env.CLERUM_REGISTRY_CLIENT_SECRET ?? '',
registryAuthEnabled: process.env.CLERUM_REGISTRY_AUTH_ENABLED === 'true',
- registryConnectionMode: parseRegistryConnectionMode(),
+ registryConnectionMode,
+ // 'true'/'false' wins explicitly; otherwise default OFF for self-hosted,
+ // ON for managed — reuses the registryConnectionMode value above rather
+ // than re-parsing REGISTRY_CONNECTION_MODE.
+ publisherUiEnabled:
+ process.env.CONTROL_API_PUBLISHER_UI_ENABLED === 'true'
+ ? true
+ : process.env.CONTROL_API_PUBLISHER_UI_ENABLED === 'false'
+ ? false
+ : registryConnectionMode !== 'self-hosted',
adminAuthMaxFailures: Number(process.env.CONTROL_API_ADMIN_AUTH_MAX_FAILURES || 5),
adminAuthLockMinutes: Number(process.env.CONTROL_API_ADMIN_AUTH_LOCK_MINUTES || 15),
adminBootstrapUsername: requiredOrDevDefault('CONTROL_API_ADMIN_BOOTSTRAP_USERNAME', 'admin'),
diff --git a/control-api/src/routes/admin/registry.ts b/control-api/src/routes/admin/registry.ts
index 96cdd4baa..7e82682cd 100644
--- a/control-api/src/routes/admin/registry.ts
+++ b/control-api/src/routes/admin/registry.ts
@@ -840,9 +840,12 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {
// GET /admin/registry/publish-scope — Where this control-api's publishes land.
// The publish UI reads this to show the target ({ curator, orgName, scope }):
// org-bound clients publish into their own org; curator clients into @clerum.
+ // publisherUiEnabled is merged in from static config (not part of
+ // resolvePublishScope()/its cache) — it gates the Publisher sidebar entry
+ // and /publisher route on control-ui.
router.get('/admin/registry/publish-scope', async (_req, res, next) => {
try {
- res.json(await resolvePublishScope())
+ res.json({ ...(await resolvePublishScope()), publisherUiEnabled: config.publisherUiEnabled })
} catch (err) {
next(err)
}
diff --git a/control-api/test/app.publisherUiEnabled.test.ts b/control-api/test/app.publisherUiEnabled.test.ts
new file mode 100644
index 000000000..e05e8f96f
--- /dev/null
+++ b/control-api/test/app.publisherUiEnabled.test.ts
@@ -0,0 +1,100 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import express from 'express'
+import request from 'supertest'
+import { MockGateway } from './mockGateway.js'
+
+const ORIGINAL_ENV = { ...process.env }
+
+// Bypass the control-ui auth gate so the supertest request reaches the real
+// publish-scope route (and the real config-driven merge) without a session
+// cookie.
+vi.mock('../src/middleware/controlUIAuth.js', () => ({
+ requireAuthForControlUI: (
+ req: express.Request,
+ _res: express.Response,
+ next: express.NextFunction
+ ) => {
+ ;(req as unknown as { adminAuth: unknown }).adminAuth = {
+ sub: 'admin-1',
+ role: 'admin',
+ typ: 'user',
+ }
+ next()
+ },
+}))
+
+// Partial-mock the registry client: keep every real export (applyPublishScope,
+// RegistryUnavailableError, …) so the admin router still loads, and override
+// only resolvePublishScope so the route returns a fixed org-bound scope
+// regardless of connection mode — this test is about the merged
+// publisherUiEnabled field, not scope resolution itself.
+const registryClient = vi.hoisted(() => ({
+ resolvePublishScope: vi.fn(),
+}))
+vi.mock('../src/services/registryClient.js', async importOriginal => ({
+ ...(await importOriginal<typeof import('../src/services/registryClient.js')>()),
+ resolvePublishScope: registryClient.resolvePublishScope,
+}))
+
+vi.mock('../src/middleware/rateLimitMiddleware.js', () => ({
+ rateLimitMiddleware:
+ () => (_req: express.Request, _res: express.Response, next: express.NextFunction) =>
+ next(),
+}))
+
+describe('GET /admin/registry/publish-scope: publisherUiEnabled (effective, through the route)', () => {
+ beforeEach(() => {
+ vi.resetModules()
+ process.env = { ...ORIGINAL_ENV }
+ delete process.env.CONTROL_API_PUBLISHER_UI_ENABLED
+ delete process.env.REGISTRY_CONNECTION_MODE
+ registryClient.resolvePublishScope.mockReset()
+ registryClient.resolvePublishScope.mockResolvedValue({
+ curator: false,
+ orgName: 'acme',
+ scope: '@acme',
+ })
+ })
+ afterEach(() => {
+ process.env = ORIGINAL_ENV
+ vi.resetModules()
+ })
+
+ it('is false by default in self-hosted mode', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ const { createApp } = await import('../src/app.js')
+ const app = createApp(new MockGateway('mcp-server') as never)
+ const res = await request(app).get('/api/v1/admin/registry/publish-scope')
+ expect(res.status).toBe(200)
+ expect(res.body.publisherUiEnabled).toBe(false)
+ // The registry-derived fields still pass through untouched.
+ expect(res.body.scope).toBe('@acme')
+ })
+
+ it('is true by default in managed mode', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'managed'
+ const { createApp } = await import('../src/app.js')
+ const app = createApp(new MockGateway('mcp-server') as never)
+ const res = await request(app).get('/api/v1/admin/registry/publish-scope')
+ expect(res.status).toBe(200)
+ expect(res.body.publisherUiEnabled).toBe(true)
+ })
+
+ it('env override CONTROL_API_PUBLISHER_UI_ENABLED=true wins on self-hosted', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ process.env.CONTROL_API_PUBLISHER_UI_ENABLED = 'true'
+ const { createApp } = await import('../src/app.js')
+ const app = createApp(new MockGateway('mcp-server') as never)
+ const res = await request(app).get('/api/v1/admin/registry/publish-scope')
+ expect(res.body.publisherUiEnabled).toBe(true)
+ })
+
+ it('env override CONTROL_API_PUBLISHER_UI_ENABLED=false wins on managed', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'managed'
+ process.env.CONTROL_API_PUBLISHER_UI_ENABLED = 'false'
+ const { createApp } = await import('../src/app.js')
+ const app = createApp(new MockGateway('mcp-server') as never)
+ const res = await request(app).get('/api/v1/admin/registry/publish-scope')
+ expect(res.body.publisherUiEnabled).toBe(false)
+ })
+})
diff --git a/control-api/test/config.publisherUiEnabled.test.ts b/control-api/test/config.publisherUiEnabled.test.ts
new file mode 100644
index 000000000..bb98aed3b
--- /dev/null
+++ b/control-api/test/config.publisherUiEnabled.test.ts
@@ -0,0 +1,54 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+const ORIGINAL_ENV = { ...process.env }
+
+beforeEach(() => {
+ vi.resetModules()
+ process.env = { ...ORIGINAL_ENV }
+ delete process.env.CONTROL_API_PUBLISHER_UI_ENABLED
+ delete process.env.REGISTRY_CONNECTION_MODE
+})
+afterEach(() => {
+ process.env = ORIGINAL_ENV
+ vi.resetModules()
+})
+
+describe('config: publisherUiEnabled (mode-based default + env override)', () => {
+ it('defaults to false when REGISTRY_CONNECTION_MODE=self-hosted', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ const { config } = await import('../src/config.js')
+ expect(config.publisherUiEnabled).toBe(false)
+ })
+
+ it('defaults to true when REGISTRY_CONNECTION_MODE=managed', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'managed'
+ const { config } = await import('../src/config.js')
+ expect(config.publisherUiEnabled).toBe(true)
+ })
+
+ it('defaults to true when REGISTRY_CONNECTION_MODE is unset (implicit managed)', async () => {
+ const { config } = await import('../src/config.js')
+ expect(config.publisherUiEnabled).toBe(true)
+ })
+
+ it('CONTROL_API_PUBLISHER_UI_ENABLED=true overrides the self-hosted default to true', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ process.env.CONTROL_API_PUBLISHER_UI_ENABLED = 'true'
+ const { config } = await import('../src/config.js')
+ expect(config.publisherUiEnabled).toBe(true)
+ })
+
+ it('CONTROL_API_PUBLISHER_UI_ENABLED=false overrides the managed default to false', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'managed'
+ process.env.CONTROL_API_PUBLISHER_UI_ENABLED = 'false'
+ const { config } = await import('../src/config.js')
+ expect(config.publisherUiEnabled).toBe(false)
+ })
+
+ it('an unrecognized CONTROL_API_PUBLISHER_UI_ENABLED value falls back to the mode-based default', async () => {
+ process.env.REGISTRY_CONNECTION_MODE = 'self-hosted'
+ process.env.CONTROL_API_PUBLISHER_UI_ENABLED = 'yes'
+ const { config } = await import('../src/config.js')
+ expect(config.publisherUiEnabled).toBe(false)
+ })
+})
diff --git a/control-api/test/routes.registryInstall.test.ts b/control-api/test/routes.registryInstall.test.ts
index 3b3d543e5..ed9baae0c 100644
--- a/control-api/test/routes.registryInstall.test.ts
+++ b/control-api/test/routes.registryInstall.test.ts
@@ -320,24 +320,27 @@ describe('GET /admin/registry/categories', () => {
// ── GET /admin/registry/publish-scope ─────────────────────────────────────────
describe('GET /admin/registry/publish-scope', () => {
- it('returns the resolved org-bound publish scope', async () => {
+ it('returns the resolved org-bound publish scope, plus the static publisherUiEnabled flag', async () => {
const scope: PublishScope = { curator: false, orgName: 'newtenantwf', scope: '@newtenantwf' }
vi.mocked(resolvePublishScope).mockResolvedValueOnce(scope)
const app = makeApp()
const res = await request(app).get('/admin/registry/publish-scope').expect(200)
- expect(res.body).toEqual(scope)
+ // publisherUiEnabled is merged in from config at the route boundary, not
+ // part of resolvePublishScope() itself — see config.publisherUiEnabled.test.ts
+ // for the default/override matrix.
+ expect(res.body).toEqual({ ...scope, publisherUiEnabled: config.publisherUiEnabled })
})
- it('returns the resolved curator publish scope', async () => {
+ it('returns the resolved curator publish scope, plus the static publisherUiEnabled flag', async () => {
const scope: PublishScope = { curator: true, orgName: 'clerum', scope: null }
vi.mocked(resolvePublishScope).mockResolvedValueOnce(scope)
const app = makeApp()
const res = await request(app).get('/admin/registry/publish-scope').expect(200)
- expect(res.body).toEqual(scope)
+ expect(res.body).toEqual({ ...scope, publisherUiEnabled: config.publisherUiEnabled })
})
it('returns 500 when resolvePublishScope throws', async () => {