forked from cflmy/deepseek-harness
fix(cordis): address loader rc.9 review and CI findings
This commit is contained in:
1 parent
dd892782af
commit
a85b27fdd4
16 files changed
+123
-107
No files matched your search
@@ -259,6 +259,8 @@ export default defineConfig({
|
||||
// internal slot the shell boot fills with the client module loader).
|
||||
'process.versions.node': '"0.0.0"',
|
||||
'process.execArgv': '[]',
|
||||
// vendored loader tree.ts: import() converts drive-letter names only on win32.
|
||||
'process.platform': '"browser"',
|
||||
// vendored loader index.ts: envData falls to its default branch.
|
||||
'process.env.CORDIS_SHARED': 'undefined',
|
||||
},
|
||||
|
||||
+7
-7
@@ -1,16 +1,16 @@
|
||||
# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading
|
||||
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
||||
# After editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.2/cordis-loader-entry-validation/guide.md
|
||||
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.3/cordis-loader-entry-validation/guide.md
|
||||
/:
|
||||
en: b414093b29c38765
|
||||
zh: 2a69f37a40e35a99
|
||||
/loader-validates-entry-options-and-include-parses-yaml-1-2:
|
||||
en: 0ba0b666924ce1f0
|
||||
zh: 0c5668ee67163d00
|
||||
en: cf5dc11adadfd1e1
|
||||
zh: 4656ed9a0d4e9087
|
||||
/loader-validates-entry-options-and-include-parses-yaml-1-2/change:
|
||||
en: b0d2ae6a748cab50
|
||||
zh: a2521c4dc48e4d3d
|
||||
en: b345762ab470b57b
|
||||
zh: 0f931faf28da0d27
|
||||
/loader-validates-entry-options-and-include-parses-yaml-1-2/migration:
|
||||
en: 2c167e1042c952a5
|
||||
zh: aec49a7754befae0
|
||||
en: ff01b0eddb91d5b1
|
||||
zh: 81478d5e1594db65
|
||||
+2
-2
@@ -12,7 +12,7 @@ English | [中文](guide.zh.md)
|
||||
`@deepseek-ai/cordis-plugin-loader` now carries upstream Loader 1.0.0-rc.9, and `@deepseek-ai/cordis-plugin-include` carries Include 1.2.0. Hand-written `cordis.yml`, `cordis.patch.yml` and overlay files, and code that calls the Include or Loader exports, are affected:
|
||||
|
||||
- Include and `parseEntryYaml` parse YAML 1.2 under the core schema instead of the js-yaml JSON schema. A binary integer such as `0b101` now reads as the string `'0b101'`. An empty `!!js` scalar now reads as an empty expression, which evaluates to `undefined`, instead of failing to parse.
|
||||
- Entry options are validated before an entry is created or updated. `name` must be a string; `group` a boolean; `disabled` a boolean or `!!js` expression; a group's `config` a list; `inject` a string list or a mapping; `isolate` a mapping whose values are `true` or a string. An entry that loaded before with such a value is now rejected and logged, and its siblings still start. An Include file with an entry that is not a mapping is rejected as a whole. Ids containing `:` remain accepted.
|
||||
- Entry options are validated before an entry is created or updated. `name` must be a string; `group` a boolean; `disabled` a boolean or `!!js` expression; an entry with `group: true` must have a `config` list, even an empty one; `inject` a string list or a mapping; `isolate` a mapping whose values are `true` or a string. An entry that loaded before with such a value is now rejected and logged, and its siblings still start. An Include file with an entry that is not a mapping is rejected as a whole. Ids containing `:` remain accepted.
|
||||
- Parse, entry option and config validation errors name the file position as `file:line:column`. When an entry's own module cannot be found, the error is a `ModuleNotFoundError` without Node's `imported from` part; its `code` is still `ERR_MODULE_NOT_FOUND`.
|
||||
- A patch that replaces a group's `config` brings child entries that later patches can address, and the children it replaces can no longer be patched.
|
||||
- `applyEntryPatches(data, patches, warn)` returns `{ data, index }` instead of the entry list, and writes generated ids into the anonymous entries of a replaced group `config` in `patches`. `parseEntryYaml` throws the `YAMLError` of the `yaml` package instead of a js-yaml `YAMLException`.
|
||||
@@ -21,7 +21,7 @@ English | [中文](guide.zh.md)
|
||||
|
||||
1. Write binary integers that must stay numbers in decimal or hexadecimal.
|
||||
2. Run `dsh --dump-config` for each profile. A parse error now names its line and column; fix the reported value.
|
||||
3. Start the profile and check the log for `invalid entry options` and `invalid config`. Correct each listed path at the position shown.
|
||||
3. Add `config: []` to every `group: true` entry without `config`, such as a group whose children all come from patch `insert`. Start the profile and check the log for `invalid entry options` and `invalid config`. Correct each listed path at the position shown.
|
||||
4. Where a later patch addressed a child of a group whose `config` an earlier patch replaced, check that the child now receives the patch.
|
||||
5. In code, read `applyEntryPatches(...).data`, and pass `structuredClone(patches)` where the patch list must stay unchanged. Catch parse errors without depending on js-yaml types; `entryYamlErrorPosition(error)` still returns the position.
|
||||
6. Confirm that `dsh --dump-config` prints the expected entries and that the profile starts without those diagnostics.
|
||||
+2
-2
@@ -12,7 +12,7 @@ description: "Cordis Loader 1.0.0-rc.9 与 Include 1.2.0 按 YAML 1.2 解析、
|
||||
`@deepseek-ai/cordis-plugin-loader` 现在包含上游 Loader 1.0.0-rc.9,`@deepseek-ai/cordis-plugin-include` 包含 Include 1.2.0。受影响的是手写的 `cordis.yml`、`cordis.patch.yml` 与 overlay 文件,以及调用 Include 或 Loader 导出的代码:
|
||||
|
||||
- Include 和 `parseEntryYaml` 按 YAML 1.2 core schema 解析,不再使用 js-yaml 的 JSON schema。`0b101` 这样的二进制整数现在读作字符串 `'0b101'`。空的 `!!js` 标量现在读作空表达式,求值结果为 `undefined`,不再解析失败。
|
||||
- 创建或更新条目前会校验条目选项。`name` 必须是字符串;`group` 必须是布尔值;`disabled` 必须是布尔值或 `!!js` 表达式;group 的 `config` 必须是列表;`inject` 必须是字符串列表或映射;`isolate` 必须是映射,其值为 `true` 或字符串。此前能加载但含有这类值的条目现在会被拒绝并记录日志,同级条目仍会启动。Include 文件中只要有一个条目不是映射,整个文件都会被拒绝。含 `:` 的 id 仍然可以使用。
|
||||
- 创建或更新条目前会校验条目选项。`name` 必须是字符串;`group` 必须是布尔值;`disabled` 必须是布尔值或 `!!js` 表达式;`group: true` 的条目必须带有 `config` 列表,空列表也要写出;`inject` 必须是字符串列表或映射;`isolate` 必须是映射,其值为 `true` 或字符串。此前能加载但含有这类值的条目现在会被拒绝并记录日志,同级条目仍会启动。Include 文件中只要有一个条目不是映射,整个文件都会被拒绝。含 `:` 的 id 仍然可以使用。
|
||||
- 解析错误、条目选项错误和配置校验错误都会以 `file:line:column` 指出文件位置。条目自身的模块找不到时,错误为 `ModuleNotFoundError`,不含 Node 的 `imported from` 部分;其 `code` 仍为 `ERR_MODULE_NOT_FOUND`。
|
||||
- 替换 group `config` 的 patch 带来的子条目可以被后续 patch 定位,被替换掉的子条目则不能再被 patch。
|
||||
- `applyEntryPatches(data, patches, warn)` 返回 `{ data, index }`,不再直接返回条目列表;它会把生成的 id 写入 `patches` 中被替换的 group `config` 里的匿名条目。`parseEntryYaml` 抛出 `yaml` 包的 `YAMLError`,不再抛出 js-yaml 的 `YAMLException`。
|
||||
@@ -21,7 +21,7 @@ description: "Cordis Loader 1.0.0-rc.9 与 Include 1.2.0 按 YAML 1.2 解析、
|
||||
|
||||
1. 必须保持为数字的二进制整数改写为十进制或十六进制。
|
||||
2. 对每个 profile 运行 `dsh --dump-config`。解析错误现在会给出行号和列号;按提示修正对应的值。
|
||||
3. 启动 profile,检查日志中的 `invalid entry options` 和 `invalid config`,在给出的位置修正列出的每个路径。
|
||||
3. 给每个缺少 `config` 的 `group: true` 条目加上 `config: []`,例如子条目全部来自 patch `insert` 的 group。启动 profile,检查日志中的 `invalid entry options` 和 `invalid config`,在给出的位置修正列出的每个路径。
|
||||
4. 如果后续 patch 针对的是某个 group 的子条目,而该 group 的 `config` 已被前面的 patch 替换,确认该子条目现在会应用这个 patch。
|
||||
5. 在代码中读取 `applyEntryPatches(...).data`;如果 patch 列表必须保持不变,传入 `structuredClone(patches)`。捕获解析错误时不要依赖 js-yaml 的类型;`entryYamlErrorPosition(error)` 仍会返回错误位置。
|
||||
6. 确认 `dsh --dump-config` 输出预期的条目,且 profile 启动时不再出现上述诊断。
|
||||
@@ -165,7 +165,7 @@ export async function collectConfigSchemas(
|
||||
if (hasNonRecordEntry(rows)) throw new Error(`include ${filename} has an entry that is not a mapping; child declarations are unavailable`)
|
||||
let children: EntryOptions[]
|
||||
try {
|
||||
children = applyEntryPatches(rows as EntryOptions[], patches, warn(path)).data
|
||||
children = applyEntryPatches(rows as EntryOptions[], structuredClone(patches), warn(path)).data
|
||||
} catch (error) {
|
||||
throw new Error(`include patches could not be composed for ${filename}; child declarations are unavailable`, { cause: error })
|
||||
}
|
||||
|
||||
@@ -670,12 +670,15 @@ export function renderConfigDump(
|
||||
const base = parsed as Parameters<typeof applyEntryPatches>[0]
|
||||
// snapshot_k = ONE application of layers 1..k flattened, using the exact
|
||||
// arguments boot passes for that prefix. snapshot_N is the mounted composition.
|
||||
// The patches are cloned per call: applyEntryPatches clones entries and
|
||||
// inserted rows but assigns override values such as `config` by reference,
|
||||
// so each snapshot keeps its own copies of those values.
|
||||
// Every snapshot reads one clone of the patches: applyEntryPatches writes the
|
||||
// ids it generates for anonymous children of a replaced group config into
|
||||
// that clone, so each prefix assigns them the same ids. The snapshots share
|
||||
// override values by reference and only read them.
|
||||
const patches = structuredClone(layers.flatMap(layer => layer.patches))
|
||||
const ends: number[] = []
|
||||
for (const layer of layers) ends.push((ends.at(-1) ?? 0) + layer.patches.length)
|
||||
const snapshot = (count: number, warnings: string[]): ReturnType<typeof applyEntryPatches>['data'] => {
|
||||
const flattened = structuredClone(layers.slice(0, count).flatMap(layer => layer.patches))
|
||||
return applyEntryPatches(base, flattened, (message: string, ...args: unknown[]) => {
|
||||
return applyEntryPatches(base, patches.slice(0, ends[count - 1]), (message: string, ...args: unknown[]) => {
|
||||
// The include logs through cordis's printf-style logger (`%C` = code); a
|
||||
// dump has no logger, so substitute inline for a plain line.
|
||||
let index = 0
|
||||
|
||||
@@ -143,6 +143,20 @@ describe('renderConfigDump', () => {
|
||||
expect(dump).toContain('# == base.yml, patched by a.yml, b.yml\n- id: g')
|
||||
})
|
||||
|
||||
it('keeps generated ids of anonymous replaced group children across layers', () => {
|
||||
const dir = tmp()
|
||||
const base = join(dir, 'base.yml')
|
||||
writeFileSync(base, '- id: g\n name: ./group.mjs\n group: true\n config: []\n- id: other\n name: ./noop.mjs\n')
|
||||
const patches = [{ id: 'g', config: [{ name: './noop.mjs' }] }]
|
||||
const dump = renderConfigDump(NAME, base, [
|
||||
{ label: 'a.yml', patches },
|
||||
{ label: 'b.yml', patches: [{ id: 'other', disabled: true }] },
|
||||
], () => {})
|
||||
expect(dump).toContain('# == base.yml, patched by a.yml\n- id: g')
|
||||
expect(dump).toContain('# == base.yml, patched by b.yml\n- id: other')
|
||||
expect(patches).toEqual([{ id: 'g', config: [{ name: './noop.mjs' }] }])
|
||||
})
|
||||
|
||||
it('drops the children of a replaced group config from the patch index', () => {
|
||||
const dir = tmp()
|
||||
const base = join(dir, 'base.yml')
|
||||
|
||||
@@ -445,6 +445,14 @@ describe('collectConfigSchemas', () => {
|
||||
expect(result['x-cordis'].complete).toBe(false)
|
||||
})
|
||||
|
||||
it('leaves the caller\'s include patches unchanged when a patch replaces a group config', async () => {
|
||||
const patches = [{ id: 'group', config: [{ name: 'noop' }] }]
|
||||
await collectConfigSchemas(profile, [row('cordis:include', {
|
||||
path: './missing.yml', initial: [{ ...row('cordis:group', []), id: 'group', group: true }], patches,
|
||||
})], resolution)
|
||||
expect(patches).toEqual([{ id: 'group', config: [{ name: 'noop' }] }])
|
||||
})
|
||||
|
||||
it('does not validate contents of an insertion that Loader skips', async () => {
|
||||
const result = await collectConfigSchemas(profile, [row('cordis:include', {
|
||||
path: './missing.yml', initial: [row('noop')], patches: [{ id: 'missing', insert: [null] }, { config: {} }],
|
||||
|
||||
Generated
+4
-65
@@ -18627,7 +18627,7 @@ importers:
|
||||
version: 16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
vitest:
|
||||
specifier: ^4.1.11
|
||||
version: 4.1.11(@opentelemetry/api@1.9.1)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.11)(happy-dom@20.11.6)(jsdom@29.1.1(@noble/hashes@2.4.0))(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1))
|
||||
version: 4.1.11(@opentelemetry/api@1.9.1)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.11)(happy-dom@20.11.6)(jsdom@29.1.1(@noble/hashes@2.4.0))(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.0))
|
||||
devDependencies:
|
||||
'@deepseek-ai/cordis':
|
||||
specifier: workspace:~
|
||||
@@ -18847,7 +18847,7 @@ importers:
|
||||
version: 4.3.2
|
||||
vitest:
|
||||
specifier: ^4.1.11
|
||||
version: 4.1.11(@opentelemetry/api@1.9.1)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.11)(happy-dom@20.11.6)(jsdom@29.1.1(@noble/hashes@2.4.0))(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1))
|
||||
version: 4.1.11(@opentelemetry/api@1.9.1)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.11)(happy-dom@20.11.6)(jsdom@29.1.1(@noble/hashes@2.4.0))(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.0))
|
||||
devDependencies:
|
||||
'@deepseek-ai/cordis':
|
||||
specifier: workspace:~
|
||||
@@ -20212,8 +20212,8 @@ importers:
|
||||
specifier: link:../cosmokit
|
||||
version: link:../cosmokit
|
||||
yaml:
|
||||
specifier: ^2.9.1
|
||||
version: 2.9.1
|
||||
specifier: ^2.9.0
|
||||
version: 2.9.0
|
||||
|
||||
vendor/loader:
|
||||
dependencies:
|
||||
@@ -27960,11 +27960,6 @@ packages:
|
||||
engines: {node: '>= 14.6'}
|
||||
hasBin: true
|
||||
|
||||
yaml@2.9.1:
|
||||
resolution: {integrity: sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==}
|
||||
engines: {node: '>= 14.6'}
|
||||
hasBin: true
|
||||
|
||||
yargs-parser@20.2.9:
|
||||
resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -30970,14 +30965,6 @@ snapshots:
|
||||
optionalDependencies:
|
||||
vite: 8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.0)
|
||||
|
||||
'@vitest/mocker@4.1.11(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1))':
|
||||
dependencies:
|
||||
'@vitest/spy': 4.1.11
|
||||
estree-walker: 3.0.3
|
||||
magic-string: 0.30.21
|
||||
optionalDependencies:
|
||||
vite: 8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1)
|
||||
|
||||
'@vitest/pretty-format@4.1.11':
|
||||
dependencies:
|
||||
tinyrainbow: 3.1.0
|
||||
@@ -35729,21 +35716,6 @@ snapshots:
|
||||
tsx: 4.23.13
|
||||
yaml: 2.9.0
|
||||
|
||||
vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1):
|
||||
dependencies:
|
||||
lightningcss: 1.33.0
|
||||
picomatch: 4.0.7
|
||||
postcss: 8.5.28
|
||||
rolldown: 1.2.7
|
||||
tinyglobby: 0.2.17
|
||||
optionalDependencies:
|
||||
'@types/node': 22.20.1
|
||||
esbuild: 0.28.2
|
||||
fsevents: 2.3.3
|
||||
jiti: 2.7.0
|
||||
tsx: 4.23.13
|
||||
yaml: 2.9.1
|
||||
|
||||
vitepress-plugin-mermaid@2.0.17(mermaid@11.17.2)(vitepress@1.6.4(@algolia/client-search@5.55.2)(@types/node@22.20.1)(@types/react@18.3.31)(lightningcss@1.33.0)(postcss@8.5.28)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(search-insights@2.17.3)(typescript@6.0.3)):
|
||||
dependencies:
|
||||
mermaid: 11.17.2
|
||||
@@ -35863,37 +35835,6 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- msw
|
||||
|
||||
vitest@4.1.11(@opentelemetry/api@1.9.1)(@types/node@22.20.1)(@vitest/coverage-v8@4.1.11)(happy-dom@20.11.6)(jsdom@29.1.1(@noble/hashes@2.4.0))(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1)):
|
||||
dependencies:
|
||||
'@vitest/expect': 4.1.11
|
||||
'@vitest/mocker': 4.1.11(vite@8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1))
|
||||
'@vitest/pretty-format': 4.1.11
|
||||
'@vitest/runner': 4.1.11
|
||||
'@vitest/snapshot': 4.1.11
|
||||
'@vitest/spy': 4.1.11
|
||||
'@vitest/utils': 4.1.11
|
||||
es-module-lexer: 2.1.0
|
||||
expect-type: 1.3.0
|
||||
magic-string: 0.30.21
|
||||
obug: 2.1.3
|
||||
pathe: 2.0.3
|
||||
picomatch: 4.0.7
|
||||
std-env: 4.1.0
|
||||
tinybench: 2.9.0
|
||||
tinyexec: 1.2.4
|
||||
tinyglobby: 0.2.17
|
||||
tinyrainbow: 3.1.0
|
||||
vite: 8.2.2(@types/node@22.20.1)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1)
|
||||
why-is-node-running: 2.3.0
|
||||
optionalDependencies:
|
||||
'@opentelemetry/api': 1.9.1
|
||||
'@types/node': 22.20.1
|
||||
'@vitest/coverage-v8': 4.1.11(vitest@4.1.11)
|
||||
happy-dom: 20.11.6
|
||||
jsdom: 29.1.1(@noble/hashes@2.4.0)
|
||||
transitivePeerDependencies:
|
||||
- msw
|
||||
|
||||
vscode-jsonrpc@5.0.1: {}
|
||||
|
||||
vscode-jsonrpc@9.0.1: {}
|
||||
@@ -36022,8 +35963,6 @@ snapshots:
|
||||
|
||||
yaml@2.9.0: {}
|
||||
|
||||
yaml@2.9.1: {}
|
||||
|
||||
yargs-parser@20.2.9: {}
|
||||
|
||||
yargs-parser@21.1.1: {}
|
||||
|
||||
@@ -39,5 +39,12 @@ describe('Include YAML dialect', () => {
|
||||
}
|
||||
expect(entryYamlErrorPosition(error)).toEqual({ line: 3, column: 1 })
|
||||
expect(entryYamlErrorPosition(new Error('other'))).toBeUndefined()
|
||||
let alias: unknown
|
||||
try {
|
||||
parseEntryYaml('- id: a\n config: *missing\n')
|
||||
} catch (caught) {
|
||||
alias = caught
|
||||
}
|
||||
expect(entryYamlErrorPosition(alias)).toEqual({ line: 2, column: 11 })
|
||||
})
|
||||
})
|
||||
@@ -13,21 +13,16 @@ const Typed = Object.assign((_ctx: Context, _config: { value: number }) => {}, {
|
||||
Config: Schema.object({ value: Schema.number().required() }),
|
||||
})
|
||||
|
||||
async function fixture(filename: string, content: string) {
|
||||
// `rows.yml` is the file the root Include reads; other files are reachable through nested includes.
|
||||
async function fixture(files: Record<string, string>) {
|
||||
const dir = await mkdtemp(join(tmpdir(), 'dsh-loader-rc9-'))
|
||||
const pathOf = (name: string) => join(dir, name)
|
||||
for (const [name, content] of Object.entries(files)) await writeFile(pathOf(name), content)
|
||||
const ctx = new Context()
|
||||
onTestFinished(async () => {
|
||||
await ctx.fiber.dispose()
|
||||
await rm(dir, { recursive: true, force: true, maxRetries: 3 })
|
||||
})
|
||||
ctx.baseUrl = pathToFileURL(dir).href + '/'
|
||||
await ctx.plugin(Loader)
|
||||
ctx.loader.builtins.include = Include
|
||||
ctx.loader.builtins.group = Group
|
||||
ctx.loader.builtins.example = () => {}
|
||||
ctx.loader.builtins.typed = Typed
|
||||
const path = join(dir, filename)
|
||||
await writeFile(path, content)
|
||||
const errors: unknown[] = []
|
||||
const warnings: unknown[] = []
|
||||
ctx.logger.exporter({
|
||||
@@ -36,10 +31,13 @@ async function fixture(filename: string, content: string) {
|
||||
if (type === 'warn') warnings.push(...args)
|
||||
},
|
||||
})
|
||||
const id = await ctx.loader.create({ name: 'cordis:include', config: { path: `./${filename}` } })
|
||||
ctx.baseUrl = pathToFileURL(dir).href + '/'
|
||||
await ctx.plugin(Loader)
|
||||
Object.assign(ctx.loader.builtins, { include: Include, group: Group, example: () => {}, typed: Typed })
|
||||
const id = await ctx.loader.create({ name: 'cordis:include', config: { path: './rows.yml' } })
|
||||
await ctx.loader.await()
|
||||
const entry = ctx.loader.resolve(id)
|
||||
return { ctx, path, entry, include: entry.subtree as Include | undefined, errors, warnings }
|
||||
return { ctx, path: pathOf('rows.yml'), pathOf, entry, include: entry.subtree as Include | undefined, errors, warnings }
|
||||
}
|
||||
|
||||
describe('Loader 1.0.0-rc.9 entry options', () => {
|
||||
@@ -63,14 +61,14 @@ describe('Loader 1.0.0-rc.9 entry options', () => {
|
||||
})
|
||||
|
||||
it('accepts explicit ids containing the separator from a file', async () => {
|
||||
const app = await fixture('rows.yml', '- id: pkg:row\n name: cordis:example\n')
|
||||
const app = await fixture({ 'rows.yml': '- id: pkg:row\n name: cordis:example\n' })
|
||||
expect(app.include!.store['pkg:row']!.fiber!.state).toBe(FiberState.ACTIVE)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Include 1.2.0 config files', () => {
|
||||
it('reports invalid entries and config values at their file positions', async () => {
|
||||
const app = await fixture('rows.yml', [
|
||||
const app = await fixture({ 'rows.yml': [
|
||||
'- id: bad',
|
||||
' name: cordis:example',
|
||||
' disabled: 1',
|
||||
@@ -79,7 +77,7 @@ describe('Include 1.2.0 config files', () => {
|
||||
' config:',
|
||||
' value: text',
|
||||
'',
|
||||
].join('\n'))
|
||||
].join('\n') })
|
||||
const messages = app.errors.map(String).join('\n')
|
||||
expect(messages).toContain(`disabled must be a boolean (at disabled, ${app.path}:3:13)`)
|
||||
expect(messages).toContain(`${app.path}:7:12`)
|
||||
@@ -88,14 +86,14 @@ describe('Include 1.2.0 config files', () => {
|
||||
})
|
||||
|
||||
it('reports an unknown plugin module at its name position', async () => {
|
||||
const app = await fixture('rows.yml', '- id: missing\n name: ./missing-plugin.js\n')
|
||||
const app = await fixture({ 'rows.yml': '- id: missing\n name: ./missing-plugin.js\n' })
|
||||
const error = app.errors.find(error => error instanceof ModuleNotFoundError)
|
||||
expect(error?.specifier).toBe('./missing-plugin.js')
|
||||
expect(error?.message).toContain(`(at name, ${app.path}:2:9)`)
|
||||
})
|
||||
|
||||
it('parses YAML 1.2 core scalars and locates syntax errors', async () => {
|
||||
const app = await fixture('rows.yml', '- id: typed\n name: cordis:typed\n config:\n value: 0x10\n')
|
||||
const app = await fixture({ 'rows.yml': '- id: typed\n name: cordis:typed\n config:\n value: 0x10\n' })
|
||||
expect(app.include!.store['typed']!.fiber!.effectiveConfig).toEqual({ value: 16 })
|
||||
await writeFile(app.path, '- id: typed\n name: [\n')
|
||||
await app.include!.refresh()
|
||||
@@ -103,4 +101,29 @@ describe('Include 1.2.0 config files', () => {
|
||||
expect(error).toBeInstanceOf(ConfigFileError)
|
||||
expect((error as ConfigFileError).issues[0]!.location).toMatchObject({ filename: app.path, line: 3 })
|
||||
})
|
||||
|
||||
it('rejects a file with a non-mapping entry at its position', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: ok\n name: cordis:example\n- id: g\n name: cordis:group\n group: true\n config:\n - plain\n' })
|
||||
const error = app.errors.find(error => error instanceof ConfigFileError)
|
||||
expect(error?.issues).toEqual([{ message: 'entry must be an object', location: { filename: app.path, line: 7, column: 7 } }])
|
||||
expect(app.entry.fiber!.state).not.toBe(FiberState.ACTIVE)
|
||||
})
|
||||
|
||||
it('locates an unresolved alias as a parse error', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: typed\n name: cordis:typed\n config: *missing\n' })
|
||||
const error = app.errors.find(error => error instanceof ConfigFileError)
|
||||
expect(error?.stage).toBe('parse')
|
||||
expect(error?.issues[0]!.location).toEqual({ filename: app.path, line: 3, column: 11 })
|
||||
})
|
||||
|
||||
it.each([
|
||||
['an override', ' patches:\n - id: typed\n config:\n value: text\n', '- id: typed\n name: cordis:typed\n config:\n value: 1\n', 8],
|
||||
['an inserted entry', ' patches:\n - insert:\n - id: typed\n name: cordis:typed\n config:\n value: text\n', '[]\n', 10],
|
||||
])('locates a config value supplied by %s in the parent file', async (_kind, patches, inner, line) => {
|
||||
const app = await fixture({
|
||||
'rows.yml': `- id: inner\n name: cordis:include\n config:\n path: ./inner.yml\n${patches}`,
|
||||
'inner.yml': inner,
|
||||
})
|
||||
expect(app.errors.map(String).join('\n')).toContain(`(at value, ${app.path}:${String(line)}:`)
|
||||
})
|
||||
})
|
||||
Vendored
+3
-2
@@ -26,10 +26,10 @@ Intentionally **not** vendored (verified unused by this set): `reggol`, `@cordis
|
||||
|
||||
## Local modifications
|
||||
|
||||
Keep this log exhaustive — every divergence from upstream must be listed. Each entry has a stable ID: remove an entry when its divergence no longer exists, and never renumber or reuse IDs. The next new entry is V29.
|
||||
Keep this log exhaustive — every divergence from upstream must be listed. Each entry has a stable ID: remove an entry when its divergence no longer exists, and never renumber or reuse IDs. The next new entry is V30.
|
||||
|
||||
- **V1 · `hmr/src/index.ts`**: removed the `./locales/en-US.yml` / `./locales/zh-CN.yml` imports, the `.i18n({...})` call on the `Config` schema, and the `src/locales/` directory. Rationale: those imports require a runtime YAML loader hook (`@cordisjs/unyaml`) that we do not vendor; the i18n texts only localize config descriptions.
|
||||
- **V2 · All `package.json` files**: regenerated for Harness releases with scoped names, release versions, publication metadata, precise bundled-runtime and `lib/types/**/*.d.ts` / `.d.ts.map` file entries, source exports where applicable, and declaration metadata pointing at `lib/types`. References within the vendored set use `workspace:~`. HMR declares `esbuild` as a direct dev dependency for its imported `BuildFailure` type, and Loader requires `node-addon-require-builtin@^0.1.4` to match published app runtimes.
|
||||
- **V2 · All `package.json` files**: regenerated for Harness releases with scoped names, release versions, publication metadata, precise bundled-runtime and `lib/types/**/*.d.ts` / `.d.ts.map` file entries, source exports where applicable, and declaration metadata pointing at `lib/types`. References within the vendored set use `workspace:~`. HMR declares `esbuild` as a direct dev dependency for its imported `BuildFailure` type, Loader requires `node-addon-require-builtin@^0.1.4` to match published app runtimes, and Include declares `yaml@^2.9.0` instead of upstream's `^2.9.1` so the workspace installs one copy of `yaml`.
|
||||
- **V3 · All `tsconfig.json` files**: regenerated to extend the repo-root `tsconfig.base.json`, emit TypeScript intermediates to `lib/types`, and declare project references.
|
||||
- **V4 · Vendored TypeScript source internal specifiers**: changed local relative imports/exports from upstream's specifier shape to explicit `.ts` specifiers so TypeScript rewrites emitted JS to `.js` while declarations keep explicit, NodeNext-safe `.ts` specifiers. This includes `loader/src/config/isolate.ts` using `declare module './entry.ts'`. Core's upstream source already uses explicit `.ts` specifiers. Type-only dependencies use `import type` or inline `type` modifiers so ESM output does not retain erased interfaces.
|
||||
- **V5 · `schemastery/tsdown.config.ts` and `logger-console/tsdown.config.ts`**: ours, not upstream files — per-package build-shape overrides (dual ESM+CJS output; separate node/browser entries) for the repo-root tsdown build. They read the JS emitted under `lib/types` and then write the publish runtime entries under `lib/`. Like the regenerated tsconfigs, they are not part of the upstream sync surface.
|
||||
@@ -48,6 +48,7 @@ Keep this log exhaustive — every divergence from upstream must be listed. Each
|
||||
- **V25 · Loader lifecycle adaptations**: before a combined context/config update, Loader refreshes dependencies locally, which prevents activation against stale isolation bindings; disabled-entry updates await disposal. Failed fibers require an explicit update after correcting their input or dependencies. Core retains the effect hardening in V6; rc.11 owns dependency teardown ordering and superseded-activation handling.
|
||||
- **V26 · `loader/src/config/tree.ts` cross-tree moves**: backports [cordiverse/cordis#271](https://github.com/cordiverse/cordis/pull/271), merged after `v4.0.0-rc.12`. When `EntryTree.update()` moves an entry into a group of another tree, the entry and the same-tree members of its group move their store registrations to the target tree, and the move is rejected before either tree changes when the target tree already holds one of their ids. The source tree receives a removal and the target tree a creation, without `legacy` or `from`. Upstream at `v4.0.0-rc.12` keeps the entry registered in the source tree and the target receives an update with `legacy`, so the Include journal writes a partial row and reconciling the target file creates a second Entry. Retire this entry when the vendored Loader includes the upstream fix. Covered by `scripts/cordis-include-journal.spec.ts`.
|
||||
- **V27 · `loader/src/config/utils.ts` explicit ids with `:`**: `validateOptions()` accepts ids containing `EntryTree.sep`, so `EntryTree.create()`, `EntryTree.update()` and group reconciliation admit them; upstream rejects them with an `id must not contain` issue. `validateOptions()` keeps its upstream `sep` parameter. Generated bundles from `@deepseek-ai/dsh-creation-recommendations` prefix their row ids with `<package name>:`, and installed profiles already contain such rows. `resolve()` still splits ids on `:`, so these entries cannot be addressed by nested path. Covered by `scripts/cordis-entry-commit.spec.ts`, `scripts/cordis-loader-rc9.spec.ts` and `packages/experimental/creation-recommendations/tests/loader-composition.spec.ts`.
|
||||
- **V29 · `include/src/index.ts` unresolved aliases**: `_read()` and `parseEntryYaml()` report each alias without a preceding anchor as a `YAMLParseError` with code `BAD_ALIAS` and its position. Upstream leaves these to `document.toJS()`, which throws an unlocated `ReferenceError` outside `ConfigFileError`. Retire this entry when upstream reports them. Covered by `scripts/cordis-loader-rc9.spec.ts` and `scripts/cordis-entry-yaml.spec.ts`.
|
||||
|
||||
### Resolver adaptations
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -44,7 +44,7 @@ Patches can insert entries or override fields on entries with a matching `id`. A
|
||||
|
||||
## File format and errors
|
||||
|
||||
YAML files are parsed as YAML 1.2 under the core schema with the `yaml` package, plus the `!!js` tag for Loader expressions. Unknown tags are rejected. The file must be a top-level array whose entries, including the entries of each group, are mappings. A file that cannot be read, parsed or validated rejects with `ConfigFileError`; parse and validation errors carry `issues`, each with a message and a `file:line:column` location, and JSON files report the position of their syntax error. Include implements `getLocation(id, path)` for its entries: values written in the file resolve to the file, values supplied by a patch resolve through the parent entry to that patch, and values changed at runtime but not yet written resolve to nothing.
|
||||
YAML files are parsed as YAML 1.2 under the core schema with the `yaml` package, plus the `!!js` tag for Loader expressions. Unknown tags and aliases without a preceding anchor are rejected. The file must be a top-level array whose entries, including the entries of each group, are mappings. A file that cannot be read, parsed or validated rejects with `ConfigFileError`; parse and validation errors carry `issues`, each with a message and a `file:line:column` location, and JSON files report the position of their syntax error. Include implements `getLocation(id, path)` for its entries: values written in the file resolve to the file, values supplied by a patch resolve through the parent entry to that patch, and values changed at runtime but not yet written resolve to nothing.
|
||||
|
||||
Anonymous entries receive ids before the Loader sees them. An anonymous entry identical to one named on the previous read, under the same parent, keeps that id unless the file or an inserted patch row now uses it explicitly.
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -35,6 +35,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@deepseek-ai/cosmokit": "workspace:~",
|
||||
"yaml": "^2.9.1"
|
||||
"yaml": "^2.9.0"
|
||||
}
|
||||
}
|
||||
Vendored
+23
-4
@@ -6,7 +6,7 @@ import { access, constants, readFile, rename, rm, writeFile } from 'node:fs/prom
|
||||
import { setTimeout as sleep } from 'node:timers/promises'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
import {
|
||||
isAlias, isMap, isNode, isScalar, isSeq, LineCounter, parseDocument, Scalar, stringify, YAMLError,
|
||||
isAlias, isMap, isNode, isScalar, isSeq, LineCounter, parseDocument, Scalar, stringify, visit, YAMLError, YAMLParseError,
|
||||
type Document, type Range, type ScalarTag, type SchemaOptions,
|
||||
} from 'yaml'
|
||||
import { stringifyString } from 'yaml/util'
|
||||
@@ -51,12 +51,31 @@ export interface EntryYamlStringifyOptions {
|
||||
* @throws the first parse error, or the first warning such as an unknown tag; {@link entryYamlErrorPosition} reads its location.
|
||||
*/
|
||||
export function parseEntryYaml(content: string): unknown {
|
||||
const document = parseDocument(content, yamlOptions)
|
||||
const [error] = [...document.errors, ...document.warnings]
|
||||
const lines = new LineCounter()
|
||||
const document = parseDocument(content, { ...yamlOptions, lineCounter: lines })
|
||||
const [error] = [...document.errors, ...document.warnings, ...unresolvedAliases(document, lines)]
|
||||
if (error) throw error
|
||||
return document.contents === null ? undefined : document.toJS()
|
||||
}
|
||||
|
||||
/**
|
||||
* The parser reports an alias without a preceding anchor only when `toJS()` throws an unlocated `ReferenceError`;
|
||||
* report each one as a located parse error instead.
|
||||
*/
|
||||
function unresolvedAliases(document: Document, lines: LineCounter): YAMLParseError[] {
|
||||
const errors: YAMLParseError[] = []
|
||||
visit(document, {
|
||||
Alias(_, node) {
|
||||
if (node.resolve(document) || !node.range) return
|
||||
const [start, end] = node.range
|
||||
const error = new YAMLParseError([start, end], 'BAD_ALIAS', `Unresolved alias (the anchor must be set before the alias): ${node.source}`)
|
||||
error.linePos = [lines.linePos(start), lines.linePos(end)]
|
||||
errors.push(error)
|
||||
},
|
||||
})
|
||||
return errors
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a value in Include's YAML dialect. JavaScript expression nodes are written as `!!js` scalars. The output
|
||||
* never contains anchors or aliases: repeated object references are written out in full, and no option changes this.
|
||||
@@ -386,7 +405,7 @@ export class Include extends EntryTree {
|
||||
syntax = parseSyntax(content)
|
||||
const { document, lines } = syntax
|
||||
// unknown tags are only warnings to the parser, but leave the data incomplete
|
||||
const errors: YAMLError[] = [...document.errors, ...document.warnings]
|
||||
const errors: YAMLError[] = [...document.errors, ...document.warnings, ...unresolvedAliases(document, lines)]
|
||||
if (errors.length) {
|
||||
const issues = errors.map(error => ({ message: error.message, location: this._locate(lines, error.pos[0]) }))
|
||||
throw new ConfigFileError('parse', this.filename, undefined, issues)
|
||||
|
||||
Vendored
+1
-1
@@ -50,7 +50,7 @@ For file-backed trees, use `@cordisjs/plugin-include`.
|
||||
|
||||
## Entry validation and source positions
|
||||
|
||||
`create()` and `update()` check the resulting options with `validateOptions()` before the tree changes and reject with `EntryValidationError`, whose `issues` list each rejected path. `id` and `name` must be strings, and `name` is required; `group` must be a boolean; `disabled` a boolean or `!!js` expression; a group's `config` an array; `inject` a string array or a mapping; `intercept` and `isolate` mappings, with each `isolate` value `true` or a string. `create()` and `update()` also check the entries of a group's `config`. A group checks each entry again as it creates it; an invalid entry is logged, any running entry with its id is disposed, and its siblings still start. Explicit ids may contain `:`.
|
||||
`create()` and `update()` check the resulting options with `validateOptions()` before the tree changes and reject with `EntryValidationError`, whose `issues` list each rejected path. `id` and `name` must be strings, and `name` is required; `group` must be a boolean; `disabled` a boolean or `!!js` expression; an entry with `group: true` requires a `config` array, which may be empty; `inject` a string array or a mapping; `intercept` and `isolate` mappings, with each `isolate` value `true` or a string. `create()` and `update()` also check the entries of a group's `config`. A group checks each entry again as it creates it; an invalid entry is logged, any running entry with its id is disposed, and its siblings still start. Explicit ids may contain `:`.
|
||||
|
||||
`EntryTree.getLocation(id, path)` returns where an entry option is written; the base tree returns `undefined`, and Include implements it. Config validation errors and entry option errors of an entry with a source list each issue with its `file:line:column`, and their stack frames name the entry ids from the innermost tree outward. A config passed at runtime has no source position, so its validation errors keep their original message.
|
||||
|
||||
|
||||
Reference in new issue
Block a user