* fix(agent): hide Anthropic-only assistant surfaces where the provider cannot run them Self-hosted deployments on an OpenAI-compatible provider (or with no AI configured) still showed every entry point into the tool-loop runtime behind /api/agent/invoke, which answers 503 there. The capability lived server-side only (getAiStatus().assistantAvailable); no UI could read it. Hand the flag to the client through CompanyContext (useAssistantAvailable, beside the paid-capability gate) and gate each entry point that opens AgentChat: the bookkeeping page's "Skapa med assistent" and "Med assistenten", the inbox workspace's "Fråga assistenten" doors, /chat/intake and /chat/new?intent=. The floating trigger falls back to general help (the single-call console runs on any provider) instead of hiding, and AgentChat itself never fires an invoke without the runtime, so a resumed thread or a forgotten entry point shows a notice instead of a 503. The Hem checklist's "Anslut till Claude" step renders only where the assistant runs on Claude and the mcp-server extension is on. Provider-agnostic AI (ask console, categorization, extraction) and the server-side 503 are unchanged; on hosted the flag is true and nothing changes. Closes #2204 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019SaJfqNi4VmsG8FMKq99G6 * test(ai): use a placeholder that cannot match an Anthropic key shape The new direct-Anthropic status test assigned a string in the exact format of a live API key, which trips secret scanners on every run. The config only reads presence, so any non-empty string exercises the path. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
186 lines
7.1 KiB
TypeScript
186 lines
7.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
checklistNumbers,
|
|
claudeConnectorLink,
|
|
mcpServerUrl,
|
|
sideDoorServerUrl,
|
|
SIDE_DOORS,
|
|
claudeStepDone,
|
|
completionPatchBody,
|
|
vatDeadlineLine,
|
|
} from '../checklist'
|
|
|
|
describe('vatDeadlineLine', () => {
|
|
it('returns null when the company is not VAT-registered', () => {
|
|
expect(
|
|
vatDeadlineLine({ vatRegistered: false, momsPeriod: 'quarterly', nextVatDueDate: '2026-11-12' })
|
|
).toBeNull()
|
|
expect(
|
|
vatDeadlineLine({ vatRegistered: null, momsPeriod: null, nextVatDueDate: null })
|
|
).toBeNull()
|
|
})
|
|
|
|
it('flags the silent zero-deadline misconfiguration when moms_period is unset', () => {
|
|
expect(
|
|
vatDeadlineLine({ vatRegistered: true, momsPeriod: null, nextVatDueDate: null })
|
|
).toEqual({ kind: 'missing_period' })
|
|
// Even with a stray row, an unset period is still a misconfiguration to surface.
|
|
expect(
|
|
vatDeadlineLine({ vatRegistered: true, momsPeriod: undefined, nextVatDueDate: '2026-11-12' })
|
|
).toEqual({ kind: 'missing_period' })
|
|
})
|
|
|
|
it('returns the due date when registered with a period and an upcoming row', () => {
|
|
expect(
|
|
vatDeadlineLine({ vatRegistered: true, momsPeriod: 'quarterly', nextVatDueDate: '2026-11-12' })
|
|
).toEqual({ kind: 'date', dueDate: '2026-11-12' })
|
|
})
|
|
|
|
it('says nothing when a period is set but no upcoming row surfaced', () => {
|
|
expect(
|
|
vatDeadlineLine({ vatRegistered: true, momsPeriod: 'yearly', nextVatDueDate: null })
|
|
).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('checklistNumbers', () => {
|
|
it('numbers all five steps when both extensions are on', () => {
|
|
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: true, hasAssistant: true })).toEqual({
|
|
count: 5,
|
|
skv: 3,
|
|
receipts: 4,
|
|
assistant: 5,
|
|
})
|
|
})
|
|
|
|
it('collapses to four steps without the inbox extension', () => {
|
|
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: false, hasAssistant: true })).toEqual({
|
|
count: 4,
|
|
skv: 3,
|
|
receipts: 4,
|
|
assistant: 4,
|
|
})
|
|
})
|
|
|
|
it('collapses to four steps without the skatteverket extension', () => {
|
|
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: true, hasAssistant: true })).toEqual({
|
|
count: 4,
|
|
skv: 3,
|
|
receipts: 3,
|
|
assistant: 4,
|
|
})
|
|
})
|
|
|
|
it('collapses to three steps with neither extension', () => {
|
|
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: false, hasAssistant: true })).toEqual({
|
|
count: 3,
|
|
skv: 3,
|
|
receipts: 3,
|
|
assistant: 3,
|
|
})
|
|
})
|
|
|
|
// A deployment that cannot run the assistant (#2204) drops the Claude step:
|
|
// the title counts one step fewer, the other ordinals stay put.
|
|
it('drops the assistant step from the count without moving the other ordinals', () => {
|
|
expect(checklistNumbers({ hasSkatteverket: true, hasInbox: true, hasAssistant: false })).toEqual({
|
|
count: 4,
|
|
skv: 3,
|
|
receipts: 4,
|
|
assistant: 5,
|
|
})
|
|
expect(checklistNumbers({ hasSkatteverket: false, hasInbox: false, hasAssistant: false })).toEqual({
|
|
count: 2,
|
|
skv: 3,
|
|
receipts: 3,
|
|
assistant: 3,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('completionPatchBody', () => {
|
|
it('keeps a recorded path out of the body', () => {
|
|
expect(completionPatchBody('bank')).toEqual({ completed: true })
|
|
expect(completionPatchBody('fresh')).toEqual({ completed: true })
|
|
})
|
|
|
|
it('records migration when no path was chosen, so the route accepts completion', () => {
|
|
// Skipped the books question, then imported: step 1 is only done via an
|
|
// import in that state. Without a path the route answers 400 and the
|
|
// completion effect used to retry it forever.
|
|
expect(completionPatchBody(null)).toEqual({ completed: true, path: 'migration' })
|
|
})
|
|
})
|
|
|
|
describe('claudeStepDone', () => {
|
|
it('is done once an OAuth-minted MCP key row exists', () => {
|
|
expect(claudeStepDone({ oauthKeyCount: 1 })).toBe(true)
|
|
expect(claudeStepDone({ oauthKeyCount: 3 })).toBe(true)
|
|
})
|
|
|
|
it('stays open without a key row, including a null head count', () => {
|
|
expect(claudeStepDone({ oauthKeyCount: 0 })).toBe(false)
|
|
expect(claudeStepDone({ oauthKeyCount: null })).toBe(false)
|
|
expect(claudeStepDone({ oauthKeyCount: undefined })).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('mcpServerUrl', () => {
|
|
it('builds the namespaced URL with the client marker and no auth flag by default', () => {
|
|
expect(mcpServerUrl({ origin: 'https://app.testbrand.example', client: 'cursor' })).toBe(
|
|
'https://app.testbrand.example/api/extensions/ext/mcp-server/mcp?tool_namespace=accounted&client=cursor',
|
|
)
|
|
})
|
|
|
|
it('appends auth=required when eagerAuth is set', () => {
|
|
const url = new URL(mcpServerUrl({ origin: 'http://localhost:3000', client: 'grok', eagerAuth: true }))
|
|
expect(url.searchParams.get('tool_namespace')).toBe('accounted')
|
|
expect(url.searchParams.get('client')).toBe('grok')
|
|
expect(url.searchParams.get('auth')).toBe('required')
|
|
})
|
|
})
|
|
|
|
describe('sideDoorServerUrl', () => {
|
|
it('lists chatgpt then grok', () => {
|
|
expect(SIDE_DOORS).toEqual(['chatgpt', 'grok'])
|
|
})
|
|
|
|
it('gives Grok the eager-auth flag: its dialog reads a 200 probe as "no auth" and never starts OAuth', () => {
|
|
const url = new URL(sideDoorServerUrl({ origin: 'https://app.testbrand.example', door: 'grok' }))
|
|
expect(url.searchParams.get('client')).toBe('grok')
|
|
expect(url.searchParams.get('auth')).toBe('required')
|
|
})
|
|
|
|
it('keeps ChatGPT on the lazy URL', () => {
|
|
const url = new URL(sideDoorServerUrl({ origin: 'https://app.testbrand.example', door: 'chatgpt' }))
|
|
expect(url.searchParams.get('client')).toBe('chatgpt')
|
|
expect(url.searchParams.get('auth')).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('claudeConnectorLink', () => {
|
|
it('builds the claude.ai deep link with namespace, client marker and eager-auth flag, from the page origin', () => {
|
|
const link = claudeConnectorLink({ origin: 'https://app.testbrand.example', appName: 'Testbrand' })
|
|
expect(link).toBe(
|
|
'https://claude.ai/customize/connectors?modal=add-custom-connector' +
|
|
'&connectorName=Testbrand' +
|
|
'&connectorUrl=https%3A%2F%2Fapp.testbrand.example%2Fapi%2Fextensions%2Fext%2Fmcp-server%2Fmcp%3Ftool_namespace%3Daccounted%26client%3Dclaude-connector%26auth%3Drequired',
|
|
)
|
|
})
|
|
|
|
it('matches the Settings → API & MCP button shape (tool_namespace + client=claude-connector + auth=required)', () => {
|
|
const link = claudeConnectorLink({ origin: 'http://localhost:3000', appName: 'Bokföring AB' })
|
|
const url = new URL(link)
|
|
expect(url.searchParams.get('connectorName')).toBe('Bokföring AB')
|
|
const server = new URL(url.searchParams.get('connectorUrl') ?? '')
|
|
expect(server.origin).toBe('http://localhost:3000')
|
|
expect(server.pathname).toBe('/api/extensions/ext/mcp-server/mcp')
|
|
expect(server.searchParams.get('tool_namespace')).toBe('accounted')
|
|
expect(server.searchParams.get('client')).toBe('claude-connector')
|
|
// Without this flag claude.ai's Add-custom-connector dialog pre-fills
|
|
// Authentication "None" (the lazy handshake answers 200) and the sign-in
|
|
// never opens.
|
|
expect(server.searchParams.get('auth')).toBe('required')
|
|
})
|
|
})
|