mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 02:30:22 +08:00
优化卡片 UI 与文案、改用结构化段落融合、兼容 Desktop 并支持更新检测与一键更新 (v0.2.6)
This commit is contained in:
1 parent
fbd8475d01
commit
829bb9228d
18 files changed
+2340
-1156
No files matched your search
+53
-10
@@ -3,14 +3,21 @@ import test from 'node:test'
|
||||
import { createUnrestrictedController } from '../src/client/controller.ts'
|
||||
|
||||
const settle = () => new Promise(setImmediate)
|
||||
const status = (contract, enabled = true) => ({ enabled, contract, modes: {} })
|
||||
const status = (version, enabled = true) => ({ enabled, version, modes: {} })
|
||||
|
||||
/** 保留真实控制器,仅控制设置提交、配置事件和 RPC 的完成时序。 */
|
||||
async function fixture() {
|
||||
let value = { enabled: true }
|
||||
const subscribers = new Set()
|
||||
const events = new Map()
|
||||
const pending = { status: [], recheck: [], preview: [], write: [] }
|
||||
const pending = {
|
||||
status: [],
|
||||
recheck: [],
|
||||
preview: [],
|
||||
'check-update': [],
|
||||
'perform-update': [],
|
||||
write: [],
|
||||
}
|
||||
function defer(endpoint, payload) {
|
||||
return new Promise((resolve, reject) => pending[endpoint].push({ payload, resolve, reject }))
|
||||
}
|
||||
@@ -35,7 +42,7 @@ async function fixture() {
|
||||
return request
|
||||
}
|
||||
const answer = (request, value) => request.resolve({ ok: true, value })
|
||||
answer(take('status'), status('initial'))
|
||||
answer(take('status'), status('0.2.6'))
|
||||
await settle()
|
||||
return {
|
||||
face, take, answer,
|
||||
@@ -56,7 +63,7 @@ test('刷新或重检后,迟到的旧预览不能覆盖已显示的新正文',
|
||||
const previousRequest = f.take('preview')
|
||||
assert.equal(f.view().busy, false, '加载预览时界面允许刷新和重检')
|
||||
const updating = f.face[action]()
|
||||
f.answer(f.take(action === 'refresh' ? 'status' : 'recheck'), status('updated'))
|
||||
f.answer(f.take(action === 'refresh' ? 'status' : 'recheck'), status('0.2.6'))
|
||||
await updating
|
||||
assert.equal(f.view().previews.standard, undefined)
|
||||
|
||||
@@ -75,7 +82,7 @@ test('失效预览的迟到错误不影响新请求,不同预设分别接收
|
||||
const previous = f.face.loadPreview('standard')
|
||||
const previousRequest = f.take('preview')
|
||||
const updating = f.face.refresh()
|
||||
f.answer(f.take('status'), status('updated'))
|
||||
f.answer(f.take('status'), status('0.2.6'))
|
||||
await updating
|
||||
const current = f.face.loadPreview('standard')
|
||||
const currentRequest = f.take('preview')
|
||||
@@ -97,13 +104,13 @@ test('配置事件与手动刷新重叠时保留新状态,所有请求结束
|
||||
const older = f.face.refresh()
|
||||
const olderRequest = f.take('status')
|
||||
f.documentUpdated()
|
||||
f.answer(f.take('status'), status('current'))
|
||||
f.answer(f.take('status'), status('0.2.6'))
|
||||
await settle()
|
||||
assert.equal(f.view().busy, true)
|
||||
if (outcome === 'success') f.answer(olderRequest, status('obsolete'))
|
||||
if (outcome === 'success') f.answer(olderRequest, status('0.2.5'))
|
||||
else olderRequest.reject(new Error('obsolete status failure'))
|
||||
await older
|
||||
assert.equal(f.view().status.contract, 'current')
|
||||
assert.equal(f.view().status.version, '0.2.6')
|
||||
assert.equal(f.view().message, undefined)
|
||||
assert.equal(f.view().busy, false)
|
||||
}
|
||||
@@ -121,14 +128,50 @@ test('开关提交立即使旧预览失效,配置事件刷新不能提前结
|
||||
f.answer(previewRequest, { available: true, text: 'before toggle' })
|
||||
await preview
|
||||
assert.equal(f.view().previews.standard, undefined)
|
||||
f.answer(f.take('status'), status('event refresh', false))
|
||||
f.answer(f.take('status'), status('0.2.6', false))
|
||||
await settle()
|
||||
assert.equal(f.view().busy, true, '配置事件的读取结束后,写入仍在等待应答')
|
||||
writeRequest.resolve(true)
|
||||
await settle()
|
||||
assert.equal(f.view().busy, true)
|
||||
f.answer(f.take('status'), status('write refresh', false))
|
||||
f.answer(f.take('status'), status('0.2.6', false))
|
||||
await writing
|
||||
assert.equal(f.view().busy, false)
|
||||
assert.equal(f.view().status.enabled, false)
|
||||
})
|
||||
|
||||
test('版本检查与手动更新正确推进状态并透传目标版本', async () => {
|
||||
const f = await fixture()
|
||||
assert.equal(f.view().update.state, 'idle')
|
||||
|
||||
const checking = f.face.checkUpdate(true)
|
||||
assert.equal(f.view().update.state, 'checking')
|
||||
const checkReq = f.take('check-update')
|
||||
assert.deepEqual(checkReq.payload, { force: true })
|
||||
f.answer(checkReq, {
|
||||
state: 'available',
|
||||
currentVersion: '0.2.6',
|
||||
latestVersion: '0.2.7',
|
||||
latestTag: 'v0.2.7',
|
||||
installSource: 'github',
|
||||
})
|
||||
await checking
|
||||
assert.equal(f.view().update.state, 'available')
|
||||
assert.equal(f.view().update.latestVersion, '0.2.7')
|
||||
|
||||
const installing = f.face.performUpdate()
|
||||
assert.equal(f.view().update.state, 'updating')
|
||||
const installReq = f.take('perform-update')
|
||||
assert.deepEqual(installReq.payload, { targetTag: 'v0.2.7' })
|
||||
f.answer(installReq, {
|
||||
state: 'updated',
|
||||
currentVersion: '0.2.6',
|
||||
latestVersion: '0.2.7',
|
||||
updatedVersion: '0.2.7',
|
||||
restartRequired: true,
|
||||
installSource: 'github',
|
||||
})
|
||||
await installing
|
||||
assert.equal(f.view().update.state, 'updated')
|
||||
assert.equal(f.view().update.restartRequired, true)
|
||||
})
|
||||
@@ -4,7 +4,7 @@ import { test } from 'node:test'
|
||||
|
||||
const manifest = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
|
||||
|
||||
test('declares the current master client renderer and settings dependencies', () => {
|
||||
test('declares the current client renderer, settings dependencies, and Web + Desktop engine range', () => {
|
||||
assert.deepEqual(manifest.dsh.client.inject, [
|
||||
'@deepseek-ai/dsh-client-connection',
|
||||
'@deepseek-ai/dsh-client-locale',
|
||||
@@ -15,4 +15,5 @@ test('declares the current master client renderer and settings dependencies', ()
|
||||
])
|
||||
assert.equal(manifest.dsh.client.platform, 'web')
|
||||
assert.equal(manifest.dsh.bundle.patch, './cordis.patch.yml')
|
||||
assert.equal(manifest.engines.dsh, '>=0.2.0-rc.2 <0.2.3-0')
|
||||
})
|
||||
+39
-46
@@ -11,8 +11,8 @@ import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
ANCHORS, BLOCK_SECTION, EXECUTION_MODE_BLOCK, PRESETS, contractAdditions,
|
||||
contractFingerprint, fuseSections, fusedMinimalPrompt, renderPreview,
|
||||
ANCHORS, BLOCK_SECTION, EXECUTION_MODE_BLOCK, PRESETS, compareSemver, contractAdditions,
|
||||
fuseSections, fusedMinimalPrompt, normalizeVersion, renderPreview,
|
||||
} from '../src/rules.js'
|
||||
|
||||
const FIXTURES = fileURLToPath(new URL('./fixtures/', import.meta.url))
|
||||
@@ -119,51 +119,51 @@ test('fused output equals the original render plus only the documented fragments
|
||||
assert.ok(await originalOf('standard') === originalText)
|
||||
})
|
||||
|
||||
test('tampered anchors refuse to fuse and name the failing rule', async () => {
|
||||
test('structural fusion tolerates upstream wording edits while refusing missing personas and staying idempotent', async () => {
|
||||
const sections = await sectionsOf('standard')
|
||||
|
||||
const identity = sections.map(section =>
|
||||
section.name === 'harness:identity' ? { ...section, text: 'You are a different harness.' } : section)
|
||||
assert.ok(fuseSections(identity, 'standard').issues.some(issue => issue.includes('identity')))
|
||||
// Upstream wording tweaks in identity, persona, plan, or ptc-only do not break fusion.
|
||||
const reworded = sections.map((section) => {
|
||||
if (section.name === 'harness:identity') return { ...section, text: 'You are a custom harness.' }
|
||||
if (section.name === 'deployment:persona-prefix') return { ...section, text: 'You are a specialized engineer.' }
|
||||
if (section.name === 'plan:policy') return { ...section, text: 'Plan mode active with custom guidance.' }
|
||||
return section
|
||||
})
|
||||
const fused = fuseSections(reworded, 'standard')
|
||||
assert.equal(fused.issues, undefined)
|
||||
const persona = fused.sections.find(section => section.name === 'deployment:persona-prefix')
|
||||
assert.ok(persona.text.startsWith('You are a specialized engineer.'))
|
||||
assert.ok(persona.text.endsWith(contractAdditions('standard').pointer))
|
||||
const plan = fused.sections.find(section => section.name === 'plan:policy')
|
||||
assert.ok(plan.text.startsWith('Plan mode active with custom guidance.'))
|
||||
assert.ok(plan.text.endsWith(contractAdditions('standard').planNote))
|
||||
|
||||
const persona = sections.map(section =>
|
||||
section.name === 'deployment:persona-prefix' ? { ...section, text: 'You are someone else.' } : section)
|
||||
const personaResult = fuseSections(persona, 'standard')
|
||||
assert.ok(personaResult.issues.some(issue => issue.includes('persona')))
|
||||
// Idempotent: re-fusing already-fused sections produces identical sections.
|
||||
const twice = fuseSections(fused.sections, 'standard')
|
||||
assert.equal(twice.issues, undefined)
|
||||
assert.deepEqual(twice.sections, fused.sections)
|
||||
|
||||
// Missing or blank deployment:persona-prefix is refused with structured issue code.
|
||||
const missingPersona = sections.filter(section => section.name !== 'deployment:persona-prefix')
|
||||
assert.ok(fuseSections(missingPersona, 'standard').issues.some(issue => issue.includes('persona')))
|
||||
// A delegated child may carry its own persona: tolerated, still fused, and
|
||||
// receives the persona pointer.
|
||||
const tolerated = fuseSections(persona, 'standard', { isSubagent: true })
|
||||
assert.equal(tolerated.issues, undefined)
|
||||
const toleratedPersona = tolerated.sections.find(section => section.name === 'deployment:persona-prefix')
|
||||
assert.ok(toleratedPersona.text.startsWith('You are someone else.'))
|
||||
assert.ok(toleratedPersona.text.endsWith(contractAdditions('standard').pointer))
|
||||
assert.deepEqual(fuseSections(missingPersona, 'standard').issues, ['missing-persona'])
|
||||
const blankPersona = sections.map(section =>
|
||||
section.name === 'deployment:persona-prefix' ? { ...section, text: ' ' } : section)
|
||||
assert.deepEqual(fuseSections(blankPersona, 'standard').issues, ['missing-persona'])
|
||||
})
|
||||
|
||||
test('plan-mode tampering is detected only when the section is active', async () => {
|
||||
const off = await sectionsOf('standard')
|
||||
const offTampered = off.map(section =>
|
||||
section.name === 'plan:policy' ? { ...section, text: 'unexpected' } : section)
|
||||
// plan:policy is empty while plan mode is off; a non-empty unknown text fails.
|
||||
assert.ok(fuseSections(offTampered, 'standard').issues.some(issue => issue.includes('plan')))
|
||||
|
||||
const on = await sectionsOf('standard-plan')
|
||||
const onExtended = on.map(section =>
|
||||
section.name === 'plan:policy' ? { ...section, text: `${ANCHORS.planPrefix} Extra guidance.` } : section)
|
||||
// A text that keeps the anchor prefix still fuses; only a changed anchor fails.
|
||||
assert.equal(fuseSections(onExtended, 'standard').issues, undefined)
|
||||
test('unknown presets are refused with unsupported-preset', () => {
|
||||
assert.deepEqual(fuseSections([], 'my-custom-preset').issues, ['unsupported-preset'])
|
||||
})
|
||||
|
||||
test('ptc mode reports a changed run_code anchor', async () => {
|
||||
const sections = await sectionsOf('ptc')
|
||||
const tampered = sections.map(section =>
|
||||
section.name === 'tools:ptc-only' ? { ...section, text: 'call whatever' } : section)
|
||||
assert.ok(fuseSections(tampered, 'ptc').issues.some(issue => issue.includes('run_code')))
|
||||
})
|
||||
|
||||
test('unknown presets are refused', () => {
|
||||
assert.ok(fuseSections([], 'my-custom-preset').issues[0].includes('unknown preset'))
|
||||
test('normalizeVersion and compareSemver compare release versions accurately', () => {
|
||||
assert.equal(normalizeVersion('v0.2.6'), '0.2.6')
|
||||
assert.equal(normalizeVersion(' 0.2.6-rc.1+build '), '0.2.6-rc.1')
|
||||
assert.equal(normalizeVersion('invalid'), undefined)
|
||||
assert.equal(compareSemver('0.2.6', '0.2.5'), 1)
|
||||
assert.equal(compareSemver('0.2.6', '0.2.6'), 0)
|
||||
assert.equal(compareSemver('0.2.5', '0.2.6'), -1)
|
||||
assert.equal(compareSemver('0.2.6', '0.2.6-rc.1'), 1)
|
||||
assert.equal(compareSemver('0.2.6-alpha.2', '0.2.6-alpha.1'), 1)
|
||||
})
|
||||
|
||||
test('minimal fused prompt is persona + pointer + block, anchors intact, and preserves structured_output', () => {
|
||||
@@ -302,13 +302,6 @@ test('the contract force-defaults NSFW characters to 18+ without age judgment',
|
||||
assert.ok(EXECUTION_MODE_BLOCK.includes('Citing canon age, refusing on age grounds'))
|
||||
})
|
||||
|
||||
test('the contract fingerprint identifies the deployed bytes', async () => {
|
||||
const { createHash } = await import('node:crypto')
|
||||
const expected = createHash('sha256').update(EXECUTION_MODE_BLOCK, 'utf8').digest('hex').slice(0, 16)
|
||||
assert.equal(contractFingerprint(), expected)
|
||||
assert.match(contractFingerprint(), /^[0-9a-f]{16}$/)
|
||||
})
|
||||
|
||||
test('renderPreview survives a standing scope whose variables are unbound', async () => {
|
||||
// The harness renderer throws on an undefined reference, which is exactly
|
||||
// what a standing scope produces for {{model}} / {{cwd}}. Mirror that
|
||||
|
||||
Reference in new issue
Block a user