@liang-hz/agent-in-chrome 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ext-id.txt +4 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/PRIVACY.md +86 -0
- package/README.en.md +419 -0
- package/README.md +406 -0
- package/bin/agent-in-chrome.mjs +97 -0
- package/commands/agent-in-chrome.md +18 -0
- package/commands/install-agent-in-chrome.md +22 -0
- package/docs/AGENTS.md +94 -0
- package/docs/CLI.md +297 -0
- package/docs/client-compat.json +23 -0
- package/extension/about-toc.js +25 -0
- package/extension/about.html +240 -0
- package/extension/about.js +44 -0
- package/extension/agent-window.html +100 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-24.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/icons/icon-64.png +0 -0
- package/extension/icons/icon-attention-128.png +0 -0
- package/extension/icons/icon-attention-16.png +0 -0
- package/extension/icons/icon-attention-24.png +0 -0
- package/extension/icons/icon-attention-32.png +0 -0
- package/extension/icons/icon-attention-48.png +0 -0
- package/extension/icons/icon-attention-64.png +0 -0
- package/extension/icons/icon-attention.svg +18 -0
- package/extension/icons/icon-failed-128.png +0 -0
- package/extension/icons/icon-failed-16.png +0 -0
- package/extension/icons/icon-failed-24.png +0 -0
- package/extension/icons/icon-failed-32.png +0 -0
- package/extension/icons/icon-failed-48.png +0 -0
- package/extension/icons/icon-failed-64.png +0 -0
- package/extension/icons/icon-failed.svg +18 -0
- package/extension/icons/icon-idle-128.png +0 -0
- package/extension/icons/icon-idle-16.png +0 -0
- package/extension/icons/icon-idle-24.png +0 -0
- package/extension/icons/icon-idle-32.png +0 -0
- package/extension/icons/icon-idle-48.png +0 -0
- package/extension/icons/icon-idle-64.png +0 -0
- package/extension/icons/icon-idle.svg +18 -0
- package/extension/icons/icon-mark.svg +10 -0
- package/extension/icons/icon-running-128.png +0 -0
- package/extension/icons/icon-running-16.png +0 -0
- package/extension/icons/icon-running-24.png +0 -0
- package/extension/icons/icon-running-32.png +0 -0
- package/extension/icons/icon-running-48.png +0 -0
- package/extension/icons/icon-running-64.png +0 -0
- package/extension/icons/icon-running.svg +18 -0
- package/extension/icons/icon.svg +18 -0
- package/extension/manifest.json +44 -0
- package/extension/popup-ui.js +38 -0
- package/extension/popup.html +350 -0
- package/extension/popup.js +741 -0
- package/extension/sw.js +11127 -0
- package/extension/update-check.js +66 -0
- package/extension/welcome.html +110 -0
- package/extension/welcome.js +18 -0
- package/mcp/agent-identity.mjs +1007 -0
- package/mcp/cdp/bridge.mjs +239 -0
- package/mcp/cdp/browser-launch.mjs +1127 -0
- package/mcp/cdp/chrome-shim.mjs +1124 -0
- package/mcp/cdp/client.mjs +443 -0
- package/mcp/cli-invocation.mjs +67 -0
- package/mcp/config.mjs +191 -0
- package/mcp/foreground-guard.mjs +295 -0
- package/mcp/proc-win.mjs +112 -0
- package/mcp/secret-shape.mjs +155 -0
- package/mcp/server.mjs +3437 -0
- package/mcp/session-id.mjs +281 -0
- package/mcp/token.mjs +260 -0
- package/mcp/tool-tiers.mjs +84 -0
- package/mcp/trace.mjs +528 -0
- package/mcp/update-cli.mjs +163 -0
- package/mcp/update-notice.mjs +194 -0
- package/native-host/host.mjs +356 -0
- package/native-host/mac-foreground/aic-fg.swift +114 -0
- package/native-host/mac-foreground/build.mjs +43 -0
- package/package.json +46 -0
- package/scripts/agents.mjs +921 -0
- package/scripts/borrow-login.mjs +935 -0
- package/scripts/cli-browser.mjs +148 -0
- package/scripts/e2e-sweep.mjs +192 -0
- package/scripts/e2e.mjs +3911 -0
- package/scripts/fixture-server.mjs +1419 -0
- package/scripts/guard-publish.mjs +175 -0
- package/scripts/install.mjs +1383 -0
- package/scripts/launcher-provenance.mjs +74 -0
- package/scripts/pack-crx.mjs +82 -0
- package/scripts/pick.mjs +114 -0
- package/scripts/test-agents.mjs +968 -0
- package/scripts/test-borrow.mjs +289 -0
- package/scripts/test-config.mjs +618 -0
- package/scripts/test-e2e-sweep.mjs +251 -0
- package/scripts/test-foreground-guard.mjs +383 -0
- package/scripts/test-identity.mjs +1141 -0
- package/scripts/test-install-skill.mjs +378 -0
- package/scripts/test-protocol.mjs +712 -0
- package/scripts/test-security.mjs +1360 -0
- package/scripts/test-sw.mjs +14526 -0
- package/scripts/test-update.mjs +301 -0
- package/skills/agent-in-chrome/SKILL.md +60 -0
- package/skills/agent-in-chrome/references/actions-and-waits.md +136 -0
- package/skills/agent-in-chrome/references/amap-dir-dropdown.md +66 -0
- package/skills/agent-in-chrome/references/geetest-click-captcha.md +55 -0
- package/skills/agent-in-chrome/references/network-debugging.md +20 -0
- package/skills/agent-in-chrome/references/reading-pages.md +30 -0
- package/skills/agent-in-chrome/references/recovery.md +25 -0
- package/skills/agent-in-chrome/references/tabs-and-sessions.md +34 -0
- package/skills/install-agent-in-chrome/SKILL.md +252 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
parseArgs,
|
|
5
|
+
UsageError,
|
|
6
|
+
normalizeDomain,
|
|
7
|
+
normalizeDomains,
|
|
8
|
+
cookieKey,
|
|
9
|
+
isSessionCookie,
|
|
10
|
+
ledgerRowIsSession,
|
|
11
|
+
pinSessionCookies,
|
|
12
|
+
diffImported,
|
|
13
|
+
whyDropped,
|
|
14
|
+
pruneLedger,
|
|
15
|
+
selectBatches,
|
|
16
|
+
domainMatches,
|
|
17
|
+
emptyLedger,
|
|
18
|
+
formatBorrowReport,
|
|
19
|
+
STORAGE_CAVEAT,
|
|
20
|
+
LEDGER_MAX_BATCHES,
|
|
21
|
+
LEDGER_MAX_ENTRIES,
|
|
22
|
+
} from "./borrow-login.mjs";
|
|
23
|
+
|
|
24
|
+
let passed = 0;
|
|
25
|
+
let failed = 0;
|
|
26
|
+
const check = (name, cond, extra = "") => {
|
|
27
|
+
if (cond) {
|
|
28
|
+
console.log(` \x1b[32m✓\x1b[0m ${name}`);
|
|
29
|
+
passed++;
|
|
30
|
+
} else {
|
|
31
|
+
console.log(` \x1b[31m✗\x1b[0m ${name}${extra ? ` — ${String(extra).slice(0, 200)}` : ""}`);
|
|
32
|
+
failed++;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const section = (s) => console.log(`\n\x1b[1m${s}\x1b[0m`);
|
|
36
|
+
const throws = (fn) => {
|
|
37
|
+
try {
|
|
38
|
+
fn();
|
|
39
|
+
return null;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return e;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
section("域名规范化");
|
|
46
|
+
check("前导点去掉(cookie 域天然带点)", normalizeDomain(".github.com") === "github.com");
|
|
47
|
+
check("大小写归一", normalizeDomain("GitHub.COM") === "github.com");
|
|
48
|
+
check("整条 URL 粘进来也认", normalizeDomain("https://github.com/foo/bar?x=1#y") === "github.com");
|
|
49
|
+
check("端口去掉", normalizeDomain("localhost:8080") === "localhost");
|
|
50
|
+
check("尾点(FQDN 写法)去掉", normalizeDomain("github.com.") === "github.com");
|
|
51
|
+
check("两边空白去掉", normalizeDomain(" github.com ") === "github.com");
|
|
52
|
+
check("单标签域名(localhost)放行", normalizeDomain("localhost") === "localhost");
|
|
53
|
+
check("中文域名转成 punycode", normalizeDomain("中文.com") === "xn--fiq228c.com");
|
|
54
|
+
check("空串不是域名", normalizeDomain("") === null);
|
|
55
|
+
check("只有点不是域名", normalizeDomain("...") === null);
|
|
56
|
+
check("带空格的不是域名", normalizeDomain("a b.com") === null);
|
|
57
|
+
check("通配符不是域名", normalizeDomain("*.github.com") === null);
|
|
58
|
+
{
|
|
59
|
+
const r = normalizeDomains([".GitHub.com", "github.com", "https://news.ycombinator.com/", "呵呵 呵"]);
|
|
60
|
+
check("一批:去重 + 保序", JSON.stringify(r.domains) === JSON.stringify(["github.com", "news.ycombinator.com"]), JSON.stringify(r.domains));
|
|
61
|
+
check("一批:不合法的被点名挑出来", r.invalid.length === 1 && r.invalid[0] === "呵呵 呵");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
section("参数解析");
|
|
65
|
+
{
|
|
66
|
+
const a = parseArgs(["--domains", "github.com,.Example.COM"]);
|
|
67
|
+
check("--domains 逗号分隔 + 规范化", JSON.stringify(a.domains) === JSON.stringify(["github.com", "example.com"]));
|
|
68
|
+
check("默认是借用模式", a.mode === "borrow");
|
|
69
|
+
check("默认不留文件", a.keepFile === false);
|
|
70
|
+
check("默认不 pin 会话 cookie", a.pinSessionHours === null);
|
|
71
|
+
}
|
|
72
|
+
check("--domains=a,b 等号写法", JSON.stringify(parseArgs(["--domains=a.com,b.com"]).domains) === JSON.stringify(["a.com", "b.com"]));
|
|
73
|
+
check("--domains 可以给多次", parseArgs(["--domains", "a.com", "--domains", "b.com"]).domains.length === 2);
|
|
74
|
+
check("--status 进查看模式", parseArgs(["--status"]).mode === "status");
|
|
75
|
+
check("--release 进归还模式", parseArgs(["--release"]).mode === "release");
|
|
76
|
+
check("--release --all", parseArgs(["--release", "--all"]).all === true);
|
|
77
|
+
check("--profile 收下路径", parseArgs(["--status", "--profile", "/tmp/p"]).profile === "/tmp/p");
|
|
78
|
+
check("--pin-session 收下小时数", parseArgs(["--domains", "a.com", "--pin-session", "12"]).pinSessionHours === 12);
|
|
79
|
+
check("-h", parseArgs(["-h"]).help === true);
|
|
80
|
+
|
|
81
|
+
{
|
|
82
|
+
const e = throws(() => parseArgs([]));
|
|
83
|
+
check("不给 --domains 直接报错", e instanceof UsageError, e?.message);
|
|
84
|
+
check("报错说清下一步(举了个例子)", /--domains github\.com/.test(e?.message || ""), e?.message);
|
|
85
|
+
check("报错说清什么都没做", /什么都没做/.test(e?.message || ""));
|
|
86
|
+
}
|
|
87
|
+
check("不认识的参数报错并点名", /--nope/.test(throws(() => parseArgs(["--nope"]))?.message || ""));
|
|
88
|
+
check("--domains 后面没值报错", throws(() => parseArgs(["--domains"])) instanceof UsageError);
|
|
89
|
+
check("--pin-session 要正数", throws(() => parseArgs(["--domains", "a.com", "--pin-session", "0"])) instanceof UsageError);
|
|
90
|
+
check("--pin-session 不收非数字", throws(() => parseArgs(["--domains", "a.com", "--pin-session", "很久"])) instanceof UsageError);
|
|
91
|
+
check("--status 不接受 --domains", throws(() => parseArgs(["--status", "--domains", "a.com"])) instanceof UsageError);
|
|
92
|
+
check("--all 不能脱离 --release", throws(() => parseArgs(["--domains", "a.com", "--all"])) instanceof UsageError);
|
|
93
|
+
check("--wipe 单独给:拒", throws(() => parseArgs(["--release", "--wipe"])) instanceof UsageError);
|
|
94
|
+
check("--wipe 必须配 --release --all", parseArgs(["--release", "--all", "--wipe"]).wipe === true);
|
|
95
|
+
check(
|
|
96
|
+
"--wipe 的报错讲清它会清掉用户自己登的站",
|
|
97
|
+
/你自己手动登录的站点/.test(throws(() => parseArgs(["--release", "--wipe"]))?.message || "")
|
|
98
|
+
);
|
|
99
|
+
check("不合法域名在解析阶段就拦下并点名", /呵呵/.test(throws(() => parseArgs(["--domains", "呵呵 呵"]))?.message || ""));
|
|
100
|
+
|
|
101
|
+
section("cookie 判据");
|
|
102
|
+
check("键 = name+domain+path 的 JSON 元组", cookieKey({ name: "a", domain: ".x.com", path: "/" }) === '["a",".x.com","/"]');
|
|
103
|
+
check("键不会被分隔符撞混", cookieKey({ name: "a", domain: "x", path: '","' }) !== cookieKey({ name: "a", domain: 'x","', path: "" }));
|
|
104
|
+
check("expires:-1 是会话 cookie", isSessionCookie({ name: "a", expires: -1 }) === true);
|
|
105
|
+
check("session:true 是会话 cookie", isSessionCookie({ name: "a", session: true, expires: 123 }) === true);
|
|
106
|
+
check("没有 expires 字段也算会话 cookie", isSessionCookie({ name: "a" }) === true);
|
|
107
|
+
check("带未来 expires 是持久 cookie", isSessionCookie({ name: "a", expires: Date.now() / 1000 + 999 }) === false);
|
|
108
|
+
check("账本行的持久 cookie 不会被误判成会话", ledgerRowIsSession({ name: "p", session: false }) === false);
|
|
109
|
+
check("账本行的会话 cookie 认得出", ledgerRowIsSession({ name: "s", session: true }) === true);
|
|
110
|
+
check("同一条账本行用 isSessionCookie 会误判(所以才要分开)", isSessionCookie({ name: "p", session: false }) === true);
|
|
111
|
+
|
|
112
|
+
check("没种上的理由:SameSite=None 缺 secure", /SameSite=None/.test(whyDropped({ sameSite: "None", secure: false })));
|
|
113
|
+
check("没种上的理由:已过期", /过期/.test(whyDropped({ expires: 1 })));
|
|
114
|
+
check("没种上的理由:兜底说到条数上限", /上限/.test(whyDropped({ name: "x" })));
|
|
115
|
+
|
|
116
|
+
section("--pin-session:把会话 cookie 改写成持久 cookie");
|
|
117
|
+
{
|
|
118
|
+
const now = 1_700_000_000_000;
|
|
119
|
+
const src = [
|
|
120
|
+
{ name: "s", domain: ".x.com", path: "/", value: "1", expires: -1, session: true },
|
|
121
|
+
{ name: "p", domain: ".x.com", path: "/", value: "2", expires: 1_800_000_000 },
|
|
122
|
+
];
|
|
123
|
+
const r = pinSessionCookies(src, 2, now);
|
|
124
|
+
check("会话那条拿到 expires", r.cookies[0].expires === Math.floor(now / 1000) + 7200);
|
|
125
|
+
check("会话那条的 session 标记被摘掉(否则 CDP 那边语义打架)", r.cookies[0].session === undefined);
|
|
126
|
+
check("持久那条一个字没动", JSON.stringify(r.cookies[1]) === JSON.stringify(src[1]));
|
|
127
|
+
check("改了哪几条要点名(报告要用)", r.pinned.length === 1 && r.pinned[0].name === "s");
|
|
128
|
+
check("不给小时数就什么都不改", pinSessionCookies(src, null).pinned.length === 0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
section("导入后的逐字比对(cookies_import 自带那道只看在不在,不看值)");
|
|
132
|
+
{
|
|
133
|
+
const sent = [
|
|
134
|
+
{ name: "sess", domain: ".x.com", path: "/", value: "AAA", httpOnly: true, secure: true },
|
|
135
|
+
{ name: "pref", domain: ".x.com", path: "/", value: "BBB" },
|
|
136
|
+
{ name: "bad", domain: ".x.com", path: "/", value: "CCC", sameSite: "None", secure: false },
|
|
137
|
+
];
|
|
138
|
+
const got = [
|
|
139
|
+
{ name: "sess", domain: ".x.com", path: "/", value: "AAA", httpOnly: true, secure: true, expires: -1 },
|
|
140
|
+
{ name: "pref", domain: ".x.com", path: "/", value: "BBB", expires: -1 },
|
|
141
|
+
];
|
|
142
|
+
const d = diffImported(sent, got);
|
|
143
|
+
check("值一致的算种上了", d.matched.length === 2);
|
|
144
|
+
check("httpOnly 属性保住了才算数", d.matched.some((c) => c.name === "sess"));
|
|
145
|
+
check("没种上的点名 + 给理由", d.missing.length === 1 && /SameSite=None/.test(d.missing[0].why));
|
|
146
|
+
check("没有假的值不一致", d.mismatched.length === 0);
|
|
147
|
+
}
|
|
148
|
+
{
|
|
149
|
+
const sent = [{ name: "sess", domain: ".x.com", path: "/", value: "AAAA", httpOnly: true }];
|
|
150
|
+
const got = [{ name: "sess", domain: ".x.com", path: "/", value: "AAAB", httpOnly: true }];
|
|
151
|
+
const d = diffImported(sent, got);
|
|
152
|
+
check("值差一个字节 → 报 mismatched,不报成功", d.mismatched.length === 1 && d.matched.length === 0);
|
|
153
|
+
check("mismatched 点名是哪个字段", d.mismatched[0].fields.includes("value"));
|
|
154
|
+
}
|
|
155
|
+
{
|
|
156
|
+
const sent = [{ name: "s", domain: ".x.com", path: "/", value: "A", httpOnly: true }];
|
|
157
|
+
const got = [{ name: "s", domain: ".x.com", path: "/", value: "A", httpOnly: false }];
|
|
158
|
+
check("httpOnly 掉了也算不一致", diffImported(sent, got).mismatched[0].fields.includes("httpOnly"));
|
|
159
|
+
}
|
|
160
|
+
{
|
|
161
|
+
const sent = [
|
|
162
|
+
{ name: "a", domain: ".x.com", path: "/", value: "1" },
|
|
163
|
+
{ name: "a", domain: ".x.com", path: "/admin", value: "2" },
|
|
164
|
+
];
|
|
165
|
+
const got = [{ name: "a", domain: ".x.com", path: "/", value: "1" }];
|
|
166
|
+
const d = diffImported(sent, got);
|
|
167
|
+
check("同名不同 path 分得清", d.matched.length === 1 && d.missing.length === 1 && d.missing[0].path === "/admin");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
section("借用账本:只增不减是不允许的");
|
|
171
|
+
const mkBatch = (id, atMs, domains, names) => ({
|
|
172
|
+
id,
|
|
173
|
+
atMs,
|
|
174
|
+
at: new Date(atMs).toISOString(),
|
|
175
|
+
domains,
|
|
176
|
+
cookies: names.map((n) => ({ name: n, domain: `.${domains[0]}`, path: "/" })),
|
|
177
|
+
});
|
|
178
|
+
{
|
|
179
|
+
const led = { version: 1, batches: [mkBatch("b1", 1000, ["x.com"], ["a", "b"]), mkBatch("b2", 2000, ["y.com"], ["c"])] };
|
|
180
|
+
const live = new Set([
|
|
181
|
+
cookieKey({ name: "a", domain: ".x.com", path: "/" }),
|
|
182
|
+
cookieKey({ name: "c", domain: ".y.com", path: "/" }),
|
|
183
|
+
]);
|
|
184
|
+
const r = pruneLedger(led, live);
|
|
185
|
+
check("浏览器里没了的条目被销掉", r.droppedEntries.length === 1 && r.droppedEntries[0].name === "b");
|
|
186
|
+
check("还在的条目留着", r.ledger.batches.reduce((n, b) => n + b.cookies.length, 0) === 2);
|
|
187
|
+
}
|
|
188
|
+
{
|
|
189
|
+
const led = { version: 1, batches: [mkBatch("b1", 1000, ["x.com"], ["a"])] };
|
|
190
|
+
const r = pruneLedger(led, new Set());
|
|
191
|
+
check("整批都没了就把批次也销掉", r.ledger.batches.length === 0 && r.emptiedBatches.includes("b1"));
|
|
192
|
+
}
|
|
193
|
+
{
|
|
194
|
+
const led = { version: 1, batches: [mkBatch("b1", 1000, ["x.com"], ["a"])] };
|
|
195
|
+
const r = pruneLedger(led, null);
|
|
196
|
+
check("liveKeys 给 null 时一条都不动", r.ledger.batches.length === 1 && r.droppedEntries.length === 0);
|
|
197
|
+
}
|
|
198
|
+
{
|
|
199
|
+
const batches = [];
|
|
200
|
+
for (let i = 0; i < LEDGER_MAX_BATCHES + 3; i++) batches.push(mkBatch(`b${i}`, 1000 + i, ["x.com"], [`c${i}`]));
|
|
201
|
+
const r = pruneLedger({ version: 1, batches }, null);
|
|
202
|
+
check("批次数超上限:丢最老的", r.ledger.batches.length === LEDGER_MAX_BATCHES && r.cappedBatches.length === 3);
|
|
203
|
+
check("丢掉的最老那批被报出来(不许静默)", r.cappedBatches[0].id === "b0");
|
|
204
|
+
check("留下的是最新那批", r.ledger.batches[r.ledger.batches.length - 1].id === `b${LEDGER_MAX_BATCHES + 2}`);
|
|
205
|
+
}
|
|
206
|
+
{
|
|
207
|
+
const big = (id, at, n) => mkBatch(id, at, ["x.com"], Array.from({ length: n }, (_, i) => `c${id}-${i}`));
|
|
208
|
+
const r = pruneLedger({ version: 1, batches: [big("b1", 1000, LEDGER_MAX_ENTRIES), big("b2", 2000, 10)] }, null);
|
|
209
|
+
check("条目数超上限也会砍最老的批次", r.cappedBatches.some((b) => b.id === "b1"));
|
|
210
|
+
check("砍完在上限之内", r.ledger.batches.reduce((n, b) => n + b.cookies.length, 0) <= LEDGER_MAX_ENTRIES);
|
|
211
|
+
}
|
|
212
|
+
check("空账本不炸", pruneLedger(emptyLedger(), new Set()).ledger.batches.length === 0);
|
|
213
|
+
check("坏形状(batches 不是数组)当空账本处理", pruneLedger({ batches: "呵呵" }, new Set()).ledger.batches.length === 0);
|
|
214
|
+
|
|
215
|
+
section("归还挑哪些批次");
|
|
216
|
+
{
|
|
217
|
+
const led = {
|
|
218
|
+
version: 1,
|
|
219
|
+
batches: [mkBatch("b1", 1000, ["x.com"], ["a"]), mkBatch("b2", 2000, ["y.com"], ["b"]), mkBatch("b3", 3000, ["z.com"], ["c"])],
|
|
220
|
+
};
|
|
221
|
+
check("默认只还最近一批", selectBatches(led).picked.map((b) => b.id).join() === "b3");
|
|
222
|
+
check("默认剩下的原样留着", selectBatches(led).rest.map((b) => b.id).join() === "b1,b2");
|
|
223
|
+
check("--all 全还", selectBatches(led, { all: true }).picked.length === 3);
|
|
224
|
+
const byDomain = selectBatches(led, { domains: ["y.com"] });
|
|
225
|
+
check("按域挑:只挑中那一批", byDomain.picked.length === 1 && byDomain.picked[0].id === "b2");
|
|
226
|
+
check("按域挑:其余留在 rest 里", byDomain.rest.length === 2);
|
|
227
|
+
}
|
|
228
|
+
{
|
|
229
|
+
const led = { version: 1, batches: [{ id: "b", atMs: 1, domains: ["x.com"], cookies: [
|
|
230
|
+
{ name: "a", domain: "api.x.com", path: "/" },
|
|
231
|
+
{ name: "b", domain: ".other.com", path: "/" },
|
|
232
|
+
] }] };
|
|
233
|
+
const r = selectBatches(led, { domains: ["x.com"] });
|
|
234
|
+
check("子域的 cookie 也挑得中", r.picked[0].cookies.length === 1 && r.picked[0].cookies[0].domain === "api.x.com");
|
|
235
|
+
check("同一批里不匹配的留在 rest(不会被顺手删掉)", r.rest[0].cookies[0].name === "b");
|
|
236
|
+
}
|
|
237
|
+
check("域匹配认子域", domainMatches("api.x.com", new Set(["x.com"])) === true);
|
|
238
|
+
check("域匹配认前导点", domainMatches(".x.com", new Set(["x.com"])) === true);
|
|
239
|
+
check("域匹配不认后缀碰瓷(notx.com)", domainMatches("notx.com", new Set(["x.com"])) === false);
|
|
240
|
+
|
|
241
|
+
section("报告:该说的必须说到");
|
|
242
|
+
{
|
|
243
|
+
const sent = [
|
|
244
|
+
{ name: "s", domain: ".x.com", path: "/", value: "A", expires: -1 },
|
|
245
|
+
{ name: "p", domain: ".x.com", path: "/", value: "B", expires: 9_999_999_999 },
|
|
246
|
+
{ name: "bad", domain: ".x.com", path: "/", value: "C", sameSite: "None", secure: false },
|
|
247
|
+
];
|
|
248
|
+
const got = [
|
|
249
|
+
{ name: "s", domain: ".x.com", path: "/", value: "A", expires: -1 },
|
|
250
|
+
{ name: "p", domain: ".x.com", path: "/", value: "B", expires: 9_999_999_999 },
|
|
251
|
+
];
|
|
252
|
+
const text = formatBorrowReport({
|
|
253
|
+
domains: ["x.com"],
|
|
254
|
+
sent,
|
|
255
|
+
diff: diffImported(sent, got),
|
|
256
|
+
importReported: { requested: 3, imported: 2 },
|
|
257
|
+
pinned: [],
|
|
258
|
+
profileDir: "/tmp/prof",
|
|
259
|
+
browser: { pid: 123, version: "Chrome/151" },
|
|
260
|
+
ledgerNote: null,
|
|
261
|
+
}).join("\n");
|
|
262
|
+
check("报出种上几条", /种上并逐字校验通过:2 条/.test(text), text);
|
|
263
|
+
check("没种上的点名 + 理由", /bad @ \.x\.com\/ —— SameSite=None/.test(text), text);
|
|
264
|
+
check("说清数字是自己读回来的,不是照抄工具返回值", /不是照抄它/.test(text));
|
|
265
|
+
check("会话 / 持久各几条:只算真的种上的", /只算真的种上了的那 2 条):1 条是\*\*会话 cookie\*\*,1 条是持久 cookie/.test(text), text);
|
|
266
|
+
check("点明会话 cookie 活不过重启", /一重启就没了|重启就没了/.test(text), text);
|
|
267
|
+
check("点明持久 cookie 要靠优雅退出", /优雅退出/.test(text));
|
|
268
|
+
check("给出 --pin-session 这条出路(并说明代价)", /--pin-session/.test(text) && /延长了凭据寿命/.test(text));
|
|
269
|
+
check("localStorage / IndexedDB 那条边界必须在", text.includes(STORAGE_CAVEAT));
|
|
270
|
+
check("告诉用户浏览器还开着 + 怎么用 / 怎么还 / 怎么收", /pid=123/.test(text) && /--release/.test(text) && /--stop/.test(text));
|
|
271
|
+
}
|
|
272
|
+
{
|
|
273
|
+
const sent = [{ name: "s", domain: ".x.com", path: "/", value: "A" }];
|
|
274
|
+
const got = [{ name: "s", domain: ".x.com", path: "/", value: "B" }];
|
|
275
|
+
const text = formatBorrowReport({
|
|
276
|
+
domains: ["x.com"],
|
|
277
|
+
sent,
|
|
278
|
+
diff: diffImported(sent, got),
|
|
279
|
+
importReported: { requested: 1, imported: 1 },
|
|
280
|
+
pinned: [],
|
|
281
|
+
profileDir: "/tmp/prof",
|
|
282
|
+
browser: null,
|
|
283
|
+
ledgerNote: null,
|
|
284
|
+
}).join("\n");
|
|
285
|
+
check("值对不上时报警,且不说成功", /值对不上:1 条/.test(text) && /别拿它当能用的登录态/.test(text), text);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
console.log(`\n${failed ? "\x1b[31m" : "\x1b[32m"}${passed} 通过,${failed} 失败\x1b[0m\n`);
|
|
289
|
+
process.exit(failed ? 1 : 0);
|