@danceiny/gotry 0.0.1-rc.21 → 0.0.1-rc.24
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/README.md +102 -194
- package/README.zh-CN.md +115 -210
- package/bin/gotry-backend.js +53 -0
- package/bin/gotry-bootstrap.js +466 -35
- package/bin/gotry-inner.js +255 -36
- package/bin/gotry-process-liveness.d.ts +27 -0
- package/bin/gotry-process-liveness.js +97 -0
- package/bin/gotry-runtime-resolution.d.ts +1 -1
- package/bin/gotry-runtime-resolution.js +2 -2
- package/client/client.js +174 -0
- package/cordis.gotry-patch.yml +70 -93
- package/dist/capabilities/agent-reach-deep.js +45 -122
- package/dist/capabilities/agent-reach.js +63 -148
- package/dist/capabilities/anything.js +89 -75
- package/dist/capabilities/artifacts.js +123 -104
- package/dist/capabilities/channel-health.js +65 -45
- package/dist/capabilities/channel-registry.js +108 -87
- package/dist/capabilities/doctor.js +357 -235
- package/dist/capabilities/effect.js +223 -309
- package/dist/capabilities/fact-log.js +28 -14
- package/dist/capabilities/flyai.js +245 -156
- package/dist/capabilities/ground-transfer.js +509 -0
- package/dist/capabilities/hbcli.js +144 -148
- package/dist/capabilities/hotelbyte-transaction.js +194 -0
- package/dist/capabilities/incident-log.js +131 -61
- package/dist/capabilities/model-override.js +30 -10
- package/dist/capabilities/opensky.js +54 -43
- package/dist/capabilities/resilience.js +50 -32
- package/dist/capabilities/session/action-cache.js +50 -44
- package/dist/capabilities/session/adapters/ctrip-flight.js +119 -62
- package/dist/capabilities/session/adapters/ctrip-hotel.js +125 -110
- package/dist/capabilities/session/adapters/dida-portal.js +206 -0
- package/dist/capabilities/session/adapters/meituan-local.js +35 -54
- package/dist/capabilities/session/adapters/rail-12306.js +169 -112
- package/dist/capabilities/session/benchmark.js +85 -149
- package/dist/capabilities/session/extension-bridge.js +320 -259
- package/dist/capabilities/session/extension-channel.js +57 -76
- package/dist/capabilities/session/extension-distribution.js +115 -119
- package/dist/capabilities/session/extract.js +31 -21
- package/dist/capabilities/session/golden-score.js +55 -33
- package/dist/capabilities/session/health-watch.js +146 -154
- package/dist/capabilities/session/read-guard.js +55 -47
- package/dist/capabilities/session/static-flight-golden.js +49 -36
- package/dist/capabilities/session/transport.js +54 -61
- package/dist/capabilities/session/wizard.js +63 -93
- package/dist/capabilities/session-consent.js +143 -47
- package/dist/capabilities/session-login.js +95 -126
- package/dist/capabilities/session-search.js +391 -253
- package/dist/capabilities/sponsor-plugin.js +341 -0
- package/dist/capabilities/visa-policy.js +87 -73
- package/dist/capabilities/weather.js +163 -235
- package/dist/scripts/action-cache-tests.js +24 -59
- package/dist/scripts/agent-planning-turn-deadline-e2e.js +91 -142
- package/dist/scripts/agent-planning-turn-deadline-tests.js +80 -176
- package/dist/scripts/agent-reach-deep-tests.js +30 -40
- package/dist/scripts/agent-reach-tests.js +26 -18
- package/dist/scripts/agent-reach-wrapper-tests.js +46 -50
- package/dist/scripts/anything-tests.js +58 -62
- package/dist/scripts/artifact-client-contract-tests.js +69 -0
- package/dist/scripts/artifacts-capability-tests.js +235 -0
- package/dist/scripts/async-collect.js +26 -15
- package/dist/scripts/benchmark-environment-bridge-e2e.js +287 -684
- package/dist/scripts/benchmark-environment-bridge-tests.js +818 -3123
- package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +66 -279
- package/dist/scripts/booking-copilot-availability-policy-tests.js +153 -1257
- package/dist/scripts/booking-copilot-bin-proof-tests.js +22 -45
- package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +64 -76
- package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +69 -199
- package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +393 -759
- package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +33 -75
- package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +60 -110
- package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +28 -66
- package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +72 -271
- package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +73 -275
- package/dist/scripts/booking-copilot-runtime-proof-tests.js +784 -3398
- package/dist/scripts/booking-copilot-server-proof-tests.js +63 -168
- package/dist/scripts/booking-copilot-startup-proof-tests.js +38 -124
- package/dist/scripts/booking-executor-tests.js +80 -0
- package/dist/scripts/booking-recovery-chain-tests.js +182 -0
- package/dist/scripts/booking-saga-tests.js +61 -123
- package/dist/scripts/booking-surface-contract-proof-tests.js +152 -1167
- package/dist/scripts/bootstrap-tests.js +1383 -128
- package/dist/scripts/build-changelog.js +89 -130
- package/dist/scripts/build-metrics-report.js +135 -143
- package/dist/scripts/changelog-tests.js +35 -82
- package/dist/scripts/channel-probe-tests.js +44 -116
- package/dist/scripts/channel-probe.js +84 -167
- package/dist/scripts/channel-registry-tests.js +97 -185
- package/dist/scripts/companion-tests.js +25 -70
- package/dist/scripts/dida-cookie-probe.js +87 -0
- package/dist/scripts/dida-sw-probe.js +114 -0
- package/dist/scripts/diff-test.js +17 -12
- package/dist/scripts/doctor-tests.js +428 -120
- package/dist/scripts/dsh-artifact-e2e.js +150 -0
- package/dist/scripts/dsh-artifact-web-e2e.js +443 -0
- package/dist/scripts/dsh-http-proxy-sse-proof.js +90 -0
- package/dist/scripts/dsh-runtime-closure-tests.js +110 -153
- package/dist/scripts/dsh-runtime-closure.js +75 -63
- package/dist/scripts/dsh-session-v3-migration-proof.js +106 -0
- package/dist/scripts/dsh-subprocess-local-proof.js +149 -0
- package/dist/scripts/dsh-target-closure-proof.js +178 -0
- package/dist/scripts/effect-tests.js +165 -552
- package/dist/scripts/engine-run.js +1 -3
- package/dist/scripts/engine-tests.js +16 -10
- package/dist/scripts/evaluation-cadence-tests.js +69 -242
- package/dist/scripts/evaluation-contract-tests.js +193 -499
- package/dist/scripts/extension-distribution-cli.js +19 -15
- package/dist/scripts/extension-distribution-tests.js +98 -211
- package/dist/scripts/extension-tests.js +366 -389
- package/dist/scripts/fact-gate-tests.js +725 -263
- package/dist/scripts/fixtures/extension-bridge-unref-child.mjs +21 -0
- package/dist/scripts/flight-hotel-anchor-363-registered-e2e.js +169 -0
- package/dist/scripts/flight-malformed-tests.js +159 -0
- package/dist/scripts/flyai-tests.js +325 -68
- package/dist/scripts/g5-guard-tests.js +131 -0
- package/dist/scripts/g5-guard.js +189 -0
- package/dist/scripts/gen-lunar-anchors.js +106 -0
- package/dist/scripts/gotry-backend-kernel-tests.js +79 -0
- package/dist/scripts/ground-transfer-tests.js +956 -0
- package/dist/scripts/hbcli-e2e-tests.js +71 -90
- package/dist/scripts/hbcli-live-optin-tests.js +96 -0
- package/dist/scripts/hbcli-release-contract-tests.js +122 -0
- package/dist/scripts/hbcli-tests.js +41 -115
- package/dist/scripts/health-watch-cli.js +42 -28
- package/dist/scripts/hotel-date-gate-tests.js +496 -0
- package/dist/scripts/hotelbyte-reconcile-tests.js +141 -0
- package/dist/scripts/hotelbyte-spawn-e2e-tests.js +373 -0
- package/dist/scripts/i18n-tests.js +16 -9
- package/dist/scripts/incident-tests.js +281 -87
- package/dist/scripts/issue-194-job-id-guard-tests.js +106 -0
- package/dist/scripts/issue-233-cancel-refund-commission-tests.js +392 -0
- package/dist/scripts/issue-271-liveness-tests.js +547 -0
- package/dist/scripts/issue-289-model-retry-real-tests.js +296 -0
- package/dist/scripts/issue-289-model-retry-tests.js +441 -0
- package/dist/scripts/issue-289-web-retry-e2e.js +630 -0
- package/dist/scripts/issue-338-home-city-e2e.js +577 -0
- package/dist/scripts/issue343-real-entry-e2e.js +160 -0
- package/dist/scripts/journey-tests.js +22 -27
- package/dist/scripts/kernel-manifest-evidence.js +109 -0
- package/dist/scripts/kernel-manifest-gate.js +126 -0
- package/dist/scripts/kernel-manifest-tests.js +212 -0
- package/dist/scripts/kernel-manifest-trace-entry.js +7 -0
- package/dist/scripts/kernel-manifest-trace-hook.mjs +28 -0
- package/dist/scripts/kernel-manifest.js +369 -0
- package/dist/scripts/ledger-repair-apply-tests.js +316 -0
- package/dist/scripts/ledger-repair-plan-tests.js +375 -0
- package/dist/scripts/ledger-tests.js +325 -340
- package/dist/scripts/ledger-workflow-crash.js +10 -20
- package/dist/scripts/map-tools-vendor-package-proof.js +206 -134
- package/dist/scripts/memory-capture-tests.js +242 -61
- package/dist/scripts/memory-decay-tests.js +18 -52
- package/dist/scripts/memory-lifecycle-tests.js +657 -0
- package/dist/scripts/memory-lifecycle.js +196 -0
- package/dist/scripts/memory-metrics.js +24 -12
- package/dist/scripts/memory-value-report.js +474 -222
- package/dist/scripts/memory-value-tests.js +328 -0
- package/dist/scripts/metrics-report-tests.js +62 -199
- package/dist/scripts/model-override-e2e.js +66 -105
- package/dist/scripts/nightly-evidence-tests.js +64 -89
- package/dist/scripts/nightly-evidence.js +108 -111
- package/dist/scripts/nudge-digest.js +39 -28
- package/dist/scripts/onboarding-tests.js +63 -88
- package/dist/scripts/opensky-check.js +18 -13
- package/dist/scripts/opensky-tests.js +28 -28
- package/dist/scripts/persona-surface-guard-tests.js +37 -12
- package/dist/scripts/pnpm-dsh-closure-proof.js +2 -5
- package/dist/scripts/policy-anchor-359-registered-e2e.js +214 -0
- package/dist/scripts/price-drift-tests.js +126 -227
- package/dist/scripts/price-drift-watch.js +209 -253
- package/dist/scripts/probe-poi-tests.js +52 -45
- package/dist/scripts/product-metrics.js +187 -273
- package/dist/scripts/publish-preverify.js +47 -41
- package/dist/scripts/realtime-pricing-tests.js +37 -76
- package/dist/scripts/replay-async.js +20 -18
- package/dist/scripts/replay-real.js +16 -18
- package/dist/scripts/replay.js +52 -82
- package/dist/scripts/session-attach-diagnose.js +16 -12
- package/dist/scripts/session-attach-poc.js +34 -37
- package/dist/scripts/session-benchmark.js +66 -147
- package/dist/scripts/session-dida-live-e2e.js +151 -0
- package/dist/scripts/session-extract-tests.js +14 -35
- package/dist/scripts/session-login.js +14 -13
- package/dist/scripts/session-tests.js +545 -583
- package/dist/scripts/sf-live-benchmark.js +92 -110
- package/dist/scripts/sf-live-cli-tests.js +2 -9
- package/dist/scripts/sf-soft-score-tests.js +19 -60
- package/dist/scripts/sf-summary-tests.js +149 -0
- package/dist/scripts/sf-summary.js +466 -84
- package/dist/scripts/skeleton-check.js +16 -14
- package/dist/scripts/skeleton-integration-test.js +11 -10
- package/dist/scripts/skills-contract-tests.js +51 -46
- package/dist/scripts/smoke-session-gate-tests.js +12 -20
- package/dist/scripts/smoke.js +541 -422
- package/dist/scripts/sponsor-reuse-tests.js +262 -0
- package/dist/scripts/state-cli-tests.js +226 -101
- package/dist/scripts/state-cli.js +549 -212
- package/dist/scripts/static-golden-tests.js +46 -180
- package/dist/scripts/time-eval-tests.js +210 -192
- package/dist/scripts/travel-timeline-tests.js +29 -93
- package/dist/scripts/turn-handoff-collect-tests.js +46 -93
- package/dist/scripts/turn-handoff-collect.js +71 -99
- package/dist/scripts/turn-policy-tests.js +28 -29
- package/dist/scripts/typed-contract-canary.js +77 -162
- package/dist/scripts/tz-resolver-sanity.js +50 -0
- package/dist/scripts/tz-resolver-tests.js +584 -0
- package/dist/scripts/unified-tests.js +23 -19
- package/dist/scripts/visa-policy-tests.js +31 -44
- package/dist/scripts/weather-tests.js +121 -543
- package/dist/scripts/wish-channel-gate-tests.js +29 -86
- package/dist/scripts/write-gate-tests.js +522 -0
- package/dist/scripts/z3-lifecycle-fault-tests.js +188 -0
- package/dist/scripts/z3-lifecycle-tests.js +170 -0
- package/dist/scripts/z3-race-repeat-tests.js +39 -0
- package/dist/scripts/z3-race-tests.js +18 -12
- package/dist/src/artifact-gate.js +652 -221
- package/dist/src/backend/kernel.js +91 -0
- package/dist/src/backend/modules/booking-copilot.js +55 -0
- package/dist/src/backend/modules/booking-executor.js +124 -0
- package/dist/src/backend/modules/session-search.js +194 -0
- package/dist/src/benchmark-agent-conformance.js +296 -262
- package/dist/src/benchmark-environment-bridge.js +298 -413
- package/dist/src/benchmark-headless-child-diagnostics.js +93 -100
- package/dist/src/benchmark-tool-isolation.js +94 -67
- package/dist/src/bookable-facts.js +299 -174
- package/dist/src/booking-saga.js +64 -120
- package/dist/src/booking-surface/availability-policy.js +443 -576
- package/dist/src/booking-surface/cancel-refund-commission.js +379 -0
- package/dist/src/booking-surface/contracts.js +24 -80
- package/dist/src/booking-surface/dsh-planner.js +510 -281
- package/dist/src/booking-surface/dsh-plugin.js +17 -1
- package/dist/src/booking-surface/error-codes.js +82 -10
- package/dist/src/booking-surface/index.js +0 -3
- package/dist/src/booking-surface/profile.js +10 -54
- package/dist/src/booking-surface/recovery-chain.js +367 -0
- package/dist/src/booking-surface/runtime.js +765 -891
- package/dist/src/booking-surface/server.js +200 -251
- package/dist/src/booking-surface/startup.js +58 -54
- package/dist/src/booking-surface/validation.js +150 -218
- package/dist/src/bridge.js +20 -13
- package/dist/src/companions.js +48 -74
- package/dist/src/contracts.js +21 -43
- package/dist/src/dsh-llm.js +82 -120
- package/dist/src/engine.js +253 -239
- package/dist/src/evaluation-cadence.js +72 -209
- package/dist/src/evaluation-contracts.js +220 -843
- package/dist/src/flight-pack-adapter.js +54 -0
- package/dist/src/flight-pack-contract.js +2 -0
- package/dist/src/gotry-backend.js +70 -0
- package/dist/src/hotel-date-gate.js +118 -0
- package/dist/src/i18n.js +18 -7
- package/dist/src/index.js +1425 -1629
- package/dist/src/journey.js +132 -81
- package/dist/src/ledger-repair-apply.js +538 -0
- package/dist/src/ledger-repair-plan.js +463 -0
- package/dist/src/loop.js +257 -166
- package/dist/src/memory-capture.js +180 -32
- package/dist/src/memory-decay.js +30 -14
- package/dist/src/memory-lifecycle.js +1310 -0
- package/dist/src/memory-utility.js +27 -40
- package/dist/src/mock-llm.js +36 -61
- package/dist/src/model.js +81 -36
- package/dist/src/realtime-pricing.js +63 -72
- package/dist/src/slot-spec.js +84 -106
- package/dist/src/state-ledger.js +310 -471
- package/dist/src/subagent-job-id-guard.js +58 -0
- package/dist/src/time-anchor.js +231 -33
- package/dist/src/tool-packet.js +20 -8
- package/dist/src/travel-slots.js +58 -35
- package/dist/src/travel-timeline.js +44 -63
- package/dist/src/turn-deadline.js +121 -127
- package/dist/src/turn-policy.js +61 -89
- package/dist/src/tz-resolver.js +143 -0
- package/dist/src/unified.js +504 -381
- package/dist/src/wish-pool.js +39 -14
- package/dist/src/write-gate.js +495 -0
- package/dist/src/z3-shared.js +273 -7
- package/extension/README.md +4 -3
- package/extension/background.js +125 -14
- package/extension/content-bridge.js +23 -1
- package/extension/content-main.js +15 -4
- package/extension/manifest.json +16 -8
- package/package.json +251 -220
- package/ts/capabilities/agent-reach.ts +4 -4
- package/ts/capabilities/anything.ts +1 -1
- package/ts/capabilities/artifacts.ts +46 -9
- package/ts/capabilities/flyai.ts +156 -37
- package/ts/capabilities/hbcli.ts +1 -1
- package/ts/capabilities/incident-log.ts +88 -59
- package/ts/capabilities/session/adapters/ctrip-flight.ts +99 -36
- package/ts/capabilities/session/adapters/dida-portal.ts +250 -0
- package/ts/capabilities/session/adapters/rail-12306.ts +123 -24
- package/ts/capabilities/session/extension-bridge.ts +226 -101
- package/ts/capabilities/session/extension-channel.ts +22 -9
- package/ts/capabilities/session/wizard.ts +2 -2
- package/ts/capabilities/session-consent.ts +98 -14
- package/ts/capabilities/session-login.ts +1 -0
- package/ts/capabilities/session-search.ts +315 -31
- package/ts/dsh-runtime/vendor/README.md +8 -4
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.en.md +7 -1
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.md +5 -3
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/settings-ns.js +1 -1
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/settings-ns.d.ts +1 -1
- package/ts/dsh-runtime/vendor/dsh-map-tools/package.json +6 -6
- package/ts/package.json +236 -16
- package/ts/scripts/map-tools-vendor-package-proof.ts +152 -31
- package/ts/scripts/state-cli.ts +418 -51
- package/ts/src/artifact-gate.ts +561 -15
- package/ts/src/benchmark-environment-bridge.ts +37 -20
- package/ts/src/bookable-facts.ts +183 -7
- package/ts/src/booking-surface/cancel-refund-commission.ts +488 -0
- package/ts/src/booking-surface/dsh-planner.ts +240 -32
- package/ts/src/booking-surface/dsh-plugin.js +17 -1
- package/ts/src/booking-surface/error-codes.ts +75 -0
- package/ts/src/booking-surface/recovery-chain.ts +409 -0
- package/ts/src/booking-surface/server.ts +84 -51
- package/ts/src/booking-surface/validation.ts +2 -0
- package/ts/src/contracts.ts +12 -2
- package/ts/src/dsh-llm.ts +4 -8
- package/ts/src/index.ts +609 -90
- package/ts/src/loop.ts +116 -7
- package/ts/src/memory-capture.ts +227 -3
- package/ts/src/mock-llm.ts +4 -8
- package/ts/src/model.ts +88 -2
- package/ts/src/state-ledger.ts +47 -29
- package/ts/src/subagent-job-id-guard.ts +72 -0
- package/ts/src/time-anchor.ts +217 -13
- package/ts/src/unified.ts +316 -54
|
@@ -1,65 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P0 PoC(RFC docs/rfc/user-session-data-rfc.md §4 P0-③):
|
|
3
|
+
* 专用测试 profile 打开携程机票 URL 参数搜索页,嗅探站内搜索 XHR 并打印 JSON。
|
|
4
|
+
* 只读:无 click/fill/submit;不进 CI;不动共享状态(profile 在 /tmp)。
|
|
5
|
+
* 运行:npx tsx scripts/session-attach-poc.ts [from-to] [YYYY-MM-DD]
|
|
6
|
+
*/
|
|
1
7
|
import { chromium } from "playwright-core";
|
|
2
|
-
const route = process.argv[2] ?? "sha-ljg";
|
|
8
|
+
const route = process.argv[2] ?? "sha-ljg"; // 上海→丽江(IATA 三字码小写)
|
|
3
9
|
const date = process.argv[3] ?? "2026-10-01";
|
|
4
10
|
const url = `https://flights.ctrip.com/online/list/oneway-${route}?depdate=${date}`;
|
|
5
|
-
const PROFILE = "/tmp/gotry-session-poc-profile";
|
|
11
|
+
const PROFILE = "/tmp/gotry-session-poc-profile"; // 专用测试 profile,绝不动日常浏览器
|
|
6
12
|
async function main() {
|
|
7
13
|
const ctx = await chromium.launchPersistentContext(PROFILE, {
|
|
8
|
-
channel: "chrome",
|
|
9
|
-
headless: false,
|
|
10
|
-
viewport: {
|
|
11
|
-
|
|
12
|
-
height: 900
|
|
13
|
-
},
|
|
14
|
-
args: [
|
|
15
|
-
"--disable-blink-features=AutomationControlled"
|
|
16
|
-
]
|
|
14
|
+
channel: "chrome", // 用本机已装 Chrome,不下载浏览器
|
|
15
|
+
headless: false, // 可见窗口:人能看到 agent 在干什么(心智红线)
|
|
16
|
+
viewport: { width: 1440, height: 900 },
|
|
17
|
+
args: ["--disable-blink-features=AutomationControlled"],
|
|
17
18
|
});
|
|
18
|
-
const page = ctx.pages()[0] ?? await ctx.newPage();
|
|
19
|
+
const page = ctx.pages()[0] ?? (await ctx.newPage());
|
|
19
20
|
const hits = [];
|
|
20
|
-
const cap = (s)=>s.replace(/\s+/g, " ").slice(0, 600);
|
|
21
|
-
ctx.on("response", async (res)=>{
|
|
21
|
+
const cap = (s) => s.replace(/\s+/g, " ").slice(0, 600);
|
|
22
|
+
ctx.on("response", async (res) => {
|
|
22
23
|
const u = res.url();
|
|
23
24
|
const ct = res.headers()["content-type"] ?? "";
|
|
24
|
-
if (!ct.includes("json") || u.length > 400)
|
|
25
|
-
|
|
25
|
+
if (!ct.includes("json") || u.length > 400)
|
|
26
|
+
return;
|
|
27
|
+
// 只关心搜索/班期相关接口,过滤埋点与配置
|
|
28
|
+
if (!/search|list|flight|itinerary|poll/i.test(u))
|
|
29
|
+
return;
|
|
26
30
|
try {
|
|
27
31
|
const body = await res.text();
|
|
28
|
-
if (body.length < 200)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bytes: body.length
|
|
32
|
-
});
|
|
32
|
+
if (body.length < 200)
|
|
33
|
+
return; // 空壳响应不记
|
|
34
|
+
hits.push({ url: u, bytes: body.length });
|
|
33
35
|
if (hits.length <= 3) {
|
|
34
36
|
console.log(`\n[HIT ${hits.length}] ${res.status()} ${cap(u)}\n body(${body.length}B): ${cap(body)}`);
|
|
35
37
|
}
|
|
36
|
-
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
/* 响应体不可读(流式/竞态)则跳过 */
|
|
41
|
+
}
|
|
37
42
|
});
|
|
38
43
|
console.log(`goto ${url}`);
|
|
39
|
-
await page.goto(url, {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
await page.waitForTimeout(15_000);
|
|
44
|
-
const title = await page.title().catch(()=>"");
|
|
44
|
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000 });
|
|
45
|
+
await page.waitForTimeout(15_000); // 等首屏搜索接口回包
|
|
46
|
+
const title = await page.title().catch(() => "");
|
|
45
47
|
console.log(`\ntitle: ${cap(title)}`);
|
|
46
|
-
const html = await page.content().catch(()=>"");
|
|
48
|
+
const html = await page.content().catch(() => "");
|
|
47
49
|
const challenged = /验证|滑块|captcha|verify/i.test(title + html.slice(0, 5000));
|
|
48
50
|
console.log(`challenge-detected: ${challenged}`);
|
|
49
|
-
console.log(`\nsummary: ${hits.length} 条搜索类 JSON XHR;总命中 ${hits.reduce((a, b)=>a + b.bytes, 0)}B`);
|
|
51
|
+
console.log(`\nsummary: ${hits.length} 条搜索类 JSON XHR;总命中 ${hits.reduce((a, b) => a + b.bytes, 0)}B`);
|
|
50
52
|
console.log("按体积 top5(P1 适配器要嗅探的接口面):");
|
|
51
|
-
for (const h of [
|
|
52
|
-
...hits
|
|
53
|
-
].sort((a, b)=>b.bytes - a.bytes).slice(0, 5)){
|
|
53
|
+
for (const h of [...hits].sort((a, b) => b.bytes - a.bytes).slice(0, 5)) {
|
|
54
54
|
console.log(` ${h.bytes}B ${cap(h.url)}`);
|
|
55
55
|
}
|
|
56
56
|
console.log(challenged ? "结论:触发风控——按红线不重试不绕过,如实记录" : "结论:嗅探链路成立(只读,零交互)");
|
|
57
57
|
await ctx.close();
|
|
58
58
|
}
|
|
59
|
-
main().catch((e)=>{
|
|
59
|
+
main().catch((e) => {
|
|
60
60
|
console.error("PoC 失败:", e instanceof Error ? e.message : e);
|
|
61
61
|
process.exit(1);
|
|
62
62
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//# sourceURL=ts/scripts/session-attach-poc.ts
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #21 首切片的确定性验收:字段级 fixture scorer、双源合同与 waiting gate。
|
|
3
|
+
*
|
|
4
|
+
* 只构造脱敏内存 fixture;不访问网络、Chrome、登录态或共享产品状态。
|
|
5
|
+
*/
|
|
1
6
|
import assert from 'node:assert/strict';
|
|
2
|
-
import { evaluateDoubleSource, scoreSessionFixture } from '../capabilities/session/benchmark.js';
|
|
7
|
+
import { evaluateDoubleSource, scoreSessionFixture, } from '../capabilities/session/benchmark.js';
|
|
3
8
|
import { parseFlyaiItemList } from '../capabilities/flyai.js';
|
|
4
9
|
import { classifyTransportFailure } from '../capabilities/session-search.js';
|
|
5
10
|
let passed = 0;
|
|
@@ -10,15 +15,13 @@ function check(label, assertion) {
|
|
|
10
15
|
}
|
|
11
16
|
const sessionFixture = {
|
|
12
17
|
query_id: 'sf-01',
|
|
13
|
-
route_segments: [
|
|
14
|
-
{
|
|
18
|
+
route_segments: [{
|
|
15
19
|
from: '上海虹桥',
|
|
16
20
|
to: '丽江三义',
|
|
17
21
|
departure_at: '2026-10-01T07:35:00+08:00',
|
|
18
22
|
arrival_at: '2026-10-01T10:55:00+08:00',
|
|
19
|
-
transport_number: 'HO5577'
|
|
20
|
-
}
|
|
21
|
-
],
|
|
23
|
+
transport_number: 'HO5577',
|
|
24
|
+
}],
|
|
22
25
|
journey_type: 'direct',
|
|
23
26
|
currency: 'CNY',
|
|
24
27
|
price: 1611,
|
|
@@ -26,58 +29,44 @@ const sessionFixture = {
|
|
|
26
29
|
fetched_at: '2026-08-28T16:00:00Z',
|
|
27
30
|
verdict: 'hit',
|
|
28
31
|
latency_ms: 4200,
|
|
29
|
-
read_guard_blocked: 0
|
|
32
|
+
read_guard_blocked: 0,
|
|
30
33
|
};
|
|
31
34
|
const officialFixture = {
|
|
32
35
|
...structuredClone(sessionFixture),
|
|
33
36
|
price: 230,
|
|
34
37
|
source: 'flyai',
|
|
35
|
-
fetched_at: '2026-08-28T15:59:00Z'
|
|
38
|
+
fetched_at: '2026-08-28T15:59:00Z',
|
|
36
39
|
};
|
|
37
40
|
console.log('SESSION DOUBLE-SOURCE CONTRACT');
|
|
38
|
-
check('完整单段 fixture 为 13/13', ()=>{
|
|
41
|
+
check('完整单段 fixture 为 13/13', () => {
|
|
39
42
|
const score = scoreSessionFixture(sessionFixture, structuredClone(sessionFixture));
|
|
40
43
|
assert.equal(score.pass, true);
|
|
41
44
|
assert.equal(score.accuracy, 1);
|
|
42
45
|
assert.equal(score.total, 13);
|
|
43
46
|
});
|
|
44
|
-
check('缺失 required 字段与错误价格都进入准确率分母', ()=>{
|
|
47
|
+
check('缺失 required 字段与错误价格都进入准确率分母', () => {
|
|
45
48
|
const actual = structuredClone(sessionFixture);
|
|
46
49
|
actual.currency = '';
|
|
47
50
|
actual.price = 999;
|
|
48
51
|
const score = scoreSessionFixture(sessionFixture, actual);
|
|
49
52
|
assert.equal(score.pass, false);
|
|
50
|
-
assert.deepEqual(score.missing, [
|
|
51
|
-
|
|
52
|
-
]);
|
|
53
|
-
assert.deepEqual(score.incorrect, [
|
|
54
|
-
'price'
|
|
55
|
-
]);
|
|
53
|
+
assert.deepEqual(score.missing, ['currency']);
|
|
54
|
+
assert.deepEqual(score.incorrect, ['price']);
|
|
56
55
|
assert.equal(score.accuracy, 11 / 13);
|
|
57
56
|
});
|
|
58
|
-
check('字段类型不一致不能靠字符串化蒙混过关', ()=>{
|
|
59
|
-
const actual = {
|
|
60
|
-
...structuredClone(sessionFixture),
|
|
61
|
-
price: '1611'
|
|
62
|
-
};
|
|
57
|
+
check('字段类型不一致不能靠字符串化蒙混过关', () => {
|
|
58
|
+
const actual = { ...structuredClone(sessionFixture), price: '1611' };
|
|
63
59
|
const score = scoreSessionFixture(sessionFixture, actual);
|
|
64
60
|
assert.equal(score.accuracy, 12 / 13);
|
|
65
|
-
assert.deepEqual(score.incorrect, [
|
|
66
|
-
'price'
|
|
67
|
-
]);
|
|
61
|
+
assert.deepEqual(score.incorrect, ['price']);
|
|
68
62
|
});
|
|
69
|
-
check('非法 golden fixture 自身 fail-closed', ()=>{
|
|
70
|
-
const expected = {
|
|
71
|
-
...structuredClone(sessionFixture),
|
|
72
|
-
price: 0
|
|
73
|
-
};
|
|
63
|
+
check('非法 golden fixture 自身 fail-closed', () => {
|
|
64
|
+
const expected = { ...structuredClone(sessionFixture), price: 0 };
|
|
74
65
|
const score = scoreSessionFixture(expected, structuredClone(expected));
|
|
75
66
|
assert.equal(score.pass, false);
|
|
76
|
-
assert.deepEqual(score.fixture_errors, [
|
|
77
|
-
'price'
|
|
78
|
-
]);
|
|
67
|
+
assert.deepEqual(score.fixture_errors, ['price']);
|
|
79
68
|
});
|
|
80
|
-
check('中转 fixture 逐段计分', ()=>{
|
|
69
|
+
check('中转 fixture 逐段计分', () => {
|
|
81
70
|
const transfer = {
|
|
82
71
|
...structuredClone(sessionFixture),
|
|
83
72
|
query_id: 'sf-02',
|
|
@@ -89,173 +78,103 @@ check('中转 fixture 逐段计分', ()=>{
|
|
|
89
78
|
to: '西双版纳嘎洒',
|
|
90
79
|
departure_at: '2026-10-02T08:20:00+08:00',
|
|
91
80
|
arrival_at: '2026-10-02T09:35:00+08:00',
|
|
92
|
-
transport_number: '8L9608'
|
|
93
|
-
}
|
|
94
|
-
]
|
|
81
|
+
transport_number: '8L9608',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
95
84
|
};
|
|
96
85
|
const score = scoreSessionFixture(transfer, structuredClone(transfer));
|
|
97
86
|
assert.equal(score.pass, true);
|
|
98
87
|
assert.equal(score.total, 18);
|
|
99
88
|
});
|
|
100
|
-
check('同路线班次可比,价格差只记录不判错', ()=>{
|
|
101
|
-
const result = evaluateDoubleSource({
|
|
102
|
-
official: officialFixture,
|
|
103
|
-
session: sessionFixture
|
|
104
|
-
});
|
|
89
|
+
check('同路线班次可比,价格差只记录不判错', () => {
|
|
90
|
+
const result = evaluateDoubleSource({ official: officialFixture, session: sessionFixture });
|
|
105
91
|
assert.equal(result.state, 'comparable');
|
|
106
92
|
assert.deepEqual(result.mismatches, []);
|
|
107
93
|
assert.equal(result.price_delta, 1381);
|
|
108
94
|
assert.equal(result.quota_disposition, 'evidence_ready');
|
|
109
95
|
});
|
|
110
|
-
check('时刻不一致投影 divergent', ()=>{
|
|
96
|
+
check('时刻不一致投影 divergent', () => {
|
|
111
97
|
const session = structuredClone(sessionFixture);
|
|
112
98
|
session.route_segments[0].arrival_at = '2026-10-01T11:15:00+08:00';
|
|
113
|
-
const result = evaluateDoubleSource({
|
|
114
|
-
official: officialFixture,
|
|
115
|
-
session
|
|
116
|
-
});
|
|
99
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
117
100
|
assert.equal(result.state, 'divergent');
|
|
118
|
-
assert.deepEqual(result.mismatches, [
|
|
119
|
-
'route_segments[0].arrival_at'
|
|
120
|
-
]);
|
|
101
|
+
assert.deepEqual(result.mismatches, ['route_segments[0].arrival_at']);
|
|
121
102
|
});
|
|
122
|
-
check('等价时区时刻保持 comparable', ()=>{
|
|
103
|
+
check('等价时区时刻保持 comparable', () => {
|
|
123
104
|
const session = structuredClone(sessionFixture);
|
|
124
105
|
session.route_segments[0].departure_at = '2026-09-30T23:35:00Z';
|
|
125
106
|
session.route_segments[0].arrival_at = '2026-10-01T02:55:00Z';
|
|
126
|
-
const result = evaluateDoubleSource({
|
|
127
|
-
official: officialFixture,
|
|
128
|
-
session
|
|
129
|
-
});
|
|
107
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
130
108
|
assert.equal(result.state, 'comparable');
|
|
131
109
|
});
|
|
132
|
-
check('needs-attach 为 waiting-user no-spend', ()=>{
|
|
133
|
-
const session = {
|
|
134
|
-
|
|
135
|
-
verdict: 'needs-attach'
|
|
136
|
-
};
|
|
137
|
-
const result = evaluateDoubleSource({
|
|
138
|
-
official: officialFixture,
|
|
139
|
-
session
|
|
140
|
-
});
|
|
110
|
+
check('needs-attach 为 waiting-user no-spend', () => {
|
|
111
|
+
const session = { ...structuredClone(sessionFixture), verdict: 'needs-attach' };
|
|
112
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
141
113
|
assert.equal(result.state, 'waiting_attach');
|
|
142
114
|
assert.equal(result.retry_allowed, false);
|
|
143
115
|
assert.equal(result.quota_disposition, 'no_spend_waiting_user');
|
|
144
116
|
});
|
|
145
|
-
check('CDP 缺席与握手失败稳定投影 needs-attach', ()=>{
|
|
117
|
+
check('CDP 缺席与握手失败稳定投影 needs-attach', () => {
|
|
146
118
|
assert.equal(classifyTransportFailure('日常 Chrome 未开调试端口', true), 'needs-attach');
|
|
147
119
|
assert.equal(classifyTransportFailure('cdp attach 失败:socket closed', true), 'needs-attach');
|
|
148
120
|
assert.equal(classifyTransportFailure('chrome launch failed', false), 'error');
|
|
149
121
|
});
|
|
150
|
-
check('needs-login 为 waiting-user no-spend', ()=>{
|
|
151
|
-
const session = {
|
|
152
|
-
|
|
153
|
-
verdict: 'needs-login'
|
|
154
|
-
};
|
|
155
|
-
const result = evaluateDoubleSource({
|
|
156
|
-
official: officialFixture,
|
|
157
|
-
session
|
|
158
|
-
});
|
|
122
|
+
check('needs-login 为 waiting-user no-spend', () => {
|
|
123
|
+
const session = { ...structuredClone(sessionFixture), verdict: 'needs-login' };
|
|
124
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
159
125
|
assert.equal(result.state, 'waiting_login');
|
|
160
126
|
assert.equal(result.retry_allowed, false);
|
|
161
127
|
assert.equal(result.quota_disposition, 'no_spend_waiting_user');
|
|
162
128
|
});
|
|
163
|
-
check('缺失 session 证据不擅自投影用户 gate', ()=>{
|
|
164
|
-
const result = evaluateDoubleSource({
|
|
165
|
-
official: officialFixture
|
|
166
|
-
});
|
|
129
|
+
check('缺失 session 证据不擅自投影用户 gate', () => {
|
|
130
|
+
const result = evaluateDoubleSource({ official: officialFixture });
|
|
167
131
|
assert.equal(result.state, 'source_unavailable');
|
|
168
132
|
assert.equal(result.quota_disposition, 'no_spend_stop');
|
|
169
133
|
});
|
|
170
|
-
check('challenge 立即停止', ()=>{
|
|
171
|
-
const session = {
|
|
172
|
-
|
|
173
|
-
verdict: 'challenged'
|
|
174
|
-
};
|
|
175
|
-
const result = evaluateDoubleSource({
|
|
176
|
-
official: officialFixture,
|
|
177
|
-
session
|
|
178
|
-
});
|
|
134
|
+
check('challenge 立即停止', () => {
|
|
135
|
+
const session = { ...structuredClone(sessionFixture), verdict: 'challenged' };
|
|
136
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
179
137
|
assert.equal(result.state, 'challenge_stop');
|
|
180
138
|
assert.equal(result.quota_disposition, 'no_spend_stop');
|
|
181
139
|
});
|
|
182
|
-
check('challenge 与 ReadGuard 优先于 waiting-user', ()=>{
|
|
183
|
-
const challengedOfficial = {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
const waitingSession = {
|
|
188
|
-
...structuredClone(sessionFixture),
|
|
189
|
-
verdict: 'needs-attach'
|
|
190
|
-
};
|
|
191
|
-
assert.equal(evaluateDoubleSource({
|
|
192
|
-
official: challengedOfficial,
|
|
193
|
-
session: waitingSession
|
|
194
|
-
}).state, 'challenge_stop');
|
|
140
|
+
check('challenge 与 ReadGuard 优先于 waiting-user', () => {
|
|
141
|
+
const challengedOfficial = { ...structuredClone(officialFixture), verdict: 'challenged' };
|
|
142
|
+
const waitingSession = { ...structuredClone(sessionFixture), verdict: 'needs-attach' };
|
|
143
|
+
assert.equal(evaluateDoubleSource({ official: challengedOfficial, session: waitingSession }).state, 'challenge_stop');
|
|
195
144
|
waitingSession.read_guard_blocked = 1;
|
|
196
|
-
assert.equal(evaluateDoubleSource({
|
|
197
|
-
official: officialFixture,
|
|
198
|
-
session: waitingSession
|
|
199
|
-
}).state, 'guard_violation');
|
|
145
|
+
assert.equal(evaluateDoubleSource({ official: officialFixture, session: waitingSession }).state, 'guard_violation');
|
|
200
146
|
});
|
|
201
|
-
check('ReadGuard 非零 fail-closed', ()=>{
|
|
202
|
-
const session = {
|
|
203
|
-
|
|
204
|
-
read_guard_blocked: 1
|
|
205
|
-
};
|
|
206
|
-
const result = evaluateDoubleSource({
|
|
207
|
-
official: officialFixture,
|
|
208
|
-
session
|
|
209
|
-
});
|
|
147
|
+
check('ReadGuard 非零 fail-closed', () => {
|
|
148
|
+
const session = { ...structuredClone(sessionFixture), read_guard_blocked: 1 };
|
|
149
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
210
150
|
assert.equal(result.state, 'guard_violation');
|
|
211
151
|
assert.equal(result.quota_disposition, 'no_spend_stop');
|
|
212
152
|
});
|
|
213
|
-
check('缺 required 合同字段时 fail-closed', ()=>{
|
|
214
|
-
const session = {
|
|
215
|
-
|
|
216
|
-
currency: ''
|
|
217
|
-
};
|
|
218
|
-
const result = evaluateDoubleSource({
|
|
219
|
-
official: officialFixture,
|
|
220
|
-
session
|
|
221
|
-
});
|
|
153
|
+
check('缺 required 合同字段时 fail-closed', () => {
|
|
154
|
+
const session = { ...structuredClone(sessionFixture), currency: '' };
|
|
155
|
+
const result = evaluateDoubleSource({ official: officialFixture, session });
|
|
222
156
|
assert.equal(result.state, 'invalid_contract');
|
|
223
|
-
assert.deepEqual(result.missing, [
|
|
224
|
-
'session.currency'
|
|
225
|
-
]);
|
|
157
|
+
assert.deepEqual(result.missing, ['session.currency']);
|
|
226
158
|
assert.equal(result.quota_disposition, 'no_spend_stop');
|
|
227
159
|
});
|
|
228
|
-
check('FlyAI stdout 前后噪声不污染完整业务 JSON', ()=>{
|
|
160
|
+
check('FlyAI stdout 前后噪声不污染完整业务 JSON', () => {
|
|
229
161
|
const payload = {
|
|
230
162
|
data: {
|
|
231
|
-
itemList: [
|
|
232
|
-
{
|
|
163
|
+
itemList: [{
|
|
233
164
|
journeys: [],
|
|
234
|
-
systemMessage: '提示含花括号 {limited} 与引号 "quoted" 仍属于 JSON 字符串'
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
}
|
|
165
|
+
systemMessage: '提示含花括号 {limited} 与引号 "quoted" 仍属于 JSON 字符串',
|
|
166
|
+
}],
|
|
167
|
+
},
|
|
238
168
|
};
|
|
239
169
|
const noisy = `npm notice {not-json}\n${JSON.stringify(payload)}\npostflight log {done}`;
|
|
240
170
|
assert.deepEqual(parseFlyaiItemList(noisy), payload.data.itemList);
|
|
241
171
|
});
|
|
242
|
-
check('FlyAI stdout 可跳过前置诊断 JSON', ()=>{
|
|
243
|
-
const payload = {
|
|
244
|
-
data: {
|
|
245
|
-
itemList: [
|
|
246
|
-
{
|
|
247
|
-
ticketPrice: '230.00'
|
|
248
|
-
}
|
|
249
|
-
]
|
|
250
|
-
}
|
|
251
|
-
};
|
|
172
|
+
check('FlyAI stdout 可跳过前置诊断 JSON', () => {
|
|
173
|
+
const payload = { data: { itemList: [{ ticketPrice: '230.00' }] } };
|
|
252
174
|
assert.deepEqual(parseFlyaiItemList(`{"level":"info","message":"warmup"}\n${JSON.stringify(payload)}\n`), payload.data.itemList);
|
|
253
175
|
});
|
|
254
|
-
check('FlyAI 无完整 itemList 对象时保持 fail-closed', ()=>{
|
|
255
|
-
assert.throws(()=>parseFlyaiItemList('{"data":{"itemList":['), /incomplete FlyAI JSON object/);
|
|
256
|
-
assert.throws(()=>parseFlyaiItemList('{"message":"SentinelBlockException"}'), /no complete FlyAI itemList JSON object/);
|
|
176
|
+
check('FlyAI 无完整 itemList 对象时保持 fail-closed', () => {
|
|
177
|
+
assert.throws(() => parseFlyaiItemList('{"data":{"itemList":['), /incomplete FlyAI JSON object/);
|
|
178
|
+
assert.throws(() => parseFlyaiItemList('{"message":"SentinelBlockException"}'), /no complete FlyAI itemList JSON object/);
|
|
257
179
|
});
|
|
258
180
|
console.log(`SESSION DOUBLE-SOURCE CONTRACT: ${passed} pass`);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
//# sourceURL=ts/scripts/session-benchmark.ts
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dida 供应商门户会话面 LIVE E2E(hotel-be portal integration 迁移线;GOTRY_SESSION_LIVE=1 显式开启)。
|
|
3
|
+
*
|
|
4
|
+
* 全链:真 Chrome(加载 unpacked Session Bridge 扩展)→ 人/驱动在 dida 官网完成登录
|
|
5
|
+
* (账密经 env 注入,gotry 永不经手)→ sessionDidaSearch 扩展车道(桥自动拉起,
|
|
6
|
+
* 扩展 cookie-names 名字级登录闸 → search job 后台标签被动嗅探)→ dida SPA 页面
|
|
7
|
+
* 自身发起 SearchRealTime → parseDidaRates 结构化报价。
|
|
8
|
+
*
|
|
9
|
+
* SPA 边界:dida find 页加载自发的是价格监控;实时价(SearchRealTime)由页内
|
|
10
|
+
* 「预订」按钮触发——驱动只在自己开的登录页与 job 的后台标签里做「去 overlay +
|
|
11
|
+
* 点页面自己的按钮」,检索请求仍由 dida 页面代码发出(扩展零写行为不变量不破)。
|
|
12
|
+
*
|
|
13
|
+
* 运行:cd ts && GOTRY_SESSION_LIVE=1 DIDA_USERNAME=... DIDA_PASSWORD=... \
|
|
14
|
+
* npx tsx scripts/session-dida-live-e2e.ts
|
|
15
|
+
*/
|
|
16
|
+
import { spawn } from 'node:child_process';
|
|
17
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { fileURLToPath } from 'node:url';
|
|
21
|
+
import { chromium } from 'playwright-core';
|
|
22
|
+
import { sessionDidaSearch, __resetRateLimiterForTest } from '../capabilities/session-search.js';
|
|
23
|
+
const EXT_DIR = fileURLToPath(new URL('../../extension/', import.meta.url));
|
|
24
|
+
const CDP_PORT = 9233;
|
|
25
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
26
|
+
async function removeOverlays(page) {
|
|
27
|
+
await page.evaluate(`(() => {
|
|
28
|
+
document.querySelectorAll('#onetrust-consent-sdk, .nd-cookie-consent, .cdk-overlay-backdrop, .cdk-overlay-container').forEach(el => el.remove())
|
|
29
|
+
})()`).catch(() => { });
|
|
30
|
+
}
|
|
31
|
+
async function main() {
|
|
32
|
+
const user = process.env.DIDA_USERNAME ?? '';
|
|
33
|
+
const pass = process.env.DIDA_PASSWORD ?? '';
|
|
34
|
+
if (!process.env.GOTRY_SESSION_LIVE || !user || !pass) {
|
|
35
|
+
console.error('GOTRY_SESSION_LIVE=1 与 DIDA_USERNAME/DIDA_PASSWORD 必填(env 注入,不入库)');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const profileDir = mkdtempSync(join(tmpdir(), 'gotry-dida-e2e-'));
|
|
39
|
+
// Chrome 137+ 品牌版移除 --load-extension;Chromium/Chrome for Testing 保留(2026-09-09 实测)。
|
|
40
|
+
const chromeBin = process.env.CHROME_BIN
|
|
41
|
+
?? `${process.env.HOME}/Library/Caches/ms-playwright/chromium-1228/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing`;
|
|
42
|
+
const chrome = spawn(chromeBin, [
|
|
43
|
+
`--remote-debugging-port=${CDP_PORT}`,
|
|
44
|
+
`--user-data-dir=${profileDir}`,
|
|
45
|
+
'--no-first-run',
|
|
46
|
+
`--disable-extensions-except=${EXT_DIR}`,
|
|
47
|
+
`--load-extension=${EXT_DIR}`,
|
|
48
|
+
'about:blank',
|
|
49
|
+
], { stdio: 'ignore' });
|
|
50
|
+
const cleanup = () => {
|
|
51
|
+
try {
|
|
52
|
+
chrome.kill();
|
|
53
|
+
}
|
|
54
|
+
catch { /* 已退出 */ }
|
|
55
|
+
try {
|
|
56
|
+
rmSync(profileDir, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
catch { /* 下次清扫 */ }
|
|
59
|
+
};
|
|
60
|
+
process.on('exit', cleanup);
|
|
61
|
+
await sleep(10_000); // 等 SW 拉起 + 扩展装载
|
|
62
|
+
const browser = await chromium.connectOverCDP(`http://127.0.0.1:${CDP_PORT}`);
|
|
63
|
+
const context = browser.contexts()[0];
|
|
64
|
+
const workers = context.serviceWorkers();
|
|
65
|
+
console.log(`扩展 service worker: ${workers.length > 0 ? '✅' : '❌(继续,job 前可能仍就绪)'}`);
|
|
66
|
+
// ── 登录(账密 env 注入;验证码如出现由人在窗口里完成)──
|
|
67
|
+
const page = await context.newPage();
|
|
68
|
+
console.log('📍 登录 portal.dida.com');
|
|
69
|
+
await page.goto('https://portal.dida.com/login', { waitUntil: 'networkidle', timeout: 45_000 });
|
|
70
|
+
await removeOverlays(page);
|
|
71
|
+
await page.waitForSelector('input[name="username"]', { timeout: 20_000 });
|
|
72
|
+
await page.evaluate(`(() => {
|
|
73
|
+
const u = document.querySelector('input[name="username"]')
|
|
74
|
+
const p = document.querySelector('input[name="password"]')
|
|
75
|
+
const setVal = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set
|
|
76
|
+
setVal.call(u, ${JSON.stringify(user)}); u.dispatchEvent(new Event('input', { bubbles: true }))
|
|
77
|
+
setVal.call(p, ${JSON.stringify(pass)}); p.dispatchEvent(new Event('input', { bubbles: true }))
|
|
78
|
+
})()`);
|
|
79
|
+
await page.evaluate(`(() => {
|
|
80
|
+
document.querySelectorAll('.ant-checkbox-wrapper, label[class*="checkbox"]').forEach(w => w.click())
|
|
81
|
+
})()`);
|
|
82
|
+
await sleep(500);
|
|
83
|
+
await page.evaluate(`(() => {
|
|
84
|
+
Array.from(document.querySelectorAll('button')).find(b => b.textContent.trim().toLowerCase() === 'login')?.click()
|
|
85
|
+
})()`);
|
|
86
|
+
let loggedIn = false;
|
|
87
|
+
try {
|
|
88
|
+
await page.waitForURL('**/hotel/**', { timeout: 60_000 });
|
|
89
|
+
await sleep(3_000);
|
|
90
|
+
loggedIn = true;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
console.log('⚠️ 60s 未跳转——若窗口出现验证码,请人工完成后脚本继续等 60s');
|
|
94
|
+
try {
|
|
95
|
+
await page.waitForURL('**/hotel/**', { timeout: 60_000 });
|
|
96
|
+
await sleep(3_000);
|
|
97
|
+
loggedIn = true;
|
|
98
|
+
}
|
|
99
|
+
catch { /* 放行给登录闸报 needs-login */ }
|
|
100
|
+
}
|
|
101
|
+
console.log(`登录: ${loggedIn ? '✅' : '❌(交由会话登录闸裁决)'}`);
|
|
102
|
+
await removeOverlays(page);
|
|
103
|
+
// ── 会话检索(扩展车道;桥由 sessionDidaSearch 拉起,扩展 5s 内接入)──
|
|
104
|
+
// SPA 点击协助与检索并发:job 开的后台标签加载后,替它点页面自己的「预订」,
|
|
105
|
+
// 触发 dida 页面代码发出 SearchRealTime(扩展/桥零写行为不变量不变)。
|
|
106
|
+
console.log('📍 sessionDidaSearch(扩展车道,后台标签被动嗅探 + 预订点击协助)');
|
|
107
|
+
__resetRateLimiterForTest();
|
|
108
|
+
const loginPageUrl = page.url();
|
|
109
|
+
const clickAssist = (async () => {
|
|
110
|
+
await sleep(3_000);
|
|
111
|
+
for (let i = 0; i < 20; i++) {
|
|
112
|
+
const jobTabs = context.pages().filter((p) => p.url().startsWith('https://portal.dida.com/') && p !== page && p.url() !== loginPageUrl);
|
|
113
|
+
for (const tab of jobTabs) {
|
|
114
|
+
await removeOverlays(tab);
|
|
115
|
+
const clicked = await tab.evaluate(`(() => {
|
|
116
|
+
const btn = document.querySelector('.hotel-index-recommends-card__book-btn')
|
|
117
|
+
|| Array.from(document.querySelectorAll('button')).find(b => b.textContent.includes('预订'))
|
|
118
|
+
if (btn) { btn.scrollIntoView(); btn.click(); return true }
|
|
119
|
+
return false
|
|
120
|
+
})()`).catch(() => false);
|
|
121
|
+
if (clicked === true) {
|
|
122
|
+
console.log('📍 已在 job 后台标签点击「预订」——等页面自己发检索');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
await sleep(2_000);
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
// CfT/Chromium 构建 cookies API 对 HttpOnly cookie 不可见(品牌版 Chrome 144 正常,
|
|
130
|
+
// 2026-09-09 SW 探针实证)——E2E 以 DIDA_E2E_SKIP_LOGIN_GATE=1 跳过登录快查,
|
|
131
|
+
// 登录真实性由本驱动前序 GUI 登录保证;嗅探链路不读 cookie 值,不受此缺陷影响。
|
|
132
|
+
const skipGate = process.env.DIDA_E2E_SKIP_LOGIN_GATE === '1';
|
|
133
|
+
let result = await sessionDidaSearch({ timeoutMs: 50_000, allowAnonymous: skipGate });
|
|
134
|
+
for (let attempt = 2; attempt <= 3 && result.ok !== true; attempt++) {
|
|
135
|
+
console.log(`⚠️ 第 ${attempt - 1} 次尝试未取回(${result.verdict}),8s 后重试(节律闸已重置;扩展 SW 30s 节律唤醒)`);
|
|
136
|
+
await sleep(8_000);
|
|
137
|
+
__resetRateLimiterForTest();
|
|
138
|
+
result = await sessionDidaSearch({ timeoutMs: 50_000, allowAnonymous: skipGate });
|
|
139
|
+
}
|
|
140
|
+
await clickAssist;
|
|
141
|
+
console.log('\n════════ 会话检索结果 ════════');
|
|
142
|
+
console.log(JSON.stringify(result, null, 2).slice(0, 4_000));
|
|
143
|
+
const rates = result.rates ?? [];
|
|
144
|
+
console.log(`\nverdict=${result.verdict} rates=${rates.length}`);
|
|
145
|
+
if (rates.length > 0) {
|
|
146
|
+
console.log('样例:', JSON.stringify(rates.slice(0, 3), null, 2));
|
|
147
|
+
}
|
|
148
|
+
await browser.close();
|
|
149
|
+
process.exit(result.verdict === 'hit' ? 0 : 2);
|
|
150
|
+
}
|
|
151
|
+
main().catch((e) => { console.error('Fatal:', e); process.exit(1); });
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话面 P2-2 纯函数测试:extract(a11y 兜底抽取)+ 美团适配器骨架 + 金标准 20 查询 schema。
|
|
3
|
+
* 美团 live 验证挂起(匿名 403 实测,2026-08-28)——登录态就绪后由心跳轮回填 networkHint。
|
|
4
|
+
*/
|
|
1
5
|
import { readFileSync } from 'node:fs';
|
|
2
6
|
import { join } from 'node:path';
|
|
3
7
|
import { extractA11yEntries, filterSubmitEntries, nameAffinity } from '../capabilities/session/extract.js';
|
|
@@ -8,7 +12,8 @@ function assert(cond, label, detail) {
|
|
|
8
12
|
if (cond) {
|
|
9
13
|
pass += 1;
|
|
10
14
|
console.log(` ok - ${label}`);
|
|
11
|
-
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
12
17
|
fail += 1;
|
|
13
18
|
console.log(` FAIL - ${label}${detail !== undefined ? ' :: ' + String(detail) : ''}`);
|
|
14
19
|
}
|
|
@@ -23,14 +28,14 @@ const entries = extractA11yEntries(snap);
|
|
|
23
28
|
assert(entries.length === 5 && entries[0].role === 'button' && entries[0].name === '搜索', 'role+name 提取(ref 行)');
|
|
24
29
|
assert(entries[2].name === '上海到丽江机票' && entries[3].role === 'listitem', 'heading/listitem 归位');
|
|
25
30
|
const noName = extractA11yEntries('- img\n- separator');
|
|
26
|
-
assert(noName.every((e)=>typeof e.name === 'string'), '无 name 行保留空占位不炸');
|
|
31
|
+
assert(noName.every((e) => typeof e.name === 'string'), '无 name 行保留空占位不炸');
|
|
27
32
|
assert(extractA11yEntries('').length === 0, '空快照返空');
|
|
28
33
|
console.log('B. filterSubmitEntries(DOM 提交件剔除)');
|
|
29
|
-
const kept = filterSubmitEntries(entries, (n)
|
|
34
|
+
const kept = filterSubmitEntries(entries, (n) => /下单|支付/.test(n));
|
|
30
35
|
assert(kept.length === entries.length, '无提交词:全保留');
|
|
31
36
|
const snap2 = extractA11yEntries('- button "立即下单" [ref=s1e9]\n- button "搜索" [ref=s2e1]');
|
|
32
|
-
assert(filterSubmitEntries(snap2, (n)
|
|
33
|
-
assert(filterSubmitEntries(extractA11yEntries('- heading "支付说明"'), (n)
|
|
37
|
+
assert(filterSubmitEntries(snap2, (n) => /下单|支付/.test(n)).length === 1, 'button 命中提交黑名单剔除,搜索保留');
|
|
38
|
+
assert(filterSubmitEntries(extractA11yEntries('- heading "支付说明"'), (n) => /下单|支付/.test(n)).length === 1, '非交互 role(heading)不剔除');
|
|
34
39
|
console.log('C. nameAffinity(自愈候选排序底座)');
|
|
35
40
|
assert(nameAffinity('吉祥航空 HO5577', '吉祥航空 HO5577') === 1, '全等=1');
|
|
36
41
|
assert(nameAffinity('上海到丽江机票', '机票') === 0.8, '包含=0.8');
|
|
@@ -47,35 +52,9 @@ assert(extractListings(extractA11yEntries('- heading "无价格标题"')).length
|
|
|
47
52
|
console.log('F. 金标准 20 查询 schema(只增不改语义)');
|
|
48
53
|
const golden = JSON.parse(readFileSync(join(import.meta.dirname, '../data/session-golden-20.json'), 'utf8'));
|
|
49
54
|
assert(golden.queries.length === 20, '恰 20 条');
|
|
50
|
-
assert(new Set(golden.queries.map((q)=>q.id)).size === 20, 'id 唯一');
|
|
51
|
-
const ctripCities = new Set([
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
'广州',
|
|
55
|
-
'深圳',
|
|
56
|
-
'成都',
|
|
57
|
-
'昆明',
|
|
58
|
-
'大理',
|
|
59
|
-
'丽江',
|
|
60
|
-
'西安',
|
|
61
|
-
'杭州',
|
|
62
|
-
'三亚',
|
|
63
|
-
'厦门',
|
|
64
|
-
'重庆',
|
|
65
|
-
'青岛',
|
|
66
|
-
'长沙',
|
|
67
|
-
'武汉',
|
|
68
|
-
'南京',
|
|
69
|
-
'郑州',
|
|
70
|
-
'贵阳',
|
|
71
|
-
'桂林',
|
|
72
|
-
'西双版纳',
|
|
73
|
-
'香格里拉'
|
|
74
|
-
]);
|
|
75
|
-
assert(golden.queries.filter((q)=>q.kind === 'flight').every((q)=>ctripCities.has(q.from) && ctripCities.has(q.to)), 'flight 城市全在双适配器词表内');
|
|
76
|
-
assert(golden.queries.filter((q)=>q.kind.startsWith('meituan') || q.kind.startsWith('flyai')).every((q)=>q.id), '每条带 id');
|
|
55
|
+
assert(new Set(golden.queries.map((q) => q.id)).size === 20, 'id 唯一');
|
|
56
|
+
const ctripCities = new Set(['上海', '北京', '广州', '深圳', '成都', '昆明', '大理', '丽江', '西安', '杭州', '三亚', '厦门', '重庆', '青岛', '长沙', '武汉', '南京', '郑州', '贵阳', '桂林', '西双版纳', '香格里拉']);
|
|
57
|
+
assert(golden.queries.filter((q) => q.kind === 'flight').every((q) => ctripCities.has(q.from) && ctripCities.has(q.to)), 'flight 城市全在双适配器词表内');
|
|
58
|
+
assert(golden.queries.filter((q) => q.kind.startsWith('meituan') || q.kind.startsWith('flyai')).every((q) => q.id), '每条带 id');
|
|
77
59
|
console.log(`\nSESSION-EXTRACT: ${pass} pass, ${fail} fail`);
|
|
78
60
|
process.exit(fail > 0 ? 1 : 0);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//# sourceURL=ts/scripts/session-extract-tests.ts
|