mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 10:27:38 +00:00
refactor(gateway): simplify restart flow and expand lock tests
This commit is contained in:
@@ -63,10 +63,34 @@ describe("infra parsing", () => {
|
||||
argv: ["node", "/repo/openclaw.mjs"],
|
||||
cwd: "/repo",
|
||||
env: {},
|
||||
wrapperEntryPairs: [{ wrapperBasename: "openclaw.mjs", entryBasename: "entry.js" }],
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for wrapper launches when wrapper pair is not configured", () => {
|
||||
expect(
|
||||
isMainModule({
|
||||
currentFile: "/repo/dist/entry.js",
|
||||
argv: ["node", "/repo/openclaw.mjs"],
|
||||
cwd: "/repo",
|
||||
env: {},
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when wrapper pair targets a different entry basename", () => {
|
||||
expect(
|
||||
isMainModule({
|
||||
currentFile: "/repo/dist/index.js",
|
||||
argv: ["node", "/repo/openclaw.mjs"],
|
||||
cwd: "/repo",
|
||||
env: {},
|
||||
wrapperEntryPairs: [{ wrapperBasename: "openclaw.mjs", entryBasename: "entry.js" }],
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when running under PM2 but this module is imported", () => {
|
||||
expect(
|
||||
isMainModule({
|
||||
|
||||
@@ -6,6 +6,10 @@ type IsMainModuleOptions = {
|
||||
argv?: string[];
|
||||
env?: NodeJS.ProcessEnv;
|
||||
cwd?: string;
|
||||
wrapperEntryPairs?: Array<{
|
||||
wrapperBasename: string;
|
||||
entryBasename: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
function normalizePathCandidate(candidate: string | undefined, cwd: string): string | undefined {
|
||||
@@ -26,6 +30,7 @@ export function isMainModule({
|
||||
argv = process.argv,
|
||||
env = process.env,
|
||||
cwd = process.cwd(),
|
||||
wrapperEntryPairs = [],
|
||||
}: IsMainModuleOptions): boolean {
|
||||
const normalizedCurrent = normalizePathCandidate(currentFile, cwd);
|
||||
const normalizedArgv1 = normalizePathCandidate(argv[1], cwd);
|
||||
@@ -41,12 +46,15 @@ export function isMainModule({
|
||||
return true;
|
||||
}
|
||||
|
||||
// The published/open-source wrapper binary is openclaw.mjs, which then imports
|
||||
// dist/entry.js. Treat that pair as the main module so entry bootstrap runs.
|
||||
if (normalizedCurrent && normalizedArgv1) {
|
||||
// Optional wrapper->entry mapping for wrapper launchers that import the real entry.
|
||||
if (normalizedCurrent && normalizedArgv1 && wrapperEntryPairs.length > 0) {
|
||||
const currentBase = path.basename(normalizedCurrent);
|
||||
const argvBase = path.basename(normalizedArgv1);
|
||||
if (currentBase === "entry.js" && (argvBase === "openclaw.mjs" || argvBase === "openclaw.js")) {
|
||||
const matched = wrapperEntryPairs.some(
|
||||
({ wrapperBasename, entryBasename }) =>
|
||||
currentBase === entryBasename && argvBase === wrapperBasename,
|
||||
);
|
||||
if (matched) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user