mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-10 13:11:30 +00:00
6afcfa80cc
Add cookie sidecar to export/restore X session cookies across runs. Implement graceful Browser.close via WebSocket before falling back to kill. Auto-detect and clean stale Chrome profile lock artifacts on launch failure. Wait for X session readiness (auth_token + ct0) before auto-continuing login flows.
106 lines
2.7 KiB
TypeScript
106 lines
2.7 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { shouldAutoContinueForceWait, shouldKeepBrowserOpenAfterInteraction } from "../commands/convert";
|
|
|
|
describe("shouldAutoContinueForceWait", () => {
|
|
test("continues when a challenge disappears", () => {
|
|
expect(
|
|
shouldAutoContinueForceWait(
|
|
{
|
|
url: "https://example.com/challenge",
|
|
hasGate: true,
|
|
loginState: "unknown",
|
|
sessionReady: true,
|
|
},
|
|
{
|
|
url: "https://example.com/article",
|
|
hasGate: false,
|
|
loginState: "unknown",
|
|
sessionReady: true,
|
|
},
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
test("waits for X session cookies before continuing after login", () => {
|
|
expect(
|
|
shouldAutoContinueForceWait(
|
|
{
|
|
url: "https://x.com/i/flow/login",
|
|
hasGate: false,
|
|
loginState: "logged_out",
|
|
sessionReady: false,
|
|
},
|
|
{
|
|
url: "https://x.com/home",
|
|
hasGate: false,
|
|
loginState: "logged_in",
|
|
sessionReady: false,
|
|
},
|
|
),
|
|
).toBe(false);
|
|
|
|
expect(
|
|
shouldAutoContinueForceWait(
|
|
{
|
|
url: "https://x.com/i/flow/login",
|
|
hasGate: false,
|
|
loginState: "logged_out",
|
|
sessionReady: false,
|
|
},
|
|
{
|
|
url: "https://x.com/home",
|
|
hasGate: false,
|
|
loginState: "logged_in",
|
|
sessionReady: true,
|
|
},
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
test("does not continue when nothing changed yet", () => {
|
|
expect(
|
|
shouldAutoContinueForceWait(
|
|
{
|
|
url: "https://x.com/lennysan/status/2036483059407810640",
|
|
hasGate: false,
|
|
loginState: "unknown",
|
|
sessionReady: false,
|
|
},
|
|
{
|
|
url: "https://x.com/lennysan/status/2036483059407810640",
|
|
hasGate: false,
|
|
loginState: "unknown",
|
|
sessionReady: false,
|
|
},
|
|
),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("shouldKeepBrowserOpenAfterInteraction", () => {
|
|
test("keeps launched X login browsers open", () => {
|
|
expect(
|
|
shouldKeepBrowserOpenAfterInteraction({
|
|
launched: true,
|
|
interaction: { kind: "login", provider: "x" },
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
test("does not keep reused or non-login browsers open", () => {
|
|
expect(
|
|
shouldKeepBrowserOpenAfterInteraction({
|
|
launched: false,
|
|
interaction: { kind: "login", provider: "x" },
|
|
}),
|
|
).toBe(false);
|
|
|
|
expect(
|
|
shouldKeepBrowserOpenAfterInteraction({
|
|
launched: true,
|
|
interaction: { kind: "cloudflare", provider: "cloudflare" },
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|