From 01581beb0fdbd9a0ef49577070853a8d592058b0 Mon Sep 17 00:00:00 2001 From: dsh-bot Date: Wed, 11 Nov 2026 23:23:31 +0800 Subject: [PATCH] test(v1.1): whole-plugin load smoke + route coverage --- docs/management-surface.md | 2 + verify-full-load.mjs | 85 ++++++++++++++++++++++++++++++++++++++ verify-plugin-entry.mjs | 4 ++ 3 files changed, 91 insertions(+) create mode 100644 verify-full-load.mjs diff --git a/docs/management-surface.md b/docs/management-surface.md index e01e3ee..54b0415 100644 --- a/docs/management-surface.md +++ b/docs/management-surface.md @@ -286,6 +286,8 @@ HTTP 层统一映射为 **409 `sync_running`**。`verify-concurrency.mjs`:8 ### 9.5 验证 - `verify-clients.mjs`:19 项通过(六适配器、安装检测、只读边界、DSH 注册工作区+分类、工作区专属技能、手动登记/去重/未知工作区、路由、能力位、迁移幂等与原文件保留)。 +- `verify-full-load.mjs`:12 项通过——用真实 `apply()` 在宿主形状上下文加载 0.7.0,起真实 HTTP 服务后逐一查询 capabilities(0.7.0 + P3/P4/P5/v1.1 能力位)、market/providers、sync/status、clients/overview(6 适配器)、clients/inventory、migrate/brain、skills/api、status,全部返回正常。 + diff --git a/verify-full-load.mjs b/verify-full-load.mjs new file mode 100644 index 0000000..22cf183 --- /dev/null +++ b/verify-full-load.mjs @@ -0,0 +1,85 @@ +// Whole-plugin load test: activate the real `apply()` against a host-shaped +// context, then serve the exact routes it registered over a real HTTP server and +// query them. This proves the 0.7.0 build loads and serves every surface a DSH +// restart will expose, without needing to restart the desktop app. +import http from 'node:http' +import { mkdtempSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' + +process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'brain-load-')) + +const results = [] +function check(name, ok, detail) { + results.push({ name, ok }) + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail === undefined ? '' : ` :: ${detail}`}`) +} + +const { apply } = await import('./lib/index.js') + +const routes = [] +const disposers = [] +const ctx = { + logger: () => ({ info: () => {}, warn: () => {} }), + effect: (fn) => { const result = fn(); if (typeof result === 'function') disposers.push(result); return () => {} }, + on: () => () => {}, + inject: (_deps, fn) => fn({ tools: { register: () => () => {} }, effect: (inner) => { inner(); return () => {} } }), + webServer: { register: (route) => { routes.push(route); return () => {} } }, +} + +let applied = true +try { + apply(ctx, { baseUrl: 'https://your-memory-host/api/longmemory', clientId: 'load-test' }) +} catch (failure) { + applied = false + console.log('apply threw:', failure) +} +check('apply() loads against a host-shaped context', applied) + +const server = http.createServer((req, res) => { + const path = (req.url ?? '/').split('?')[0] + for (const route of routes) { + if (route.kind === 'exact' && path === route.path) return route.handler(req, res) + if (route.kind === 'prefix' && (path === route.path || path.startsWith(`${route.path}/`))) return route.handler(req, res) + } + res.writeHead(404, { 'content-type': 'application/json' }) + res.end('{"ok":false,"error":"no-route"}') +}) +await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)) +const origin = `http://127.0.0.1:${server.address().port}` +async function get(path) { + const response = await fetch(`${origin}${path}`) + return { status: response.status, body: await response.json().catch(() => null) } +} +async function post(path, body) { + const response = await fetch(`${origin}${path}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body ?? {}) }) + return { status: response.status, body: await response.json().catch(() => null) } +} + +const caps = await get('/cloud-memory/capabilities') +check('capabilities answers with 0.7.0', caps.body?.version === '0.7.0', String(caps.body?.version)) +check('P3 market is advertised with one provider', caps.body?.features?.skillsMarketplace === true && caps.body?.features?.marketProviders === 1) +check('P3 update and sync-resolve are advertised', caps.body?.features?.skillUpdate === true && caps.body?.features?.syncResolve === true) +check('P4/P5/v1.1 flags are advertised', caps.body?.features?.multiClient === true && caps.body?.features?.brainMigration === 'pending-deploy') + +const providers = await get('/cloud-memory/market/providers') +check('market providers route lists the verified source', providers.body?.providers?.[0]?.id === 'anthropic-skills', JSON.stringify(providers.body?.providers)) +const sync = await get('/cloud-memory/sync/status') +check('sync status route answers', sync.body?.ok === true && Array.isArray(sync.body?.conflicts)) +const clients = await get('/cloud-memory/clients/overview') +check('clients overview lists six adapters', clients.body?.ok === true && clients.body?.adapters?.length === 6) +const brain = await get('/cloud-memory/migrate/brain') +check('brain migration status answers', brain.body?.ok === true && brain.body?.product === 'DSH Brain' && brain.body?.packageRename === 'pending-deploy') +const inv = await get('/cloud-memory/clients/inventory?software=dsh&scope=global') +check('inventory route answers for DSH', inv.body?.ok === true && Array.isArray(inv.body?.items)) +const skills = await get('/cloud-memory/skills/api') +check('skill inventory route answers', skills.body?.ok === true && Array.isArray(skills.body?.skills)) +const status = await get('/cloud-memory/status') +check('status route answers', status.body?.ok === true && status.body?.settings?.baseUrlConfigured === false) + +await new Promise((resolve) => server.close(resolve)) +for (const dispose of disposers) { try { dispose() } catch { /* teardown noise */ } } + +const failed = results.filter((item) => !item.ok).length +console.log(failed === 0 ? `\nALL ${results.length} CHECKS PASSED` : `\n${failed} CHECK(S) FAILED`) +process.exit(failed === 0 ? 0 : 1) diff --git a/verify-plugin-entry.mjs b/verify-plugin-entry.mjs index 762feb0..5235267 100644 --- a/verify-plugin-entry.mjs +++ b/verify-plugin-entry.mjs @@ -69,6 +69,10 @@ const expected = [ 'exact:/cloud-memory/test', 'exact:/cloud-memory/flush', 'prefix:/cloud-memory/skills', + 'prefix:/cloud-memory/market', + 'prefix:/cloud-memory/sync', + 'prefix:/cloud-memory/clients', + 'prefix:/cloud-memory/migrate', ] const actual = routes.map((route) => `${route.kind}:${route.path}`) check('every route the card depends on is registered', expected.every((item) => actual.includes(item)), actual.join(' | '))