Merge remote-tracking branch 'origin/master' into fix/sdk-dsh-doc-parity
# Conflicts: # packages/bundle/sdk-app/README.i18n.yaml # packages/bundle/sdk-app/README.md # packages/bundle/sdk-app/README.zh.md # scripts/snapshots/python-sdk-single-exe/authoring/model-visible.json # scripts/snapshots/python-sdk-single-exe/authoring/win-x64/model-visible.json
This commit is contained in:
commit
c19f8fadfe
223 files changed
+4684
-760
No files matched your search
@@ -486,6 +486,87 @@ describe('Python SDK dsh profile keyless smoke', () => {
|
||||
}
|
||||
}, 30_000)
|
||||
|
||||
// TZ belongs to the spawned runtime only; GMT makes ICU report "+00:00", which is not a usable zone name.
|
||||
it.each([
|
||||
{ tz: 'America/New_York', sampled: 'Browser time zone for this request: America/New_York. Interpret otherwise-unqualified dates and times in this zone.' },
|
||||
{ tz: 'GMT', sampled: 'Browser time zone for this request: unavailable. Ask the user to clarify otherwise-unqualified dates and times.' },
|
||||
])('shows the model the reported or sampled prompt time zone (TZ=$tz)', async ({ tz, sampled }) => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'dsh-sdk-time-zone-'))
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }))
|
||||
const modelRequests: string[] = []
|
||||
const modelServer = createServer((request, response) => {
|
||||
let body = ''
|
||||
request.setEncoding('utf8')
|
||||
request.on('data', (chunk: string) => { body += chunk })
|
||||
request.on('end', () => {
|
||||
modelRequests.push(body)
|
||||
response.writeHead(200, { 'content-type': 'text/event-stream' })
|
||||
response.end(messagesResponse({ type: 'text', text: 'done' }, 'end_turn'))
|
||||
})
|
||||
})
|
||||
onTestFinished(() => new Promise<void>((resolve) => { modelServer.close(() => { resolve() }) }))
|
||||
await new Promise<void>(resolve => modelServer.listen(0, '127.0.0.1', resolve))
|
||||
const address = modelServer.address()
|
||||
if (address === null || typeof address === 'string') throw new Error('model server did not bind a TCP port')
|
||||
const child = execa(launch.command, [...launch.args, '--profile', 'sdk'], {
|
||||
cwd: repoRoot,
|
||||
env: {
|
||||
...launch.env,
|
||||
DSH_HOME: join(root, '.dsh'),
|
||||
DSH_TELEMETRY_DISABLED: '1',
|
||||
DEEPSEEK_API_KEY: 'keyless-smoke-no-call',
|
||||
DEEPSEEK_BASE_URL: `http://127.0.0.1:${address.port}`,
|
||||
TZ: tz,
|
||||
},
|
||||
timeout: 35_000,
|
||||
killSignal: 'SIGKILL',
|
||||
reject: false,
|
||||
})
|
||||
onTestFinished(async () => { child.kill('SIGKILL'); await child })
|
||||
const lines: string[] = []
|
||||
let stdoutBuffer = ''
|
||||
let stderr = ''
|
||||
child.stdout.on('data', (chunk: Buffer) => {
|
||||
stdoutBuffer += chunk.toString('utf8')
|
||||
const parts = stdoutBuffer.split('\n')
|
||||
stdoutBuffer = parts.pop() ?? ''
|
||||
lines.push(...parts)
|
||||
})
|
||||
child.stderr.on('data', (chunk: Buffer) => { stderr += chunk.toString('utf8') })
|
||||
const send = (id: number, method: string, params?: object) => {
|
||||
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`)
|
||||
return waitForLine(lines, value => value.id === id, () => stderr)
|
||||
}
|
||||
const promptRequest = async (id: number, sessionId: string, timeZone?: string): Promise<string> => {
|
||||
const requests = modelRequests.length
|
||||
expect(await send(id, 'session/prompt', {
|
||||
sessionId, contentBlocks: [{ type: 'text', text: 'When is noon tomorrow?' }], ...timeZone === undefined ? {} : { timeZone },
|
||||
})).toHaveProperty('result.messageId')
|
||||
await waitForLine(lines, (value) => {
|
||||
const params = value.params as { sessionId?: string; event?: { type?: string } } | undefined
|
||||
return value.method === 'session.event' && params?.sessionId === sessionId && params.event?.type === 'turn/end'
|
||||
}, () => stderr)
|
||||
expect(modelRequests).toHaveLength(requests + 1)
|
||||
return modelRequests.at(-1)!
|
||||
}
|
||||
|
||||
await send(1, 'initialize', { cwd: root, provider: 'deepseek-official', model: 'deepseek-v4-pro' })
|
||||
expect(await promptRequest(2, 'explicit', 'US/Eastern')).toContain(
|
||||
'Browser time zone for this request: America/New_York. Interpret otherwise-unqualified dates and times in this zone.',
|
||||
)
|
||||
expect(await promptRequest(3, 'sampled')).toContain(sampled)
|
||||
expect(await send(4, 'session/prompt', {
|
||||
sessionId: 'invalid', contentBlocks: [{ type: 'text', text: 'When is noon?' }], timeZone: 'CST',
|
||||
})).toMatchObject({
|
||||
error: { code: -32603, message: 'timeZone must be UTC or a valid IANA Area/Location name: "CST"' },
|
||||
})
|
||||
expect(modelRequests).toHaveLength(2)
|
||||
|
||||
await send(5, 'shutdown')
|
||||
const exit = await child
|
||||
expect(exit.exitCode, `signal=${String(exit.signal)}; stderr=${stderr}`).toBe(0)
|
||||
}, 40_000)
|
||||
|
||||
it('rejects an invalid max-token success env value', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'dsh-python-sdk-runtime-invalid-'))
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
// Feishu setup failures and recovery through the real Host/Remote/browser composition.
|
||||
// A stand-in CLI waits for each authorization page visit and keeps account state on disk.
|
||||
import { chmod, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import type { Browser, BrowserContext, Page } from 'playwright'
|
||||
import { chromium } from 'playwright'
|
||||
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
|
||||
import { launchWebScaffold, watchConsole, type WebScaffold } from './scaffold.ts'
|
||||
import { ZH_BROWSER_LOCALE, saveFailureShot } from './support.ts'
|
||||
|
||||
const FEISHU_DIR = fileURLToPath(new URL('../../../packages/connector/feishu', import.meta.url))
|
||||
const SETUP_URL = 'https://open.feishu.cn/page/cli?e2e=1'
|
||||
const SETUP_RETRY_URL = `${SETUP_URL}&retry=1`
|
||||
const SIGN_IN_URL = 'https://accounts.feishu.cn/oauth/device?e2e=1'
|
||||
|
||||
// The stand-in keeps its account in state.json beside itself; app setup and
|
||||
// sign-in wait until the test marks their page visited.
|
||||
const LARK_CLI = `#!/usr/bin/env node
|
||||
const { existsSync, readFileSync, writeFileSync } = require('node:fs')
|
||||
const { join } = require('node:path')
|
||||
const dir = __dirname
|
||||
const statePath = join(dir, 'state.json')
|
||||
const state = existsSync(statePath) ? JSON.parse(readFileSync(statePath, 'utf8')) : { app: false, user: false }
|
||||
const save = () => { writeFileSync(statePath, JSON.stringify(state)) }
|
||||
const visited = (name, done) => {
|
||||
const poll = setInterval(() => {
|
||||
if (!existsSync(join(dir, name))) return
|
||||
clearInterval(poll)
|
||||
done()
|
||||
}, 50)
|
||||
}
|
||||
const line = (value) => { process.stdout.write(JSON.stringify(value) + '\\n') }
|
||||
switch (process.argv.slice(2).join(' ')) {
|
||||
case 'auth status --verify --json':
|
||||
if (!state.app) {
|
||||
process.stderr.write(JSON.stringify({ ok: false, error: { type: 'config', subtype: 'not_configured' } }))
|
||||
process.exitCode = 3
|
||||
} else if (!state.user) line({ appId: 'cli_e2e', identities: { user: { status: 'missing', available: false } } })
|
||||
else line({ appId: 'cli_e2e', identities: { user: { status: 'ready', available: true, verified: true, userName: '测试用户', openId: 'ou_e2e' } } })
|
||||
break
|
||||
case 'config init --new':
|
||||
process.stderr.write('Open this link to create an app:\\n ' + (existsSync(join(dir, 'setup-fails')) ? '${SETUP_URL}' : '${SETUP_RETRY_URL}') + '\\n')
|
||||
visited('setup-visited', () => {
|
||||
if (existsSync(join(dir, 'setup-fails'))) {
|
||||
process.stderr.write('OK: App configured!\\n' + JSON.stringify({ ok: false, error: {
|
||||
type: 'internal', subtype: 'sdk_error',
|
||||
message: 'keychain Set failed: /private/user/appsecret.enc.tmp: operation not permitted; token=fixture-secret',
|
||||
hint: 'https://open.feishu.cn/page/cli?user_code=fixture-code',
|
||||
} }, null, 2) + '\\n')
|
||||
process.exitCode = 5
|
||||
} else { state.app = true; save() }
|
||||
})
|
||||
break
|
||||
case 'auth login --json':
|
||||
line({ event: 'device_authorization', verification_uri_complete: '${SIGN_IN_URL}' })
|
||||
visited('sign-in-visited', () => { state.user = true; save(); line({ event: 'authorization_complete', user_open_id: 'ou_e2e', missing: [] }) })
|
||||
break
|
||||
case 'auth logout --json': state.user = false; save(); line({ ok: true }); break
|
||||
default:
|
||||
process.stderr.write('unexpected lark-cli arguments: ' + process.argv.slice(2).join(' ') + '\\n')
|
||||
process.exitCode = 1
|
||||
}
|
||||
`
|
||||
|
||||
// The stand-in runs through its shebang, which Windows cannot execute.
|
||||
describe.skipIf(process.platform === 'win32')('web e2e: Feishu plugin connection', () => {
|
||||
let binDir: string
|
||||
let scaffold: WebScaffold
|
||||
let browser: Browser
|
||||
let context: BrowserContext
|
||||
let page: Page
|
||||
let tripwire: ReturnType<typeof watchConsole>
|
||||
|
||||
beforeAll(async () => {
|
||||
binDir = await mkdtemp(join(tmpdir(), 'dsh-feishu-e2e-'))
|
||||
await writeFile(join(binDir, 'lark-cli'), LARK_CLI)
|
||||
await chmod(join(binDir, 'lark-cli'), 0o755)
|
||||
const overlay = join(binDir, 'feishu.overlay.yml')
|
||||
await writeFile(overlay, `- id: feishu\n config:\n binDir: ${JSON.stringify(binDir)}\n`)
|
||||
scaffold = await launchWebScaffold({
|
||||
extraOverlayPath: [fileURLToPath(new URL('./pin-browse-picker.overlay.yml', import.meta.url)), overlay],
|
||||
profile: { packages: [{ dir: FEISHU_DIR, enabled: true }] },
|
||||
})
|
||||
browser = await chromium.launch()
|
||||
context = await browser.newContext({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
|
||||
for (const [url, marker] of [[SETUP_URL, 'setup-visited'], [SETUP_RETRY_URL, 'setup-visited'], [SIGN_IN_URL, 'sign-in-visited']] as const) {
|
||||
await context.route(url, async (route) => {
|
||||
await writeFile(join(binDir, marker), '')
|
||||
await route.fulfill({ contentType: 'text/html; charset=utf-8', body: '<!doctype html><title>Feishu</title><p>Feishu stand-in page</p>' })
|
||||
})
|
||||
}
|
||||
page = await context.newPage()
|
||||
tripwire = watchConsole(page)
|
||||
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
||||
await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
|
||||
}, 120_000)
|
||||
|
||||
afterAll(async () => {
|
||||
await browser?.close()
|
||||
await scaffold?.close()
|
||||
if (binDir !== undefined) await rm(binDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('reports failed local setup, then links an existing app, signs in, and signs out', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-feishu-connection'))
|
||||
await page.getByRole('navigation', { name: '全局面板' }).getByRole('button', { name: '插件', exact: true }).click()
|
||||
const panel = page.locator('[data-plugin-panel]')
|
||||
await panel.getByRole('button', { name: '查看 飞书插件', exact: true }).click({ timeout: 20_000 })
|
||||
const section = panel.locator('[data-connector-account-key="@deepseek-ai/dsh-feishu"]')
|
||||
await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('disconnected')
|
||||
expect(await panel.locator('[data-plugin-detail]').getByText('未连接', { exact: true }).count()).toBe(2)
|
||||
|
||||
const opened: Page[] = []
|
||||
context.on('page', (popup) => { opened.push(popup) })
|
||||
await writeFile(join(binDir, 'setup-fails'), '')
|
||||
await section.getByRole('button', { name: '关联飞书应用', exact: true }).click()
|
||||
await section.getByRole('alert').waitFor({ timeout: 20_000 })
|
||||
expect(await section.getAttribute('data-connector-account')).toBe('disconnected')
|
||||
expect(await section.getByRole('alert').innerText()).toContain('config-init · exit 5')
|
||||
expect(await section.getByRole('alert').innerText()).toContain('已有应用')
|
||||
expect(await section.innerText()).not.toContain('fixture-secret')
|
||||
expect(await section.innerText()).not.toContain('fixture-code')
|
||||
expect(await section.innerText()).not.toContain('/private/user')
|
||||
await expect(readFile(join(binDir, 'state.json'), 'utf8')).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
await rm(join(binDir, 'setup-fails'))
|
||||
await rm(join(binDir, 'setup-visited'))
|
||||
await section.getByRole('button', { name: '关联飞书应用', exact: true }).click()
|
||||
await page.getByText('飞书应用已关联,下一步登录飞书账号', { exact: true }).waitFor({ timeout: 20_000 })
|
||||
expect(opened.map(popup => popup.url())).toEqual([SETUP_URL, SETUP_RETRY_URL])
|
||||
await section.getByRole('button', { name: '登录飞书账号', exact: true }).click()
|
||||
await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('connected')
|
||||
expect(opened.map(popup => popup.url())).toEqual([SETUP_URL, SETUP_RETRY_URL, SIGN_IN_URL])
|
||||
await section.getByText('已登录为 测试用户。可以在对话中直接请 Agent 使用飞书。', { exact: true }).waitFor({ timeout: 10_000 })
|
||||
await page.getByText('飞书已连接', { exact: true }).waitFor({ timeout: 10_000 })
|
||||
|
||||
await section.getByRole('button', { name: '退出登录', exact: true }).click()
|
||||
await page.getByRole('dialog', { name: '退出飞书登录?' }).getByRole('button', { name: '退出登录', exact: true }).click()
|
||||
await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('disconnected')
|
||||
await page.getByText('已退出飞书登录', { exact: true }).waitFor({ timeout: 10_000 })
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -843,7 +843,11 @@ export async function launchWebScaffold(options: LaunchOptions = {}): Promise<We
|
||||
throw new Error(`web e2e scaffold: the web app requested exit ${String(code)} with no arguments to reject`)
|
||||
},
|
||||
})
|
||||
const resolution = await createRuntimeResolution(resolutionOptions)
|
||||
// Like the launcher, resolve the dependencies of every selected bundle, not only the extra install anchors.
|
||||
const selectedLayers = loadProfileDirectory('dsh', profileDir, INSTALL_ANCHOR).layers
|
||||
const resolution = await createRuntimeResolution({
|
||||
...resolutionOptions, profile: { ...profile, layers: [...profile.layers, ...selectedLayers] },
|
||||
})
|
||||
await ctx.plugin(PluginPackages, {
|
||||
resolution,
|
||||
})
|
||||
|
||||
@@ -276,7 +276,8 @@
|
||||
"tests/notion-connection.e2e.ts",
|
||||
"tests/notion-oauth-fixture.ts",
|
||||
"tests/tencent-docs-connection.e2e.ts",
|
||||
"tests/tencent-docs-oauth-fixture.ts"
|
||||
"tests/tencent-docs-oauth-fixture.ts",
|
||||
"tests/feishu-connection.e2e.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../../packages/experimental/auto-review" },
|
||||
|
||||
Reference in new issue
Block a user