Compare commits
1 Commits
fix/issue-
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ae055d30b |
@@ -288,3 +288,30 @@ describe('Context overflow 500 fix', () => {
|
||||
expect(content).toContain('automatic compaction has failed')
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fix N: Project-scope MCP servers from .mcp.json not detected for 3P providers (issue #696)
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('Project-scope MCP approval — third-party providers (issue #696)', () => {
|
||||
test('handleMcpjsonServerApprovals is NOT gated behind usesAnthropicSetup', async () => {
|
||||
const content = await file('interactiveHelpers.tsx').text()
|
||||
|
||||
// The call site for handleMcpjsonServerApprovals must not sit inside an
|
||||
// `if (usesAnthropicSetup) { ... }` block, or third-party providers will
|
||||
// never get the dialog and project-scope .mcp.json servers will be silently
|
||||
// dropped from /mcp listings (issue #696).
|
||||
const approvalCallIdx = content.indexOf('await handleMcpjsonServerApprovals(root)')
|
||||
expect(approvalCallIdx).toBeGreaterThan(-1)
|
||||
|
||||
// Look at the 800 chars BEFORE the call site for any `if (usesAnthropicSetup)`
|
||||
// block that would still be open. Pick a window that's definitely inside the
|
||||
// showSetupScreens function but not in earlier dialogs.
|
||||
const before = content.slice(Math.max(0, approvalCallIdx - 800), approvalCallIdx)
|
||||
expect(before).not.toMatch(/if\s*\(\s*usesAnthropicSetup\s*\)\s*{[^}]*$/)
|
||||
})
|
||||
|
||||
test('issue #696 is referenced from the comment so future readers can find context', async () => {
|
||||
const content = await file('interactiveHelpers.tsx').text()
|
||||
expect(content).toContain('#696')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -158,24 +158,25 @@ export async function showSetupScreens(root: Root, permissionMode: PermissionMod
|
||||
// Now that trust is established, prefetch system context if it wasn't already
|
||||
void getSystemContext();
|
||||
|
||||
// Skip MCP approval dialogs for third-party providers (no interactive auth prompts)
|
||||
if (usesAnthropicSetup) {
|
||||
// If settings are valid, check for any mcp.json servers that need approval
|
||||
const {
|
||||
errors: allErrors
|
||||
} = getSettingsWithAllErrors();
|
||||
if (allErrors.length === 0) {
|
||||
await handleMcpjsonServerApprovals(root);
|
||||
}
|
||||
// MCP approval and external-includes warnings are about workspace
|
||||
// trust, not about Anthropic auth. They must run for all providers
|
||||
// — including third-party — otherwise project-scoped .mcp.json
|
||||
// servers never get the approval that writes
|
||||
// enableAllProjectMcpServers / enabledMcpjsonServers into
|
||||
// settings.local.json, and the servers are silently dropped from
|
||||
// /mcp and `mcp list` (issue #696).
|
||||
const { errors: allErrors } = getSettingsWithAllErrors();
|
||||
if (allErrors.length === 0) {
|
||||
await handleMcpjsonServerApprovals(root);
|
||||
}
|
||||
|
||||
// Check for claude.md includes that need approval
|
||||
if (await shouldShowClaudeMdExternalIncludesWarning()) {
|
||||
const externalIncludes = getExternalClaudeMdIncludes(await getMemoryFiles(true));
|
||||
const {
|
||||
ClaudeMdExternalIncludesDialog
|
||||
} = await import('./components/ClaudeMdExternalIncludesDialog.js');
|
||||
await showSetupDialog(root, done => <ClaudeMdExternalIncludesDialog onDone={done} isStandaloneDialog externalIncludes={externalIncludes} />);
|
||||
}
|
||||
// Check for claude.md includes that need approval
|
||||
if (await shouldShowClaudeMdExternalIncludesWarning()) {
|
||||
const externalIncludes = getExternalClaudeMdIncludes(await getMemoryFiles(true));
|
||||
const {
|
||||
ClaudeMdExternalIncludesDialog
|
||||
} = await import('./components/ClaudeMdExternalIncludesDialog.js');
|
||||
await showSetupDialog(root, done => <ClaudeMdExternalIncludesDialog onDone={done} isStandaloneDialog externalIncludes={externalIncludes} />);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,38 +28,6 @@ test('maps endpoint_not_found category markers to actionable setup guidance', ()
|
||||
expect(text).toContain('/v1')
|
||||
})
|
||||
|
||||
test('endpoint_not_found from a remote host shows the actual host, not Ollama (issue #926)', () => {
|
||||
const error = APIError.generate(
|
||||
404,
|
||||
undefined,
|
||||
'OpenAI API error 404: Not Found [openai_category=endpoint_not_found,host=integrate.api.nvidia.com] Hint: Endpoint at integrate.api.nvidia.com returned 404.',
|
||||
new Headers(),
|
||||
)
|
||||
|
||||
const message = getAssistantMessageFromError(error, 'moonshotai/kimi-k2.5-thinking')
|
||||
const text = getFirstText(message)
|
||||
|
||||
expect(text).toContain('integrate.api.nvidia.com')
|
||||
expect(text).toContain('moonshotai/kimi-k2.5-thinking')
|
||||
expect(text).not.toContain('Ollama')
|
||||
expect(text).not.toContain('11434')
|
||||
})
|
||||
|
||||
test('endpoint_not_found without a host falls back to the Ollama-aware message', () => {
|
||||
const error = APIError.generate(
|
||||
404,
|
||||
undefined,
|
||||
'OpenAI API error 404: Not Found [openai_category=endpoint_not_found] Hint: Confirm OPENAI_BASE_URL includes /v1.',
|
||||
new Headers(),
|
||||
)
|
||||
|
||||
const message = getAssistantMessageFromError(error, 'qwen2.5-coder:7b')
|
||||
const text = getFirstText(message)
|
||||
|
||||
expect(text).toContain('Provider endpoint was not found')
|
||||
expect(text).toContain('Ollama')
|
||||
})
|
||||
|
||||
test('maps tool_call_incompatible category markers to model/tool guidance', () => {
|
||||
const error = APIError.generate(
|
||||
400,
|
||||
|
||||
@@ -51,9 +51,7 @@ import {
|
||||
import { shouldProcessRateLimits } from '../rateLimitMocking.js' // Used for /mock-limits command
|
||||
import { extractConnectionErrorDetails, formatAPIError } from './errorUtils.js'
|
||||
import {
|
||||
extractOpenAICategoryHost,
|
||||
extractOpenAICategoryMarker,
|
||||
isLocalhostLikeHost,
|
||||
type OpenAICompatibilityFailureCategory,
|
||||
} from './openaiErrorClassification.js'
|
||||
|
||||
@@ -70,29 +68,25 @@ function mapOpenAICompatibilityFailureToAssistantMessage(options: {
|
||||
category: OpenAICompatibilityFailureCategory
|
||||
model: string
|
||||
rawMessage: string
|
||||
host?: string
|
||||
}): AssistantMessage {
|
||||
const switchCmd = getIsNonInteractiveSession() ? '--model' : '/model'
|
||||
const compactHint = getIsNonInteractiveSession()
|
||||
? 'Reduce prompt size or start a new session.'
|
||||
: 'Run /compact or start a new session with /new.'
|
||||
const isLocalhost = options.host === undefined || isLocalhostLikeHost(options.host)
|
||||
|
||||
switch (options.category) {
|
||||
case 'localhost_resolution_failed':
|
||||
case 'connection_refused':
|
||||
return createAssistantAPIErrorMessage({
|
||||
content: isLocalhost
|
||||
? 'Could not connect to the local OpenAI-compatible provider. Ensure the local server is running, then use OPENAI_BASE_URL=http://127.0.0.1:11434/v1 for Ollama.'
|
||||
: `Could not connect to the provider at ${options.host}. Verify OPENAI_BASE_URL is correct and that the host is reachable.`,
|
||||
content:
|
||||
'Could not connect to the local OpenAI-compatible provider. Ensure the local server is running, then use OPENAI_BASE_URL=http://127.0.0.1:11434/v1 for Ollama.',
|
||||
error: 'unknown',
|
||||
})
|
||||
|
||||
case 'endpoint_not_found':
|
||||
return createAssistantAPIErrorMessage({
|
||||
content: isLocalhost
|
||||
? 'Provider endpoint was not found. Confirm OPENAI_BASE_URL targets an OpenAI-compatible /v1 endpoint (for Ollama: http://127.0.0.1:11434/v1).'
|
||||
: `Provider endpoint at ${options.host} returned 404. Verify OPENAI_BASE_URL is correct and that the selected model (${options.model}) is supported by this provider.`,
|
||||
content:
|
||||
'Provider endpoint was not found. Confirm OPENAI_BASE_URL targets an OpenAI-compatible /v1 endpoint (for Ollama: http://127.0.0.1:11434/v1).',
|
||||
error: 'invalid_request',
|
||||
})
|
||||
|
||||
@@ -573,7 +567,6 @@ export function getAssistantMessageFromError(
|
||||
category: openaiCategory,
|
||||
model,
|
||||
rawMessage: error.message,
|
||||
host: extractOpenAICategoryHost(error.message),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ import {
|
||||
buildOpenAICompatibilityErrorMessage,
|
||||
classifyOpenAIHttpFailure,
|
||||
classifyOpenAINetworkFailure,
|
||||
extractOpenAICategoryHost,
|
||||
extractOpenAICategoryMarker,
|
||||
formatOpenAICategoryMarker,
|
||||
isLocalhostLikeHost,
|
||||
} from './openaiErrorClassification.js'
|
||||
|
||||
test('classifies localhost ECONNREFUSED as connection_refused', () => {
|
||||
@@ -97,58 +95,3 @@ test('ignores unknown category markers during extraction', () => {
|
||||
const malformed = 'OpenAI API error 500 [openai_category=totally_fake_category]'
|
||||
expect(extractOpenAICategoryMarker(malformed)).toBeUndefined()
|
||||
})
|
||||
|
||||
test('endpoint_not_found 404 from a remote host gets a host-aware hint (issue #926)', () => {
|
||||
const failure = classifyOpenAIHttpFailure({
|
||||
status: 404,
|
||||
body: 'Not Found',
|
||||
url: 'https://integrate.api.nvidia.com/v1/chat/completions',
|
||||
})
|
||||
|
||||
expect(failure.category).toBe('endpoint_not_found')
|
||||
expect(failure.requestUrl).toBe('https://integrate.api.nvidia.com/v1/chat/completions')
|
||||
expect(failure.hint).toContain('integrate.api.nvidia.com')
|
||||
expect(failure.hint).not.toContain('local providers')
|
||||
})
|
||||
|
||||
test('endpoint_not_found 404 from localhost keeps the Ollama-flavored hint', () => {
|
||||
const failure = classifyOpenAIHttpFailure({
|
||||
status: 404,
|
||||
body: 'Not Found',
|
||||
url: 'http://127.0.0.1:11434/v1/chat/completions',
|
||||
})
|
||||
|
||||
expect(failure.category).toBe('endpoint_not_found')
|
||||
expect(failure.hint).toContain('local providers')
|
||||
})
|
||||
|
||||
test('marker round-trip preserves host segment', () => {
|
||||
const formatted = buildOpenAICompatibilityErrorMessage(
|
||||
'OpenAI API error 404: Not Found',
|
||||
{
|
||||
category: 'endpoint_not_found',
|
||||
hint: 'Endpoint at integrate.api.nvidia.com returned 404.',
|
||||
requestUrl: 'https://integrate.api.nvidia.com/v1/chat/completions',
|
||||
},
|
||||
)
|
||||
|
||||
expect(formatted).toContain('[openai_category=endpoint_not_found,host=integrate.api.nvidia.com]')
|
||||
expect(extractOpenAICategoryMarker(formatted)).toBe('endpoint_not_found')
|
||||
expect(extractOpenAICategoryHost(formatted)).toBe('integrate.api.nvidia.com')
|
||||
})
|
||||
|
||||
test('marker without host stays backward-compatible', () => {
|
||||
const marker = formatOpenAICategoryMarker('endpoint_not_found')
|
||||
expect(marker).toBe('[openai_category=endpoint_not_found]')
|
||||
expect(extractOpenAICategoryMarker(marker)).toBe('endpoint_not_found')
|
||||
expect(extractOpenAICategoryHost(marker)).toBeUndefined()
|
||||
})
|
||||
|
||||
test('isLocalhostLikeHost matches loopback variants', () => {
|
||||
expect(isLocalhostLikeHost('localhost')).toBe(true)
|
||||
expect(isLocalhostLikeHost('127.0.0.1')).toBe(true)
|
||||
expect(isLocalhostLikeHost('127.0.0.5')).toBe(true)
|
||||
expect(isLocalhostLikeHost('::1')).toBe(true)
|
||||
expect(isLocalhostLikeHost('integrate.api.nvidia.com')).toBe(false)
|
||||
expect(isLocalhostLikeHost(undefined)).toBe(false)
|
||||
})
|
||||
|
||||
@@ -21,7 +21,6 @@ export type OpenAICompatibilityFailure = {
|
||||
hint?: string
|
||||
code?: string
|
||||
status?: number
|
||||
requestUrl?: string
|
||||
}
|
||||
|
||||
const OPENAI_CATEGORY_MARKER_PREFIX = '[openai_category='
|
||||
@@ -97,11 +96,6 @@ function isLocalhostLikeHostname(hostname: string | null): boolean {
|
||||
return /^127\./.test(hostname)
|
||||
}
|
||||
|
||||
export function isLocalhostLikeHost(host: string | null | undefined): boolean {
|
||||
if (!host) return false
|
||||
return isLocalhostLikeHostname(host.toLowerCase())
|
||||
}
|
||||
|
||||
function isContextOverflowMessage(body: string): boolean {
|
||||
const lower = body.toLowerCase()
|
||||
return (
|
||||
@@ -155,18 +149,14 @@ function isModelNotFoundMessage(body: string): boolean {
|
||||
|
||||
export function formatOpenAICategoryMarker(
|
||||
category: OpenAICompatibilityFailureCategory,
|
||||
host?: string,
|
||||
): string {
|
||||
if (host && /^[A-Za-z0-9.\-:]+$/.test(host)) {
|
||||
return `${OPENAI_CATEGORY_MARKER_PREFIX}${category},host=${host}]`
|
||||
}
|
||||
return `${OPENAI_CATEGORY_MARKER_PREFIX}${category}]`
|
||||
}
|
||||
|
||||
export function extractOpenAICategoryMarker(
|
||||
message: string,
|
||||
): OpenAICompatibilityFailureCategory | undefined {
|
||||
const match = message.match(/\[openai_category=([a-z_]+)(?:,host=[^\]]+)?]/)
|
||||
const match = message.match(/\[openai_category=([a-z_]+)]/)
|
||||
const category = match?.[1]
|
||||
|
||||
if (!category || !isOpenAICompatibilityFailureCategory(category)) {
|
||||
@@ -176,17 +166,11 @@ export function extractOpenAICategoryMarker(
|
||||
return category
|
||||
}
|
||||
|
||||
export function extractOpenAICategoryHost(message: string): string | undefined {
|
||||
const match = message.match(/\[openai_category=[a-z_]+,host=([A-Za-z0-9.\-:]+)]/)
|
||||
return match?.[1]
|
||||
}
|
||||
|
||||
export function buildOpenAICompatibilityErrorMessage(
|
||||
baseMessage: string,
|
||||
failure: Pick<OpenAICompatibilityFailure, 'category' | 'hint' | 'requestUrl'>,
|
||||
failure: Pick<OpenAICompatibilityFailure, 'category' | 'hint'>,
|
||||
): string {
|
||||
const host = failure.requestUrl ? getHostname(failure.requestUrl) ?? undefined : undefined
|
||||
const marker = formatOpenAICategoryMarker(failure.category, host)
|
||||
const marker = formatOpenAICategoryMarker(failure.category)
|
||||
const hint = failure.hint ? ` Hint: ${failure.hint}` : ''
|
||||
return `${baseMessage} ${marker}${hint}`
|
||||
}
|
||||
@@ -263,11 +247,8 @@ export function classifyOpenAINetworkFailure(
|
||||
export function classifyOpenAIHttpFailure(options: {
|
||||
status: number
|
||||
body: string
|
||||
url?: string
|
||||
}): OpenAICompatibilityFailure {
|
||||
const body = options.body ?? ''
|
||||
const hostname = options.url ? getHostname(options.url) : null
|
||||
const isLocalHost = isLocalhostLikeHostname(hostname)
|
||||
|
||||
if (options.status === 401 || options.status === 403) {
|
||||
return {
|
||||
@@ -303,17 +284,13 @@ export function classifyOpenAIHttpFailure(options: {
|
||||
}
|
||||
|
||||
if (options.status === 404) {
|
||||
const isRemote = hostname !== null && !isLocalHost
|
||||
return {
|
||||
source: 'http',
|
||||
category: 'endpoint_not_found',
|
||||
retryable: false,
|
||||
status: options.status,
|
||||
message: body,
|
||||
requestUrl: options.url,
|
||||
hint: isRemote
|
||||
? `Endpoint at ${hostname} returned 404. Verify OPENAI_BASE_URL is correct and the requested model is supported by this provider.`
|
||||
: 'Endpoint was not found. Confirm OPENAI_BASE_URL includes /v1 for OpenAI-compatible local providers.',
|
||||
hint: 'Endpoint was not found. Confirm OPENAI_BASE_URL includes /v1 for OpenAI-compatible local providers.',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1935,9 +1935,7 @@ class OpenAIShimMessages {
|
||||
classifyOpenAIHttpFailure({
|
||||
status,
|
||||
body: errorBody,
|
||||
url: requestUrl,
|
||||
})
|
||||
const failureWithUrl = { ...failure, requestUrl: failure.requestUrl ?? requestUrl }
|
||||
const redactedUrl = redactUrlForDiagnostics(requestUrl)
|
||||
|
||||
logForDebugging(
|
||||
@@ -1950,7 +1948,7 @@ class OpenAIShimMessages {
|
||||
parsedBody,
|
||||
buildOpenAICompatibilityErrorMessage(
|
||||
`OpenAI API error ${status}: ${errorBody}${rateHint}`,
|
||||
failureWithUrl,
|
||||
failure,
|
||||
),
|
||||
responseHeaders,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user