返回 CodeWhale
mcp-bundle-redaction.test.mjs
根目录 / crates / engine / extension-host / test / mcp-bundle-redaction.test.mjs
1 import { readFileSync } from 'node:fs'
2 import { test } from 'node:test'
3 import assert from 'node:assert/strict'
4 import { dirname, join } from 'node:path'
5 import { fileURLToPath } from 'node:url'
6 import { runInNewContext } from 'node:vm'
7
8 const here = dirname(fileURLToPath(import.meta.url))
9 const bundle = readFileSync(join(here, '..', 'dist', 'builtin', 'mcp.mjs'), 'utf8')
10
11 test('bundled MCP OAuth errors omit response bodies and dynamic error details', () => {
12 assert.doesNotMatch(bundle, /Raw body: \$\{body\}/)
13 assert.doesNotMatch(bundle, /Cause: \$\{JSON\.stringify\(error2\.message\)\}/)
14 assert.doesNotMatch(bundle, /Cause: \$\{JSON\.stringify\(error2 instanceof Error/)
15 assert.match(bundle, /OAuth error response details omitted/)
16 assert.ok(bundle.includes('falling back to a new authorization request.'))
17 })
18
19 test('credential retry logging never reads provider-controlled OAuth error fields', () => {
20 const logger = bundle.match(/function warnCredentialInvalidation\(provider, error2, invalidated\) \{[\s\S]*?\n\}/)?.[0]
21 assert.ok(logger, 'the shipped SDK credential retry logger must be exercised')
22 for (const provider of [{}, { invalidateCredentials() {} }]) {
23 const warnings = []
24 runInNewContext(`${logger}\nwarnCredentialInvalidation(provider, error, "tokens");`, {
25 provider,
26 error: new Proxy({}, { get() { throw new Error('read of provider-controlled OAuth error') } }),
27 console: { warn: message => warnings.push(message) },
28 })
29 assert.equal(warnings.length, 1)
30 assert.match(warnings[0], /tokens.*retrying authorization|retrying authorization.*tokens/)
31 assert.match(warnings[0], /details omitted/)
32 }
33 })
34
34 lines Plain Text