@sema-agent/settings-schema 33.0.0 → 34.0.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.
- package/CHANGELOG.md +525 -0
- package/README.md +151 -17
- package/conformance/VERSION +1 -1
- package/dist/api/wire-scalars.d.ts +3 -2
- package/dist/api/wire-scalars.js +3 -2
- package/dist/atomic-write.d.ts +59 -0
- package/dist/atomic-write.js +303 -1
- package/dist/cli.d.ts +6 -3
- package/dist/cli.js +16 -4
- package/dist/config-dir-migration.d.ts +4 -3
- package/dist/config-dir-migration.js +36 -21
- package/dist/config-fns.d.ts +60 -14
- package/dist/config-fns.js +48 -13
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/warnings.d.ts +1 -1
- package/dist/conformance/warnings.js +3 -3
- package/dist/conformance/web-admin-credential-lock.d.ts +17 -0
- package/dist/conformance/web-admin-credential-lock.js +346 -0
- package/dist/cross-session.d.ts +2 -2
- package/dist/declared-capture.js +1 -1
- package/dist/fleet.d.ts +125 -7
- package/dist/fleet.js +138 -3
- package/dist/hooks-config.d.ts +12 -4
- package/dist/hooks-config.js +28 -11
- package/dist/index.js +2 -2
- package/dist/local-load.d.ts +66 -1
- package/dist/local-load.js +123 -39
- package/dist/mcp-request-entry.d.ts +24 -5
- package/dist/mcp-request-entry.js +57 -17
- package/dist/node.d.ts +1 -0
- package/dist/node.js +2 -0
- package/dist/read-sentences.d.ts +16 -4
- package/dist/read-sentences.js +34 -12
- package/dist/safety-merge-spec.d.ts +5 -5
- package/dist/safety-merge-spec.js +5 -3
- package/dist/settings-units.d.ts +35 -1
- package/dist/settings-units.js +51 -16
- package/dist/types.d.ts +9 -9
- package/dist/types.js +27 -8
- package/dist/ui-language.d.ts +3 -1
- package/dist/ui-language.js +3 -1
- package/dist/web-admin-credential.d.ts +14 -1
- package/dist/web-admin-credential.js +15 -1
- package/docs/API-SURFACE.md +52 -5
- package/docs/CONFORMANCE.md +19 -2
- package/docs/CONSUMER-INTEGRATION.md +140 -11
- package/llms-full.txt +40 -10
- package/llms.txt +16 -7
- package/package.json +1 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web-admin 凭证文件单写者锁的**协议一致性测试**(随包、可被别的实现复用):一份协议、一份判据。
|
|
3
|
+
*
|
|
4
|
+
* 别的实现(壳若不调本包 `./node` 的 `tryWebAdminCredentialFileLock`、自己写一份)把它交给 {@link runWebAdminCredentialLockConformance}:签名必须与本包原语逐字同
|
|
5
|
+
* ({@link WebAdminCredentialLockImplementation}),kit 在私有临时根里逐格跑黑盒场景(只经文件系统观察:锁文件在哪、是谁、留没留残件、凭证文件的内容),答一份报告。
|
|
6
|
+
* 「两份实现各自声明合规」不算数 —— 过这份 kit 才算。
|
|
7
|
+
*
|
|
8
|
+
* 每格造一个新的临时根(与语料 kit 同一只铸点、同一套残留收口),格里的凭证文件在根下的 `c/` 里;格跑完根整个删掉。
|
|
9
|
+
* kit 扮「另一个写者」时只做协议里另一个写者会做的事:按协议建锁;接手 = 协议里的收残留(把锁**改名挪开**、删掉挪开件,再建自己的锁)—— 从不按路径删锁、不等待。
|
|
10
|
+
* 看不到的东西不判:只试一次的「次数」、收残留的交错、身份取自 fd 且 fd 钉到放锁 —— 这些要注入系统调用才能排出来,在本包自己的白盒钉里(黑盒里只量「忙时不等待」的耗时上界)。
|
|
11
|
+
* 「失锁」两格(锁被换成继任者)对一只不钉 fd 的实现是概率性的:继任者的锁恰好复用了持有者那只的 inode 号时,那样的实现会读成「仍是自己的」。
|
|
12
|
+
* 锁名被命名管道 / 悬空软链占着的两种形在本包自己的白盒钉里(命名管道要放进可超时终止的子进程,黑盒格里不造);黑盒里用目录代表「锁名上不是普通文件」那一类,答案是同一个。
|
|
13
|
+
* 悬空软链(链接在、目标不在 —— 经软链到达的凭据文件登出之后的样子)是**失败关闭**:`unreadable`、不建文件、不写。这是本版协议的答案,也是已知限制(登出后再登录写不进去;出路 = 删掉悬空链接或先重建目标),
|
|
14
|
+
* 根修后这一格翻成「写穿」。
|
|
15
|
+
* 已知范围:软链两格(写穿 · 悬空)要求宿主允许建符号链接(Windows 上普通用户默认不允许,那两格会以「建链接失败」红)。
|
|
16
|
+
*/
|
|
17
|
+
import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { basename, dirname, join } from "node:path";
|
|
19
|
+
import { performance } from "node:perf_hooks";
|
|
20
|
+
import { removeLockIf } from "../atomic-write.js";
|
|
21
|
+
import { WEB_ADMIN_CREDENTIAL_FILE_LOCK, webAdminCredentialLockName } from "../web-admin-credential.js";
|
|
22
|
+
import { mintLocalRoot, removeLocalRoot } from "./temp-roots.js";
|
|
23
|
+
const STALE = WEB_ADMIN_CREDENTIAL_FILE_LOCK.staleMs;
|
|
24
|
+
/** 「忙时不等待」的耗时上界(毫秒,单调钟):只为抓「先等一会儿再答」的实现,留足慢盘余量。一只正确的实现在调用期间被宿主调度停住超过它,这一格会红 —— 那是宿主读数,不是协议结论:重跑一次分得开。 */
|
|
25
|
+
const BUSY_ANSWER_BOUND_MS = 1000;
|
|
26
|
+
function check(cond, why) {
|
|
27
|
+
if (!cond)
|
|
28
|
+
throw new Error(why);
|
|
29
|
+
}
|
|
30
|
+
const lockOf = (file) => join(dirname(file), webAdminCredentialLockName(basename(file)));
|
|
31
|
+
const inoOf = (p) => statSync(p, { bigint: true }).ino;
|
|
32
|
+
const entries = (dir) => readdirSync(dir).sort().join(", ");
|
|
33
|
+
/** 按协议建一只别人的锁,mtime 拨到 `ageMs` 之前(负数 = 未来);返回它的 inode。 */
|
|
34
|
+
function plantLock(p, ageMs) {
|
|
35
|
+
closeSync(openSync(p, "wx"));
|
|
36
|
+
const t = (Date.now() - ageMs) / 1000;
|
|
37
|
+
utimesSync(p, t, t);
|
|
38
|
+
return inoOf(p);
|
|
39
|
+
}
|
|
40
|
+
/** 另一个写者接手 `target` 的锁:按协议收残留 —— 走包里收 / 放锁的**那一套动作**(`removeLockIf`:把锁改名挪开、核挪走的是不是此刻在路径上的那一只、删挪开件;从不按路径删锁)—— 再建自己的锁;返回它的 inode。 */
|
|
41
|
+
function takeOver(target) {
|
|
42
|
+
const lock = lockOf(target);
|
|
43
|
+
const held = statSync(lock, { bigint: true });
|
|
44
|
+
removeLockIf(lock, { dev: held.dev, ino: held.ino });
|
|
45
|
+
return plantLock(lock, 0);
|
|
46
|
+
}
|
|
47
|
+
function writeCredential(dir) {
|
|
48
|
+
const cred = join(dir, "credential");
|
|
49
|
+
writeFileSync(cred, "R1");
|
|
50
|
+
return cred;
|
|
51
|
+
}
|
|
52
|
+
function expectBusyUntouched(impl, dir, ageMs) {
|
|
53
|
+
const cred = writeCredential(dir);
|
|
54
|
+
const lock = lockOf(cred);
|
|
55
|
+
const ino = plantLock(lock, ageMs);
|
|
56
|
+
let ran = false;
|
|
57
|
+
const started = performance.now(); // 单调钟:墙钟被拨动不影响这只量
|
|
58
|
+
const r = impl(cred, () => {
|
|
59
|
+
ran = true;
|
|
60
|
+
});
|
|
61
|
+
const elapsed = Math.round(performance.now() - started);
|
|
62
|
+
check(r.status === "busy", `a lock aged ${ageMs} ms answered ${r.status}, expected busy`);
|
|
63
|
+
check(!ran, "the callback ran while another writer held the lock");
|
|
64
|
+
check(existsSync(lock) && inoOf(lock) === ino, "the other writer's lock was moved or replaced");
|
|
65
|
+
check(r.heldForMs === undefined || (r.heldForMs >= 0 && r.heldForMs <= STALE), `heldForMs ${String(r.heldForMs)} is outside 0..staleMs`);
|
|
66
|
+
check(elapsed < BUSY_ANSWER_BOUND_MS, `busy took ${elapsed} ms — the lock is tried once and never waited for`);
|
|
67
|
+
}
|
|
68
|
+
const CASES = [
|
|
69
|
+
[
|
|
70
|
+
"free-acquires",
|
|
71
|
+
(impl, _root, dir) => {
|
|
72
|
+
const cred = writeCredential(dir);
|
|
73
|
+
const r = impl(cred, (held) => ({ current: held.current, lockThere: existsSync(lockOf(held.target)), mine: held.stillMine(), same: realpathSync(held.target) === realpathSync(cred) }));
|
|
74
|
+
check(r.status === "acquired", `answered ${r.status}, expected acquired`);
|
|
75
|
+
check(r.value.current === "R1", "the callback did not get the credential text read under the lock");
|
|
76
|
+
check(r.value.lockThere, "no lock file named .<file>.lock beside the target while held");
|
|
77
|
+
check(r.value.mine, "stillMine() was false for an undisturbed holder");
|
|
78
|
+
check(r.value.same, "held.target is not the credential file");
|
|
79
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
["fresh-lock-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, 0)],
|
|
83
|
+
["future-mtime-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, -60_000)],
|
|
84
|
+
["young-lock-is-busy", (impl, _root, dir) => expectBusyUntouched(impl, dir, STALE / 2)],
|
|
85
|
+
[
|
|
86
|
+
"stale-lock-is-reclaimed",
|
|
87
|
+
(impl, _root, dir) => {
|
|
88
|
+
const cred = writeCredential(dir);
|
|
89
|
+
const lock = lockOf(cred);
|
|
90
|
+
const old = plantLock(lock, STALE + 5000);
|
|
91
|
+
const keepOld = openSync(lock, "r"); // 钉住残留那个文件对象:它被删后 inode 号不会被新锁复用,「不是同一只」的比对才成立
|
|
92
|
+
try {
|
|
93
|
+
const r = impl(cred, () => (existsSync(lock) ? inoOf(lock) : undefined));
|
|
94
|
+
check(r.status === "acquired", `a lock older than staleMs answered ${r.status}, expected acquired`);
|
|
95
|
+
check(r.value !== undefined && r.value !== old, "the holder did not hold a lock of its own");
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
closeSync(keepOld);
|
|
99
|
+
}
|
|
100
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"lost-when-replaced",
|
|
105
|
+
(impl, _root, dir) => {
|
|
106
|
+
const cred = writeCredential(dir);
|
|
107
|
+
const lock = lockOf(cred);
|
|
108
|
+
const tmp = join(dir, "kit-next.tmp");
|
|
109
|
+
const r = impl(cred, (held) => {
|
|
110
|
+
const successor = takeOver(held.target); // another writer took the lock over (the protocol's reclaim) and holds a lock of its own
|
|
111
|
+
const mine = held.stillMine();
|
|
112
|
+
writeFileSync(tmp, "R2");
|
|
113
|
+
return { successor, mine, wrote: held.replaceWith(tmp) };
|
|
114
|
+
});
|
|
115
|
+
check(r.status === "lost", `answered ${r.status}, expected lost`);
|
|
116
|
+
check(!r.value.mine, "stillMine() was true after the lock was replaced");
|
|
117
|
+
check(!r.value.wrote, "replaceWith() wrote after the lock was replaced");
|
|
118
|
+
check(readFileSync(cred, "utf8") === "R1", "the credential changed without the lock");
|
|
119
|
+
check(existsSync(tmp), "the caller's temporary file was consumed");
|
|
120
|
+
check(existsSync(lock) && inoOf(lock) === r.value.successor, "the successor's lock was removed or replaced on release");
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
"replace-after-loss-unchecked",
|
|
125
|
+
(impl, _root, dir) => {
|
|
126
|
+
const cred = writeCredential(dir);
|
|
127
|
+
const tmp = join(dir, "kit-next.tmp");
|
|
128
|
+
const r = impl(cred, (held) => {
|
|
129
|
+
takeOver(held.target); // another writer holds the lock now; the callback does not ask stillMine() first
|
|
130
|
+
writeFileSync(tmp, "R2");
|
|
131
|
+
return held.replaceWith(tmp);
|
|
132
|
+
});
|
|
133
|
+
check(r.status === "lost", `answered ${r.status}, expected lost`);
|
|
134
|
+
check(!r.value, "replaceWith() wrote without checking the lock itself");
|
|
135
|
+
check(readFileSync(cred, "utf8") === "R1", "the credential changed without the lock");
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
"remove-after-loss-unchecked",
|
|
140
|
+
(impl, _root, dir) => {
|
|
141
|
+
const cred = writeCredential(dir);
|
|
142
|
+
const r = impl(cred, (held) => {
|
|
143
|
+
takeOver(held.target); // another writer holds the lock now; the callback does not ask stillMine() first
|
|
144
|
+
return held.remove();
|
|
145
|
+
});
|
|
146
|
+
check(r.status === "lost", `answered ${r.status}, expected lost`);
|
|
147
|
+
check(!r.value, "remove() deleted without checking the lock itself");
|
|
148
|
+
check(existsSync(cred), "the credential was removed without the lock");
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
"replace-writes-through-link",
|
|
153
|
+
(impl, root, dir) => {
|
|
154
|
+
const d = join(root, "d");
|
|
155
|
+
mkdirSync(d);
|
|
156
|
+
const realFile = join(d, "real");
|
|
157
|
+
writeFileSync(realFile, "R1");
|
|
158
|
+
const link = join(dir, "credential");
|
|
159
|
+
symlinkSync(realFile, link);
|
|
160
|
+
const r = impl(link, (held) => {
|
|
161
|
+
const seen = {
|
|
162
|
+
besideTarget: existsSync(join(d, webAdminCredentialLockName("real"))),
|
|
163
|
+
besideLink: existsSync(join(dir, webAdminCredentialLockName("credential"))),
|
|
164
|
+
targetIsLink: lstatSync(held.target).isSymbolicLink(),
|
|
165
|
+
same: realpathSync(held.target) === realpathSync(realFile),
|
|
166
|
+
};
|
|
167
|
+
const tmp = join(dirname(held.target), "kit-next.tmp");
|
|
168
|
+
writeFileSync(tmp, "R2");
|
|
169
|
+
return { ...seen, wrote: held.replaceWith(tmp) };
|
|
170
|
+
});
|
|
171
|
+
check(r.status === "acquired", `answered ${r.status}, expected acquired`);
|
|
172
|
+
check(r.value.wrote, "replaceWith() did not land for an undisturbed holder");
|
|
173
|
+
check(r.value.besideTarget, "no lock beside the link's real target");
|
|
174
|
+
check(!r.value.besideLink, "a lock beside the link itself");
|
|
175
|
+
check(!r.value.targetIsLink && r.value.same, "held.target is not the link's real target");
|
|
176
|
+
check(lstatSync(link).isSymbolicLink(), "the link was replaced by a regular file");
|
|
177
|
+
check(readFileSync(realFile, "utf8") === "R2", "the real target was not written");
|
|
178
|
+
check(entries(dir) === "credential" && entries(d) === "real", `left behind: ${entries(dir)} | ${entries(d)}`);
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
"dangling-link-is-unreadable",
|
|
183
|
+
(impl, root, dir) => {
|
|
184
|
+
const link = join(dir, "credential");
|
|
185
|
+
symlinkSync(join(root, "gone"), link); // the link's target does not exist (what a logout through a link leaves behind): fail closed — nothing is created, nothing is written through it
|
|
186
|
+
let ran = false;
|
|
187
|
+
const r = impl(link, () => {
|
|
188
|
+
ran = true;
|
|
189
|
+
});
|
|
190
|
+
check(r.status === "unreadable", `a dangling link answered ${r.status}, expected unreadable`);
|
|
191
|
+
check(!ran, "the callback ran through a dangling link");
|
|
192
|
+
check(entries(dir) === "credential" && !existsSync(join(root, "gone")), `left behind: ${entries(dir)} | ${existsSync(join(root, "gone")) ? "a file at the link's target" : "nothing at the link's target"}`);
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
"remove-under-lock",
|
|
197
|
+
(impl, _root, dir) => {
|
|
198
|
+
const cred = writeCredential(dir);
|
|
199
|
+
const r = impl(cred, (held) => held.remove());
|
|
200
|
+
check(r.status === "acquired" && r.value, `answered ${r.status}, expected acquired with the removal landed`);
|
|
201
|
+
check(entries(dir) === "", `left behind: ${entries(dir)}`);
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
"absent-target-reads-undefined",
|
|
206
|
+
(impl, _root, dir) => {
|
|
207
|
+
const r = impl(join(dir, "credential"), (held) => held.current === undefined);
|
|
208
|
+
check(r.status === "acquired" && r.value, `answered ${r.status}; an absent target is read as undefined under the lock`);
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
"critical-throws-releases",
|
|
213
|
+
(impl, _root, dir) => {
|
|
214
|
+
const cred = writeCredential(dir);
|
|
215
|
+
const sentinel = new Error("kit sentinel");
|
|
216
|
+
let caught;
|
|
217
|
+
try {
|
|
218
|
+
impl(cred, () => {
|
|
219
|
+
throw sentinel;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
caught = e;
|
|
224
|
+
}
|
|
225
|
+
check(caught === sentinel, "the callback's error was not rethrown as it was");
|
|
226
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
"thenable-is-refused",
|
|
231
|
+
(impl, _root, dir) => {
|
|
232
|
+
const cred = writeCredential(dir);
|
|
233
|
+
const sneaky = () => Promise.resolve();
|
|
234
|
+
let caught;
|
|
235
|
+
try {
|
|
236
|
+
impl(cred, sneaky);
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
caught = e;
|
|
240
|
+
}
|
|
241
|
+
check(caught instanceof TypeError, "a callback that returned a promise was not refused with a TypeError");
|
|
242
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
[
|
|
246
|
+
"handle-expires-on-return",
|
|
247
|
+
(impl, _root, dir) => {
|
|
248
|
+
const cred = writeCredential(dir);
|
|
249
|
+
const r = impl(cred, (held) => held);
|
|
250
|
+
check(r.status === "acquired", `answered ${r.status}, expected acquired`);
|
|
251
|
+
const kept = r.value;
|
|
252
|
+
const tmp = join(dir, "kit-late.tmp");
|
|
253
|
+
writeFileSync(tmp, "R2");
|
|
254
|
+
const answers = ["stillMine", "replaceWith", "remove"].filter((method) => {
|
|
255
|
+
try {
|
|
256
|
+
if (method === "stillMine")
|
|
257
|
+
kept.stillMine();
|
|
258
|
+
else if (method === "replaceWith")
|
|
259
|
+
kept.replaceWith(tmp);
|
|
260
|
+
else
|
|
261
|
+
kept.remove();
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
check(answers.length === 0, `the handle still answered after the callback returned: ${answers.join(", ")}`);
|
|
269
|
+
check(readFileSync(cred, "utf8") === "R1", "a late call on the handle changed the credential");
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
"unreadable-target",
|
|
274
|
+
(impl, _root, dir) => {
|
|
275
|
+
mkdirSync(join(dir, "credential"));
|
|
276
|
+
let ran = false;
|
|
277
|
+
const r = impl(join(dir, "credential"), () => {
|
|
278
|
+
ran = true;
|
|
279
|
+
});
|
|
280
|
+
check(r.status === "unreadable", `a target that cannot be read answered ${r.status}, expected unreadable`);
|
|
281
|
+
check(!ran, "the callback ran without a readable target");
|
|
282
|
+
check(entries(dir) === "credential", `left behind: ${entries(dir)}`);
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
"non-file-lock-name-is-unreadable",
|
|
287
|
+
(impl, _root, dir) => {
|
|
288
|
+
const cred = writeCredential(dir);
|
|
289
|
+
const lock = lockOf(cred);
|
|
290
|
+
mkdirSync(lock); // something that is not a regular file holds the lock's name (a directory here — a named pipe or a link is the same answer, pinned beside the package's own implementation)
|
|
291
|
+
let ran = false;
|
|
292
|
+
const started = performance.now();
|
|
293
|
+
const r = impl(cred, () => {
|
|
294
|
+
ran = true;
|
|
295
|
+
});
|
|
296
|
+
const elapsed = Math.round(performance.now() - started);
|
|
297
|
+
check(r.status === "unreadable", `a lock name held by a directory answered ${r.status}, expected unreadable (it cannot be a lock: not busy, not stale, not waited for)`);
|
|
298
|
+
check(!ran, "the callback ran although the lock name is not a lock");
|
|
299
|
+
check(lstatSync(lock).isDirectory(), "the entry on the lock's name was moved or removed");
|
|
300
|
+
check(elapsed < BUSY_ANSWER_BOUND_MS, `the answer took ${elapsed} ms — never waited for`);
|
|
301
|
+
check(entries(dir) === ".credential.lock, credential", `left behind: ${entries(dir)}`);
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
[
|
|
305
|
+
"unreadable-lock-directory",
|
|
306
|
+
(impl, _root, dir) => {
|
|
307
|
+
let ran = false;
|
|
308
|
+
const r = impl(join(dir, "missing", "credential"), () => {
|
|
309
|
+
ran = true;
|
|
310
|
+
});
|
|
311
|
+
check(r.status === "unreadable", `a lock that cannot be created answered ${r.status}, expected unreadable`);
|
|
312
|
+
check(!ran, "the callback ran without the lock");
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
];
|
|
316
|
+
const describeThrown = (e) => {
|
|
317
|
+
try {
|
|
318
|
+
return e instanceof Error ? e.message : String(e);
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
return "the case threw a value that cannot be described";
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* 跑整份协议一致性测试:`implementation` 是被测实现(本包自己的原语过它;壳自己写的实现也必须过它)。逐格造临时根、跑、删根;一格抛 ⇒ 那一格红,`why` 说哪一条没做到,别的格照跑。
|
|
326
|
+
* 返回 {@link WebAdminCredentialLockConformanceReport};断言 `report.ok`,红了读 `cases` 里 `ok: false` 的那几格。
|
|
327
|
+
*/
|
|
328
|
+
export async function runWebAdminCredentialLockConformance(implementation) {
|
|
329
|
+
const cases = [];
|
|
330
|
+
for (const [id, run] of CASES) {
|
|
331
|
+
const root = await mintLocalRoot();
|
|
332
|
+
try {
|
|
333
|
+
const dir = join(root, "c");
|
|
334
|
+
mkdirSync(dir);
|
|
335
|
+
run(implementation, root, dir);
|
|
336
|
+
cases.push({ id, ok: true });
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
cases.push({ id, ok: false, why: describeThrown(e) });
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
await removeLocalRoot(root);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return { ok: cases.every((c) => c.ok), cases };
|
|
346
|
+
}
|
package/dist/cross-session.d.ts
CHANGED
|
@@ -64,8 +64,8 @@ export type DialogExpiryValue = (typeof DIALOG_EXPIRY_VALUES)[number];
|
|
|
64
64
|
export declare const DIALOG_EXPIRY_DEFAULT: DialogExpiryValue;
|
|
65
65
|
/** 文件层受理面:四个值 + `"default"`(未设 ⇒ 落 {@link DIALOG_EXPIRY_DEFAULT})。 */
|
|
66
66
|
export declare const DialogExpirySetting: z.ZodEnum<{
|
|
67
|
-
default: "default";
|
|
68
67
|
never: "never";
|
|
68
|
+
default: "default";
|
|
69
69
|
"60s": "60s";
|
|
70
70
|
"5m": "5m";
|
|
71
71
|
"10m": "10m";
|
|
@@ -85,8 +85,8 @@ export declare const CrossSessionSettings: z.ZodObject<{
|
|
|
85
85
|
hold: "hold";
|
|
86
86
|
}>>;
|
|
87
87
|
dialogExpiry: z.ZodOptional<z.ZodEnum<{
|
|
88
|
-
default: "default";
|
|
89
88
|
never: "never";
|
|
89
|
+
default: "default";
|
|
90
90
|
"60s": "60s";
|
|
91
91
|
"5m": "5m";
|
|
92
92
|
"10m": "10m";
|
package/dist/declared-capture.js
CHANGED
|
@@ -54,7 +54,7 @@ const shapeOf = (object) => object._zod.def.shape;
|
|
|
54
54
|
const isPlainUnion = (schema) => schema instanceof z.ZodUnion && !(schema instanceof z.ZodDiscriminatedUnion);
|
|
55
55
|
/** 寻常对象从 `Object.prototype` 继承来的成员名(ES 规定的闭集)。声明键叫这些名字时,zod 在调用方的值上 `[[Get]]` 读到继承来的成员,投影把它读成缺席 —— 两边不同答。 */
|
|
56
56
|
const ORDINARY_OBJECT_MEMBERS = new Set(["constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "toString", "valueOf", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
57
|
-
/** 走过白名单门的 schema(按根;fleet
|
|
57
|
+
/** 走过白名单门的 schema(按根;fleet 每次请求都是那几只固定的 schema,不重走)。 */
|
|
58
58
|
const ADMITTED = new WeakSet();
|
|
59
59
|
/** 白名单门(见文件头):整棵 schema 树只含放行的形 ⇒ 记下、交回 `undefined`;否则交回不支持的那一句(见 {@link Refusal})。与 `evaluate` / `snapshotOf` 同一套判据(`isPlainUnion` / `innerOf`)。 */
|
|
60
60
|
function admit(schema) {
|
package/dist/fleet.d.ts
CHANGED
|
@@ -110,9 +110,9 @@ export declare function compareGeneration(a: string, b: string): -1 | 0 | 1;
|
|
|
110
110
|
*/
|
|
111
111
|
export declare const LEASE_STATES: readonly ["none", "granted", "expired", "denied"];
|
|
112
112
|
export declare const LeaseState: z.ZodEnum<{
|
|
113
|
+
expired: "expired";
|
|
113
114
|
none: "none";
|
|
114
115
|
granted: "granted";
|
|
115
|
-
expired: "expired";
|
|
116
116
|
denied: "denied";
|
|
117
117
|
}>;
|
|
118
118
|
export type LeaseState = z.infer<typeof LeaseState>;
|
|
@@ -283,7 +283,9 @@ export declare function readModelRefusals(body: unknown): ModelRefusalsSignal |
|
|
|
283
283
|
/**
|
|
284
284
|
* The engine's draining fact — ONE object wherever the engine says "I am draining": inside {@link EngineSignal}`.draining`
|
|
285
285
|
* and as the body of a {@link DrainReceipt}.
|
|
286
|
-
* - `actionId` — the action that put the engine into draining
|
|
286
|
+
* - `actionId` — the action that put the engine into draining: for a request of the identity form ({@link DrainRequest}) its `actionId`, the
|
|
287
|
+
* idempotency key; a request of the credential-named form ({@link CredentialDrainRequest}) carries none, and how the engine mints this one
|
|
288
|
+
* for it is the engine's to define (this package does not).
|
|
287
289
|
* - `since` — epoch ms when draining began; it does not move when the same action repeats.
|
|
288
290
|
* - `deadlineAt` — epoch ms by which the engine stops on its own.
|
|
289
291
|
*/
|
|
@@ -341,9 +343,9 @@ export declare const EngineSignal: z.ZodObject<{
|
|
|
341
343
|
}, z.core.$strip>>;
|
|
342
344
|
generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
343
345
|
leaseState: z.ZodOptional<z.ZodEnum<{
|
|
346
|
+
expired: "expired";
|
|
344
347
|
none: "none";
|
|
345
348
|
granted: "granted";
|
|
346
|
-
expired: "expired";
|
|
347
349
|
denied: "denied";
|
|
348
350
|
}>>;
|
|
349
351
|
leaseUntil: z.ZodOptional<z.ZodNumber>;
|
|
@@ -384,9 +386,9 @@ export declare const InstanceHealth: z.ZodObject<{
|
|
|
384
386
|
}, z.core.$strip>>;
|
|
385
387
|
generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
386
388
|
leaseState: z.ZodOptional<z.ZodEnum<{
|
|
389
|
+
expired: "expired";
|
|
387
390
|
none: "none";
|
|
388
391
|
granted: "granted";
|
|
389
|
-
expired: "expired";
|
|
390
392
|
denied: "denied";
|
|
391
393
|
}>>;
|
|
392
394
|
leaseUntil: z.ZodOptional<z.ZodNumber>;
|
|
@@ -456,9 +458,9 @@ export declare const InstanceAnnouncement: z.ZodObject<{
|
|
|
456
458
|
}, z.core.$strip>>;
|
|
457
459
|
generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
458
460
|
leaseState: z.ZodOptional<z.ZodEnum<{
|
|
461
|
+
expired: "expired";
|
|
459
462
|
none: "none";
|
|
460
463
|
granted: "granted";
|
|
461
|
-
expired: "expired";
|
|
462
464
|
denied: "denied";
|
|
463
465
|
}>>;
|
|
464
466
|
leaseUntil: z.ZodOptional<z.ZodNumber>;
|
|
@@ -505,9 +507,9 @@ export declare const InstanceRegistration: z.ZodObject<{
|
|
|
505
507
|
}, z.core.$strip>>;
|
|
506
508
|
generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
507
509
|
leaseState: z.ZodOptional<z.ZodEnum<{
|
|
510
|
+
expired: "expired";
|
|
508
511
|
none: "none";
|
|
509
512
|
granted: "granted";
|
|
510
|
-
expired: "expired";
|
|
511
513
|
denied: "denied";
|
|
512
514
|
}>>;
|
|
513
515
|
leaseUntil: z.ZodOptional<z.ZodNumber>;
|
|
@@ -776,7 +778,8 @@ export declare const DrainRequest: z.ZodObject<{
|
|
|
776
778
|
}, z.core.$strip>;
|
|
777
779
|
export type DrainRequest = z.infer<typeof DrainRequest>;
|
|
778
780
|
/** What a drain request leaves the engine in: `draining` — this call put it into draining; `already_draining` — it already was
|
|
779
|
-
* (the same action repeated), and the receipt reports the first call's facts.
|
|
781
|
+
* (for the identity form: the same action repeated), and the receipt reports the first call's facts. For the credential-named form see
|
|
782
|
+
* {@link CredentialDrainRequest}. */
|
|
780
783
|
export declare const DRAIN_RECEIPT_STATES: readonly ["draining", "already_draining"];
|
|
781
784
|
export declare const DrainReceiptState: z.ZodEnum<{
|
|
782
785
|
draining: "draining";
|
|
@@ -799,6 +802,121 @@ export type DrainReceipt = z.infer<typeof DrainReceipt>;
|
|
|
799
802
|
export declare function readDrainRequest(body: unknown): DrainRequest | undefined;
|
|
800
803
|
/** Caller side: the drain endpoint's answer. Shape mismatch / non-object / throwing accessor ⇒ `undefined`, never throws. */
|
|
801
804
|
export declare function readDrainReceipt(body: unknown): DrainReceipt | undefined;
|
|
805
|
+
/**
|
|
806
|
+
* The two words of {@link CredentialDrainRequest}`.turns` — a CLOSED set, owned here (a reader that switches on it exhaustively is told
|
|
807
|
+
* by the compiler when a word is added): how the turns that are running at the moment the engine accepts the drain give way. This package
|
|
808
|
+
* fixes the words; what each word does is engine-side behaviour, described here and not verified by this package.
|
|
809
|
+
* - `yield` — the way a drain always stops them: a running turn parks at its next clean turn boundary, and what has not finished when the
|
|
810
|
+
* deadline passes is cut by the hard stop. An absent `turns` means `yield`.
|
|
811
|
+
* - `halt` — everything `yield` does, and in the same step the engine asks every running turn that has a turn surface to stop now — the
|
|
812
|
+
* cut a user's Esc makes in that window. The deadline does not move; a turn that does not take the cut in time is handled as under
|
|
813
|
+
* `yield`. The engine honours it only for a caller that holds the operator authority to halt any run; otherwise it refuses and changes nothing.
|
|
814
|
+
*/
|
|
815
|
+
export declare const DRAIN_TURNS: readonly ["yield", "halt"];
|
|
816
|
+
export declare const DrainTurns: z.ZodEnum<{
|
|
817
|
+
yield: "yield";
|
|
818
|
+
halt: "halt";
|
|
819
|
+
}>;
|
|
820
|
+
export type DrainTurns = z.infer<typeof DrainTurns>;
|
|
821
|
+
/**
|
|
822
|
+
* The drain endpoint's request in its CREDENTIAL-NAMED form: the sender (the side that sends the request) names the engine by the credential it
|
|
823
|
+
* presents (the one a launcher minted for this process), not by the identity quadruple of {@link DrainRequest} — so the body carries no action
|
|
824
|
+
* id, no worker, no deadline, only what is to be said about THIS call. A STRICT object: one key more, one word off, a negative / fractional /
|
|
825
|
+
* string / oversize count ⇒ the body is not this form (and a half-built {@link DrainRequest} is never read as a stop request). Every key is
|
|
826
|
+
* optional and the empty body `{}` is the whole default form. A reader never mints a key the sender did not write, and this package exports
|
|
827
|
+
* no default constant: the RECEIVING side applies the meaning of an absent key — an absent `turns` is `yield`, an absent `attachedAtMost`
|
|
828
|
+
* sets no condition.
|
|
829
|
+
* - `instanceId` — a non-empty string: the engine's own per-process identity ({@link InstanceHealth}`.instanceId`). When present the engine
|
|
830
|
+
* compares it with its own and refuses on a mismatch. The very schema of {@link DrainRequest}`.instanceId`, not a copy.
|
|
831
|
+
* - `turns` — how the turns running at acceptance give way ({@link DRAIN_TURNS}).
|
|
832
|
+
* - `attachedAtMost` — a non-negative safe integer: accept the drain only if at most this many streams are attached to the engine at the
|
|
833
|
+
* moment it judges the request; more ⇒ a refusal carrying {@link DrainConditionUnmet}, nothing changed. It bounds what was attached at that moment;
|
|
834
|
+
* it is not a promise about the streams and requests that arrive afterwards.
|
|
835
|
+
* The two forms of the endpoint's request share no body that is plain data (what JSON parsing yields): {@link DrainRequest} requires
|
|
836
|
+
* `actionId`, `worker` and `deadlineAt`, which this form refuses as unknown keys. `turns` and `attachedAtMost` belong to this form only —
|
|
837
|
+
* {@link DrainRequest} does not carry them; its single-form reader strips them like any unknown key, and the reader of the endpoint's body
|
|
838
|
+
* ({@link readDrainRequestReading}) reads an identity body that carries either of them as neither form. The answer is the same
|
|
839
|
+
* {@link DrainReceipt} shape for both forms. What the engine puts in it for this form — engine-side behaviour, which this package does not
|
|
840
|
+
* verify: `deadlineAt` is the engine's own drain window (the body names no deadline); a `halt` sent while the engine is already draining is
|
|
841
|
+
* answered `already_draining` with the first call's facts and cuts the turns running at that moment; while the hard stop is under way the
|
|
842
|
+
* receipt's `actionId` is `hard-stop` and neither `turns` nor `attachedAtMost` is read; the naming is judged before the condition (a naming
|
|
843
|
+
* mismatch is refused without the attached count), and the condition is judged even when the engine is already draining. How the engine
|
|
844
|
+
* mints the receipt's `actionId` for this form, and what it answers for other requests of this form sent while it is draining, is the
|
|
845
|
+
* engine's to define; this package does not.
|
|
846
|
+
*/
|
|
847
|
+
export declare const CredentialDrainRequest: z.ZodObject<{
|
|
848
|
+
instanceId: z.ZodOptional<z.ZodString>;
|
|
849
|
+
turns: z.ZodOptional<z.ZodEnum<{
|
|
850
|
+
yield: "yield";
|
|
851
|
+
halt: "halt";
|
|
852
|
+
}>>;
|
|
853
|
+
attachedAtMost: z.ZodOptional<z.ZodNumber>;
|
|
854
|
+
}, z.core.$strict>;
|
|
855
|
+
export type CredentialDrainRequest = z.infer<typeof CredentialDrainRequest>;
|
|
856
|
+
/**
|
|
857
|
+
* Engine side: the request body of the drain endpoint in its credential-named form. Shape mismatch / non-object / throwing accessor ⇒
|
|
858
|
+
* `undefined`, never throws. A body of the identity form ({@link DrainRequest}) reads `undefined` here and a body of this form reads
|
|
859
|
+
* `undefined` for {@link readDrainRequest}: no plain-data body is read by both (an object that shows two different key sets to the two
|
|
860
|
+
* readers — a Proxy whose `ownKeys` trap lies — is outside that promise; a body parsed from JSON never is one). A request with no bytes is
|
|
861
|
+
* the engine's to turn into `{}` before it calls this reader (`undefined` and `null` are not objects here).
|
|
862
|
+
* The result is an ordinary object, like every reader's in this file: the reader looks only at the body's own keys, but an optional key it
|
|
863
|
+
* did not read is absent only as an own key — test for it with `Object.hasOwn`, do not read it through the prototype chain.
|
|
864
|
+
*/
|
|
865
|
+
export declare function readCredentialDrainRequest(body: unknown): CredentialDrainRequest | undefined;
|
|
866
|
+
/**
|
|
867
|
+
* What {@link readDrainRequestReading} makes of a drain request body: which of the endpoint's two forms it is, and the request read in
|
|
868
|
+
* that form — the identity quadruple ({@link DrainRequest}) or the credential-named form ({@link CredentialDrainRequest}). Branch on
|
|
869
|
+
* `form`; each arm's `request` has that form's type.
|
|
870
|
+
*/
|
|
871
|
+
export type DrainRequestReading = {
|
|
872
|
+
form: "identity";
|
|
873
|
+
request: DrainRequest;
|
|
874
|
+
} | {
|
|
875
|
+
form: "credential";
|
|
876
|
+
request: CredentialDrainRequest;
|
|
877
|
+
};
|
|
878
|
+
/** The form words of {@link DrainRequestReading}, in the order the reader tries them. `satisfies` bites a word the union does not have;
|
|
879
|
+
* the converse (a union arm missing from this list) is pinned by a test that compares the two. */
|
|
880
|
+
export declare const DRAIN_REQUEST_FORMS: readonly ["identity", "credential"];
|
|
881
|
+
/**
|
|
882
|
+
* Engine side: THE reader of the drain endpoint's request body — which form it is and the request in that form; neither ⇒ `undefined`.
|
|
883
|
+
* A body is one form or the other: a body that mixes the keys of the two forms is NEITHER — a body the identity reader reads that also
|
|
884
|
+
* carries, as its own key, a key only the credential-named form has (`turns`, `attachedAtMost`: that form's keys minus the shared
|
|
885
|
+
* `instanceId`) reads `undefined` here, whatever that key's value, so a condition or a turn policy sent on the identity form is refused
|
|
886
|
+
* instead of being stripped. It composes the two single-form readers and that one key check (no second schema): {@link readDrainRequest}
|
|
887
|
+
* first, then {@link readCredentialDrainRequest}; the `request` handed back is that reader's answer in this call. When this reader reads a
|
|
888
|
+
* body, its `request` equals the answer of that form's single-form reader; the converse does not hold: a mixed body that is plain data reads
|
|
889
|
+
* `undefined` here while {@link readDrainRequest} reads it (stripping the keys). For plain data the order changes nothing (no such body is
|
|
890
|
+
* read by both single-form readers). An object that shows the two single-form readers different key sets reads as the identity form only
|
|
891
|
+
* when the key check, which asks for each credential-only key's own descriptor, finds none of them; when it finds one the object is a mixed
|
|
892
|
+
* body and reads `undefined`. A proxy that changes itself while it is read may answer differently than when the credential reader is asked
|
|
893
|
+
* alone (the identity probe came first). Never throws. The single-form readers stay for a side that
|
|
894
|
+
* already knows which form it sent; {@link readDrainRequest} still strips the credential-named form's keys as it strips any unknown key.
|
|
895
|
+
*/
|
|
896
|
+
export declare function readDrainRequestReading(body: unknown): DrainRequestReading | undefined;
|
|
897
|
+
/** The machine code of the drain endpoint's refusal "the condition the request set is not met": the HTTP 409 whose body carries {@link DrainConditionUnmet}.
|
|
898
|
+
* One spelling — the engine mints the refusal with it, a caller branches on it. */
|
|
899
|
+
export declare const DRAIN_CONDITION_UNMET_CODE = "conflict.drain_condition_unmet";
|
|
900
|
+
/**
|
|
901
|
+
* The facts a {@link DRAIN_CONDITION_UNMET_CODE} refusal carries at the root of its body, beside the refusal's own `error` sentence and `errorCode`:
|
|
902
|
+
* - `attached` — how many streams were attached when the engine judged the request;
|
|
903
|
+
* - `attachedAtMost` — the bound the request set, echoed.
|
|
904
|
+
* A refused call changed nothing, and the engine answers this only when `attached` is above `attachedAtMost` (engine-side behaviour, not
|
|
905
|
+
* verified by this package); the reader judges the form of the
|
|
906
|
+
* two numbers (non-negative safe integers), not their relation. The refusal's own keys are stripped, so the reader takes the whole body.
|
|
907
|
+
*/
|
|
908
|
+
export declare const DrainConditionUnmet: z.ZodObject<{
|
|
909
|
+
attached: z.ZodNumber;
|
|
910
|
+
attachedAtMost: z.ZodNumber;
|
|
911
|
+
}, z.core.$strip>;
|
|
912
|
+
export type DrainConditionUnmet = z.infer<typeof DrainConditionUnmet>;
|
|
913
|
+
/**
|
|
914
|
+
* Caller side: the facts of a {@link DRAIN_CONDITION_UNMET_CODE} refusal. Compare the refusal's `errorCode` with {@link DRAIN_CONDITION_UNMET_CODE}
|
|
915
|
+
* first and read the two numbers with this only when they are equal: this reader does not judge the code, so any body that carries the two
|
|
916
|
+
* facts reads, whatever refusal it is. A body that does not carry both facts (another refusal of the same status, a receipt, a request) reads `undefined`.
|
|
917
|
+
* Shape mismatch / non-object / throwing accessor ⇒ `undefined`, never throws.
|
|
918
|
+
*/
|
|
919
|
+
export declare function readDrainConditionUnmet(body: unknown): DrainConditionUnmet | undefined;
|
|
802
920
|
export declare const DISPATCH_STRATEGIES: readonly ["round-robin", "least-inflight", "consistent-hash"];
|
|
803
921
|
export type DispatchStrategy = (typeof DISPATCH_STRATEGIES)[number];
|
|
804
922
|
/** Per-worker dispatch policy (web-admin-configured; the gateway is OPTIONAL — D3: TOC/self-maintained TOB go
|