diff --git a/apps/cli/README.i18n.yaml b/apps/cli/README.i18n.yaml index a035a44693..741c64c21d 100644 --- a/apps/cli/README.i18n.yaml +++ b/apps/cli/README.i18n.yaml @@ -12,8 +12,8 @@ en: cc03e6b75206661b zh: 99e41f4143198352 /deepseek-ai-dsh/profiles: - en: 523477a093beb0c2 - zh: f88ea21e5fbea969 + en: 85171337ac2fb2ff + zh: 705a4eef97d9b519 /deepseek-ai-dsh/optional-overlays: en: 3a40ddc44e55f79c zh: 8d3949132e1ef93c diff --git a/apps/cli/README.md b/apps/cli/README.md index 644eba2aa5..4a5dd73e04 100644 --- a/apps/cli/README.md +++ b/apps/cli/README.md @@ -34,7 +34,7 @@ dsh --help # the launcher's own help ## Profiles -A profile directory holds a `package.json` (out-of-tree plugin dependencies plus the profile manifest `dsh.profile` with its ordered `bundles` list) and a `cordis.patch.yml` (the user's own patch layer). `dsh-hmr`, when enabled in YAML, watches the profile manifest and both profile and home patch files, then recomposes all layers through one serialized reload. Without HMR, changes apply on restart. Edits arriving during watcher registration use the same nonfatal reload reporting as later edits. [Plugin Manager](../../packages/boot/plugin-manager/README.md) shares package operations and the profile write lock with `dsh plugin`; package updates retain disabled bundle selections. CLI package commands inherit authentication variables and terminal descriptors, including interactive build approval; service calls retain their scrubbed environment and captured diagnostics. +A profile directory holds a `package.json` (out-of-tree plugin dependencies plus the profile manifest `dsh.profile` with its ordered `bundles` list) and a `cordis.patch.yml` (the user's own patch layer). `dsh-hmr`, when enabled in YAML, watches the profile manifest, the profile and home patch files, and every `--patch` overlay file, then recomposes all layers through one serialized reload. Without HMR, changes apply on restart, except that a Config Editor save applies the current contents of every patch and overlay file. Edits arriving during watcher registration use the same nonfatal reload reporting as later edits. [Plugin Manager](../../packages/boot/plugin-manager/README.md) shares package operations and the profile write lock with `dsh plugin`; package updates retain disabled bundle selections. CLI package commands inherit authentication variables and terminal descriptors, including interactive build approval; service calls retain their scrubbed environment and captured diagnostics. Installation and profile startup enforce the declared `engines.dsh` range, or DSH peer ranges when it is absent, against the same runtime version shown by `dsh --version`. Incompatible plugins require an explicitly acknowledged exact-version exemption. The [plugin manager's compatibility reference](../../packages/boot/plugin-manager/README.md#version-compatibility-and-exemptions) documents `version-exemptions`, `allow-version`, `revoke-version`, persistence, and risks. diff --git a/apps/cli/README.zh.md b/apps/cli/README.zh.md index 318e12440f..5d0ce78b86 100644 --- a/apps/cli/README.zh.md +++ b/apps/cli/README.zh.md @@ -34,7 +34,7 @@ dsh --help # the launcher's own help ## Profile -profile 目录包含一个 `package.json`,其中记录树外插件依赖,以及 profile manifest(元数据清单)`dsh.profile`、其中按顺序排列的 `bundles` 列表;还包含一个 `cordis.patch.yml`,其中保存用户自己的 patch 层。在 YAML 中启用的 `dsh-hmr` 监视 profile manifest、profile 与 home 级 patch 文件,再通过统一串行重载重新组合所有层。未启用 HMR 时,更改在重启后生效。监听器注册期间发生的编辑与后续编辑使用相同的非致命重载错误报告。[插件管理器](../../packages/boot/plugin-manager/README.zh.md) 与 `dsh plugin` 共享包操作和 profile 写锁;更新依赖会保留已停用的组合包选择。CLI 包操作继承认证环境和终端描述符,支持交互式构建批准;service 调用保留清理后的环境并捕获诊断。 +profile 目录包含一个 `package.json`,其中记录树外插件依赖,以及 profile manifest(元数据清单)`dsh.profile`、其中按顺序排列的 `bundles` 列表;还包含一个 `cordis.patch.yml`,其中保存用户自己的 patch 层。在 YAML 中启用的 `dsh-hmr` 监视 profile manifest、profile 与 home 级 patch 文件以及每个 `--patch` overlay 文件,再通过统一串行重载重新组合所有层。未启用 HMR 时,更改在重启后生效;例外是 Config Editor 保存时会应用所有 patch 与 overlay 文件的当前内容。监听器注册期间发生的编辑与后续编辑使用相同的非致命重载错误报告。[插件管理器](../../packages/boot/plugin-manager/README.zh.md) 与 `dsh plugin` 共享包操作和 profile 写锁;更新依赖会保留已停用的组合包选择。CLI 包操作继承认证环境和终端描述符,支持交互式构建批准;service 调用保留清理后的环境并捕获诊断。 安装和 profile 启动会按声明的 `engines.dsh` 范围(未声明时按 DSH peer 范围),检查与 `dsh --version` 显示值相同的运行时版本。不兼容插件需要用户明确确认精确版本豁免。[插件管理器的兼容性参考](../../packages/boot/plugin-manager/README.zh.md#version-compatibility-and-exemptions)说明 `version-exemptions`、`allow-version`、`revoke-version`、持久化规则与风险。 diff --git a/apps/cli/reference/README.i18n.yaml b/apps/cli/reference/README.i18n.yaml index 2c33416553..93a4389770 100644 --- a/apps/cli/reference/README.i18n.yaml +++ b/apps/cli/reference/README.i18n.yaml @@ -21,8 +21,8 @@ en: 8d2cfff9bab7327f zh: 21515ab6e6798504 /dsh-cli-behavior-reference/web-profile: - en: 149c5571acd51baf - zh: 300e3c2425273a92 + en: afc6ddcd63f24664 + zh: ed11d2ad6d7a9852 /dsh-cli-behavior-reference/shared-deployment-behavior: en: f02219118dcec531 zh: fe2977628d7340da diff --git a/apps/cli/reference/README.md b/apps/cli/reference/README.md index dc84a267d8..ff5b1914ad 100644 --- a/apps/cli/reference/README.md +++ b/apps/cli/reference/README.md @@ -128,7 +128,7 @@ The production Web runner needs built package and frontend artifacts (`pnpm run Process shutdown gives the plugin tree up to five seconds to dispose. The first `SIGINT`/`SIGTERM` starts that graceful drain — `SIGTERM` is a supervisor's ordinary stop request and exits 0 on every surface, `SIGINT` reports 130; a second signal forces immediate exit. If one-shot normal completion is already stuck in disposal, the first `Ctrl+C` is the escalation and exits immediately instead of being swallowed. -The base-backed modes treat the invoking directory as the default workspace root, load applicable `AGENTS.md` or `CLAUDE.md` instructions with a 65,536-byte render budget for each instruction chain, and use an in-memory SQLite session content index. The standalone `sdk-minimal` profile uses the invoking directory as its sandbox-policy root and includes `read_image`, but omits text filesystem tools, instruction discovery, and SQLite. An enabled HMR plugin watches both `cordis.patch.yml` layers (profile and home) and reapplies valid edits transactionally; without HMR, the process applies them once. A one-shot surface exits through its bounded shutdown, which disposes any live watchers. +The base-backed modes treat the invoking directory as the default workspace root, load applicable `AGENTS.md` or `CLAUDE.md` instructions with a 65,536-byte render budget for each instruction chain, and use an in-memory SQLite session content index. The standalone `sdk-minimal` profile uses the invoking directory as its sandbox-policy root and includes `read_image`, but omits text filesystem tools, instruction discovery, and SQLite. An enabled HMR plugin watches both `cordis.patch.yml` layers (profile and home) and every `--patch` overlay file, and reapplies valid edits transactionally; without HMR, the process applies them once. A one-shot surface exits through its bounded shutdown, which disposes any live watchers. New sessions in base-backed profiles default to the `workspace-write` permission preset. Bash and filesystem mutations are restricted to the session workspace and platform temporary roots; reads and network access are not confined, while process visibility depends on the selected sandbox backend — bwrap runs commands in a private PID namespace that hides host processes, and Landlock and Seatbelt leave host process visibility unchanged. `DSH_PERMISSION_MODE` changes the process fallback. Stored General-settings permissions affect later Web sessions, not an already-open one. The standalone `sdk-minimal` tree instead pins `danger-full-access` and mounts no approval or permission-settings service. diff --git a/apps/cli/reference/README.zh.md b/apps/cli/reference/README.zh.md index 2de7755983..bc1e6ed8ac 100644 --- a/apps/cli/reference/README.zh.md +++ b/apps/cli/reference/README.zh.md @@ -128,7 +128,7 @@ dsh web --help 进程关闭时,插件树最多有 5 秒完成 dispose。首次收到 `SIGINT` 或 `SIGTERM` 时会开始优雅排空:`SIGTERM` 是监督进程发出的常规停止请求,在所有运行模式下都以 0 退出;`SIGINT` 则报告 130。第二次收到信号时会立即强制退出。如果一次性运行在正常结束时已经卡在 dispose 阶段,第一次按下 `Ctrl+C` 就会直接升级为强制退出,而不会被忽略。 -基于 base 的模式都将运行命令时所在的目录作为默认 workspace 根目录,以每条指令链 65,536 字节的渲染预算加载适用的 `AGENTS.md` 或 `CLAUDE.md` 指令,并使用内存 SQLite 会话内容索引。独立的 `sdk-minimal` profile 把运行命令时所在的目录作为沙箱策略根目录并包含 `read_image`,但省略文本文件系统工具、指令发现与 SQLite。启用的 HMR 插件会监视 profile 与 home 两个 `cordis.patch.yml` 配置层的有效变更,并以事务方式重新应用;未启用 HMR 时只应用一次。一次性运行模式通过有界关闭流程退出,该流程会 dispose 所有实时监视器。 +基于 base 的模式都将运行命令时所在的目录作为默认 workspace 根目录,以每条指令链 65,536 字节的渲染预算加载适用的 `AGENTS.md` 或 `CLAUDE.md` 指令,并使用内存 SQLite 会话内容索引。独立的 `sdk-minimal` profile 把运行命令时所在的目录作为沙箱策略根目录并包含 `read_image`,但省略文本文件系统工具、指令发现与 SQLite。启用的 HMR 插件会监视 profile 与 home 两个 `cordis.patch.yml` 配置层以及每个 `--patch` overlay 文件的有效变更,并以事务方式重新应用;未启用 HMR 时只应用一次。一次性运行模式通过有界关闭流程退出,该流程会 dispose 所有实时监视器。 基于 base 的 profile 中,新会话默认使用 `workspace-write` 权限预设。Bash 和文件系统修改仅限于会话 workspace 与平台临时根目录;读取和网络访问不受限制,进程可见性则取决于所选沙箱后端——bwrap 在私有 PID 命名空间中运行命令并隐藏宿主进程,Landlock 与 Seatbelt 保持宿主进程可见性不变。`DSH_PERMISSION_MODE` 更改进程后备值。General settings 中存储的权限影响后续 Web 会话,不改变已打开的会话。独立的 `sdk-minimal` 配置树则固定为 `danger-full-access`,且不挂载 approval 或权限 settings 服务。 diff --git a/apps/cli/src/profile-boot.ts b/apps/cli/src/profile-boot.ts index 2b1977deed..9ac6ffbe42 100644 --- a/apps/cli/src/profile-boot.ts +++ b/apps/cli/src/profile-boot.ts @@ -14,14 +14,12 @@ import { existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } import { dirname, join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' import { FiberState, type Context } from '@deepseek-ai/cordis' -import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include' import { boot, readProfilePatches, createRuntimeResolution, initProfile, installFailLoud, - loadOverlayPatches, loadProfile, reportSkippedBundles, PluginPackages, @@ -204,8 +202,8 @@ interface ComposedProfile { profile: Profile /** Immutable runtime resolution computed before any plugin imports. */ resolution: RuntimeResolution - /** Command-line overlay contents, frozen for this invocation. */ - overlays: PatchOptions[] + /** Absolute command-line overlay files, in argv order. */ + overlayPaths: string[] } /** @@ -231,8 +229,7 @@ async function composeProfile( if (resolvedProfile !== undefined) writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG) const resolutionOptions = { installAnchor: resolvedProfile?.installAnchor ?? INSTALL_ANCHOR, profile } const resolution = await createRuntimeResolution(resolutionOptions) - const overlays = patchFiles.flatMap(file => loadOverlayPatches(NAME, resolve(file))) - return { profile, resolution, overlays } + return { profile, resolution, overlayPaths: patchFiles.map(file => resolve(file)) } } /** An application-owned profile and its independent installation fallback. */ @@ -331,7 +328,7 @@ export async function runProfile(options: RunProfileOptions): Promise<{ ctx: Con installAnchor: options.resolvedProfile?.installAnchor ?? INSTALL_ANCHOR, startedBundles: composed.profile.layers.map(layer => layer.packageName), cwd: process.cwd(), home: resolveDshHome(), - overlays: composed.overlays, telemetryDisabledEnv: process.env.DSH_TELEMETRY_DISABLED, + overlayPaths: composed.overlayPaths, telemetryDisabledEnv: process.env.DSH_TELEMETRY_DISABLED, } const ctx = await boot(NAME, rootConfig, readProfilePatches(NAME, profileContext, composed.profile), async (hostCtx) => { app.current = hostCtx diff --git a/apps/cli/tests/optional-bundle-transitions.e2e.ts b/apps/cli/tests/optional-bundle-transitions.e2e.ts index ac04460a79..d7e81f2c47 100644 --- a/apps/cli/tests/optional-bundle-transitions.e2e.ts +++ b/apps/cli/tests/optional-bundle-transitions.e2e.ts @@ -95,7 +95,7 @@ describe.skipIf(!existsSync(join(root, 'apps/cli/lib/bin.js')))('Official option const profile = app.loadProfileDirectory('bundle-test', directory, installAnchor) const profileContext: ProfileContext = { name: 'web', dir: directory, patchPath: profile.patchPath, installAnchor, cwd: workspace, home, - startedBundles: profile.layers.map(layer => layer.packageName), overlays: [], telemetryDisabledEnv: '1', + startedBundles: profile.layers.map(layer => layer.packageName), overlayPaths: [], telemetryDisabledEnv: '1', } const resolution = await app.createRuntimeResolution({ installAnchor, home, profile }) const listeners = new Set<() => void>() diff --git a/apps/cli/tests/resolved-profile-boot.spec.ts b/apps/cli/tests/resolved-profile-boot.spec.ts index b8415fb974..40630df491 100644 --- a/apps/cli/tests/resolved-profile-boot.spec.ts +++ b/apps/cli/tests/resolved-profile-boot.spec.ts @@ -2,7 +2,7 @@ import { lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { createRequire } from 'node:module' import { tmpdir } from 'node:os' -import { join } from 'node:path' +import { join, relative } from 'node:path' import { Context } from '@deepseek-ai/cordis' import { createLaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment' import { @@ -139,7 +139,7 @@ describe('runProfile with an application-owned profile', () => { try { const { shutdown } = await runProfile({ environment, profile: 'desktop', resolvedProfile: runtime, - patchFiles: [overlay], args: ['--port', '0', '--no-open'], + patchFiles: [relative(process.cwd(), overlay)], args: ['--port', '0', '--no-open'], }) expect(installProxyFromEnvironment).toHaveBeenCalledWith(environment, expect.any(Function)) const resolution = vi.mocked(createRuntimeResolution).mock.settledResults @@ -165,7 +165,9 @@ describe('runProfile with an application-owned profile', () => { ]) expect(rows.find(row => row.id === 'target')?.config).toEqual({ overlay: true, priority: 'overlay' }) expect(rows.find(row => row.id === 'session-telemetry-otel')?.disabled).toBe(true) - expect(ctx.profileContext).toMatchObject({ dir: home, patchPath: profilePatch, installAnchor: runtime.installAnchor }) + expect(ctx.profileContext).toMatchObject({ + dir: home, patchPath: profilePatch, installAnchor: runtime.installAnchor, overlayPaths: [overlay], + }) await shutdown.shutdown(0) expect(dispose).toHaveBeenCalledOnce() expect(disposeProxy).toHaveBeenCalledOnce() diff --git a/apps/cli/tests/web-agent-presets.e2e.ts b/apps/cli/tests/web-agent-presets.e2e.ts index ce5ed66071..efdb68d158 100644 --- a/apps/cli/tests/web-agent-presets.e2e.ts +++ b/apps/cli/tests/web-agent-presets.e2e.ts @@ -221,7 +221,7 @@ async function bootWeb( bootCtx.provide('profileContext', { name: surface, dir: profileDir, patchPath: profile.patchPath, installAnchor: INSTALL_ANCHOR, home, cwd: home, startedBundles: profileBundles ?? ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app'], - overlays: [], telemetryDisabledEnv: '1' }) + overlayPaths: [], telemetryDisabledEnv: '1' }) await bootCtx.plugin(PluginPackages, { resolution }) bootCtx.provide('connection', { fetch: { register: () => () => {} }, diff --git a/apps/web/tests/scaffold.ts b/apps/web/tests/scaffold.ts index 736ba7c228..d3528d9eec 100644 --- a/apps/web/tests/scaffold.ts +++ b/apps/web/tests/scaffold.ts @@ -450,10 +450,11 @@ export interface LaunchOptions { harnessHome?: string } -/** Dispose the booted tree and remove both owned temp roots, reporting every independent cleanup failure. */ -async function cleanupScaffoldWorld(ctx: Context, workspaceCwd: string, persistenceRoot: string): Promise { +/** Dispose the booted tree and remove the owned temp roots and overlay file, reporting every independent cleanup failure. */ +async function cleanupScaffoldWorld(ctx: Context, workspaceCwd: string, persistenceRoot: string, overlayPath: string): Promise { const failures: unknown[] = [] await Promise.resolve(ctx.fiber.dispose()).catch((error: unknown) => failures.push(error)) + await rm(overlayPath, { force: true }).catch((error: unknown) => failures.push(error)) await rm(workspaceCwd, { recursive: true, force: true }).catch((error: unknown) => failures.push(error)) await rm(persistenceRoot, { recursive: true, force: true }).catch((error: unknown) => failures.push(error)) return failures @@ -526,6 +527,8 @@ export async function launchWebScaffold(options: LaunchOptions = {}): Promise layer.packageName), - overlays: processOverlays, telemetryDisabledEnv: undefined, + overlayPaths: [overlayPath], telemetryDisabledEnv: undefined, } // HMR gates file-driven reloads on application readiness, which the // launcher commits after boot; this direct harness is ready at once. @@ -975,7 +980,7 @@ export async function launchWebScaffold(options: LaunchOptions = {}): Promise cleanupFailures.push(closeError)) } @@ -1051,7 +1056,7 @@ export async function launchWebScaffold(options: LaunchOptions = {}): Promise loadOverlayPatches(binName, path))`, which returns the same overlay layer. Call `readProfilePatches(binName, ctx.profileContext)` only when you need the full composition of bundle, profile, home, and overlay layers. +2. Where code constructs a `ProfileContext`, replace `overlays: [...]` with `overlayPaths: [...]`. Write any in-memory overlay rows to a patch file first and pass its absolute path. +3. Confirm the migration by running your type checker: no `overlays` property remains on `ProfileContext` values. diff --git a/docs/upgrade-guide/v0.2.2-rc.3/profile-context-overlay-paths/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.3/profile-context-overlay-paths/guide.zh.md new file mode 100644 index 0000000000..281e1b9566 --- /dev/null +++ b/docs/upgrade-guide/v0.2.2-rc.3/profile-context-overlay-paths/guide.zh.md @@ -0,0 +1,18 @@ +--- +kind: upgrade-guide +description: "ProfileContext 以 overlay 文件路径取代已解析的 overlay,每次组合都会重新读取这些文件。" +--- + +# 从文件读取命令行 overlay + +[English](guide.md) | 中文 + +## 变更 + +`@deepseek-ai/dsh-app-boot` 的 `ProfileContext`(以 `ctx.profileContext` 提供)不再包含 `overlays: readonly PatchOptions[]`,改为 `overlayPaths: readonly string[]`:按命令行顺序排列的 `--patch` 文件绝对路径。`readProfilePatches()` 每次调用都会读取这些文件,因此返回当前的 overlay 内容,并在 overlay 文件缺失或无效时抛出异常。启用 `dsh-hmr` 时,编辑 `--patch` 文件会重新组合运行中的 profile。读取 `profileContext.overlays` 的插件,以及构造 `ProfileContext` 的启动器或测试会受到影响。 + +## 迁移 + +1. 将对 `ctx.profileContext.overlays` 的读取替换为 `ctx.profileContext.overlayPaths.flatMap(path => loadOverlayPatches(binName, path))`,它返回相同的 overlay 层。只有需要 bundle、profile、home 与 overlay 各层的完整组合结果时,才调用 `readProfilePatches(binName, ctx.profileContext)`。 +2. 在构造 `ProfileContext` 的代码中,将 `overlays: [...]` 替换为 `overlayPaths: [...]`。内存中的 overlay 行需先写入 patch 文件,再传入该文件的绝对路径。 +3. 运行类型检查确认迁移完成:`ProfileContext` 值上不再存在 `overlays` 属性。 diff --git a/packages/boot/app-boot/README.i18n.yaml b/packages/boot/app-boot/README.i18n.yaml index f0fecadd3b..24c97f03cc 100644 --- a/packages/boot/app-boot/README.i18n.yaml +++ b/packages/boot/app-boot/README.i18n.yaml @@ -24,8 +24,8 @@ en: 65bf2834b81f87da zh: c864ac60a3005b99 /deepseek-ai-dsh-app-boot/use-this-package/profiles: - en: 781fe487a973ee6f - zh: e95188274f75f9ad + en: ba1c456bf22d8fc0 + zh: 018bd12bd56912e4 /deepseek-ai-dsh-app-boot/use-this-package/previewing-the-effective-configuration: en: 646a0ccdd7881ad1 zh: e3696acb1573dd7b @@ -36,14 +36,14 @@ en: 91d80c444ac0cfe5 zh: e7db496043528ffb /deepseek-ai-dsh-app-boot/use-this-package/startup-and-reload-failures: - en: dc13dfa1f79292e4 - zh: d51682ced7a18ac2 + en: 9b9e08c8638a975b + zh: 8a3f906c4d98cb89 /deepseek-ai-dsh-app-boot/understand-the-implementation: en: f4a2695cb4c8a570 zh: 89837235d2f376cf /deepseek-ai-dsh-app-boot/understand-the-implementation/design-notes: - en: 6eba01e24a2a68ab - zh: 64af424489087ec7 + en: 2943e0f4e90f2dde + zh: 1c752b58515153e5 /deepseek-ai-dsh-app-boot/understand-the-implementation/helper-behavior: en: 6fa850d1bb000d0e zh: aa83a40a9d3db295 diff --git a/packages/boot/app-boot/README.md b/packages/boot/app-boot/README.md index f480a5886d..2425e7aabf 100644 --- a/packages/boot/app-boot/README.md +++ b/packages/boot/app-boot/README.md @@ -64,7 +64,7 @@ Your machine-local preferences also live in the Harness home: - **`.env`** — your ordinary environment layers: the invoking directory's file outranks the Harness-home file, and both sit below the inherited environment. Variables that decide how the process starts (`PATH`, `DSH_*`, `XDG_*` and similar) are rejected from files: export them instead. The four proxy names (`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY`) in any letter case and the DeepSeek endpoint names (`DEEPSEEK_BASE_URL`, `DEEPSEEK_SEARCH_BASE_URL`) in exactly that spelling are accepted from the Harness-home file only, never from the invoking directory's, which arrives with a clone. For a non-product bin that just wants one directory's `.env`, a missing file is fine and an unloadable one prints one labelled warning line. - **`cordis.patch.yml`** — your tweak layer, applied after every bundle layer (per-profile first, then the home-level file, which therefore outranks it): replace one entry's whole config (restating the fields you keep), insert new entries, or interpolate `!!js` expressions at boot. A patch naming an entry that does not exist prints a stderr warning; an empty or comments-only file fails boot — disable the layer with `[]` instead. -The enabled `dsh-hmr` plugin watches the profile manifest and both user patch files, re-reads the ordered bundle layers, and applies the [reload failure policy](#startup-and-reload-failures). [DSH HMR](../hmr/README.md) serializes these reloads with [Plugin Manager](../plugin-manager/README.md) configuration writes; package operations run outside its queue. The launcher does not install HMR or watchers; disabled or absent HMR means changes require restart. +The enabled `dsh-hmr` plugin watches the profile manifest, both user patch files, and every `--patch` overlay file, re-reads the ordered bundle layers, and applies the [reload failure policy](#startup-and-reload-failures). [DSH HMR](../hmr/README.md) serializes these reloads with [Plugin Manager](../plugin-manager/README.md) configuration writes; package operations run outside its queue. The launcher does not install HMR or watchers; disabled or absent HMR means changes require restart, except that a Config Editor save applies the current contents of every patch and overlay file. Inserted plugin names may be absolute filesystem paths, file URLs, or package specifiers. Patch loading converts absolute paths and patch-relative `./` or `../` paths to file URLs within `insert` rows and their nested groups; existing-entry name assertions and replacement `config` values remain literal. @@ -101,7 +101,7 @@ After the Loader settles, app-boot warns when only optional entries are inactive | Failure pattern | Optional entry at startup | Required entry at startup | Later configuration HMR | |---|---|---|---| -| Root config or required overlay is missing, unreadable, malformed, or contains invalid entries | Stop startup | Stop startup | Malformed or invalid live patches are rejected without changing the running configuration; a valid edit applies | +| Root config or required overlay is missing, unreadable, malformed, or contains invalid entries | Stop startup | Stop startup | Missing, malformed, or invalid live patches and overlays are rejected without changing the running configuration; a valid edit applies | | Module import fails or module evaluation throws | Warn; continue | Stop startup | Report the error; keep successful siblings; a corrected import can activate | | Plugin config schema validation fails | Warn; continue | Stop startup | A new entry stays inactive; an existing entry retains its prior instance and config; a valid correction applies | | Config `!!js` evaluation throws | Warn; continue | Stop startup | Report the error; keep successful siblings; a valid correction can activate | @@ -133,7 +133,7 @@ This section explains how the outcomes above are realized and points at the code ### Design notes - **Runtime version.** `getDshRuntimeVersion()` reads this package's manifest through a filesystem path, including the executable's virtual filesystem; missing or invalid versions fail rather than bypassing compatibility checks. -- **Profile launch data.** `ctx.profileContext` contains only profile locations, startup bundle names, parsed invocation overlays and the telemetry opt-out value. `readProfilePatches()` composes the supplied startup profile or reads current files at those locations; callers schedule and apply the result. +- **Profile launch data.** `ctx.profileContext` contains only profile locations, startup bundle names, absolute invocation overlay paths and the telemetry opt-out value. `readProfilePatches()` composes the supplied startup profile or reads current files at those locations, and always rereads the overlay files; callers schedule and apply the result. Plugin Manager listings and Config Editor writes call it with or without HMR, so they see current overlay contents and fail while an overlay file is missing or invalid. - **Process-local module resolution.** The launcher installs the runtime resolution on Node's internal ESM and CommonJS resolvers before profile rows mount. Node still owns exports, conditions, subpaths, module caches, and error codes; routed ESM failures report the original importer. Explicit CommonJS `paths` always retain native lookup, including paths inside profiles. - **Linked directories.** A profile link to an external directory admits its importers to peer-aware ancestor lookup, even without its own `package.json`. At each `D/node_modules` position, current `D/package.json` peer names present in the runtime table use the runtime package; other names use the physical candidate. A nearer physical package precedes a later peer declaration, and a peer position needs no physical `node_modules`. Installation-scope package directories are excluded from linked interception; overlapping roots do not change the importer's lookup order ([rule](../../../.agents/notes/implemented/architecture/2026-09-19-profile-resolution-lookup-order.md)). - **Package metadata.** `ctx.pluginPackages.packageOf` locates the owning package without loading code or requiring an exported `package.json`; a subpath selects its package without validating that file. The installed runtime resolution owns selection even for a miss. Low-level embedders that install the service without one retain native lookup. Display metadata uses the separate entry-aware reader described above. diff --git a/packages/boot/app-boot/README.zh.md b/packages/boot/app-boot/README.zh.md index 2a9c53a38e..8d2d4adf5b 100644 --- a/packages/boot/app-boot/README.zh.md +++ b/packages/boot/app-boot/README.zh.md @@ -64,7 +64,7 @@ profile 导入插件前,DSH 会将其声明的 DSH 版本要求与 `getDshRunt - **`.env`**——你的普通环境层:调用目录的文件优先于 harness home 的文件,两者都低于继承环境。在文件中设置的进程启动变量(如 `PATH`、`DSH_*`、`XDG_*`)会被拒绝:请改为导出这些变量。四个代理名(`HTTP_PROXY`、`HTTPS_PROXY`、`ALL_PROXY`、`NO_PROXY`,大小写不限)和 DeepSeek 端点变量名(`DEEPSEEK_BASE_URL`、`DEEPSEEK_SEARCH_BASE_URL`,须按此拼写)只从 harness home 的文件接受,绝不从调用目录的文件接受——后者随 clone 一起到来。对于只想加载某个目录 `.env` 的非产品 bin,文件缺失不影响启动,文件无法加载时输出一行带标签的警告。 - **`cordis.patch.yml`**——你的 tweak 层,应用在所有组合包层之后(先应用逐 profile 的文件,再应用 home 级文件,因此后者优先级更高):替换某个条目的整个配置(重述你要保留的字段)、插入新条目,或在启动时插值 `!!js` 表达式。patch 指定的条目不存在时输出 stderr 警告;空文件或仅含注释的文件会导致启动失败——如需禁用该层,请改用 `[]`。 -启用的 `dsh-hmr` 插件会监视 profile manifest 与两份用户 patch 文件,重新读取按顺序排列的组合包层,并应用[重载失败策略](#startup-and-reload-failures)。[DSH HMR](../hmr/README.zh.md) 将这些重载与[插件管理器](../plugin-manager/README.zh.md)的配置写入串行化;包操作在其队列之外执行。启动器不安装 HMR 或监视器;HMR 被禁用或不存在时,更改需要重启。 +启用的 `dsh-hmr` 插件会监视 profile manifest、两份用户 patch 文件与每个 `--patch` overlay 文件,重新读取按顺序排列的组合包层,并应用[重载失败策略](#startup-and-reload-failures)。[DSH HMR](../hmr/README.zh.md) 将这些重载与[插件管理器](../plugin-manager/README.zh.md)的配置写入串行化;包操作在其队列之外执行。启动器不安装 HMR 或监视器;HMR 被禁用或不存在时,更改需要重启;例外是 Config Editor 保存时会应用所有 patch 与 overlay 文件的当前内容。 插入条目的插件名可以是绝对文件系统路径、文件 URL 或包标识符。patch 加载会把 `insert` 条目及其嵌套分组中的绝对路径以及相对于 patch 文件的 `./` 或 `../` 路径转换为文件 URL;对已有条目名称的断言及替换用的 `config` 值保持原样。 @@ -101,7 +101,7 @@ Loader 结算后,app-boot 在仅 optional 条目未激活时输出警告。如 | 失败模式 | Optional 条目启动时 | Required 条目启动时 | 后续配置 HMR | |---|---|---|---| -| 根配置或必需 overlay 缺失、不可读、格式错误,或包含无效条目 | 终止启动 | 终止启动 | 拒绝格式错误或无效的实时 patch,不改变运行中的配置;有效修改可以应用 | +| 根配置或必需 overlay 缺失、不可读、格式错误,或包含无效条目 | 终止启动 | 终止启动 | 拒绝缺失、格式错误或无效的实时 patch 与 overlay,不改变运行中的配置;有效修改可以应用 | | 模块 import 失败或模块求值抛出异常 | 警告;继续 | 终止启动 | 报告错误;保留成功的兄弟插件;修正 import 后可以激活 | | 插件配置 schema 校验失败 | 警告;继续 | 终止启动 | 新条目保持未激活;现有条目保留原实例与配置;有效修正可以应用 | | 配置 `!!js` 求值抛出异常 | 警告;继续 | 终止启动 | 报告错误;保留成功的兄弟插件;有效修正后可以激活 | @@ -133,7 +133,7 @@ Loader 结算后,app-boot 在仅 optional 条目未激活时输出警告。如 ### 设计说明 - **运行时版本。** `getDshRuntimeVersion()` 通过文件系统路径读取本包清单,也支持可执行文件内的虚拟文件系统;版本缺失或无效时会失败,而不会绕过兼容性检查。 -- **Profile 启动数据。** `ctx.profileContext` 只包含 profile 位置、启动时组合包名称、已解析的调用级 overlay 与遥测退出值。`readProfilePatches()` 组合传入的启动 profile,或读取这些位置上的当前文件;调用方负责调度和应用结果。 +- **Profile 启动数据。** `ctx.profileContext` 只包含 profile 位置、启动时组合包名称、调用级 overlay 的绝对路径与遥测退出值。`readProfilePatches()` 组合传入的启动 profile,或读取这些位置上的当前文件,并且总是重新读取 overlay 文件;调用方负责调度和应用结果。插件管理器的列表与 Config Editor 的写入无论是否启用 HMR 都调用它,因此会读到当前 overlay 内容,并在 overlay 文件缺失或无效时失败。 - **进程内模块解析。** launcher 在挂载 profile 条目前,将 runtime resolution 安装到 Node 的 ESM 与 CommonJS 内部 resolver。exports、conditions、子路径、模块缓存和错误码仍由 Node 负责;路由后的 ESM 失败报告原始 importer。显式 CommonJS `paths` 始终保留原生查询,包括指向 profile 内的路径。 - **链接目录。** profile 链接到树外目录时,其下的 importer 参与逐层 peer 查询,即使目标没有自身的 `package.json`。在每个 `D/node_modules` 位置,当前 `D/package.json` 的 peer 包名若存在于运行时表,就使用运行时包;其他包名查询物理候选。更近的物理包先于后续 peer 声明,peer 位置无需物理 `node_modules`。installation 作用域包目录不参与 linked 拦截,重叠 root 不改变 importer 的查询顺序([规则](../../../.agents/notes/implemented/architecture/2026-09-19-profile-resolution-lookup-order.zh.md))。 - **包元数据。** `ctx.pluginPackages.packageOf` 定位所属包,不加载代码,也不要求导出 `package.json`;子路径选择其所属包,不校验该文件。安装 runtime resolution 后,即使查询未命中也以其选包规则为准。仅安装服务而不提供 runtime resolution 的底层嵌入方保留原生查询。展示元数据使用上文另述的入口感知读取器。 diff --git a/packages/boot/app-boot/src/profile-context.ts b/packages/boot/app-boot/src/profile-context.ts index e2ebfad5ce..32e94426fa 100644 --- a/packages/boot/app-boot/src/profile-context.ts +++ b/packages/boot/app-boot/src/profile-context.ts @@ -1,7 +1,7 @@ /** Launcher-owned profile locations and composition inputs. */ import { join } from 'node:path' import { composeEntries, loadProfileDirectory, PROFILE_PATCH_FILENAME, type Profile } from './profile.ts' -import { loadOptionalPatches } from './index.ts' +import { loadOptionalPatches, loadOverlayPatches } from './index.ts' import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include' /** Application-owned package manager executable; environment applies only to package operations. */ @@ -23,8 +23,8 @@ export interface ProfileContext { readonly home: string /** Bundle packages used to start this process, before any persisted edits. */ readonly startedBundles: readonly string[] - /** Parsed command-line overlays, applied above profile and home patches. */ - readonly overlays: readonly PatchOptions[] + /** Absolute command-line overlay files in argv order, read on every composition and applied above profile and home patches. */ + readonly overlayPaths: readonly string[] /** Launch-time DSH_TELEMETRY_DISABLED value; any non-empty value opts out. */ readonly telemetryDisabledEnv: string | undefined } @@ -65,18 +65,19 @@ export function readBundlePatches(binName: string, context: ProfileContext, init return profile.layers.flatMap(layer => layer.patches) } -/** Read current bundle and user layers with the launch-time overlays. +/** Read current bundle, user, and command-line overlay layers. * @param binName Diagnostic prefix for malformed or missing configuration. * @param context Data supplied by the profile launcher. * @param initialProfile Already loaded startup profile; omitted reads the current files. * @returns Detached ordered patches; this function does not update the Loader. + * @throws When a present patch file or any overlay file is missing, unreadable, or not a patch list. */ export function readProfilePatches(binName: string, context: ProfileContext, initialProfile?: Profile): PatchOptions[] { const patches = structuredClone([ ...readBundlePatches(binName, context, initialProfile), ...(initialProfile?.patches ?? loadOptionalPatches(binName, context.patchPath) ?? []), ...(loadOptionalPatches(binName, join(context.home, PROFILE_PATCH_FILENAME)) ?? []), - ...context.overlays, + ...context.overlayPaths.flatMap(path => loadOverlayPatches(binName, path)), ]) const telemetryPatch = resolveTelemetryPatch(context.telemetryDisabledEnv, composeEntries([patches]).some(row => row.id === TELEMETRY_ROW_ID)) diff --git a/packages/boot/app-boot/tests/compatibility-preflight.spec.ts b/packages/boot/app-boot/tests/compatibility-preflight.spec.ts index 0fcf850d56..7b97e4c9a8 100644 --- a/packages/boot/app-boot/tests/compatibility-preflight.spec.ts +++ b/packages/boot/app-boot/tests/compatibility-preflight.spec.ts @@ -51,7 +51,7 @@ export function apply() { record('apply:${name}') } const profile: ProfileContext = { name: 'preflight', dir, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: join(dir, 'package.json'), cwd: dir, home: dir, - startedBundles: [], overlays: [], telemetryDisabledEnv: undefined, + startedBundles: [], overlayPaths: [], telemetryDisabledEnv: undefined, } const configPath = join(dir, 'cordis.yml') writeFileSync(configPath, '[]\n') diff --git a/packages/boot/app-boot/tests/profile.spec.ts b/packages/boot/app-boot/tests/profile.spec.ts index 7122ff80f3..c935206adf 100644 --- a/packages/boot/app-boot/tests/profile.spec.ts +++ b/packages/boot/app-boot/tests/profile.spec.ts @@ -198,7 +198,7 @@ describe('resolveProfileDir', () => { }) }) -it('composes current files from profile data and retains launch overlay and telemetry precedence', () => { +it('composes current profile, home, and overlay files with telemetry precedence', () => { const home = tmp() const installAnchor = stageInstallation({ base: { patch: '- insert:\n - id: session-telemetry-otel\n name: telemetry\n' } }) const dir = resolveProfileDir('test', home) @@ -206,23 +206,26 @@ it('composes current files from profile data and retains launch overlay and tele const patchPath = join(dir, 'application.patch.yml') writeFileSync(patchPath, '- id: session-telemetry-otel\n disabled: true\n') writeFileSync(join(home, PROFILE_PATCH_FILENAME), '- id: session-telemetry-otel\n disabled: false\n') + const overlayPath = join(home, 'overlay.yml') + writeFileSync(overlayPath, '- id: session-telemetry-otel\n disabled: false\n') const context = { name: 'test', dir, patchPath, installAnchor, home, cwd: home, startedBundles: ['base'], - overlays: [{ id: 'session-telemetry-otel', disabled: false }], telemetryDisabledEnv: 'false', + overlayPaths: [overlayPath], telemetryDisabledEnv: 'false', } expect(composeEntries([readProfilePatches('test', context)])[0]?.disabled).toBe(true) const enabled = { ...context, telemetryDisabledEnv: undefined } expect(composeEntries([readProfilePatches('test', enabled)])[0]?.disabled).toBe(false) - const patches = readProfilePatches('test', enabled) - patches.at(-1)!.disabled = true - expect(context.overlays[0]?.disabled).toBe(false) + writeFileSync(overlayPath, '- id: session-telemetry-otel\n disabled: true\n') + expect(composeEntries([readProfilePatches('test', enabled)])[0]?.disabled).toBe(true) + rmSync(overlayPath) + expect(() => readProfilePatches('test', enabled)).toThrow(`failed to read overlay ${overlayPath}`) writeFileSync(join(home, PROFILE_PATCH_FILENAME), '- id: session-telemetry-otel\n disabled: true\n') - expect(composeEntries([readProfilePatches('test', { ...enabled, overlays: [] })])[0]?.disabled).toBe(true) + expect(composeEntries([readProfilePatches('test', { ...enabled, overlayPaths: [] })])[0]?.disabled).toBe(true) writeFileSync(join(home, PROFILE_PATCH_FILENAME), '[]\n') - expect(composeEntries([readProfilePatches('test', { ...enabled, overlays: [] })])[0]?.disabled).toBe(true) + expect(composeEntries([readProfilePatches('test', { ...enabled, overlayPaths: [] })])[0]?.disabled).toBe(true) writeFileSync(patchPath, '- id: session-telemetry-otel\n disabled: false\n') - expect(composeEntries([readProfilePatches('test', { ...enabled, overlays: [] })])[0]?.disabled).toBe(false) + expect(composeEntries([readProfilePatches('test', { ...enabled, overlayPaths: [] })])[0]?.disabled).toBe(false) }) describe('initProfile', () => { diff --git a/packages/boot/hmr/README.i18n.yaml b/packages/boot/hmr/README.i18n.yaml index 776c0d0fe7..6f0b6aab63 100644 --- a/packages/boot/hmr/README.i18n.yaml +++ b/packages/boot/hmr/README.i18n.yaml @@ -21,8 +21,8 @@ en: 11ef18c6d08f39f3 zh: 2911cdd03ff3747d /deepseek-ai-dsh-hmr/understand-the-implementation: - en: bd608f418630317f - zh: 053fa77a3fa571a9 + en: a1eede170f8754f0 + zh: dd2bfef9ad06ee3b /deepseek-ai-dsh-hmr/model-experience: en: 215e7ba838619b7b zh: a311da3843709f90 diff --git a/packages/boot/hmr/README.md b/packages/boot/hmr/README.md index 8d2270b4a1..a5399d6ac4 100644 --- a/packages/boot/hmr/README.md +++ b/packages/boot/hmr/README.md @@ -56,9 +56,9 @@ Profile recompositions run by HMR's profile watches and by Plugin Manager also r
Implementation internals — click to expand -`watchConfig()` registers an awaited configuration handler and watches only its target path and required parent directories; sibling files, including temporary writer locks, are excluded before native watcher creation. `runExclusive()` serializes configuration changes and Loader updates with automatic reloads and rejects nested transactions. Package installation and removal run outside this queue. HMR does not acquire the package writer lock; manifest notifications reload only when the ordered `dsh.profile.bundles` list changes. Profile and home patch changes also trigger recomposition. File events received during a configuration transaction are processed afterward. Include refreshes and profile reconciliation reach plugins through ordinary Loader entry updates; Loader commits volatile-only changes in place. +`watchConfig()` registers an awaited configuration handler and watches only its target path and required parent directories; sibling files, including temporary writer locks, are excluded before native watcher creation. `runExclusive()` serializes configuration changes and Loader updates with automatic reloads and rejects nested transactions. Package installation and removal run outside this queue. HMR does not acquire the package writer lock; manifest notifications reload only when the ordered `dsh.profile.bundles` list changes. Profile, home, and `--patch` overlay file changes also trigger recomposition. File events received during a configuration transaction are processed afterward. Include refreshes and profile reconciliation reach plugins through ordinary Loader entry updates; Loader commits volatile-only changes in place. -App-boot owns profile parsing and patch precedence. HMR reads the launcher’s data-only `profileContext`, registers the profile manifest and both user patch watches during initialization, and waits for application readiness before processing changes. Its disposal closes the watchers and cancels reloads waiting for startup. Configuration watchers start outside the active transaction context so later notifications can enter the queue. +App-boot owns profile parsing and patch precedence. HMR reads the launcher’s data-only `profileContext`, registers watches for the profile manifest, both user patches, and each `--patch` overlay during initialization, watching a file named under several spellings once, and waits for application readiness before processing changes. Its disposal closes the watchers and cancels reloads waiting for startup. Configuration watchers start outside the active transaction context so later notifications can enter the queue. `reconcileProfile()` is shared by HMR’s profile watches and Plugin Manager; callers hold `runExclusive()`. Config Editor recomposes through app-boot without replacing modules. App-boot prepares and preflights the generation before caches or running entries change. diff --git a/packages/boot/hmr/README.zh.md b/packages/boot/hmr/README.zh.md index 21044fe7d1..ceef662a95 100644 --- a/packages/boot/hmr/README.zh.md +++ b/packages/boot/hmr/README.zh.md @@ -56,9 +56,9 @@ HMR 的 profile 监听和 Plugin Manager 执行的 profile 重新组合,还会
实现细节——点击展开 -`watchConfig()` 注册会被等待的配置处理器,仅监听目标路径及必要的父目录;同级文件(包括临时写锁)在创建原生 watcher 前即被排除。`runExclusive()` 将配置变更、Loader 更新与自动重载串行化,并拒绝嵌套事务。包安装和删除在该队列之外执行。HMR 不获取包操作写锁;manifest 通知仅在有序的 `dsh.profile.bundles` 列表变化时触发重载。profile 与 home patch 变化也会触发重新组合。配置事务期间收到的文件事件在事务结束后处理。 Include 刷新和 profile 重载都通过普通的 Loader 条目更新到达插件;仅 volatile 变化由 Loader 就地提交。 +`watchConfig()` 注册会被等待的配置处理器,仅监听目标路径及必要的父目录;同级文件(包括临时写锁)在创建原生 watcher 前即被排除。`runExclusive()` 将配置变更、Loader 更新与自动重载串行化,并拒绝嵌套事务。包安装和删除在该队列之外执行。HMR 不获取包操作写锁;manifest 通知仅在有序的 `dsh.profile.bundles` 列表变化时触发重载。profile、home 与 `--patch` overlay 文件的变化也会触发重新组合。配置事务期间收到的文件事件在事务结束后处理。 Include 刷新和 profile 重载都通过普通的 Loader 条目更新到达插件;仅 volatile 变化由 Loader 就地提交。 -App-boot 负责 profile 解析和 patch 优先级规则。HMR 读取启动器提供的纯数据 `profileContext`,在初始化时注册 profile manifest 和两份用户 patch 的监听,并等待应用就绪后处理更改。销毁 HMR 时会关闭监听器并取消等待启动的重载。配置监听器在当前事务上下文之外启动,使后续通知可以进入队列。 +App-boot 负责 profile 解析和 patch 优先级规则。HMR 读取启动器提供的纯数据 `profileContext`,在初始化时注册 profile manifest、两份用户 patch 与每个 `--patch` overlay 的监听,以不同写法指向同一文件的路径只监听一次,并等待应用就绪后处理更改。销毁 HMR 时会关闭监听器并取消等待启动的重载。配置监听器在当前事务上下文之外启动,使后续通知可以进入队列。 `reconcileProfile()` 由 HMR 的 profile 监听和 Plugin Manager 共用;调用方持有 `runExclusive()`。Config Editor 通过 app-boot 重新组合,不替换模块。app-boot 在缓存或运行中条目发生变化前准备新一代组合并执行预检。 diff --git a/packages/boot/hmr/src/index.ts b/packages/boot/hmr/src/index.ts index 112732ca77..3d2ca35735 100644 --- a/packages/boot/hmr/src/index.ts +++ b/packages/boot/hmr/src/index.ts @@ -382,7 +382,14 @@ class Hmr extends Service { }) yield () => { unsubscribe(); started.resolve(false); return Promise.resolve() } const manifestPath = join(profile.dir, 'package.json') - const patchFiles = [profile.patchPath, join(profile.home, PROFILE_PATCH_FILENAME)] + // A file named by several layers or repeated `--patch` options, under any spelling, is watched and compared once. + const canonicalFiles = new Set() + const patchFiles = [profile.patchPath, join(profile.home, PROFILE_PATCH_FILENAME), ...profile.overlayPaths].filter((filename) => { + const canonical = canonicalPath(filename) + if (canonicalFiles.has(canonical)) return false + canonicalFiles.add(canonical) + return true + }) let lastInputs: string | undefined let lastBundles = JSON.stringify(profile.startedBundles) const refresh = async (manifestOnly: boolean): Promise => { diff --git a/packages/boot/hmr/tests/package-reload.spec.ts b/packages/boot/hmr/tests/package-reload.spec.ts index cb084b3deb..0e0d01d329 100644 --- a/packages/boot/hmr/tests/package-reload.spec.ts +++ b/packages/boot/hmr/tests/package-reload.spec.ts @@ -129,7 +129,7 @@ async function fixture(bundles = ['addon', 'other'], before?: (home: string, dir await before?.(home, dir) const profile: ProfileContext = { name: 'test', dir, patchPath: join(dir, 'cordis.patch.yml'), home, cwd: home, - installAnchor: join(home, 'package.json'), startedBundles: bundles, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), startedBundles: bundles, overlayPaths: [], telemetryDisabledEnv: undefined, } writeFileSync(profile.patchPath, JSON.stringify([{ insert: [ { id: 'timer', name: 'cordis:timer' }, diff --git a/packages/boot/hmr/tests/profile.spec.ts b/packages/boot/hmr/tests/profile.spec.ts index e096e6dbc5..7d92da88c3 100644 --- a/packages/boot/hmr/tests/profile.spec.ts +++ b/packages/boot/hmr/tests/profile.spec.ts @@ -1,5 +1,5 @@ /** Profile watches share HMR's queue and readiness barrier without waiting for package installation. */ -import { mkdtempSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs' +import { mkdtempSync, mkdirSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { pathToFileURL } from 'node:url' @@ -23,14 +23,32 @@ vi.mock('chokidar', async (original) => { } } }) -async function fixture(beforeWatch?: (profile: ProfileContext) => void) { +/** An overlay file's content, or the empty home patch named directly or through a linked directory. */ +type Overlay = string | { home: 'path' | 'link' } + +/** Write each overlay beside the home patch. */ +async function fixture(beforeWatch?: (profile: ProfileContext) => void, overlays: readonly Overlay[] = []) { const home = realpathSync(mkdtempSync(join(tmpdir(), 'hmr-profile-'))) const dir = join(home, 'profiles', 'test') initProfile(dir, []) writeFileSync(join(dir, 'cordis.yml'), '[]\n') + const homePatch = join(home, 'cordis.patch.yml') + const overlayPaths = overlays.map((overlay, index) => { + if (typeof overlay === 'string') { + const path = join(home, `overlay-${index}.yml`) + writeFileSync(path, overlay) + return path + } + writeFileSync(homePatch, '[]\n') + if (overlay.home === 'path') return homePatch + // A directory junction aliases the home patch on every platform without file-symlink privileges. + const alias = join(home, `alias-${index}`) + symlinkSync(home, alias, 'junction') + return join(alias, 'cordis.patch.yml') + }) const profile: ProfileContext = { name: 'test', dir, patchPath: join(dir, 'cordis.patch.yml'), home, cwd: home, - installAnchor: join(home, 'package.json'), startedBundles: [], overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), startedBundles: [], overlayPaths, telemetryDisabledEnv: undefined, } const rows = [{ insert: [ { id: 'timer', name: 'cordis:timer' }, @@ -49,7 +67,8 @@ async function fixture(beforeWatch?: (profile: ProfileContext) => void) { host.loader.builtins.probe = { apply(ctx: Context, config: { value: string }) { ctx.provide('profileProbe', config.value) } } }) onTestFinished(async () => { await ctx.fiber.dispose(); rmSync(home, { recursive: true, force: true }) }) - const configWatches = watchers.slice(start, start + 3) + // Profile, home, and overlay patch watches precede the manifest watch. + const configWatches = watchers.slice(start, start + 3 + overlayPaths.length) const emit = (index: number, filename: string) => { configWatches[index]!.emit('change', filename) } const drain = () => ctx.hmr.runExclusive(async () => {}) return { ctx, profile, dir, home, emit, drain, commit: () => commit?.() } @@ -205,3 +224,50 @@ it('applies a patch edited after boot parsing but before watcher registration', await f.drain() expect(f.ctx.get('profileProbe')).toBe('edited-during-boot') }) + +it('applies edited --patch overlays above profile and home patches in argv order', async () => { + const f = await fixture(undefined, ['- id: probe\n config: { value: first }\n', '[]\n']) + f.commit() + expect(f.ctx.get('profileProbe')).toBe('first') + const [first, second] = f.profile.overlayPaths + writeFileSync(second!, '- id: probe\n config: { value: second }\n') + f.emit(3, second!) + await f.drain() + expect(f.ctx.get('profileProbe')).toBe('second') + writeFileSync(join(f.home, 'cordis.patch.yml'), '- id: probe\n config: { value: home }\n') + writeFileSync(second!, '[]\n') + f.emit(1, join(f.home, 'cordis.patch.yml')) + await f.drain() + expect(f.ctx.get('profileProbe')).toBe('first') + writeFileSync(first!, '[]\n') + f.emit(2, first!) + await f.drain() + expect(f.ctx.get('profileProbe')).toBe('home') +}) + +it('keeps the running configuration when an overlay file disappears and recovers when it returns', async () => { + const f = await fixture(undefined, ['- id: probe\n config: { value: overlay }\n']) + f.commit() + const warn = vi.spyOn(f.ctx.logger, 'warn').mockImplementation(() => {}) + onTestFinished(() => { warn.mockRestore() }) + const [overlay] = f.profile.overlayPaths + rmSync(overlay!) + f.emit(2, overlay!) + await f.drain() + expect(warn.mock.calls.some(([reason]) => reason instanceof Error && reason.message.includes(`failed to read overlay ${overlay}`))).toBe(true) + expect(f.ctx.get('profileProbe')).toBe('overlay') + writeFileSync(overlay!, '- id: probe\n config: { value: restored }\n') + f.emit(2, overlay!) + await f.drain() + expect(f.ctx.get('profileProbe')).toBe('restored') +}) + +it('watches a home patch also named by repeated or linked-directory overlays once', async () => { + const f = await fixture(undefined, [{ home: 'path' }, { home: 'path' }, { home: 'link' }]) + f.commit() + const homePatch = join(f.home, 'cordis.patch.yml') + writeFileSync(homePatch, '- id: probe\n config: { value: home }\n') + f.emit(1, homePatch) + await f.drain() + expect(f.ctx.get('profileProbe')).toBe('home') +}) diff --git a/packages/boot/plugin-manager/tests/bundle-detail.spec.ts b/packages/boot/plugin-manager/tests/bundle-detail.spec.ts index 732f08e6aa..8aa162e5f3 100644 --- a/packages/boot/plugin-manager/tests/bundle-detail.spec.ts +++ b/packages/boot/plugin-manager/tests/bundle-detail.spec.ts @@ -63,7 +63,7 @@ async function fixture(config: Config = {}) { writeFileSync(join(dir, 'cordis.yml'), '[]\n') const profile: ProfileContext = { name: 'test', startedBundles: loadProfileDirectory('test', dir, join(home, 'package.json')).layers.map(layer => layer.packageName), - dir, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + dir, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, } const ctx = await boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (root) => { owner = root diff --git a/packages/boot/plugin-manager/tests/manager.spec.ts b/packages/boot/plugin-manager/tests/manager.spec.ts index 6ab1cf8029..b36e4ae14f 100644 --- a/packages/boot/plugin-manager/tests/manager.spec.ts +++ b/packages/boot/plugin-manager/tests/manager.spec.ts @@ -63,13 +63,14 @@ async function fixture(reload: 'live' | 'startup' = 'live', overlay = false, pre writeFileSync(join(dir, 'package.json'), JSON.stringify(manifest)) writeFileSync(join(dir, 'cordis.yml'), '[]\n') prepareFiles?.(dir) - const overlays: PatchOptions[] = overlay ? [{ id: 'managed', disabled: true }] : [] + const overlayPath = join(home, 'overlay.patch.yml') + writeFileSync(overlayPath, JSON.stringify(overlay ? [{ id: 'managed', disabled: true }] : [])) const profile: ProfileContext = { name: 'test', ...(packageManager === undefined ? {} : { packageManager }), startedBundles: loadProfileDirectory('test', dir, anchor).layers.map(layer => layer.packageName), dir, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: anchor, cwd: home, home, - overlays, telemetryDisabledEnv: undefined, + overlayPaths: [overlayPath], telemetryDisabledEnv: undefined, } const ctx = await boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (ctx) => { owner = ctx @@ -90,7 +91,7 @@ async function fixture(reload: 'live' | 'startup' = 'live', overlay = false, pre stopHmr = () => owner.dispose() await ctx.hmr.runExclusive(async () => {}) } - return { ctx, dir, manager: ctx.pluginManager, bundle, profile, stopHmr, overlays, connection, gitConnection } + return { ctx, dir, manager: ctx.pluginManager, bundle, profile, stopHmr, overlayPath, connection, gitConnection } } it.each(['live', 'startup'] as const)('refuses an unsupported bundle before saving or applying it with %s reload', async (reload) => { @@ -736,6 +737,15 @@ it('reports an overlay overriding a saved plugin toggle', async () => { expect(await manager.setPluginEnabled(id, true)).toMatchObject({ changed: false, application: 'overridden' }) }) +it('lists plugins from current overlay files in a startup-only profile', async () => { + const { manager, overlayPath } = await fixture('startup') + const id = (await manager.listPlugins()).find(row => row.patchId === 'managed')!.entryId + rmSync(overlayPath) + await expect(manager.listPlugins()).rejects.toThrow(`failed to read overlay ${overlayPath}`) + writeFileSync(overlayPath, '[]\n') + expect((await manager.listPlugins()).some(row => row.entryId === id)).toBe(true) +}) + it('saves startup-only toggles and refuses removal of currently used packages', async () => { const { manager } = await fixture('startup') const id = (await manager.listPlugins()).find(row => row.patchId === 'managed')!.entryId @@ -1463,9 +1473,10 @@ it('omits installation-owned plain packages from the bundle inventory', async () }) it('does not delete a bundle retained by a higher-priority overlay', async () => { - const { ctx, manager, overlays, dir } = await fixture() + const { ctx, manager, overlayPath, dir } = await fixture() const entry = [...ctx.loader.entries()].find(row => row.id === 'include:managed')! - overlays.push({ insert: [{ ...entry.options }] }) + const retained: PatchOptions[] = [{ insert: [{ ...entry.options }] }] + writeFileSync(overlayPath, JSON.stringify(retained)) const remove = vi.spyOn(operations, 'runProfilePnpm') onTestFinished(() => { remove.mockRestore() }) expect(await manager.removeBundle('extra')).toMatchObject({ changed: true, application: 'failed', error: { code: 'bundle-in-use' } }) diff --git a/packages/boot/plugin-manager/tests/package-reload.spec.ts b/packages/boot/plugin-manager/tests/package-reload.spec.ts index b5569a6229..0b63af8382 100644 --- a/packages/boot/plugin-manager/tests/package-reload.spec.ts +++ b/packages/boot/plugin-manager/tests/package-reload.spec.ts @@ -123,7 +123,7 @@ export function apply(ctx) { const loaded = loadProfileDirectory('test', dir, installAnchor) const profile: ProfileContext = { name: 'test', dir, patchPath: join(dir, 'cordis.patch.yml'), installAnchor, cwd: home, home, - startedBundles: loaded.layers.map(layer => layer.packageName), overlays: [], telemetryDisabledEnv: undefined, + startedBundles: loaded.layers.map(layer => layer.packageName), overlayPaths: [], telemetryDisabledEnv: undefined, } const resolution = await createRuntimeResolution({ installAnchor, profile: loaded, home }) const trace: string[] = [] diff --git a/packages/boot/plugin-manager/tests/patch.spec.ts b/packages/boot/plugin-manager/tests/patch.spec.ts index 9580da1e52..34538377c4 100644 --- a/packages/boot/plugin-manager/tests/patch.spec.ts +++ b/packages/boot/plugin-manager/tests/patch.spec.ts @@ -23,7 +23,7 @@ async function fixture(text?: string, rows: object[] = []): Promise { diff --git a/packages/boot/plugin-market/tests/configuration.spec.ts b/packages/boot/plugin-market/tests/configuration.spec.ts index 321fff1e1b..3c26936795 100644 --- a/packages/boot/plugin-market/tests/configuration.spec.ts +++ b/packages/boot/plugin-market/tests/configuration.spec.ts @@ -30,7 +30,7 @@ it('saves index sources without remounting, announces them, and restores them at writeFileSync(join(dir, 'cordis.yml'), '[]\n') const profile: ProfileContext = { name: 'test', startedBundles: ['test-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, } const start = () => boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (root) => { root.provide('profileContext', profile) @@ -99,7 +99,7 @@ it('reads a market entry detail document and serves its images through the compo writeFileSync(join(dir, 'cordis.yml'), '- name: cordis:connection\n') const profile: ProfileContext = { name: 'test', startedBundles: ['test-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, } ctx = await boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (root) => { root.provide('profileContext', profile) diff --git a/packages/boot/plugin-market/tests/detail-remote.spec.ts b/packages/boot/plugin-market/tests/detail-remote.spec.ts index ddcf9d1333..86bbcadf94 100644 --- a/packages/boot/plugin-market/tests/detail-remote.spec.ts +++ b/packages/boot/plugin-market/tests/detail-remote.spec.ts @@ -79,7 +79,7 @@ async function mount(options: { profile?: boolean; connection?: boolean } = {}) if (options.profile === true) { ctx.provide('profileContext', { name: 'test', startedBundles: [], dir: join(home, 'profile'), patchPath: join(home, 'profile', 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, }) } const routes = new Map Promise>() diff --git a/packages/bundle/web-app/tests/browser-defaults.spec.ts b/packages/bundle/web-app/tests/browser-defaults.spec.ts index 73ee9b1a82..1aef765ddf 100644 --- a/packages/bundle/web-app/tests/browser-defaults.spec.ts +++ b/packages/bundle/web-app/tests/browser-defaults.spec.ts @@ -26,7 +26,7 @@ it.each([ if (profile !== undefined) { ctx.provide('profileContext', { name: profile, dir: '/profile', patchPath: '/profile/cordis.patch.yml', installAnchor: '/profile/package.json', - cwd: '/workspace', home: '/home', startedBundles: [], overlays: [], telemetryDisabledEnv: undefined, + cwd: '/workspace', home: '/home', startedBundles: [], overlayPaths: [], telemetryDisabledEnv: undefined, }) } ctx.baseUrl = 'file:///' diff --git a/packages/bundle/web-app/tests/desktop-office.spec.ts b/packages/bundle/web-app/tests/desktop-office.spec.ts index 33bdcd81da..b6b2d23559 100644 --- a/packages/bundle/web-app/tests/desktop-office.spec.ts +++ b/packages/bundle/web-app/tests/desktop-office.spec.ts @@ -71,7 +71,7 @@ async function boot(profile: string, primaryRuntime: (root: string) => string | onTestFinished(() => ctx.fiber.dispose()) ctx.provide('profileContext', { name: profile, dir: '/profile', patchPath: '/profile/cordis.patch.yml', installAnchor: join(root, 'package.json'), - cwd: workspace, home: '/home', startedBundles: [], overlays: [], telemetryDisabledEnv: undefined, + cwd: workspace, home: '/home', startedBundles: [], overlayPaths: [], telemetryDisabledEnv: undefined, }) ctx.provide('dshHomePath', dshHomePath) provideWorkingDirectoryFixture(ctx, workspace) diff --git a/packages/bundle/web-app/tests/product-analytics.spec.ts b/packages/bundle/web-app/tests/product-analytics.spec.ts index d9bf9f31dd..1531aaecad 100644 --- a/packages/bundle/web-app/tests/product-analytics.spec.ts +++ b/packages/bundle/web-app/tests/product-analytics.spec.ts @@ -26,7 +26,7 @@ it.each(['desktop', 'web'])('limits collection and its shutdown to the Desktop l onTestFinished(() => ctx.fiber.dispose()) ctx.provide('profileContext', { name: profile, dir: '/profile', patchPath: '/profile/cordis.patch.yml', installAnchor: '/profile/package.json', - cwd: '/workspace', home: '/home', startedBundles: [], overlays: [], telemetryDisabledEnv: undefined, + cwd: '/workspace', home: '/home', startedBundles: [], overlayPaths: [], telemetryDisabledEnv: undefined, }) const identity = vi.fn().mockResolvedValue(undefined) ctx.provide('deepseekAccount', { getDeviceIdentity: identity } as never) diff --git a/packages/experimental/creation-recommendations/tests/loader-composition.spec.ts b/packages/experimental/creation-recommendations/tests/loader-composition.spec.ts index 7295c47cb4..4d30d34d4e 100644 --- a/packages/experimental/creation-recommendations/tests/loader-composition.spec.ts +++ b/packages/experimental/creation-recommendations/tests/loader-composition.spec.ts @@ -54,7 +54,7 @@ it.each(['portable-bundle', 'foreign-nested-row'] as const)('validates and insta const profile: ProfileContext = { name: 'test', dir, home, cwd: home, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: anchor, startedBundles: loadProfileDirectory('test', dir, anchor).layers.map(layer => layer.packageName), - overlays: [], telemetryDisabledEnv: undefined, + overlayPaths: [], telemetryDisabledEnv: undefined, } const starts: SubagentActivationSpec[] = [] const ctx = await boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (ctx) => { diff --git a/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts b/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts index 21ac4dd895..5c8a4d26c5 100644 --- a/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts +++ b/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts @@ -1077,7 +1077,7 @@ async function permissionProfile(allowedApps: Array<{ id: string; name: string; await writeFile(join(dir, 'cordis.yml'), '[]\n') const profile: ProfileContext = { name: 'test', startedBundles: ['permission-fixture-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: join(home, 'package.json'), cwd: home, home, - overlays: [], telemetryDisabledEnv: undefined } + overlayPaths: [], telemetryDisabledEnv: undefined } f.ctx.baseUrl = pathToFileURL(home).href + '/' f.ctx.provide('profileContext', profile) f.ctx.provide('appReady', { onReady: (listener: () => void) => { listener(); return () => {} } }) diff --git a/packages/experimental/personalized-recommendations/tests/bundle.spec.ts b/packages/experimental/personalized-recommendations/tests/bundle.spec.ts index e3e9d5d588..4f80203b8e 100644 --- a/packages/experimental/personalized-recommendations/tests/bundle.spec.ts +++ b/packages/experimental/personalized-recommendations/tests/bundle.spec.ts @@ -89,7 +89,7 @@ it('addresses every row through its own id and switches the shared card service const profile: ProfileContext = { name: 'test', dir, home, cwd: home, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: anchor, startedBundles: loadProfileDirectory('test', dir, anchor).layers.map(layer => layer.packageName), - overlays: [], telemetryDisabledEnv: undefined, + overlayPaths: [], telemetryDisabledEnv: undefined, } const ctx = await boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (ctx) => { owner = ctx diff --git a/packages/experimental/plugin-recommendations/tests/loader-composition.spec.ts b/packages/experimental/plugin-recommendations/tests/loader-composition.spec.ts index 196dbe9ef0..06c6a59d75 100644 --- a/packages/experimental/plugin-recommendations/tests/loader-composition.spec.ts +++ b/packages/experimental/plugin-recommendations/tests/loader-composition.spec.ts @@ -60,7 +60,7 @@ it.each(['normal', 'consumer-unload'] as const)('enables through the real Loader const profile: ProfileContext = { name: 'test', dir, home, cwd: home, patchPath: join(dir, 'cordis.patch.yml'), installAnchor: anchor, startedBundles: loadProfileDirectory('test', dir, anchor).layers.map(layer => layer.packageName), - overlays: [], telemetryDisabledEnv: undefined, + overlayPaths: [], telemetryDisabledEnv: undefined, } const ctx = await boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (ctx) => { owner = ctx diff --git a/packages/experimental/speech-to-text/tests/configuration.spec.ts b/packages/experimental/speech-to-text/tests/configuration.spec.ts index 05a2b97f35..1835bfdbaa 100644 --- a/packages/experimental/speech-to-text/tests/configuration.spec.ts +++ b/packages/experimental/speech-to-text/tests/configuration.spec.ts @@ -23,7 +23,7 @@ it('saves language and provider preferences without remounting and restores them writeFileSync(join(dir, 'cordis.yml'), '[]\n') const profile: ProfileContext = { name: 'test', startedBundles: ['test-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, } const start = () => boot('test', join(dir, 'cordis.yml'), readProfilePatches('test', profile), (root) => { root.provide('profileContext', profile) diff --git a/packages/experimental/webworker-runtime/src/worker-host.ts b/packages/experimental/webworker-runtime/src/worker-host.ts index 5f19a032c3..eaf801ac1b 100644 --- a/packages/experimental/webworker-runtime/src/worker-host.ts +++ b/packages/experimental/webworker-runtime/src/worker-host.ts @@ -443,7 +443,7 @@ function prepareProfile( const profile: ProfileContext = { name: loaded.name, dir: loaded.dir, patchPath: loaded.patchPath, installAnchor, cwd: root, home, startedBundles: loaded.layers.map(layer => layer.packageName), - overlays: [], telemetryDisabledEnv: env.DSH_TELEMETRY_DISABLED, + overlayPaths: [], telemetryDisabledEnv: env.DSH_TELEMETRY_DISABLED, } return { patches: appBoot.readProfilePatches(BIN_NAME, profile, loaded), profile, environment } } diff --git a/packages/extensions/tool-cordis/src/api-catalog.ts b/packages/extensions/tool-cordis/src/api-catalog.ts index 0a98e1468c..60d9618528 100644 --- a/packages/extensions/tool-cordis/src/api-catalog.ts +++ b/packages/extensions/tool-cordis/src/api-catalog.ts @@ -2727,8 +2727,8 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [ parameters: [], }, { - signature: 'readonly overlays: readonly PatchOptions[]', - description: 'Parsed command-line overlays, applied above profile and home patches.', + signature: 'readonly overlayPaths: readonly string[]', + description: 'Absolute command-line overlay files in argv order, read on every composition and applied above profile and home patches.', parameters: [], }, { diff --git a/packages/mcp/mcp-manager/tests/profile-fixture.ts b/packages/mcp/mcp-manager/tests/profile-fixture.ts index bb7f7833d9..224e4969be 100644 --- a/packages/mcp/mcp-manager/tests/profile-fixture.ts +++ b/packages/mcp/mcp-manager/tests/profile-fixture.ts @@ -38,7 +38,7 @@ export async function managerProfile(ctx: Context, options: { id?: string; base? writeFileSync(join(dir, 'cordis.yml'), '[]\n') const profile: ProfileContext = { name: 'test', startedBundles: ['test-mcp-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, } if (options.user !== undefined) writeFileSync(profile.patchPath, JSON.stringify([{ id, config: options.user }])) const start = async (context: Context) => { diff --git a/packages/preset/agent-preset-registry/tests/mount.spec.ts b/packages/preset/agent-preset-registry/tests/mount.spec.ts index f669058d92..24cc03ba73 100644 --- a/packages/preset/agent-preset-registry/tests/mount.spec.ts +++ b/packages/preset/agent-preset-registry/tests/mount.spec.ts @@ -125,7 +125,7 @@ it('mounts a profile-denied row disabled and the same row active once exempted', writeFileSync(compatibilityPath, '{}\n') ctx.provide('profileContext', { name: 'test', dir: profileDir, patchPath: join(profileDir, 'cordis.patch.yml'), home: dir, - cwd: dir, installAnchor: join(dir, 'package.json'), startedBundles: [], overlays: [], + cwd: dir, installAnchor: join(dir, 'package.json'), startedBundles: [], overlayPaths: [], telemetryDisabledEnv: undefined, } satisfies ProfileContext) const row = { id: 'row', name: pathToFileURL(join(pluginDir, 'index.mjs')).href } diff --git a/packages/settings/settings/tests/configuration-fixture.ts b/packages/settings/settings/tests/configuration-fixture.ts index 4f81ec8d90..cf2ce763d4 100644 --- a/packages/settings/settings/tests/configuration-fixture.ts +++ b/packages/settings/settings/tests/configuration-fixture.ts @@ -12,7 +12,9 @@ import Hmr from '@deepseek-ai/dsh-hmr' import DefaultModel from '@deepseek-ai/dsh-agent-default-model' import Settings from '../src/index.ts' -export async function configurationFixture(options: { schema?: z; apply?: (ctx: Context, config: unknown) => void; hmr?: boolean } = {}) { +export async function configurationFixture( + options: { schema?: z; apply?: (ctx: Context, config: unknown) => void; hmr?: boolean; overlay?: string } = {}, +) { const home = realpathSync(mkdtempSync(join(tmpdir(), 'settings-config-'))) const dir = join(home, 'profiles', 'test') onTestFinished(() => { rmSync(home, { recursive: true, force: true }) }) @@ -29,9 +31,12 @@ export async function configurationFixture(options: { schema?: z; apply?: (ctx: { id: 'second', name: 'cordis:probe', config: { ordinary: 'second' } }, ] }])) writeFileSync(join(dir, 'cordis.yml'), '[]\n') + const overlayPath = join(home, 'overlay.patch.yml') + if (options.overlay !== undefined) writeFileSync(overlayPath, options.overlay) const profile: ProfileContext = { name: 'test', startedBundles: ['test-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, + overlayPaths: options.overlay === undefined ? [] : [overlayPath], telemetryDisabledEnv: undefined, } const Probe = { Config: options.schema ?? z.object({ ordinary: z.string().required(), count: z.number().min(1).default(2).volatile(), token: z.string().role('secret').volatile(), list: z.array(z.object({ name: z.string().required(), token: z.string().role('secret') })).volatile() }), @@ -54,5 +59,5 @@ export async function configurationFixture(options: { schema?: z; apply?: (ctx: } return ctx } - return { ctx: await start(), profile, home, start } + return { ctx: await start(), profile, home, overlayPath, start } } diff --git a/packages/settings/settings/tests/configuration.spec.ts b/packages/settings/settings/tests/configuration.spec.ts index 6fd9b9fe13..1d23083b50 100644 --- a/packages/settings/settings/tests/configuration.spec.ts +++ b/packages/settings/settings/tests/configuration.spec.ts @@ -45,6 +45,19 @@ it('refuses an edit shadowed by a higher home layer', async () => { expect(ctx.agentDefaultModel.currentSelection().model).toBe('home') }, 15_000) +it('reads current overlay files for edits in a startup-only profile', async () => { + const { ctx, profile, overlayPath } = await fixture({ hmr: false, overlay: '[]\n' }) + writeFileSync(overlayPath, JSON.stringify([{ id: 'default-model', config: { provider: 'test', model: 'overlay' } }])) + const before = readFileSync(profile.patchPath, 'utf8') + await expect(ctx.settings.update('default-model', { model: 'profile' })).rejects.toThrow('overridden') + expect(readFileSync(profile.patchPath, 'utf8')).toBe(before) + expect(ctx.agentDefaultModel.currentSelection().model).toBe('overlay') + rmSync(overlayPath) + await expect(ctx.settings.update('default-model', { model: 'profile' })).rejects.toThrow(`failed to read overlay ${overlayPath}`) + expect(readFileSync(profile.patchPath, 'utf8')).toBe(before) + expect(ctx.agentDefaultModel.currentSelection().model).toBe('overlay') +}, 15_000) + it('serializes concurrent writes and refuses stale revisions after external changes', async () => { const { ctx, profile } = await fixture() const revision = ctx.settings.describe().find(row => row.ns === 'first')!.revision diff --git a/packages/settings/settings/tests/profile-composition.ts b/packages/settings/settings/tests/profile-composition.ts index fceb74a585..49fe5591ee 100644 --- a/packages/settings/settings/tests/profile-composition.ts +++ b/packages/settings/settings/tests/profile-composition.ts @@ -24,7 +24,7 @@ export async function profileComposition(ctx: Context, home: string, baseFile: s await writeFile(join(dir, 'cordis.yml'), '[]\n') const profile: ProfileContext = { name: 'test', startedBundles: ['test-profile-bundle'], dir, patchPath: join(dir, 'cordis.patch.yml'), - installAnchor: join(home, 'package.json'), cwd: home, home, overlays: [], telemetryDisabledEnv: undefined, + installAnchor: join(home, 'package.json'), cwd: home, home, overlayPaths: [], telemetryDisabledEnv: undefined, } ctx.provide('profileContext', profile) ctx.provide('appReady', { onReady: (listener: () => void) => { listener(); return () => {} } }) diff --git a/packages/shell/shell-env/tests/shell-env.spec.ts b/packages/shell/shell-env/tests/shell-env.spec.ts index 5131ec2d4d..4a8006b861 100644 --- a/packages/shell/shell-env/tests/shell-env.spec.ts +++ b/packages/shell/shell-env/tests/shell-env.spec.ts @@ -72,7 +72,7 @@ describe('ShellEnvRegistry', () => { const ctx = new Context() ctx.provide('profileContext', { name: 'web', dir: '/profiles/web', patchPath: '/profiles/web/cordis.patch.yml', installAnchor: '/dsh/package.json', - cwd: '/work', home: '/home', startedBundles: [], overlays: [], telemetryDisabledEnv: undefined, + cwd: '/work', home: '/home', startedBundles: [], overlayPaths: [], telemetryDisabledEnv: undefined, }) const registry = new ShellEnvRegistry(ctx, { dshHome: './test-dsh-home' }) expect(registry.collect(execution())).toMatchObject({ diff --git a/packages/test-support/loader-smoke/tests/fixtures/production-profile.ts b/packages/test-support/loader-smoke/tests/fixtures/production-profile.ts index 415dc2c74a..a66a526afd 100644 --- a/packages/test-support/loader-smoke/tests/fixtures/production-profile.ts +++ b/packages/test-support/loader-smoke/tests/fixtures/production-profile.ts @@ -105,7 +105,7 @@ export async function bootProductionProfile(options: ProductionProfileOptions): name: options.profile, dir: profile.dir, patchPath: profile.patchPath, installAnchor, cwd: process.cwd(), home: process.env['DSH_HOME'] ?? join(homedir(), '.dsh'), startedBundles: profile.layers.map(layer => layer.packageName), - overlays: overlays.flat(), telemetryDisabledEnv: process.env['DSH_TELEMETRY_DISABLED'], + overlayPaths: options.overlayPaths, telemetryDisabledEnv: process.env['DSH_TELEMETRY_DISABLED'], } ctx.provide('profileContext', profileContext) await ctx.plugin(PluginPackages, { resolution })