三个问题一起修:
1. 复制不生效:copyText 只试 navigator.clipboard.writeText,在 webview
(非安全上下文/权限未授予)会抛错直接返回 false,且按钮仍显示原样 →
表现为「点了没反应」。改为三级降级:Clipboard API → execCommand('copy')
→ 再次 Clipboard API;并新增 update.copyFailed 失败态提示(3s)。
2. 按钮颜色太浅:.dsh-wt_updateBtnCopy 原为 rgba(79,142,247,.18) 半透明底
+ #cfe0ff 浅蓝字,在浅色主题上几乎看不见。改为实心强调色 + 白字 + 加粗,
并补 hover/active 反馈。
3. 升级命令用的是当前版本:UPDATE_TGZ 写死 v0.5.3-local.9,不随检测结果变化,
「有新版本」提示里给的却是自己这一版的地址。改为
worktableUpgrade(tag) 按目标版本生成;index.tsx / split.tsx 两个调用点
均传 updateInfo.latest。
测试:
- host-transport.test.mjs 调用签名补 tag 参数
- 新增断言:命令必须指向目标版本(local.10 与 local.9 各验一次)
验证:npm run pack 全绿,双资产同源 sha256 2ff7d45a…。
61 lines
3.9 KiB
JavaScript
61 lines
3.9 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
import { createRequire } from 'node:module'
|
|
import { runInNewContext } from 'node:vm'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const require = createRequire(new URL('../01_content/package.json', import.meta.url))
|
|
const { buildSync } = require('esbuild')
|
|
const source = buildSync({ entryPoints: [fileURLToPath(new URL('../01_content/src/client/hostTransport.ts', import.meta.url))], bundle: true, write: false, platform: 'node', format: 'cjs' }).outputFiles[0].text
|
|
const module = { exports: {} }
|
|
runInNewContext(source, { module, exports: module.exports, URL })
|
|
const { hostWebSocketUrl, hostPreviewUrl, worktableUpgrade } = module.exports
|
|
|
|
test('Desktop sandbox assets use the owned Host URL without a login token', () => {
|
|
assert.equal(hostPreviewUrl('/api/worktable/preview-static/cap/app.js', {protocol:'dsh-app:',streamBaseUrl:'http://127.0.0.1:19499'}), 'http://127.0.0.1:19499/api/worktable/preview-static/cap/app.js')
|
|
})
|
|
test('Web sandbox assets retain a relative URL; missing Desktop carrier fails closed', () => {
|
|
assert.equal(hostPreviewUrl('/api/worktable/preview-static/cap/index.html', {protocol:'https:'}), '/api/worktable/preview-static/cap/index.html')
|
|
assert.throws(() => hostPreviewUrl('/api/worktable/preview-static/cap/index.html',{protocol:'dsh-app:'}), /unavailable/)
|
|
assert.throws(() => hostPreviewUrl('/api/worktable/preview-static/cap/index.html',{protocol:'dsh-app:',streamBaseUrl:'file:///fixture'}), /Unsupported/)
|
|
assert.throws(() => hostPreviewUrl('//other.example/api',{protocol:'https:'}), /Invalid/)
|
|
})
|
|
|
|
test('Web HTTP uses its current authority and preserves encoded query', () => {
|
|
assert.equal(hostWebSocketUrl('/api/worktable/term?cwd=C%3A%2Ftest&cols=80', { href: 'http://127.0.0.1:3080/', protocol: 'http:' }), 'ws://127.0.0.1:3080/api/worktable/term?cwd=C%3A%2Ftest&cols=80')
|
|
})
|
|
test('Web HTTPS keeps the secure WebSocket transport', () => {
|
|
assert.equal(hostWebSocketUrl('/api/worktable/term', { href: 'https://example.test/dsh', protocol: 'https:' }), 'wss://example.test/api/worktable/term')
|
|
})
|
|
test('Desktop uses the injected Host port, never the app scheme authority', () => {
|
|
assert.equal(hostWebSocketUrl('/api/worktable/term?sessionId=fixture', { href: 'dsh-app://app/', protocol: 'dsh-app:', streamBaseUrl: 'http://127.0.0.1:19499' }), 'ws://127.0.0.1:19499/api/worktable/term?sessionId=fixture')
|
|
})
|
|
test('Desktop without its bridge fails visibly rather than connecting to ws://app', () => {
|
|
assert.throws(() => hostWebSocketUrl('/api/worktable/term', { href: 'dsh-app://app/', protocol: 'dsh-app:' }), /stream URL unavailable/)
|
|
})
|
|
test('Unknown stream protocols are rejected', () => {
|
|
assert.throws(() => hostWebSocketUrl('/api/worktable/term', { href: 'dsh-app://app/', protocol: 'dsh-app:', streamBaseUrl: 'file:///fixture' }), /Unsupported Host transport/)
|
|
})
|
|
|
|
test('Web update instructions retain the web profile', () => {
|
|
const { command, prompt, desktop } = worktableUpgrade('0.5.3-local.10', 'https:')
|
|
assert.equal(desktop, false)
|
|
assert.match(command, /--profile web add/)
|
|
assert.match(prompt, /重启 dsh web/)
|
|
// 命令必须指向「要装的版本」,不能是当前已装版本(否则提示与命令自相矛盾)
|
|
assert.match(command, /\/releases\/download\/v0\.5\.3-local\.10\/dsh-worktable\.tgz/)
|
|
const older = worktableUpgrade('0.5.3-local.9', 'https:').command
|
|
assert.match(older, /v0\.5\.3-local\.9/)
|
|
assert.doesNotMatch(older, /v0\.5\.3-local\.10/)
|
|
})
|
|
|
|
test('Desktop update instructions require its bundled CLI and manual restart', () => {
|
|
const { command, prompt, desktop } = worktableUpgrade('0.5.3-local.10', 'dsh-app:')
|
|
assert.equal(desktop, true)
|
|
assert.match(command, /--profile desktop add/)
|
|
assert.doesNotMatch(command, /--profile web/)
|
|
assert.match(prompt, /桌面端自带的 dsh CLI/)
|
|
assert.match(prompt, /不要修改 web profile/)
|
|
assert.match(prompt, /手动重新打开桌面端/)
|
|
})
|