目录重组:后端按core/domains分领域存放(仅移动与更新引用)
- 50个后端模块用git mv移入core/与domains/<领域>/,入口server.js、launch.js、restore.js及server/原位不动 - 所有require路径由脚本按新旧位置统一换算(后端、server/、测试) - 新增test/app-paths.test.js,锁定默认数据目录、public目录与飞书配置文件的绝对位置 - 维护与部署.md补充目录说明并更新模块路径 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95c481c74a
commit
9ec37196d4
172 files changed
+458
-384
No files matched your search
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
// 目录重组后的路径护栏:默认数据目录、静态资源目录与飞书配置文件必须仍落在 新账系统/ 下的原位置,
|
||||
// 否则用户机器上的真实账本会“消失”(启动时在新位置建空库)。
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { Ledger } = require('../core/ledger');
|
||||
const { createApp } = require('../server');
|
||||
const { serveStatic } = require('../server/middleware/static');
|
||||
|
||||
const APP_DIR = path.resolve(__dirname, '..');
|
||||
|
||||
function withSpy(object, method, record, fn) {
|
||||
const original = object[method];
|
||||
object[method] = function (...args) {
|
||||
record.push(args[0]);
|
||||
return original.apply(this, args);
|
||||
};
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
object[method] = original;
|
||||
}
|
||||
}
|
||||
|
||||
test('默认数据目录仍为 新账系统/data/<mode>', () => {
|
||||
for (const mode of ['trial', 'demo']) {
|
||||
const app = createApp({ mode, ledger: new Ledger(':memory:'), feishuConfig: { enabled: false } });
|
||||
try {
|
||||
assert.equal(app.dataDir, path.join(APP_DIR, 'data', mode));
|
||||
} finally {
|
||||
app.ledger.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('默认飞书配置文件仍为 新账系统/feishu.local.json', () => {
|
||||
const saved = process.env.FEISHU_CONFIG;
|
||||
delete process.env.FEISHU_CONFIG;
|
||||
const checked = [];
|
||||
const original = fs.existsSync;
|
||||
fs.existsSync = file => {
|
||||
checked.push(file);
|
||||
return file === path.join(APP_DIR, 'feishu.local.json') ? false : original(file);
|
||||
};
|
||||
try {
|
||||
const app = createApp({ mode: 'trial', ledger: new Ledger(':memory:') });
|
||||
app.ledger.close();
|
||||
} finally {
|
||||
fs.existsSync = original;
|
||||
if (saved !== undefined) process.env.FEISHU_CONFIG = saved;
|
||||
}
|
||||
assert.ok(checked.includes(path.join(APP_DIR, 'feishu.local.json')), checked.join('\n'));
|
||||
});
|
||||
|
||||
test('静态资源仍从 新账系统/public 读取', () => {
|
||||
const read = [];
|
||||
const res = { writeHead() {}, setHeader() {}, end() {} };
|
||||
withSpy(fs, 'readFileSync', read, () => serveStatic(res, '/', false));
|
||||
assert.ok(read.includes(path.join(APP_DIR, 'public', 'index.html')), read.join('\n'));
|
||||
});
|
||||
Reference in new issue
Block a user