@sema-agent/settings-schema 34.1.0 → 35.1.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 +482 -0
- package/README.md +73 -32
- package/conformance/VERSION +1 -1
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/expected.json +101 -0
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/input.json +28 -0
- package/conformance/cases/c100-a2a-inside-stale-fingerprint-dropped/meta.json +6 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/expected.json +113 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/input.json +38 -0
- package/conformance/cases/c101-a2a-inside-incomplete-dropped/meta.json +6 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/expected.json +85 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/input.json +34 -0
- package/conformance/cases/c102-a2a-inside-incomplete-zero-survivors/meta.json +6 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/expected.json +106 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/input.json +28 -0
- package/conformance/cases/c103-mcp-caller-meta-declared/meta.json +6 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/expected.json +163 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/input.json +42 -0
- package/conformance/cases/c98-a2a-registration-keys-carried/meta.json +6 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/expected.json +100 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/input.json +23 -0
- package/conformance/cases/c99-a2a-preapproval-on-outside-peer-dropped/meta.json +6 -0
- package/conformance/profile/annotations.md +65 -0
- package/conformance/profile/loading-rules.md +193 -0
- package/conformance/profile/profiles/solo-auto.json +22 -0
- package/conformance/profile/profiles/solo-managed.json +21 -0
- package/conformance/profile/profiles/tenant-auto.json +36 -0
- package/conformance/profile/profiles/tenant-managed.json +36 -0
- package/conformance/profile/sema-profile.schema.json +201 -0
- package/conformance/profile/tools/mutations.md +62 -0
- package/conformance/profile/tools/validate.mjs +1190 -0
- package/conformance/profile/vectors/frozen-promises.json +120 -0
- package/conformance/profile/vectors/vectors.json +362 -0
- package/dist/a2a-peer-identity.d.ts +116 -0
- package/dist/a2a-peer-identity.js +182 -0
- package/dist/atomic-write.js +1 -1
- package/dist/catalog-manages.js +2 -2
- package/dist/config-dir-migration.js +0 -1
- package/dist/config-document-refusal.d.ts +1 -1
- package/dist/config-fns.d.ts +21 -8
- package/dist/config-fns.js +16 -3
- package/dist/config-root-documents.d.ts +3 -54
- package/dist/config-root-documents.js +24 -21
- package/dist/config-root-node.d.ts +2 -96
- package/dist/config-root-node.js +15 -163
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +1 -0
- package/dist/conformance/profile.d.ts +55 -0
- package/dist/conformance/profile.js +108 -0
- package/dist/conformance/warnings.js +1 -1
- package/dist/env-model-table.d.ts +3 -3
- package/dist/env-model-table.js +5 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/migration-receipt.d.ts +9 -11
- package/dist/migration-receipt.js +4 -5
- package/dist/node.d.ts +3 -3
- package/dist/node.js +3 -3
- package/dist/one-time-migrations.d.ts +3 -4
- package/dist/one-time-migrations.js +3 -28
- package/dist/retired-envs.js +5 -0
- package/dist/safety-merge-spec.d.ts +21 -0
- package/dist/safety-merge-spec.js +13 -0
- package/dist/scheduler-store-node.d.ts +14 -11
- package/dist/scheduler-store-node.js +22 -34
- package/dist/scheduler-store.d.ts +21 -6
- package/dist/scheduler-store.js +100 -19
- package/dist/settings-units.d.ts +9 -0
- package/dist/settings-units.js +12 -7
- package/dist/types.d.ts +44 -2
- package/dist/types.js +70 -2
- package/docs/API-SURFACE.md +38 -12
- package/docs/CC-DIVERGENCE.md +2 -1
- package/docs/CONFORMANCE.md +20 -3
- package/docs/CONSUMER-INTEGRATION.md +110 -13
- package/llms-full.txt +36 -13
- package/llms.txt +15 -5
- package/package.json +3 -3
|
@@ -1,22 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置根上的**根级文档**(纯、零 I/O、浏览器安全;读写函数在 `./node`,见 `./config-root-node`)。
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* <根>/
|
|
6
|
+
* config.d/… 域文档(本地读取域的文件;文件仓库只扫这一个目录)
|
|
7
|
+
* config.env-models.json env 模型表被目录顶替的部署决定 {"envModels":"replaced"|"kept"}
|
|
8
|
+
* .env 秘密值(不归本包读)
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* ## 律
|
|
12
|
+
* · **根归客户端(TOC)所有**,引擎在根上只写这一份文档;它在 `config.d/` 之外 —— 已核的各版文件仓库都只扫 `<根>/config.d`(抽样,不证全称),
|
|
13
|
+
* 被检视的配置读者不把它当域文档、不因它在场拒配置,所以写者不探引擎版本。
|
|
14
|
+
* 离线预置(引擎在本根起服之前铺好:镜像 / ConfigMap / 还原)时它与域文档可按任意顺序写;运行时写序是定的:写者先写决定、再写 `config.d/models.json`
|
|
15
|
+
* (都在它对 models.json 的那把锁里)。
|
|
16
|
+
* · **一份读法、一张闭集答案表**:决定只有 {@link EnvModelsDecision} 这一种答案(从字节读出的带同一次读的 `digest`,读不到字节的带 `errno`),
|
|
17
|
+
* 读这份决定的两方 —— 服务端的本地配置腿(读它并强制这道闸)、写者的计划助手 —— 吃同一个答案;它的身份(告警去重键、本地 etag 的贡献)只有一种拼法 {@link envModelsDecisionTag}。
|
|
18
|
+
* 缺席 ≡ `kept`(35.0.0 起无条件:铸 `replaced` 的一次性迁移 SS-M11 窗关删了;配置根上留着的旧运行记录 `config.migration.SS-M11.json` 是惰性文件,没有读者)。
|
|
19
|
+
* · 文档的形是 strict 的:多一个键(含自有 `__proto__`)、拼错的词都读成 `bad_shape`,不剥、不猜;digest 对读到的**字节**求。名字只在这里定一次(引擎的目录信任判官取 {@link CONFIG_ROOT_DOCUMENTS})。
|
|
20
|
+
*/
|
|
1
21
|
import { isPlainJsonObject } from "./plain-json-object.js";
|
|
2
22
|
import { sha256Digest, toHex } from "./sha256-core.js";
|
|
3
23
|
import { deepFreeze } from "./deep-freeze.js";
|
|
4
24
|
/** 配置根上的 env 模型表决定文档的名字(文件 `<根>/config.env-models.json`)。 */
|
|
5
25
|
export const ENV_MODELS_DOCUMENT = "config.env-models";
|
|
6
|
-
/** 运行记录文档名的前缀(包内:名字 = 前缀 + 迁移 id,文件 = 名字 + `.json`)。 */
|
|
7
|
-
const MIGRATION_MARKER_PREFIX = "config.migration.";
|
|
8
|
-
/** 一条一次性迁移的运行记录文档名(包内)。 */
|
|
9
|
-
export const migrationMarkerDocument = (id) => `${MIGRATION_MARKER_PREFIX}${id}`;
|
|
10
26
|
/**
|
|
11
|
-
* 根级文档名单(闭集、序固定;文件 = 名字 + `.json`,与 `config.d` 文档同一拼法)
|
|
27
|
+
* 根级文档名单(闭集、序固定;文件 = 名字 + `.json`,与 `config.d` 文档同一拼法):今天只有决定文档一份(35.0.0 起;此前还有一次性迁移 SS-M11 的运行记录,随迁移删了)。
|
|
12
28
|
* 引擎对配置根的目录信任判官、客户端的持久文件登记都取这一张,不手抄。判法与 `config.d` 里的文档**同一条律**(属主可信、路径上非链接组件不得组 / 他人可写、
|
|
13
29
|
* 常规文件、有大小上界)—— 一条律、两张名单(`config.d` 读回面一张,本张一张);`config.d` 不在时也照判。
|
|
14
30
|
* `<根>/.env` **不在**这张名单:引擎今天的目录信任判官只判 `config.d` 与它的读回面,不判 `.env`(秘密值文件,本包的文件仓库不读它);本名单只登记引擎会读的根级文档。
|
|
15
31
|
*/
|
|
16
|
-
export const CONFIG_ROOT_DOCUMENTS = deepFreeze([ENV_MODELS_DOCUMENT
|
|
17
|
-
/**
|
|
18
|
-
export const isMarkedMigrationId = (id) => typeof id === "string" && CONFIG_ROOT_DOCUMENTS.includes(`${MIGRATION_MARKER_PREFIX}${id}`);
|
|
19
|
-
/** 决定文档里能写的两个词(闭集):`replaced` = 目录管模型面时顶替 env 模型表;`kept` = 不顶替(与缺席同义,运行记录在场之后)。 */
|
|
32
|
+
export const CONFIG_ROOT_DOCUMENTS = deepFreeze([ENV_MODELS_DOCUMENT]);
|
|
33
|
+
/** 决定文档里能写的两个词(闭集):`replaced` = 目录管模型面时顶替 env 模型表;`kept` = 不顶替(与缺席同义)。 */
|
|
20
34
|
export const ENV_MODELS_DECISIONS = deepFreeze(["replaced", "kept"]);
|
|
21
35
|
/** 包内:是不是决定词(闭集,判法只此一只;写函数与读法同调)。 */
|
|
22
36
|
export const isDecisionWord = (v) => ENV_MODELS_DECISIONS.includes(v);
|
|
@@ -47,7 +61,7 @@ const digestOf = (bytes) => toHex(sha256Digest(bytes)).slice(0, 16);
|
|
|
47
61
|
const textOf = (bytes) => new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
48
62
|
/**
|
|
49
63
|
* 一个 JSON 值若是「恰好这一个自有键」的纯对象 ⇒ 那个键的值;否则(多一个键 —— 含 `JSON.parse` 铸出的自有 `__proto__` 键 —— 少一个键、不是纯对象)⇒ `undefined`。
|
|
50
|
-
*
|
|
64
|
+
* 决定文档的形是 strict 的,判在这里一处;不交给 zod 的 strict:它对自有 `__proto__` 键的处置随版本变(4.4.x 跳过它、4.6.x 拒它;32.0.0 起声明的区间已不含 4.4.x,判仍在这里一处,不依赖 zod 的处置)。
|
|
51
65
|
* 文档是 `JSON.parse` 的产物,自有键都是可枚举数据属性,`Object.keys` 就是它的全部键。
|
|
52
66
|
*/
|
|
53
67
|
function soleOwnValue(v, key) {
|
|
@@ -81,14 +95,3 @@ export function readEnvModelsDecisionBytes(bytes) {
|
|
|
81
95
|
export function ioDecision(errno) {
|
|
82
96
|
return { kind: "unreadable", reason: "io", errno: errno ?? "uncoded" };
|
|
83
97
|
}
|
|
84
|
-
/** 包内:运行记录文档的值(`{"migration":<id>}`,写与读同一只形)。 */
|
|
85
|
-
export const migrationMarkerValue = (id) => ({ migration: id });
|
|
86
|
-
/** 包内:运行记录的**字节读法**(唯一一份):`{"migration":<这条记录的 id>}` strict ⇒ `present`;别的 ⇒ 读不懂(id 对不上也是坏形)。 */
|
|
87
|
-
export function readMigrationMarkerBytes(id, bytes) {
|
|
88
|
-
const json = parseJsonText(textOf(bytes));
|
|
89
|
-
if (!json.ok)
|
|
90
|
-
return { kind: "unreadable", reason: "bad_json" };
|
|
91
|
-
return soleOwnValue(json.value, "migration") === id ? { kind: "present" } : { kind: "unreadable", reason: "bad_shape" };
|
|
92
|
-
}
|
|
93
|
-
/** 包内:字节 → 文本(`config.d/models.json` 的读也经它,与上面两份同一解码)。 */
|
|
94
|
-
export const decodeRootBytes = textOf;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { type ConfigRootDocument, type EnvModelsDecision, type EnvModelsDecisionWord
|
|
2
|
-
import { type EnvModelTableEntry, type EnvSnapshot } from "./env-model-table.js";
|
|
3
|
-
import type { MigrationReceipt } from "./migration-receipt.js";
|
|
1
|
+
import { type ConfigRootDocument, type EnvModelsDecision, type EnvModelsDecisionWord } from "./config-root-documents.js";
|
|
4
2
|
/** 根级文档读写的 I/O 座(注入;真绑定 {@link nodeConfigRootIo})。写的两只按文档名取模式类({@link ROOT_DOCUMENT_CLASS},类的规则见原子写器的模式表)。 */
|
|
5
3
|
export interface ConfigRootIo {
|
|
6
4
|
/** 读一份文件的**字节**(digest 对字节求;解码由本包做);不存在 ⇒ 抛 `code: "ENOENT"` 的错,别的读不出照常抛(带 errno)。 */
|
|
@@ -9,8 +7,6 @@ export interface ConfigRootIo {
|
|
|
9
7
|
writeDocument(document: ConfigRootDocument, file: string, text: string): Promise<void>;
|
|
10
8
|
/** 原子地**独占创建**一份根级文档(独占建临时文件、fsync → `link`;新建模式同 {@link writeDocument}):建成 ⇒ `created`;目标名已在(只有 `EEXIST`)⇒ `present`(一字不动);别的失败照常抛。 */
|
|
11
9
|
createDocument(document: ConfigRootDocument, file: string, text: string): Promise<"created" | "present">;
|
|
12
|
-
/** 目录不在就建(仅属主可进,连同缺的上级):建了 ⇒ `created`;已在 ⇒ `present`。 */
|
|
13
|
-
ensureDirectory(dir: string): Promise<"created" | "present">;
|
|
14
10
|
}
|
|
15
11
|
/** 真文件系统的绑定:读先过本包的符号链接判法(链接 ⇒ 它指向的真文件;悬空 ⇒ 抛,不是缺席),只读常规文件;写走本包唯一的原子写器。 */
|
|
16
12
|
export declare const nodeConfigRootIo: Readonly<ConfigRootIo>;
|
|
@@ -18,16 +14,10 @@ export declare const nodeConfigRootIo: Readonly<ConfigRootIo>;
|
|
|
18
14
|
export declare function readEnvModelsDecision(root: string, io?: ConfigRootIo): Promise<EnvModelsDecision>;
|
|
19
15
|
/** {@link readEnvModelsDecision} 的**同步孪生**(壳在同步具名锁里写模型池,要在锁里读决定):同一个字节读法、同一个缺席律、同一个答案表;读真文件系统(不收注入座 —— 注入座是异步的)。从不抛。 */
|
|
20
16
|
export declare function readEnvModelsDecisionSync(root: string): EnvModelsDecision;
|
|
21
|
-
/**
|
|
22
|
-
* 一条一次性迁移的运行记录的**唯一读者**(文件 `<根>/config.migration.<id>.json`):不存在 ⇒ `absent`;`{"migration":<id>}` ⇒ `present`;别的 ⇒ `unreadable`
|
|
23
|
-
* (坏 JSON / 坏形 —— id 对不上也算 / 读不出)。「跑过」只问这一份文件在不在、读不读得懂,不读任何聚合文件。读数从不抛;`id` 不是写运行记录的迁移(根级文档名单里没有它的记录)⇒
|
|
24
|
-
* `TypeError`,不拿它拼路径。
|
|
25
|
-
*/
|
|
26
|
-
export declare function readMigrationMarker(root: string, id: MarkedMigrationId, io?: ConfigRootIo): Promise<MigrationMarker>;
|
|
27
17
|
/** {@link writeEnvModelsDecision} 的写法(闭集):`overwrite` = 写者(用户确认之后,整份覆盖);`createIfAbsent` = 不存在才建。 */
|
|
28
18
|
export type EnvModelsDecisionWrite = "overwrite" | "createIfAbsent";
|
|
29
19
|
/**
|
|
30
|
-
* 写配置根上的 env 模型表决定 ——
|
|
20
|
+
* 写配置根上的 env 模型表决定 —— 决定文件的**唯一写函数**。`overwrite` 恒答 `written`;`createIfAbsent` 在文档已在(`EEXIST`)时答 `present`(一字不动)。
|
|
31
21
|
* 决定词 / 写法不在闭集 ⇒ `TypeError`(一字不写)。写失败 ⇒ 抛本包的文件系统失败句(点名路径)。根须已存在。
|
|
32
22
|
*/
|
|
33
23
|
export declare function writeEnvModelsDecision(root: string, decision: EnvModelsDecisionWord, opts: {
|
|
@@ -38,87 +28,3 @@ export declare function writeEnvModelsDecision(root: string, decision: EnvModels
|
|
|
38
28
|
export declare function writeEnvModelsDecisionSync(root: string, decision: EnvModelsDecisionWord, opts: {
|
|
39
29
|
readonly write: EnvModelsDecisionWrite;
|
|
40
30
|
}): "written" | "present";
|
|
41
|
-
/** SS-M11 的结局(闭集,调用方穷举;本函数不出声,告警由调用方按结局发)。 */
|
|
42
|
-
export type EnvModelsMigration =
|
|
43
|
-
/** 运行记录已在:不跑。 */
|
|
44
|
-
{
|
|
45
|
-
readonly kind: "already_ran";
|
|
46
|
-
}
|
|
47
|
-
/** 运行记录读不懂:按已跑处理(读不懂记录就不替人铸确认),一字不写。调用方告警。 */
|
|
48
|
-
| {
|
|
49
|
-
readonly kind: "marker_unreadable";
|
|
50
|
-
readonly reason: RootDocumentUnreadableReason;
|
|
51
|
-
}
|
|
52
|
-
/** 独占创建运行记录时它已在(`EEXIST`):别的进程已是本根的铸造者 ⇒ 本进程永不铸。 */
|
|
53
|
-
| {
|
|
54
|
-
readonly kind: "not_minter";
|
|
55
|
-
}
|
|
56
|
-
/** 运行记录建不成(只读根、根建不出、`ENOSPC`、文件系统不支持硬链接 —— `ENOTSUP` / `EPERM` …):不铸 —— 缺席照旧读作 kept。
|
|
57
|
-
* 记录始终建不成 ⇒ 每次起服都重跑、都答这一格(调用方每次告警;手写的决定照常生效,告警不因它停)。`error` 点名记录文件,`wayOut` 是手工恢复句。 */
|
|
58
|
-
| {
|
|
59
|
-
readonly kind: "marker_write_failed";
|
|
60
|
-
readonly errno: string | undefined;
|
|
61
|
-
readonly error: string;
|
|
62
|
-
readonly wayOut: string;
|
|
63
|
-
}
|
|
64
|
-
/** 本进程独占创建了运行记录 = 本根唯一的铸造者;`decision` = 选举**之前**读到的决定(铸只按它),`mint` = 铸没铸。 */
|
|
65
|
-
| {
|
|
66
|
-
readonly kind: "recorded";
|
|
67
|
-
readonly createdRoot: boolean;
|
|
68
|
-
readonly decision: EnvModelsDecision;
|
|
69
|
-
readonly mint: EnvModelsMint;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* SS-M11 铸确认的结局(闭集)。**披露**:运行记录先于确认建;进程在两者之间中断,或铸失败、或 models.json 读不出 ⇒ 此后无人再铸、决定缺席读作 kept ——
|
|
73
|
-
* 升级前由目录服务的根这时换成 env 模型服务,旧目录不会自动保住;出路是 `wayOut` 那一句(手写决定文件)。
|
|
74
|
-
*/
|
|
75
|
-
export type EnvModelsMint =
|
|
76
|
-
/** 铸了 `replaced`:`replacedEnvModels` = 从此被目录顶替的 env 模型(名 + 槽 + 来源键;env 表没声明 ⇒ 空)—— 非空时调用方据此发一行一次性告警,点名它们与出路(删掉 / 写 kept)。 */
|
|
77
|
-
{
|
|
78
|
-
readonly kind: "minted";
|
|
79
|
-
readonly receipt: MigrationReceipt;
|
|
80
|
-
readonly replacedEnvModels: readonly EnvModelTableEntry[];
|
|
81
|
-
}
|
|
82
|
-
/** 独占创建决定时它已在(只有 `EEXIST` 算):期间有人写了决定(用户的 kept / 写者的 replaced)⇒ 一字不动。 */
|
|
83
|
-
| {
|
|
84
|
-
readonly kind: "exists";
|
|
85
|
-
}
|
|
86
|
-
/** 决定建不成(`ENOSPC` / `EIO` / `EPERM` / 文件系统不支持硬链接 …):缺席照旧读作 kept,记录在 ⇒ 此后不再尝试。`error` 点名决定文件,`wayOut` 是手工恢复句。 */
|
|
87
|
-
| {
|
|
88
|
-
readonly kind: "failed";
|
|
89
|
-
readonly errno: string | undefined;
|
|
90
|
-
readonly error: string;
|
|
91
|
-
readonly wayOut: string;
|
|
92
|
-
}
|
|
93
|
-
/** 不铸:选举前读到的决定已在(replaced / kept / 读不懂 —— 读不懂的不覆盖;它之后被删也不重铸)/ 目录不管模型面(没有 models.json —— 只有 `ENOENT` 算没有 —— 或坏文件)。
|
|
94
|
-
* 判序:决定 → 目录。铸不铸不看 env 表:迁移保的是升级前「管模型面的目录整表顶替 env」这个读法,与 env 声没声明无关。 */
|
|
95
|
-
| {
|
|
96
|
-
readonly kind: "skipped";
|
|
97
|
-
readonly why: "decision_present" | "not_managing";
|
|
98
|
-
}
|
|
99
|
-
/** 不铸,且要运维动手:决定缺席,而 models.json 读不出(`EACCES` / `EIO` / `ESTALE` / 悬空符号链接 / 不是常规文件 …)—— 管不管判不了,不替人铸(fail-closed)。
|
|
100
|
-
* 运行记录已在 ⇒ 此后不再尝试:与 `failed` 同一出路(`wayOut`,手写决定文件);`error` 点名 models.json 与读错,`errno` 只在底层错误带码时有
|
|
101
|
-
* (悬空链接 / 不是常规文件 ⇒ `undefined`),调用方告警。 */
|
|
102
|
-
| {
|
|
103
|
-
readonly kind: "models_unreadable";
|
|
104
|
-
readonly errno: string | undefined;
|
|
105
|
-
readonly error: string;
|
|
106
|
-
readonly wayOut: string;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* **一次性迁移 SS-M11**(登记见 `ONE_TIME_MIGRATIONS`;起服、第一次读本地配置之前调,只在配置源是本地时):
|
|
110
|
-
* 1. 读运行记录:`present` ⇒ `already_ran`;读不懂 ⇒ `marker_unreadable`(按已跑处理)。
|
|
111
|
-
* 2. **先读**:决定 D0 = `readEnvModelsDecision`,M0 = `config.d/models.json` 管不管模型面(管 / 不管 / 读不出)。此后的铸只按 D0 / M0 决定,不再读决定 ——
|
|
112
|
-
* D0 是 replaced(预置)而它在选举之后被删 ⇒ 不重铸;D0 是 absent 而选举之后有人写了决定 ⇒ 第 5 步的独占创建守住它。
|
|
113
|
-
* 3. 根缺席 ⇒ 建(仅属主可进,连同缺的上级,模式恰是 0o700);**不建 `config.d`**。
|
|
114
|
-
* 4. **独占创建运行记录** `{"migration":"SS-M11"}`:建成 ⇒ 本进程是本根**唯一的铸造者**;已在(`EEXIST`)⇒ `not_minter`,永不铸;别的失败 ⇒ `marker_write_failed`,不铸。
|
|
115
|
-
* 5. 仅铸造者:D0 不是 `absent` ⇒ 不铸(读不懂的也不覆盖);M0 不管 ⇒ 不铸;M0 读不出 ⇒ 不铸(`models_unreadable`,带 errno(若有)与手工恢复句);否则**独占创建** `{"envModels":"replaced"}` —— 结局三词:`minted` / `exists`(只有 `EEXIST`)/
|
|
116
|
-
* `failed`(带 errno 与手工恢复句)。铸不铸不看 env;env 只在铸成之后读一次、只读两槽,用来点名被顶替的 env 模型。
|
|
117
|
-
* 运行记录在场之后,确认缺席 ≡ kept(读这份决定的一律这么读:服务端的本地配置腿、迁移、写者)。
|
|
118
|
-
* 撤销的终局按运行记录的创建者算:只有创建者能写确认;以运行记录在场为前提,创建者写完 / 判定不写 / 失败(结局 `minted` / `exists` / `skipped` / `models_unreadable` / `failed`,调用方各记一行)之后,删掉决定文件就是撤销且是终局(删掉运行记录再起服 ⇒ 迁移重跑,决定缺席即重铸);其它副本读到记录在场 = 已跑、跳过(或得 `EEXIST` 答 `not_minter`),它们的返回不构成终局;创建者当选到结局落定之间的窗口在挂起 / I/O 卡顿下无上界,窗口内唯一安全的撤销是写 `kept`(独占创建护住它;删掉的会被创建者照它先读的 D0 铸回);创建者在写确认之前崩溃 ⇒ 永久 `kept`(fail-closed,披露)。
|
|
119
|
-
*/
|
|
120
|
-
export declare function migrateEnvModelsDecision(input: {
|
|
121
|
-
readonly root: string;
|
|
122
|
-
readonly env: EnvSnapshot;
|
|
123
|
-
readonly io?: ConfigRootIo;
|
|
124
|
-
}): Promise<EnvModelsMigration>;
|
package/dist/config-root-node.js
CHANGED
|
@@ -1,39 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 配置根上决定文档的**读写函数**(Node 专用,经 `./node` 出口;名字、形与闭集答案表在 `./config-root-documents`)。
|
|
3
|
+
* (35.0.0 起这里没有迁移体:一次性迁移 SS-M11 与它的运行记录读者窗关删了,决定缺席 ≡ `kept`。)
|
|
3
4
|
*
|
|
4
5
|
* 读写都经一只注入的 I/O 座 {@link ConfigRootIo}(真绑定 {@link nodeConfigRootIo}:读走 `node:fs/promises`,写走本包唯一的原子写器与它的模式表),
|
|
5
6
|
* 所以单元层能把任意读写失败造出来;调用方不传就是真文件系统。
|
|
6
7
|
*
|
|
7
|
-
* · {@link readEnvModelsDecision}
|
|
8
|
-
* 读恒 `EACCES`,是**持久**的 —— 不是常规文件、悬空符号链接、瞬时错)⇒ `unreadable io`;字节在 ⇒ 文本读法(`./config-root-documents
|
|
9
|
-
*
|
|
8
|
+
* · {@link readEnvModelsDecision} —— 唯一的读者:不存在(`ENOENT`)⇒ `absent`;别的读错(权限 —— 可信属主的 0000 文件过得了引擎的目录信任判官、
|
|
9
|
+
* 读恒 `EACCES`,是**持久**的 —— 不是常规文件、悬空符号链接、瞬时错)⇒ `unreadable io`;字节在 ⇒ 文本读法(`./config-root-documents`;答案带同一次读的 `digest`)。
|
|
10
|
+
* 读数从不抛。**引擎在读之前先过它自己的目录信任判官**(属主 / 写位 / 常规文件);
|
|
10
11
|
* 本函数不判属主。确认文件的字节只在这里被打开。
|
|
11
12
|
* · {@link readEnvModelsDecisionSync} / {@link writeEnvModelsDecisionSync} —— 决定文档读 / 写的**同步孪生**(壳在同步具名锁里写模型池:先写决定 `replaced`、再写目录,两次写在同一把锁里 —— 要在锁里读、在锁里写):
|
|
12
13
|
* 同一个字节读法、同一个缺席律、同一份答案表、同一份写计划、同一对同步原子写原语(异步座的写本来就是它们的异步包装);读写真文件系统,不收注入座(注入座是异步的,`ConfigRootIo` 不动)。
|
|
13
|
-
* · {@link writeEnvModelsDecision} ——
|
|
14
|
-
* `createIfAbsent` 不存在才建(已在 ⇒ `present
|
|
14
|
+
* · {@link writeEnvModelsDecision} —— 决定文件的唯一写函数:写者(用户确认之后)用 `overwrite`(原子改名覆盖,读不懂的旧文件整份换掉);
|
|
15
|
+
* `createIfAbsent` 不存在才建(已在 ⇒ `present`)。
|
|
15
16
|
* 模式与 `config.d` 域文档同一条规则(原子写器的 `config-document` 类:新建 0o644 经进程 umask、更严的 umask 只会更严;已有的文件沿用它原来的模式)—— 写者不要自己写这份文件:
|
|
16
17
|
* 自写在 umask 002 下落 0664,引擎的目录信任判官会拒。
|
|
17
|
-
* · {@link migrateEnvModelsDecision} —— SS-M11(窗与删法见 `ONE_TIME_MIGRATIONS` 登记表那一行)。**先读后选举**:先读决定与 models.json,再以「不存在才建」写
|
|
18
|
-
* 运行记录 `config.migration.SS-M11.json` —— 建成的那个进程是本根唯一的铸造者,且只按它选举之前读到的决定铸;别的进程见记录已在即停、永不铸。
|
|
19
|
-
* 撤销的终局按创建者算(见 {@link migrateEnvModelsDecision}):运行记录在场、创建者的结局落定之后,删掉决定文件与写 `kept` 同义、是终局(删掉运行记录再起服会重跑迁移);其它副本的返回不构成终局。
|
|
20
18
|
*/
|
|
21
19
|
import { readFileSync, statSync } from "node:fs";
|
|
22
20
|
import { readFile, stat } from "node:fs/promises";
|
|
23
21
|
import path from "node:path";
|
|
24
|
-
import { createFileExclusive,
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { ENV_MODEL_TABLE_KEYS, buildEnvModelBaseline, snapshotEnvModelTable } from "./env-model-table.js";
|
|
29
|
-
import { FsFailure, fsFailureMessage } from "./fs-failure.js";
|
|
22
|
+
import { createFileExclusive, resolveSymlinkTarget, writeFileAtomic } from "./atomic-write.js";
|
|
23
|
+
import { configDDocumentText } from "./config-d-file.js";
|
|
24
|
+
import { ENV_MODELS_DECISIONS, ENV_MODELS_DOCUMENT, ioDecision, isDecisionWord, readEnvModelsDecisionBytes, } from "./config-root-documents.js";
|
|
25
|
+
import { FsFailure } from "./fs-failure.js";
|
|
30
26
|
import { readKey } from "./own-key-read.js";
|
|
31
27
|
import { jsonShapeOf } from "./plain-json-object.js";
|
|
32
28
|
import { deepFreeze } from "./deep-freeze.js";
|
|
33
|
-
/** 根级文档 → 原子写器的模式类(穷举:加一份根级文档不补这一行 ⇒ 编译红,逼着为它选一类)
|
|
29
|
+
/** 根级文档 → 原子写器的模式类(穷举:加一份根级文档不补这一行 ⇒ 编译红,逼着为它选一类)。决定文档是契约文档(只带固定词,不带秘密值),与 `config.d` 域文档同属 `config-document`。 */
|
|
34
30
|
const ROOT_DOCUMENT_CLASS = {
|
|
35
31
|
[ENV_MODELS_DOCUMENT]: "config-document",
|
|
36
|
-
[migrationMarkerDocument("SS-M11")]: "config-document",
|
|
37
32
|
};
|
|
38
33
|
/** 「不是常规文件」的拒句(异步读座与同步读口共用一句)。 */
|
|
39
34
|
const notRegularFile = (file) => new Error(`${file} is not a regular file`);
|
|
@@ -52,7 +47,6 @@ export const nodeConfigRootIo = deepFreeze({
|
|
|
52
47
|
},
|
|
53
48
|
writeDocument: async (document, file, text) => writeRootDocumentSync(document, file, text),
|
|
54
49
|
createDocument: async (document, file, text) => createRootDocumentSync(document, file, text),
|
|
55
|
-
ensureDirectory: async (dir) => ensureOwnerOnlyDirectory(dir),
|
|
56
50
|
});
|
|
57
51
|
/** {@link nodeConfigRootIo}`.readFile` 的同步孪生(同步读口 {@link readEnvModelsDecisionSync} 用):同一条判法(符号链接 ⇒ 真文件,悬空抛;只读常规文件),只有读字节那一步同步。 */
|
|
58
52
|
function readRootFileSync(file) {
|
|
@@ -62,7 +56,6 @@ function readRootFileSync(file) {
|
|
|
62
56
|
return readFileSync(real);
|
|
63
57
|
}
|
|
64
58
|
const decisionFile = (root) => path.join(root, `${ENV_MODELS_DOCUMENT}.json`);
|
|
65
|
-
const markerFile = (root, id) => path.join(root, `${migrationMarkerDocument(id)}.json`);
|
|
66
59
|
/** 一个被抛出的东西的 errno:**只认自有的**字符串 `code`(经内核的键读法);读不出(会抛的 `code` getter、已撤销的 Proxy)、只靠继承、不是串 ⇒ `undefined`。从不抛(读者「从不抛」靠它)。 */
|
|
67
60
|
const errnoOf = (e) => {
|
|
68
61
|
const shape = jsonShapeOf(e); // 形状只问座位(总、不抛);穷举 switch:座位加一个词这里编译红
|
|
@@ -83,10 +76,10 @@ const errnoOf = (e) => {
|
|
|
83
76
|
}
|
|
84
77
|
}
|
|
85
78
|
};
|
|
86
|
-
/** 读字节失败之后怎么答 —— 本文件唯一的缺席律(异步 {@link readRootBytes} 与同步 {@link readRootBytesSync} 共用):不存在(只有 `ENOENT`)⇒ `absent`;别的读不出 ⇒ `io`(带 errno
|
|
79
|
+
/** 读字节失败之后怎么答 —— 本文件唯一的缺席律(异步 {@link readRootBytes} 与同步 {@link readRootBytesSync} 共用):不存在(只有 `ENOENT`)⇒ `absent`;别的读不出 ⇒ `io`(带 errno;决定读数只要 errno —— 35.0.0 前还带捕获的错,给 SS-M11 读 models.json 时铸句用,随它删)。 */
|
|
87
80
|
function rootBytesFailure(e) {
|
|
88
81
|
const errno = errnoOf(e);
|
|
89
|
-
return errno === "ENOENT" ? { kind: "absent" } : { kind: "io", errno
|
|
82
|
+
return errno === "ENOENT" ? { kind: "absent" } : { kind: "io", errno };
|
|
90
83
|
}
|
|
91
84
|
/** 经注入座读一份文件的字节(异步);失败的分类是 {@link rootBytesFailure}。 */
|
|
92
85
|
async function readRootBytes(io, file) {
|
|
@@ -129,28 +122,6 @@ export async function readEnvModelsDecision(root, io = nodeConfigRootIo) {
|
|
|
129
122
|
export function readEnvModelsDecisionSync(root) {
|
|
130
123
|
return decisionOfBytes(readRootBytesSync(decisionFile(root)));
|
|
131
124
|
}
|
|
132
|
-
/**
|
|
133
|
-
* 一条一次性迁移的运行记录的**唯一读者**(文件 `<根>/config.migration.<id>.json`):不存在 ⇒ `absent`;`{"migration":<id>}` ⇒ `present`;别的 ⇒ `unreadable`
|
|
134
|
-
* (坏 JSON / 坏形 —— id 对不上也算 / 读不出)。「跑过」只问这一份文件在不在、读不读得懂,不读任何聚合文件。读数从不抛;`id` 不是写运行记录的迁移(根级文档名单里没有它的记录)⇒
|
|
135
|
-
* `TypeError`,不拿它拼路径。
|
|
136
|
-
*/
|
|
137
|
-
export async function readMigrationMarker(root, id, io = nodeConfigRootIo) {
|
|
138
|
-
if (!isMarkedMigrationId(id))
|
|
139
|
-
throw new TypeError(`readMigrationMarker: ${JSON.stringify(id)} is not a migration that writes a run marker (the root documents list it) — no path is built from it`);
|
|
140
|
-
const bytes = await readRootBytes(io, markerFile(root, id));
|
|
141
|
-
switch (bytes.kind) {
|
|
142
|
-
case "absent":
|
|
143
|
-
return { kind: "absent" };
|
|
144
|
-
case "io":
|
|
145
|
-
return { kind: "unreadable", reason: "io" };
|
|
146
|
-
case "bytes":
|
|
147
|
-
return readMigrationMarkerBytes(id, bytes.bytes);
|
|
148
|
-
default: {
|
|
149
|
-
const unhandled = bytes;
|
|
150
|
-
throw new Error(`readMigrationMarker: unhandled reading ${JSON.stringify(unhandled)}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
125
|
/** 写决定的**计划**(异步 {@link writeEnvModelsDecision} 与同步 {@link writeEnvModelsDecisionSync} 共用,三件事只在这里):决定词与写法都在闭集里(不在 ⇒ `TypeError`,调用方的错,一字不写)· 铸文本 · 写失败 ⇒ 本包的文件系统失败句(点名路径)。
|
|
155
126
|
* `who` 只用来在 `TypeError` 里点名调用的是哪一只。 */
|
|
156
127
|
function planDecisionWrite(who, root, decision, opts) {
|
|
@@ -175,7 +146,7 @@ function planDecisionWrite(who, root, decision, opts) {
|
|
|
175
146
|
return { write, file, text, loud };
|
|
176
147
|
}
|
|
177
148
|
/**
|
|
178
|
-
* 写配置根上的 env 模型表决定 ——
|
|
149
|
+
* 写配置根上的 env 模型表决定 —— 决定文件的**唯一写函数**。`overwrite` 恒答 `written`;`createIfAbsent` 在文档已在(`EEXIST`)时答 `present`(一字不动)。
|
|
179
150
|
* 决定词 / 写法不在闭集 ⇒ `TypeError`(一字不写)。写失败 ⇒ 抛本包的文件系统失败句(点名路径)。根须已存在。
|
|
180
151
|
*/
|
|
181
152
|
export async function writeEnvModelsDecision(root, decision, opts, io = nodeConfigRootIo) {
|
|
@@ -223,122 +194,3 @@ export function writeEnvModelsDecisionSync(root, decision, opts) {
|
|
|
223
194
|
}
|
|
224
195
|
}
|
|
225
196
|
}
|
|
226
|
-
/** 手工恢复句(迁移建不成收据 / 建不成决定时随结局交出;调用方原样放进它那一行告警):点名决定文件与两种写法。 */
|
|
227
|
-
const wayOutFor = (root) => `write ${decisionFile(root)} by hand — {"envModels":"replaced"} lets the catalog replace the env models, {"envModels":"kept"} keeps them`;
|
|
228
|
-
/** 读 `config.d/models.json` 一次(字节经 {@link readRootBytes} —— 与两份根级文档同一条缺席律;文本过 `config.d` 文档的那一只文本判 —— 与文件仓库同一读法):
|
|
229
|
-
* 缺席 / 坏文件 ⇒ 不管;别的读错 ⇒ 读不出(不折成不管)。 */
|
|
230
|
-
async function readModelsDocument(io, root) {
|
|
231
|
-
const file = configDPath(root, "models");
|
|
232
|
-
const read = await readRootBytes(io, file);
|
|
233
|
-
let bytes;
|
|
234
|
-
switch (read.kind) {
|
|
235
|
-
case "absent":
|
|
236
|
-
return { kind: "not_managing" };
|
|
237
|
-
case "io":
|
|
238
|
-
return { kind: "unreadable", errno: read.errno, error: fsFailureMessage({ landing: "read", path: file, of: "file" }, read.cause) };
|
|
239
|
-
case "bytes":
|
|
240
|
-
bytes = read.bytes;
|
|
241
|
-
break;
|
|
242
|
-
default: {
|
|
243
|
-
const unhandled = read;
|
|
244
|
-
throw new Error(`readModelsDocument: unhandled reading ${JSON.stringify(unhandled)}`);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
let doc;
|
|
248
|
-
try {
|
|
249
|
-
doc = judgeConfigDText("models", decodeRootBytes(bytes), file);
|
|
250
|
-
}
|
|
251
|
-
catch {
|
|
252
|
-
return { kind: "not_managing" }; // a bad file manages nothing; the file store refuses it loudly on its own read
|
|
253
|
-
}
|
|
254
|
-
return catalogManagesModelPlane(doc) ? { kind: "manages" } : { kind: "not_managing" }; // JSON 解析出来的值恒是纯数据:判官不会抛
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* **一次性迁移 SS-M11**(登记见 `ONE_TIME_MIGRATIONS`;起服、第一次读本地配置之前调,只在配置源是本地时):
|
|
258
|
-
* 1. 读运行记录:`present` ⇒ `already_ran`;读不懂 ⇒ `marker_unreadable`(按已跑处理)。
|
|
259
|
-
* 2. **先读**:决定 D0 = `readEnvModelsDecision`,M0 = `config.d/models.json` 管不管模型面(管 / 不管 / 读不出)。此后的铸只按 D0 / M0 决定,不再读决定 ——
|
|
260
|
-
* D0 是 replaced(预置)而它在选举之后被删 ⇒ 不重铸;D0 是 absent 而选举之后有人写了决定 ⇒ 第 5 步的独占创建守住它。
|
|
261
|
-
* 3. 根缺席 ⇒ 建(仅属主可进,连同缺的上级,模式恰是 0o700);**不建 `config.d`**。
|
|
262
|
-
* 4. **独占创建运行记录** `{"migration":"SS-M11"}`:建成 ⇒ 本进程是本根**唯一的铸造者**;已在(`EEXIST`)⇒ `not_minter`,永不铸;别的失败 ⇒ `marker_write_failed`,不铸。
|
|
263
|
-
* 5. 仅铸造者:D0 不是 `absent` ⇒ 不铸(读不懂的也不覆盖);M0 不管 ⇒ 不铸;M0 读不出 ⇒ 不铸(`models_unreadable`,带 errno(若有)与手工恢复句);否则**独占创建** `{"envModels":"replaced"}` —— 结局三词:`minted` / `exists`(只有 `EEXIST`)/
|
|
264
|
-
* `failed`(带 errno 与手工恢复句)。铸不铸不看 env;env 只在铸成之后读一次、只读两槽,用来点名被顶替的 env 模型。
|
|
265
|
-
* 运行记录在场之后,确认缺席 ≡ kept(读这份决定的一律这么读:服务端的本地配置腿、迁移、写者)。
|
|
266
|
-
* 撤销的终局按运行记录的创建者算:只有创建者能写确认;以运行记录在场为前提,创建者写完 / 判定不写 / 失败(结局 `minted` / `exists` / `skipped` / `models_unreadable` / `failed`,调用方各记一行)之后,删掉决定文件就是撤销且是终局(删掉运行记录再起服 ⇒ 迁移重跑,决定缺席即重铸);其它副本读到记录在场 = 已跑、跳过(或得 `EEXIST` 答 `not_minter`),它们的返回不构成终局;创建者当选到结局落定之间的窗口在挂起 / I/O 卡顿下无上界,窗口内唯一安全的撤销是写 `kept`(独占创建护住它;删掉的会被创建者照它先读的 D0 铸回);创建者在写确认之前崩溃 ⇒ 永久 `kept`(fail-closed,披露)。
|
|
267
|
-
*/
|
|
268
|
-
export async function migrateEnvModelsDecision(input) {
|
|
269
|
-
const { root, env } = input;
|
|
270
|
-
const io = input.io ?? nodeConfigRootIo;
|
|
271
|
-
const marker = await readMigrationMarker(root, "SS-M11", io);
|
|
272
|
-
switch (marker.kind) {
|
|
273
|
-
case "present":
|
|
274
|
-
return { kind: "already_ran" };
|
|
275
|
-
case "unreadable":
|
|
276
|
-
return { kind: "marker_unreadable", reason: marker.reason };
|
|
277
|
-
case "absent":
|
|
278
|
-
break;
|
|
279
|
-
default: {
|
|
280
|
-
const unhandled = marker;
|
|
281
|
-
throw new Error(`migrateEnvModelsDecision: unhandled marker ${JSON.stringify(unhandled)}`);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const decision = await readEnvModelsDecision(root, io);
|
|
285
|
-
const models = await readModelsDocument(io, root);
|
|
286
|
-
const file = markerFile(root, "SS-M11");
|
|
287
|
-
let createdRoot;
|
|
288
|
-
let created;
|
|
289
|
-
try {
|
|
290
|
-
// 一次操作一条路径串:建的目录是随后要写的那份文件的路径串的 dirname(原子写器的文件头「一次操作一条路径串」)—— 配置根下的文件一向是 `path.join(根, 文件名)`
|
|
291
|
-
createdRoot = (await io.ensureDirectory(path.dirname(file))) === "created";
|
|
292
|
-
created = await io.createDocument(migrationMarkerDocument("SS-M11"), file, configDDocumentText(migrationMarkerValue("SS-M11")));
|
|
293
|
-
}
|
|
294
|
-
catch (e) {
|
|
295
|
-
return { kind: "marker_write_failed", errno: errnoOf(e), error: fsFailureMessage({ landing: "write", path: file }, e), wayOut: wayOutFor(root) };
|
|
296
|
-
}
|
|
297
|
-
if (created === "present")
|
|
298
|
-
return { kind: "not_minter" };
|
|
299
|
-
return { kind: "recorded", createdRoot, decision, mint: await mintDecision(io, root, env, decision, models) };
|
|
300
|
-
}
|
|
301
|
-
async function mintDecision(io, root, env, decision, models) {
|
|
302
|
-
switch (decision.kind) {
|
|
303
|
-
case "absent":
|
|
304
|
-
break;
|
|
305
|
-
case "replaced":
|
|
306
|
-
case "kept":
|
|
307
|
-
case "unreadable":
|
|
308
|
-
return { kind: "skipped", why: "decision_present" };
|
|
309
|
-
default: {
|
|
310
|
-
const unhandled = decision;
|
|
311
|
-
throw new Error(`migrateEnvModelsDecision: unhandled decision ${JSON.stringify(unhandled)}`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
switch (models.kind) {
|
|
315
|
-
case "manages":
|
|
316
|
-
break;
|
|
317
|
-
case "not_managing":
|
|
318
|
-
return { kind: "skipped", why: "not_managing" };
|
|
319
|
-
case "unreadable":
|
|
320
|
-
return { kind: "models_unreadable", errno: models.errno, error: models.error, wayOut: wayOutFor(root) };
|
|
321
|
-
default: {
|
|
322
|
-
const unhandled = models;
|
|
323
|
-
throw new Error(`migrateEnvModelsDecision: unhandled models reading ${JSON.stringify(unhandled)}`);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
let wrote;
|
|
327
|
-
try {
|
|
328
|
-
wrote = await writeEnvModelsDecision(root, "replaced", { write: "createIfAbsent" }, io);
|
|
329
|
-
}
|
|
330
|
-
catch (e) {
|
|
331
|
-
// the write function throws only its file-system failure (it names the decision file and carries the errno)
|
|
332
|
-
return { kind: "failed", errno: errnoOf(e), error: fsFailureMessage({ landing: "write", path: decisionFile(root) }, e), wayOut: wayOutFor(root) };
|
|
333
|
-
}
|
|
334
|
-
if (wrote === "present")
|
|
335
|
-
return { kind: "exists" };
|
|
336
|
-
// env is read only now, once, and only the two slot keys: it names the env models the minted decision replaces (none when no table is declared);
|
|
337
|
-
// a run that stops earlier reads no env at all
|
|
338
|
-
const slots = snapshotEnvModelTable(env, [ENV_MODEL_TABLE_KEYS.mainId, ENV_MODEL_TABLE_KEYS.cheapId]);
|
|
339
|
-
return {
|
|
340
|
-
kind: "minted",
|
|
341
|
-
receipt: { migration: "SS-M11", document: ENV_MODELS_DOCUMENT, path: ["envModels"], appliedAs: "minted" },
|
|
342
|
-
replacedEnvModels: buildEnvModelBaseline(slots).entries,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
@@ -18,6 +18,7 @@ export { runConformance, materializeLocalRoot, resolveLegExpectation } from "./r
|
|
|
18
18
|
export { runWebAdminCredentialLockConformance, type WebAdminCredentialLockConformanceReport, type WebAdminCredentialLockImplementation } from "./web-admin-credential-lock.js";
|
|
19
19
|
export { createContractAdapter, type ContractAdapterOptions, type ContractModule } from "./contract-adapter.js";
|
|
20
20
|
export { loadCorpus, loadCase, kitIdentity, DEFAULT_CORPUS_DIR, PACKAGE_ROOT, type Corpus, type ConformanceCase, type CaseInput, type CaseMeta, type LegExpectationJson } from "./corpus.js";
|
|
21
|
+
export { PROFILE_CONFORMANCE_DIR, PROFILE_VECTORS_FORMAT, PROFILE_FROZEN_PROMISES_FORMAT, PROFILE_VECTOR_EXPECTS, BUILTIN_PROFILE_NAMES, loadProfileVectors, loadBuiltinProfilesAndSchema, type BuiltinProfileName, type ProfileVectorExpect, type ProfileVector, type ProfileVectorsDocument, type ProfileFrozenPromises, type ProfileVectorsData, type BuiltinProfilesAndSchema, } from "./profile.js";
|
|
21
22
|
export { DERIVATION_TRANSFORMS, LEG_EXPECTATION, NON_LOCAL_READ_DOMAINS, EPOCH_ISO, deriveWireInput, deriveLocalInput, deriveWireExpectation, deriveLocalExpectation, foreignKeysOf, toManifestDoc, type DerivationTransform, type LegExpectation, } from "./derive.js";
|
|
22
23
|
export { canonicalize, deepEqual, diffJson, stableKey, type JsonPatchOp } from "./canonical.js";
|
|
23
24
|
export { WARNING_KINDS, projectWarning, normalizeProjection, projectionKey, projectionValue, diffWarningMultiset, findSecretLeaks, type WarningKind, type WarningProjection, } from "./warnings.js";
|
|
@@ -19,6 +19,7 @@ export { runConformance, materializeLocalRoot, resolveLegExpectation } from "./r
|
|
|
19
19
|
export { runWebAdminCredentialLockConformance } from "./web-admin-credential-lock.js";
|
|
20
20
|
export { createContractAdapter } from "./contract-adapter.js";
|
|
21
21
|
export { loadCorpus, loadCase, kitIdentity, DEFAULT_CORPUS_DIR, PACKAGE_ROOT } from "./corpus.js";
|
|
22
|
+
export { PROFILE_CONFORMANCE_DIR, PROFILE_VECTORS_FORMAT, PROFILE_FROZEN_PROMISES_FORMAT, PROFILE_VECTOR_EXPECTS, BUILTIN_PROFILE_NAMES, loadProfileVectors, loadBuiltinProfilesAndSchema, } from "./profile.js";
|
|
22
23
|
export { DERIVATION_TRANSFORMS, LEG_EXPECTATION, NON_LOCAL_READ_DOMAINS, EPOCH_ISO, deriveWireInput, deriveLocalInput, deriveWireExpectation, deriveLocalExpectation, foreignKeysOf, toManifestDoc, } from "./derive.js";
|
|
23
24
|
export { canonicalize, deepEqual, diffJson, stableKey } from "./canonical.js";
|
|
24
25
|
export { WARNING_KINDS, projectWarning, normalizeProjection, projectionKey, projectionValue, diffWarningMultiset, findSecretLeaks, } from "./warnings.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Absolute path of the published `conformance/profile/` directory, so consumers can also read the prose files. */
|
|
2
|
+
export declare const PROFILE_CONFORMANCE_DIR: string;
|
|
3
|
+
/** Format string of the profile judgment-vectors document shipped by this package version. */
|
|
4
|
+
export declare const PROFILE_VECTORS_FORMAT: "sema-profile@1 judgment vectors v5";
|
|
5
|
+
/** Format string of the profile frozen-promises document shipped by this package version. */
|
|
6
|
+
export declare const PROFILE_FROZEN_PROMISES_FORMAT: "sema-profile@1 frozen promises v1";
|
|
7
|
+
/** Closed set of expected outcomes declared on every profile judgment vector. */
|
|
8
|
+
export declare const PROFILE_VECTOR_EXPECTS: readonly ["accept", "reject"];
|
|
9
|
+
/** Expected outcome of a profile judgment vector. */
|
|
10
|
+
export type ProfileVectorExpect = (typeof PROFILE_VECTOR_EXPECTS)[number];
|
|
11
|
+
/** Closed set of the four built-in configuration profile names shipped under `conformance/profile/profiles/`. */
|
|
12
|
+
export declare const BUILTIN_PROFILE_NAMES: readonly ["solo-auto", "solo-managed", "tenant-auto", "tenant-managed"];
|
|
13
|
+
/** Name of a built-in configuration profile shipped under `conformance/profile/profiles/`. */
|
|
14
|
+
export type BuiltinProfileName = (typeof BUILTIN_PROFILE_NAMES)[number];
|
|
15
|
+
/**
|
|
16
|
+
* One judgment vector from `conformance/profile/vectors/vectors.json`.
|
|
17
|
+
* Only the fields present on every vector in the document are typed; optional and rule-specific fields stay `unknown`.
|
|
18
|
+
*/
|
|
19
|
+
export interface ProfileVector {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly rule: string;
|
|
22
|
+
readonly expect: ProfileVectorExpect;
|
|
23
|
+
readonly judge: string;
|
|
24
|
+
readonly executedBy: readonly string[];
|
|
25
|
+
readonly [key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
/** Parsed `conformance/profile/vectors/vectors.json` document. */
|
|
28
|
+
export interface ProfileVectorsDocument {
|
|
29
|
+
readonly format: typeof PROFILE_VECTORS_FORMAT;
|
|
30
|
+
readonly vectors: readonly ProfileVector[];
|
|
31
|
+
readonly [key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** Parsed `conformance/profile/vectors/frozen-promises.json` document. */
|
|
34
|
+
export interface ProfileFrozenPromises {
|
|
35
|
+
readonly format: typeof PROFILE_FROZEN_PROMISES_FORMAT;
|
|
36
|
+
readonly builtins: Readonly<Record<string, unknown>>;
|
|
37
|
+
readonly channelDestinations: Readonly<Record<string, unknown>>;
|
|
38
|
+
readonly readBeforeFold: Readonly<Record<string, unknown>>;
|
|
39
|
+
readonly reportClosedSets: Readonly<Record<string, unknown>>;
|
|
40
|
+
readonly [key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** Parsed profile judgment vectors and frozen promises loaded from disk. */
|
|
43
|
+
export interface ProfileVectorsData {
|
|
44
|
+
readonly vectorsDocument: ProfileVectorsDocument;
|
|
45
|
+
readonly frozenPromises: ProfileFrozenPromises;
|
|
46
|
+
}
|
|
47
|
+
/** The four built-in profile JSON documents keyed by name, plus the profile JSON schema. */
|
|
48
|
+
export interface BuiltinProfilesAndSchema {
|
|
49
|
+
readonly profiles: Readonly<Record<BuiltinProfileName, Readonly<Record<string, unknown>>>>;
|
|
50
|
+
readonly schema: Readonly<Record<string, unknown>>;
|
|
51
|
+
}
|
|
52
|
+
/** Load and parse `vectors/vectors.json` and `vectors/frozen-promises.json` from the published profile conformance directory. */
|
|
53
|
+
export declare function loadProfileVectors(profileDir?: string): Promise<ProfileVectorsData>;
|
|
54
|
+
/** Load and parse the four built-in profiles (keyed by name) and `sema-profile.schema.json`. */
|
|
55
|
+
export declare function loadBuiltinProfilesAndSchema(profileDir?: string): Promise<BuiltinProfilesAndSchema>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration-profile loading/validation vectors published on the `./conformance` face.
|
|
3
|
+
*
|
|
4
|
+
* The published directory is `conformance/profile/` inside this package ({@link PROFILE_CONFORMANCE_DIR}).
|
|
5
|
+
* All reads are lazy (no filesystem I/O at import time), following the same root-resolution idiom as
|
|
6
|
+
* `DEFAULT_CORPUS_DIR`. `conformance/profile/tools/validate.mjs` ships as reference text only and is
|
|
7
|
+
* not executed by this module.
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { deepFreeze } from "../deep-freeze.js";
|
|
12
|
+
import { isJsonArray, isPlainJsonObject } from "../plain-json-object.js";
|
|
13
|
+
import { DEFAULT_CORPUS_DIR } from "./corpus.js";
|
|
14
|
+
/** Absolute path of the published `conformance/profile/` directory, so consumers can also read the prose files. */
|
|
15
|
+
export const PROFILE_CONFORMANCE_DIR = join(DEFAULT_CORPUS_DIR, "profile");
|
|
16
|
+
/** Format string of the profile judgment-vectors document shipped by this package version. */
|
|
17
|
+
export const PROFILE_VECTORS_FORMAT = "sema-profile@1 judgment vectors v5";
|
|
18
|
+
/** Format string of the profile frozen-promises document shipped by this package version. */
|
|
19
|
+
export const PROFILE_FROZEN_PROMISES_FORMAT = "sema-profile@1 frozen promises v1";
|
|
20
|
+
/** Closed set of expected outcomes declared on every profile judgment vector. */
|
|
21
|
+
export const PROFILE_VECTOR_EXPECTS = deepFreeze(["accept", "reject"]);
|
|
22
|
+
/** Closed set of the four built-in configuration profile names shipped under `conformance/profile/profiles/`. */
|
|
23
|
+
export const BUILTIN_PROFILE_NAMES = deepFreeze(["solo-auto", "solo-managed", "tenant-auto", "tenant-managed"]);
|
|
24
|
+
async function readJson(filePath) {
|
|
25
|
+
return JSON.parse(await readFile(filePath, "utf8"));
|
|
26
|
+
}
|
|
27
|
+
function formatFoundValue(value) {
|
|
28
|
+
return value === undefined ? "undefined" : JSON.stringify(value);
|
|
29
|
+
}
|
|
30
|
+
function requirePlainObject(value, where) {
|
|
31
|
+
if (!isPlainJsonObject(value))
|
|
32
|
+
throw new Error(`conformance profile: ${where} must be a JSON object`);
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function requireNonEmptyString(value, where) {
|
|
36
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
37
|
+
throw new Error(`conformance profile: ${where} must be a non-empty string`);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function requireExactFormat(value, file, supported) {
|
|
42
|
+
if (value !== supported) {
|
|
43
|
+
throw new Error(`conformance profile: ${file}#format is ${formatFoundValue(value)}, supported format is ${JSON.stringify(supported)}`);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function requireVectorExpect(value, where) {
|
|
48
|
+
if (typeof value !== "string" || !PROFILE_VECTOR_EXPECTS.includes(value)) {
|
|
49
|
+
throw new Error(`conformance profile: ${where} must be one of ${PROFILE_VECTOR_EXPECTS.join(" | ")}, found ${formatFoundValue(value)}`);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function checkProfileVector(value, index) {
|
|
54
|
+
const row = requirePlainObject(value, `vectors/vectors.json#vectors[${index}]`);
|
|
55
|
+
requireNonEmptyString(row.id, `vectors[${index}].id`);
|
|
56
|
+
requireNonEmptyString(row.rule, `vectors[${index}].rule`);
|
|
57
|
+
requireVectorExpect(row.expect, `vectors[${index}].expect`);
|
|
58
|
+
requireNonEmptyString(row.judge, `vectors[${index}].judge`);
|
|
59
|
+
if (!isJsonArray(row.executedBy) ||
|
|
60
|
+
row.executedBy.length === 0 ||
|
|
61
|
+
!row.executedBy.every((entry) => typeof entry === "string" && entry.length > 0)) {
|
|
62
|
+
throw new Error(`conformance profile: vectors[${index}].executedBy must be a non-empty array of non-empty strings`);
|
|
63
|
+
}
|
|
64
|
+
return row;
|
|
65
|
+
}
|
|
66
|
+
/** Load and parse `vectors/vectors.json` and `vectors/frozen-promises.json` from the published profile conformance directory. */
|
|
67
|
+
export async function loadProfileVectors(profileDir = PROFILE_CONFORMANCE_DIR) {
|
|
68
|
+
const [vectorsRaw, frozenRaw] = await Promise.all([
|
|
69
|
+
readJson(join(profileDir, "vectors", "vectors.json")),
|
|
70
|
+
readJson(join(profileDir, "vectors", "frozen-promises.json")),
|
|
71
|
+
]);
|
|
72
|
+
const vectorsObj = requirePlainObject(vectorsRaw, "vectors/vectors.json");
|
|
73
|
+
const vectorsFormat = requireExactFormat(vectorsObj.format, "vectors/vectors.json", PROFILE_VECTORS_FORMAT);
|
|
74
|
+
if (!isJsonArray(vectorsObj.vectors) || vectorsObj.vectors.length === 0) {
|
|
75
|
+
throw new Error("conformance profile: vectors/vectors.json#vectors must be a non-empty array");
|
|
76
|
+
}
|
|
77
|
+
const vectors = vectorsObj.vectors.map((entry, idx) => checkProfileVector(entry, idx));
|
|
78
|
+
const frozenObj = requirePlainObject(frozenRaw, "vectors/frozen-promises.json");
|
|
79
|
+
const frozenFormat = requireExactFormat(frozenObj.format, "vectors/frozen-promises.json", PROFILE_FROZEN_PROMISES_FORMAT);
|
|
80
|
+
const builtins = requirePlainObject(frozenObj.builtins, "vectors/frozen-promises.json#builtins");
|
|
81
|
+
const channelDestinations = requirePlainObject(frozenObj.channelDestinations, "vectors/frozen-promises.json#channelDestinations");
|
|
82
|
+
const readBeforeFold = requirePlainObject(frozenObj.readBeforeFold, "vectors/frozen-promises.json#readBeforeFold");
|
|
83
|
+
const reportClosedSets = requirePlainObject(frozenObj.reportClosedSets, "vectors/frozen-promises.json#reportClosedSets");
|
|
84
|
+
return {
|
|
85
|
+
vectorsDocument: { ...vectorsObj, format: vectorsFormat, vectors },
|
|
86
|
+
frozenPromises: {
|
|
87
|
+
...frozenObj,
|
|
88
|
+
format: frozenFormat,
|
|
89
|
+
builtins,
|
|
90
|
+
channelDestinations,
|
|
91
|
+
readBeforeFold,
|
|
92
|
+
reportClosedSets,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Load and parse the four built-in profiles (keyed by name) and `sema-profile.schema.json`. */
|
|
97
|
+
export async function loadBuiltinProfilesAndSchema(profileDir = PROFILE_CONFORMANCE_DIR) {
|
|
98
|
+
const [profileEntries, schemaRaw] = await Promise.all([
|
|
99
|
+
Promise.all(BUILTIN_PROFILE_NAMES.map(async (name) => {
|
|
100
|
+
const parsed = requirePlainObject(await readJson(join(profileDir, "profiles", `${name}.json`)), `profiles/${name}.json`);
|
|
101
|
+
return [name, parsed];
|
|
102
|
+
})),
|
|
103
|
+
readJson(join(profileDir, "sema-profile.schema.json")),
|
|
104
|
+
]);
|
|
105
|
+
const schema = requirePlainObject(schemaRaw, "sema-profile.schema.json");
|
|
106
|
+
const profiles = Object.fromEntries(profileEntries);
|
|
107
|
+
return { profiles, schema };
|
|
108
|
+
}
|