@danceiny/gotry 0.0.1-rc.9 → 0.2.0-rc.27
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 +172 -219
- package/README.zh-CN.md +222 -0
- package/bin/gotry-backend.js +53 -0
- package/bin/gotry-booking-copilot.js +53 -0
- package/bin/gotry-bootstrap.js +1744 -0
- package/bin/gotry-inner.js +733 -83
- package/bin/gotry-process-liveness.d.ts +27 -0
- package/bin/gotry-process-liveness.js +97 -0
- package/bin/gotry-runtime-resolution.d.ts +27 -0
- package/bin/gotry-runtime-resolution.js +49 -0
- package/bin/gotry.js +1 -1
- package/client/client.js +203 -0
- package/cordis.gotry-patch.yml +80 -56
- package/data/airline-airports.json +39 -0
- package/data/stations-12306-verify.json +524 -0
- package/dist/capabilities/agent-reach-deep.js +45 -122
- package/dist/capabilities/agent-reach.js +101 -146
- package/dist/capabilities/anything.js +135 -94
- package/dist/capabilities/artifacts.js +370 -0
- package/dist/capabilities/channel-health.js +131 -0
- package/dist/capabilities/channel-registry.js +256 -0
- package/dist/capabilities/doctor.js +546 -0
- package/dist/capabilities/effect.js +394 -0
- package/dist/capabilities/external-event.js +149 -0
- package/dist/capabilities/fact-log.js +55 -0
- package/dist/capabilities/flyai-config.js +337 -0
- package/dist/capabilities/flyai.js +947 -110
- package/dist/capabilities/fx-contract.js +293 -0
- package/dist/capabilities/geo-atlas.js +246 -0
- package/dist/capabilities/ground-transfer.js +509 -0
- package/dist/capabilities/hbcli.js +260 -123
- package/dist/capabilities/hotelbyte-transaction.js +194 -0
- package/dist/capabilities/incident-log.js +131 -61
- package/dist/capabilities/itinerary-artifact.js +190 -0
- package/dist/capabilities/itinerary-deck-artifact.js +194 -0
- package/dist/capabilities/itinerary-deck-export.js +339 -0
- package/dist/capabilities/lavish-local.js +924 -0
- package/dist/capabilities/model-override.js +38 -0
- package/dist/capabilities/opensky.js +54 -43
- package/dist/capabilities/resilience.js +191 -0
- package/dist/capabilities/session/action-cache.js +50 -44
- package/dist/capabilities/session/adapters/ctrip-flight.js +120 -62
- package/dist/capabilities/session/adapters/ctrip-hotel.js +222 -0
- package/dist/capabilities/session/adapters/dida-portal.js +274 -0
- package/dist/capabilities/session/adapters/meituan-local.js +35 -54
- package/dist/capabilities/session/adapters/rail-12306.js +342 -0
- package/dist/capabilities/session/benchmark.js +189 -0
- package/dist/capabilities/session/bridge-ledger.js +224 -0
- package/dist/capabilities/session/extension-bridge.js +636 -0
- package/dist/capabilities/session/extension-channel.js +109 -0
- package/dist/capabilities/session/extension-distribution.js +230 -0
- package/dist/capabilities/session/extract.js +31 -21
- package/dist/capabilities/session/golden-score.js +114 -0
- package/dist/capabilities/session/health-watch.js +215 -0
- package/dist/capabilities/session/read-guard.js +75 -24
- package/dist/capabilities/session/static-flight-golden.js +150 -0
- package/dist/capabilities/session/transport.js +97 -83
- package/dist/capabilities/session/wizard.js +117 -0
- package/dist/capabilities/session-consent.js +178 -0
- package/dist/capabilities/session-login.js +170 -0
- package/dist/capabilities/session-search.js +635 -44
- package/dist/capabilities/spawn-bounded.js +203 -0
- package/dist/capabilities/sponsor-plugin.js +341 -0
- package/dist/capabilities/visa-policy.js +140 -0
- package/dist/capabilities/weather.js +243 -138
- package/dist/data/session-golden-20.json +25 -0
- package/dist/data/sf-golden-manifest.json +103 -0
- package/dist/data/sf-static-routes.json +91 -0
- package/dist/scripts/action-cache-tests.js +24 -59
- package/dist/scripts/agent-planning-turn-deadline-e2e.js +242 -0
- package/dist/scripts/agent-planning-turn-deadline-tests.js +185 -0
- package/dist/scripts/agent-reach-deep-tests.js +30 -40
- package/dist/scripts/agent-reach-error-tests.js +354 -0
- package/dist/scripts/agent-reach-tests.js +26 -18
- package/dist/scripts/agent-reach-wrapper-tests.js +50 -50
- package/dist/scripts/anything-tests.js +116 -60
- package/dist/scripts/artifact-client-contract-tests.js +220 -0
- package/dist/scripts/artifacts-capability-tests.js +727 -0
- package/dist/scripts/async-collect.js +50 -11
- package/dist/scripts/benchmark-environment-bridge-e2e.js +741 -0
- package/dist/scripts/benchmark-environment-bridge-tests.js +1452 -0
- package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +126 -0
- package/dist/scripts/booking-copilot-availability-policy-tests.js +265 -0
- package/dist/scripts/booking-copilot-bin-proof-tests.js +66 -0
- package/dist/scripts/booking-copilot-cleanup-proof-helper.js +76 -0
- package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +144 -0
- package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +424 -0
- package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +2839 -0
- package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +309 -0
- package/dist/scripts/booking-copilot-dsh-readiness-proof.js +238 -0
- package/dist/scripts/booking-copilot-dsh-warmer-proof.js +123 -0
- package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +156 -0
- package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +70 -0
- package/dist/scripts/booking-copilot-intent-proof-tests.js +422 -0
- package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +184 -0
- package/dist/scripts/booking-copilot-planner-live-probe.js +95 -0
- package/dist/scripts/booking-copilot-proof-runtime.js +42 -0
- package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +210 -0
- package/dist/scripts/booking-copilot-runtime-proof-tests.js +2349 -0
- package/dist/scripts/booking-copilot-server-proof-tests.js +784 -0
- package/dist/scripts/booking-copilot-startup-proof-tests.js +94 -0
- 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 +125 -0
- package/dist/scripts/booking-surface-contract-proof-tests.js +212 -0
- package/dist/scripts/bootstrap-tests.js +1479 -0
- package/dist/scripts/bridge-events-tests.js +239 -0
- package/dist/scripts/bridge-ledger-tests.js +428 -0
- package/dist/scripts/build-changelog.js +238 -0
- package/dist/scripts/build-metrics-report.js +331 -0
- package/dist/scripts/changelog-tests.js +118 -0
- package/dist/scripts/channel-probe-tests.js +103 -0
- package/dist/scripts/channel-probe.js +169 -0
- package/dist/scripts/channel-registry-tests.js +208 -0
- package/dist/scripts/companion-tests.js +25 -70
- package/dist/scripts/dida-cookie-probe.js +87 -0
- package/dist/scripts/dida-runner-stop-tests.js +311 -0
- package/dist/scripts/dida-sw-probe.js +114 -0
- package/dist/scripts/diff-test.js +17 -12
- package/dist/scripts/doctor-tests.js +564 -0
- package/dist/scripts/dsh-artifact-e2e.js +279 -0
- package/dist/scripts/dsh-artifact-web-e2e.js +675 -0
- package/dist/scripts/dsh-http-proxy-sse-proof.js +90 -0
- package/dist/scripts/dsh-runtime-closure-tests.js +182 -0
- package/dist/scripts/dsh-runtime-closure.js +162 -0
- package/dist/scripts/dsh-session-v3-migration-proof.js +109 -0
- package/dist/scripts/dsh-subprocess-local-proof.js +150 -0
- package/dist/scripts/dsh-target-closure-proof.js +178 -0
- package/dist/scripts/effect-tests.js +539 -0
- package/dist/scripts/engine-run.js +1 -3
- package/dist/scripts/engine-tests.js +16 -10
- package/dist/scripts/evaluation-cadence-tests.js +174 -0
- package/dist/scripts/evaluation-contract-tests.js +268 -0
- package/dist/scripts/extension-distribution-cli.js +39 -0
- package/dist/scripts/extension-distribution-tests.js +443 -0
- package/dist/scripts/extension-tests.js +988 -0
- package/dist/scripts/external-event-tests.js +350 -0
- package/dist/scripts/fact-gate-tests.js +869 -0
- 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-setup-tests.js +228 -0
- package/dist/scripts/flyai-setup-tool-tests.js +54 -0
- package/dist/scripts/flyai-tests.js +692 -0
- package/dist/scripts/flyai-tool-registration-contract-tests.js +91 -0
- package/dist/scripts/fx-contract-tests.js +201 -0
- 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/geo-atlas-tests.js +283 -0
- package/dist/scripts/gotry-backend-kernel-tests.js +206 -0
- package/dist/scripts/gotry-try-demo-tests.js +79 -0
- package/dist/scripts/gotry-try-demo.js +49 -0
- package/dist/scripts/ground-transfer-tests.js +956 -0
- package/dist/scripts/hbcli-e2e-tests.js +159 -0
- 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 +121 -69
- package/dist/scripts/health-watch-cli.js +73 -0
- 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 +41 -0
- 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 +569 -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/issue436-persisted-routing-e2e.js +247 -0
- package/dist/scripts/itinerary-artifact-tests.js +368 -0
- package/dist/scripts/itinerary-deck-artifact-tests.js +416 -0
- package/dist/scripts/itinerary-deck-export-tests.js +552 -0
- package/dist/scripts/itinerary-deck-tests.js +435 -0
- package/dist/scripts/itinerary-html-tests.js +426 -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/lavish-local-tests.js +1226 -0
- package/dist/scripts/lavish-product-tools-tests.js +537 -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 +382 -246
- package/dist/scripts/ledger-workflow-crash.js +10 -20
- package/dist/scripts/managed-dsh-cleanup-diagnostic-proof.js +184 -0
- package/dist/scripts/managed-dsh-close-failure-proof.js +172 -0
- package/dist/scripts/managed-dsh-run-port-proof.js +153 -0
- package/dist/scripts/managed-dsh-terminal-proof.js +252 -0
- package/dist/scripts/map-tools-vendor-package-proof.js +365 -0
- 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 +631 -0
- package/dist/scripts/memory-value-tests.js +328 -0
- package/dist/scripts/metrics-report-tests.js +151 -0
- package/dist/scripts/model-override-e2e.js +137 -0
- package/dist/scripts/nightly-evidence-tests.js +161 -0
- package/dist/scripts/nightly-evidence.js +286 -0
- package/dist/scripts/nudge-digest.js +39 -28
- package/dist/scripts/observability-tests.js +381 -0
- package/dist/scripts/onboarding-tests.js +161 -0
- package/dist/scripts/opensky-check.js +18 -13
- package/dist/scripts/opensky-tests.js +28 -28
- package/dist/scripts/persona-surface-guard-tests.js +49 -0
- package/dist/scripts/pnpm-dsh-closure-proof.js +17 -0
- package/dist/scripts/policy-anchor-359-registered-e2e.js +214 -0
- package/dist/scripts/price-drift-tests.js +340 -0
- package/dist/scripts/price-drift-watch.js +447 -0
- package/dist/scripts/probe-poi-tests.js +53 -45
- package/dist/scripts/product-metrics.js +483 -0
- package/dist/scripts/publish-preverify.js +110 -0
- package/dist/scripts/realtime-pricing-tests.js +76 -0
- package/dist/scripts/recall-tests.js +513 -0
- package/dist/scripts/replay-async.js +20 -18
- package/dist/scripts/replay-real.js +18 -18
- package/dist/scripts/replay.js +52 -82
- package/dist/scripts/session-attach-diagnose.js +20 -20
- package/dist/scripts/session-attach-poc.js +34 -37
- package/dist/scripts/session-benchmark.js +180 -0
- package/dist/scripts/session-dida-live-e2e.js +199 -0
- package/dist/scripts/session-extract-tests.js +14 -35
- package/dist/scripts/session-link-tests.js +478 -0
- package/dist/scripts/session-login.js +27 -46
- package/dist/scripts/session-tests.js +796 -96
- package/dist/scripts/session-zones-tests.js +358 -0
- package/dist/scripts/sf-live-benchmark.js +367 -0
- package/dist/scripts/sf-live-challenge-stop-tests.js +453 -0
- package/dist/scripts/sf-live-cli-tests.js +92 -0
- package/dist/scripts/sf-live-options.js +46 -0
- package/dist/scripts/sf-manifest-tests.js +30 -0
- package/dist/scripts/sf-manifest.js +33 -0
- package/dist/scripts/sf-soft-score-tests.js +67 -0
- package/dist/scripts/sf-summary-tests.js +324 -0
- package/dist/scripts/sf-summary.js +525 -0
- package/dist/scripts/share-tests.js +432 -0
- package/dist/scripts/skeleton-check.js +16 -14
- package/dist/scripts/skeleton-integration-test.js +28 -11
- package/dist/scripts/skills-contract-tests.js +51 -46
- package/dist/scripts/smoke-session-gate-tests.js +21 -0
- package/dist/scripts/smoke.js +690 -246
- package/dist/scripts/spawn-bounded-abort-tests.js +241 -0
- package/dist/scripts/sponsor-reuse-tests.js +262 -0
- package/dist/scripts/state-cli-tests.js +226 -101
- package/dist/scripts/state-cli.js +550 -199
- package/dist/scripts/state-repair-cli.js +66 -0
- package/dist/scripts/state-repair-tests.js +140 -0
- package/dist/scripts/static-golden-tests.js +165 -0
- 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 +169 -0
- package/dist/scripts/turn-handoff-collect.js +161 -0
- package/dist/scripts/turn-policy-tests.js +55 -0
- package/dist/scripts/typed-contract-canary.js +176 -0
- 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 +62 -0
- package/dist/scripts/weather-tests.js +276 -41
- package/dist/scripts/wish-channel-gate-tests.js +54 -0
- 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 +41 -0
- package/dist/src/artifact-gate.js +829 -0
- package/dist/src/backend/kernel.js +91 -0
- package/dist/src/backend/modules/booking-copilot.js +92 -0
- package/dist/src/backend/modules/booking-executor.js +124 -0
- package/dist/src/backend/modules/session-search.js +551 -0
- package/dist/src/benchmark-agent-conformance.js +578 -0
- package/dist/src/benchmark-environment-bridge.js +515 -0
- package/dist/src/benchmark-headless-child-diagnostics.js +166 -0
- package/dist/src/benchmark-tool-isolation.js +151 -0
- package/dist/src/bookable-facts.js +533 -0
- package/dist/src/booking-saga.js +97 -0
- package/dist/src/booking-surface/availability-policy.js +697 -0
- package/dist/src/booking-surface/booking-intent.js +43 -0
- package/dist/src/booking-surface/cancel-refund-commission.js +379 -0
- package/dist/src/booking-surface/canonical-schema.js +116 -0
- package/dist/src/booking-surface/contracts.js +75 -0
- package/dist/src/booking-surface/dsh-planner.js +1854 -0
- package/dist/src/booking-surface/dsh-plugin.js +378 -0
- package/dist/src/booking-surface/dsh-worker.js +98 -0
- package/dist/src/booking-surface/error-codes.js +231 -0
- package/dist/src/booking-surface/index.js +9 -0
- package/dist/src/booking-surface/managed-dsh-cleanup-diagnostic.js +97 -0
- package/dist/src/booking-surface/managed-dsh-run-port.js +244 -0
- package/dist/src/booking-surface/profile.js +24 -0
- package/dist/src/booking-surface/recovery-chain.js +367 -0
- package/dist/src/booking-surface/runtime.js +1968 -0
- package/dist/src/booking-surface/server.js +674 -0
- package/dist/src/booking-surface/startup.js +168 -0
- package/dist/src/booking-surface/validation.js +261 -0
- 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 +97 -111
- package/dist/src/engine.js +276 -193
- package/dist/src/evaluation-cadence.js +97 -0
- package/dist/src/evaluation-contracts.js +283 -0
- package/dist/src/flight-pack-adapter.js +54 -0
- package/dist/src/flight-pack-contract.js +2 -0
- package/dist/src/flyai-setup-tool.js +70 -0
- package/dist/src/gotry-backend.js +125 -0
- package/dist/src/hotel-date-gate.js +118 -0
- package/dist/src/i18n.js +88 -0
- package/dist/src/index.js +2227 -882
- package/dist/src/itinerary-deck.js +139 -0
- package/dist/src/itinerary-doc-shared.js +661 -0
- package/dist/src/itinerary-html.js +131 -0
- package/dist/src/journey.js +155 -108
- package/dist/src/lavish-tools.js +400 -0
- package/dist/src/ledger-repair-apply.js +538 -0
- package/dist/src/ledger-repair-plan.js +463 -0
- package/dist/src/loop.js +319 -160
- 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 +103 -0
- package/dist/src/recall/card.js +74 -0
- package/dist/src/recall/evaluator.js +140 -0
- package/dist/src/recall/integration.js +17 -0
- package/dist/src/recall/tick.js +166 -0
- package/dist/src/session-link/plan-it-action.js +48 -0
- package/dist/src/session-link/session-link.js +248 -0
- package/dist/src/session-zones.js +507 -0
- package/dist/src/share/adapters.js +51 -0
- package/dist/src/share/share-consent.js +76 -0
- package/dist/src/share/share-deck.js +58 -0
- package/dist/src/share/share-token.js +146 -0
- package/dist/src/slot-spec.js +84 -106
- package/dist/src/state-ledger.js +435 -516
- package/dist/src/state-repair.js +299 -0
- 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 +287 -0
- package/dist/src/turn-policy.js +118 -0
- package/dist/src/tz-resolver.js +143 -0
- package/dist/src/unified.js +535 -359
- package/dist/src/wish-pool.js +42 -12
- package/dist/src/write-gate.js +495 -0
- package/dist/src/z3-shared.js +284 -0
- package/extension/README.md +21 -0
- package/extension/README.zh-CN.md +21 -0
- package/extension/background.js +463 -0
- package/extension/content-bridge.js +270 -0
- package/extension/content-main.js +111 -0
- package/extension/manifest.json +60 -0
- package/package.json +407 -14
- package/schemas/booking.intent.schema.json +193 -0
- package/schemas/booking.surface.schema.json +2622 -0
- package/ts/capabilities/agent-reach-deep.ts +114 -0
- package/ts/capabilities/agent-reach.ts +198 -0
- package/ts/capabilities/anything.ts +255 -0
- package/ts/capabilities/artifacts.ts +428 -0
- package/ts/capabilities/fact-log.ts +54 -0
- package/ts/capabilities/flyai-config.ts +388 -0
- package/ts/capabilities/flyai.ts +1274 -0
- package/ts/capabilities/hbcli.ts +253 -71
- package/ts/capabilities/incident-log.ts +88 -59
- package/ts/capabilities/itinerary-artifact.ts +214 -0
- package/ts/capabilities/itinerary-deck-artifact.ts +218 -0
- package/ts/capabilities/itinerary-deck-export.ts +378 -0
- package/ts/capabilities/opensky.ts +121 -0
- package/ts/capabilities/session/action-cache.ts +148 -0
- package/ts/capabilities/session/adapters/ctrip-flight.ts +181 -0
- package/ts/capabilities/session/adapters/ctrip-hotel.ts +238 -0
- package/ts/capabilities/session/adapters/dida-portal.ts +338 -0
- package/ts/capabilities/session/adapters/meituan-local.ts +70 -0
- package/ts/capabilities/session/adapters/rail-12306.ts +392 -0
- package/ts/capabilities/session/benchmark.ts +276 -0
- package/ts/capabilities/session/bridge-ledger.ts +333 -0
- package/ts/capabilities/session/extension-bridge.ts +794 -0
- package/ts/capabilities/session/extension-channel.ts +144 -0
- package/ts/capabilities/session/extension-distribution.ts +266 -0
- package/ts/capabilities/session/extract.ts +54 -0
- package/ts/capabilities/session/golden-score.ts +139 -0
- package/ts/capabilities/session/health-watch.ts +264 -0
- package/ts/capabilities/session/read-guard.ts +141 -0
- package/ts/capabilities/session/static-flight-golden.ts +209 -0
- package/ts/capabilities/session/transport.ts +146 -0
- package/ts/capabilities/session/wizard.ts +140 -0
- package/ts/capabilities/session-consent.ts +211 -0
- package/ts/capabilities/session-login.ts +208 -0
- package/ts/capabilities/session-search.ts +893 -0
- package/ts/capabilities/weather.ts +330 -0
- package/ts/dsh-runtime/vendor/README.md +68 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/LICENSE +21 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.en.md +405 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.md +404 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/client/client.js +1584 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/cordis.patch.yml +5 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/icon.svg +5 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/amap.js +595 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/nominatim.js +63 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/osrm.js +58 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/photon.js +55 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-file.js +87 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-route.js +131 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config.js +16 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/geo.js +232 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/index.js +120 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/settings-ns.js +40 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/staticmap-route.js +115 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/geocode.js +127 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/poi.js +84 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/routes.js +267 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/amap.d.ts +90 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/nominatim.d.ts +17 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/osrm.d.ts +15 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/photon.d.ts +22 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-file.d.ts +33 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-route.d.ts +23 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config.d.ts +23 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/geo.d.ts +61 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/index.d.ts +18 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/settings-ns.d.ts +14 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/staticmap-route.d.ts +31 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/geocode.d.ts +11 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/poi.d.ts +9 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/routes.d.ts +75 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/types.d.ts +68 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types.js +16 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/package.json +97 -0
- package/ts/package.json +293 -3
- package/ts/scripts/async-collect.ts +91 -0
- package/ts/scripts/map-tools-vendor-package-proof.ts +404 -0
- package/ts/scripts/skeleton-check.ts +1 -1
- package/ts/scripts/skeleton-integration-test.ts +23 -1
- package/ts/scripts/state-cli.ts +568 -0
- package/ts/scripts/turn-handoff-collect.ts +178 -0
- package/ts/src/artifact-gate.ts +991 -0
- package/ts/src/benchmark-agent-conformance.ts +619 -0
- package/ts/src/benchmark-environment-bridge.ts +538 -0
- package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
- package/ts/src/benchmark-tool-isolation.ts +166 -0
- package/ts/src/bookable-facts.ts +837 -0
- package/ts/src/booking-saga.ts +133 -0
- package/ts/src/booking-surface/availability-policy.ts +522 -0
- package/ts/src/booking-surface/booking-intent.ts +86 -0
- package/ts/src/booking-surface/cancel-refund-commission.ts +488 -0
- package/ts/src/booking-surface/canonical-schema.js +116 -0
- package/ts/src/booking-surface/contracts.ts +475 -0
- package/ts/src/booking-surface/dsh-planner.ts +1949 -0
- package/ts/src/booking-surface/dsh-plugin.js +378 -0
- package/ts/src/booking-surface/dsh-worker.ts +110 -0
- package/ts/src/booking-surface/error-codes.ts +241 -0
- package/ts/src/booking-surface/index.ts +9 -0
- package/ts/src/booking-surface/managed-dsh-cleanup-diagnostic.ts +151 -0
- package/ts/src/booking-surface/managed-dsh-run-port.ts +273 -0
- package/ts/src/booking-surface/profile.ts +42 -0
- package/ts/src/booking-surface/recovery-chain.ts +409 -0
- package/ts/src/booking-surface/runtime.ts +1793 -0
- package/ts/src/booking-surface/server.ts +733 -0
- package/ts/src/booking-surface/startup.ts +201 -0
- package/ts/src/booking-surface/validation.ts +217 -0
- package/ts/src/companions.ts +113 -0
- package/ts/src/contracts.ts +13 -3
- package/ts/src/dsh-llm.ts +44 -11
- package/ts/src/flyai-setup-tool.ts +77 -0
- package/ts/src/index.ts +1948 -198
- package/ts/src/itinerary-deck.ts +189 -0
- package/ts/src/itinerary-doc-shared.ts +741 -0
- package/ts/src/itinerary-html.ts +171 -0
- package/ts/src/loop.ts +223 -25
- package/ts/src/memory-capture.ts +283 -0
- package/ts/src/memory-decay.ts +55 -0
- package/ts/src/memory-utility.ts +70 -0
- package/ts/src/mock-llm.ts +4 -8
- package/ts/src/model.ts +88 -2
- package/ts/src/recall/card.ts +106 -0
- package/ts/src/recall/evaluator.ts +170 -0
- package/ts/src/recall/integration.ts +35 -0
- package/ts/src/recall/tick.ts +213 -0
- package/ts/src/session-link/plan-it-action.ts +78 -0
- package/ts/src/session-link/session-link.ts +275 -0
- package/ts/src/share/adapters.ts +93 -0
- package/ts/src/share/share-consent.ts +105 -0
- package/ts/src/share/share-deck.ts +85 -0
- package/ts/src/share/share-token.ts +166 -0
- package/ts/src/slot-spec.ts +172 -0
- package/ts/src/state-ledger.ts +912 -0
- package/ts/src/subagent-job-id-guard.ts +72 -0
- package/ts/src/time-anchor.ts +338 -0
- package/ts/src/tool-packet.ts +32 -0
- package/ts/src/travel-slots.ts +219 -0
- package/ts/src/travel-timeline.ts +83 -0
- package/ts/src/turn-deadline.ts +366 -0
- package/ts/src/turn-policy.ts +154 -0
- package/ts/src/unified.ts +354 -88
- package/ts/src/wish-pool.ts +79 -0
- package/dist/scripts/session-attach-wait.js +0 -41
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M4 memory value scorer contract tests(issue #223).
|
|
3
|
+
*
|
|
4
|
+
* Focus:
|
|
5
|
+
* - frozen M4 thresholds (N>=5, median reduction >=0.5) cannot be weakened
|
|
6
|
+
* - public synthetic fixture keeps correct calculations but never closes M4
|
|
7
|
+
* - observed_private is only a candidate without a human source-review attestation
|
|
8
|
+
* - manual attestation is bound to the current scoring payload digest
|
|
9
|
+
* - root/nested unknown fields and PII-like values are rejected without echoing attacker keys/values
|
|
10
|
+
* - all id refs use hmac-sha256:<64lowerhex>; chronology/waits/duplicates/P4/preference guards fail closed
|
|
11
|
+
*/
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
14
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { tmpdir } from 'node:os';
|
|
17
|
+
import { memoryValueSummaryDigest, scoreMemoryValue } from './memory-value-report.js';
|
|
18
|
+
const fixture = JSON.parse(readFileSync('data/memory-value-fixture.json', 'utf8'));
|
|
19
|
+
const hmac = (n) => `hmac-sha256:${n.toString(16).padStart(64, '0')}`;
|
|
20
|
+
let passed = 0;
|
|
21
|
+
function ok(label) {
|
|
22
|
+
passed += 1;
|
|
23
|
+
console.log(` ok ${label}`);
|
|
24
|
+
}
|
|
25
|
+
function clone(value) {
|
|
26
|
+
return structuredClone(value);
|
|
27
|
+
}
|
|
28
|
+
function asText(value) {
|
|
29
|
+
return JSON.stringify(value);
|
|
30
|
+
}
|
|
31
|
+
function assertInvalid(value, label) {
|
|
32
|
+
const report = scoreMemoryValue(value);
|
|
33
|
+
assert.equal(report.contract_valid, false, label);
|
|
34
|
+
assert.equal(report.exit_ready, false, label);
|
|
35
|
+
}
|
|
36
|
+
function observedCopy() {
|
|
37
|
+
const payload = clone(fixture);
|
|
38
|
+
payload.evidence_kind = 'observed_private';
|
|
39
|
+
return payload;
|
|
40
|
+
}
|
|
41
|
+
function manualAttestation(payload) {
|
|
42
|
+
return {
|
|
43
|
+
schema_version: 'memory_value_source_review.v1',
|
|
44
|
+
state: 'manual_attested',
|
|
45
|
+
reviewed_at: '2026-09-08T00:00:00Z',
|
|
46
|
+
reviewer_ref: hmac(9001),
|
|
47
|
+
attestation_ref: hmac(9002),
|
|
48
|
+
private_source_digest_sha256: 'a'.repeat(64),
|
|
49
|
+
reviewed_summary_digest_sha256: memoryValueSummaryDigest(payload),
|
|
50
|
+
checks: {
|
|
51
|
+
raw_private_material_excluded: true,
|
|
52
|
+
paired_cohort_source_reviewed: true,
|
|
53
|
+
summary_matches_private_source: true,
|
|
54
|
+
no_synthetic_or_test_subjects: true,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function attest(payload) {
|
|
59
|
+
payload.source_review = manualAttestation(payload);
|
|
60
|
+
return payload;
|
|
61
|
+
}
|
|
62
|
+
function setPairDurations(payload, firstMs, returningMs) {
|
|
63
|
+
for (const [index, pair] of payload.pairs.entries()) {
|
|
64
|
+
const firstStartedAt = Date.UTC(2026, 8, 1 + index, 10, 0, 0, 0);
|
|
65
|
+
const returningStartedAt = Date.UTC(2026, 8, 8 + index, 10, 0, 0, 0);
|
|
66
|
+
pair.first.started_at = new Date(firstStartedAt).toISOString();
|
|
67
|
+
pair.first.completed_at = new Date(firstStartedAt + firstMs).toISOString();
|
|
68
|
+
pair.first.external_waits = [];
|
|
69
|
+
pair.returning.started_at = new Date(returningStartedAt).toISOString();
|
|
70
|
+
pair.returning.completed_at = new Date(returningStartedAt + returningMs).toISOString();
|
|
71
|
+
pair.returning.external_waits = [];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function runCli(input) {
|
|
75
|
+
const root = mkdtempSync(join(tmpdir(), 'gotry-memory-value-'));
|
|
76
|
+
const path = join(root, 'input.json');
|
|
77
|
+
writeFileSync(path, JSON.stringify(input), 'utf8');
|
|
78
|
+
const result = spawnSync('npx', ['tsx', 'scripts/memory-value-report.ts', path], {
|
|
79
|
+
cwd: process.cwd(),
|
|
80
|
+
encoding: 'utf8',
|
|
81
|
+
});
|
|
82
|
+
let report;
|
|
83
|
+
try {
|
|
84
|
+
report = JSON.parse(result.stdout);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
rmSync(root, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
return { status: result.status, stdout: result.stdout, stderr: result.stderr, report };
|
|
90
|
+
}
|
|
91
|
+
function runMalformedCli(contents) {
|
|
92
|
+
const root = mkdtempSync(join(tmpdir(), 'privacy-sentinel-path-'));
|
|
93
|
+
const path = join(root, 'privacy-sentinel-input.json');
|
|
94
|
+
writeFileSync(path, contents, 'utf8');
|
|
95
|
+
const result = spawnSync('npx', ['tsx', 'scripts/memory-value-report.ts', path], {
|
|
96
|
+
cwd: process.cwd(),
|
|
97
|
+
encoding: 'utf8',
|
|
98
|
+
});
|
|
99
|
+
rmSync(root, { recursive: true, force: true });
|
|
100
|
+
return { status: result.status, stdout: result.stdout, stderr: result.stderr };
|
|
101
|
+
}
|
|
102
|
+
// ---- 1. synthetic fixture: metric-positive but business-ineligible ----
|
|
103
|
+
const synthetic = scoreMemoryValue(fixture);
|
|
104
|
+
assert.equal(synthetic.contract_valid, true);
|
|
105
|
+
assert.equal(synthetic.cohort.eligible_pair_count, 5);
|
|
106
|
+
assert.deepEqual(synthetic.cohort.first_active_seconds, { p50: 720, p75: 900 });
|
|
107
|
+
assert.deepEqual(synthetic.cohort.returning_active_seconds, { p50: 360, p75: 450 });
|
|
108
|
+
assert.deepEqual(synthetic.cohort.paired_reduction_ratio, { p50: 0.5, p75: 0.5 });
|
|
109
|
+
assert.equal(synthetic.cohort.minimum_pair_count_for_exit, 5);
|
|
110
|
+
assert.equal(synthetic.cohort.target_median_reduction_ratio, 0.5);
|
|
111
|
+
assert.equal(synthetic.cohort.sample_size_met, true);
|
|
112
|
+
assert.equal(synthetic.cohort.target_met, true);
|
|
113
|
+
assert.equal(synthetic.experience_reflux.baseline, 0.5);
|
|
114
|
+
assert.equal(synthetic.preference_assertions.traceable_ratio, 1);
|
|
115
|
+
assert.equal(synthetic.preference_assertions.hard_filter_violation_count, 0);
|
|
116
|
+
assert.equal(synthetic.p4.contract_met, true);
|
|
117
|
+
assert.equal(synthetic.source.source_review.contract_met, false);
|
|
118
|
+
assert.equal(synthetic.exit_evidence_eligible, false);
|
|
119
|
+
assert.equal(synthetic.exit_ready, false);
|
|
120
|
+
ok('synthetic fixture N=5/0.5 指标通过但不可作为 M4 Exit 证据');
|
|
121
|
+
// ---- 2. legal manual_attested observed-private positive path ----
|
|
122
|
+
const manualPositive = attest(observedCopy());
|
|
123
|
+
const manualPositiveReport = scoreMemoryValue(manualPositive);
|
|
124
|
+
assert.equal(manualPositiveReport.contract_valid, true);
|
|
125
|
+
assert.equal(manualPositiveReport.source.source_review.contract_met, true);
|
|
126
|
+
assert.equal(manualPositiveReport.source.source_review.provenance_verified_by_scorer, false);
|
|
127
|
+
assert.equal(manualPositiveReport.source.source_review.reviewed_summary_digest_sha256, memoryValueSummaryDigest(manualPositive));
|
|
128
|
+
assert.equal(manualPositiveReport.source.source_review.current_summary_digest_sha256, memoryValueSummaryDigest(manualPositive));
|
|
129
|
+
assert.equal(manualPositiveReport.source.source_review.reviewer_ref, hmac(9001));
|
|
130
|
+
assert.equal(manualPositiveReport.source.source_review.attestation_ref, hmac(9002));
|
|
131
|
+
assert.equal(manualPositiveReport.experience_reflux.real_evidence, true);
|
|
132
|
+
assert.equal(manualPositiveReport.exit_evidence_eligible, true);
|
|
133
|
+
assert.equal(manualPositiveReport.exit_ready, true);
|
|
134
|
+
ok('合法 manual_attested observed_private 在数字门槛与人工声明齐备时可达 ready');
|
|
135
|
+
// ---- 3. observed_private without provenance remains candidate despite passing metrics ----
|
|
136
|
+
const candidate = observedCopy();
|
|
137
|
+
candidate.source_review = {
|
|
138
|
+
schema_version: 'memory_value_source_review.v1',
|
|
139
|
+
state: 'candidate',
|
|
140
|
+
reviewed_at: null,
|
|
141
|
+
reviewer_ref: null,
|
|
142
|
+
attestation_ref: null,
|
|
143
|
+
private_source_digest_sha256: null,
|
|
144
|
+
reviewed_summary_digest_sha256: null,
|
|
145
|
+
checks: {
|
|
146
|
+
raw_private_material_excluded: true,
|
|
147
|
+
paired_cohort_source_reviewed: true,
|
|
148
|
+
summary_matches_private_source: true,
|
|
149
|
+
no_synthetic_or_test_subjects: false,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const candidateReport = scoreMemoryValue(candidate);
|
|
153
|
+
assert.equal(candidateReport.contract_valid, true);
|
|
154
|
+
assert.equal(candidateReport.cohort.sample_size_met, true);
|
|
155
|
+
assert.equal(candidateReport.cohort.target_met, true);
|
|
156
|
+
assert.equal(candidateReport.source.evidence_kind, 'observed_private');
|
|
157
|
+
assert.equal(candidateReport.source.source_review.required_for_exit, true);
|
|
158
|
+
assert.equal(candidateReport.source.source_review.contract_met, false);
|
|
159
|
+
assert.equal(candidateReport.source.source_review.provenance_verified_by_scorer, false);
|
|
160
|
+
assert.equal(candidateReport.experience_reflux.real_evidence, false);
|
|
161
|
+
assert.equal(candidateReport.exit_evidence_eligible, false);
|
|
162
|
+
assert.equal(candidateReport.exit_ready, false);
|
|
163
|
+
ok('observed_private 缺人工 source-review attestation 时只可作为 candidate');
|
|
164
|
+
// ---- 4. attestation digest binds the current scoring payload ----
|
|
165
|
+
const staleAttestation = attest(observedCopy());
|
|
166
|
+
staleAttestation.pairs[0].returning.completed_at = '2026-08-08T10:07:00Z';
|
|
167
|
+
const staleAttestationReport = scoreMemoryValue(staleAttestation);
|
|
168
|
+
assert.equal(staleAttestationReport.contract_valid, false);
|
|
169
|
+
assert.equal(staleAttestationReport.exit_ready, false);
|
|
170
|
+
assert.match(asText(staleAttestationReport.errors), /reviewed_summary_digest_sha256/);
|
|
171
|
+
assert.notEqual(staleAttestation.source_review.reviewed_summary_digest_sha256, memoryValueSummaryDigest(staleAttestation));
|
|
172
|
+
ok('manual attestation 的 reviewed_summary_digest 绑定本次评分 payload,改 summary 后旧 attestation 失效');
|
|
173
|
+
// ---- 5. raw ratio threshold: report may round to 0.5, comparison must not ----
|
|
174
|
+
const exactHalf = observedCopy();
|
|
175
|
+
setPairDurations(exactHalf, 2_000_000, 1_000_000);
|
|
176
|
+
attest(exactHalf);
|
|
177
|
+
const exactHalfReport = scoreMemoryValue(exactHalf);
|
|
178
|
+
assert.equal(exactHalfReport.contract_valid, true);
|
|
179
|
+
assert.equal(exactHalfReport.cohort.paired_reduction_ratio.p50, 0.5);
|
|
180
|
+
assert.equal(exactHalfReport.cohort.target_met, true);
|
|
181
|
+
assert.equal(exactHalfReport.exit_ready, true);
|
|
182
|
+
const justUnderHalf = observedCopy();
|
|
183
|
+
setPairDurations(justUnderHalf, 2_000_001, 1_000_001);
|
|
184
|
+
attest(justUnderHalf);
|
|
185
|
+
const justUnderHalfReport = scoreMemoryValue(justUnderHalf);
|
|
186
|
+
assert.equal(justUnderHalfReport.contract_valid, true);
|
|
187
|
+
assert.equal(justUnderHalfReport.cohort.paired_reduction_ratio.p50, 0.5);
|
|
188
|
+
assert.equal(justUnderHalfReport.cohort.target_met, false);
|
|
189
|
+
assert.equal(justUnderHalfReport.exit_ready, false);
|
|
190
|
+
ok('raw ratio 比较:exact 50% 通过,49.999975% 即使展示 round 到 50% 仍未达标');
|
|
191
|
+
// ---- 6. original exploit: self-declared observed, N=1, target=0, email ids, undeclared fields ----
|
|
192
|
+
const exploit = clone(fixture);
|
|
193
|
+
exploit.evidence_kind = 'observed_private';
|
|
194
|
+
delete exploit.source_review;
|
|
195
|
+
exploit.attacker_note = 'self-declared observed';
|
|
196
|
+
exploit.user_email = 'victim@example.com';
|
|
197
|
+
exploit.measurement_policy.minimum_pair_count_for_exit = 1;
|
|
198
|
+
exploit.measurement_policy.target_median_reduction_ratio = 0;
|
|
199
|
+
exploit.pairs = [exploit.pairs[0]];
|
|
200
|
+
exploit.pairs[0].subject_ref = 'victim@example.com';
|
|
201
|
+
exploit.pairs[0].returning.raw_transcript = 'PII leak field';
|
|
202
|
+
const exploitReport = scoreMemoryValue(exploit);
|
|
203
|
+
assert.equal(exploitReport.contract_valid, false);
|
|
204
|
+
assert.equal(exploitReport.exit_ready, false);
|
|
205
|
+
const exploitText = asText(exploitReport);
|
|
206
|
+
assert.doesNotMatch(exploitText, /victim@example\.com/);
|
|
207
|
+
assert.doesNotMatch(exploitText, /attacker_note/);
|
|
208
|
+
assert.doesNotMatch(exploitText, /raw_transcript/);
|
|
209
|
+
assert.doesNotMatch(exploitText, /PII leak field/);
|
|
210
|
+
ok('原反例红:observed 自报+降阈+明文邮箱+未知字段 fail-closed 且不回显攻击者 key/value');
|
|
211
|
+
// ---- 7. frozen policy and HMAC id format ----
|
|
212
|
+
const relaxedPolicy = clone(fixture);
|
|
213
|
+
relaxedPolicy.measurement_policy.minimum_pair_count_for_exit = 1;
|
|
214
|
+
relaxedPolicy.measurement_policy.target_median_reduction_ratio = 0.49;
|
|
215
|
+
assertInvalid(relaxedPolicy, 'weakened M4 threshold must be invalid');
|
|
216
|
+
const nonHmacIds = clone(fixture);
|
|
217
|
+
nonHmacIds.pairs[0].pair_id = 'pair-a';
|
|
218
|
+
nonHmacIds.pairs[0].subject_ref = 'user@example.com';
|
|
219
|
+
nonHmacIds.pairs[0].first.flow_id = 'flow-a-first';
|
|
220
|
+
nonHmacIds.experience_reflux_events[0].experience_id = 'experience-a';
|
|
221
|
+
nonHmacIds.experience_reflux_events[0].evidence_ref = 'fixture:evidence';
|
|
222
|
+
nonHmacIds.preference_assertions[0].assertion_id = 'preference-a';
|
|
223
|
+
nonHmacIds.preference_assertions[0].evidence_ref = 'raw evidence ref';
|
|
224
|
+
assertInvalid(nonHmacIds, 'all ids/refs must be hmac-sha256 pseudonyms');
|
|
225
|
+
ok('M4 阈值冻结且 subject/flow/pair/experience/assertion/evidence ref 均要求 HMAC');
|
|
226
|
+
// ---- 8. strict timestamps, first/return chronology, and wait interval guard ----
|
|
227
|
+
const invalidDate = clone(fixture);
|
|
228
|
+
invalidDate.pairs[0].first.started_at = '2026-02-30T10:00:00Z';
|
|
229
|
+
assertInvalid(invalidDate, 'invalid calendar date must be rejected');
|
|
230
|
+
const nonIsoDate = clone(fixture);
|
|
231
|
+
nonIsoDate.pairs[0].first.started_at = '2026-08-01 10:00:00';
|
|
232
|
+
assertInvalid(nonIsoDate, 'non-ISO timestamp must be rejected');
|
|
233
|
+
const reversedReturn = clone(fixture);
|
|
234
|
+
reversedReturn.pairs[0].returning.started_at = '2026-07-31T10:00:00Z';
|
|
235
|
+
reversedReturn.pairs[0].returning.completed_at = '2026-07-31T10:08:00Z';
|
|
236
|
+
reversedReturn.pairs[0].returning.external_waits = [];
|
|
237
|
+
assertInvalid(reversedReturn, 'returning flow must follow first flow');
|
|
238
|
+
const outsideWait = clone(fixture);
|
|
239
|
+
outsideWait.pairs[0].returning.external_waits[0].started_at = '2026-08-08T09:59:00Z';
|
|
240
|
+
assertInvalid(outsideWait, 'external wait must stay inside flow');
|
|
241
|
+
const overlappingWait = clone(fixture);
|
|
242
|
+
overlappingWait.pairs[0].returning.external_waits.push({
|
|
243
|
+
code: 'tool_latency',
|
|
244
|
+
started_at: '2026-08-08T10:05:00Z',
|
|
245
|
+
completed_at: '2026-08-08T10:07:00Z',
|
|
246
|
+
});
|
|
247
|
+
assertInvalid(overlappingWait, 'external waits must not overlap');
|
|
248
|
+
ok('严格 ISO 日期、首返时序、等待区间与不重叠守卫');
|
|
249
|
+
// ---- 9. duplicate pair/subject/flow and reflux/assertion pairing; preference evidence_ref may be reused ----
|
|
250
|
+
const duplicatePair = clone(fixture);
|
|
251
|
+
duplicatePair.pairs[1].pair_id = duplicatePair.pairs[0].pair_id;
|
|
252
|
+
assertInvalid(duplicatePair, 'pair ids must be unique');
|
|
253
|
+
const duplicateSubject = clone(fixture);
|
|
254
|
+
duplicateSubject.pairs[1].subject_ref = duplicateSubject.pairs[0].subject_ref;
|
|
255
|
+
assertInvalid(duplicateSubject, 'subjects must be unique');
|
|
256
|
+
const duplicateFlow = clone(fixture);
|
|
257
|
+
duplicateFlow.pairs[1].first.flow_id = duplicateFlow.pairs[0].first.flow_id;
|
|
258
|
+
assertInvalid(duplicateFlow, 'flow ids must be globally unique');
|
|
259
|
+
const duplicateReflux = clone(fixture);
|
|
260
|
+
duplicateReflux.experience_reflux_events.push({
|
|
261
|
+
experience_id: duplicateReflux.experience_reflux_events[0].experience_id,
|
|
262
|
+
kind: duplicateReflux.experience_reflux_events[0].kind,
|
|
263
|
+
evidence_ref: hmac(604),
|
|
264
|
+
});
|
|
265
|
+
assertInvalid(duplicateReflux, 'same experience/kind reflux event must not duplicate');
|
|
266
|
+
const unpairedVerified = clone(fixture);
|
|
267
|
+
unpairedVerified.experience_reflux_events.push({ experience_id: hmac(599), kind: 'verified_outcome', evidence_ref: hmac(605) });
|
|
268
|
+
assertInvalid(unpairedVerified, 'verified outcome must have recalled event');
|
|
269
|
+
const duplicateAssertion = clone(fixture);
|
|
270
|
+
duplicateAssertion.preference_assertions[1].assertion_id = duplicateAssertion.preference_assertions[0].assertion_id;
|
|
271
|
+
assertInvalid(duplicateAssertion, 'assertion ids must be unique');
|
|
272
|
+
const sharedPreferenceEvidence = clone(fixture);
|
|
273
|
+
sharedPreferenceEvidence.preference_assertions[1].evidence_ref = sharedPreferenceEvidence.preference_assertions[0].evidence_ref;
|
|
274
|
+
const sharedPreferenceEvidenceReport = scoreMemoryValue(sharedPreferenceEvidence);
|
|
275
|
+
assert.equal(sharedPreferenceEvidenceReport.contract_valid, true);
|
|
276
|
+
assert.equal(sharedPreferenceEvidenceReport.preference_assertions.contract_met, true);
|
|
277
|
+
ok('重复 pair/subject/flow、回流重复/配对、断言重复 fail-closed;preference evidence_ref 可合法复用');
|
|
278
|
+
// ---- 10. explicit hard_filter bool, consumer enum, and P4 bool/state ----
|
|
279
|
+
const hardFilter = clone(fixture);
|
|
280
|
+
hardFilter.preference_assertions[0].hard_filter = true;
|
|
281
|
+
const hardFilterReport = scoreMemoryValue(hardFilter);
|
|
282
|
+
assert.equal(hardFilterReport.contract_valid, true);
|
|
283
|
+
assert.equal(hardFilterReport.preference_assertions.hard_filter_violation_count, 1);
|
|
284
|
+
assert.equal(hardFilterReport.preference_assertions.contract_met, false);
|
|
285
|
+
assert.equal(hardFilterReport.exit_ready, false);
|
|
286
|
+
const hardFilterConsumer = clone(fixture);
|
|
287
|
+
hardFilterConsumer.preference_assertions[0].consumer = 'hard_filter';
|
|
288
|
+
const hardFilterConsumerReport = scoreMemoryValue(hardFilterConsumer);
|
|
289
|
+
assert.equal(hardFilterConsumerReport.contract_valid, true);
|
|
290
|
+
assert.equal(hardFilterConsumerReport.preference_assertions.hard_filter_violation_count, 1);
|
|
291
|
+
assert.equal(hardFilterConsumerReport.preference_assertions.contract_met, false);
|
|
292
|
+
const missingHardFilterBool = clone(fixture);
|
|
293
|
+
missingHardFilterBool.preference_assertions[0].hard_filter = 'false';
|
|
294
|
+
assertInvalid(missingHardFilterBool, 'hard_filter must be explicit boolean');
|
|
295
|
+
const badConsumer = clone(fixture);
|
|
296
|
+
badConsumer.preference_assertions[0].consumer = 'prompt';
|
|
297
|
+
assertInvalid(badConsumer, 'consumer must be declared enum');
|
|
298
|
+
const earlyP4 = clone(fixture);
|
|
299
|
+
earlyP4.p4.state = 'open';
|
|
300
|
+
const earlyP4Report = scoreMemoryValue(earlyP4);
|
|
301
|
+
assert.equal(earlyP4Report.contract_valid, true);
|
|
302
|
+
assert.equal(earlyP4Report.p4.contract_met, false);
|
|
303
|
+
assert.equal(earlyP4Report.exit_ready, false);
|
|
304
|
+
const badP4Bool = clone(fixture);
|
|
305
|
+
badP4Bool.p4.triggers.real_usage = 'false';
|
|
306
|
+
assertInvalid(badP4Bool, 'P4 triggers must be boolean');
|
|
307
|
+
const badP4State = clone(fixture);
|
|
308
|
+
badP4State.p4.state = 'paused';
|
|
309
|
+
assertInvalid(badP4State, 'P4 state must be declared enum');
|
|
310
|
+
ok('偏好硬过滤、consumer enum、显式 bool 与 P4 状态/触发守卫');
|
|
311
|
+
// ---- 11. CLI E2E: isolated JSON input -> report + exit code; malformed JSON never echoes private text/path ----
|
|
312
|
+
const cliSynthetic = runCli(fixture);
|
|
313
|
+
assert.equal(cliSynthetic.status, 0);
|
|
314
|
+
assert.equal(cliSynthetic.report.contract_valid, true);
|
|
315
|
+
assert.equal(cliSynthetic.report.exit_ready, false);
|
|
316
|
+
const cliExploit = runCli(exploit);
|
|
317
|
+
assert.equal(cliExploit.status, 2);
|
|
318
|
+
assert.equal(cliExploit.report.contract_valid, false);
|
|
319
|
+
assert.equal(cliExploit.report.exit_ready, false);
|
|
320
|
+
const cliExploitText = asText(cliExploit.report);
|
|
321
|
+
assert.doesNotMatch(cliExploitText, /victim@example\.com|attacker_note|raw_transcript|PII leak field/);
|
|
322
|
+
const malformed = runMalformedCli('{"schema":"privacy-sentinel-value", "unterminated": ');
|
|
323
|
+
assert.equal(malformed.status, 2);
|
|
324
|
+
assert.equal(malformed.stdout, '');
|
|
325
|
+
assert.match(malformed.stderr, /MEMORY_VALUE_INPUT_INVALID/);
|
|
326
|
+
assert.doesNotMatch(`${malformed.stdout}\n${malformed.stderr}`, /privacy-sentinel/);
|
|
327
|
+
ok('CLI E2E:隔离 synthetic/恶意/畸形 JSON 输入产生确定 exit 且不回显私有值或路径');
|
|
328
|
+
console.log(`memory-value tests: ${passed} 组断言全绿(严格 schema/source-review digest/raw ratio/PII fail-closed)`);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #138 指标面板第一切片测试(全离线,隔离 mkdtemp stateRoot;绝不触真实状态目录):
|
|
3
|
+
* 聚合正确性(去重/blocked 率/窗口过滤/百分位)、坏行容忍、空根成型、只读纪律
|
|
4
|
+
* (collect 前后目录条目集合不变)、--out 落盘形态。
|
|
5
|
+
*/
|
|
6
|
+
import { strict as assert } from 'node:assert';
|
|
7
|
+
import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { aggregateFacts, aggregateChannels, aggregateIncidents, aggregateLatency, collectMetrics, renderMetricsReport, main } from './build-metrics-report.js';
|
|
11
|
+
// fixture 时间戳必须相对真实时钟:聚合器(main)按真实 now 取 --days 窗口,
|
|
12
|
+
// 硬编码绝对日期会随日历自然老化出窗(2026-09-11 起 iso(1) 跌出 7 天窗,§6 假红)。
|
|
13
|
+
const DAY = 86_400_000;
|
|
14
|
+
const NOW = new Date(Date.now() - 1 * DAY);
|
|
15
|
+
const iso = (daysAgo) => new Date(NOW.getTime() - daysAgo * DAY).toISOString();
|
|
16
|
+
let checkCount = 0;
|
|
17
|
+
function check(name, fn) {
|
|
18
|
+
fn();
|
|
19
|
+
checkCount += 1;
|
|
20
|
+
console.log(` ok ${checkCount} ${name}`);
|
|
21
|
+
}
|
|
22
|
+
async function withRoot(fn) {
|
|
23
|
+
const root = mkdtempSync(join(tmpdir(), 'gotry-metrics-'));
|
|
24
|
+
const stateDir = join(root, 'gotry-state');
|
|
25
|
+
mkdirSync(stateDir, { recursive: true });
|
|
26
|
+
try {
|
|
27
|
+
return await fn(root, stateDir);
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
rmSync(root, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function writeJsonl(dir, name, lines) {
|
|
34
|
+
writeFileSync(join(dir, name), lines.map((l) => (typeof l === 'string' ? l : JSON.stringify(l))).join('\n') + '\n', 'utf-8');
|
|
35
|
+
}
|
|
36
|
+
// 1. 事实闸:同 fact_id 取最新 + 坏行跳过 + blocked 率
|
|
37
|
+
check('事实闸聚合:去重/blocked 率/坏行容忍', () => {
|
|
38
|
+
const stats = aggregateFacts([
|
|
39
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'f1', kind: 'flight_like', verdict: 'hit' },
|
|
40
|
+
'NOT JSON',
|
|
41
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'f1', kind: 'flight_like', verdict: 'error' }, // 重查后翻转为 error,后者胜
|
|
42
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'f2', kind: 'flight_like', verdict: 'hit' },
|
|
43
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'f3', kind: 'hotel', verdict: 'needs-setup' },
|
|
44
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'f4', kind: 'hotel', verdict: 'miss' },
|
|
45
|
+
{ fact_id: 'f5', kind: 'hotel' }, // 无 verdict → n/a 桶,不计 blocked
|
|
46
|
+
]);
|
|
47
|
+
assert.equal(stats.lines, 7);
|
|
48
|
+
assert.equal(stats.deduped, 5);
|
|
49
|
+
const flight = stats.byKind.flight_like;
|
|
50
|
+
assert.equal(flight.total, 2);
|
|
51
|
+
assert.equal(flight.verdicts.error, 1);
|
|
52
|
+
assert.equal(flight.verdicts.hit, 1);
|
|
53
|
+
assert.equal(flight.blocked, 1);
|
|
54
|
+
const hotel = stats.byKind.hotel;
|
|
55
|
+
assert.equal(hotel.total, 3);
|
|
56
|
+
assert.equal(hotel.blocked, 1);
|
|
57
|
+
assert.equal(hotel.verdicts['n/a'], 1);
|
|
58
|
+
});
|
|
59
|
+
// 2. 通道健康:窗口过滤 + 每通道最新 + 事件计数
|
|
60
|
+
check('通道健康聚合:30 天窗/最新事件/计数', () => {
|
|
61
|
+
const stats = aggregateChannels([
|
|
62
|
+
{ channel: 'flyai', state: 'down', reason: 'trial-exhausted', at: iso(40) }, // 窗外 → 滤掉
|
|
63
|
+
{ channel: 'flyai', state: 'down', reason: '429', at: iso(2) },
|
|
64
|
+
{ channel: 'flyai', state: 'cooldown', reason: 'retry-after', at: iso(1) }, // 更新 → 最新
|
|
65
|
+
{ channel: 'session:ctrip-hotel', state: 'down', reason: 'needs-login', at: iso(5) },
|
|
66
|
+
'BROKEN',
|
|
67
|
+
], { now: NOW });
|
|
68
|
+
assert.equal(stats.latest.length, 2);
|
|
69
|
+
const flyai = stats.latest.find((c) => c.channel === 'flyai');
|
|
70
|
+
assert.equal(flyai?.state, 'cooldown');
|
|
71
|
+
assert.equal(flyai?.events, 2);
|
|
72
|
+
const ctrip = stats.latest.find((c) => c.channel === 'session:ctrip-hotel');
|
|
73
|
+
assert.equal(ctrip?.events, 1);
|
|
74
|
+
});
|
|
75
|
+
// 3. 事故面:窗口过滤 + byKind + 最近一条 + top 来源
|
|
76
|
+
check('事故面聚合:窗口/kind 计数/最近一条/top 来源', () => {
|
|
77
|
+
const stats = aggregateIncidents([
|
|
78
|
+
{ ts: iso(10), kind: 'uncaughtException', message: '太旧不计', source: 'old-plugin' },
|
|
79
|
+
{ ts: iso(1), kind: 'plugin_error', message: 'z3 wasm boom', source: 'z3' },
|
|
80
|
+
{ ts: iso(0.2), kind: 'plugin_error', message: 'second boom', source: 'z3' },
|
|
81
|
+
{ ts: iso(0.1), kind: 'tool_execute_error', message: 'flyai 429', source: 'flyai' },
|
|
82
|
+
], { now: NOW, windowDays: 7 });
|
|
83
|
+
assert.equal(stats.totalInWindow, 3);
|
|
84
|
+
assert.equal(stats.byKind.plugin_error.count, 2);
|
|
85
|
+
assert.equal(stats.byKind.plugin_error.lastMessage, 'second boom');
|
|
86
|
+
assert.deepEqual(stats.topSources[0], { source: 'z3', count: 2 });
|
|
87
|
+
});
|
|
88
|
+
// 4. 桥延迟:百分位与超预算计数
|
|
89
|
+
check('桥延迟聚合:p50/p95/max/超预算', () => {
|
|
90
|
+
const stats = aggregateLatency([
|
|
91
|
+
{ ts: iso(1), kind: 'hotel_search:hbcli', latencyMs: 100 },
|
|
92
|
+
{ ts: iso(1), kind: 'hotel_search:hbcli', latencyMs: 200 },
|
|
93
|
+
{ ts: iso(0.5), kind: 'weather:open-meteo', latencyMs: 300 },
|
|
94
|
+
{ ts: iso(0.4), kind: 'weather:open-meteo', latencyMs: 400 },
|
|
95
|
+
{ ts: iso(0.3), kind: 'hotel_search:session', latencyMs: 501 }, // 超预算
|
|
96
|
+
{ ts: iso(9), kind: 'old', latencyMs: 999_999 }, // 窗外
|
|
97
|
+
{ ts: iso(0.2), kind: 'bad', latencyMs: Number.NaN }, // 非数 → 跳过
|
|
98
|
+
], { now: NOW, windowDays: 7 });
|
|
99
|
+
assert.equal(stats.count, 5);
|
|
100
|
+
assert.equal(stats.p50, 300);
|
|
101
|
+
assert.equal(stats.p95, 501);
|
|
102
|
+
assert.equal(stats.max, 501);
|
|
103
|
+
assert.equal(stats.overBudget, 1);
|
|
104
|
+
assert.deepEqual(stats.topKinds[0], { kind: 'hotel_search:hbcli', count: 2 });
|
|
105
|
+
});
|
|
106
|
+
// 5. 空根:collect+render 成型、零写入
|
|
107
|
+
await withRoot(async (root) => {
|
|
108
|
+
const before = readdirSync(root).sort();
|
|
109
|
+
const snap = await collectMetrics(root, { now: NOW });
|
|
110
|
+
const md = renderMetricsReport(snap);
|
|
111
|
+
assert.match(md, /事实闸 verdict 分布/);
|
|
112
|
+
assert.match(md, /通道健康/);
|
|
113
|
+
assert.match(md, /事故面/);
|
|
114
|
+
assert.match(md, /桥延迟/);
|
|
115
|
+
assert.match(md, /\(空:窗口内无事故\)/);
|
|
116
|
+
assert.match(md, /不存在\(该 stateRoot 无账本\)/);
|
|
117
|
+
assert.deepEqual(readdirSync(root).sort(), before, 'collect 不得在 stateRoot 新建任何文件');
|
|
118
|
+
checkCount += 1;
|
|
119
|
+
console.log(` ok ${checkCount} 空 stateRoot:报告成型且零写入`);
|
|
120
|
+
});
|
|
121
|
+
// 6. 全量端到端:写各侧车 → 聚合进报告;--out 落盘;gotry-state 目录零改动
|
|
122
|
+
await withRoot(async (root, stateDir) => {
|
|
123
|
+
writeJsonl(stateDir, 'bookable-facts.jsonl', [
|
|
124
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'a', kind: 'hotel', verdict: 'hit' },
|
|
125
|
+
{ schema: 'gotry_bookable_fact.v1', fact_id: 'b', kind: 'hotel', verdict: 'error' },
|
|
126
|
+
]);
|
|
127
|
+
writeJsonl(stateDir, 'channel-health.jsonl', [
|
|
128
|
+
{ channel: 'flyai', state: 'down', reason: 'trial-exhausted', at: iso(1) },
|
|
129
|
+
]);
|
|
130
|
+
writeJsonl(stateDir, 'incidents.jsonl', [
|
|
131
|
+
{ ts: iso(1), kind: 'plugin_error', message: 'boom', source: 'z3' },
|
|
132
|
+
]);
|
|
133
|
+
writeJsonl(stateDir, 'bridge-latency.jsonl', [
|
|
134
|
+
{ ts: iso(1), kind: 'hotel_search:hbcli', latencyMs: 120 },
|
|
135
|
+
]);
|
|
136
|
+
writeFileSync(join(stateDir, 'doctor-report.md'), '# doctor\n', 'utf-8');
|
|
137
|
+
const before = readdirSync(stateDir).sort();
|
|
138
|
+
const outPath = join(root, 'report.md');
|
|
139
|
+
await main(['--state-root', root, '--out', outPath, '--days', '7'], NOW);
|
|
140
|
+
const md = readFileSync(outPath, 'utf-8');
|
|
141
|
+
assert.match(md, /hotel \| 2 \| hit:1 \/ error:1 \| 1\/2\(50%\)/);
|
|
142
|
+
assert.match(md, /\| flyai \| down \| trial-exhausted \|/);
|
|
143
|
+
assert.match(md, /plugin_error \| 1 /);
|
|
144
|
+
assert.match(md, /p50=120ms/);
|
|
145
|
+
assert.match(md, /doctor 报告 doctor-report\.md:存在/);
|
|
146
|
+
assert.deepEqual(readdirSync(stateDir).sort(), before, '报告生成不得改动 gotry-state 目录');
|
|
147
|
+
assert.ok(existsSync(outPath));
|
|
148
|
+
checkCount += 1;
|
|
149
|
+
console.log(` ok ${checkCount} 端到端:侧车聚合→--out 落盘,stateRoot 只读`);
|
|
150
|
+
});
|
|
151
|
+
console.log(`\nMETRICS REPORT TESTS OK(${checkCount} checks)`);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* issue #77 E2E:LLM_MODEL 对 dsh 会话面生效的端到端证据。
|
|
3
|
+
*
|
|
4
|
+
* 四场景(全部走真实路径:clean package bin → dsh headless →
|
|
5
|
+
* llm-deepseek → 本地 mock OpenAI 兼容中转,中转落盘每个请求体的 model 字段):
|
|
6
|
+
*
|
|
7
|
+
* 1. 设 LLM_MODEL,干净 DSH_HOME → 请求体 model = LLM_MODEL
|
|
8
|
+
* 2. 设 LLM_MODEL,DSH_HOME 预置用户层选择 → 请求体 model = LLM_MODEL
|
|
9
|
+
* (用户层 ~/.dsh 选择被 .env 显式意图压过——#77 发现场景的正面回归)
|
|
10
|
+
* 3. 不设 LLM_MODEL,干净 DSH_HOME → 请求体 model = deepseek-v4-flash
|
|
11
|
+
* (dsh 组合默认,默认路径面不变)
|
|
12
|
+
* 4. 不设 LLM_MODEL,DSH_HOME 预置用户层选择 → 请求体 model = 用户层模型
|
|
13
|
+
* (用户 web 选择不被误伤,默认路径面不变)
|
|
14
|
+
*
|
|
15
|
+
* 隔离纪律(巡检/测试状态纪律):DSH_HOME 指向临时目录(会话/设置零污染);
|
|
16
|
+
* mock 模型只回固定文本、从不调工具 → gotry-state 零写入(动机/愿望池不动);
|
|
17
|
+
* 环境变量直接 export(不走 .env 文件,repo 模式 .env 加载路径已由 #48 覆盖)。
|
|
18
|
+
*
|
|
19
|
+
* 形态:只接受 clean npm 安装形态——插件走 dist/ 纯 JS,不再通过移动源码树依赖
|
|
20
|
+
* 来伪装 package mode。调用方须提供当前 tarball 安装出的 bin。
|
|
21
|
+
*
|
|
22
|
+
* 运行(在仓根):GOTRY_MODEL_OVERRIDE_E2E_BIN=/clean/node_modules/.bin/gotry
|
|
23
|
+
* npx tsx ts/scripts/model-override-e2e.ts
|
|
24
|
+
*/
|
|
25
|
+
import { createServer } from 'node:http';
|
|
26
|
+
import { existsSync, mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
27
|
+
import { tmpdir } from 'node:os';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
import { spawn } from 'node:child_process';
|
|
30
|
+
const BOOT_TIMEOUT_MS = 120_000;
|
|
31
|
+
/** mock OpenAI 兼容中转:落盘请求体 model,回最小合法 SSE 流 */
|
|
32
|
+
async function startMockRelay() {
|
|
33
|
+
const bodies = [];
|
|
34
|
+
const server = createServer((req, res) => {
|
|
35
|
+
if (req.method !== 'POST' || !req.url?.endsWith('/chat/completions')) {
|
|
36
|
+
res.writeHead(404).end('not found');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const chunks = [];
|
|
40
|
+
req.on('data', (c) => chunks.push(c));
|
|
41
|
+
req.on('end', () => {
|
|
42
|
+
try {
|
|
43
|
+
bodies.push(JSON.parse(Buffer.concat(chunks).toString('utf-8')));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
bodies.push({});
|
|
47
|
+
}
|
|
48
|
+
const chunk = (delta, finish) => `data: ${JSON.stringify({ id: 'e2e', object: 'chat.completion.chunk', created: 1, model: 'mock', choices: [{ index: 0, delta, finish_reason: finish }] })}\n\n`;
|
|
49
|
+
res.writeHead(200, { 'content-type': 'text/event-stream', 'cache-control': 'no-cache' });
|
|
50
|
+
res.write(chunk({ role: 'assistant', content: 'ok' }, null));
|
|
51
|
+
res.write(chunk({}, 'stop'));
|
|
52
|
+
res.write('data: [DONE]\n\n');
|
|
53
|
+
res.end();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
57
|
+
const port = server.address().port;
|
|
58
|
+
return { port, bodies, close: () => new Promise((resolve) => server.close(() => resolve())) };
|
|
59
|
+
}
|
|
60
|
+
async function runScenario(s, packageBin) {
|
|
61
|
+
const relay = await startMockRelay();
|
|
62
|
+
const dshHome = mkdtempSync(join(tmpdir(), 'gotry-77-dsh-home-'));
|
|
63
|
+
const childCwd = mkdtempSync(join(tmpdir(), 'gotry-77-cwd-'));
|
|
64
|
+
try {
|
|
65
|
+
if (s.userLayerModel) {
|
|
66
|
+
// 预置用户层设置(等价于用户在 dsh web UI 选过模型并持久化)
|
|
67
|
+
writeFileSync(join(dshHome, 'settings.yaml'), `agent-default-model:\n provider: deepseek-official\n model: ${s.userLayerModel}\n`);
|
|
68
|
+
}
|
|
69
|
+
const env = {
|
|
70
|
+
...process.env,
|
|
71
|
+
LLM_API_KEY: 'e2e-mock-key',
|
|
72
|
+
LLM_BASE_URL: `http://127.0.0.1:${relay.port}/v1`,
|
|
73
|
+
DSH_HOME: dshHome,
|
|
74
|
+
};
|
|
75
|
+
delete env['GOTRY_LLM_MODEL']; // 防宿主环境串扰;只认本场景显式设定
|
|
76
|
+
if (s.llmModel)
|
|
77
|
+
env['LLM_MODEL'] = s.llmModel;
|
|
78
|
+
else
|
|
79
|
+
delete env['LLM_MODEL'];
|
|
80
|
+
const child = spawn(packageBin, ['reply with the word ok'], {
|
|
81
|
+
env,
|
|
82
|
+
cwd: childCwd,
|
|
83
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
84
|
+
});
|
|
85
|
+
let logTail = '';
|
|
86
|
+
child.stdout.on('data', (d) => { logTail = (logTail + d).slice(-2000); });
|
|
87
|
+
child.stderr.on('data', (d) => { logTail = (logTail + d).slice(-2000); });
|
|
88
|
+
const exit = await new Promise((resolve) => {
|
|
89
|
+
const timer = setTimeout(() => { child.kill('SIGKILL'); resolve(null); }, BOOT_TIMEOUT_MS);
|
|
90
|
+
child.on('exit', (code) => { clearTimeout(timer); resolve(code); });
|
|
91
|
+
});
|
|
92
|
+
if (relay.bodies.length === 0) {
|
|
93
|
+
return { ok: false, detail: `中转未收到任何请求(exit=${exit});尾部日志: ${logTail.slice(-400)}` };
|
|
94
|
+
}
|
|
95
|
+
const models = relay.bodies.map((b) => String(b.model));
|
|
96
|
+
const bad = models.filter((m) => m !== s.expectModel);
|
|
97
|
+
return bad.length === 0
|
|
98
|
+
? { ok: true, detail: `${models.length} 个请求体 model 全部 = ${s.expectModel}(exit=${exit})` }
|
|
99
|
+
: { ok: false, detail: `请求体 model 不符:期望 ${s.expectModel},实际 ${JSON.stringify(models)}` };
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await relay.close();
|
|
103
|
+
rmSync(dshHome, { recursive: true, force: true });
|
|
104
|
+
rmSync(childCwd, { recursive: true, force: true });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function main() {
|
|
108
|
+
const packageBin = process.env.GOTRY_MODEL_OVERRIDE_E2E_BIN;
|
|
109
|
+
if (!packageBin || !existsSync(packageBin)) {
|
|
110
|
+
console.error('GOTRY_MODEL_OVERRIDE_E2E_BIN 必须指向当前 tarball 的 clean installed-package bin');
|
|
111
|
+
process.exit(2);
|
|
112
|
+
}
|
|
113
|
+
await runAll(packageBin);
|
|
114
|
+
}
|
|
115
|
+
async function runAll(packageBin) {
|
|
116
|
+
const scenarios = [
|
|
117
|
+
{ name: '① 设 LLM_MODEL(干净 DSH_HOME)', llmModel: 'gotry-e2e-model', expectModel: 'gotry-e2e-model' },
|
|
118
|
+
{ name: '② 设 LLM_MODEL + 用户层已选模型', llmModel: 'gotry-e2e-model', userLayerModel: 'user-picked-model', expectModel: 'gotry-e2e-model' },
|
|
119
|
+
{ name: '③ 不设 LLM_MODEL(干净 DSH_HOME)', expectModel: 'deepseek-v4-flash' },
|
|
120
|
+
{ name: '④ 不设 LLM_MODEL + 用户层已选模型', userLayerModel: 'user-picked-model', expectModel: 'user-picked-model' },
|
|
121
|
+
];
|
|
122
|
+
let fail = 0;
|
|
123
|
+
for (const s of scenarios) {
|
|
124
|
+
process.stdout.write(`${s.name} … `);
|
|
125
|
+
const t0 = Date.now();
|
|
126
|
+
const r = await runScenario(s, packageBin);
|
|
127
|
+
console.log(`${r.ok ? 'PASS' : 'FAIL'}(${((Date.now() - t0) / 1000).toFixed(1)}s)${r.detail}`);
|
|
128
|
+
if (!r.ok)
|
|
129
|
+
fail = 1;
|
|
130
|
+
}
|
|
131
|
+
if (fail) {
|
|
132
|
+
console.error('\nMODEL OVERRIDE E2E FAIL');
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
console.log('\nMODEL OVERRIDE E2E OK');
|
|
136
|
+
}
|
|
137
|
+
await main();
|