mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-13 22:29:48 +08:00
feat(baoyu-fetch): add X session cookie sidecar and graceful Chrome lifecycle
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.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { shouldAutoContinueForceWait } from "../commands/convert";
|
||||
import { shouldAutoContinueForceWait, shouldKeepBrowserOpenAfterInteraction } from "../commands/convert";
|
||||
|
||||
describe("shouldAutoContinueForceWait", () => {
|
||||
test("continues when a challenge disappears", () => {
|
||||
@@ -9,28 +9,49 @@ describe("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("continues when login state improves from logged out", () => {
|
||||
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);
|
||||
@@ -43,13 +64,42 @@ describe("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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user