@clawdao/limschain-agent 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +41 -0
- package/CHANGELOG.md +223 -0
- package/Dockerfile +50 -0
- package/LICENSE +21 -0
- package/README.md +627 -0
- package/bin/lims-mcp.mjs +101 -0
- package/bin/lims.mjs +1639 -0
- package/docs/MARKETPLACE-GUIDELINES.md +99 -0
- package/docs/clawdao-mcp-listing.md +308 -0
- package/docs/clawdao-mcp-setup.md +294 -0
- package/docs/ddn-hub-postType-issue.md +54 -0
- package/docs/deploy-http.md +192 -0
- package/docs/install-mcp.md +268 -0
- package/docs/limschain-migration-and-readme-backfill.md +212 -0
- package/docs/marketplace-readmes/clawdao-video-factory.md +49 -0
- package/docs/node-free-install.md +196 -0
- package/docs/release-notes/v1.0.30-short.md +63 -0
- package/docs/site-design-studio-api.md +162 -0
- package/lib/articles.mjs +397 -0
- package/lib/client.mjs +588 -0
- package/lib/courses.mjs +169 -0
- package/lib/dao.mjs +195 -0
- package/lib/env.mjs +32 -0
- package/lib/feedback.mjs +68 -0
- package/lib/http-server.mjs +257 -0
- package/lib/marketplace-readme-path.mjs +17 -0
- package/lib/marketplace.mjs +273 -0
- package/lib/materials.mjs +260 -0
- package/lib/mcp-server.mjs +334 -0
- package/lib/site.mjs +471 -0
- package/lib/versions.mjs +904 -0
- package/mcp-listing.http.json +25 -0
- package/mcp-listing.json +34 -0
- package/package.json +77 -0
- package/scripts/build-binary.mjs +104 -0
- package/scripts/build-site-dashboard.mjs +52 -0
- package/scripts/collect-site-articles.mjs +432 -0
- package/scripts/export-ddn-env.mjs +107 -0
- package/scripts/fetch-article-stats.mjs +212 -0
- package/scripts/pack-and-verify.mjs +111 -0
- package/scripts/publisher.mjs +255 -0
- package/scripts/sync-marketplace-readme.mjs +380 -0
- package/scripts/tool-set.mjs +48 -0
- package/scripts/verify-binary.mjs +115 -0
- package/scripts/verify-clawdao-bridge.mjs +41 -0
- package/scripts/verify-e2e.mjs +176 -0
- package/scripts/verify-http-mcp.mjs +94 -0
- package/scripts/verify-listing-sync.mjs +90 -0
- package/scripts/verify-marketplace-readme.mjs +266 -0
- package/scripts/verify-mcp-handshake.mjs +98 -0
- package/scripts/verify-news-publish.mjs +257 -0
- package/scripts/verify-npx-install.mjs +171 -0
- package/scripts/verify-site-dashboard.mjs +87 -0
- package/scripts/verify-site-layout.mjs +194 -0
- package/tests/client-auth.test.mjs +159 -0
- package/tests/dao-profile.test.mjs +126 -0
- package/tests/marketplace-readme-path.test.mjs +16 -0
- package/tests/mcp-server.test.mjs +187 -0
- package/tests/member-submission.test.mjs +150 -0
- package/tests/official-listing.test.mjs +52 -0
- package/tests/smoke.mjs +262 -0
- package/tests/sync-marketplace-readme.test.mjs +50 -0
- package/tests/tool-set.test.mjs +54 -0
- package/tests/versions-sync-dryrun.test.mjs +315 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import { ArticleManager } from '../lib/articles.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 2026-11-27(plan 158 追问)—— **成员投稿**链路的守卫。
|
|
8
|
+
*
|
|
9
|
+
* ── 为什么要有这个文件 ────────────────────────────────────────────────────
|
|
10
|
+
* 实跑取证(server 侧 egg-bin e2e):
|
|
11
|
+
* · 成员 `POST /api/v1/posts`(status=published)⇒ **201**,落库 draft+pending,
|
|
12
|
+
* 文案「内容已提交组织审核(您没有直接发布权限,发布需组织管理员确认)」;
|
|
13
|
+
* · 成员 `POST /api/v1/posts/:id/publish` ⇒ **403 PERMISSION_DENIED**
|
|
14
|
+
* `permission=cms:posts:update`。
|
|
15
|
+
*
|
|
16
|
+
* 也就是说:**成员能投稿、不能发**。服务端的产品口径是
|
|
17
|
+
* 「组织成员只能投稿,公开可见必须由组织管理员拍板」。
|
|
18
|
+
*
|
|
19
|
+
* MCP 侧曾在这里出过两个错:
|
|
20
|
+
* ① plan 158 去掉「自审自发」后,`publishViaPlatform` 忘了判 `platformGetPost` 的 ok
|
|
21
|
+
* ⇒ 平台侧读被拒时 status=undefined ⇒ 跳过状态机 ⇒ 谎报「文章已创建并发布」;
|
|
22
|
+
* ② 成员那条 403 被当成「发布失败」⇒ 智能体据此推断「成员不具备发布文章权限」
|
|
23
|
+
* (与事实相反:成员**能**投稿)。
|
|
24
|
+
*
|
|
25
|
+
* ⇒ 这里把三条口径钉死:不得谎报成功 / 投稿待审 ≠ 失败 / 越权必须报错。
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** 服务端 403 信封(真实形状:body.data 里带 permission / reason) */
|
|
29
|
+
const permissionDenied = (permission, permissionLabel = '更新内容') => ({
|
|
30
|
+
success: false,
|
|
31
|
+
code: 'PERMISSION_DENIED',
|
|
32
|
+
message: `权限不足:需要「${permissionLabel}」权限`,
|
|
33
|
+
data: { permission, permissionLabel, requiredPermission: permission, reason: 'role_required' },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 拦掉全局 fetch,按 (method, url) 命中返回固定信封。
|
|
38
|
+
* @param {(method: string, url: string) => {status: number, body: any}} handler
|
|
39
|
+
*/
|
|
40
|
+
const withFetch = async (handler, fn) => {
|
|
41
|
+
const original = globalThis.fetch;
|
|
42
|
+
const calls = [];
|
|
43
|
+
globalThis.fetch = async (url, init) => {
|
|
44
|
+
const method = init?.method || 'GET';
|
|
45
|
+
const u = String(url);
|
|
46
|
+
calls.push(`${method} ${u}`);
|
|
47
|
+
const { status, body } = handler(method, u);
|
|
48
|
+
return {
|
|
49
|
+
ok: status < 400,
|
|
50
|
+
status,
|
|
51
|
+
headers: { get: () => 'application/json' },
|
|
52
|
+
text: async () => JSON.stringify(body),
|
|
53
|
+
json: async () => body,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
return await fn(calls);
|
|
58
|
+
} finally {
|
|
59
|
+
globalThis.fetch = original;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const createOkBody = {
|
|
64
|
+
status: 0,
|
|
65
|
+
msg: '内容已提交组织审核(您没有直接发布权限,发布需组织管理员确认)',
|
|
66
|
+
data: {
|
|
67
|
+
id: 4242,
|
|
68
|
+
visibilityStatus: 'draft',
|
|
69
|
+
complianceStatus: 'pending',
|
|
70
|
+
status: 'draft',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const manager = () =>
|
|
75
|
+
new ArticleManager({
|
|
76
|
+
baseUrl: 'https://limschain.example',
|
|
77
|
+
authToken: `jzd_${'a'.repeat(8)}_${'b'.repeat(64)}`,
|
|
78
|
+
daoId: 'dao-b',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const UPLOAD = {
|
|
82
|
+
title: '成员投稿守卫标题',
|
|
83
|
+
description: '成员投稿守卫描述',
|
|
84
|
+
content: '成员投稿守卫正文,长度超过二十个字符以满足内容长度约束。',
|
|
85
|
+
postType: 'news',
|
|
86
|
+
publish: true,
|
|
87
|
+
daoId: 'dao-b',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
test('成员投稿:租户侧 publish 403(cms:posts:update) ⇒ 回报「已投稿待审」,不得谎报已发布', async () => {
|
|
91
|
+
await withFetch(
|
|
92
|
+
(method, url) => {
|
|
93
|
+
if (method === 'POST' && url.endsWith('/api/v1/posts')) {
|
|
94
|
+
return { status: 201, body: createOkBody };
|
|
95
|
+
}
|
|
96
|
+
if (method === 'POST' && /\/api\/v1\/posts\/\d+\/publish$/.test(url)) {
|
|
97
|
+
return { status: 403, body: permissionDenied('cms:posts:update') };
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`不该打这个端点: ${method} ${url}`);
|
|
100
|
+
},
|
|
101
|
+
async (calls) => {
|
|
102
|
+
const res = await manager().upload(UPLOAD);
|
|
103
|
+
|
|
104
|
+
assert.equal(res.pendingReview, true, '成员投稿必须标记 pendingReview');
|
|
105
|
+
assert.notEqual(res.message, '文章已创建并发布', '不得谎报已发布');
|
|
106
|
+
assert.match(res.message, /尚未公开/, '文案必须说明尚未公开');
|
|
107
|
+
assert.match(res.message, /组织管理员/, '文案必须说明由组织管理员拍板');
|
|
108
|
+
assert.ok(
|
|
109
|
+
!calls.some((c) => c.includes('/api/v1/platform/posts')),
|
|
110
|
+
'成员没有平台权限,不该再去兜底平台侧',
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('平台侧读被拒 ⇒ publishViaPlatform 必须返回失败,绝不能回 ok:true', async () => {
|
|
117
|
+
await withFetch(
|
|
118
|
+
(method, url) => {
|
|
119
|
+
if (method === 'GET' && /\/api\/v1\/platform\/posts\/\d+$/.test(url)) {
|
|
120
|
+
return { status: 403, body: permissionDenied('platform:posts:view', '查看平台文章') };
|
|
121
|
+
}
|
|
122
|
+
throw new Error(`不该打这个端点: ${method} ${url}`);
|
|
123
|
+
},
|
|
124
|
+
async () => {
|
|
125
|
+
const res = await manager().publishViaPlatform(4242, {});
|
|
126
|
+
assert.equal(res.ok, false, '平台侧读失败 ⇒ 必须失败');
|
|
127
|
+
assert.match(res.message, /平台侧读取文章状态失败/);
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('越权 403(不是 cms:posts:update)⇒ 必须报错,不得当成「投稿待审」', async () => {
|
|
133
|
+
await withFetch(
|
|
134
|
+
(method, url) => {
|
|
135
|
+
if (method === 'POST' && /\/api\/v1\/posts\/\d+\/publish$/.test(url)) {
|
|
136
|
+
return { status: 403, body: permissionDenied('dao:communities:view', '社区查看') };
|
|
137
|
+
}
|
|
138
|
+
if (method === 'GET' && /\/api\/v1\/platform\/posts\/\d+$/.test(url)) {
|
|
139
|
+
return { status: 403, body: permissionDenied('platform:posts:view', '查看平台文章') };
|
|
140
|
+
}
|
|
141
|
+
throw new Error(`不该打这个端点: ${method} ${url}`);
|
|
142
|
+
},
|
|
143
|
+
async () => {
|
|
144
|
+
const res = await manager().publish(4242, {});
|
|
145
|
+
assert.equal(res.pendingReview, undefined, '越权不是投稿待审');
|
|
146
|
+
assert.equal(res.ok, false, '越权必须失败');
|
|
147
|
+
assert.match(res.message, /权限不足/);
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { TOOL_NAMES } from '../lib/mcp-server.mjs';
|
|
8
|
+
|
|
9
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
|
+
|
|
11
|
+
const readJson = (rel) => JSON.parse(readFileSync(join(ROOT, rel), 'utf-8'));
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 官方清单条目里的「N 个 MCP 工具」是**给用户看的承诺**,
|
|
15
|
+
* 加了工具忘了改清单 ⇒ 承诺与事实脱节(而且是跨仓的,clawdao 侧那份是拷贝)。
|
|
16
|
+
*
|
|
17
|
+
* 这里的判据从 TOOL_NAMES.length **派生** —— 不写死 14/15。
|
|
18
|
+
*/
|
|
19
|
+
const COUNT_PATTERNS = [
|
|
20
|
+
{ key: 'zh', re: /((\d+)\s*个 MCP 工具)/ },
|
|
21
|
+
{ key: 'en', re: /\((\d+)\s*MCP tools\)/ },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
for (const file of ['mcp-listing.json', 'mcp-listing.http.json']) {
|
|
25
|
+
test(`${file}:三语描述里的工具数都等于源码实际工具数`, () => {
|
|
26
|
+
const data = readJson(file);
|
|
27
|
+
assert.ok(Array.isArray(data.servers) && data.servers.length > 0, `${file} 没有 servers`);
|
|
28
|
+
|
|
29
|
+
for (const server of data.servers) {
|
|
30
|
+
for (const field of ['description', 'description_zh', 'description_en']) {
|
|
31
|
+
const text = server[field];
|
|
32
|
+
assert.ok(typeof text === 'string' && text.length > 0, `${server.id}.${field} 缺失`);
|
|
33
|
+
const pattern = field === 'description_en' ? COUNT_PATTERNS[1] : COUNT_PATTERNS[0];
|
|
34
|
+
const m = text.match(pattern.re);
|
|
35
|
+
assert.ok(m, `${server.id}.${field} 里找不到工具数(期望形如「(15 个 MCP 工具)」/「(15 MCP tools)」):${text}`);
|
|
36
|
+
assert.equal(
|
|
37
|
+
Number(m[1]),
|
|
38
|
+
TOOL_NAMES.length,
|
|
39
|
+
`${server.id}.${field} 写的是 ${m[1]} 个工具,源码实际 ${TOOL_NAMES.length} 个 —— 官方清单与源码脱节`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test('mcp-listing.json 的 limschain 条目与 http 形态描述的工具数一致', () => {
|
|
47
|
+
const stdio = readJson('mcp-listing.json').servers.find((s) => s.id === 'limschain');
|
|
48
|
+
const http = readJson('mcp-listing.http.json').servers.find((s) => s.id === 'limschain-http');
|
|
49
|
+
assert.ok(stdio && http, '两个清单文件都必须有 limschain 条目');
|
|
50
|
+
const countOf = (text) => Number(text.match(/\((\d+)\s*MCP tools\)/)[1]);
|
|
51
|
+
assert.equal(countOf(stdio.description_en), countOf(http.description_en));
|
|
52
|
+
});
|
package/tests/smoke.mjs
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Smoke tests for @clawdao/limschain-agent
|
|
4
|
+
* - 验证 lib/ 所有模块可加载(不要求真网络调用)
|
|
5
|
+
* - 验证 CLI 可启动并打印 usage
|
|
6
|
+
* - 验证 LimsClient 配置解析(不需要 DDN_HUB_* 也能 fail soft)
|
|
7
|
+
*
|
|
8
|
+
* 运行:node tests/smoke.mjs
|
|
9
|
+
* 或 npm run test:smoke
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { LimsClient } from '../lib/client.mjs';
|
|
13
|
+
import { ArticleManager } from '../lib/articles.mjs';
|
|
14
|
+
import { CourseManager } from '../lib/courses.mjs';
|
|
15
|
+
import { FeedbackManager } from '../lib/feedback.mjs';
|
|
16
|
+
import { MarketplaceManager } from '../lib/marketplace.mjs';
|
|
17
|
+
import { VersionManager, KNOWN_PRODUCT_IDS, emptyReleaseNotes, buildZhNotes } from '../lib/versions.mjs';
|
|
18
|
+
import { MaterialManager, MATERIAL_TYPES } from '../lib/materials.mjs';
|
|
19
|
+
import { DaoManager } from '../lib/dao.mjs';
|
|
20
|
+
|
|
21
|
+
let passed = 0;
|
|
22
|
+
let failed = 0;
|
|
23
|
+
|
|
24
|
+
function ok(name) {
|
|
25
|
+
passed++;
|
|
26
|
+
console.log(` ✓ ${name}`);
|
|
27
|
+
}
|
|
28
|
+
function fail(name, err) {
|
|
29
|
+
failed++;
|
|
30
|
+
console.error(` ✗ ${name}: ${err && err.message ? err.message : err}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log('🧪 @clawdao/limschain-agent smoke tests\n');
|
|
34
|
+
|
|
35
|
+
// 1. 所有 lib 模块可加载
|
|
36
|
+
console.log('[1/4] 模块加载');
|
|
37
|
+
try { LimsClient; ok('LimsClient 加载'); } catch (e) { fail('LimsClient', e); }
|
|
38
|
+
try { ArticleManager; ok('ArticleManager 加载'); } catch (e) { fail('ArticleManager', e); }
|
|
39
|
+
try { CourseManager; ok('CourseManager 加载'); } catch (e) { fail('CourseManager', e); }
|
|
40
|
+
try { FeedbackManager; ok('FeedbackManager 加载'); } catch (e) { fail('FeedbackManager', e); }
|
|
41
|
+
try { MarketplaceManager; ok('MarketplaceManager 加载'); } catch (e) { fail('MarketplaceManager', e); }
|
|
42
|
+
try { VersionManager; ok('VersionManager 加载'); } catch (e) { fail('VersionManager', e); }
|
|
43
|
+
try { MaterialManager; ok('MaterialManager 加载'); } catch (e) { fail('MaterialManager', e); }
|
|
44
|
+
try { DaoManager; ok('DaoManager 加载'); } catch (e) { fail('DaoManager', e); }
|
|
45
|
+
|
|
46
|
+
// 2. 工具函数
|
|
47
|
+
console.log('\n[2/4] 工具函数');
|
|
48
|
+
try {
|
|
49
|
+
const notes = emptyReleaseNotes();
|
|
50
|
+
if (notes.zh.length === 0 && notes.en.length === 0) ok('emptyReleaseNotes 返回空对象');
|
|
51
|
+
else fail('emptyReleaseNotes', '应返回 {zh:[],en:[]}');
|
|
52
|
+
} catch (e) { fail('emptyReleaseNotes', e); }
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const out = buildZhNotes('<h2>x</h2>');
|
|
56
|
+
if (Array.isArray(out) && out[0] === '<h2>x</h2>') ok('buildZhNotes(string) 包装为数组');
|
|
57
|
+
else fail('buildZhNotes', '未正确包装');
|
|
58
|
+
} catch (e) { fail('buildZhNotes(string)', e); }
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const out = buildZhNotes(['<a>', '<b>']);
|
|
62
|
+
if (out.length === 2 && out[0] === '<a>') ok('buildZhNotes(array) 保留原数组');
|
|
63
|
+
else fail('buildZhNotes(array)', '未保留');
|
|
64
|
+
} catch (e) { fail('buildZhNotes(array)', e); }
|
|
65
|
+
|
|
66
|
+
// 3. KNOWN_PRODUCT_IDS
|
|
67
|
+
console.log('\n[3/4] KNOWN_PRODUCT_IDS');
|
|
68
|
+
try {
|
|
69
|
+
if (KNOWN_PRODUCT_IDS.clawdao && /^[0-9a-f-]{36}$/.test(KNOWN_PRODUCT_IDS.clawdao)) {
|
|
70
|
+
ok(`clawdao UUID 格式正确: ${KNOWN_PRODUCT_IDS.clawdao}`);
|
|
71
|
+
} else {
|
|
72
|
+
fail('KNOWN_PRODUCT_IDS.clawdao', '格式错误');
|
|
73
|
+
}
|
|
74
|
+
} catch (e) { fail('KNOWN_PRODUCT_IDS.clawdao', e); }
|
|
75
|
+
|
|
76
|
+
// 4. LimsClient fail-soft(无效 base_url 不崩溃)
|
|
77
|
+
console.log('\n[4/4] LimsClient fail-soft');
|
|
78
|
+
try {
|
|
79
|
+
const client = new LimsClient({ baseUrl: 'not-a-valid-url' });
|
|
80
|
+
const snap = client.getRuntimeSnapshot();
|
|
81
|
+
if (snap && snap.baseUrlValid === false) ok('明显无效的 baseUrl 被标记为 baseUrlValid:false');
|
|
82
|
+
else fail('LimsClient baseUrl validation', '未标记为 invalid');
|
|
83
|
+
} catch (e) { fail('LimsClient baseUrl', e); }
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const client = new LimsClient();
|
|
87
|
+
const snap = client.getRuntimeSnapshot();
|
|
88
|
+
if (snap && snap.baseUrl === 'https://limschain.com') ok('默认 baseUrl = https://limschain.com');
|
|
89
|
+
else fail('LimsClient default baseUrl', `got ${snap && snap.baseUrl}`);
|
|
90
|
+
} catch (e) { fail('LimsClient default', e); }
|
|
91
|
+
|
|
92
|
+
// 5. VersionManager 验证(不调 API)
|
|
93
|
+
try {
|
|
94
|
+
const vm = new VersionManager({ baseUrl: 'http://localhost' });
|
|
95
|
+
const r = await vm.create({ productId: '', version: '' });
|
|
96
|
+
if (!r.ok && r.error && r.error.kind === 'validation') ok('create 拒绝空 productId');
|
|
97
|
+
else fail('create validation', '应拒绝空 productId');
|
|
98
|
+
} catch (e) { fail('create validation', e); }
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const vm = new VersionManager({ baseUrl: 'http://localhost' });
|
|
102
|
+
const r = await vm.syncFromS3({ productKey: '', version: '' });
|
|
103
|
+
if (!r.ok && r.error && r.error.kind === 'validation') ok('syncFromS3 拒绝空参数');
|
|
104
|
+
else fail('syncFromS3 validation', '应拒绝空参数');
|
|
105
|
+
} catch (e) { fail('syncFromS3 validation', e); }
|
|
106
|
+
|
|
107
|
+
// platformToken 加载
|
|
108
|
+
try {
|
|
109
|
+
const client = new LimsClient({ authToken: 'dao-tok', platformToken: 'platform-tok' });
|
|
110
|
+
const snap = client.getRuntimeSnapshot();
|
|
111
|
+
if (snap.hasAuthToken && snap.hasPlatformToken) ok('LimsClient 同时加载 auth + platform token');
|
|
112
|
+
else fail('platform token loading', `hasAuth=${snap.hasAuthToken} hasPlatform=${snap.hasPlatformToken}`);
|
|
113
|
+
} catch (e) { fail('LimsClient platform token', e); }
|
|
114
|
+
|
|
115
|
+
// release() 走完整流程(不用真发布,只验证 schema)
|
|
116
|
+
try {
|
|
117
|
+
const vm = new VersionManager({ baseUrl: 'http://localhost' });
|
|
118
|
+
const r = await vm.release({});
|
|
119
|
+
if (!r.ok && r.error && r.error.kind === 'validation') ok('release 拒绝空 productKey');
|
|
120
|
+
else fail('release validation', '应拒绝');
|
|
121
|
+
} catch (e) { fail('release validation', e); }
|
|
122
|
+
|
|
123
|
+
// MaterialManager 健康检查(不调网络)
|
|
124
|
+
try {
|
|
125
|
+
const mm = new MaterialManager({ baseUrl: 'http://localhost', authToken: 'tok', daoId: 'dao-1' });
|
|
126
|
+
const h = mm.health();
|
|
127
|
+
if (h.ok && h.config.baseUrl === 'http://localhost') ok('MaterialManager.health() 通过(baseUrl + token + dao)');
|
|
128
|
+
else fail('MaterialManager.health()', h);
|
|
129
|
+
} catch (e) { fail('MaterialManager.health()', e); }
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
// 环境里若已导出 DDN_HUB_*(例如从 .env source 进来),会污染「缺凭证」这个用例:
|
|
133
|
+
// 客户端会从环境补上 token/dao,导致这里断言的 message 变了。先摘干净再断言。
|
|
134
|
+
const saved = {};
|
|
135
|
+
for (const key of ['DDN_HUB_BASE_URL', 'DDN_HUB_AUTH_TOKEN', 'DDN_HUB_PLATFORM_TOKEN', 'DDN_HUB_DAO_ID']) {
|
|
136
|
+
saved[key] = process.env[key];
|
|
137
|
+
delete process.env[key];
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const mm = new MaterialManager({ baseUrl: 'not-valid' }); // 缺 token & dao
|
|
141
|
+
const h = mm.health();
|
|
142
|
+
if (!h.ok && /token|DAO/i.test(h.message)) ok('MaterialManager.health() 缺凭证时返回 ok:false');
|
|
143
|
+
else fail('MaterialManager.health() missing-creds', h);
|
|
144
|
+
} finally {
|
|
145
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
146
|
+
if (value !== undefined) process.env[key] = value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} catch (e) { fail('MaterialManager.health() missing-creds', e); }
|
|
150
|
+
|
|
151
|
+
// MATERIAL_TYPES 常量
|
|
152
|
+
try {
|
|
153
|
+
const expected = ['image', 'video', 'file'];
|
|
154
|
+
const got = MATERIAL_TYPES.slice().sort();
|
|
155
|
+
if (expected.every((x) => got.includes(x))) ok('MATERIAL_TYPES = image/video/file');
|
|
156
|
+
else fail('MATERIAL_TYPES', `got ${got.join(',')}`);
|
|
157
|
+
} catch (e) { fail('MATERIAL_TYPES', e); }
|
|
158
|
+
|
|
159
|
+
// uploadBatch 不传路径应得到空 map + ok(不调网络)
|
|
160
|
+
try {
|
|
161
|
+
const mm = new MaterialManager({ baseUrl: 'http://localhost', authToken: 't', daoId: 'd' });
|
|
162
|
+
const r = await mm.uploadBatch([], { type: 'image' });
|
|
163
|
+
if (r.ok && r.map.size === 0 && r.failures.length === 0) ok('uploadBatch([]) 空输入返回 ok + 空 map');
|
|
164
|
+
else fail('uploadBatch([])', r);
|
|
165
|
+
} catch (e) { fail('uploadBatch([])', e); }
|
|
166
|
+
|
|
167
|
+
// upload 不存在文件 → not_found 错误(不调网络)
|
|
168
|
+
try {
|
|
169
|
+
const mm = new MaterialManager({ baseUrl: 'http://localhost', authToken: 't', daoId: 'd' });
|
|
170
|
+
const r = await mm.upload('/nonexistent/__no_such_file__.png');
|
|
171
|
+
if (!r.ok && r.error && r.error.kind === 'not_found') ok('upload() 不存在文件 → not_found(不调网络)');
|
|
172
|
+
else fail('upload() not_found', r);
|
|
173
|
+
} catch (e) { fail('upload() not_found', e); }
|
|
174
|
+
|
|
175
|
+
// upload 文件为空 → invalid_input(创建 0 字节文件)
|
|
176
|
+
try {
|
|
177
|
+
const fs = await import('fs');
|
|
178
|
+
const tmpPath = '/tmp/__lims_smoke_empty_' + Date.now() + '.png';
|
|
179
|
+
fs.writeFileSync(tmpPath, '');
|
|
180
|
+
try {
|
|
181
|
+
const mm = new MaterialManager({ baseUrl: 'http://localhost', authToken: 't', daoId: 'd' });
|
|
182
|
+
const r = await mm.upload(tmpPath);
|
|
183
|
+
if (!r.ok && r.error && r.error.kind === 'invalid_input') ok('upload() 空文件 → invalid_input(不调网络)');
|
|
184
|
+
else fail('upload() empty file', r);
|
|
185
|
+
} finally {
|
|
186
|
+
try { fs.unlinkSync(tmpPath); } catch {}
|
|
187
|
+
}
|
|
188
|
+
} catch (e) { fail('upload() empty file', e); }
|
|
189
|
+
|
|
190
|
+
// upload 非法 type 应被 MATERIAL_TYPES 拦截(不调网络)
|
|
191
|
+
try {
|
|
192
|
+
if (!MATERIAL_TYPES.includes('weird')) ok('MATERIAL_TYPES 拒绝非法 type 值');
|
|
193
|
+
else fail('MATERIAL_TYPES guard', '应不含 weird');
|
|
194
|
+
} catch (e) { fail('MATERIAL_TYPES guard', e); }
|
|
195
|
+
|
|
196
|
+
// mdToHtml 转换器
|
|
197
|
+
try {
|
|
198
|
+
const { mdToHtml, buildZhNotesFromMd, escapeHtml } = await import('../lib/versions.mjs');
|
|
199
|
+
const md = `# 一级标题
|
|
200
|
+
## 二级标题
|
|
201
|
+
### 三级标题
|
|
202
|
+
这是普通段落包含 **加粗** 和 *斜体* 和 \`代码\`。
|
|
203
|
+
|
|
204
|
+
> 这是一个 blockquote。
|
|
205
|
+
|
|
206
|
+
- item 1
|
|
207
|
+
- item 2
|
|
208
|
+
- nested(不支持但不会崩溃)
|
|
209
|
+
|
|
210
|
+
1. ordered 1
|
|
211
|
+
2. ordered 2
|
|
212
|
+
|
|
213
|
+
| 列1 | 列2 |
|
|
214
|
+
|-----|-----|
|
|
215
|
+
| a | b |
|
|
216
|
+
| c | d |
|
|
217
|
+
|
|
218
|
+
---`;
|
|
219
|
+
const html = mdToHtml(md);
|
|
220
|
+
const required = ['<h2>', '<h3>', '<h4>', '<strong>', '<em>', '<code>', '<blockquote>', '<ul>', '<ol>', '<table>', '<hr'];
|
|
221
|
+
const missing = required.filter((tag) => !html.includes(tag));
|
|
222
|
+
if (missing.length === 0) ok(`mdToHtml 覆盖 11 种语法(h2/h3/h4/strong/em/code/bq/ul/ol/table/hr)`);
|
|
223
|
+
else fail('mdToHtml 覆盖', `缺失: ${missing.join(',')}`);
|
|
224
|
+
|
|
225
|
+
// HTML 字符串不应该被转换
|
|
226
|
+
const rawHtml = '<h2>v1.0.26 更新说明</h2><p>已有 html</p>';
|
|
227
|
+
const passthrough = buildZhNotesFromMd(rawHtml);
|
|
228
|
+
if (passthrough[0] === rawHtml) ok('buildZhNotesFromMd 识别 HTML 不转');
|
|
229
|
+
else fail('buildZhNotesFromMd HTML', passthrough[0]);
|
|
230
|
+
|
|
231
|
+
// MD 字符串应该转换
|
|
232
|
+
const fromMd = buildZhNotesFromMd('## Hello');
|
|
233
|
+
if (fromMd[0].includes('<h3>')) ok('buildZhNotesFromMd MD→HTML');
|
|
234
|
+
else fail('buildZhNotesFromMd MD', fromMd[0]);
|
|
235
|
+
|
|
236
|
+
// escapeHtml 不出错
|
|
237
|
+
const esc = escapeHtml('<script>alert("xss")</script>');
|
|
238
|
+
if (esc.includes('<script>') && !esc.includes('<script>')) ok('escapeHtml 防 XSS');
|
|
239
|
+
else fail('escapeHtml', esc);
|
|
240
|
+
|
|
241
|
+
// normalizeReleaseNotes 5 种输入
|
|
242
|
+
const { normalizeReleaseNotes } = await import('../lib/versions.mjs');
|
|
243
|
+
const cases = [
|
|
244
|
+
['MD string → HTML', '# Hi', '<h2>Hi</h2>'],
|
|
245
|
+
['HTML string 不变', '<h2>Hi</h2>', '<h2>Hi</h2>'],
|
|
246
|
+
['{zh,en} 提取 zh', { zh: ['<h2>X</h2>'], en: [] }, '<h2>X</h2>'],
|
|
247
|
+
['null → 空', null, ''],
|
|
248
|
+
['array → join', ['<h2>X</h2>'], '<h2>X</h2>'],
|
|
249
|
+
];
|
|
250
|
+
let normalizePass = 0;
|
|
251
|
+
for (const [name, input, expected] of cases) {
|
|
252
|
+
const got = normalizeReleaseNotes(input);
|
|
253
|
+
if (got === expected) { normalizePass++; }
|
|
254
|
+
else console.log(` [normalize] ${name}: 期望 ${JSON.stringify(expected)}, 实际 ${JSON.stringify(got)}`);
|
|
255
|
+
}
|
|
256
|
+
if (normalizePass === cases.length) ok(`normalizeReleaseNotes 5 种输入`);
|
|
257
|
+
else fail('normalizeReleaseNotes', `${normalizePass}/${cases.length} pass`);
|
|
258
|
+
} catch (e) { fail('mdToHtml 测试', e); }
|
|
259
|
+
|
|
260
|
+
// 总结
|
|
261
|
+
console.log(`\n${failed === 0 ? '🎉' : '⚠️'} ${passed} passed, ${failed} failed`);
|
|
262
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import { fetchReadme, updateMarketplaceReadme } from '../scripts/sync-marketplace-readme.mjs';
|
|
5
|
+
|
|
6
|
+
test('JSON 模式所用更新器在非 dry-run 时调用管理端更新', async () => {
|
|
7
|
+
const calls = [];
|
|
8
|
+
const mp = { update: async (...args) => { calls.push(args); return { ok: true }; } };
|
|
9
|
+
const asset = { uuid: 'asset-id', license: null };
|
|
10
|
+
const got = { readme: '# README', license: 'MIT' };
|
|
11
|
+
|
|
12
|
+
const result = await updateMarketplaceReadme(mp, asset, got, false);
|
|
13
|
+
|
|
14
|
+
assert.deepEqual(result, { status: 'updated', length: 8, license: 'MIT' });
|
|
15
|
+
assert.deepEqual(calls, [['asset-id', { readme: '# README', license: 'MIT' }]]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('dry-run 更新器不调用管理端写接口', async () => {
|
|
19
|
+
const mp = { update: async () => { throw new Error('dry-run must not write'); } };
|
|
20
|
+
const result = await updateMarketplaceReadme(mp, { uuid: 'asset-id', license: 'Apache-2.0' }, {
|
|
21
|
+
readme: '# README',
|
|
22
|
+
license: 'MIT',
|
|
23
|
+
}, true);
|
|
24
|
+
|
|
25
|
+
assert.deepEqual(result, { status: 'dry_run', length: 8, license: 'MIT' });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('Gitee sourceUrl 只从 Gitee 获取 README', async () => {
|
|
29
|
+
const originalFetch = globalThis.fetch;
|
|
30
|
+
const requested = [];
|
|
31
|
+
globalThis.fetch = async (url) => {
|
|
32
|
+
requested.push(String(url));
|
|
33
|
+
return { ok: true, text: async () => '# Gitee README' };
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const result = await fetchReadme({
|
|
38
|
+
slug: 'example',
|
|
39
|
+
sourceUrl: 'https://gitee.com/owner/repo',
|
|
40
|
+
version: 'main',
|
|
41
|
+
}, { localDir: '' });
|
|
42
|
+
|
|
43
|
+
assert.equal(result.readme, '# Gitee README');
|
|
44
|
+
assert.equal(result.origin, 'gitee');
|
|
45
|
+
assert.equal(requested.length, 1);
|
|
46
|
+
assert.match(requested[0], /^https:\/\/gitee\.com\//);
|
|
47
|
+
} finally {
|
|
48
|
+
globalThis.fetch = originalFetch;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import { TOOL_NAMES, describeToolSetDiff } from '../scripts/tool-set.mjs';
|
|
5
|
+
import { TOOL_NAMES as SERVER_TOOL_NAMES } from '../lib/mcp-server.mjs';
|
|
6
|
+
|
|
7
|
+
const asTools = (names) => names.map((name) => ({ name }));
|
|
8
|
+
|
|
9
|
+
test('helper 的期望清单直接来自 MCP server 常量(没有第二份真源)', () => {
|
|
10
|
+
assert.equal(TOOL_NAMES, SERVER_TOOL_NAMES);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('工具集完全一致时返回 null(不报错)', () => {
|
|
14
|
+
assert.equal(describeToolSetDiff(asTools(TOOL_NAMES)), null);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('少一个工具 → 报「缺少」并点名', () => {
|
|
18
|
+
const missing = TOOL_NAMES.filter((n) => n !== 'lims_category_list');
|
|
19
|
+
const problem = describeToolSetDiff(asTools(missing));
|
|
20
|
+
assert.ok(problem, '缺工具时必须返回问题描述');
|
|
21
|
+
assert.match(problem, /缺少 1 个/);
|
|
22
|
+
assert.match(problem, /lims_category_list/);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('多一个工具 → 报「多出」并点名', () => {
|
|
26
|
+
const problem = describeToolSetDiff(asTools([...TOOL_NAMES, 'lims_ghost_tool']));
|
|
27
|
+
assert.ok(problem);
|
|
28
|
+
assert.match(problem, /多出 1 个/);
|
|
29
|
+
assert.match(problem, /lims_ghost_tool/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('名字重复 → 报「重复」(数量相同也要能发现)', () => {
|
|
33
|
+
// ⚠️ 这一条是「只比数量会漏」的反例:数量没变,集合也没变多,
|
|
34
|
+
// 但同一个工具被注册了两次 —— 只比数量/集合的断言会漏掉它。
|
|
35
|
+
const problem = describeToolSetDiff(asTools([...TOOL_NAMES, TOOL_NAMES[0]]));
|
|
36
|
+
assert.ok(problem);
|
|
37
|
+
assert.match(problem, /重复 1 个/);
|
|
38
|
+
assert.match(problem, new RegExp(TOOL_NAMES[0]));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('空数组 / 非数组 → 报出全部缺少,不抛异常', () => {
|
|
42
|
+
const empty = describeToolSetDiff([]);
|
|
43
|
+
assert.ok(empty);
|
|
44
|
+
assert.match(empty, new RegExp(`缺少 ${TOOL_NAMES.length} 个`));
|
|
45
|
+
|
|
46
|
+
const garbage = describeToolSetDiff(undefined);
|
|
47
|
+
assert.ok(garbage);
|
|
48
|
+
assert.match(garbage, /缺少/);
|
|
49
|
+
|
|
50
|
+
// 名字不是字符串的脏数据也不能让 helper 崩
|
|
51
|
+
const dirty = describeToolSetDiff([{ name: 123 }, null, undefined, { name: 'lims_health' }]);
|
|
52
|
+
assert.ok(dirty);
|
|
53
|
+
assert.match(dirty, /缺少/);
|
|
54
|
+
});
|