@sanqianx/project-knowledge 5.0.35 → 5.1.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/.claude-plugin/marketplace.json +1 -1
- package/_site/_test/chat-claudecodeui-match-test.js +1 -1
- package/_site/_test/integration-runtime-binding-test.js +1 -1
- package/_site/_test/mcp-server-test.js +149 -149
- package/_site/_test/packaged-ui-smoke-test.js +1 -1
- package/_site/_test/parallel-nav-theme-test.js +5 -4
- package/_site/_test/parallel-nav-viewport-test.js +4 -2
- package/_site/_test/product-empty-state-test.js +2 -2
- package/_site/_test/product-navigation-test.js +2 -2
- package/_site/_test/workflow-module-wiring-test.js +102 -0
- package/_site/_test/workflow-tools-test.js +97 -0
- package/_site/_test/workspace-ui-contract-test.js +16 -3
- package/_site/lib/integration-installer.js +3 -1
- package/_site/lib/module-bridge.js +42 -4
- package/_site/lib/server-app.js +12 -0
- package/_site/lib/workflow-tool-runtime.js +209 -0
- package/bin/project-knowledge-mcp.js +282 -201
- package/module-runtime-manifest.json +5 -5
- package/package.json +1 -1
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/plugins/project-knowledge/skills/pk-team/SKILL.md +35 -0
- package/ui/index.html +6 -0
- package/ui/product.js +81 -11
|
@@ -91,7 +91,7 @@ const runner = require('../lib/claude-cli-runner');
|
|
|
91
91
|
const nav = /<nav aria-label="主要导航">([\s\S]*?)<\/nav>/.exec(html);
|
|
92
92
|
assert(nav, 'the navigation block exists');
|
|
93
93
|
const navViews = [...nav[1].matchAll(/data-view="([a-z]+)"/g)].map(match => match[1]);
|
|
94
|
-
assert.deepStrictEqual(navViews, ['home', 'memory', 'projects', 'search', 'activity'], 'the navigation offers exactly the
|
|
94
|
+
assert.deepStrictEqual(navViews, ['home', 'team', 'memory', 'projects', 'search', 'activity'], 'the navigation offers exactly the six fixed pages (AI 团队 added 2026-11)');
|
|
95
95
|
// 检索页不再内嵌 vectorHub:服务端检索取代 vectorFrame。
|
|
96
96
|
assert(html.includes('id="view-search"') && !html.includes('id="vectorFrame"'));
|
|
97
97
|
assert(app.includes("'/api/engine/search'"), 'the search page drives the server-side engine search');
|
|
@@ -328,7 +328,7 @@ async function testMcpStartupProbe() {
|
|
|
328
328
|
assert(ready.state === 'ready', `a healthy binding must probe ready, got ${JSON.stringify(ready)}`);
|
|
329
329
|
assert(ready.actualVersion === packageInfo.version && ready.expectedVersion === packageInfo.version, 'the probe must report both versions');
|
|
330
330
|
assert(ready.scope === 'product-runtime' && ready.serverName === 'project-knowledge', 'A2: the probe reports its scope and the verified server identity');
|
|
331
|
-
assert(Array.isArray(ready.tools) && ready.tools.length
|
|
331
|
+
assert(Array.isArray(ready.tools) && ready.tools.length >= 6 && ['project_knowledge_resolve','project_knowledge_search','project_knowledge_ask','project_knowledge_get','project_knowledge_history','project_knowledge_record_requirement'].every(n => ready.tools.includes(n)), 'A2: the probe verifies the six knowledge tools are present (workflow tools are additive)');
|
|
332
332
|
assert(typeof ready.checkedAt === 'string', 'the probe must record checkedAt');
|
|
333
333
|
|
|
334
334
|
// A broken binding must surface a failed probe with a machine code.
|
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { spawn, spawnSync } = require('child_process');
|
|
6
|
-
const { StorageLayout } = require('../lib/storage-layout');
|
|
7
|
-
const { SettingsStore } = require('../lib/settings-store');
|
|
8
|
-
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
9
|
-
const { ProjectStore } = require('../lib/project-store');
|
|
10
|
-
const { ConversationStore } = require('../lib/conversation-store');
|
|
11
|
-
const { KnowledgeDatabase } = require('../lib/knowledge-db');
|
|
12
|
-
const { EMBEDDING_DIMENSIONS } = require('../lib/knowledge-schema');
|
|
13
|
-
|
|
14
|
-
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
-
const MCP_BIN = path.join(ROOT, 'bin', 'project-knowledge-mcp.js');
|
|
16
|
-
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-mcp-v2-'));
|
|
17
|
-
const dataDir = path.join(temp, 'data');
|
|
18
|
-
const repo = path.join(temp, 'repo');
|
|
19
|
-
const vectorRepo = path.join(temp, 'vector-repo');
|
|
20
|
-
const markdownKb = path.join(temp, 'knowledge-markdown');
|
|
21
|
-
const vectorKb = path.join(temp, 'knowledge-vector');
|
|
22
|
-
|
|
23
|
-
function write(filePath, content) {
|
|
24
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
25
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function git(cwd, args) {
|
|
29
|
-
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
30
|
-
assert.strictEqual(result.status, 0, result.stderr);
|
|
31
|
-
return String(result.stdout || '').trim();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function fakeVector(text) {
|
|
35
|
-
const vector = new Array(EMBEDDING_DIMENSIONS).fill(0);
|
|
36
|
-
for (let index = 0; index < String(text).length; index += 1) vector[String(text).charCodeAt(index) % vector.length] += 1;
|
|
37
|
-
const norm = Math.sqrt(vector.reduce((sum, item) => sum + item * item, 0)) || 1;
|
|
38
|
-
return vector.map(item => item / norm);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function createMcpClient() {
|
|
42
|
-
const child = spawn(process.execPath, [MCP_BIN], {
|
|
43
|
-
cwd: repo,
|
|
44
|
-
env: { ...process.env, KB_DATA_DIR: dataDir, KB_SKIP_MIGRATION: '1', KB_EMBEDDING_FAKE: '1' },
|
|
45
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
46
|
-
windowsHide: true,
|
|
47
|
-
});
|
|
48
|
-
let stderr = '';
|
|
49
|
-
let buffer = '';
|
|
50
|
-
let nextId = 1;
|
|
51
|
-
const pending = new Map();
|
|
52
|
-
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
53
|
-
child.stdout.on('data', chunk => {
|
|
54
|
-
buffer += chunk;
|
|
55
|
-
let newline;
|
|
56
|
-
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
57
|
-
const line = buffer.slice(0, newline).trim();
|
|
58
|
-
buffer = buffer.slice(newline + 1);
|
|
59
|
-
if (!line) continue;
|
|
60
|
-
const message = JSON.parse(line);
|
|
61
|
-
const entry = pending.get(message.id);
|
|
62
|
-
if (entry) { entry(message); pending.delete(message.id); }
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
const request = (method, params = {}) => new Promise((resolve, reject) => {
|
|
66
|
-
const id = nextId++;
|
|
67
|
-
const timer = setTimeout(() => { pending.delete(id); reject(new Error(`MCP timeout: ${method}\n${stderr}`)); }, 15_000);
|
|
68
|
-
pending.set(id, message => { clearTimeout(timer); resolve(message); });
|
|
69
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
70
|
-
});
|
|
71
|
-
await request('initialize', { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'test', version: '1' } });
|
|
72
|
-
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized', params: {} })}\n`);
|
|
73
|
-
return { child, request, stderr: () => stderr };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
(async () => {
|
|
77
|
-
for (const cwd of [repo, vectorRepo]) {
|
|
78
|
-
fs.mkdirSync(cwd, { recursive: true });
|
|
79
|
-
git(cwd, ['init', '--initial-branch=main']);
|
|
80
|
-
git(cwd, ['config', 'user.email', 'mcp@example.test']);
|
|
81
|
-
git(cwd, ['config', 'user.name', 'MCP Test']);
|
|
82
|
-
write(path.join(cwd, 'README.md'), '# source\n');
|
|
83
|
-
git(cwd, ['add', 'README.md']);
|
|
84
|
-
git(cwd, ['commit', '-m', 'baseline']);
|
|
85
|
-
}
|
|
86
|
-
write(path.join(markdownKb, 'README.md'), '# Demo knowledge\n\nThis project uses rotating refresh tokens.\n');
|
|
87
|
-
write(path.join(markdownKb, 'modules', 'auth.md'), '# Authentication\n\nRefresh tokens rotate after every successful renewal.\n');
|
|
88
|
-
write(path.join(markdownKb, 'changes', 'auth.md'), '# Authentication update\n\nIntroduced rotating refresh tokens.\n');
|
|
89
|
-
write(path.join(vectorKb, 'modules', 'payments.md'), '# Payment tokens\n\nPayment tokens expire after fifteen minutes.\n');
|
|
90
|
-
|
|
91
|
-
const layout = new StorageLayout({ dataDir });
|
|
92
|
-
const settingsStore = new SettingsStore({ layout });
|
|
93
|
-
const registryStore = new ProjectRegistryStore({ layout });
|
|
94
|
-
const projectStore = new ProjectStore({ layout });
|
|
95
|
-
await settingsStore.initialize({ knowledge: { rootPath: path.join(temp, 'future-root') } });
|
|
96
|
-
await registryStore.initialize();
|
|
97
|
-
await projectStore.create('project-demo', { displayName: 'Demo', storageName: 'demo', repoPath: repo, knowledgePath: markdownKb, legacyExtensions: { slug: 'demo' } }, { trackingStartCommit: git(repo, ['rev-parse', 'HEAD']), index: { dirty: true, generation: 1 } });
|
|
98
|
-
await registryStore.add('project-demo', { displayNameSnapshot: 'Demo' });
|
|
99
|
-
await projectStore.create('project-vector', { displayName: 'Vector', storageName: 'vector', repoPath: vectorRepo, knowledgePath: vectorKb, legacyExtensions: { slug: 'vector' } }, { trackingStartCommit: git(vectorRepo, ['rev-parse', 'HEAD']) });
|
|
100
|
-
await registryStore.add('project-vector', { displayNameSnapshot: 'Vector' });
|
|
101
|
-
|
|
102
|
-
const database = new KnowledgeDatabase({ dbPath: layout.getIndexPath(), maintenancePath: layout.getRuntimePath('index-maintenance.json') });
|
|
103
|
-
await database.replaceEntry('project:project-vector', 'modules/payments.md', [{ chunkOrder: 0, title: 'Payment tokens', chunkText: 'Payment tokens expire after fifteen minutes.', vector: fakeVector('payment tokens'), sourceCommit: 'abc123' }]);
|
|
104
|
-
await database.ensureSearchIndexes();
|
|
105
|
-
await database.close();
|
|
106
|
-
|
|
107
|
-
const client = await createMcpClient();
|
|
108
|
-
try {
|
|
109
|
-
const listed = await client.request('tools/list');
|
|
110
|
-
assert.strictEqual(listed.result.tools.length,
|
|
111
|
-
assert(listed.result.tools.some(tool => tool.name === 'project_knowledge_record_requirement'));
|
|
112
|
-
|
|
113
|
-
let response = await client.request('tools/call', { name: 'project_knowledge_resolve', arguments: { repoPath: repo } });
|
|
114
|
-
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
115
|
-
assert.strictEqual(response.result.structuredContent.knowledgePath, markdownKb);
|
|
116
|
-
assert.strictEqual(response.result.structuredContent.indexPath, layout.getVectorRootPath(settingsStore.read()));
|
|
117
|
-
|
|
118
|
-
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { projectId: 'project-demo', query: 'refresh tokens' } });
|
|
119
|
-
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
120
|
-
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
121
|
-
assert.strictEqual(response.result.structuredContent.health.scopes[0].dirty, true);
|
|
122
|
-
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/auth.md'));
|
|
123
|
-
|
|
124
|
-
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { project: 'vector', query: 'payment tokens' } });
|
|
125
|
-
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
126
|
-
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
127
|
-
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/payments.md'));
|
|
128
|
-
|
|
129
|
-
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: 'modules/auth.md' } });
|
|
130
|
-
assert.match(response.result.structuredContent.chunks[0].chunk_text, /rotate/i);
|
|
131
|
-
response = await client.request('tools/call', { name: 'project_knowledge_history', arguments: { projectId: 'project-demo' } });
|
|
132
|
-
assert.strictEqual(response.result.structuredContent.results[0].entry_id, 'changes/auth.md');
|
|
133
|
-
|
|
134
|
-
const stateBefore = fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8');
|
|
135
|
-
response = await client.request('tools/call', { name: 'project_knowledge_record_requirement', arguments: { projectId: 'project-demo', repoPath: repo, client: 'codex', sessionId: 'session-mcp', text: 'Keep refresh token rotation documented.' } });
|
|
136
|
-
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
137
|
-
assert.strictEqual(new ConversationStore({ layout, projectStore }).readEvents('project-demo').length, 1);
|
|
138
|
-
assert.strictEqual(fs.existsSync(layout.getProjectRequirementsPath('project-demo')), false, 'explicit MCP adapter must not create legacy requirements.jsonl');
|
|
139
|
-
assert.strictEqual(fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8'), stateBefore, 'requirement tool must not trigger analysis or mutate state');
|
|
140
|
-
assert(!fs.existsSync(layout.getRuntimePath('staging')));
|
|
141
|
-
|
|
142
|
-
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: '../settings.json' } });
|
|
143
|
-
assert.strictEqual(response.result.isError, true);
|
|
144
|
-
console.log('mcp-server-test PASS');
|
|
145
|
-
} finally {
|
|
146
|
-
client.child.stdin.end();
|
|
147
|
-
await new Promise(resolve => client.child.once('exit', resolve));
|
|
148
|
-
}
|
|
149
|
-
})().catch(error => { console.error(error); process.exitCode = 1; }).finally(() => fs.rmSync(temp, { recursive: true, force: true }));
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn, spawnSync } = require('child_process');
|
|
6
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
7
|
+
const { SettingsStore } = require('../lib/settings-store');
|
|
8
|
+
const { ProjectRegistryStore } = require('../lib/project-registry-store');
|
|
9
|
+
const { ProjectStore } = require('../lib/project-store');
|
|
10
|
+
const { ConversationStore } = require('../lib/conversation-store');
|
|
11
|
+
const { KnowledgeDatabase } = require('../lib/knowledge-db');
|
|
12
|
+
const { EMBEDDING_DIMENSIONS } = require('../lib/knowledge-schema');
|
|
13
|
+
|
|
14
|
+
const ROOT = path.resolve(__dirname, '..', '..');
|
|
15
|
+
const MCP_BIN = path.join(ROOT, 'bin', 'project-knowledge-mcp.js');
|
|
16
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'pkb-mcp-v2-'));
|
|
17
|
+
const dataDir = path.join(temp, 'data');
|
|
18
|
+
const repo = path.join(temp, 'repo');
|
|
19
|
+
const vectorRepo = path.join(temp, 'vector-repo');
|
|
20
|
+
const markdownKb = path.join(temp, 'knowledge-markdown');
|
|
21
|
+
const vectorKb = path.join(temp, 'knowledge-vector');
|
|
22
|
+
|
|
23
|
+
function write(filePath, content) {
|
|
24
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
25
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function git(cwd, args) {
|
|
29
|
+
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
30
|
+
assert.strictEqual(result.status, 0, result.stderr);
|
|
31
|
+
return String(result.stdout || '').trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function fakeVector(text) {
|
|
35
|
+
const vector = new Array(EMBEDDING_DIMENSIONS).fill(0);
|
|
36
|
+
for (let index = 0; index < String(text).length; index += 1) vector[String(text).charCodeAt(index) % vector.length] += 1;
|
|
37
|
+
const norm = Math.sqrt(vector.reduce((sum, item) => sum + item * item, 0)) || 1;
|
|
38
|
+
return vector.map(item => item / norm);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function createMcpClient() {
|
|
42
|
+
const child = spawn(process.execPath, [MCP_BIN], {
|
|
43
|
+
cwd: repo,
|
|
44
|
+
env: { ...process.env, KB_DATA_DIR: dataDir, KB_SKIP_MIGRATION: '1', KB_EMBEDDING_FAKE: '1' },
|
|
45
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
46
|
+
windowsHide: true,
|
|
47
|
+
});
|
|
48
|
+
let stderr = '';
|
|
49
|
+
let buffer = '';
|
|
50
|
+
let nextId = 1;
|
|
51
|
+
const pending = new Map();
|
|
52
|
+
child.stderr.on('data', chunk => { stderr += chunk; });
|
|
53
|
+
child.stdout.on('data', chunk => {
|
|
54
|
+
buffer += chunk;
|
|
55
|
+
let newline;
|
|
56
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
57
|
+
const line = buffer.slice(0, newline).trim();
|
|
58
|
+
buffer = buffer.slice(newline + 1);
|
|
59
|
+
if (!line) continue;
|
|
60
|
+
const message = JSON.parse(line);
|
|
61
|
+
const entry = pending.get(message.id);
|
|
62
|
+
if (entry) { entry(message); pending.delete(message.id); }
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const request = (method, params = {}) => new Promise((resolve, reject) => {
|
|
66
|
+
const id = nextId++;
|
|
67
|
+
const timer = setTimeout(() => { pending.delete(id); reject(new Error(`MCP timeout: ${method}\n${stderr}`)); }, 15_000);
|
|
68
|
+
pending.set(id, message => { clearTimeout(timer); resolve(message); });
|
|
69
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
70
|
+
});
|
|
71
|
+
await request('initialize', { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'test', version: '1' } });
|
|
72
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized', params: {} })}\n`);
|
|
73
|
+
return { child, request, stderr: () => stderr };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
(async () => {
|
|
77
|
+
for (const cwd of [repo, vectorRepo]) {
|
|
78
|
+
fs.mkdirSync(cwd, { recursive: true });
|
|
79
|
+
git(cwd, ['init', '--initial-branch=main']);
|
|
80
|
+
git(cwd, ['config', 'user.email', 'mcp@example.test']);
|
|
81
|
+
git(cwd, ['config', 'user.name', 'MCP Test']);
|
|
82
|
+
write(path.join(cwd, 'README.md'), '# source\n');
|
|
83
|
+
git(cwd, ['add', 'README.md']);
|
|
84
|
+
git(cwd, ['commit', '-m', 'baseline']);
|
|
85
|
+
}
|
|
86
|
+
write(path.join(markdownKb, 'README.md'), '# Demo knowledge\n\nThis project uses rotating refresh tokens.\n');
|
|
87
|
+
write(path.join(markdownKb, 'modules', 'auth.md'), '# Authentication\n\nRefresh tokens rotate after every successful renewal.\n');
|
|
88
|
+
write(path.join(markdownKb, 'changes', 'auth.md'), '# Authentication update\n\nIntroduced rotating refresh tokens.\n');
|
|
89
|
+
write(path.join(vectorKb, 'modules', 'payments.md'), '# Payment tokens\n\nPayment tokens expire after fifteen minutes.\n');
|
|
90
|
+
|
|
91
|
+
const layout = new StorageLayout({ dataDir });
|
|
92
|
+
const settingsStore = new SettingsStore({ layout });
|
|
93
|
+
const registryStore = new ProjectRegistryStore({ layout });
|
|
94
|
+
const projectStore = new ProjectStore({ layout });
|
|
95
|
+
await settingsStore.initialize({ knowledge: { rootPath: path.join(temp, 'future-root') } });
|
|
96
|
+
await registryStore.initialize();
|
|
97
|
+
await projectStore.create('project-demo', { displayName: 'Demo', storageName: 'demo', repoPath: repo, knowledgePath: markdownKb, legacyExtensions: { slug: 'demo' } }, { trackingStartCommit: git(repo, ['rev-parse', 'HEAD']), index: { dirty: true, generation: 1 } });
|
|
98
|
+
await registryStore.add('project-demo', { displayNameSnapshot: 'Demo' });
|
|
99
|
+
await projectStore.create('project-vector', { displayName: 'Vector', storageName: 'vector', repoPath: vectorRepo, knowledgePath: vectorKb, legacyExtensions: { slug: 'vector' } }, { trackingStartCommit: git(vectorRepo, ['rev-parse', 'HEAD']) });
|
|
100
|
+
await registryStore.add('project-vector', { displayNameSnapshot: 'Vector' });
|
|
101
|
+
|
|
102
|
+
const database = new KnowledgeDatabase({ dbPath: layout.getIndexPath(), maintenancePath: layout.getRuntimePath('index-maintenance.json') });
|
|
103
|
+
await database.replaceEntry('project:project-vector', 'modules/payments.md', [{ chunkOrder: 0, title: 'Payment tokens', chunkText: 'Payment tokens expire after fifteen minutes.', vector: fakeVector('payment tokens'), sourceCommit: 'abc123' }]);
|
|
104
|
+
await database.ensureSearchIndexes();
|
|
105
|
+
await database.close();
|
|
106
|
+
|
|
107
|
+
const client = await createMcpClient();
|
|
108
|
+
try {
|
|
109
|
+
const listed = await client.request('tools/list');
|
|
110
|
+
assert.strictEqual(listed.result.tools.length, 12, 'six knowledge tools + six workflow tools');
|
|
111
|
+
assert(listed.result.tools.some(tool => tool.name === 'project_knowledge_record_requirement'));
|
|
112
|
+
|
|
113
|
+
let response = await client.request('tools/call', { name: 'project_knowledge_resolve', arguments: { repoPath: repo } });
|
|
114
|
+
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
115
|
+
assert.strictEqual(response.result.structuredContent.knowledgePath, markdownKb);
|
|
116
|
+
assert.strictEqual(response.result.structuredContent.indexPath, layout.getVectorRootPath(settingsStore.read()));
|
|
117
|
+
|
|
118
|
+
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { projectId: 'project-demo', query: 'refresh tokens' } });
|
|
119
|
+
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
120
|
+
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
121
|
+
assert.strictEqual(response.result.structuredContent.health.scopes[0].dirty, true);
|
|
122
|
+
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/auth.md'));
|
|
123
|
+
|
|
124
|
+
response = await client.request('tools/call', { name: 'project_knowledge_search', arguments: { project: 'vector', query: 'payment tokens' } });
|
|
125
|
+
assert.strictEqual(response.result.structuredContent.source, 'knowledge-retrieval-service');
|
|
126
|
+
assert.strictEqual(response.result.structuredContent.backend, 'hybrid+markdown-truth');
|
|
127
|
+
assert(response.result.structuredContent.results.some(result => result.entry_id === 'modules/payments.md'));
|
|
128
|
+
|
|
129
|
+
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: 'modules/auth.md' } });
|
|
130
|
+
assert.match(response.result.structuredContent.chunks[0].chunk_text, /rotate/i);
|
|
131
|
+
response = await client.request('tools/call', { name: 'project_knowledge_history', arguments: { projectId: 'project-demo' } });
|
|
132
|
+
assert.strictEqual(response.result.structuredContent.results[0].entry_id, 'changes/auth.md');
|
|
133
|
+
|
|
134
|
+
const stateBefore = fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8');
|
|
135
|
+
response = await client.request('tools/call', { name: 'project_knowledge_record_requirement', arguments: { projectId: 'project-demo', repoPath: repo, client: 'codex', sessionId: 'session-mcp', text: 'Keep refresh token rotation documented.' } });
|
|
136
|
+
assert.strictEqual(response.result.structuredContent.projectId, 'project-demo');
|
|
137
|
+
assert.strictEqual(new ConversationStore({ layout, projectStore }).readEvents('project-demo').length, 1);
|
|
138
|
+
assert.strictEqual(fs.existsSync(layout.getProjectRequirementsPath('project-demo')), false, 'explicit MCP adapter must not create legacy requirements.jsonl');
|
|
139
|
+
assert.strictEqual(fs.readFileSync(layout.getProjectStatePath('project-demo'), 'utf8'), stateBefore, 'requirement tool must not trigger analysis or mutate state');
|
|
140
|
+
assert(!fs.existsSync(layout.getRuntimePath('staging')));
|
|
141
|
+
|
|
142
|
+
response = await client.request('tools/call', { name: 'project_knowledge_get', arguments: { projectId: 'project-demo', entry: '../settings.json' } });
|
|
143
|
+
assert.strictEqual(response.result.isError, true);
|
|
144
|
+
console.log('mcp-server-test PASS');
|
|
145
|
+
} finally {
|
|
146
|
+
client.child.stdin.end();
|
|
147
|
+
await new Promise(resolve => client.child.once('exit', resolve));
|
|
148
|
+
}
|
|
149
|
+
})().catch(error => { console.error(error); process.exitCode = 1; }).finally(() => fs.rmSync(temp, { recursive: true, force: true }));
|
|
@@ -109,7 +109,7 @@ function buildAndInstallPackage() {
|
|
|
109
109
|
}, 'packaged UI bootstrap', 20000);
|
|
110
110
|
|
|
111
111
|
assert.strictEqual(await browser.evaluate("document.getElementById('projectSelect').disabled"), true);
|
|
112
|
-
assert.strictEqual(await browser.evaluate("document.querySelectorAll('nav [data-view]').length"),
|
|
112
|
+
assert.strictEqual(await browser.evaluate("document.querySelectorAll('nav [data-view]').length"), 6, 'six fixed pages (AI 团队 added 2026-11)');
|
|
113
113
|
assert.strictEqual(await browser.evaluate("document.querySelector('[data-view=\"work\"]')"), null, 'the packed UI ships no work navigation entry');
|
|
114
114
|
assert.strictEqual(browser.exceptions.length, 0, `packaged UI runtime exceptions: ${JSON.stringify(browser.exceptions)}`);
|
|
115
115
|
console.log('packaged-ui-smoke-test PASS');
|
|
@@ -62,12 +62,13 @@ async function main() {
|
|
|
62
62
|
20000,
|
|
63
63
|
);
|
|
64
64
|
|
|
65
|
-
// NAV-002 navigation contract (
|
|
66
|
-
// work button, and the workbench survives
|
|
65
|
+
// NAV-002 navigation contract (six-page UI, AI 团队 added 2026-11):
|
|
66
|
+
// exactly the six fixed pages, no work button, and the workbench survives
|
|
67
|
+
// as a hidden service mount.
|
|
67
68
|
assert.deepEqual(
|
|
68
69
|
await harness.run("[...document.querySelectorAll('nav [data-view]')].map(button => button.dataset.view)"),
|
|
69
|
-
['home', 'memory', 'projects', 'search', 'activity'],
|
|
70
|
-
'the navigation offers exactly the
|
|
70
|
+
['home', 'team', 'memory', 'projects', 'search', 'activity'],
|
|
71
|
+
'the navigation offers exactly the six fixed pages',
|
|
71
72
|
);
|
|
72
73
|
assert.equal(await harness.run("document.querySelector('[data-view=\"work\"]') === null"), true, 'the work navigation button is removed');
|
|
73
74
|
assert.equal(await harness.run("document.getElementById('view-work') !== null"), true, 'the work section survives in the DOM');
|
|
@@ -51,10 +51,12 @@ const VIEWPORTS = [
|
|
|
51
51
|
|
|
52
52
|
const THEMES = ['light', 'dark'];
|
|
53
53
|
|
|
54
|
-
// The
|
|
55
|
-
// activity. The workbench section stays hidden and
|
|
54
|
+
// The six-page navigation contract (2026-11 adds AI 团队): home, team,
|
|
55
|
+
// memory, projects, search, activity. The workbench section stays hidden and
|
|
56
|
+
// is not a page; the team page is the workflow module's embedded surface.
|
|
56
57
|
const PAGES = [
|
|
57
58
|
{ key: 'home', view: 'home' },
|
|
59
|
+
{ key: 'team', view: 'team' },
|
|
58
60
|
{ key: 'memory', view: 'memory' },
|
|
59
61
|
{ key: 'projects', view: 'projects' },
|
|
60
62
|
{ key: 'search', view: 'search' },
|
|
@@ -137,8 +137,8 @@ async function main() {
|
|
|
137
137
|
// hidden service mount.
|
|
138
138
|
assert.deepEqual(
|
|
139
139
|
await run("[...document.querySelectorAll('nav [data-view]')].map(button => button.dataset.view)"),
|
|
140
|
-
['home', 'memory', 'projects', 'search', 'activity'],
|
|
141
|
-
'the navigation offers exactly the
|
|
140
|
+
['home', 'team', 'memory', 'projects', 'search', 'activity'],
|
|
141
|
+
'the navigation offers exactly the six fixed pages (AI 团队 added 2026-11)',
|
|
142
142
|
);
|
|
143
143
|
assert.equal(await run("document.querySelector('[data-view=\"work\"]') === null"), true, 'the work navigation button is removed');
|
|
144
144
|
assert.equal(await run("document.getElementById('view-work') !== null"), true, 'the work section survives in the DOM');
|
|
@@ -114,9 +114,9 @@ async function main() {
|
|
|
114
114
|
const run = expression => browser.evaluate(expression);
|
|
115
115
|
|
|
116
116
|
await waitFor(() => run("document.getElementById('homeContent').textContent.includes('第一个项目')"), 'the real empty home', 20000);
|
|
117
|
-
assert.equal(await run("document.querySelectorAll('nav [data-view]').length"),
|
|
117
|
+
assert.equal(await run("document.querySelectorAll('nav [data-view]').length"), 6, 'the shell exposes six navigation entries (AI 团队 added 2026-11)');
|
|
118
118
|
assert.equal(await run("document.querySelector('[data-view=\"work\"]')"), null, 'the retired work page no longer has a navigation entry');
|
|
119
|
-
assert.equal(await run("document.querySelectorAll('.view').length"),
|
|
119
|
+
assert.equal(await run("document.querySelectorAll('.view').length"), 7, 'six pages plus the hidden work service mount');
|
|
120
120
|
|
|
121
121
|
const readShell = () => run(`(() => ({
|
|
122
122
|
marker: window.__navMarker === undefined ? null : String(window.__navMarker),
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// 第五模块(独立工作流)接线合同(W1):
|
|
3
|
+
// - /api/workflow/<rest> 改写到模块 /api/workflow/v1/<rest>;
|
|
4
|
+
// - 模块身份探测(MODULE_IDENTITY.workflow)按 name+apiVersion 判定,
|
|
5
|
+
// 外来服务占用端口时判 foreign,不误认、不抢端口;
|
|
6
|
+
// - 模块未安装(resolveModuleEntry null)时:不产生受管 spec、四模块
|
|
7
|
+
// spec 不受影响,modulesHealth 如实报 installed:false;
|
|
8
|
+
// - /workflow-ui/ 页面代理仅 GET、拒绝编码分隔符与 api/internal 段;
|
|
9
|
+
// - 模块不可达时代理返回结构化 502,不影响其他模块路由。
|
|
10
|
+
// 真实 tarball 安装级验证(五模块同装)在 W8 前以隔离 prefix 单独执行,
|
|
11
|
+
// 不在本文件伪造。
|
|
12
|
+
const assert = require('node:assert/strict');
|
|
13
|
+
const http = require('node:http');
|
|
14
|
+
const { Readable } = require('node:stream');
|
|
15
|
+
const { EventEmitter } = require('node:events');
|
|
16
|
+
const { ModuleBridge } = require('../lib/module-bridge');
|
|
17
|
+
|
|
18
|
+
function workflowInstalled() {
|
|
19
|
+
try { require.resolve('@sanqianx/ai-coding-workflow/src/bin.js'); return true; } catch { return false; }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
(async () => {
|
|
23
|
+
// 1) URL rewrite contract.
|
|
24
|
+
const bridge = new ModuleBridge({ workflowUrl: 'http://127.0.0.1:5810' });
|
|
25
|
+
assert.equal(bridge._workflowApi('/api/workflow/team'), 'http://127.0.0.1:5810/api/workflow/v1/team');
|
|
26
|
+
assert.equal(bridge._workflowApi('/api/workflow'), 'http://127.0.0.1:5810/api/workflow/v1/');
|
|
27
|
+
|
|
28
|
+
// 2) Identity classification against a REAL workflow-shaped health body and
|
|
29
|
+
// a foreign listener.
|
|
30
|
+
const workflowBody = JSON.stringify({ ok: true, name: 'ai-coding-workflow', version: '0.1.0', apiVersion: 'v1', capabilities: {} });
|
|
31
|
+
const foreignBody = JSON.stringify({ ok: true, name: 'something-else', apiVersion: 'v1' });
|
|
32
|
+
const upstream = http.createServer((req, res) => {
|
|
33
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
34
|
+
res.end(req.url === '/api/health?foreign=1' ? foreignBody : workflowBody);
|
|
35
|
+
});
|
|
36
|
+
await new Promise(resolve => upstream.listen(0, '127.0.0.1', resolve));
|
|
37
|
+
const port = upstream.address().port;
|
|
38
|
+
try {
|
|
39
|
+
assert.equal(await bridge._probeClass(`http://127.0.0.1:${port}`, 'workflow'), 'module', 'a real workflow health body classifies as our module');
|
|
40
|
+
// A dedicated foreign listener: same shape, wrong identity.
|
|
41
|
+
const foreignServer = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(foreignBody); });
|
|
42
|
+
await new Promise(resolve => foreignServer.listen(0, '127.0.0.1', resolve));
|
|
43
|
+
try {
|
|
44
|
+
assert.equal(await bridge._probeClass(`http://127.0.0.1:${foreignServer.address().port}`, 'workflow'), 'foreign', 'an identity mismatch is foreign, never reused');
|
|
45
|
+
} finally { foreignServer.closeAllConnections(); await new Promise(resolve => foreignServer.close(resolve)); }
|
|
46
|
+
} finally { upstream.closeAllConnections(); await new Promise(resolve => upstream.close(resolve)); }
|
|
47
|
+
|
|
48
|
+
// 3) Optional-module degradation: without the package installed the
|
|
49
|
+
// supervisor builds no workflow spec and health reports not installed.
|
|
50
|
+
const specs = bridge._supervisedSpecs();
|
|
51
|
+
if (!workflowInstalled()) {
|
|
52
|
+
assert.ok(!specs.some(spec => spec.name === 'workflow'), 'no workflow spec when the runtime is not installed');
|
|
53
|
+
} else {
|
|
54
|
+
assert.ok(specs.some(spec => spec.name === 'workflow'), 'an installed workflow runtime gets a supervised spec');
|
|
55
|
+
assert.match(specs.find(spec => spec.name === 'workflow').command, /ai-coding-workflow.*serve/, 'the spec launches the workflow CLI');
|
|
56
|
+
}
|
|
57
|
+
for (const pinned of ['terminal', 'vector-hub', 'event-bridge', 'knowledge-engine']) {
|
|
58
|
+
assert.ok(specs.some(spec => spec.name === pinned), `pinned module ${pinned} keeps its spec`);
|
|
59
|
+
}
|
|
60
|
+
const health = await bridge.modulesHealth();
|
|
61
|
+
assert.ok(health.modules.workflow, 'health lists the workflow module');
|
|
62
|
+
assert.equal(health.modules.workflow.installed, workflowInstalled(), 'installed reflects package presence');
|
|
63
|
+
|
|
64
|
+
// 4) Workflow UI proxy: GET-only, rejects encoded separators and api/internal
|
|
65
|
+
// segments, accepts the bare entry.
|
|
66
|
+
const uiUpstream = http.createServer((req, res) => {
|
|
67
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
68
|
+
res.end('<html>AI 团队</html>');
|
|
69
|
+
});
|
|
70
|
+
await new Promise(resolve => uiUpstream.listen(0, '127.0.0.1', resolve));
|
|
71
|
+
const uiBridge = new ModuleBridge({ workflowUrl: `http://127.0.0.1:${uiUpstream.address().port}` });
|
|
72
|
+
const shellUi = http.createServer((req, res) => {
|
|
73
|
+
const match = req.url.match(/^\/workflow-ui\/?(.*)$/);
|
|
74
|
+
if (!match || req.method !== 'GET') { res.statusCode = 404; res.end('Not found'); return; }
|
|
75
|
+
return uiBridge.proxyModuleUi(req, res, 'workflow', match[1], '');
|
|
76
|
+
});
|
|
77
|
+
await new Promise(resolve => shellUi.listen(0, '127.0.0.1', resolve));
|
|
78
|
+
try {
|
|
79
|
+
const page = await fetch(`http://127.0.0.1:${shellUi.address().port}/workflow-ui/`);
|
|
80
|
+
assert.equal(page.status, 200);
|
|
81
|
+
assert.match(await page.text(), /AI 团队/);
|
|
82
|
+
for (const bad of ['/workflow-ui/app.js/../../package.json', '/workflow-ui/%2e%2e/secret', '/workflow-ui/api/health', '/workflow-ui/internal/x']) {
|
|
83
|
+
const response = await fetch(`http://127.0.0.1:${shellUi.address().port}${bad}`);
|
|
84
|
+
assert.notEqual(response.status, 200, `${bad} must not proxy`);
|
|
85
|
+
}
|
|
86
|
+
const post = await fetch(`http://127.0.0.1:${shellUi.address().port}/workflow-ui/`, { method: 'POST' });
|
|
87
|
+
assert.equal(post.status, 404, 'the UI proxy is GET-only');
|
|
88
|
+
} finally {
|
|
89
|
+
shellUi.closeAllConnections(); await new Promise(resolve => shellUi.close(resolve));
|
|
90
|
+
uiUpstream.closeAllConnections(); await new Promise(resolve => uiUpstream.close(resolve));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 5) Unreachable module yields a structured 502 without breaking the bridge.
|
|
94
|
+
const deadBridge = new ModuleBridge({ workflowUrl: 'http://127.0.0.1:1' });
|
|
95
|
+
const req = Readable.from([]); req.method = 'GET'; req.headers = {};
|
|
96
|
+
const res = new EventEmitter(); res.writeHead = () => {}; res.end = bytes => { res.writableEnded = true; res.body = JSON.parse(bytes); };
|
|
97
|
+
await deadBridge.proxy(req, res, deadBridge._workflowApi('/api/workflow/team'));
|
|
98
|
+
assert.equal(res.body.error, 'MODULE_UNREACHABLE');
|
|
99
|
+
assert.equal(res.body.details.failureKind, 'NETWORK_ERROR');
|
|
100
|
+
|
|
101
|
+
console.log('workflow-module-wiring-test PASS');
|
|
102
|
+
})().catch(error => { console.error(error); process.exitCode = 1; });
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// project_workflow_* MCP tool contract: the tools are a thin adapter over the
|
|
3
|
+
// shell proxy into the workflow module. This suite runs a REAL workflow
|
|
4
|
+
// module instance as upstream and verifies start/resume/status/checkpoint and
|
|
5
|
+
// the truthful UNSUPPORTED answers for the review pipeline, plus the
|
|
6
|
+
// structured degradation when no service is reachable.
|
|
7
|
+
const assert = require('node:assert/strict');
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const os = require('node:os');
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const { WorkflowToolRuntime } = require('../lib/workflow-tool-runtime');
|
|
12
|
+
|
|
13
|
+
// Development-machine suite: the upstream is the real workflow module from
|
|
14
|
+
// its private source checkout. CI without that checkout gets an explicit,
|
|
15
|
+
// logged skip (never a silent pass); once the package publishes (W8) this
|
|
16
|
+
// switches to installing the tarball and the suite becomes mandatory.
|
|
17
|
+
let createWorkflowServer = null;
|
|
18
|
+
try {
|
|
19
|
+
createWorkflowServer = require('D:/SanQian.Xu/ai-coding-workflow/src/server').createWorkflowServer;
|
|
20
|
+
} catch { /* not present on this machine */ }
|
|
21
|
+
if (!createWorkflowServer) {
|
|
22
|
+
console.log('workflow-tools-test SKIP: workflow module source not present (dev-machine suite; becomes mandatory after the package publishes in W8)');
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function tempDataDir() { return fs.mkdtempSync(path.join(os.tmpdir(), 'ai-workflow-mcp-')); }
|
|
27
|
+
|
|
28
|
+
async function withUpstream(fn) {
|
|
29
|
+
const runtime = createWorkflowServer({ dataDir: tempDataDir() });
|
|
30
|
+
const bound = await runtime.listen(0);
|
|
31
|
+
const base = `http://127.0.0.1:${bound.port}`;
|
|
32
|
+
// Seed the default team so task creation is allowed.
|
|
33
|
+
await fetch(`${base}/api/workflow/v1/team`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ requestId: 'mcp-seed' }) });
|
|
34
|
+
try { await fn(base); } finally { await runtime.close(); }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
(async () => {
|
|
38
|
+
await withUpstream(async base => {
|
|
39
|
+
const tools = new WorkflowToolRuntime({ workflowUrl: base });
|
|
40
|
+
|
|
41
|
+
// start creates a task, binds the declared session, returns the contract.
|
|
42
|
+
const started = await tools.start({ title: '修复重复重试', goal: '超时后不得重复提交', acceptance: [{ title: '重试幂等', kind: 'automated' }], client: 'claude', sessionId: 'sess-mcp-1', projectId: 'p1' });
|
|
43
|
+
assert.ok(started.taskId.startsWith('task_'));
|
|
44
|
+
assert.equal(started.sessionBinding.basis, 'declared');
|
|
45
|
+
assert.ok(started.nextStep.includes('checkpoint'));
|
|
46
|
+
|
|
47
|
+
// resume answers the short contract with acceptance and remaining.
|
|
48
|
+
const resumed = await tools.resume({ taskId: started.taskId });
|
|
49
|
+
assert.equal(resumed.title, '修复重复重试');
|
|
50
|
+
assert.equal(resumed.acceptance.length, 1);
|
|
51
|
+
assert.equal(resumed.remaining[0], '重试幂等');
|
|
52
|
+
assert.ok(resumed.acceptanceRevision >= 1);
|
|
53
|
+
|
|
54
|
+
// status lists and reads.
|
|
55
|
+
const list = await tools.status({ projectId: 'p1' });
|
|
56
|
+
assert.equal(list.total, 1);
|
|
57
|
+
const one = await tools.status({ taskId: started.taskId });
|
|
58
|
+
assert.equal(one.task.taskId, started.taskId);
|
|
59
|
+
|
|
60
|
+
// checkpoint candidate does not move nextAction; fact does.
|
|
61
|
+
await tools.checkpoint({ taskId: started.taskId, kind: 'candidate', summary: '可能完成', nextAction: '不该出现' });
|
|
62
|
+
let task = await tools.status({ taskId: started.taskId });
|
|
63
|
+
assert.notEqual(task.task.nextAction, '不该出现');
|
|
64
|
+
await tools.checkpoint({ taskId: started.taskId, kind: 'fact', summary: '修复完成', verifiedResults: ['单测通过'], nextAction: '提交审查' });
|
|
65
|
+
task = await tools.status({ taskId: started.taskId });
|
|
66
|
+
assert.equal(task.task.nextAction, '提交审查');
|
|
67
|
+
const resumed2 = await tools.resume({ taskId: started.taskId });
|
|
68
|
+
assert.deepEqual(resumed2.verifiedResults, ['单测通过']);
|
|
69
|
+
|
|
70
|
+
// request_review now runs the real check pipeline: use a synthetic repo
|
|
71
|
+
// with a real eslint violation so the receipt path is exercised (the
|
|
72
|
+
// verdict depends only on the synthetic files, never on this machine's
|
|
73
|
+
// other state).
|
|
74
|
+
const { spawnSync } = require('node:child_process');
|
|
75
|
+
const repo = fs.mkdtempSync(path.join(os.tmpdir(), 'wf-mcp-review-'));
|
|
76
|
+
const git = args => { const r = spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8' }); if (r.status !== 0) throw new Error(r.stderr); };
|
|
77
|
+
git(['init', '-b', 'main']); git(['config', 'user.email', 't@t']); git(['config', 'user.name', 't']);
|
|
78
|
+
fs.writeFileSync(path.join(repo, 'package.json'), '{"name":"x","private":true}');
|
|
79
|
+
fs.writeFileSync(path.join(repo, 'eslint.config.mjs'), 'export default [{ rules: { complexity: ["error", { max: 1 }] } }];\n');
|
|
80
|
+
fs.writeFileSync(path.join(repo, 'violation.js'), 'export function b(x){if(x===1){return 1;}if(x===2){return 2;}if(x===3){return 3;}return 0;}\n');
|
|
81
|
+
git(['add', '.']); git(['commit', '-m', 'init']);
|
|
82
|
+
const review = await tools.requestReview({ taskId: started.taskId, repoPath: repo, tools: ['eslint'] });
|
|
83
|
+
assert.ok(review.receipts.some(r => r.toolId === 'eslint'));
|
|
84
|
+
assert.ok(['fail', 'warn', 'error'].includes(review.receipts[0].verdict), `real violation must not pass: ${JSON.stringify(review.receipts[0])}`);
|
|
85
|
+
assert.equal(review.decision.delivered, false);
|
|
86
|
+
assert.equal(review.modelReview, 'pending-model-review');
|
|
87
|
+
const resultRead = await tools.reviewResult({ taskId: started.taskId });
|
|
88
|
+
assert.ok(Array.isArray(resultRead.checks) && resultRead.checks.length >= 1, 'review_result reads the recorded checks');
|
|
89
|
+
console.log('workflow-tools-test PASS (start/resume/status/checkpoint + real check receipts over a real module instance)');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Degradation: no live shell, no explicit URL -> structured WORKFLOW_UNAVAILABLE.
|
|
93
|
+
const offline = new WorkflowToolRuntime({ workflowUrl: 'http://127.0.0.1:9' });
|
|
94
|
+
try { await offline.status({}); throw new Error('offline status should fail'); }
|
|
95
|
+
catch (error) { assert.equal(error.code, 'WORKFLOW_UNAVAILABLE'); }
|
|
96
|
+
console.log('workflow-tools-test PASS (structured degradation when unreachable)');
|
|
97
|
+
})().catch(error => { console.error(error); process.exitCode = 1; });
|