fix(server): worktree 启动时 ECAT_DIR 回指主检出 tools/ecat
从 .worktrees/<slug> 跑 esp32_server 时 join(BASE_DIR,'..','ecat') 会拼成 .worktrees/ecat,找不到 ecat_native.exe。先走出 .worktrees 再取兄弟目录。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 从 git worktree 启动 esp32_server 时,ECAT_DIR 必须指回主检出的
|
||||
* tools/ecat,而不是 .../ESP32/.worktrees/ecat。
|
||||
* 复刻 _resolve_ecat_dir 的纯路径逻辑(无 DOM/无网络)。
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
/** 与 esp32_server._resolve_ecat_dir 同构(JS 侧只测路径形状)。 */
|
||||
function resolveEcatDir(baseDir) {
|
||||
let d = path.resolve(baseDir);
|
||||
const parent = path.dirname(d);
|
||||
if (path.basename(parent) === ".worktrees") {
|
||||
d = path.dirname(parent);
|
||||
}
|
||||
return path.normalize(path.join(d, "..", "ecat"));
|
||||
}
|
||||
|
||||
let failed = 0;
|
||||
function check(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(" ✓", name);
|
||||
} catch (e) {
|
||||
failed++;
|
||||
console.log(" ✗", name, "—", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("[worktree ECAT_DIR]");
|
||||
|
||||
check("主检出 BASE_DIR → 兄弟 tools/ecat", () => {
|
||||
const base = path.resolve("G:/Robot_v2/DCU/tools/ESP32");
|
||||
const got = resolveEcatDir(base);
|
||||
assert.equal(got, path.resolve("G:/Robot_v2/DCU/tools/ecat"), got);
|
||||
});
|
||||
|
||||
check("worktree BASE_DIR → 仍指主检出的 tools/ecat", () => {
|
||||
const base = path.resolve("G:/Robot_v2/DCU/tools/ESP32/.worktrees/device-link");
|
||||
const got = resolveEcatDir(base);
|
||||
assert.equal(got, path.resolve("G:/Robot_v2/DCU/tools/ecat"), got);
|
||||
});
|
||||
|
||||
check("嵌套 slug 也走 .worktrees 父级", () => {
|
||||
const base = path.resolve("G:/x/tools/ESP32/.worktrees/foo-bar");
|
||||
const got = resolveEcatDir(base);
|
||||
assert.equal(got, path.resolve("G:/x/tools/ecat"), got);
|
||||
});
|
||||
|
||||
/* BASE_DIR 恒为 esp32_server.py 所在目录;普通主检出已在第一项覆盖。 */
|
||||
|
||||
if (failed) {
|
||||
console.log(`失败 ${failed} 项`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("通过 3 项,失败 0 项");
|
||||
Reference in New Issue
Block a user