test(e2e): stabilize suite

This commit is contained in:
Peter Steinberger
2026-02-14 20:54:31 +01:00
parent 2a3da21333
commit c06a962bb6
15 changed files with 238 additions and 84 deletions

View File

@@ -448,7 +448,7 @@ describe("gateway server agent", () => {
const spy = vi.mocked(agentCommand);
const call = spy.mock.calls.at(-1)?.[0] as Record<string, unknown>;
expect(call.sessionKey).toBe("main");
expect(call.sessionKey).toBe("agent:main:main");
expectChannels(call, "webchat");
expect(typeof call.message).toBe("string");
expect(call.message).toContain("what is in the image?");

View File

@@ -117,6 +117,18 @@ describe("gateway server auth/connect", () => {
ws.close();
});
test("ignores requested scopes when device identity is omitted", async () => {
const ws = await openWs(port);
const res = await connectReq(ws, { device: null });
expect(res.ok).toBe(true);
const health = await rpcReq(ws, "health");
expect(health.ok).toBe(false);
expect(health.error?.message).toContain("missing scope");
ws.close();
});
test("does not grant admin when scopes are omitted", async () => {
const ws = await openWs(port);
const token =
@@ -144,18 +156,6 @@ describe("gateway server auth/connect", () => {
signedAtMs,
token: token ?? null,
});
test("ignores requested scopes when device identity is omitted", async () => {
const ws = await openWs(port);
const res = await connectReq(ws, { device: null });
expect(res.ok).toBe(true);
const health = await rpcReq(ws, "health");
expect(health.ok).toBe(false);
expect(health.error?.message).toContain("missing scope");
ws.close();
});
const device = {
id: identity.deviceId,
publicKey: publicKeyRawBase64UrlFromPem(identity.publicKeyPem),

View File

@@ -403,8 +403,7 @@ describe("gateway server misc", () => {
const plugins = updated.plugins as Record<string, unknown> | undefined;
const entries = plugins?.entries as Record<string, unknown> | undefined;
const discord = entries?.discord as Record<string, unknown> | undefined;
// Auto-enable registers the plugin entry but keeps it disabled for explicit opt-in.
expect(discord?.enabled).toBe(false);
expect(discord?.enabled).toBe(true);
expect((updated.channels as Record<string, unknown> | undefined)?.discord).toMatchObject({
token: "token-123",
});

View File

@@ -170,12 +170,15 @@ installGatewayTestHooks({ scope: "suite" });
describe("gateway hot reload", () => {
let prevSkipChannels: string | undefined;
let prevSkipGmail: string | undefined;
let prevSkipProviders: string | undefined;
beforeEach(() => {
prevSkipChannels = process.env.OPENCLAW_SKIP_CHANNELS;
prevSkipGmail = process.env.OPENCLAW_SKIP_GMAIL_WATCHER;
prevSkipProviders = process.env.OPENCLAW_SKIP_PROVIDERS;
process.env.OPENCLAW_SKIP_CHANNELS = "0";
delete process.env.OPENCLAW_SKIP_GMAIL_WATCHER;
delete process.env.OPENCLAW_SKIP_PROVIDERS;
});
afterEach(() => {
@@ -189,6 +192,11 @@ describe("gateway hot reload", () => {
} else {
process.env.OPENCLAW_SKIP_GMAIL_WATCHER = prevSkipGmail;
}
if (prevSkipProviders === undefined) {
delete process.env.OPENCLAW_SKIP_PROVIDERS;
} else {
process.env.OPENCLAW_SKIP_PROVIDERS = prevSkipProviders;
}
});
it("applies hot reload actions and emits restart signal", async () => {

View File

@@ -207,6 +207,7 @@ describe("gateway update.run", () => {
process.on("SIGUSR1", sigusr1);
try {
await fs.mkdir(path.dirname(CONFIG_PATH), { recursive: true });
await fs.writeFile(CONFIG_PATH, JSON.stringify({ update: { channel: "beta" } }, null, 2));
const updateMock = vi.mocked(runGatewayUpdate);
updateMock.mockClear();