dsh-session-superagent 0.9.214 → 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,44 @@
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
+
5
43
  ## [0.9.214] - 2026-11-05 —— 覆盖率高 ≠ 测试有效:5 条「其实测不出东西」的断言
6
44
 
7
45
  ### ① 先说结论
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.214-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.214'
17
+ const CLIENT_VERSION = '0.9.215'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
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.214'
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.214",
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",