Initial import of streamline

This commit is contained in:
2026-11-16 17:26:44 -08:00
commit 8e4aec1855
1221 changed files with 274256 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
import { test, expect, describe } from "bun:test";
/**
* 空档部署的换装时机。
*
* 这里测的是判据本身,不是 applyPendingDeployIfIdle —— 后者会 process.exit(),没法在
* 测试里跑。判据是「连续空闲够久」而不是「此刻空闲」,理由值得钉住:
*
* 一批执行结束的那一刻,正是控制面开始回连这台节点的那一刻 —— manual_review 跃迁
* 会一口气发出五个请求(报告生成、证据镜像、执行条件入库、ImplReport 归档、会话摘要
* 归档)。控制面要先过几趟 DB、归档那条还要反向拉一次本节点的报告文件,需要好几秒;
* 而 claim 循环 1.5 秒就回到顶部看见「空闲」。节点是**结构性地**赢这场竞速的,于是
* 对任何 armed 了部署的节点,"释放它的那一批"的收尾产物必然被切掉。
*
* 实测 30 天:53 次可读性报告生成死于 2 秒内的连接被拒,占全部自动生成的 2.8%。
*/
describe("空档部署:换装前要求持续空闲", () => {
const SETTLE = 90_000;
/** 判据本体:忙则清零,闲则累积,够久才放行。 */
function settled(idleSince: number, now: number, busy: boolean): { idleSince: number; ok: boolean } {
if (busy) return { idleSince: 0, ok: false };
const started = idleSince === 0 ? now : idleSince;
return { idleSince: started, ok: now - started >= SETTLE };
}
test("刚空闲的那一瞬间不换装 —— 这正是收尾请求还在路上的时刻", () => {
const t0 = 1_000_000;
expect(settled(0, t0, false).ok).toBe(false);
expect(settled(t0, t0 + 1_500, false).ok).toBe(false); // claim 循环回到顶部的时刻
});
test("持续空闲够久才换装", () => {
const t0 = 1_000_000;
expect(settled(t0, t0 + SETTLE - 1, false).ok).toBe(false);
expect(settled(t0, t0 + SETTLE, false).ok).toBe(true);
});
test("窗口内来了活就清零 —— 报告生成到达时正该如此", () => {
const t0 = 1_000_000;
const busy = settled(t0, t0 + 30_000, true);
expect(busy.idleSince).toBe(0);
expect(busy.ok).toBe(false);
// 干完之后重新开始计时,而不是接着之前的 30 秒。
const after = settled(busy.idleSince, t0 + 200_000, false);
expect(after.ok).toBe(false);
expect(after.idleSince).toBe(t0 + 200_000);
});
test("窗口必须宽过 claim 循环的间隔,否则等于没加", () => {
// claim 循环 drain 时每 1.5 秒回到顶部一次。窗口跟它同量级的话,
// 节点照样在收尾请求到达前就换装了。
expect(SETTLE).toBeGreaterThan(1_500 * 10);
});
});