fix(boot): own the rows a config override sets, queue recompositions, and let records follow the configuration
Second review round on the contained-group composition:
- Ownership scanned only `insert` rows, so an external bundle could set a
built-in row's id as a child through `{ id: own, config: [...] }` and the
Loader re-parented that row under the bundle while `originOf` still named
the built-in layer. The rows an id-targeted patch sets as a group's config
now count as the layer's own: an external bundle that sets an id another
layer owns is left out whole, a built-in layer that takes another layer's
id fails loud, and a layer restating its own child is not a repeat.
- `recompose` read the committed profile before awaiting the update, so a
watcher firing while a bundle was being enabled composed the tree before
the enable and applied it after; the plugin vanished while `layers` kept
listing it. Recompositions now queue, each reading what the previous one
committed, and a rejection stays its own caller's outcome.
- A patch that replaced a built-in target's config removed the wrapper the
bundle had put there, yet later inserts still targeted the detached
wrapper and vanished. The composition forgets the wrapper on such an
override and creates a new one under the same id.
- Generated wrapper ids bypassed the duplicate check, so a bundle declaring
a row spelled like a wrapper produced two nodes with one id. Declared and
generated ids now go through one registration.
- Failure records outlived their rows when a bundle update dropped a failed
row without unmounting the group, or when a pending row sat in a plain
nested group whose id the record named. A contained group now drops the
records of rows its configuration no longer names after each update, and
the audit records every row under the contained group that isolates it.
- `applyEntryPatches` assigned override values by reference, so applying a
patch list carried a later insert's rows back into the patch object; the
vendored include now clones object-valued overrides as it does inserts.
This commit is contained in:
1 parent
8357838bc5
commit
aaf58eb5bf
23 files changed
+344
-86
No files matched your search
@@ -16,7 +16,7 @@
|
||||
import type { EntryOptions } from '@deepseek-ai/cordis-plugin-loader'
|
||||
import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
|
||||
import { composeExternalLayer, isContainedLayer, type ComposedExternalLayer } from './external-bundles.ts'
|
||||
import { visitInsertedRows, visitRowTree } from './patch-rows.ts'
|
||||
import { visitPatchRows, visitRowTree } from './patch-rows.ts'
|
||||
import type { ProfileLayer } from './profile.ts'
|
||||
|
||||
/** One user-owned patch list in the stack: the profile file, the home file, or a `--patch` overlay. */
|
||||
@@ -89,12 +89,14 @@ function rowIds(row: EntryOptions): string[] {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide row-id ownership across the bundle layers. Built-in and boot-staged
|
||||
* layers claim first, in manifest order; an id two of them declare, or one
|
||||
* declares twice, is a defect of the shipped composition and throws.
|
||||
* Contained external layers then claim in manifest order, each rendered once
|
||||
* here; one whose id is already owned, or which declares an id twice, is left
|
||||
* out whole.
|
||||
* Decide row-id ownership across the bundle layers. A layer introduces the
|
||||
* rows it inserts and the rows its config overrides set as a group's
|
||||
* children. Built-in and boot-staged layers claim first, in manifest order;
|
||||
* an id two of them declare, or one inserts twice, is a defect of the shipped
|
||||
* composition and throws, while a config override restating a row the same
|
||||
* layer declared is that layer keeping its own child. Contained external
|
||||
* layers then claim in manifest order, each rendered once here; one whose id
|
||||
* is already owned, or which declares an id twice, is left out whole.
|
||||
* @param layers - the profile's bundle layers, in manifest order.
|
||||
* @returns the owner of every claimed id, the conflicts of each skipped bundle, and the composition of each mounted one.
|
||||
* @throws when two built-in or boot-staged layers declare the same id, or one of them declares an id twice.
|
||||
@@ -103,10 +105,13 @@ export function claimLayerIds(layers: readonly ProfileLayer[]): LayerOwnership {
|
||||
const owners = new Map<string, ProfileLayer>()
|
||||
for (const layer of layers) {
|
||||
if (isContainedLayer(layer)) continue
|
||||
visitInsertedRows(layer.patches, (row) => {
|
||||
visitPatchRows(layer.patches, (row, source) => {
|
||||
if (typeof row.id !== 'string') return
|
||||
const owner = owners.get(row.id)
|
||||
if (owner === layer) throw new Error(`row ${JSON.stringify(row.id)} is declared twice by ${layer.packageName}`)
|
||||
if (owner === layer) {
|
||||
if (source === 'insert') throw new Error(`row ${JSON.stringify(row.id)} is declared twice by ${layer.packageName}`)
|
||||
return
|
||||
}
|
||||
if (owner !== undefined) {
|
||||
throw new Error(`row ${JSON.stringify(row.id)} is declared by both ${owner.packageName} and ${layer.packageName}`)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user