Skip to content

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

TypeScript

test(control-ui): assert the payload the guardrail install actually sends

Andy Pavia6d5db28f7394
diff --git a/control-ui/components/__tests__/HookInstallForm.test.tsx b/control-ui/components/__tests__/HookInstallForm.test.tsx
index 6a6e1348f..7af9cf4a4 100644
--- a/control-ui/components/__tests__/HookInstallForm.test.tsx
+++ b/control-ui/components/__tests__/HookInstallForm.test.tsx
@@ -71,6 +71,18 @@ beforeEach(() => {
const noop = () => undefined
+/** Walks the wizard to step 1 and installs, returning the submitted payload. */
+async function installAndCapturePayload() {
+ vi.mocked(api.installHookFromRegistry).mockResolvedValue({
+ hookName: 'token-compactor',
+ trustLevel: 'verified',
+ } as never)
+ fireEvent.click(await screen.findByRole('button', { name: /continue/i }))
+ fireEvent.click(await screen.findByRole('button', { name: /^install$/i }))
+ await waitFor(() => expect(api.installHookFromRegistry).toHaveBeenCalledTimes(1))
+ return vi.mocked(api.installHookFromRegistry).mock.calls[0][0]
+}
+
describe('HookInstallForm — author declarations', () => {
it('pre-ticks the capabilities the author declares', async () => {
render(
@@ -366,3 +378,67 @@ describe('HookInstallForm — ungranted-capability warning', () => {
expect(screen.getByText(/the author also lists may_add_context/i)).toBeInTheDocument()
})
})
+
+describe('HookInstallForm — what actually reaches the install route', () => {
+ it('requests no capability from an agent with no ceiling', async () => {
+ // The claim this form makes is about the request it sends, so assert the
+ // request. control-api reads a missing capabilityCeiling as [] and 403s
+ // anything against it, so a seeded may_rewrite here would be rejected.
+ vi.mocked(api.getHosts).mockResolvedValue({ items: [host('agent-a', null)] } as never)
+ render(
+ <HookInstallForm
+ entry={entryWith({ requiredCapabilities: ['may_rewrite'] })}
+ onCancel={noop}
+ onInstalled={noop}
+ />
+ )
+ const payload = await installAndCapturePayload()
+ expect(payload.capabilities).toBeUndefined()
+ expect(payload).toMatchObject({
+ hostRef: 'agent-a',
+ registryEntryName: '@acme1/token-compactor',
+ registryEntryVersion: '0.2.3',
+ order: 100,
+ failMode: 'open',
+ })
+ })
+
+ it('sends the declared capabilities the agent permits, fail mode included', async () => {
+ render(
+ <HookInstallForm
+ entry={entryWith({
+ requiredCapabilities: ['may_deny'],
+ // The author asks for fail open; a granted may_deny overrides it, and
+ // the override has to reach the payload, not just the select.
+ authorDefaults: { failMode: 'open' },
+ })}
+ onCancel={noop}
+ onInstalled={noop}
+ />
+ )
+ await openAdvanced()
+ await waitFor(() => expect(capabilityBox('May deny').checked).toBe(true))
+ const payload = await installAndCapturePayload()
+ expect(payload.capabilities).toEqual(['may_deny'])
+ expect(payload.failMode).toBe('closed')
+ })
+
+ it('drops a declared capability the agent forbids before sending', async () => {
+ vi.mocked(api.getHosts).mockResolvedValue({
+ items: [host('agent-a', ['may_add_context'])],
+ } as never)
+ render(
+ <HookInstallForm
+ entry={entryWith({ requiredCapabilities: ['may_deny', 'may_add_context'] })}
+ onCancel={noop}
+ onInstalled={noop}
+ />
+ )
+ await openAdvanced()
+ await waitFor(() => expect(capabilityBox('May add context').checked).toBe(true))
+ const payload = await installAndCapturePayload()
+ expect(payload.capabilities).toEqual(['may_add_context'])
+ // Nothing outside the ceiling escapes, so fail mode is not forced either.
+ expect(payload.failMode).toBe('open')
+ })
+})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 17c73022c..22ebfb978 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.456",
+ "version": "0.1.457",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.456",
+ "version": "0.1.457",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index baf02e9fd..2c1ef70e0 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.456",
+ "version": "0.1.457",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",