test: remove duplicate gateway server coverage

This commit is contained in:
Peter Steinberger
2026-04-10 21:15:34 +01:00
parent 851294126b
commit fa97004ee1
4 changed files with 34 additions and 111 deletions

View File

@@ -40,6 +40,40 @@ describe("buildWorkspaceSkillStatus", () => {
expect(report.skills).toHaveLength(1);
expect(report.skills[0]?.install).toEqual([]);
});
it("does not expose raw config values in config checks", () => {
const secret = "discord-token-secret-abc"; // pragma: allowlist secret
const entry: SkillEntry = {
skill: createFixtureSkill({
name: "discord",
description: "test",
filePath: "/tmp/discord/SKILL.md",
baseDir: "/tmp/discord",
source: "test",
}),
frontmatter: {},
metadata: {
requires: { config: ["channels.discord.token"] },
},
};
const report = buildWorkspaceSkillStatus("/tmp/ws", {
entries: [entry],
config: {
channels: {
discord: {
token: secret,
},
},
},
});
expect(JSON.stringify(report)).not.toContain(secret);
const discord = report.skills.find((skill) => skill.name === "discord");
const check = discord?.configChecks.find((entry) => entry.path === "channels.discord.token");
expect(check).toEqual({ path: "channels.discord.token", satisfied: true });
expect(check && "value" in check).toBe(false);
});
});
function createFixtureSkill(params: {

View File

@@ -6,7 +6,6 @@ import { WebSocket } from "ws";
import type { ChannelOutboundAdapter } from "../channels/plugins/types.js";
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
import { resolveCanvasHostUrl } from "../infra/canvas-host-url.js";
import { GatewayLockError } from "../infra/gateway-lock.js";
import { createOutboundTestPlugin } from "../test-utils/channel-plugins.js";
import { withEnvAsync } from "../test-utils/env.js";
import { createTempHomeEnv } from "../test-utils/temp-home.js";
@@ -16,7 +15,6 @@ import {
connectOk,
getFreePort,
installGatewayTestHooks,
occupyPort,
onceMessage,
piSdkMock,
rpcReq,
@@ -557,14 +555,6 @@ describe("gateway server misc", () => {
});
});
test("refuses to start when port already bound", async () => {
const { server: blocker, port: blockedPort } = await occupyPort();
const startup = startGatewayServer(blockedPort);
await expect(startup).rejects.toBeInstanceOf(GatewayLockError);
await expect(startup).rejects.toThrow(/already listening/i);
blocker.close();
});
test("releases port after close", async () => {
const releasePort = await getFreePort();
const releaseServer = await startGatewayServer(releasePort);

View File

@@ -1,49 +0,0 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import { withEnvAsync } from "../test-utils/env.js";
import { connectOk, installGatewayTestHooks, rpcReq } from "./test-helpers.js";
import { withServer } from "./test-with-server.js";
installGatewayTestHooks({ scope: "suite" });
describe("gateway skills.status", () => {
it("does not expose raw config values to operator.read clients", async () => {
await withEnvAsync(
{ OPENCLAW_BUNDLED_SKILLS_DIR: path.join(process.cwd(), "skills") },
async () => {
const secret = "discord-token-secret-abc"; // pragma: allowlist secret
const { writeConfigFile } = await import("../config/config.js");
await writeConfigFile({
session: { mainKey: "main-test" },
channels: {
discord: {
token: secret,
},
},
});
await withServer(async (ws) => {
await connectOk(ws, { token: "secret", scopes: ["operator.read"] });
const res = await rpcReq<{
skills?: Array<{
name?: string;
configChecks?: Array<
{ path?: string; satisfied?: boolean } & Record<string, unknown>
>;
}>;
}>(ws, "skills.status", {});
expect(res.ok).toBe(true);
expect(JSON.stringify(res.payload)).not.toContain(secret);
const discord = res.payload?.skills?.find((s) => s.name === "discord");
expect(discord).toBeTruthy();
const check = discord?.configChecks?.find((c) => c.path === "channels.discord.token");
expect(check).toBeTruthy();
expect(check?.satisfied).toBe(true);
expect(check && "value" in check).toBe(false);
});
},
);
});
});

View File

@@ -1,52 +0,0 @@
import { describe, expect, it } from "vitest";
import { connectOk, installGatewayTestHooks, rpcReq } from "./test-helpers.js";
import { withServer } from "./test-with-server.js";
installGatewayTestHooks({ scope: "suite" });
describe("gateway tools.effective", () => {
it("returns effective tool inventory data", async () => {
await withServer(async (ws) => {
await connectOk(ws, { token: "secret", scopes: ["operator.read", "operator.write"] });
const created = await rpcReq<{ key?: string }>(ws, "sessions.create", {
label: "Tools Effective Test",
});
expect(created.ok).toBe(true);
const sessionKey = created.payload?.key;
expect(sessionKey).toBeTruthy();
const res = await rpcReq<{
agentId?: string;
groups?: Array<{
id?: "core" | "plugin" | "channel";
source?: "core" | "plugin" | "channel";
tools?: Array<{ id?: string; source?: "core" | "plugin" | "channel" }>;
}>;
}>(ws, "tools.effective", { sessionKey });
expect(res.ok).toBe(true);
expect(res.payload?.agentId).toBeTruthy();
expect((res.payload?.groups ?? []).length).toBeGreaterThan(0);
expect(
(res.payload?.groups ?? []).some((group) =>
(group.tools ?? []).some((tool) => tool.id === "exec"),
),
).toBe(true);
});
});
it("rejects unknown agent ids", async () => {
await withServer(async (ws) => {
await connectOk(ws, { token: "secret", scopes: ["operator.read", "operator.write"] });
const created = await rpcReq<{ key?: string }>(ws, "sessions.create", {
label: "Tools Effective Test",
});
expect(created.ok).toBe(true);
const unknownAgent = await rpcReq(ws, "tools.effective", {
sessionKey: created.payload?.key,
agentId: "does-not-exist",
});
expect(unknownAgent.ok).toBe(false);
expect(unknownAgent.error?.message ?? "").toContain("unknown agent id");
});
});
});