fix: normalize gateway dev mode detection

This commit is contained in:
Peter Steinberger
2026-01-18 01:08:42 +00:00
parent 2c070952e1
commit 36d88f6079
29 changed files with 95 additions and 107 deletions

View File

@@ -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}`,
),
}));

View File

@@ -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"));
}