Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-ui): close four residual test-strength gaps (PR #277)
Jose Ramirez200e00197db4
diff --git a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsxindex 531f2c36a..9d53c58cf 100644--- a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx+++ b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx@@ -897,12 +897,35 @@ describe('UpdateConnectorCredentials — required semantics and validation', ()}})- it('flags only the missing inputs, points them at the error, and focuses the first one', async () => {+ // ─── The focus TARGET needs three cases to be pinned, not one ─────────────+ //+ // `rejectSubmit` focuses `missing[0]`, and `missing` is built by filtering the+ // DECLARED key order — so the assertion "focus the first invalid input" has+ // two independent claims inside it: that focus follows declaration ORDER, and+ // that it follows INVALIDITY rather than mere position. A single fixture can+ // only ever pin one of them:+ //+ // - fill nothing -> first invalid IS field #1. Pins order only;+ // indistinguishable from "focus field #1".+ // - fill the SECOND key -> first invalid is STILL field #1. Pins+ // nothing about focus at all — it is exactly+ // the coincidence that makes a hardcoded+ // "focus field #1" pass.+ // - fill the FIRST key -> first invalid is field #2. The only fixture+ // where position and invalidity DISAGREE, so+ // the only one that can catch a focus target+ // that ignores which fields are actually bad.+ //+ // All three are below. The last one is the discriminating one; the first two+ // exist so a regression that breaks ordering is still caught.++ it('flags only the missing inputs and points them at the error (missing key first)', async () => {await renderPanel(ENV_SECRET, 'set')- // Fill the SECOND declared key only, so the first one is the missing one- // and "focus the first invalid input" cannot pass by focusing field #1 by- // accident.+ // The SECOND declared key is filled, so the missing one happens to be field+ // #1. Deliberately NOT the case that pins the focus target — see the+ // "focuses the first INVALID input" test below for that. This one carries+ // the per-input aria wiring.fireEvent.change(screen.getByLabelText('workspace-id', { exact: false }), {target: { value: 'w-value' },})@@ -924,6 +947,56 @@ describe('UpdateConnectorCredentials — required semantics and validation', ()expect(missing).toHaveFocus()})+ it('focuses the FIRST declared key when every input is empty', async () => {+ await renderPanel(ENV_SECRET, 'set')++ // Nothing filled: both keys are invalid, so the focus target is decided+ // purely by declaration ORDER. Reverse that order in `rejectSubmit` (focus+ // `missing[missing.length - 1]`) and only this case goes red.+ fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))+ await flush()++ const first = screen.getByLabelText('api-key', { exact: false })+ const second = screen.getByLabelText('workspace-id', { exact: false })++ expect(screen.getByText(/Missing: api-key, workspace-id/)).toBeInTheDocument()+ expect(first).toHaveAttribute('aria-invalid', 'true')+ expect(second).toHaveAttribute('aria-invalid', 'true')+ expect(first).toHaveFocus()+ expect(second).not.toHaveFocus()+ })++ it('focuses the first INVALID input, not the first input, when an earlier key is already filled', async () => {+ await renderPanel(ENV_SECRET, 'set')++ // The DISCRIMINATING fixture: field #1 is valid and field #2 is not, so+ // position and invalidity point at different elements. Replace the focus+ // target with an unconditional `envSecret.keys[0]` (i.e. "focus the first+ // field on the form") and this is the assertion that fails — every other+ // focus case in this file keeps passing, because in all of them the first+ // field IS the first invalid one.+ fireEvent.change(screen.getByLabelText('api-key', { exact: false }), {+ target: { value: 'a-value' },+ })+ fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))+ await flush()++ const filled = screen.getByLabelText('api-key', { exact: false })+ const missing = screen.getByLabelText('workspace-id', { exact: false })+ const alert = screen.getByRole('alert')++ expect(+ screen.getByText(/Enter every credential value\. Missing: workspace-id/)+ ).toBeInTheDocument()+ expect(missing).toHaveAttribute('aria-invalid', 'true')+ expect(filled).not.toHaveAttribute('aria-invalid', 'true')+ expect(missing.getAttribute('aria-describedby')).toContain(alert.getAttribute('id'))+ expect(filled).not.toHaveAttribute('aria-describedby')+ // The whole point: focus is on field #2, and demonstrably NOT on field #1.+ expect(missing).toHaveFocus()+ expect(filled).not.toHaveFocus()+ })+it('clears the invalid state as soon as the operator types into the flagged input', async () => {await renderPanel(ENV_SECRET, 'set')@@ -1058,6 +1131,51 @@ describe('UpdateConnectorCredentials — set mode submit', () => {expect(screen.getByText(/Setting credentials — waiting for/i)).toBeInTheDocument()})+ // The third side, and the one that makes "status-agnostic" actually mean ANY:+ // every other retry fixture in this file carries a `.status`, so a gate+ // written as `if (postError.status === undefined) throw postError` — the shape+ // a well-meaning "only retry real HTTP failures" refactor produces — survives+ // all of them green. A transport failure (fetch rejects before any response+ // exists, so there is no status to read) is the real-world case that gate+ // would break, and it is exactly when the Secret may well have been created+ // by a request whose response never came back.+ it('retries the merge-patch and still succeeds when the create rejects with NO status at all', async () => {+ // A bare Error: no `.status` property whatsoever, not even undefined-valued.+ const transportFailure = new Error('Failed to fetch')+ expect('status' in transportFailure).toBe(false)+ mockCreateMcpSecret.mockRejectedValue(transportFailure)+ mockUpdateMcpSecret.mockResolvedValue({+ name: ENV_SECRET.name,+ namespace: 'mcp-server',+ keys: ['api-key', 'workspace-id'],+ affectedConnectors: [SERVER_NAME],+ })+ mockGetMcpServer.mockResolvedValue(+ serverWithCondition({+ status: 'True',+ message: 'Running',+ lastTransitionTime: '2026-01-01T00:00:30.000Z',+ })+ )+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ // Exactly once — not zero (the gate above), not twice (a retry loop).+ expect(mockCreateMcpSecret).toHaveBeenCalledTimes(1)+ expect(mockUpdateMcpSecret).toHaveBeenCalledTimes(1)+ expect(mockUpdateMcpSecret).toHaveBeenCalledWith(ENV_SECRET.name, ALL_KEYS)+ expect(screen.queryByText(/Could not set credentials/i)).not.toBeInTheDocument()+ expect(screen.getByText(/Setting credentials — waiting for/i)).toBeInTheDocument()++ // ...and the operator reaches the user-visible success state, so this cannot+ // pass on a retry that fired but left the screen stuck mid-flight.+ await act(async () => {+ vi.advanceTimersByTime(POLL_INTERVAL_MS)+ })+ await flush()+ expect(screen.getByText(/Credentials set\./)).toBeInTheDocument()+ })+// ─── R1-M1: which failure the operator is shown when BOTH legs fail ──────//// A 404 from the follow-up PUT is noise — the whole point of the retry is@@ -1080,6 +1198,38 @@ describe('UpdateConnectorCredentials — set mode submit', () => {expect(mockUpdateMcpSecret).toHaveBeenCalledTimes(1)})+ // The SAME rule against the PRODUCTION pair. The case above uses a 400 create,+ // which is a legible error on its own; this one uses control-api's real+ // duplicate-create answer — a bare 500 (see `serverError()`) — where the+ // temptation to prefer the "more specific" 404 is strongest. It must still+ // lose: the retry exists on the hypothesis "the Secret already exists", and a+ // 404 only refutes that hypothesis. It explains nothing about why the create+ // failed, and telling the operator the Secret does not exist on the screen+ // whose whole job is creating it is worse than opaque — it is misleading.+ it('reports the create error, not the PUT 404, for the production POST 500 + PUT 404 pair', async () => {+ mockCreateMcpSecret.mockRejectedValue(serverError())+ mockUpdateMcpSecret.mockRejectedValue(+ Object.assign(new Error('404 - Secret "linear-credentials" not found in mcp-server'), {+ status: 404,+ })+ )+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ expect(+ screen.getByText(/Could not set credentials: 500 Internal Server Error/)+ ).toBeInTheDocument()+ expect(screen.queryByText(/not found in mcp-server/)).not.toBeInTheDocument()+ // Neither leg may be skipped: the create ran, and the retry it is being+ // preferred over genuinely ran too.+ expect(mockCreateMcpSecret).toHaveBeenCalledTimes(1)+ expect(mockUpdateMcpSecret).toHaveBeenCalledTimes(1)+ // A 404 must not be mistaken for the rotate path's vanished-Secret recovery:+ // this IS the create path, so there is nothing to flip to.+ expect(screen.queryByText(/This Secret no longer exists\./)).not.toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument()+ })+// Any OTHER PUT failure describes the CURRENT state more precisely than the// opaque create error does. The production pair: control-api answers a bare// 500 for the AlreadyExists, then the merge-patch answers the real 409 thatdiff --git a/control-ui/components/__tests__/resolveCredentialSurface.test.ts b/control-ui/components/__tests__/resolveCredentialSurface.test.tsindex b2a391ca7..89c6529c3 100644--- a/control-ui/components/__tests__/resolveCredentialSurface.test.ts+++ b/control-ui/components/__tests__/resolveCredentialSurface.test.ts@@ -5,6 +5,19 @@ import {} from '@components/UpdateConnectorCredentials/resolveCredentialSurface'import type { McpServerCondition } from '@lib/api'+// ─── Fixtures are copied from the PRODUCER, not invented ───────────────────+//+// The only producer of `SecretResolved` is the HCC:+// host-context-controller/src/reconciler.ts. A fixture that drifts from what it+// actually writes tests a condition Kubernetes will never hold, and the drift+// is invisible — the resolver matches on `reason`, so a plausible-but-wrong+// reason string still exercises "not an absence claim" and stays green while+// proving nothing about the real one.+//+// Absence claim: reconciler.ts:2039-2046 writes `SecretResolved` / `False` with+// `secretResult.reason` and `secretResult.message` straight from validateSecret,+// whose 404 branch (reconciler.ts:470-473) produces exactly the reason and+// message below.function condition(overrides: Partial<McpServerCondition> = {}): McpServerCondition {return {type: 'SecretResolved',@@ -16,6 +29,25 @@ function condition(overrides: Partial<McpServerCondition> = {}): McpServerCondit}}+// Clean resolution: reconciler.ts:1979-1986 (managed connectors) and+// :2061-2068 (WRC-owned runtimes) both write this exact triple.+//+// The reason is `SecretFound`. It is NOT `SecretResolved` — that is the+// condition TYPE, and reusing it as the reason is the specific mistake these+// fixtures used to make. The resolver only asks "is this an absence claim?", so+// the wrong string passed just as happily, which is what made the drift+// survivable in the first place.+function resolvedCondition(overrides: Partial<McpServerCondition> = {}): McpServerCondition {+ return {+ type: 'SecretResolved',+ status: 'True',+ reason: 'SecretFound',+ message: 'Secret resolved and validated',+ lastTransitionTime: '2026-08-06T04:48:48.564Z',+ ...overrides,+ }+}+describe('resolveCredentialSurface', () => {it('returns "set" when the Secret does not exist on a managed connector', () => {expect(resolveCredentialSurface([condition()], { managed: true })).toBe('set')@@ -36,6 +68,9 @@ describe('resolveCredentialSurface', () => {// the whole suite green: a DeploymentReady=False/SecretNotFound (or any other// condition type reusing that reason) would then be read as a missing Secret// and send the operator to the create form.+ //+ // SYNTHETIC ADVERSARY, not producer output: the HCC writes `SecretNotFound`+ // only on `SecretResolved`. The fixture deliberately misplaces it.it('returns "rotate" when SecretNotFound is carried by a different condition type', () => {expect(resolveCredentialSurface([condition({ type: 'Ready', reason: 'SecretNotFound' })], {@@ -54,9 +89,7 @@ describe('resolveCredentialSurface', () => {})it('returns "rotate" when the Secret resolves cleanly', () => {- expect(- resolveCredentialSurface([condition({ status: 'True', reason: 'SecretResolved' })], {})- ).toBe('rotate')+ expect(resolveCredentialSurface([resolvedCondition()], {})).toBe('rotate')})it('returns "rotate" when there are no conditions', () => {@@ -75,7 +108,7 @@ describe('resolveCredentialSurface', () => {// works today on a WRC-owned connector must not be taken away.it('returns "rotate" for a WRC-owned connector whose Secret resolves', () => {expect(- resolveCredentialSurface([condition({ status: 'True', reason: 'SecretResolved' })], {+ resolveCredentialSurface([resolvedCondition()], {managed: false,})).toBe('rotate')@@ -103,9 +136,7 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()resolveCredentialSurface([condition({ lastTransitionTime: '2026-08-06T04:00:00.000Z' }),- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: '2026-08-06T05:00:00.000Z',}),],@@ -131,9 +162,7 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()expect(resolveCredentialSurface([- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: '2026-08-06T05:00:00.000Z',}),condition({ lastTransitionTime: '2026-08-06T04:00:00.000Z' }),@@ -147,9 +176,7 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()expect(resolveCredentialSurface([- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: '2026-08-06T04:00:00.000Z',}),condition({ lastTransitionTime: '2026-08-06T05:00:00.000Z' }),@@ -163,9 +190,7 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()expect(resolveCredentialSurface([- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: '2026-08-06T04:00:00.000Z',}),condition({ lastTransitionTime: '2026-08-06T05:00:00.000Z' }),@@ -181,19 +206,13 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()const same = '2026-08-06T04:00:00.000Z'expect(resolveCredentialSurface(- [- condition({ lastTransitionTime: same }),- condition({ status: 'True', reason: 'SecretResolved', lastTransitionTime: same }),- ],+ [condition({ lastTransitionTime: same }), resolvedCondition({ lastTransitionTime: same })],{ managed: true })).toBe('rotate')expect(resolveCredentialSurface(- [- condition({ status: 'True', reason: 'SecretResolved', lastTransitionTime: same }),- condition({ lastTransitionTime: same }),- ],+ [resolvedCondition({ lastTransitionTime: same }), condition({ lastTransitionTime: same })],{ managed: true })).toBe('rotate')@@ -201,14 +220,16 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()// Tie-break rule 2. An unparseable timestamp carries no recency proof, so it// must not let a stale absence claim outrank a well-stamped resolution.+ //+ // DELIBERATELY MALFORMED — not producer output. The HCC always stamps a valid+ // RFC3339 `lastTransitionTime`; these two tests exist for hand-edited or+ // legacy resources, which is the only way such a value reaches the resolver.it('returns "rotate" when the SecretNotFound duplicate carries an unparseable timestamp', () => {expect(resolveCredentialSurface([condition({ lastTransitionTime: 'not-a-timestamp' }),- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: '2026-08-06T04:00:00.000Z',}),],@@ -222,9 +243,7 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()resolveCredentialSurface([condition({ lastTransitionTime: '' }),- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: 'whenever',}),],@@ -235,6 +254,7 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()// A LONE absence claim with a malformed timestamp still means "missing":// there is nothing contradicting it, so today's behavior is preserved.+ // DELIBERATELY MALFORMED — see above; the HCC never emits this.it('returns "set" for a lone SecretNotFound with an unparseable timestamp', () => {expect(resolveCredentialSurface([condition({ lastTransitionTime: 'not-a-timestamp' })], {@@ -245,6 +265,13 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', ()// Unrelated condition types must not participate in the selection at all —// not as candidates, and not by shifting array order.+ //+ // The two bracketing entries are SYNTHETIC ADVERSARIES, not producer output:+ // they pair a real `SecretResolved` reason with the WRONG condition type, and+ // carry the NEWEST timestamps in the array. The HCC only ever writes those+ // reasons on `SecretResolved` (reconciler.ts:2039-2046, :1979-1986), so a+ // resolver that dropped the `type` clause and matched on reason alone would+ // pick one of these instead of either real candidate.it('ignores unrelated condition types regardless of their position or recency', () => {const conditions: McpServerCondition[] = [{@@ -258,13 +285,11 @@ describe('resolveCredentialSurface — duplicate SecretResolved conditions', (){type: 'Ready',status: 'True',- reason: 'SecretResolved',+ reason: 'SecretFound',message: 'noise',lastTransitionTime: '2026-08-06T09:00:00.000Z',},- condition({- status: 'True',- reason: 'SecretResolved',+ resolvedCondition({lastTransitionTime: '2026-08-06T05:00:00.000Z',}),]diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex b664ca638..d2c4f473b 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.399",+ "version": "0.1.400","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.399",+ "version": "0.1.400","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex ae5a2b4ee..8d467f529 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.399",+ "version": "0.1.400","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",