deep-read-summarize 0.3.13 → 0.3.15
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 +13 -12
- package/CHANGELOG.md +376 -321
- package/README.en.md +11 -5
- package/README.md +10 -5
- package/cordis.patch.yml +4 -0
- package/docs/RELEASE.md +3 -1
- package/index.js +18 -2
- package/lib/cache.js +102 -102
- package/lib/workflow-script.txt +215 -0
- package/package.json +71 -73
- package/parsers/_prompt.js +44 -44
- package/scripts/lint.js +62 -14
- package/workflow.js +6 -1
- package/docs/RELEASE-v0.1.0.md +0 -61
- package/tests/cache.test.js +0 -117
- package/tests/fixtures/fable.txt +0 -28
- package/tests/index.test.js +0 -456
- package/tests/quick_validate.js +0 -52
- package/tests/run-tests.js +0 -275
package/tests/run-tests.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
// tests/run-tests.js — fixture-driven tests
|
|
2
|
-
const assert = require('assert');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
|
-
let passed = 0, failed = 0;
|
|
8
|
-
function test(name, fn) {
|
|
9
|
-
try { fn(); passed++; console.log(' ✅', name); }
|
|
10
|
-
catch (e) { failed++; console.error(' ❌', name, '—', e.message); }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// ---------- Test: parser registry ----------
|
|
14
|
-
const parsers = require('../parsers');
|
|
15
|
-
test('registry exposes 4 built-in parsers', () => {
|
|
16
|
-
const list = parsers.list();
|
|
17
|
-
const names = list.map(p => p.name).sort();
|
|
18
|
-
assert.deepStrictEqual(names, ['book', 'paper', 'video', 'web']);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('resolve returns matching parser', () => {
|
|
22
|
-
assert.strictEqual(parsers.resolve('paper').name, 'paper');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('resolve falls back to web for unknown type', () => {
|
|
26
|
-
assert.strictEqual(parsers.resolve('unknown').name, 'web');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('every parser builds a non-empty prompt', () => {
|
|
30
|
-
for (const type of ['book', 'paper', 'video', 'web']) {
|
|
31
|
-
const p = parsers.resolve(type);
|
|
32
|
-
const prompt = p.buildPrompt('https://example.com/x', { tempDir: '/tmp', tempFile: '/tmp/in.txt', maxChunks: 4 });
|
|
33
|
-
assert.ok(typeof prompt === 'string' && prompt.length > 50, p.name + ' prompt too short');
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('parser prompts embed input, tempFile and maxChunks', () => {
|
|
38
|
-
for (const type of ['book', 'paper', 'video', 'web']) {
|
|
39
|
-
const p = parsers.resolve(type);
|
|
40
|
-
const prompt = p.buildPrompt('https://x.test/doc', { tempDir: '/t', maxChunks: 4 });
|
|
41
|
-
assert.ok(prompt.includes('https://x.test/doc'), type + ': input missing');
|
|
42
|
-
assert.ok(prompt.includes('/t\\input.txt') || prompt.includes('/t/input.txt'), type + ': tempFile missing');
|
|
43
|
-
assert.ok(prompt.includes('块数不超过 4 块'), type + ': maxChunks not applied');
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// ---------- Test: schemas ----------
|
|
48
|
-
const schemas = require('../schemas');
|
|
49
|
-
test('fetchResultSchema requires saved', () => {
|
|
50
|
-
assert.ok(schemas.fetchResultSchema.required.includes('saved'));
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('qualityChecklistSchema requires 5 gates', () => {
|
|
54
|
-
assert.strictEqual(schemas.qualityChecklistSchema.required.length, 5);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// ---------- Test: workflow script parses ----------
|
|
58
|
-
const wf = require('../workflow');
|
|
59
|
-
test('workflow meta is valid', () => {
|
|
60
|
-
assert.strictEqual(wf.meta.name, 'deep-read-summarize');
|
|
61
|
-
assert.ok(wf.meta.phases.length >= 3);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('workflow script parses as async body', () => {
|
|
65
|
-
const fn = new Function('args','phase','agent','parallel','log', 'return (async () => { ' + wf.script + ' })()');
|
|
66
|
-
assert.ok(typeof fn === 'function');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// ---------- Test: workflow exports parsers ----------
|
|
70
|
-
test('workflow.js exports parser registry', () => {
|
|
71
|
-
assert.ok(wf.parsers && typeof wf.parsers.resolve === 'function');
|
|
72
|
-
assert.strictEqual(wf.parsers.resolve('video').name, 'video');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// ---------- Test: fixture is self-authored (no copyright markers) ----------
|
|
76
|
-
test('fixture fable.txt exists and is public-domain self-authored', () => {
|
|
77
|
-
const fx = fs.readFileSync(path.join(__dirname, 'fixtures/fable.txt'), 'utf8');
|
|
78
|
-
assert.ok(fx.includes('released into the public domain'));
|
|
79
|
-
assert.ok(!fx.includes('Copyright ©'));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// ---------- Test: plugin entry contract (Cordis) ----------
|
|
83
|
-
// Regression for 0.3.3: the entry exported only { load, workflow, parsers,
|
|
84
|
-
// schemas } - no apply method - so dsh rejected the plugin at startup
|
|
85
|
-
// ("invalid plugin, expect function or object with an \"apply\" method"),
|
|
86
|
-
// the web server exited immediately, and the launcher just sat waiting on a
|
|
87
|
-
// dead port. The entry must satisfy the Cordis contract, always.
|
|
88
|
-
const plugin = require('../index');
|
|
89
|
-
|
|
90
|
-
test('plugin entry satisfies the Cordis contract (function or object with apply)', () => {
|
|
91
|
-
const ok = typeof plugin === 'function' ||
|
|
92
|
-
(plugin && typeof plugin === 'object' && typeof plugin.apply === 'function');
|
|
93
|
-
assert.ok(ok, 'entry must be a function or an object with an apply method');
|
|
94
|
-
assert.ok(typeof plugin.apply === 'function', 'apply must be callable');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('plugin entry carries name + inject for the bundle row', () => {
|
|
98
|
-
assert.ok(typeof plugin.name === 'string' && plugin.name !== '', 'name must be a non-empty string');
|
|
99
|
-
assert.ok(Array.isArray(plugin.inject) && plugin.inject.every((s) => typeof s === 'string'),
|
|
100
|
-
'inject must be an array of strings');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('plugin entry keeps the legacy load/workflow/parsers exports', () => {
|
|
104
|
-
assert.ok(typeof plugin.load === 'function', 'legacy load() export missing');
|
|
105
|
-
assert.ok(plugin.workflow && plugin.workflow.meta, 'workflow export missing');
|
|
106
|
-
assert.ok(plugin.parsers && typeof plugin.parsers.resolve === 'function', 'parsers export missing');
|
|
107
|
-
assert.ok(plugin.schemas, 'schemas export missing');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// ---------- Test: security scanner (negative/positive samples) ----------
|
|
111
|
-
const { scanDir } = require('../scripts/security-check');
|
|
112
|
-
test('security scanner flags fake secrets and skips clean/ignored files', () => {
|
|
113
|
-
const t = fs.mkdtempSync(path.join(os.tmpdir(), 'drs-sec-'));
|
|
114
|
-
try {
|
|
115
|
-
// 拼接构造,避免源码中出现完整密钥模式(被 security-check 误报)
|
|
116
|
-
fs.writeFileSync(path.join(t, 'bad.js'), 'const key = "' + 'sk-' + 'abcdefghijklmnopqrstuvwxyz123";');
|
|
117
|
-
fs.writeFileSync(path.join(t, 'good.md'), '# clean\nno secrets here\n');
|
|
118
|
-
fs.mkdirSync(path.join(t, 'node_modules'));
|
|
119
|
-
fs.writeFileSync(path.join(t, 'node_modules', 'dep.js'), 'sk-' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
|
|
120
|
-
const issues = scanDir(t);
|
|
121
|
-
assert.ok(issues.some(i => i.includes('OpenAI-style key')), 'should flag fake key');
|
|
122
|
-
assert.ok(!issues.some(i => i.includes('good.md')), 'clean file should not be flagged');
|
|
123
|
-
assert.ok(!issues.some(i => i.includes('node_modules')), 'node_modules should be skipped');
|
|
124
|
-
} finally {
|
|
125
|
-
fs.rmSync(t, { recursive: true, force: true });
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// ---------- Test: workflow script contract(DSH workflow 工具)----------
|
|
130
|
-
// 现行契约(0.1.2-rc.1):agent/parallel/pipeline/phase/log/args 六个钩子;agent() 选项只允许
|
|
131
|
-
// label/phase/schema/provider/model(其它选项会被引擎判为 fatal);schema 只允许
|
|
132
|
-
// type/properties/required/additionalProperties/items/enum/const/oneOf + 注解键;
|
|
133
|
-
// 脚本沙箱没有文件系统/网络/定时器/require。任何一条违反都会在真机上直接终止整条 workflow。
|
|
134
|
-
const workflow = require('../workflow');
|
|
135
|
-
const wfScript = workflow.script;
|
|
136
|
-
|
|
137
|
-
const ALLOWED_SCHEMA_KEYWORDS = [
|
|
138
|
-
'type', 'properties', 'required', 'additionalProperties', 'items', 'enum', 'const', 'oneOf',
|
|
139
|
-
'description', 'title', 'default', 'examples',
|
|
140
|
-
];
|
|
141
|
-
const ALLOWED_AGENT_OPTIONS = ['label', 'phase', 'schema', 'provider', 'model'];
|
|
142
|
-
|
|
143
|
-
/** 从脚本里取出 \`const XSchema = { ... }\` 的字面量并求值(脚本里的 schema 只是对象字面量)。 */
|
|
144
|
-
function extractSchemaLiterals(text) {
|
|
145
|
-
const out = [];
|
|
146
|
-
const re = /const (\w*[Ss]chema) = \{/g;
|
|
147
|
-
let m;
|
|
148
|
-
while ((m = re.exec(text)) !== null) {
|
|
149
|
-
const from = text.indexOf('{', m.index);
|
|
150
|
-
let depth = 0;
|
|
151
|
-
let i = from;
|
|
152
|
-
for (; i < text.length; i += 1) {
|
|
153
|
-
if (text[i] === '{') depth += 1;
|
|
154
|
-
else if (text[i] === '}') { depth -= 1; if (depth === 0) break; }
|
|
155
|
-
}
|
|
156
|
-
out.push({ name: m[1], value: eval('(' + text.slice(from, i + 1) + ')') }); // eslint-disable-line no-eval
|
|
157
|
-
}
|
|
158
|
-
return out;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 递归校验一个 JSON Schema 节点:只允许 DSH 子集的关键字。
|
|
163
|
-
* 只有 schema 位置的关键字受限——\`properties\` 下的键名是数据字段名,不参与校验。
|
|
164
|
-
* @returns {string[]} 违规关键字(含路径)
|
|
165
|
-
*/
|
|
166
|
-
function unsupportedSchemaKeywords(node, path = '$') {
|
|
167
|
-
if (node === null || typeof node !== 'object' || Array.isArray(node)) return [];
|
|
168
|
-
const bad = [];
|
|
169
|
-
for (const key of Object.keys(node)) {
|
|
170
|
-
if (!ALLOWED_SCHEMA_KEYWORDS.includes(key)) bad.push(path + '.' + key);
|
|
171
|
-
}
|
|
172
|
-
if (node.properties && typeof node.properties === 'object') {
|
|
173
|
-
for (const [name, child] of Object.entries(node.properties)) {
|
|
174
|
-
bad.push(...unsupportedSchemaKeywords(child, path + '.properties.' + name));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (node.items) bad.push(...unsupportedSchemaKeywords(node.items, path + '.items'));
|
|
178
|
-
if (Array.isArray(node.oneOf)) node.oneOf.forEach((child, i) => bad.push(...unsupportedSchemaKeywords(child, path + '.oneOf[' + i + ']')));
|
|
179
|
-
return bad;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
test('workflow: agent() schemas stay inside the DSH-supported subset', () => {
|
|
183
|
-
// 违反子集 = 引擎抛 UNSUPPORTED_SCHEMA = 整条 workflow 直接终止(不是降级)。
|
|
184
|
-
const schemas = extractSchemaLiterals(wfScript);
|
|
185
|
-
assert.ok(schemas.length >= 2, 'expected the fetch/check schemas, found ' + schemas.length);
|
|
186
|
-
for (const s of schemas) {
|
|
187
|
-
assert.deepStrictEqual(unsupportedSchemaKeywords(s.value), [],
|
|
188
|
-
s.name + ' uses unsupported schema keyword(s)');
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
test('workflow: the schema-subset checker actually rejects an unsupported keyword', () => {
|
|
193
|
-
// 反向断言:确保上面的“通过”不是因为校验器写空了。
|
|
194
|
-
const bad = unsupportedSchemaKeywords({ type: 'object', properties: { a: { type: 'string', minLength: 3 } } });
|
|
195
|
-
assert.deepStrictEqual(bad, ['$.properties.a.minLength']);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('workflow: agent() options stay inside the engine whitelist', () => {
|
|
199
|
-
const re = /agent\([^,]*,\s*\{([^}]*)\}/g;
|
|
200
|
-
let m;
|
|
201
|
-
let calls = 0;
|
|
202
|
-
while ((m = re.exec(wfScript)) !== null) {
|
|
203
|
-
calls += 1;
|
|
204
|
-
const keys = [];
|
|
205
|
-
const keyRe = /([A-Za-z_][A-Za-z0-9_]*)\s*:/g;
|
|
206
|
-
let k;
|
|
207
|
-
while ((k = keyRe.exec(m[1])) !== null) keys.push(k[1]);
|
|
208
|
-
for (const key of keys) {
|
|
209
|
-
assert.ok(ALLOWED_AGENT_OPTIONS.includes(key),
|
|
210
|
-
'agent() option "' + key + '" is not supported by the engine (allowed: ' + ALLOWED_AGENT_OPTIONS.join(', ') + ')');
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
assert.ok(calls >= 5, 'expected the script agent() calls, found ' + calls);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test('workflow: the script never reaches for APIs the sandbox does not provide', () => {
|
|
217
|
-
const forbidden = [
|
|
218
|
-
[/\brequire\s*\(/, 'require()'],
|
|
219
|
-
[/\bprocess\s*\./, 'process'],
|
|
220
|
-
[/\bfs\s*\./, 'fs'],
|
|
221
|
-
[/\bfetch\s*\(/, 'fetch()'],
|
|
222
|
-
[/\bsetTimeout\s*\(/, 'setTimeout()'],
|
|
223
|
-
[/\bsetInterval\s*\(/, 'setInterval()'],
|
|
224
|
-
[/\b__dirname\b/, '__dirname'],
|
|
225
|
-
[/\bchild_process\b/, 'child_process'],
|
|
226
|
-
];
|
|
227
|
-
for (const [re, label] of forbidden) {
|
|
228
|
-
assert.ok(!re.test(wfScript), 'the workflow sandbox provides no ' + label);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test('workflow: the script self-contains every registered parser', () => {
|
|
233
|
-
// 内联的是注册表里的全部解析器(含 custom-parsers/ 的覆盖与自定义类型),
|
|
234
|
-
// 不是写死的四个 —— 断言跟着注册表走,注册表加了东西这里自动跟着收紧。
|
|
235
|
-
for (const name of Object.keys(workflow.parsers.registry.parsers)) {
|
|
236
|
-
assert.ok(wfScript.includes(JSON.stringify(name) + ': { buildPrompt:'),
|
|
237
|
-
'parser "' + name + '" is not inlined');
|
|
238
|
-
}
|
|
239
|
-
assert.ok(wfScript.includes('const parsers = args._parsers || __parsers;'), 'the args._parsers fallback is missing');
|
|
240
|
-
assert.ok(wfScript.includes('const fetchSchema = {'), 'the fetch schema must be injected, not hand-copied');
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// ---------- Test: skill content(复用本文件顶部已有的 plugin 引用)----------
|
|
244
|
-
test('skill content carries meta + script + args and the write-back step', () => {
|
|
245
|
-
const content = plugin.buildSkillContent();
|
|
246
|
-
assert.ok(content.includes(workflow.meta.name), 'meta missing from the skill body');
|
|
247
|
-
assert.ok(content.includes(wfScript), 'the workflow script must be embedded verbatim');
|
|
248
|
-
assert.ok(content.includes('"input"'), 'the args example is missing');
|
|
249
|
-
// 脚本没有文件系统权限:技能必须明确要求主代理把 note 落盘,否则笔记会丢。
|
|
250
|
-
assert.ok(/filePath/.test(content) && /write/.test(content), 'the skill must tell the model to persist note -> filePath');
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test('plugin entry satisfies the Cordis contract and registers one bundled skill', () => {
|
|
254
|
-
assert.strictEqual(plugin.name, 'deep-read-summarize');
|
|
255
|
-
assert.deepStrictEqual(plugin.inject, ['skills']);
|
|
256
|
-
assert.strictEqual(typeof plugin.apply, 'function');
|
|
257
|
-
const registered = [];
|
|
258
|
-
const ctx = { skills: { register: (skill) => { registered.push(skill); return () => {}; } } };
|
|
259
|
-
const dispose = plugin.apply(ctx, {});
|
|
260
|
-
assert.strictEqual(registered.length, 1);
|
|
261
|
-
assert.strictEqual(registered[0].name, 'deep-read-summarize');
|
|
262
|
-
assert.strictEqual(registered[0].source, 'bundled');
|
|
263
|
-
assert.ok(registered[0].content.length > 1000);
|
|
264
|
-
assert.strictEqual(typeof dispose, 'function');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
// ---------- Run cache tests ----------
|
|
268
|
-
console.log('\n=== cache tests ===');
|
|
269
|
-
const cacheResult = require('./cache.test.js');
|
|
270
|
-
passed += cacheResult.passed;
|
|
271
|
-
failed += cacheResult.failed;
|
|
272
|
-
|
|
273
|
-
console.log('');
|
|
274
|
-
console.log('TOTAL: ' + passed + ' passed, ' + failed + ' failed');
|
|
275
|
-
process.exit(failed ? 1 : 0);
|