dsh-clash-subscription 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ # 0.10.0 · 支持 Ubuntu(及 Linux / macOS)
2
+
3
+ > 上一版 `0.9.0` · 本版 `0.10.0`
4
+
5
+ ## 0.9.0 在 Ubuntu 上会怎样
6
+
7
+ 能安装,能识别平台,能下载内核,**然后卡在解包**。
8
+
9
+ ```
10
+ core download 100%
11
+ core bootstrap: verified
12
+ THROWS: tar exited 1: tar: Error opening archive: Unrecognized archive format
13
+ ```
14
+
15
+ ## 根因:Linux 的 `.gz` 不是 tar
16
+
17
+ mihomo 的 Linux 与 macOS 发布资产是**裸二进制经 gzip 压缩**,不是 tar 归档。实测三份:
18
+
19
+ | 资产 | 解压后 | 形态 |
20
+ |---|---|---|
21
+ | `mihomo-linux-amd64-compatible-v1.19.34.gz` | 61 948 030 字节 | ELF64,`ustar`=false |
22
+ | `mihomo-linux-arm64-v1.19.34.gz` | 57 344 126 字节 | ELF,`ustar`=false |
23
+ | `mihomo-darwin-arm64-v1.19.34.gz` | 56 698 738 字节 | Mach-O,`ustar`=false |
24
+
25
+ 而旧代码对所有 `.gz` 都执行 `tar -xzf`,它只能读 tar 归档。
26
+
27
+ ## 改了什么
28
+
29
+ ### 1. 解包器按内容判别,不再按扩展名
30
+
31
+ ```
32
+ .gz → node:zlib 流式解压 → 看 offset 257 是不是 "ustar"
33
+ ├─ 是 → tar 解包(兼容真有 tar.gz 的发布)
34
+ └─ 否 → 它本身就是内核,直接落位
35
+ ```
36
+
37
+ 不再依赖外部 `tar` 命令,**精简 Ubuntu 镜像没有 tar 也能用**。`.zip` 在 Linux 上改为先试 `unzip`、再试 `tar`,都失败时把两个错误一起报出来(GNU tar 读不了 zip)。
38
+
39
+ ### 2. 补全 `KNOWN_ARCHIVES` 摘要
40
+
41
+ 原来只有 `win32-x64`,导致在 Linux 上设 `coreVersion: 1.19.34` 直接抛
42
+ `coreVersion 1.19.34 has no verified archive for linux-x64`。
43
+
44
+ 现在五条齐全,摘要全部取自发布方 API 自述值,并与本地下载的字节**逐条比对一致**:
45
+
46
+ | 平台 | 摘要(前 16 位) | 体积 |
47
+ |---|---|---|
48
+ | `linux-x64` | `2763f5b414527f7b` | 22 766 457 |
49
+ | `linux-arm64` | `daaf78a6240a282c` | 20 684 679 |
50
+ | `darwin-x64` | `703bceaa494732fa` | 22 213 898 |
51
+ | `darwin-arm64` | `1a7a20eca63fbbae` | 20 649 699 |
52
+ | `win32-x64` | `cd6738d4648cc1a5` | 22 417 383 |
53
+
54
+ Linux x64 优先用 `-compatible` 构建(CPU 基线版本),避免 `v3` 类构建在旧机器上触发 SIGILL。
55
+
56
+ ### 3. `platformSupported` 不再谎报
57
+
58
+ 旧值只看 `platformKey()`(发布页有没有对应资产),在 Linux 上返回 `true`,但两条获取路径其实都抛错。现在要求「自带内核或可下载,至少一条成立」,并新增 `coreSource` 说明来源:
59
+
60
+ ```
61
+ platformSupported = true
62
+ coreSource = download ← 或 "bundled"
63
+ ```
64
+
65
+ ### 4. 无自带内核的平台默认开启自动获取
66
+
67
+ `autoFetchCore` 默认 `false`,而 Linux/macOS 没有自带内核——装完什么都不发生,看起来像坏掉。现在:**未显式配置且本平台无自带内核时,默认开启**。显式写 `false` 仍然尊重。
68
+
69
+ ### 5. `chmod` 失败不再静默
70
+
71
+ `placeCore` 里给执行位;失败时抛出明确错误(`could not make ... executable`),而不是让 spawn 之后蹦出一个莫名其妙的 `EACCES`。
72
+
73
+ ## 关于 glibc / 发行版版本
74
+
75
+ **不需要针对 Ubuntu 版本做任何适配**。验证方式不是读文档,而是解析 ELF 程序头:
76
+
77
+ ```
78
+ ELF class = 64-bit
79
+ e_machine = x86-64
80
+ PT_INTERP = NONE → 静态链接
81
+ GLIBC_2. 符号 = 无
82
+ libc.so / ld-linux 引用 = 无
83
+ ```
84
+
85
+ 静态链接意味着系统 glibc 完全不参与,**同一个二进制在 Ubuntu 22.04 / 24.04 LTS (Noble) / 26.04 LTS (Resolute Raccoon) 上都能跑**。
86
+
87
+ ## 验收
88
+
89
+ ```
90
+ node test/regression-070.mjs → 113 passed, 0 failed
91
+ node test/regression-063.mjs → 31 passed, 0 failed
92
+ node test/regression-0100.mjs → 48 passed, 0 failed ← 新增(Ubuntu 适配)
93
+ ```
94
+
95
+ 新增测试里有几条是靠运行结果取证的:
96
+
97
+ | 断言 | 证据 |
98
+ |---|---|
99
+ | 裸 gzip 能解包 | 构造裸 gzip → 解出 4100 字节,ELF 头完整 |
100
+ | **负向对照**:`tar -xzf` 对同一文件确实失败 | `exit=1`(证明这个修复是必要的,不是装饰) |
101
+ | tar.gz 形状仍能处理 | 现场打包 tar.gz → 成员正确取出 |
102
+ | 真实资产 61 948 030 字节 | 用真下载的 22 766 457 字节 `.gz` 解包 |
103
+ | 静态链接 | 遍历程序头,确认无 `PT_INTERP` |
104
+ | 五平台矩阵 | 每对平台都有「自带或可下载」 |
105
+
106
+ 端到端(模拟 Linux 平台,真下载 + 真解包):
107
+
108
+ ```
109
+ core bootstrap: resolved v1.19.34 → verified → installed
110
+ bytes = 61948030
111
+ ELF magic = 7f454c46 ✓
112
+ ```
113
+
114
+ ## 一个被测试抓到的自身 bug
115
+
116
+ 给技能补 Linux 章节时写了 `${DSH_HOME}/data/...`,而技能正文是模板字符串——`${}` 被当成插值求值,导入直接 `ReferenceError: DSH_HOME is not defined`。
117
+
118
+ 原有断言 `!content.includes('${')` 抓不到它,因为**模块根本没加载成功**,断言不会执行。补了两条真正有效的:
119
+
120
+ ```
121
+ ok 源码里没有未转义的 ${(会被当成插值求值)
122
+ ok 源码里未转义的反引号成对(模板未被截断)
123
+ ```
124
+
125
+ ## 本机无法验证的一点(如实记录)
126
+
127
+ `chmod 0755` 设执行位这件事在 Windows 上无法验证:NTFS 没有 POSIX 执行位,`chmodSync` 只能切只读属性,`mode & 0o111` 恒为 0。所以模拟运行里显示 `executable? = NO` 是本机文件系统的限制,不是代码缺陷——真 Ubuntu 上该分支会执行。要彻底证实,需要在真 Linux 上跑一次 `test/regression-0100.mjs`。
package/README.md CHANGED
@@ -119,8 +119,56 @@ unpacking and the executable **after**, and re-unpacks if an already-installed c
119
119
  matches — a corrupted or replaced binary is restored rather than trusted. If the manifest and
120
120
  the archive ever disagree, the plugin refuses to run the binary at all.
121
121
 
