Skip to content

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

TypeScript

fix(control-api): stop the provider guard answering for a missing channel

Jose Ramirezed3735cae4e9
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index e580496e1..7a68d2d8d 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.439",
+ "version": "0.1.440",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.439",
+ "version": "0.1.440",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index cde104553..caddbdcb8 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.439",
+ "version": "0.1.440",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/resources.ts b/control-api/src/routes/admin/resources.ts
index ed3260924..6c00d42d0 100644
--- a/control-api/src/routes/admin/resources.ts
+++ b/control-api/src/routes/admin/resources.ts
@@ -603,7 +603,12 @@ export function createAdminResourcesRouter(gateway: K8sGateway): Router {
),
}
: body
- if (isCommunicationChannelUpdate) {
+ // A null snapshot means the channel does not exist (loadCommunicationChannelSpecSnapshot
+ // returns null only on 404). Skipping the guard here is what makes the response
+ // honest: with no previous spec every provider reads as newly added, so the guard
+ // would answer a PUT to a missing channel with `credentials[...] is required`
+ // instead of the 404 updateResource is about to produce.
+ if (isCommunicationChannelUpdate && previousCommunicationChannelSpec) {
// updateBody.spec, not body.spec: the ref the write will actually carry
// is the preserved one, and that is the Secret whose keys decide whether
// a newly enabled provider can work. Reuses the snapshot already loaded
diff --git a/control-api/test/routes.providerTransition.test.ts b/control-api/test/routes.providerTransition.test.ts
index 58914f71f..e9cdf02a7 100644
--- a/control-api/test/routes.providerTransition.test.ts
+++ b/control-api/test/routes.providerTransition.test.ts
@@ -242,4 +242,34 @@ describe('admin communicationchannels — provider transition validation (#312)'
expect(res.body.error).toMatch(/Cannot read the credentials Secret/)
expect(gatewayMock.updateResource).not.toHaveBeenCalled()
})
+
+ it('PUT to a channel that does not exist does not answer with a credentials error', async () => {
+ // The guard is scoped to an absent->present TRANSITION, and a channel that was
+ // never there has no previous spec — so without the snapshot check every provider
+ // in the body reads as newly added and the operator is told their credentials are
+ // missing for a channel that does not exist. The snapshot is null only on 404, so
+ // it is the honest signal to stand down and let the write answer.
+ //
+ // What the caller then sees is this codebase's generic k8s error surface, NOT a
+ // 404: ApiException sets `.code` and the error handler forwards `.status`. That
+ // collapse is pre-existing and applies to every route, so it is deliberately out
+ // of scope here. This test pins the part that IS in scope — the operator is no
+ // longer told to fix credentials on a channel that does not exist.
+ gatewayMock.getResource.mockRejectedValue(
+ new ApiException(404, 'Not Found', { message: 'communicationchannels "ghost" not found' }, {})
+ )
+ gatewayMock.updateResource.mockRejectedValue(
+ new ApiException(404, 'Not Found', { message: 'communicationchannels "ghost" not found' }, {})
+ )
+
+ const res = await request(makeApp())
+ .put('/admin/communicationchannels/ghost')
+ .send({ spec: { hostRef: 'h1', slackSettings: { botHandle: 'Jose Bot' } } })
+
+ expect(res.status).not.toBe(400)
+ expect(res.body.error ?? '').not.toMatch(/slack-bot-token|slack-signing-secret/)
+ // The write must be ATTEMPTED — that is what proves the guard stood down rather
+ // than the route inferring an answer of its own.
+ expect(gatewayMock.updateResource).toHaveBeenCalled()
+ })
})