| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 'use strict';
- const assert = require('assert/strict');
- const fs = require('fs');
- const os = require('os');
- const path = require('path');
- const { spawnSync } = require('child_process');
- const { resolveWorkspaceRoot, workspaceIdentity } = require('../mcp/src/core/runtime-context');
- const { buildStartupSummary, startupAssistantMessage } = require('../mcp/src/core/startup-summary');
- const ROOT = path.resolve(__dirname, '..');
- function testRuntimeContext(tempRoot) {
- const installedPackage = path.join(tempRoot, '.claude', 'plugins', 'qiwei-assistant');
- fs.mkdirSync(installedPackage, { recursive: true });
- assert.equal(resolveWorkspaceRoot({ packageRoot: installedPackage, cwd: installedPackage }), tempRoot);
- assert.equal(resolveWorkspaceRoot({ packageRoot: ROOT, workspaceRoot: tempRoot }), tempRoot);
- assert.match(workspaceIdentity(tempRoot), /^[0-9a-f]{12}$/);
- }
- function testStartupSummary() {
- const offline = buildStartupSummary(
- { summary: { authConfigured: true, subscribed: true } },
- { data: { account: { configured: true, online: false }, listener: { running: false }, config: { allowedSenderCount: 1 } } },
- );
- assert.equal(offline.ready, false);
- assert.equal(offline.nextAction, '在工作台点击“恢复登录”');
- assert.match(startupAssistantMessage(offline), /企微账号待处理/);
- const ready = buildStartupSummary(
- { summary: { authConfigured: true, subscribed: true } },
- { data: { account: { configured: true, online: true }, listener: { running: true }, config: { allowedSenderCount: 1 } } },
- );
- assert.equal(ready.ready, true);
- assert.match(ready.nextAction, /可以进入智能会话/);
- }
- function testWorkspaceInstall(tempRoot) {
- const target = path.join(tempRoot, 'customer-project');
- fs.mkdirSync(target, { recursive: true });
- const result = spawnSync(process.execPath, [path.join(ROOT, 'install.js'), 'workspace', target, '--skip-install'], {
- cwd: ROOT,
- encoding: 'utf8',
- windowsHide: true,
- });
- assert.equal(result.status, 0, result.stderr || result.stdout);
- const mcp = JSON.parse(fs.readFileSync(path.join(target, '.mcp.json'), 'utf8'));
- const config = mcp.mcpServers?.['qiwei-assistant'];
- assert.equal(config.cwd, target);
- assert.equal(config.env?.QIWEI_WORKSPACE_ROOT, target);
- assert.equal(config.env?.QIWEI_OUTPUTS_DIR, path.join(target, 'outputs'));
- assert.equal(config.env?.CLAUDE_CODE_WORKDIR, target);
- assert(fs.existsSync(path.join(target, '.claude', 'plugins', 'qiwei-assistant', 'scripts', 'preview-dashboard.js')));
- assert(!fs.existsSync(path.join(target, '.claude', 'plugins', 'qiwei-assistant', '.env.local')));
- }
- function main() {
- const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'qiwei-preview-smoke-'));
- try {
- testRuntimeContext(tempRoot);
- testStartupSummary();
- testWorkspaceInstall(tempRoot);
- } finally {
- fs.rmSync(tempRoot, { recursive: true, force: true });
- }
- process.stdout.write(`${JSON.stringify({ status: 'ok', checks: 3 }, null, 2)}\n`);
- }
- try { main(); }
- catch (error) {
- process.stderr.write(`${error.message}\n`);
- process.exit(1);
- }
|