fix: normalize gateway dev mode detection
This commit is contained in:
@@ -5,18 +5,15 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ChannelPlugin } from "../../channels/plugins/types.js";
|
||||
import { channelsCapabilitiesCommand } from "./capabilities.js";
|
||||
import { fetchSlackScopes } from "../../slack/scopes.js";
|
||||
import {
|
||||
getChannelPlugin,
|
||||
listChannelPlugins,
|
||||
} from "../../channels/plugins/index.js";
|
||||
import { getChannelPlugin, listChannelPlugins } from "../../channels/plugins/index.js";
|
||||
|
||||
const logs: string[] = [];
|
||||
const errors: string[] = [];
|
||||
|
||||
vi.mock("./shared.js", () => ({
|
||||
requireValidConfig: vi.fn(async () => ({ channels: {} })),
|
||||
formatChannelAccountLabel: vi.fn(({ channel, accountId }: { channel: string; accountId: string }) =>
|
||||
`${channel}:${accountId}`,
|
||||
formatChannelAccountLabel: vi.fn(
|
||||
({ channel, accountId }: { channel: string; accountId: string }) => `${channel}:${accountId}`,
|
||||
),
|
||||
}));
|
||||
|
||||
|
||||
@@ -146,8 +146,10 @@ function formatProbeLines(channelId: string, probe: unknown): string[] {
|
||||
}
|
||||
const flags: string[] = [];
|
||||
const canJoinGroups = (bot as { canJoinGroups?: boolean | null })?.canJoinGroups;
|
||||
const canReadAll = (bot as { canReadAllGroupMessages?: boolean | null })?.canReadAllGroupMessages;
|
||||
const inlineQueries = (bot as { supportsInlineQueries?: boolean | null })?.supportsInlineQueries;
|
||||
const canReadAll = (bot as { canReadAllGroupMessages?: boolean | null })
|
||||
?.canReadAllGroupMessages;
|
||||
const inlineQueries = (bot as { supportsInlineQueries?: boolean | null })
|
||||
?.supportsInlineQueries;
|
||||
if (typeof canJoinGroups === "boolean") flags.push(`joinGroups=${canJoinGroups}`);
|
||||
if (typeof canReadAll === "boolean") flags.push(`readAllGroupMessages=${canReadAll}`);
|
||||
if (typeof inlineQueries === "boolean") flags.push(`inlineQueries=${inlineQueries}`);
|
||||
@@ -187,14 +189,15 @@ function formatProbeLines(channelId: string, probe: unknown): string[] {
|
||||
const roles = Array.isArray(graph.roles)
|
||||
? graph.roles.map((role) => String(role).trim()).filter(Boolean)
|
||||
: [];
|
||||
const scopes = typeof graph.scopes === "string"
|
||||
? graph.scopes
|
||||
.split(/\s+/)
|
||||
.map((scope) => scope.trim())
|
||||
.filter(Boolean)
|
||||
: Array.isArray(graph.scopes)
|
||||
? graph.scopes.map((scope) => String(scope).trim()).filter(Boolean)
|
||||
: [];
|
||||
const scopes =
|
||||
typeof graph.scopes === "string"
|
||||
? graph.scopes
|
||||
.split(/\s+/)
|
||||
.map((scope) => scope.trim())
|
||||
.filter(Boolean)
|
||||
: Array.isArray(graph.scopes)
|
||||
? graph.scopes.map((scope) => String(scope).trim()).filter(Boolean)
|
||||
: [];
|
||||
if (graph.ok === false) {
|
||||
lines.push(`Graph: ${theme.error(graph.error ?? "failed")}`);
|
||||
} else if (roles.length > 0 || scopes.length > 0) {
|
||||
@@ -219,7 +222,8 @@ function formatProbeLines(channelId: string, probe: unknown): string[] {
|
||||
lines.push("Probe: ok");
|
||||
}
|
||||
if (ok === false) {
|
||||
const error = typeof probeObj.error === "string" && probeObj.error ? ` (${probeObj.error})` : "";
|
||||
const error =
|
||||
typeof probeObj.error === "string" && probeObj.error ? ` (${probeObj.error})` : "";
|
||||
lines.push(`Probe: ${theme.error(`failed${error}`)}`);
|
||||
}
|
||||
return lines;
|
||||
@@ -388,8 +392,7 @@ export async function channelsCapabilitiesCommand(
|
||||
const cfg = await requireValidConfig(runtime);
|
||||
if (!cfg) return;
|
||||
const timeoutMs = normalizeTimeout(opts.timeout, 10_000);
|
||||
const rawChannel =
|
||||
typeof opts.channel === "string" ? opts.channel.trim().toLowerCase() : "";
|
||||
const rawChannel = typeof opts.channel === "string" ? opts.channel.trim().toLowerCase() : "";
|
||||
const rawTarget = typeof opts.target === "string" ? opts.target.trim() : "";
|
||||
|
||||
if (opts.account && (!rawChannel || rawChannel === "all")) {
|
||||
@@ -483,9 +486,7 @@ export async function channelsCapabilitiesCommand(
|
||||
const label = perms.channelId ? ` (${perms.channelId})` : "";
|
||||
lines.push(`Permissions${label}: ${list}`);
|
||||
if (perms.missingRequired && perms.missingRequired.length > 0) {
|
||||
lines.push(
|
||||
`${theme.warn("Missing required:")} ${perms.missingRequired.join(", ")}`,
|
||||
);
|
||||
lines.push(`${theme.warn("Missing required:")} ${perms.missingRequired.join(", ")}`);
|
||||
} else {
|
||||
lines.push(theme.success("Missing required: none"));
|
||||
}
|
||||
|
||||
@@ -34,9 +34,10 @@ afterEach(() => {
|
||||
|
||||
describe("resolveGatewayDevMode", () => {
|
||||
it("detects dev mode for src ts entrypoints", () => {
|
||||
expect(
|
||||
resolveGatewayDevMode(["node", "/Users/me/clawdbot/src/cli/index.ts"]),
|
||||
).toBe(true);
|
||||
expect(resolveGatewayDevMode(["node", "/Users/me/clawdbot/src/cli/index.ts"])).toBe(true);
|
||||
expect(resolveGatewayDevMode(["node", "C:\\Users\\me\\clawdbot\\src\\cli\\index.ts"])).toBe(
|
||||
true,
|
||||
);
|
||||
expect(resolveGatewayDevMode(["node", "/Users/me/clawdbot/dist/cli/index.js"])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import path from "node:path";
|
||||
|
||||
import { resolveGatewayLaunchAgentLabel } from "../daemon/constants.js";
|
||||
import { resolveGatewayProgramArguments } from "../daemon/program-args.js";
|
||||
import {
|
||||
@@ -20,7 +18,8 @@ export type GatewayInstallPlan = {
|
||||
|
||||
export function resolveGatewayDevMode(argv: string[] = process.argv): boolean {
|
||||
const entry = argv[1];
|
||||
return Boolean(entry?.includes(`${path.sep}src${path.sep}`) && entry.endsWith(".ts"));
|
||||
const normalizedEntry = entry?.replaceAll("\\", "/");
|
||||
return Boolean(normalizedEntry?.includes("/src/") && normalizedEntry.endsWith(".ts"));
|
||||
}
|
||||
|
||||
export async function buildGatewayInstallPlan(params: {
|
||||
|
||||
@@ -15,10 +15,7 @@ import {
|
||||
GATEWAY_DAEMON_RUNTIME_OPTIONS,
|
||||
type GatewayDaemonRuntime,
|
||||
} from "./daemon-runtime.js";
|
||||
import {
|
||||
buildGatewayInstallPlan,
|
||||
gatewayInstallErrorHint,
|
||||
} from "./daemon-install-helpers.js";
|
||||
import { buildGatewayInstallPlan, gatewayInstallErrorHint } from "./daemon-install-helpers.js";
|
||||
import { buildGatewayRuntimeHints, formatGatewayRuntimeSummary } from "./doctor-format.js";
|
||||
import type { DoctorOptions, DoctorPrompter } from "./doctor-prompter.js";
|
||||
import { healthCommand } from "./health.js";
|
||||
|
||||
@@ -4,10 +4,7 @@ import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { resolveGatewayPort, resolveIsNixMode } from "../config/paths.js";
|
||||
import { findExtraGatewayServices, renderGatewayServiceCleanupHints } from "../daemon/inspect.js";
|
||||
import { findLegacyGatewayServices, uninstallLegacyGatewayServices } from "../daemon/legacy.js";
|
||||
import {
|
||||
renderSystemNodeWarning,
|
||||
resolveSystemNodeInfo,
|
||||
} from "../daemon/runtime-paths.js";
|
||||
import { renderSystemNodeWarning, resolveSystemNodeInfo } from "../daemon/runtime-paths.js";
|
||||
import { resolveGatewayService } from "../daemon/service.js";
|
||||
import {
|
||||
auditGatewayServiceConfig,
|
||||
@@ -16,10 +13,7 @@ import {
|
||||
} from "../daemon/service-audit.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { note } from "../terminal/note.js";
|
||||
import {
|
||||
buildGatewayInstallPlan,
|
||||
gatewayInstallErrorHint,
|
||||
} from "./daemon-install-helpers.js";
|
||||
import { buildGatewayInstallPlan, gatewayInstallErrorHint } from "./daemon-install-helpers.js";
|
||||
import {
|
||||
DEFAULT_GATEWAY_DAEMON_RUNTIME,
|
||||
GATEWAY_DAEMON_RUNTIME_OPTIONS,
|
||||
|
||||
@@ -3,10 +3,7 @@ import { resolveGatewayService } from "../../../daemon/service.js";
|
||||
import { isSystemdUserServiceAvailable } from "../../../daemon/systemd.js";
|
||||
import type { RuntimeEnv } from "../../../runtime.js";
|
||||
import { DEFAULT_GATEWAY_DAEMON_RUNTIME, isGatewayDaemonRuntime } from "../../daemon-runtime.js";
|
||||
import {
|
||||
buildGatewayInstallPlan,
|
||||
gatewayInstallErrorHint,
|
||||
} from "../../daemon-install-helpers.js";
|
||||
import { buildGatewayInstallPlan, gatewayInstallErrorHint } from "../../daemon-install-helpers.js";
|
||||
import type { OnboardOptions } from "../../onboard-types.js";
|
||||
import { ensureSystemdUserLingerNonInteractive } from "../../systemd-linger.js";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user