fix: audit doctor service entrypoint
This commit is contained in:
@@ -80,6 +80,7 @@
|
|||||||
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
||||||
"test:live": "vitest run --config vitest.live.config.ts",
|
"test:live": "vitest run --config vitest.live.config.ts",
|
||||||
"test:docker:qr": "bash scripts/e2e/qr-import-docker.sh",
|
"test:docker:qr": "bash scripts/e2e/qr-import-docker.sh",
|
||||||
|
"test:docker:doctor-switch": "bash scripts/e2e/doctor-install-switch-docker.sh",
|
||||||
"protocol:gen": "tsx scripts/protocol-gen.ts",
|
"protocol:gen": "tsx scripts/protocol-gen.ts",
|
||||||
"protocol:gen:swift": "tsx scripts/protocol-gen-swift.ts",
|
"protocol:gen:swift": "tsx scripts/protocol-gen-swift.ts",
|
||||||
"protocol:check": "pnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code -- dist/protocol.schema.json apps/macos/Sources/ClawdbotProtocol/GatewayModels.swift",
|
"protocol:check": "pnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code -- dist/protocol.schema.json apps/macos/Sources/ClawdbotProtocol/GatewayModels.swift",
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { resolveGatewayService } from "../daemon/service.js";
|
|||||||
import {
|
import {
|
||||||
auditGatewayServiceConfig,
|
auditGatewayServiceConfig,
|
||||||
needsNodeRuntimeMigration,
|
needsNodeRuntimeMigration,
|
||||||
|
SERVICE_AUDIT_CODES,
|
||||||
} from "../daemon/service-audit.js";
|
} from "../daemon/service-audit.js";
|
||||||
import { buildServiceEnvironment } from "../daemon/service-env.js";
|
import { buildServiceEnvironment } from "../daemon/service-env.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
@@ -48,6 +49,17 @@ function detectGatewayRuntime(
|
|||||||
return DEFAULT_GATEWAY_DAEMON_RUNTIME;
|
return DEFAULT_GATEWAY_DAEMON_RUNTIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findGatewayEntrypoint(programArguments?: string[]): string | null {
|
||||||
|
if (!programArguments || programArguments.length === 0) return null;
|
||||||
|
const gatewayIndex = programArguments.indexOf("gateway");
|
||||||
|
if (gatewayIndex <= 0) return null;
|
||||||
|
return programArguments[gatewayIndex - 1] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeExecutablePath(value: string): string {
|
||||||
|
return path.resolve(value);
|
||||||
|
}
|
||||||
|
|
||||||
export async function maybeMigrateLegacyGatewayService(
|
export async function maybeMigrateLegacyGatewayService(
|
||||||
cfg: ClawdbotConfig,
|
cfg: ClawdbotConfig,
|
||||||
mode: "local" | "remote",
|
mode: "local" | "remote",
|
||||||
@@ -171,6 +183,46 @@ export async function maybeRepairGatewayServiceConfig(
|
|||||||
env: process.env,
|
env: process.env,
|
||||||
command,
|
command,
|
||||||
});
|
});
|
||||||
|
const needsNodeRuntime = needsNodeRuntimeMigration(audit.issues);
|
||||||
|
const systemNodePath = needsNodeRuntime
|
||||||
|
? await resolveSystemNodePath(process.env)
|
||||||
|
: null;
|
||||||
|
if (needsNodeRuntime && !systemNodePath) {
|
||||||
|
note(
|
||||||
|
"System Node 22+ not found. Install via Homebrew/apt/choco and rerun doctor to migrate off Bun/version managers.",
|
||||||
|
"Gateway runtime",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const devMode =
|
||||||
|
process.argv[1]?.includes(`${path.sep}src${path.sep}`) &&
|
||||||
|
process.argv[1]?.endsWith(".ts");
|
||||||
|
const port = resolveGatewayPort(cfg, process.env);
|
||||||
|
const runtimeChoice = detectGatewayRuntime(command.programArguments);
|
||||||
|
const { programArguments, workingDirectory } =
|
||||||
|
await resolveGatewayProgramArguments({
|
||||||
|
port,
|
||||||
|
dev: devMode,
|
||||||
|
runtime: needsNodeRuntime && systemNodePath ? "node" : runtimeChoice,
|
||||||
|
nodePath: systemNodePath ?? undefined,
|
||||||
|
});
|
||||||
|
const expectedEntrypoint = findGatewayEntrypoint(programArguments);
|
||||||
|
const currentEntrypoint = findGatewayEntrypoint(command.programArguments);
|
||||||
|
if (
|
||||||
|
expectedEntrypoint &&
|
||||||
|
currentEntrypoint &&
|
||||||
|
normalizeExecutablePath(expectedEntrypoint) !==
|
||||||
|
normalizeExecutablePath(currentEntrypoint)
|
||||||
|
) {
|
||||||
|
audit.issues.push({
|
||||||
|
code: SERVICE_AUDIT_CODES.gatewayEntrypointMismatch,
|
||||||
|
message:
|
||||||
|
"Gateway service entrypoint does not match the current install.",
|
||||||
|
detail: `${currentEntrypoint} -> ${expectedEntrypoint}`,
|
||||||
|
level: "recommended",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (audit.issues.length === 0) return;
|
if (audit.issues.length === 0) return;
|
||||||
|
|
||||||
note(
|
note(
|
||||||
@@ -207,30 +259,6 @@ export async function maybeRepairGatewayServiceConfig(
|
|||||||
initialValue: true,
|
initialValue: true,
|
||||||
});
|
});
|
||||||
if (!repair) return;
|
if (!repair) return;
|
||||||
|
|
||||||
const needsNodeRuntime = needsNodeRuntimeMigration(audit.issues);
|
|
||||||
const systemNodePath = needsNodeRuntime
|
|
||||||
? await resolveSystemNodePath(process.env)
|
|
||||||
: null;
|
|
||||||
if (needsNodeRuntime && !systemNodePath) {
|
|
||||||
note(
|
|
||||||
"System Node 22+ not found. Install via Homebrew/apt/choco and rerun doctor to migrate off Bun/version managers.",
|
|
||||||
"Gateway runtime",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const devMode =
|
|
||||||
process.argv[1]?.includes(`${path.sep}src${path.sep}`) &&
|
|
||||||
process.argv[1]?.endsWith(".ts");
|
|
||||||
const port = resolveGatewayPort(cfg, process.env);
|
|
||||||
const runtimeChoice = detectGatewayRuntime(command.programArguments);
|
|
||||||
const { programArguments, workingDirectory } =
|
|
||||||
await resolveGatewayProgramArguments({
|
|
||||||
port,
|
|
||||||
dev: devMode,
|
|
||||||
runtime: needsNodeRuntime && systemNodePath ? "node" : runtimeChoice,
|
|
||||||
nodePath: systemNodePath ?? undefined,
|
|
||||||
});
|
|
||||||
const environment = buildServiceEnvironment({
|
const environment = buildServiceEnvironment({
|
||||||
env: process.env,
|
env: process.env,
|
||||||
port,
|
port,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export type ServiceConfigAudit = {
|
|||||||
|
|
||||||
export const SERVICE_AUDIT_CODES = {
|
export const SERVICE_AUDIT_CODES = {
|
||||||
gatewayCommandMissing: "gateway-command-missing",
|
gatewayCommandMissing: "gateway-command-missing",
|
||||||
|
gatewayEntrypointMismatch: "gateway-entrypoint-mismatch",
|
||||||
gatewayPathMissing: "gateway-path-missing",
|
gatewayPathMissing: "gateway-path-missing",
|
||||||
gatewayPathMissingDirs: "gateway-path-missing-dirs",
|
gatewayPathMissingDirs: "gateway-path-missing-dirs",
|
||||||
gatewayPathNonMinimal: "gateway-path-nonminimal",
|
gatewayPathNonMinimal: "gateway-path-nonminimal",
|
||||||
|
|||||||
Reference in New Issue
Block a user