dsh-session-superagent 0.9.213 → 0.9.215

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/CHANGELOG.md CHANGED
@@ -2,6 +2,83 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.9.215] - 2026-11-05 —— 把「测试在自己算」的两个函数抽出来,断言才真的在断言
6
+
7
+ ### ① `effectiveIntervalMs` 从 `index.js` 挪到 `watch.js`
8
+
9
+ T23 指出 `routes.test.mjs` 那条断言其实在**算测试自己的 `Math.max`** —— `effectiveIntervalMs()` 一次没被调用。
10
+ 写反、写成 `Math.min`、忘了乘 1000(60 毫秒轮询 = 疯转),测试全都绿。
11
+
12
+ 它是纯函数,挪进 `watch.js` 之后可以直接 import:
13
+
14
+ ```
15
+ effectiveIntervalMs({ minIntervalSec: 120 }, 60000) === 120000 ← 乘了 1000
16
+ effectiveIntervalMs({ minIntervalSec: 10 }, 300000) === 300000 ← 自己更大时用自己的
17
+ effectiveIntervalMs({ minIntervalSec: 'abc' }, 60000) === 60000 ← 坏值不产出 NaN
18
+ ```
19
+
20
+ ### ② `isOfflineMode()` 从 `run()` 闭包里抽出来
21
+
22
+ `route-resilience.test.mjs` 那条叫「设了 OFFLINE 就不再调 gh」的用例,
23
+ **实际只测了两个跟离线无关的纯函数** —— 删掉短路照样绿。
24
+
25
+ 现在离线判定是纯函数,真值表可以真断言 —— 尤其是 `'0'` / `'false'` 不该被当成离线这个坑:
26
+
27
+ ```
28
+ '1' / 'true' / ' ON ' → true
29
+ '0' / 'false' / 未设 → false
30
+ ```
31
+
32
+ ### ③ 为什么值得单独立一条
33
+
34
+ 这两条都属于同一类:**测试通过「重算一遍」来假装验证实现**。
35
+ 它比没有测试更糟 —— 看覆盖率是绿的,看代码是真没测。
36
+
37
+ ### 证据
38
+
39
+ ```
40
+ node --test → 365/365(新增:effectiveIntervalMs 真实用法 6 组断言)
41
+ ```
42
+
43
+ ## [0.9.214] - 2026-11-05 —— 覆盖率高 ≠ 测试有效:5 条「其实测不出东西」的断言
44
+
45
+ ### ① 先说结论
46
+
47
+ `lib/watch.js` 98% 行覆盖、364 个测试全绿 —— T23 的断言强度审计说明**这不代表它们真在守东西**:
48
+
49
+ - 断言数 < 2 的用例 **43 个**;
50
+ - `assert.ok` 是「只看真假不看内容」的 **33 个**,其中 6 个往后不再对该值做任何内容断言;
51
+ - 0 个 `assert.ok(true)` / 两边同表达式(这点是好的)。
52
+
53
+ ### ② 修掉的 5 条(每条都先确认「它现在测不出什么」)
54
+
55
+ | 位置 | 以前 | 现在 |
56
+ |---|---|---|
57
+ | `watch.test.mjs` 事件上限 | `assert.ok(length <= 22)` —— **恒真**(实际最多 7 条) | 断言真实上限 8 以内且不为空 |
58
+ | `watch.test.mjs` cap 兜底 | `assert.equal(typeof x, 'number')` —— 返回任意数字都过 | 断言 **`cap=0` 与 `cap=6` 结果相同** |
59
+ | `redact.test.mjs` | `assert.ok(redact(input).includes('***'))` —— 部分脱敏/残留一段密钥都能过 | 断言 **`hasSecret(脱敏后) === false`** |
60
+ | `gate-lock.test.mjs` | `assert.ok(existsSync(lockPath))` —— 那个目录是**测试自己**刚 mkdir 的 | 断言 `owner.json` 里的 pid **换成了当前进程** |
61
+ | `client.test.mjs` defaults | 只断言 `all.length > 0`,名字却说「从 defaults 读」 | 收集 **placeholder 属性**,断言自定义 defaults 真的渲染进去了 |
62
+
63
+ ### ③ 顺带修的产品 bug(T23 记录、我改掉)
64
+
65
+ `client.js` 有两处把「每小时最多唤醒次数 / 单次最多条数」的占位符**写死**成 `'6(1-60)'` / `'5(1-20)'`,
66
+ 而同页别的字段都是从 `/state` 的 `defaults` 读的 —— 这正是上面那条测试「声称要防」的回归。
67
+ 现在统一走 `String(DEFAULTS.x || 默认值)`。
68
+
69
+ ### 证据
70
+
71
+ ```
72
+ node --test → 364/364
73
+ ui-audit → 11/11(100 分)
74
+ ```
75
+
76
+ ### 未修(登记)
77
+
78
+ `routes.test.mjs` 有一条在**算测试自己的 `Math.max`**(`effectiveIntervalMs()` 一次没被调用);
79
+ `route-resilience.test.mjs` 有一条说「设了 OFFLINE 就不调 gh」但只测了两个纯函数。
80
+ 这两条要先把内部函数挂进 `__test` 导出才能真断言,改动面比断言本身大,单独立项。
81
+
5
82
  ## [0.9.213] - 2026-11-05 —— 失败后不回读、awesome 早已合并、走查清单合成一份