122
- Only `win32-x64` ships. Other platforms report `platformSupported: false` and use `corePath`
123
- or `autoFetchCore` instead.
122
+ Only `win32-x64` ships a copy inside the package. Every other supported platform fetches the
123
+ release asset on first start instead; `status.coreSource` reports which applies
124
+ (`bundled` or `download`), and `status.platformSupported` is true when at least one of the two
125
+ paths exists.
126
+
127
+ | Platform | Core source | Archive |
128
+ |---|---|---|
129
+ | `win32-x64` | bundled + downloadable | `.zip` |
130
+ | `win32-arm64` | downloadable | `.zip` |
131
+ | `linux-x64` | downloadable | `.gz` (bare binary) |
132
+ | `linux-arm64` | downloadable | `.gz` (bare binary) |
133
+ | `darwin-x64` / `darwin-arm64` | downloadable | `.gz` (bare binary) |
134
+
135
+ ## Ubuntu (and other Linux): 24.04 LTS and 26.04 LTS
136
+
137
+ Supported. Nothing beyond the DSH runtime has to be installed beforehand.
138
+
139
+ **Why the distro version does not matter.** The release asset decompresses to a *statically
140
+ linked* ELF64 — verified: no `PT_INTERP`, no `GLIBC_*` symbols, no `ld-linux` reference — so the
141
+ system glibc is never consulted. The same binary runs on Ubuntu 22.04, 24.04 (Noble) and 26.04
142
+ (Resolute Raccoon).
143
+
144
+ **What happens on first start.**
145
+
146
+ 1. no bundled core exists for Linux, so `autoFetchCore` defaults to **on** there;
147
+ 2. the plugin downloads `mihomo-linux-amd64-compatible-v1.19.34.gz` (22 766 457 bytes) from the
148
+ GitHub release, trying `gh-proxy.com` / `ghfast.top` / `ghproxy.net` first if those answer
149
+ faster;
150
+ 3. the SHA-256 is checked against the publisher's own digest **before** anything is unpacked;
151
+ 4. the archive is decompressed with `node:zlib` — **not** with `tar`, because every Linux and
152
+ macOS release asset is a *bare gzip-compressed binary*, not a tar. Feeding one to
153
+ `tar -xzf` fails with `Unrecognized archive format`, which is exactly what 0.9.0 did after a
154
+ successful 22 MB download;
155
+ 5. the result (61 948 030 bytes) is written to
156
+ `${DSH_HOME}/data/dsh-clash-proxy/bin/mihomo` and chmod `0755`.
157
+
158
+ Because step 4 uses `node:zlib` instead of an external command, a slim image without `tar` still
159
+ works. `tar` is only needed if a release ever switches back to a `tar.gz` payload — both shapes
160
+ are handled and both are covered by tests.
161
+
162
+ **Pinning a version.** `coreVersion: 1.19.34` works on every listed platform:
163
+ `KNOWN_ARCHIVES` carries the publisher digest for each. Without a pin, the plugin asks the release
164
+ API, falling back to the release-page redirect when the API is rate limited.
165
+
166
+ **If the download cannot happen** (air-gapped host, or a mirror that does not carry it), set
167
+ `corePath` to a `mihomo` binary placed on disk, or install a local archive with
168
+ `installCoreFromFile`. Both are verified the same way.
169
+
170
+ **Not supported:** 32-bit x86 (`linux-ia32`) and architectures with no published asset. On those
171
+ `status.platformSupported` is false and the panel says so up front instead of failing later.
124
172
 
125
173
  ## The optional GeoIP upgrade
126
174
 
