mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 23:14:32 +00:00
test(cli): dedupe browser state command setup
This commit is contained in:
@@ -26,6 +26,26 @@ vi.mock("../runtime.js", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe("browser state option collisions", () => {
|
describe("browser state option collisions", () => {
|
||||||
|
const createBrowserProgram = () => {
|
||||||
|
const program = new Command();
|
||||||
|
const browser = program
|
||||||
|
.command("browser")
|
||||||
|
.option("--browser-profile <name>", "Browser profile")
|
||||||
|
.option("--json", "Output JSON", false);
|
||||||
|
const parentOpts = (cmd: Command) => cmd.parent?.opts?.() as BrowserParentOpts;
|
||||||
|
registerBrowserStateCommands(browser, parentOpts);
|
||||||
|
return program;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLastRequest = () => {
|
||||||
|
const call = mocks.callBrowserRequest.mock.calls.at(-1);
|
||||||
|
expect(call).toBeDefined();
|
||||||
|
if (!call) {
|
||||||
|
throw new Error("expected browser request call");
|
||||||
|
}
|
||||||
|
return call[1] as { body?: Record<string, unknown> };
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks.callBrowserRequest.mockClear();
|
mocks.callBrowserRequest.mockClear();
|
||||||
mocks.runBrowserResizeWithOutput.mockClear();
|
mocks.runBrowserResizeWithOutput.mockClear();
|
||||||
@@ -35,14 +55,7 @@ describe("browser state option collisions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("forwards parent-captured --target-id on `browser cookies set`", async () => {
|
it("forwards parent-captured --target-id on `browser cookies set`", async () => {
|
||||||
const program = new Command();
|
const program = createBrowserProgram();
|
||||||
const browser = program
|
|
||||||
.command("browser")
|
|
||||||
.option("--browser-profile <name>", "Browser profile")
|
|
||||||
.option("--json", "Output JSON", false);
|
|
||||||
|
|
||||||
const parentOpts = (cmd: Command) => cmd.parent?.opts?.() as BrowserParentOpts;
|
|
||||||
registerBrowserStateCommands(browser, parentOpts);
|
|
||||||
|
|
||||||
await program.parseAsync(
|
await program.parseAsync(
|
||||||
[
|
[
|
||||||
@@ -59,35 +72,18 @@ describe("browser state option collisions", () => {
|
|||||||
{ from: "user" },
|
{ from: "user" },
|
||||||
);
|
);
|
||||||
|
|
||||||
const call = mocks.callBrowserRequest.mock.calls.at(-1);
|
const request = getLastRequest() as { body?: { targetId?: string } };
|
||||||
expect(call).toBeDefined();
|
|
||||||
if (!call) {
|
|
||||||
throw new Error("expected browser request call");
|
|
||||||
}
|
|
||||||
const request = call[1] as { body?: { targetId?: string } };
|
|
||||||
expect(request.body?.targetId).toBe("tab-1");
|
expect(request.body?.targetId).toBe("tab-1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("accepts legacy parent `--json` by parsing payload via positional headers fallback", async () => {
|
it("accepts legacy parent `--json` by parsing payload via positional headers fallback", async () => {
|
||||||
const program = new Command();
|
const program = createBrowserProgram();
|
||||||
const browser = program
|
|
||||||
.command("browser")
|
|
||||||
.option("--browser-profile <name>", "Browser profile")
|
|
||||||
.option("--json", "Output JSON", false);
|
|
||||||
|
|
||||||
const parentOpts = (cmd: Command) => cmd.parent?.opts?.() as BrowserParentOpts;
|
|
||||||
registerBrowserStateCommands(browser, parentOpts);
|
|
||||||
|
|
||||||
await program.parseAsync(["browser", "set", "headers", "--json", '{"x-auth":"ok"}'], {
|
await program.parseAsync(["browser", "set", "headers", "--json", '{"x-auth":"ok"}'], {
|
||||||
from: "user",
|
from: "user",
|
||||||
});
|
});
|
||||||
|
|
||||||
const call = mocks.callBrowserRequest.mock.calls.at(-1);
|
const request = getLastRequest() as { body?: { headers?: Record<string, string> } };
|
||||||
expect(call).toBeDefined();
|
|
||||||
if (!call) {
|
|
||||||
throw new Error("expected browser request call");
|
|
||||||
}
|
|
||||||
const request = call[1] as { body?: { headers?: Record<string, string> } };
|
|
||||||
expect(request.body?.headers).toEqual({ "x-auth": "ok" });
|
expect(request.body?.headers).toEqual({ "x-auth": "ok" });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user