6
83
 
7
84
  ### ① 面板失败后不回读(T22 B3 的另一半)
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.213-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.215-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
  [![awesome](https://img.shields.io/badge/awesome-dsh--plugin-%E2%9C%93-success.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
@@ -145,7 +145,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
145
145
  ## 开发
146
146
 
147
147
  ```sh
148
- node --test # 364 项单测
148
+ node --test # 365 项单测
149
149
  ```
150
150
 
151
151
  ### 工具输出:文本给人和 agent,JSON 给程序
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.213'
17
+ const CLIENT_VERSION = '0.9.215'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -1346,8 +1346,8 @@ window.__ModuleLoader__.load({
1346
1346
  field('活跃时段', h(HoursField, { value: draft.activeHours, onChange: (next) => setField({ ...draft, activeHours: next }) }), '只在这个时间段内唤醒;窗口外只攒条目,不打扰'),
1347
1347
  field('目标/规则', h(Input, { value: draft.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setField({ ...draft, goal: e.target.value }) })),
1348
1348
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.onlyAssigned, onChange: (v) => setField({ ...draft, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1349
- field('单次最多唤醒条数', h(Input, { value: draft.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setField({ ...draft, batchLimit: e.target.value }) })),
1350
- field('每小时最多唤醒次数', h(Input, { value: draft.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setField({ ...draft, maxWakesPerHour: e.target.value }) })),
1349
+ field('单次最多唤醒条数', h(Input, { value: draft.batchLimit || '', placeholder: String(DEFAULTS.batchLimit || 5) + '(1-20)', onChange: (e) => setField({ ...draft, batchLimit: e.target.value }) })),
1350
+ field('每小时最多唤醒次数', h(Input, { value: draft.maxWakesPerHour || '', placeholder: String(DEFAULTS.maxWakesPerHour || 6) + '(1-60)', onChange: (e) => setField({ ...draft, maxWakesPerHour: e.target.value }) })),
1351
1351
  field('这条会话每小时最多被唤醒', h(Input, { value: draft.sessionMaxWakes || '', placeholder: String(DEFAULTS.sessionMaxWakes || 12) + '(1-60)', onChange: (e) => setField({ ...draft, sessionMaxWakes: e.target.value }) }), '跨所有守累计:守 5 个仓库时,光有单守上限挡不住叠加'),
1352
1352
  field('优先级(在「单次最多唤醒条数」内先挑谁)', h('div', { className: 'dt-actions' },
1353
1353
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityReopened !== false, onChange: (v) => setField({ ...draft, priorityReopened: v }), label: '重开优先' }), '被重开的排最前'),
@@ -1746,8 +1746,8 @@ window.__ModuleLoader__.load({
1746
1746
  h('div', { className: 'dt-form' },
1747
1747
  field('仓库', h(Input, { value: form.repo, placeholder: 'owner/name,或 gitee:owner/name', onChange: (e) => setForm({ ...form, repo: e.target.value }) })),
1748
1748
  field('间隔(秒)', h(Input, { value: form.intervalSec, onChange: (e) => setForm({ ...form, intervalSec: e.target.value }) })),
1749
- field('单次最多唤醒条数', h(Input, { value: form.batchLimit || '', placeholder: '5(1-20)', onChange: (e) => setForm({ ...form, batchLimit: e.target.value }) })),
1750
- field('每小时最多唤醒次数', h(Input, { value: form.maxWakesPerHour || '', placeholder: '6(1-60)', onChange: (e) => setForm({ ...form, maxWakesPerHour: e.target.value }) })),
1749
+ field('单次最多唤醒条数', h(Input, { value: form.batchLimit || '', placeholder: String(DEFAULTS.batchLimit || 5) + '(1-20)', onChange: (e) => setForm({ ...form, batchLimit: e.target.value }) })),
1750
+ field('每小时最多唤醒次数', h(Input, { value: form.maxWakesPerHour || '', placeholder: String(DEFAULTS.maxWakesPerHour || 6) + '(1-60)', onChange: (e) => setForm({ ...form, maxWakesPerHour: e.target.value }) })),
1751
1751
  field('只处理这些标签', h(Input, { value: form.labels, placeholder: '逗号分隔,留空 = 全部', onChange: (e) => setForm({ ...form, labels: e.target.value }) })),
1752
1752
  field('活跃时段', h(HoursField, { value: form.activeHours, onChange: (next) => setForm({ ...form, activeHours: next }) }), '只在这个时间段内唤醒;不填 = 全天'),
1753
1753
  field('目标/规则', h(Input, { value: form.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setForm({ ...form, goal: e.target.value }) })),
package/lib/gh-format.js CHANGED
@@ -596,3 +596,15 @@ export function quotaDeferText(remaining, resumeInMs, now = Date.now()) {
596
596
  text: '额度紧张(剩余 ' + String(remaining) + '),已推迟到 ' + hhmm + ' UTC',
597
597
  }
598
598
  }
599
+
600
+ /**
601
+ * 离线模式判定(`DSH_SUPERAGENT_OFFLINE`)。
602
+ *
603
+ * 审核 T23:以前这条判断是内联的 `process.env.DSH_SUPERAGENT_OFFLINE === '1'`,
604
+ * 藏在 `lib/index.js` 的 `run()` 闭包里 —— 测试只能「跑整套用例看快不快」来间接证明。
605
+ * 抽成纯函数后可以真的断言它的真值表(尤其是 `'0'` / `'false'` 不该被当成离线)。
606
+ */
607
+ export function isOfflineMode(env = process.env) {
608
+ const raw = String((env && env.DSH_SUPERAGENT_OFFLINE) || '').trim().toLowerCase()
609
+ return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on'
610
+ }
package/lib/index.js CHANGED
@@ -23,10 +23,10 @@ import { zstdDecompressSync } from 'node:zlib'
23
23
 
24
24
  import { redact } from './redact.js'
25
25
  import { decodeBody, truncateUtf8 } from './body.js'
26
- import { quotaDeferText } from './gh-format.js'
26
+ import { quotaDeferText, isOfflineMode } from './gh-format.js'
27
27
  import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
28
28
  import {
29
- planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
29
+ effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
30
30
  parseRepoSpec, markGiteeReopened,
31
31
  TRIAGE_SIGNALS, accessNote, wakeCriteria, sessionMissingVerdict, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, diagnoseEmptyBody, diagnoseBadBody, isAuthBroken, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, enterActiveHoursDefer, recordOtherError, permanentBackoffMs, RETRY_BUDGET_ATTEMPTS, RETRY_SLOW_CAP_MINUTES, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
32
32
  shouldRunCleanup,
@@ -43,7 +43,7 @@ import {
43
43
 
44
44
  export const name = 'dsh-session-superagent'
45
45
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
46
- export const SERVER_VERSION = '0.9.213'
46
+ export const SERVER_VERSION = '0.9.215'
47
47
  export const inject = ['tools', 'agents', 'webServer']
48
48
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
49
49
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -478,11 +478,6 @@ function noteEvent(entry, kind, text) {
478
478
  } catch { /* 观测失败不能影响主流程 */ }
479
479
  }
480
480
 
481
- // 实际间隔:自己的配置与 GitHub 要求的 x-poll-interval 取大者
482
- function effectiveIntervalMs(entry, baseMs) {
483
- const floor = (Number(entry.minIntervalSec) || 0) * 1000
484
- return Math.max(Number(baseMs) || 0, floor)
485
- }
486
481
 
487
482
  function bumpFailure(entry, baseMs) {
488
483
  entry.consecutiveFailures = (Number(entry.consecutiveFailures) || 0) + 1
@@ -613,7 +608,8 @@ function run(file, args, options = {}) {
613
608
  return
614
609
  }
615
610
  }
616
- if (file === 'gh' && process.env.DSH_SUPERAGENT_OFFLINE === '1') {
611
+ // 离线判定抽成纯函数(有单测),见 isOfflineMode。
612
+ if (file === 'gh' && isOfflineMode()) {
617
613
  resolve({ code: 0, stdout: offlineGhReply(args), stderr: '' })
618
614
  return
619
615
  }
package/lib/watch.js CHANGED
@@ -1244,3 +1244,16 @@ export function planWakeSettlement(entry, { ok, reason, fresh = [], firstSync =
1244
1244
  error: null,
1245
1245
  }
1246
1246
  }
1247
+
1248
+ /**
1249
+ * 实际轮询间隔:自己的配置与 GitHub 要求的 `x-poll-interval` 取**大者**。
1250
+ *
1251
+ * 审核 T23:这个函数以前在 `lib/index.js` 里(不导出),于是测试只能自己算一遍
1252
+ * `Math.max(base, minIntervalSec * 1000)` —— **断言的是测试自己的算术**,
1253
+ * `Math.max` 写反、写成 `Math.min`、或者忘了乘 1000,测试全都绿。
1254
+ * 挪到这里(纯函数、可直接 import)之后,才能真正测它。
1255
+ */
1256
+ export function effectiveIntervalMs(entry, baseMs) {
1257
+ const floor = (Number(entry && entry.minIntervalSec) || 0) * 1000
1258
+ return Math.max(Number(baseMs) || 0, floor)
1259
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.213",
3
+ "version": "0.9.215",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",