package/client.js CHANGED
@@ -81,7 +81,7 @@ const en = {
81
81
  noUsableNode: 'No node reached every required service.',
82
82
  usableCount: '{usable} / {total} nodes usable',
83
83
  autoFetchCore: 'Fetch a core automatically',
84
- autoFetchCoreHint: 'When no mihomo binary is present, download a verified private copy on startup instead of waiting for you to press Download.',
84
+ autoFetchCoreHint: 'When no mihomo binary is present, download a verified private copy on startup instead of waiting for you to press Download. On Linux and macOS there is no bundled core, so this is on by default there — the plugin fetches the 22 MB release asset once, verifies it against the publisher SHA-256, and unpacks it into its own data directory.',
85
85
  dns: 'DNS servers',
86
86
  dnsHint: 'Comma-separated resolvers the core uses for its own lookups.',
87
87
  start: 'Start',
@@ -248,7 +248,7 @@ const zh = {
248
248
  noUsableNode: '没有任何节点能访问全部必需服务。',
249
249
  usableCount: '{usable} / {total} 个节点可用',
250
250
  autoFetchCore: '自动获取内核',
251
- autoFetchCoreHint: '机器上没有 mihomo 时,启动时自动下载一份经过校验的私有内核,不用手动点下载。',
251
+ autoFetchCoreHint: '机器上没有 mihomo 时,启动时自动下载一份经过校验的私有内核,不用手动点下载。Linux 与 macOS 没有自带内核,因此在那里默认开启:首次启动会下载 22 MB 的发布资产,用发布方 SHA-256 校验后解包进插件自己的数据目录。',
252
252
  dns: 'DNS 服务器',
253
253
  dnsHint: '逗号分隔,内核自己解析时使用。',
254
254
  start: '启动',
package/index.js CHANGED
@@ -79,7 +79,16 @@ export const CONFIG_DEFAULTS = {
79
79
  speedTestCount: 8,
80
80
  /** How often the core is checked for liveness, in minutes; 0 disables the watchdog. */
81
81
  healthCheckMinutes: 1,
82
- /** Download a private core automatically when the machine has none. */
82
+ /**
83
+ * Download a private core automatically when the machine has none.
84
+ *
85
+ * Default off was right while every supported platform shipped a vendored copy: downloading
86
+ * was an optimisation. Linux and macOS have no vendored copy (the payload is 61 MB, which is
87
+ * not something to embed for a platform whose package can just fetch it), so on those the flag
88
+ * being off means a fresh install does nothing at all until someone presses a button. The
89
+ * effective default is therefore "on when there is nothing bundled for this platform", handled
90
+ * in `resolveConfig` rather than by leaving the literal `false` here.
91
+ */
83
92
  autoFetchCore: false,
84
93
  /** Pin the core version to a build whose digest this plugin ships; empty means current. */
85
94
  coreVersion: '',
@@ -127,6 +136,15 @@ export const CONFIG_DEFAULTS = {
127
136
  autoSwitch: true,
128
137
  /** How often the round runs, in seconds; 0 disables it. */
129
138
  healthRoundSeconds: 30,
139
+ /**
140
+ * Consecutive attempts on the live node inside one round before it is given up on.
141
+ *
142
+ * The retries happen **immediately**, not one per timer tick: a node that fails gets its
143
+ * second and third chance seconds later, and only then does the round measure every other
144
+ * node. Spreading the attempts across ticks made a dead node cost a minute and a half before
145
+ * anything was done about it.
146
+ */
147
+ healthAttempts: 3,
130
148
  /** Consecutive failed rounds before the node is given up on. */
131
149
  healthStrikeLimit: 3,
132
150
  /**
@@ -146,10 +164,25 @@ export const CONFIG_DEFAULTS = {
146
164
  * traffic reuses warm state, so the second measurement is the one that means something.
147
165
  */
148
166
  healthMaxDelayMs: 400,
167
+ /**
168
+ * Latency samples per attempt; the median of the samples after the first is compared.
169
+ *
170
+ * Measured, consecutive Google probes on one node in one minute returned 2256, 967, 1412, 179,
171
+ * 1190 and 180 ms — a single sample against a 400 ms ceiling decides mostly by luck. Three is
172
+ * the cheapest sample that rejects one outlier; the first sample is dropped from the median
173
+ * because it pays DNS + TCP + TLS on a freshly started core.
174
+ */
175
+ healthLatencySamples: 3,
149
176
  /** Which probe supplies the latency number. Google is the distance baseline, not a gate. */
150
177
  healthBaselineProbe: 'google',
151
- /** How many candidate nodes one switch search may test, cheapest first; 0 means all. */
152
- healthSwitchCandidates: 12,
178
+ /**
179
+ * Cap on how many nodes one switch measures. 0 (the default) measures every unblocked node.
180
+ *
181
+ * A cap turns "find the best exit" into "find the best of the first N", which on a large
182
+ * subscription can pick a worse node than one further down the list. It stays configurable for
183
+ * an operator on a very large subscription who would rather switch fast than switch well.
184
+ */
185
+ healthSwitchCandidates: 0,
153
186
  /** Let a switch proceed even while connections are open. Off by default: it aborts work. */
154
187
  switchWhileBusy: false,
155
188
  /**
@@ -205,10 +238,12 @@ async function buildConfigSchema() {
205
238
  probeTimeoutMs: z.number().default(8000),
206
239
  autoSwitch: z.boolean().default(true),
207
240
  healthRoundSeconds: z.number().default(30),
241
+ healthAttempts: z.number().default(3),
208
242
  healthStrikeLimit: z.number().default(3),
209
243
  healthMaxDelayMs: z.number().default(400),
244
+ healthLatencySamples: z.number().default(3),
210
245
  healthBaselineProbe: z.string().default('google'),
211
- healthSwitchCandidates: z.number().default(12),
246
+ healthSwitchCandidates: z.number().default(0),
212
247
  switchWhileBusy: z.boolean().default(false),
213
248
  healthSurveyEvery: z.number().default(20),
214
249
  })
@@ -233,6 +268,11 @@ export function resolveConfig(raw) {
233
268
  config.mode = mode === 'global' ? 'global' : 'rule'
234
269
  config.autoStart = config.autoStart !== false && config.autoStart !== 'false'
235
270
  config.autoFetchCore = config.autoFetchCore === true || config.autoFetchCore === 'true'
271
+ // A platform with no bundled core gets the download switched on, because otherwise a fresh
272
+ // install there has no core and no action: the panel offers a button, but nothing happens on
273
+ // its own and "the proxy does not work" looks like a bug rather than an unset default. An
274
+ // explicit `true`/`false` in the profile still wins, so this only fills the gap.
275
+ if (input.autoFetchCore === undefined && vendoredFor() === undefined) config.autoFetchCore = true
236
276
  config.autoFetchGeo = config.autoFetchGeo !== false && config.autoFetchGeo !== 'false'
237
277
  config.autoReselect = config.autoReselect !== false && config.autoReselect !== 'false'
238
278
  for (const field of ['subscriptionUrls', 'subscriptionUrl', 'node', 'corePath', 'coreVersion', 'dnsServers', 'directDomains', 'proxyDomains', 'dataDir', 'probes', 'requiredProbes']) {
@@ -265,8 +305,10 @@ export function resolveConfig(raw) {
265
305
  config.healthRoundSeconds = clamp(config.healthRoundSeconds, 0, 3_600, 30)
266
306
  config.healthStrikeLimit = clamp(config.healthStrikeLimit, 1, 20, 3)
267
307
  config.healthMaxDelayMs = clamp(config.healthMaxDelayMs, 0, 30_000, 400)
308
+ config.healthLatencySamples = clamp(config.healthLatencySamples, 2, 5, 3)
268
309
  config.healthBaselineProbe = String(config.healthBaselineProbe ?? 'google').trim() || 'google'
269
- config.healthSwitchCandidates = clamp(config.healthSwitchCandidates, 0, 100, 12)
310
+ config.healthAttempts = clamp(config.healthAttempts, 1, 10, 3)
311
+ config.healthSwitchCandidates = clamp(config.healthSwitchCandidates, 0, 200, 0)
270
312
  config.healthSurveyEvery = clamp(config.healthSurveyEvery, 0, 10_000, 20)
271
313
  // 0.7.0 kept the interval in minutes; carry the value over so an existing profile does not
272
314
  // silently fall back to the new 30 s default when someone had deliberately set 15 minutes.
@@ -491,6 +533,7 @@ export class Runtime {
491
533
  reselectMinutes: this.config.reselectMinutes,
492
534
  autoSwitch: this.config.autoSwitch,
493
535
  healthRoundSeconds: this.config.healthRoundSeconds,
536
+ healthAttempts: this.config.healthAttempts,
494
537
  healthStrikeLimit: this.config.healthStrikeLimit,
495
538
  healthMaxDelayMs: this.config.healthMaxDelayMs,
496
539
  healthSwitchCandidates: this.config.healthSwitchCandidates,
@@ -572,6 +615,7 @@ export class Runtime {
572
615
  if (
573
616
  next.healthRoundSeconds !== previous.healthRoundSeconds ||
574
617
  next.autoSwitch !== previous.autoSwitch ||
618
+ next.healthAttempts !== previous.healthAttempts ||
575
619
  next.healthStrikeLimit !== previous.healthStrikeLimit ||
576
620
  next.healthMaxDelayMs !== previous.healthMaxDelayMs ||
577
621
  next.healthSurveyEvery !== previous.healthSurveyEvery
@@ -684,17 +728,122 @@ export class Runtime {
684
728
  }
685
729
 
686
730
  /**
687
- * Run one real-probe round against the node that is currently carrying traffic.
731
+ * Measure one node once and turn it into a verdict.
688
732
  *
689
- * This is the piece the plugin was missing. Its old check asked mihomo whether a URL answered
690
- * at all, and a GitHub rate-limit `403` counts as "answered" — measured, the panel reported
691
- * six unusable nodes as `usable` while five of them had `x-ratelimit-remaining: 0` and two
692
- * could not complete a git fetch at all. So the round sends the real requests through the
693
- * probe listener, reads the real status and quota, and records a strike only when a probe
694
- * that gates usability failed.
733
+ * Extracted so one round can call it three times in a row without waiting for the next timer
734
+ * tick. "Unqualified" means either test failed:
695
735
  *
696
- * A usable round resets the streak, because a node that recovers must not be switched away
697
- * from for old failures.
736
+ * - a gating probe did not answer (unreachable / reset / wrong status), or
737
+ * - the Google round trip exceeded `healthMaxDelayMs`.
738
+ *
739
+ * Both are folded into `usable === false` on the returned verdict, with `failed` naming which,
740
+ * so the caller does not need a second condition.
741
+ *
742
+ * @param name - node to measure.
743
+ * @param plan - the probe plan in force.
744
+ * @returns `{ results, verdict, latency, latencySource, coldLatency, ceiling, baseline }`, or
745
+ * `undefined` when the probe listener did not answer (an instrument fault, not a node fault).
746
+ */
747
+ async measureNode(name, plan) {
748
+ const { results, verdict } = await this.core.checkNodeReal(name, plan.specs, plan.gating, {
749
+ timeoutMs: this.config.probeTimeoutMs ?? 8000,
750
+ })
751
+ if (Object.keys(results).length === 0) return undefined
752
+
753
+ // Google is not a gating probe, so it is absent from `plan.specs` and from `results`: the
754
+ // node already answered the gating set and Google has to be measured on its own. Two
755
+ // measurements are taken, and the second is the number that means something — the first one
756
+ // on a freshly started core pays DNS + TCP + TLS for that host (measured, 513 ms cold vs
757
+ // 82 ms warm), which is not the node's latency.
758
+ //
759
+ // An unreachable Google is **not** a slow node. The ceiling is skipped for that attempt and
760
+ // the node is judged on the gating probes alone, because inventing a latency for an
761
+ // unreachable host would switch away from a node that may be fast for everything else.
762
+ const baseline = plan.probes.find((spec) => spec.id === this.config.healthBaselineProbe) ?? plan.specs[0]
763
+ let latency
764
+ let latencySource = 'not-measured'
765
+ let coldLatency
766
+ /** Every Google sample taken this attempt, so the panel can show the spread. */
767
+ const samples = []
768
+ if (verdict.usable === true && baseline !== undefined && typeof this.core.remeasure === 'function') {
769
+ try {
770
+ // Pin the probe group to this node first. `probeNodeReal` already does that for the gating
771
+ // probes, but relying on that would make the latency number depend on call order: a
772
+ // candidate measured right after the live node would otherwise get the live node's
773
+ // latency. Moving it here makes `measureNode(name)` self-contained — measure the node you
774
+ // name, no matter what was measured before.
775
+ if (typeof this.core.selectProbe === 'function') await this.core.selectProbe(name)
776
+
777
+ // Three samples, and the number used is the MEDIAN of the last two.
778
+ //
779
+ // Measured on a live node, consecutive Google probes returned 2256, 967, 1412, 179, 1190
780
+ // and 180 ms for the same node in the same minute. A single sample against a 400 ms
781
+ // ceiling therefore decides mostly by luck: it lets a momentarily slow-but-fine node fail,
782
+ // and a momentarily fast-but-bad node pass. The median of a small sample is the standard
783
+ // defence, and it is cheap here because each probe is one request to a static endpoint.
784
+ //
785
+ // The first sample is discarded from the median when there are three, because the first
786
+ // one on a freshly started core pays DNS + TCP + TLS for that host — measured, 513 ms cold
787
+ // against 82 ms warm.
788
+ const wanted = Math.max(2, Math.min(Number(this.config.healthLatencySamples ?? 3), 5))
789
+ for (let i = 0; i < wanted; i += 1) {
790
+ const sample = await this.core.remeasure(baseline, { timeoutMs: this.config.probeTimeoutMs ?? 8000, expectNode: name })
791
+ if (typeof sample?.ms === 'number' && sample.ok === true) samples.push(sample.ms)
792
+ }
793
+ if (samples.length > 0) {
794
+ coldLatency = samples[0]
795
+ const forMedian = samples.length > 1 ? samples.slice(1) : samples
796
+ const sorted = [...forMedian].sort((a, b) => a - b)
797
+ latency = sorted[Math.floor(sorted.length / 2)]
798
+ latencySource = samples.length > 1 ? 'warm-median' : 'cold'
799
+ } else {
800
+ latencySource = 'unreachable'
801
+ }
802
+ } catch (error) {
803
+ latencySource = 'failed'
804
+ this.log(`latency measurement failed on ${name}: ${error?.message ?? error}`)
805
+ }
806
+ }
807
+
808
+ const ceiling = Number(this.config.healthMaxDelayMs ?? 400)
809
+
810
+ // A latency that could not be measured must not be treated as "fast enough".
811
+ //
812
+ // The ceiling is the whole point of "unqualified = unusable OR too slow", so `undefined`
813
+ // silently disabling it would let a node with an unreachable Google stay selected forever.
814
+ // But an unreachable Google is also not proof the node is slow, so it cannot simply fail
815
+ // either — that is what caused a healthy node to be switched away from when the probe itself
816
+ // hiccuped.
817
+ //
818
+ // The resolution is a fallback chain, and what it settles on is what gets compared:
819
+ // 1. the warm Google round trip (the measurement the ceiling is defined against);
820
+ // 2. the cold Google round trip (a real number, just includes connection setup);
821
+ // 3. the fastest gating probe that did answer (gstatic is a static 204 too, and every
822
+ // gating probe already ran, so this costs nothing).
823
+ // Only when nothing at all answered does the latency stay undefined — and a node in that
824
+ // state has already failed its gating probes, so it is unqualified on the other count.
825
+ if (latency === undefined) {
826
+ const fallback = [coldLatency, ...Object.values(results).map((row) => (row?.ok === true ? row?.ms : undefined))]
827
+ .filter((value) => typeof value === 'number' && value >= 0)
828
+ .sort((a, b) => a - b)[0]
829
+ if (typeof fallback === 'number') {
830
+ latency = fallback
831
+ latencySource = latencySource === 'unreachable' ? 'fallback-probe' : latencySource
832
+ }
833
+ }
834
+
835
+ const tooSlow = ceiling > 0 && verdict.usable === true && latency !== undefined && latency > ceiling
836
+ const judged = tooSlow ? { ...verdict, usable: false, failed: [...verdict.failed, 'latency'], slow: true } : verdict
837
+ return { results, verdict: judged, latency, latencySource, coldLatency, ceiling, baseline: baseline?.id, samples }
838
+ }
839
+
840
+ /**
841
+ * Run one real-probe round against the node that is currently carrying traffic.
842
+ *
843
+ * The round retries **immediately**, in the same round, rather than spreading attempts across
844
+ * timer ticks: a node that failed once gets a second and third chance seconds later, and only
845
+ * when all of them fail does the round search for a replacement. That is what makes a bad node
846
+ * cost seconds instead of a minute and a half, while still not switching on a single blip.
698
847
  *
699
848
  * @param options - `force` ignores the enable flag; `node` overrides the node under test.
700
849
  * @returns the round report.
@@ -714,101 +863,90 @@ export class Runtime {
714
863
  return { state: 'no-node', required: plan.gating }
715
864
  }
716
865
 
717
- const { results, verdict } = await this.core.checkNodeReal(current, plan.specs, plan.gating, {
718
- timeoutMs: this.config.probeTimeoutMs ?? 8000,
719
- })
720
- if (Object.keys(results).length === 0) {
721
- // The probe listener is not answering, which says nothing about the node. Reporting a
722
- // strike here would switch away from a healthy node because the instrument broke.
723
- return { state: 'probe-unavailable', node: current }
724
- }
725
-
726
- // Google is not a gating probe, so it is absent from both `plan.specs` and the `results`
727
- // this round produced — the node already answered the gating set, and Google has to be
728
- // measured separately. One measurement is taken for the warm number, and a second only
729
- // when that one failed, so "Google unreachable" can be told from "Google slow".
730
- //
731
- // Consequence worth stating: an unreachable Google does **not** make the node slow. The
732
- // ceiling is skipped for that round and the node is judged on the gating probes alone,
733
- // because inventing a latency for an unreachable host would switch away from a node that
734
- // may be perfectly fast for everything else.
735
- const baseline =
736
- plan.probes.find((spec) => spec.id === this.config.healthBaselineProbe) ??
737
- plan.specs[0]
738
- let latency
739
- let latencySource = 'not-measured'
740
- let coldLatency
741
- if (verdict.usable === true && baseline !== undefined && typeof this.core.remeasure === 'function') {
742
- try {
743
- const first = await this.core.remeasure(baseline, { timeoutMs: this.config.probeTimeoutMs ?? 8000 })
744
- if (typeof first?.ms === 'number' && first.ok === true) {
745
- coldLatency = first.ms
746
- // Second measurement: the first one on a freshly started core pays DNS + TCP + TLS for
747
- // that host, which is not the node's latency. Measured, 513 ms cold vs 82 ms warm.
748
- const warm = await this.core.remeasure(baseline, { timeoutMs: this.config.probeTimeoutMs ?? 8000 })
749
- if (typeof warm?.ms === 'number' && warm.ok === true) {
750
- latency = warm.ms
751
- latencySource = 'warm'
752
- } else {
753
- latency = first.ms
754
- latencySource = 'cold'
755
- }
756
- } else {
757
- latencySource = 'unreachable'
866
+ const attempts = Math.max(1, Number(this.config.healthAttempts ?? 3))
867
+ const tried = []
868
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
869
+ const measured = await this.measureNode(current, plan)
870
+ if (measured === undefined) {
871
+ // The probe listener is not answering, which says nothing about the node. Reporting a
872
+ // failure here would switch away from a healthy node because the instrument broke.
873
+ return { state: 'probe-unavailable', node: current, attempts: tried }
874
+ }
875
+ const entry = {
876
+ attempt,
877
+ usable: measured.verdict.usable === true,
878
+ latency: measured.latency,
879
+ latencySource: measured.latencySource,
880
+ failed: measured.verdict.failed ?? [],
881
+ slow: measured.verdict.slow === true,
882
+ at: new Date().toISOString(),
883
+ }
884
+ tried.push(entry)
885
+ this.healthRows.set(current, { results: measured.results, verdict: measured.verdict, at: Date.now() })
886
+ this.lastMatrix = [{ name: current, results: measured.results }]
887
+ this.lastCheckAt = Date.now()
888
+
889
+ if (measured.verdict.usable === true) {
890
+ // Kept. One good attempt ends the round; the remaining attempts are not spent, because
891
+ // the node already answered the question this round is asking.
892
+ this.watch.record(current, measured.verdict, { probes: measured.results })
893
+ const report = {
894
+ state: measured.verdict.degraded === true ? 'degraded' : 'ok',
895
+ node: current,
896
+ required: plan.gating,
897
+ results: measured.results,
898
+ verdict: measured.verdict,
899
+ latency: measured.latency,
900
+ latencySource: measured.latencySource,
901
+ coldLatency: measured.coldLatency,
902
+ totalLatency: measured.results && undefined,
903
+ ceiling: measured.ceiling,
904
+ baseline: measured.baseline,
905
+ attempt,
906
+ attempts: tried,
907
+ attemptLimit: attempts,
908
+ giveUp: false,
909
+ at: new Date().toISOString(),
758
910
  }
759
- } catch (error) {
760
- // A probe that throws is a broken instrument, not a slow node: no latency verdict.
761
- latencySource = 'failed'
762
- this.log(`latency measurement failed on ${current}: ${error?.message ?? error}`)
911
+ this.health = report
912
+ this.log(`round ok on ${current} at attempt ${attempt}/${attempts} (${measured.latency ?? '?'} ms)`)
913
+ void this.runSurveyTick()
914
+ return report
763
915
  }
916
+
917
+ this.log(
918
+ `round attempt ${attempt}/${attempts} failed on ${current}: ` +
919
+ `${measured.verdict.failed.join(',') || 'no-answer'}` +
920
+ (measured.latency === undefined ? '' : ` (${measured.latency} ms, ceiling ${measured.ceiling} ms)`),
921
+ )
922
+ }
923
+
924
+ // Every attempt failed.
925
+ this.watch.record(current, { usable: false, failed: tried.at(-1)?.failed ?? [], limited: [], blocked: [], score: 100 })
926
+ const verdictNow = {
927
+ usable: false,
928
+ degraded: false,
929
+ failed: tried.at(-1)?.failed ?? [],
930
+ limited: [],
931
+ blocked: [],
932
+ slow: tried.every((entry) => entry.slow === true),
764
933
  }
765
- const ceiling = Number(this.config.healthMaxDelayMs ?? 400)
766
- const tooSlow = ceiling > 0 && verdict.usable === true && latency !== undefined && latency > ceiling
767
- const judged = tooSlow ? { ...verdict, usable: false, failed: [...verdict.failed, 'latency'], slow: true } : verdict
768
-
769
- this.healthRows.set(current, { results, verdict: judged, at: Date.now() })
770
- this.lastMatrix = [{ name: current, results }]
771
- this.lastCheckAt = Date.now()
772
- const counted = this.watch.record(current, judged, { probes: results })
773
- // `degraded` is a usable node that is short on quota. It is reported, never acted on:
774
- // switching away from it would land on an equally short node and lose the connection.
775
- const state = judged.usable ? (judged.degraded === true ? 'degraded' : 'ok') : judged.slow === true ? 'slow' : 'bad'
776
934
  const report = {
777
- state,
935
+ state: verdictNow.slow ? 'slow' : 'bad',
778
936
  node: current,
779
937
  required: plan.gating,
780
- results,
781
- verdict: judged,
782
- /** Warm baseline round trip in ms — the number the ceiling refers to. */
783
- latency,
784
- /** `warm` | `cold` | `unreachable` | `not-measured`: how to read `latency`. */
785
- latencySource,
786
- /** Cold first measurement, kept so a genuinely slow node can be told from a cold start. */
787
- coldLatency,
788
- /** Sum across every gating probe; informational, never compared to the ceiling. */
789
- totalLatency: verdict.total,
790
- ceiling,
791
- baseline: baseline?.id,
792
- strikes: counted.strikes,
793
- strikeLimit: counted.limit,
794
- giveUp: counted.giveUp,
938
+ verdict: verdictNow,
939
+ latency: tried.at(-1)?.latency,
940
+ latencySource: tried.at(-1)?.latencySource,
941
+ ceiling: Number(this.config.healthMaxDelayMs ?? 400),
942
+ attempt: attempts,
943
+ attempts: tried,
944
+ attemptLimit: attempts,
945
+ giveUp: true,
795
946
  at: new Date().toISOString(),
796
947
  }
797
948
  this.health = report
798
- if (judged.usable) {
799
- this.log(`round ok on ${current} (${latency ?? '?'} ms, ${Object.keys(results).join('/')})`)
800
- void this.runSurveyTick()
801
- return report
802
- }
803
- if (tooSlow) {
804
- this.log(`round slow on ${current}: ${latency} ms > ${ceiling} ms ceiling (${counted.strikes}/${counted.limit})`)
805
- } else {
806
- this.log(
807
- `round bad on ${current} ${counted.strikes}/${counted.limit}: ${judged.failed.join(',') || 'no-answer'}` +
808
- (judged.limited.length > 0 ? ` (limited: ${judged.limited.join(',')})` : ''),
809
- )
810
- }
811
- if (!counted.giveUp) return report
949
+ this.log(`${attempts} attempts all failed on ${current}; searching every unblocked node`)
812
950
  return await this.switchAfterStrikes(report, plan, options)
813
951
  } finally {
814
952
  this.healthRunning = false
@@ -816,12 +954,22 @@ export class Runtime {
816
954
  }
817
955
 
818
956
  /**
819
- * Switch away from a node whose streak reached the limit.
957
+ * Switch away from a node that failed every attempt in its round.
820
958
  *
821
- * The search is bounded by `healthSwitchCandidates` and ordered by measured latency, because
822
- * a 54-node subscription cannot be probed for real inside one round without spending minutes
823
- * on nodes that answered worst last time. The node that just failed is excluded from its own
824
- * replacement, which is the difference between "we tried" and "we picked it again".
959
+ * Every unblocked node is measured, then the best one is chosen. Nothing is capped by default:
960
+ * the point of a switch is to find the best exit that exists right now, and a cap turns that
961
+ * into "the best of the first twelve", which on a 54-node subscription can silently pick a
962
+ * worse node than one further down the list. `healthSwitchCandidates` still exists as an
963
+ * operator escape hatch for a huge subscription, but its default is 0 (everything).
964
+ *
965
+ * "Best" is decided from this round's measurements, in this order:
966
+ *
967
+ * 1. usable (no gating probe failed) before anything else;
968
+ * 2. the lowest warm Google latency — this is the number the ceiling talks about, and the
969
+ * fastest working node is what "最优" means here;
970
+ * 3. fewer failed probes, then a quota-limited node before an unreachable one, as tie-breaks.
971
+ *
972
+ * The node that just failed is not a candidate for its own replacement.
825
973
  *
826
974
  * Busy-line handling: a switch tears down in-flight connections. When the line is carrying
827
975
  * work the switch waits for the next round unless `switchWhileBusy` is on — a broken node that
@@ -829,14 +977,14 @@ export class Runtime {
829
977
  *
830
978
  * @param report - the failing round.
831
979
  * @param plan - the probe plan.
832
- * @param options - `force` bypasses the busy gate.
980
+ * @param options - `bypassBusy` skips the busy gate.
833
981
  * @returns the round report with the switch result attached.
834
982
  */
835
983
  async switchAfterStrikes(report, plan, options = {}) {
836
984
  const traffic = await this.core.connections().catch(() => undefined)
837
985
  const limit = Number(this.config.reselectIdleConnections ?? 2)
838
- // `force` means "run this round now", not "ignore in-flight work": the two were conflated
839
- // in the first draft and an explicit check aborted a download. Only `bypassBusy` (or the
986
+ // `force` means "run this round now", not "ignore in-flight work": the two were conflated in
987
+ // an earlier draft and an explicit check aborted a download. Only `bypassBusy` (or the
840
988
  // configuration switch) may interrupt traffic.
841
989
  const bypassBusy = options.bypassBusy === true || this.config.switchWhileBusy === true
842
990
  if (!bypassBusy && traffic !== undefined && traffic.count > limit) {
@@ -845,36 +993,62 @@ export class Runtime {
845
993
  }
846
994
 
847
995
  const group = await this.core.group()
848
- const candidates = group.all.filter((name) => name !== 'DIRECT' && name !== 'REJECT' && name !== report.node)
849
- const cap = Number(this.config.healthSwitchCandidates ?? 12)
996
+ // `group.all` is what the core carries, which already excludes blocked nodes — the blocklist
997
+ // is applied as the provider's `exclude-filter`, so a hidden node never enters the table.
998
+ // Filtering again here is belt-and-braces for a table that was built before a blocklist edit.
999
+ const candidates = group.all.filter(
1000
+ (name) => name !== 'DIRECT' && name !== 'REJECT' && name !== report.node && !isBlocked(name, this.config.blocklist),
1001
+ )
1002
+ const cap = Number(this.config.healthSwitchCandidates ?? 0)
850
1003
  const ordered = cap > 0 ? candidates.slice(0, cap) : candidates
851
1004
  const startedAt = Date.now()
852
- const matrix = await this.core.realMatrix({
853
- nodes: ordered,
854
- specs: plan.specs,
855
- gating: plan.gating,
856
- delays: this.measured,
857
- budgetMs: Math.min(Number(this.config.selectBudgetMs ?? 90_000), 120_000),
858
- timeoutMs: this.config.probeTimeoutMs ?? 8000,
1005
+ this.log(`measuring ${ordered.length} candidate node(s) for a replacement`)
1006
+
1007
+ // Measured one at a time, reusing `measureNode` so a candidate is judged exactly like the
1008
+ // live node was — same probes, same ceiling, same warm latency. The budget is generous
1009
+ // because this path runs once per failure, not on every tick.
1010
+ const rows = []
1011
+ for (const name of ordered) {
1012
+ const measured = await this.measureNode(name, plan)
1013
+ if (measured === undefined) continue
1014
+ rows.push({ name, ...measured })
1015
+ this.healthRows.set(name, { results: measured.results, verdict: measured.verdict, at: Date.now() })
1016
+ }
1017
+ this.lastMatrix = rows.map((row) => ({ name: row.name, results: row.results }))
1018
+
1019
+ // Usable first, then fastest warm latency, then fewest failures, then a limited node before
1020
+ // an unreachable one. Missing latency sorts last among usable nodes: a node whose speed could
1021
+ // not be measured is not the one to prefer.
1022
+ const rank = (row) => [
1023
+ row.verdict?.usable === true ? 0 : 1,
1024
+ typeof row.latency === 'number' ? row.latency : Number.POSITIVE_INFINITY,
1025
+ (row.verdict?.failed ?? []).length,
1026
+ (row.verdict?.blocked ?? []).length,
1027
+ ]
1028
+ rows.sort((a, b) => {
1029
+ const ra = rank(a)
1030
+ const rb = rank(b)
1031
+ for (let i = 0; i < ra.length; i += 1) {
1032
+ if (ra[i] !== rb[i]) return ra[i] - rb[i]
1033
+ }
1034
+ return a.name.localeCompare(b.name)
859
1035
  })
860
- const best = matrix.best
861
- this.healthRows = new Map(
862
- matrix.rows.map((row) => [row.name, { results: row.results, verdict: row.verdict, at: Date.now() }]),
863
- )
864
- this.lastMatrix = matrix.rows.map((row) => ({ name: row.name, results: row.results }))
865
- // `usable` here means "no hard failure". A degraded node (quota spent, tunnel fine) is a
866
- // legitimate replacement: with every exit address out of GitHub quota, insisting on a
867
- // quota-clean node leaves the plugin on the node it just gave up on.
1036
+ const best = rows[0]
1037
+ const tested = rows.length
1038
+ const elapsedMs = Date.now() - startedAt
1039
+
868
1040
  if (best === undefined || best.verdict?.usable !== true) {
869
1041
  this.lastSwitch = {
870
1042
  state: 'no-alternative',
871
1043
  from: report.node,
872
1044
  at: new Date().toISOString(),
873
- tested: matrix.tested,
874
- elapsedMs: Date.now() - startedAt,
1045
+ tested,
1046
+ elapsedMs,
1047
+ // Every candidate's reason, so "no alternative" can be audited instead of trusted.
1048
+ rejected: rows.slice(0, 8).map((row) => ({ name: row.name, failed: row.verdict?.failed ?? [], latency: row.latency })),
875
1049
  }
876
- this.log(`no usable alternative to ${report.node} out of ${matrix.tested} tested`)
877
- return { ...report, state: 'no-alternative', tested: matrix.tested }
1050
+ this.log(`no usable alternative to ${report.node} out of ${tested} tested`)
1051
+ return { ...report, state: 'no-alternative', tested, elapsedMs }
878
1052
  }
879
1053
 
880
1054
  await this.core.select(best.name)
@@ -886,13 +1060,22 @@ export class Runtime {
886
1060
  to: best.name,
887
1061
  at: new Date().toISOString(),
888
1062
  failed: report.verdict?.failed ?? [],
889
- limited: report.verdict?.limited ?? [],
890
1063
  degraded: best.verdict?.degraded === true,
891
- tested: matrix.tested,
892
- elapsedMs: Date.now() - startedAt,
1064
+ latency: best.latency,
1065
+ tested,
1066
+ elapsedMs,
1067
+ }
1068
+ this.log(`switched ${report.node} -> ${best.name} (${best.latency ?? '?'} ms) after ${report.attemptLimit ?? report.attempts?.length ?? 3} failed attempts`)
1069
+ return {
1070
+ ...report,
1071
+ state: 'switched',
1072
+ from: report.node,
1073
+ to: best.name,
1074
+ switchedTo: best.name,
1075
+ toLatency: best.latency,
1076
+ tested,
1077
+ elapsedMs,
893
1078
  }
894
- this.log(`switched ${report.node} -> ${best.name} after ${report.strikes} bad rounds`)
895
- return { ...report, state: 'switched', from: report.node, to: best.name, switchedTo: best.name, tested: matrix.tested }
896
1079
  }
897
1080
 
898
1081
  /**
@@ -1736,8 +1919,13 @@ export class Runtime {
1736
1919
  health: {
1737
1920
  enabled: this.config.autoSwitch !== false && this.config.healthRoundSeconds > 0,
1738
1921
  everySeconds: this.config.healthRoundSeconds,
1922
+ /** Consecutive attempts inside one round before the node is given up on. */
1923
+ attempts: this.config.healthAttempts,
1739
1924
  strikeLimit: this.watch.strikeLimit,
1740
1925
  maxDelayMs: this.config.healthMaxDelayMs,
1926
+ baselineProbe: this.config.healthBaselineProbe,
1927
+ /** 0 means "measure every unblocked node when switching". */
1928
+ switchCandidates: this.config.healthSwitchCandidates,
1741
1929
  surveyEvery: this.config.healthSurveyEvery,
1742
1930
  survey: this.lastSurvey ?? null,
1743
1931
  lastRound: this.health ?? null,
@@ -1767,7 +1955,17 @@ export class Runtime {
1767
1955
  })),
1768
1956
  },
1769
1957
  /** Whether a download could be attempted at all on this platform. */
1770
- platformSupported: platformKey() !== undefined,
1958
+ /**
1959
+ * Whether a core can be obtained on this platform at all.
1960
+ *
1961
+ * `platformKey()` only says the release has an asset for this pair. Reporting that alone as
1962
+ * "supported" was wrong on Linux: the panel said yes while both acquisition paths refused —
1963
+ * there is no vendored copy for it, and a pinned `coreVersion` had no digest entry. What
1964
+ * actually matters is whether at least one path exists, so both are checked and the answer
1965
+ * says which one it is.
1966
+ */
1967
+ platformSupported: platformKey() !== undefined || vendoredFor() !== undefined,
1968
+ coreSource: vendoredFor() !== undefined ? 'bundled' : platformKey() !== undefined ? 'download' : undefined,
1771
1969
  degraded: this.degraded,
1772
1970
  lastError: this.lastError ?? this.core?.lastError,
1773
1971
  probe: this.lastProbe,
package/lib/core.js CHANGED
@@ -708,6 +708,24 @@ export class Core {
708
708
  */
709
709
  async remeasure(spec, options = {}) {
710
710
  if (this.probePort === undefined || spec === undefined) return undefined
711
+ // The PROBE group must already point at the node under test, and the only caller of
712
+ // `remeasure` is the latency measurement right after `probeNodeReal`. Switching again here
713
+ // would be harmless but would also hide the dependency, so it is asserted instead: a caller
714
+ // that measures latency without first probing that node gets a warning, not a number that
715
+ // silently belongs to a different node.
716
+ if (options.expectNode !== undefined && options.expectNode !== null) {
717
+ try {
718
+ const group = await this.probeGroup()
719
+ if (group.now !== options.expectNode) {
720
+ this.log(
721
+ `remeasure: PROBE group is on ${group.now ?? '(none)'} but the caller expects ${options.expectNode}; re-pointing it`,
722
+ )
723
+ await this.selectProbe(options.expectNode)
724
+ }
725
+ } catch (error) {
726
+ this.log(`remeasure: could not confirm the probe group: ${error?.message ?? error}`)
727
+ }
728
+ }
711
729
  const results = await runProbes(this.probePort, [spec], options)
712
730
  return results[spec.id]
713
731
  }
package/lib/corefetch.js CHANGED
@@ -22,8 +22,10 @@
22
22
  */
23
23
  import { createHash } from 'node:crypto'
24
24
  import { spawn } from 'node:child_process'
25
- import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
25
+ import { createReadStream, createWriteStream, chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
26
+ import { open } from 'node:fs/promises'
26
27
  import { join } from 'node:path'
28
+ import { createGunzip } from 'node:zlib'
27
29
 
28
30
  /**
29
31
  * Mirror prefixes tried before the direct GitHub URL.
@@ -84,6 +86,36 @@ export const KNOWN_ARCHIVES = {
84
86
  size: 22417383,
85
87
  archive: 'zip',
86
88
  },
89
+ // Every Linux and macOS asset is a bare gzip-compressed binary, not a tar — see
90
+ // `unpackCore`. The `-compatible` builds are preferred for the same reason as on Windows:
91
+ // they are compiled for the oldest supported CPU baseline, so a `v3`-style build cannot
92
+ // crash on an older machine with SIGILL. Ubuntu 24.04 and 26.04 both run these: the payload
93
+ // is statically linked (no PT_INTERP, no GLIBC_* symbols), so the distro's glibc version is
94
+ // irrelevant.
95
+ 'linux-x64': {
96
+ url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-linux-amd64-compatible-v1.19.34.gz',
97
+ digest: '2763f5b414527f7baf6dc57e3f82f3ab561eedf34bfd7c2f2cde1f7e592efe06',
98
+ size: 22766457,
99
+ archive: 'gz',
100
+ },
101
+ 'linux-arm64': {
102
+ url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-linux-arm64-v1.19.34.gz',
103
+ digest: 'daaf78a6240a282cdfd75bcbf98fe321f6bd52765cc29e79f344191198f0b50f',
104
+ size: 20684679,
105
+ archive: 'gz',
106
+ },
107
+ 'darwin-x64': {
108
+ url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-darwin-amd64-compatible-v1.19.34.gz',
109
+ digest: '703bceaa494732fa456f47e6ac2f06bf0bc5593d4c927d5f61e10f1a31039c37',
110
+ size: 22213898,
111
+ archive: 'gz',
112
+ },
113
+ 'darwin-arm64': {
114
+ url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-darwin-arm64-v1.19.34.gz',
115
+ digest: '1a7a20eca63fbbaec90137717465bfde488d0db2a3a79b8fadebf9b2545b6e4c',
116
+ size: 20649699,
117
+ archive: 'gz',
118
+ },
87
119
  },
88
120
  }
89
121
 
@@ -524,13 +556,23 @@ function runTool(command, args) {
524
556
  /**
525
557
  * Unpack the archive and move the executable into place.
526
558
  *
527
- * `tar` is used for `.gz` on every platform (it is present on Windows 10+, macOS and
528
- * Linux, and reads gzip natively). `.zip` also goes through `tar` on Windows, whose
529
- * bundled `bsdtar` reads zip; that avoids shipping an unzip library for one platform.
559
+ * Two archive shapes have to be handled, and conflating them is what broke Linux:
560
+ *
561
+ * 1. a **tar** (optionally gzipped) — the Windows release assets are `.zip`, whose entries
562
+ * carry the build-suffixed name;
563
+ * 2. a **bare gzip-compressed binary** — every Linux and macOS release asset is this shape.
564
+ * Measured on v1.19.34: `mihomo-linux-amd64-compatible-v1.19.34.gz` decompresses to a single
565
+ * 61 948 030-byte ELF with no `ustar` header at offset 257, and the darwin assets are the same
566
+ * with a Mach-O payload. `tar -xzf` cannot read either, so it failed with
567
+ * "Unrecognized archive format" *after* a successful 22 MB download.
568
+ *
569
+ * So a `.gz` is decompressed with `node:zlib` (no external tool, present on every Node ≥ 22
570
+ * build) and then classified: a tar payload is extracted with `tar`, a bare payload *is* the
571
+ * core and is moved straight into place. That also removes the dependency on `tar` being
572
+ * installed for the common Linux case, which matters on slim Ubuntu images.
530
573
  *
531
- * The archive's own file name is not trusted to equal the final name: whichever file
532
- * looks like the core is renamed, so a release that changes its internal name keeps
533
- * working.
574
+ * The archive's own file name is not trusted to equal the final name: whichever file looks like
575
+ * the core is renamed, so a release that changes its internal name keeps working.
534
576
  *
535
577
  * @param archivePath - downloaded archive.
536
578
  * @param kind - `zip` or `gz`.
@@ -541,34 +583,137 @@ function runTool(command, args) {
541
583
  export async function unpackCore(archivePath, kind, workDir, finalPath) {
542
584
  mkdirSync(workDir, { recursive: true })
543
585
  if (kind === 'gz') {
544
- // -z: gzip, -x: extract, -f: file, -O: to stdout would lose the name; extract then find.
545
- await runTool('tar', ['-xzf', archivePath, '-C', workDir])
546
- } else if (kind === 'zip') {
547
- await runTool('tar', ['-xf', archivePath, '-C', workDir])
548
- } else {
549
- throw new Error(`unsupported archive kind "${kind}"`)
586
+ // 1. Decompress once, to a file. Streaming keeps the 61 MB payload off the heap.
587
+ const inflated = join(workDir, 'payload.bin')
588
+ await gunzipFile(archivePath, inflated)
589
+ // 2. Is the payload a tar? A POSIX tar carries "ustar" at offset 257 of its header block.
590
+ if (await isTarArchive(inflated)) {
591
+ // Some releases ship `mihomo-linux-amd64-v1.19.34.gz` where the .gz wraps a tar.
592
+ await runTool('tar', ['-xf', inflated, '-C', workDir])
593
+ const source = pickCoreFrom(workDir)
594
+ return await placeCore(source, finalPath)
595
+ }
596
+ // 3. A bare binary: it is the core, already fully decompressed.
597
+ return await placeCore(inflated, finalPath)
598
+ }
599
+
600
+ if (kind === 'zip') {
601
+ // `.zip` only ever arrives on Windows (its assets are the only zip ones), where the bundled
602
+ // `bsdtar` reads it. On Linux `unzip` is tried first and `tar` second, because GNU tar cannot
603
+ // read zip and a stock Ubuntu image may have either tool or neither — the error names both.
604
+ if (process.platform === 'win32') {
605
+ await runTool('tar', ['-xf', archivePath, '-C', workDir])
606
+ } else {
607
+ try {
608
+ await runTool('unzip', ['-o', '-q', archivePath, '-d', workDir])
609
+ } catch (first) {
610
+ try {
611
+ await runTool('tar', ['-xf', archivePath, '-C', workDir])
612
+ } catch (second) {
613
+ throw new Error(
614
+ `could not unpack ${archivePath}: neither \`unzip\` nor a zip-capable \`tar\` worked ` +
615
+ `(unzip: ${first?.message ?? first}; tar: ${second?.message ?? second}). ` +
616
+ `Install unzip, or download the .gz asset for this platform instead.`,
617
+ )
618
+ }
619
+ }
620
+ }
621
+ return await placeCore(pickCoreFrom(workDir), finalPath)
622
+ }
623
+
624
+ throw new Error(`unsupported archive kind "${kind}"`)
625
+ }
626
+
627
+ /**
628
+ * Stream a gzip file into a plain file.
629
+ *
630
+ * @param archivePath - the `.gz` file.
631
+ * @param destination - where the decompressed bytes go.
632
+ */
633
+ function gunzipFile(archivePath, destination) {
634
+ return new Promise((resolve, reject) => {
635
+ const input = createReadStream(archivePath)
636
+ const output = createWriteStream(destination)
637
+ const gunzip = createGunzip()
638
+ const fail = (error) => {
639
+ input.destroy()
640
+ output.destroy()
641
+ gunzip.destroy()
642
+ reject(error)
643
+ }
644
+ input.once('error', fail)
645
+ output.once('error', fail)
646
+ gunzip.once('error', fail)
647
+ output.once('finish', resolve)
648
+ input.pipe(gunzip).pipe(output)
649
+ })
650
+ }
651
+
652
+ /**
653
+ * Whether a file is a POSIX tar archive.
654
+ *
655
+ * @param path - file to test.
656
+ * @returns true when `ustar` sits at offset 257, which is where every tar variant puts it.
657
+ */
658
+ async function isTarArchive(path) {
659
+ const handle = await open(path, 'r')
660
+ try {
661
+ const buffer = Buffer.alloc(262)
662
+ const { bytesRead } = await handle.read(buffer, 0, 262, 0)
663
+ if (bytesRead < 262) return false
664
+ return buffer.subarray(257, 262).toString('latin1') === 'ustar'
665
+ } finally {
666
+ await handle.close()
550
667
  }
668
+ }
551
669
 
552
- const entries = readdirSync(workDir)
553
- // The archive names its payload after the build, not after the fixed name this plugin
554
- // stores it under: the Windows zip holds `mihomo-windows-amd64-compatible.exe`. Match the
555
- // build suffix rather than only the bare `mihomo.exe`, or a correct download is reported
556
- // as holding no core at all — which is exactly what happened on the first run.
670
+ /**
671
+ * Find the core executable among unpacked entries.
672
+ *
673
+ * @param workDir - directory holding unpacked files.
674
+ * @returns the path of the best candidate.
675
+ */
676
+ function pickCoreFrom(workDir) {
677
+ const entries = readdirSync(workDir).filter((name) => name !== 'payload.bin')
678
+ // The archive names its payload after the build, not after the fixed name this plugin stores it
679
+ // under: the Windows zip holds `mihomo-windows-amd64-compatible.exe`. Match the build suffix
680
+ // rather than only the bare name, or a correct download is reported as holding no core at all.
557
681
  const isCore = (name) =>
558
682
  /^(verge-)?mihomo([-.][\w.-]+)?(\.exe)?$/i.test(name) ||
559
683
  /^(verge-)?mihomo(-[\w.-]+)?\.exe$/i.test(name) ||
560
684
  /^clash(-meta)?([-.][\w.-]+)?(\.exe)?$/i.test(name)
561
685
  const wanted = entries.filter(isCore)
562
- // Prefer an exact `mihomo` / `mihomo.exe` when the archive ships several matches.
563
686
  wanted.sort((a, b) => Number(!/^(verge-)?mihomo(\.exe)?$/i.test(a)) - Number(!/^(verge-)?mihomo(\.exe)?$/i.test(b)))
564
- const source = wanted.length > 0 ? join(workDir, wanted[0]) : undefined
565
- if (source === undefined) {
687
+ if (wanted.length === 0) {
566
688
  throw new Error(`the archive held no core executable (found: ${entries.slice(0, 5).join(', ') || 'nothing'})`)
567
689
  }
690
+ return join(workDir, wanted[0])
691
+ }
692
+
693
+ /**
694
+ * Move a candidate into its final location and make it executable.
695
+ *
696
+ * @param source - the unpacked binary.
697
+ * @param finalPath - where it must live.
698
+ * @returns the path and its size.
699
+ */
700
+ async function placeCore(source, finalPath) {
568
701
  mkdirSync(join(finalPath, '..'), { recursive: true })
569
702
  if (existsSync(finalPath)) rmSync(finalPath, { force: true })
570
703
  renameSync(source, finalPath)
571
- if (process.platform !== 'win32') chmodSync(finalPath, 0o755)
704
+ // Linux and macOS refuse to exec a file without the execute bit, and the failure surfaces much
705
+ // later as an opaque EACCES from spawn. Applied on every non-Windows platform — and keyed on
706
+ // `process.platform`, which is genuinely the platform whose filesystem is being written, since
707
+ // the chmod has to land on the machine actually holding the file.
708
+ if (process.platform !== 'win32') {
709
+ try {
710
+ chmodSync(finalPath, 0o755)
711
+ } catch (error) {
712
+ // A read-only or noexec mount reports this; the caller's spawn will fail with a clearer
713
+ // message than a silent success would produce.
714
+ throw new Error(`could not make ${finalPath} executable: ${error?.message ?? error}`)
715
+ }
716
+ }
572
717
  return { path: finalPath, bytes: statSync(finalPath).size }
573
718
  }
574
719
 
package/lib/skill.js CHANGED
@@ -55,7 +55,8 @@ curl -sS -m 8 http://127.0.0.1:<宿主端口>/clash-proxy/status
55
55
  | \`routingHealthy\` | 策略 + 内核同时成立 | \`true\` |
56
56
  | \`node\` | 当前出口 | 具体节点名,不是 \`DIRECT\` |
57
57
  | \`health.lastRound.state\` | 最近一轮真实探测结论 | \`ok\` / \`degraded\` |
58
- | \`health.lastRound.strikes\` | 连续失败轮数 / 上限 | 小于 \`strikeLimit\` |
58
+ | \`health.lastRound.attempt\` | 本轮第几次尝试通过的 | 1 或 2;3 表示三次都不合格 |
59
+ | \`health.lastRound.attemptLimit\` | 一轮内最多试几次 | 3 |
59
60
 
60
61
  \`routingHealthy: true\` 就**什么都不要做**,直接跑原命令。
61
62
 
@@ -124,13 +125,19 @@ clash_proxy action=select node=<精确节点名>
124
125
 
125
126
  ## 四、自动切换已经在跑,不要抢它
126
127
 
127
- 插件自己每 30 秒做一轮:通过当前节点发真请求(基础连通 204、GitHub API 连配额、git 拉取),
128
- **可用且延迟低于阈值**就保持;连续 3 轮不合格才自动切到最优节点。
128
+ 插件自己每 30 秒做一轮。**一轮之内**会连续试当前节点最多 3 次:
129
+
130
+ 1. 通过它发真请求(基础连通 204、GitHub API 连配额、git 拉取)+ 测 Google 延迟;
131
+ 2. 不合格就**立刻**再试一次,不合格再试第三次——不等下一个 30 秒;
132
+ 3. 只要任何一次合格就保持,剩下的次数不浪费;
133
+ 4. 三次都不合格,就把**所有未被屏蔽的节点**各测一遍,切到「可用且真实延迟最低」的那个。
129
134
 
130
135
  所以:
131
136
 
132
- - 用户问「为什么还没换」,先看 \`health.lastRound.strikes\`:1/3、2/3 是正常的等待,不是卡住。
133
- - 不要在 \`strikes\` 还没到上限时手动换节点,那会把计数清零,坏节点永远攒不满 3 轮。
137
+ - 用户问「为什么还没换」,先看 \`health.lastRound.attempt\`:1 或 2 表示已经通过;3 表示三次全败、正在切换。
138
+ - 不合格 = **不可用**(某个门槛探针没通)**或真实延迟过高**(超过 \`health.maxDelayMs\`,默认 400 ms)。
139
+ - 三次重试是**同一轮内连续**的,所以坏节点几秒内就会被处理,不需要手动介入。
140
+ - 手动换节点会打断正在进行的切换搜索,没必要别动它。
134
141
  - 要立刻验证,用 \`action=health\` 强制跑一轮并看明细。
135
142
 
136
143
  ## 五、按症状查
@@ -144,6 +151,23 @@ clash_proxy action=select node=<精确节点名>
144
151
  | \`web_fetch\` 全部失败 | \`routingHealthy\` | 内核死了,级别 1 |
145
152
  | 只有某个 AI 服务连不上 | 该节点的 \`usable\` 与失败探针 | 该服务的地区/机房限制,换节点 |
146
153
  | 面板显示节点「限流」但还能上网 | —— | 正常,配额是单服务限制 |
154
+ | Linux 上首次启动很久没反应 | \`status.bootstrap\` | 正在下载 22 MB 内核,不是卡死 |
155
+
156
+ ## 五之二、Linux / Ubuntu 特有的事
157
+
158
+ Ubuntu 22.04 / 24.04 LTS / 26.04 LTS 都支持,且**不需要预装任何东西**。二进制是静态链接的(无 \`PT_INTERP\`、无 \`GLIBC_*\`),所以发行版 glibc 版本无关。
159
+
160
+ | 现象 | 真因 | 动作 |
161
+ |---|---|---|
162
+ | 首次启动什么都不发生,面板显示"未运行" | Linux 没有自带内核,需要下载 22 MB | 等首次下载完成(\`status.bootstrap\` 有进度),或点「下载内核」 |
163
+ | \`bootstrap\` 显示 \`Unrecognized archive format\` | 旧版用 \`tar -xzf\` 解 Linux 资产,而那是**裸 gzip 二进制**不是 tar | 升级到 0.10.0+(改用 \`node:zlib\` 解压) |
164
+ | \`no vendored core for linux-x64\` | 同上,旧版没有 Linux 自带内核且未开自动下载 | 升级,或设 \`corePath\` 指向已有的 \`mihomo\` |
165
+ | 内核文件存在但 \`spawn EACCES\` | 缺执行位 | \`chmod 755\` 那个 \`bin/mihomo\`;0.10.0+ 会自动设 |
166
+ | 下载卡住 | GitHub 在境内慢 | 插件会先试 gh-proxy.com / ghfast.top / ghproxy.net |
167
+
168
+ 内核落点固定为 \`\${DSH_HOME}/data/dsh-clash-proxy/bin/mihomo\`(Linux 上不带 \`.exe\`)。
169
+
170
+ **不要**用 \`apt install mihomo\` 之类的路径替换它:插件只认自己的二进制(或你显式配置的 \`corePath\`),混用系统的 Clash 会重演"两层代理互相抢"的老问题。
147
171
 
148
172
  ## 六、边界
149
173
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-clash-subscription",
3
- "version": "0.8.0",
4
- "description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin, with real-request node health checks every 30 seconds (status codes, GitHub quota, git fetch, Google latency under a 400 ms ceiling) and automatic switching to the best node after three consecutive failed rounds.",
3
+ "version": "0.10.0",
4
+ "description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin. Runs on Windows, Linux (Ubuntu 22.04/24.04/26.04 LTS) and macOS: the core is fetched and SHA-256 verified on platforms without a bundled copy, from a bare gzip asset unpacked with node:zlib. Every 30 seconds the live node gets up to three immediate real-request attempts; after three failures every unblocked node is measured and the fastest usable one is selected.",
5
5
  "keywords": [
6
6
  "dsh",
7
7
  "dsh-plugin",
@@ -34,7 +34,7 @@
34
34
  "locale/*.json",
35
35
  "icon.svg",
36
36
  "README.md",
37
- "CHANGELOG-0.8.0.md",
37
+ "CHANGELOG-0.10.0.md",
38
38
  "LICENSE"
39
39
  ],
40
40
  "engines": {
@@ -69,6 +69,7 @@
69
69
  "scripts": {
70
70
  "test": "node test/regression-070.mjs",
71
71
  "test:legacy": "node test/regression-063.mjs",
72
- "test:e2e": "node test/e2e-080.mjs"
72
+ "test:linux": "node test/regression-0100.mjs",
73
+ "test:e2e": "node test/e2e-090.mjs"
73
74
  }
74
75
  }
@@ -1,120 +0,0 @@
1
- # 0.8.0 · 一个循环、30 秒、延迟进判定;插件自带技能
2
-
3
- > 上一版 `0.7.0` · 本版 `0.8.0`
4
-
5
- ## 为什么改
6
-
7
- 0.7.0 有两个定时器做同一件事,而且延迟完全不参与判定:
8
-
9
- | 0.7.0 的字段 | 实际行为 |
10
- |---|---|
11
- | `reselectMinutes: 15` | 每 15 分钟按能力重挑一次节点 |
12
- | `healthRoundMinutes: 2` | 每 2 分钟真实探测当前节点 |
13
- | — | 延迟只显示在面板上,**从不影响去留** |
14
-
15
- 后果:一个 1 800 ms 的节点每次都通过探测,于是被永久保留,而所有走它的请求都慢得像卡住。
16
- 两个循环还会互相清零计数,同一个节点得到两份结论。
17
-
18
- ## 改了什么
19
-
20
- ### 1. 合并成一个循环
21
-
22
- `reselect` 不再是独立定时器,手动 `action=reselect` 变成「立刻跑一轮」。
23
- 删掉了 `scheduleReselect` / `stopReselect`,只留 `scheduleHealthRound`。
24
-
25
- ```
26
- 每 30 秒:
27
- ├─ 通过当前节点发真实请求(gstatic 204 / GitHub 配额 / git 拉取)
28
- ├─ 测 Google 延迟(warm)
29
- ├─ 可用 且 延迟 ≤ 400 ms → 保持,strikes = 0
30
- ├─ 不可用 或 延迟超阈值 → strikes += 1
31
- └─ strikes ≥ 3 → 排除当前节点,按真实探测结果切到最优
32
- ```
33
-
34
- | 字段 | 默认 | 说明 |
35
- |---|---|---|
36
- | `healthRoundSeconds` | **30** | 轮询间隔(秒)。0 = 关闭 |
37
- | `healthStrikeLimit` | 3 | 连续几轮不合格才切 |
38
- | `healthMaxDelayMs` | **400** | 延迟阈值;0 = 只看连通性 |
39
- | `healthBaselineProbe` | **google** | 延迟取哪个探针 |
40
- | `healthSurveyEvery` | 20 | 每 N 轮后台巡测其他节点(30 秒间隔下约 10 分钟) |
41
-
42
- 旧的 `healthRoundMinutes` 会自动迁移成秒(2 分钟 → 120 秒),不会静默回落到 30 秒默认。
43
-
44
- ### 2. 延迟改成 Google,且要 warm
45
-
46
- **基准是 Google 的 `generate_204`**:静态 204,没有 API 处理逻辑,是最接近「这个节点离你多远」的量。
47
-
48
- 但直接测出来是错的,实测两次修正:
49
-
50
- | 错法 | 实测 | 真因 |
51
- |---|---|---|
52
- | 用所有探针的**总和** | 健康节点 1 286 ms,其中 gstatic 只占 90 ms | GitHub 自己的处理时间和三次 TLS 握手都在总和里,节点不背这个锅 |
53
- | 用**第一次**请求 | 同一节点首轮 513 ms,之后 82 ms | 每个探针都是 `Connection: close`,首次要付 DNS + TCP + TLS;真实流量是复用的 |
54
-
55
- 所以延迟 = **Google 探针的第二次测量**。e2e 实测:`warm 149ms (cold 240ms)`,阈值 400 ms 内保持不动。
56
-
57
- ### 3. Google 不通 ≠ 节点慢
58
-
59
- Google 不是门槛探针(`gating: false`)。它不通时:
60
-
61
- - 不判 `slow`,不发明一个延迟;
62
- - `latencySource` 标为 `unreachable`,面板能解释;
63
- - 节点只按门槛探针判去留。
64
-
65
- 否则一个 Google 被限、但 GitHub/git 全通的节点会被当成慢节点切走。
66
-
67
- ### 4. 插件自带技能
68
-
69
- 原来这套排障知识只写在 README 和工具描述里,真正需要它的时候没人去翻。
70
- 现在通过 `ctx.skills.register()` 注册成技能 `clash-proxy-egress`,随插件加载/卸载:
71
-
72
- | 项 | 值 |
73
- |---|---|
74
- | 名字 | `clash-proxy-egress` |
75
- | 何时触发 | 境外命令失败(git/curl/npm/pip/web_fetch)、问代理通不通、问为什么某节点慢、要指定地区出口 |
76
- | 内容 | 取证三条命令 → 修复阶梯(start → select → restart → refresh,按代价从小到大)→ 按真实探测挑节点 → 不要抢自动切换 → 症状对照表 |
77
- | 长度 | 3 051 字符,含 8 个代码围栏 |
78
-
79
- 技能里明确写了两条最常犯的错:
80
-
81
- 1. **不要开桌面 Clash Verge 或改系统代理** —— 会和插件抢同一个 dispatcher,表现是「时通时不通」;
82
- 2. **`strikes` 没到上限时不要手动换节点** —— 会把计数清零,坏节点永远攒不满 3 轮。
83
-
84
- ### 5. 新增 `action=restart`
85
-
86
- 「内核在跑但控制 API 不应答」时的一条命令,不用先 stop 再 start。
87
-
88
- ## 验收
89
-
90
- ```
91
- node test/regression-070.mjs → 106 passed, 0 failed
92
- node test/regression-063.mjs → 31 passed, 0 failed
93
- node test/e2e-080.mjs → 21 passed, 0 failed(真内核 + 真订阅 + 真请求)
94
- ```
95
-
96
- e2e 真实输出:
97
-
98
- ```
99
- round#1: state=ok latency=149ms source=warm ceiling=400 strikes=0
100
- warm 149ms (cold 240ms) → 用第二次测量
101
- gstatic 204 / github 200 / git 200
102
-
103
- strict round (ceiling=1ms): state=slow latency=184ms strikes=1
104
- 前两轮不切换: slow/1 slow/2
105
- round3: state=switched from=🇸🇬 新加坡01 to=🇺🇸 美国02 tested=7
106
- ```
107
-
108
- ## 一个被测试抓住的判据错误(留档)
109
-
110
- 第一版把 `verdict.total`(所有门槛探针耗时之和)当延迟比 400 ms,e2e 立刻报
111
- `健康节点首轮通过: slow 1286ms`。改用 Google 单探针后又报 `slow 513ms`,
112
- 再查才发现那是冷启动。两次都是判据错,不是节点慢——**如果没在真机上跑一遍,
113
- 上线后会把整批健康节点判成慢节点并疯狂切换**。
114
-
115
- ## 遗留
116
-
117
- - 面板新增的两个字段(`healthMaxDelayMs` / `healthSurveyEvery`)已接进 `client.js`,
118
- 但**没有在真浏览器里看过渲染**(本轮只跑了逻辑测试)。
119
- - `healthSurveyEvery` 的后台巡测只做了单元级验证,真机轮次里被设为 0 跳过,
120
- 以避免 e2e 结果受巡测干扰。