diff --git a/scripts/cordis-entry-yaml.spec.ts b/scripts/cordis-entry-yaml.spec.ts index d2426d8b49..a91d8b96d9 100644 --- a/scripts/cordis-entry-yaml.spec.ts +++ b/scripts/cordis-entry-yaml.spec.ts @@ -46,5 +46,6 @@ describe('Include YAML dialect', () => { alias = caught } expect(entryYamlErrorPosition(alias)).toEqual({ line: 2, column: 11 }) + expect(() => parseEntryYaml('- id: a\n config: *later\n- id: b\n config: &later {}\n')).toThrow('Alias *later must follow its anchor') }) }) diff --git a/vendor/README.md b/vendor/README.md index a0e73b7813..f4830a221d 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -26,7 +26,7 @@ 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 V30. +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 V31. - **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, 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`. @@ -37,7 +37,7 @@ Keep this log exhaustive — every divergence from upstream must be listed. Each - **V7 · JSDoc enrichment**: added `@param`/`@returns` tags and contract documentation (disposal semantics, waterfall veto, bail conditions, error cases) across the public plugin-author surface — `Context` (class, statics, the `isolate()` rule that isolated scopes never fall back to an injected view, and the `Context` interface properties incl. `[Context.root]`), module re-exports, shared utility helpers, `EventsService`, `Fiber`, `ValidationError` and its path helpers, `RegistryService`, `ReflectService`, `Service` and its intercept-metadata members, `LoggerService` and their `declare module './context.ts'` overloads. The upstream line comment on `reflect.ts`'s exported `locate()` is rewritten as JSDoc. Loader documentation covers `loader/src/{index,internal,config/entry,config/group,config/isolate,config/tree,config/utils}.ts`, including entry ownership, tree mutation methods, the `!!js` discriminator, entry option validation, source positions and `ModuleNotFoundError`. The upstream `EventsService.dispatch()` deprecation annotation is omitted: DSH enumerates callbacks to contain each observer failure independently, which the typed dispatch methods do not provide. Timer retains its local class and helper summaries; its README is local documentation because the upstream package has none. Cosmokit and Schemastery add summaries to their exported helpers, types and namespaces, logger-console to its exporters and config namespace, and HMR to its build-failure logger in `hmr/src/error.ts`. Comment-only; no code changes. Motivation: the website API-reference generator renders these docs and hard-errors on undocumented members. Retire this entry when the enrichment is upstreamed. - **V9 · `hmr/src/index.ts` module-watcher readiness and native paths**: realpath the existing watch base, classify framework modules and attach listeners before reporting readiness, and compare config paths using both canonical and configured spellings. This preserves Node module-cache identity across Windows short-name paths and filesystem aliases. The main watcher uses `ignoreInitial: true` so startup reads do not trigger another refresh; exact profile patch watching is owned by `packages/boot/hmr/src/watch-config.ts`. The Include change listener logs a rejected `Include.refresh()` instead of leaving the rejection unhandled; the rejection reports unsaved runtime changes while Include keeps its running tree. Covered by `packages/boot/hmr/tests/watch-config.spec.ts` and `scripts/cordis-vendor-hmr-include.spec.ts`. - **V10 · Vendored Node-compatible TypeScript**: marked erased imports explicitly across `cordis`, `loader`, `include`, `hmr`, and `schemastery` so Node's native TypeScript transform does not request types as runtime exports. Schemastery's source uses an ESM default export and its package declares `type: module`. Conditional exports select `.mjs` for import and `.cjs` for require; without them, concurrent imports under module-hook hosts reach the CJS entry and can race its require of ESM Cosmokit (`ERR_REQUIRE_ESM_RACE_CONDITION`). -- **V11 · Include patch and YAML exports**: `include/src/index.ts` exports upstream `applyPatches` as `applyEntryPatches` with its `PatchResult` type, so `dsh --dump-config` composes entries with the same algorithm that mounting uses. It also exports `parseEntryYaml`, `stringifyEntryYaml` and `entryYamlErrorPosition` over the `!!js` YAML dialect, using the `yaml` options with which `_read()` parses Include's own file, so every DSH reader and writer of Include-dialect YAML uses Include's parser. `parseEntryYaml` throws the first parse error or warning, such as an unknown tag, and returns `undefined` for an empty document; `stringifyEntryYaml` always writes with `aliasDuplicateObjects: false`, matching the previous `noRefs` output, and offers no option to emit aliases, while Include's own writer keeps upstream's options. Covered by `packages/boot/app-boot/tests/config-reload.spec.ts`, `scripts/cordis-entry-commit.spec.ts` and `scripts/cordis-entry-yaml.spec.ts`. +- **V11 · Include patch and YAML exports**: `include/src/index.ts` exports upstream `applyPatches` as `applyEntryPatches` with its `PatchResult` type, so `dsh --dump-config` composes entries with the same algorithm that mounting uses. It also exports `parseEntryYaml`, `stringifyEntryYaml` and `entryYamlErrorPosition` over the `!!js` YAML dialect, using the `yaml` options with which `_read()` parses Include's own file, so every DSH reader and writer of Include-dialect YAML uses Include's parser. `parseEntryYaml` throws the first parse error or warning, such as an unknown tag or an alias without a preceding anchor (V30), adds line positions to alias errors so `entryYamlErrorPosition` reads them, and returns `undefined` for an empty document; `stringifyEntryYaml` always writes with `aliasDuplicateObjects: false`, matching the previous `noRefs` output, and offers no option to emit aliases, while Include's own writer keeps upstream's options. Covered by `packages/boot/app-boot/tests/config-reload.spec.ts`, `scripts/cordis-entry-commit.spec.ts` and `scripts/cordis-entry-yaml.spec.ts`. - **V14 · Include persistence results**: `include/src/index.ts` keeps an error for unsaved journal changes. `flush()` retries pending writes and rejects while changes remain unsaved; `stop()` returns the same result and always stops the child tree; a later successful flush clears previous errors. A failed `refresh()` can also reject while runtime changes remain unsaved. Patch-owned changes route to the parent Include, so callers that need them persisted must flush that parent too. The constructor omits upstream's `ctx.hmr.watch(this.filename, () => this.refresh())` registration because neither HMR provider exposes `watch()`; both find each Include by scanning loader entries for its `filename` and call `refresh()`. Ordinary Fiber teardown keeps its error containment. Covered by `scripts/cordis-include-journal.spec.ts` and `packages/host/directory-picker-auto/tests/loader-composition.spec.ts`. - **V15 · Configuration access across Core, Loader, Include and HMR**: rc.11 Core owns raw `Fiber.config`, `internal/config(fiber, next)`, `internal/commit` and awaited `internal/update(config, next)`. Root-fiber candidate resolution remains available without a plugin schema. Local `rawConfig`, `resolveConfig(candidate)` and `effectiveConfig` accessors retain the DSH consumer API. Fiber caches the object passed to activation or a successful update that keeps the instance; candidate resolution is pure, failed or superseded updates cannot replace the cache, and volatile updates retain references. Loader resolves only entry roots and excludes Group/Include tree carriers, so nested `!!js` expressions wait for their own injections. Include retains its tree-carrier marker and public patch exports, and HMR transfers raw config through the accessors. Covered by `scripts/cordis-config-access.spec.ts`, `scripts/cordis-core-lifecycle.spec.ts` and the boot/HMR suites. - **V16 · `cordis/package.json` publishes `src`**: added `src` to the `files` list, joining the other eight vendored packages. Cordis declares `"./src/*": "./src/*"` in its exports, so a tarball without `src` publishes an export map pointing at absent files; the release change judgement also reads `files` to decide whether a diff reaches the payload, and a package whose only published paths are build output has no tracked path to match. @@ -48,7 +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 `:`, 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`. +- **V30 · `include/src/index.ts` unresolved aliases**: backports [cordiverse/cordis#354](https://github.com/cordiverse/cordis/pull/354) (`c9fe179ce5ac484620a387a1697409cb007d4178`), merged after `v4.0.0-rc.12`. `_read()` reports each alias without a preceding anchor as a `BAD_ALIAS` `YAMLParseError` with its position, distinguishing an unknown anchor from one written after the alias; at the tag, `document.toJS()` throws an unlocated `ReferenceError` outside `ConfigFileError`. `unresolvedAliases()` matches the upstream commit verbatim. Retire this entry when the vendored Include includes #354. Covered by `scripts/cordis-loader-rc9.spec.ts` and `scripts/cordis-entry-yaml.spec.ts`. ### Resolver adaptations diff --git a/vendor/include/src/index.ts b/vendor/include/src/index.ts index 2fe77103f0..d60c4eb2c1 100644 --- a/vendor/include/src/index.ts +++ b/vendor/include/src/index.ts @@ -7,7 +7,7 @@ import { setTimeout as sleep } from 'node:timers/promises' import { fileURLToPath, pathToFileURL } from 'node:url' import { isAlias, isMap, isNode, isScalar, isSeq, LineCounter, parseDocument, Scalar, stringify, visit, YAMLError, YAMLParseError, - type Document, type Range, type ScalarTag, type SchemaOptions, + type Alias, type Document, type Range, type ScalarTag, type SchemaOptions, } from 'yaml' import { stringifyString } from 'yaml/util' import { applyJournal, flatten, type Journal, merge, reconcile, record } from './journal.ts' @@ -53,29 +53,15 @@ export interface EntryYamlStringifyOptions { export function parseEntryYaml(content: string): unknown { const lines = new LineCounter() const document = parseDocument(content, { ...yamlOptions, lineCounter: lines }) - const [error] = [...document.errors, ...document.warnings, ...unresolvedAliases(document, lines)] - if (error) throw error + const [error] = [...document.errors, ...document.warnings, ...unresolvedAliases(document)] + if (error) { + // Alias errors carry offsets only; the parser's own errors already carry line positions. + error.linePos ??= [lines.linePos(error.pos[0]), lines.linePos(error.pos[1])] + 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. @@ -118,6 +104,31 @@ function parseSyntax(content: string): Syntax { return { document, lines } } +/** + * The parser accepts an alias without a preceding anchor, which only fails in + * `toJS()` with an unlocated `ReferenceError`. Nodes are visited in document + * order, so an anchor is known exactly when it precedes the alias. + */ +function unresolvedAliases(document: Document) { + const anchors = new Set() + const unresolved: Alias[] = [] + visit(document, (_, node) => { + if (isAlias(node)) { + if (!anchors.has(node.source)) unresolved.push(node) + } else if (isNode(node) && node.anchor) { + anchors.add(node.anchor) + } + }) + // every anchor is known once the scan ends + return unresolved.map((node) => { + const [start, end] = node.range! + const message = anchors.has(node.source) + ? `Alias *${node.source} must follow its anchor` + : `Unresolved alias: *${node.source}` + return new YAMLParseError([start, end], 'BAD_ALIAS', message) + }) +} + interface Snapshot { content: string data: EntryOptions[] @@ -405,7 +416,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, ...unresolvedAliases(document, lines)] + const errors: YAMLError[] = [...document.errors, ...document.warnings, ...unresolvedAliases(document)] 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)