mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:50:46 +00:00
fix(acp): keep server logs off stdout
This commit is contained in:
@@ -21,6 +21,7 @@ const mockState = vi.hoisted(() => ({
|
|||||||
gatewayAuth: [] as GatewayClientAuth[],
|
gatewayAuth: [] as GatewayClientAuth[],
|
||||||
agentSideConnectionCtor: vi.fn(),
|
agentSideConnectionCtor: vi.fn(),
|
||||||
agentStart: vi.fn(),
|
agentStart: vi.fn(),
|
||||||
|
routeLogsToStderr: vi.fn(),
|
||||||
resolveGatewayClientBootstrap: vi.fn<ResolveGatewayClientBootstrap>(async (_params) => ({
|
resolveGatewayClientBootstrap: vi.fn<ResolveGatewayClientBootstrap>(async (_params) => ({
|
||||||
url: "ws://127.0.0.1:18789",
|
url: "ws://127.0.0.1:18789",
|
||||||
urlSource: "local loopback",
|
urlSource: "local loopback",
|
||||||
@@ -104,6 +105,10 @@ vi.mock("../infra/is-main.js", () => ({
|
|||||||
isMainModule: () => false,
|
isMainModule: () => false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock("../logging/console.js", () => ({
|
||||||
|
routeLogsToStderr: () => mockState.routeLogsToStderr(),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("./translator.js", () => ({
|
vi.mock("./translator.js", () => ({
|
||||||
AcpGatewayAgent: class {
|
AcpGatewayAgent: class {
|
||||||
start(): void {
|
start(): void {
|
||||||
@@ -166,6 +171,7 @@ describe("serveAcpGateway startup", () => {
|
|||||||
mockState.gatewayAuth.length = 0;
|
mockState.gatewayAuth.length = 0;
|
||||||
mockState.agentSideConnectionCtor.mockReset();
|
mockState.agentSideConnectionCtor.mockReset();
|
||||||
mockState.agentStart.mockReset();
|
mockState.agentStart.mockReset();
|
||||||
|
mockState.routeLogsToStderr.mockReset();
|
||||||
mockState.resolveGatewayClientBootstrap.mockReset();
|
mockState.resolveGatewayClientBootstrap.mockReset();
|
||||||
mockState.resolveGatewayClientBootstrap.mockResolvedValue({
|
mockState.resolveGatewayClientBootstrap.mockResolvedValue({
|
||||||
url: "ws://127.0.0.1:18789",
|
url: "ws://127.0.0.1:18789",
|
||||||
@@ -192,6 +198,26 @@ describe("serveAcpGateway startup", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("routes logs to stderr before loading gateway config", async () => {
|
||||||
|
const { signalHandlers, onceSpy } = captureProcessSignalHandlers();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const servePromise = serveAcpGateway({});
|
||||||
|
await Promise.resolve();
|
||||||
|
|
||||||
|
expect(mockState.routeLogsToStderr).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockState.routeLogsToStderr.mock.invocationCallOrder[0]).toBeLessThan(
|
||||||
|
mockState.resolveGatewayClientBootstrap.mock.invocationCallOrder[0] ??
|
||||||
|
Number.MAX_SAFE_INTEGER,
|
||||||
|
);
|
||||||
|
|
||||||
|
await emitHelloAndWaitForAgentSideConnection();
|
||||||
|
await stopServeWithSigint(signalHandlers, servePromise);
|
||||||
|
} finally {
|
||||||
|
onceSpy.mockRestore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("rejects startup when gateway connect fails before hello", async () => {
|
it("rejects startup when gateway connect fails before hello", async () => {
|
||||||
const onceSpy = vi
|
const onceSpy = vi
|
||||||
.spyOn(process, "once")
|
.spyOn(process, "once")
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import { resolveGatewayClientBootstrap } from "../gateway/client-bootstrap.js";
|
|||||||
import { GatewayClient } from "../gateway/client.js";
|
import { GatewayClient } from "../gateway/client.js";
|
||||||
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../gateway/protocol/client-info.js";
|
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from "../gateway/protocol/client-info.js";
|
||||||
import { isMainModule } from "../infra/is-main.js";
|
import { isMainModule } from "../infra/is-main.js";
|
||||||
|
import { routeLogsToStderr } from "../logging/console.js";
|
||||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||||
import { readSecretFromFile } from "./secret-file.js";
|
import { readSecretFromFile } from "./secret-file.js";
|
||||||
import { AcpGatewayAgent } from "./translator.js";
|
import { AcpGatewayAgent } from "./translator.js";
|
||||||
import { normalizeAcpProvenanceMode, type AcpServerOptions } from "./types.js";
|
import { normalizeAcpProvenanceMode, type AcpServerOptions } from "./types.js";
|
||||||
|
|
||||||
export async function serveAcpGateway(opts: AcpServerOptions = {}): Promise<void> {
|
export async function serveAcpGateway(opts: AcpServerOptions = {}): Promise<void> {
|
||||||
|
routeLogsToStderr();
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
const bootstrap = await resolveGatewayClientBootstrap({
|
const bootstrap = await resolveGatewayClientBootstrap({
|
||||||
config: cfg,
|
config: cfg,
|
||||||
|
|||||||
Reference in New Issue
Block a user