@acryldev/harness-runtime 0.0.0-stage → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/LICENSE +49 -0
  2. package/lib/index.mjs +5693 -0
  3. package/lib/index.mjs.map +1 -0
  4. package/lib/types/acryl-home.d.ts +81 -0
  5. package/lib/types/app/new-app.d.ts +65 -0
  6. package/lib/types/app/start-source.d.ts +47 -0
  7. package/lib/types/blueprint/blueprint.d.ts +74 -0
  8. package/lib/types/blueprint/brand-identity.d.ts +26 -0
  9. package/lib/types/blueprint/compose.d.ts +53 -0
  10. package/lib/types/blueprint/definition.d.ts +22 -0
  11. package/lib/types/blueprint/index.d.ts +7 -0
  12. package/lib/types/blueprint/manifest.d.ts +35 -0
  13. package/lib/types/blueprint/selection.d.ts +19 -0
  14. package/lib/types/cli-market-install.d.ts +97 -0
  15. package/lib/types/cli-market-plugins.d.ts +81 -0
  16. package/lib/types/coding-capabilities.d.ts +29 -0
  17. package/lib/types/durable-message.d.ts +18 -0
  18. package/lib/types/engine-dsh.d.ts +181 -0
  19. package/lib/types/engine-files.d.ts +8 -0
  20. package/lib/types/engine-host.d.ts +32 -0
  21. package/lib/types/engine-tools.d.ts +11 -0
  22. package/lib/types/index.d.ts +67 -0
  23. package/lib/types/instance/announce-self.d.ts +38 -0
  24. package/lib/types/instance/app-instance.d.ts +125 -0
  25. package/lib/types/instance/index.d.ts +6 -0
  26. package/lib/types/instance/offline-lock.d.ts +29 -0
  27. package/lib/types/instance/online-secret.d.ts +29 -0
  28. package/lib/types/instance/registry.d.ts +26 -0
  29. package/lib/types/instance/select.d.ts +43 -0
  30. package/lib/types/module-hooks.d.ts +19 -0
  31. package/lib/types/module-resolution.d.ts +31 -0
  32. package/lib/types/package-overlay.d.ts +41 -0
  33. package/lib/types/pinned-pnpm.d.ts +15 -0
  34. package/lib/types/plugin-acryl-workspace-status.d.ts +24 -0
  35. package/lib/types/plugin-doctor.d.ts +49 -0
  36. package/lib/types/plugin-lifecycle-state.d.ts +92 -0
  37. package/lib/types/plugin-lifecycle.d.ts +87 -0
  38. package/lib/types/profile-layout.d.ts +17 -0
  39. package/lib/types/profile-owner.d.ts +25 -0
  40. package/lib/types/profile-repair/backup.d.ts +37 -0
  41. package/lib/types/profile-repair/findings.d.ts +29 -0
  42. package/lib/types/profile-repair/index.d.ts +9 -0
  43. package/lib/types/profile-repair/inspector.d.ts +11 -0
  44. package/lib/types/profile-repair/repair.d.ts +38 -0
  45. package/lib/types/profile-resolution/moved-framework.d.ts +21 -0
  46. package/lib/types/profile-resolution/resolver.d.ts +41 -0
  47. package/lib/types/profile-resolution/service.d.ts +22 -0
  48. package/lib/types/prompt-budget.d.ts +44 -0
  49. package/lib/types/session-bridge.d.ts +57 -0
  50. package/lib/types/session-log-exporter.d.ts +31 -0
  51. package/lib/types/system-prompt-capture.d.ts +29 -0
  52. package/lib/types/web-favicon-data.d.ts +5 -0
  53. package/lib/types/web-favicon.d.ts +23 -0
  54. package/lib/types/web-market-install.d.ts +114 -0
  55. package/lib/types/web-market-plugins.d.ts +106 -0
  56. package/lib/types/web-port.d.ts +15 -0
  57. package/package.json +211 -3
  58. package/src/acryl-home.ts +103 -0
  59. package/src/app/new-app.ts +239 -0
  60. package/src/app/start-source.ts +110 -0
  61. package/src/blueprint/blueprint.ts +141 -0
  62. package/src/blueprint/brand-identity.ts +75 -0
  63. package/src/blueprint/compose.ts +222 -0
  64. package/src/blueprint/definition.ts +92 -0
  65. package/src/blueprint/index.ts +20 -0
  66. package/src/blueprint/manifest.ts +145 -0
  67. package/src/blueprint/selection.ts +74 -0
  68. package/src/cli-market-install.ts +181 -0
  69. package/src/cli-market-plugins.ts +176 -0
  70. package/src/coding-capabilities.ts +61 -0
  71. package/src/durable-message.ts +23 -0
  72. package/src/engine-dsh.ts +856 -0
  73. package/src/engine-files.ts +9 -0
  74. package/src/engine-host.ts +128 -0
  75. package/src/engine-tools.ts +26 -0
  76. package/src/index.ts +436 -0
  77. package/src/instance/announce-self.ts +88 -0
  78. package/src/instance/app-instance.ts +240 -0
  79. package/src/instance/index.ts +45 -0
  80. package/src/instance/offline-lock.ts +71 -0
  81. package/src/instance/online-secret.ts +55 -0
  82. package/src/instance/registry.ts +53 -0
  83. package/src/instance/select.ts +134 -0
  84. package/src/module-hooks.ts +41 -0
  85. package/src/module-resolution.ts +187 -0
  86. package/src/package-overlay.ts +160 -0
  87. package/src/pinned-pnpm.ts +67 -0
  88. package/src/plugin-acryl-workspace-status.ts +99 -0
  89. package/src/plugin-doctor.ts +141 -0
  90. package/src/plugin-lifecycle-state.ts +347 -0
  91. package/src/plugin-lifecycle.ts +223 -0
  92. package/src/profile-layout.ts +97 -0
  93. package/src/profile-owner.ts +52 -0
  94. package/src/profile-repair/backup.ts +119 -0
  95. package/src/profile-repair/findings.ts +43 -0
  96. package/src/profile-repair/index.ts +10 -0
  97. package/src/profile-repair/inspector.ts +156 -0
  98. package/src/profile-repair/repair.ts +137 -0
  99. package/src/profile-resolution/moved-framework.ts +64 -0
  100. package/src/profile-resolution/resolver.ts +876 -0
  101. package/src/profile-resolution/service.ts +99 -0
  102. package/src/prompt-budget.ts +118 -0
  103. package/src/session-bridge.ts +350 -0
  104. package/src/session-log-exporter.ts +68 -0
  105. package/src/system-prompt-capture.ts +99 -0
  106. package/src/web-favicon-data.ts +6 -0
  107. package/src/web-favicon.ts +43 -0
  108. package/src/web-market-install.ts +206 -0
  109. package/src/web-market-plugins.ts +215 -0
  110. package/src/web-port.ts +39 -0
  111. package/tests/account-callback.spec.ts +173 -0
  112. package/tests/acryl-home.spec.ts +39 -0
  113. package/tests/agent-self-hosting.spec.ts +101 -0
  114. package/tests/announce-self.spec.ts +84 -0
  115. package/tests/app-lifecycle.spec.ts +99 -0
  116. package/tests/blank-blueprint.spec.ts +110 -0
  117. package/tests/blueprint-definition.spec.ts +128 -0
  118. package/tests/blueprint.spec.ts +138 -0
  119. package/tests/bulkhead.spec.ts +187 -0
  120. package/tests/coding-vocabulary.spec.ts +15 -0
  121. package/tests/dump-system-prompt.spec.ts +65 -0
  122. package/tests/e2e-real-model.spec.ts +71 -0
  123. package/tests/e2e-restart-real-model.spec.ts +77 -0
  124. package/tests/engine-dsh.spec.ts +340 -0
  125. package/tests/engine-host-mount-root-include.spec.ts +118 -0
  126. package/tests/engine-host.spec.ts +176 -0
  127. package/tests/engine-optional.spec.ts +81 -0
  128. package/tests/extension-examples.spec.ts +261 -0
  129. package/tests/hooks-thread-stack.ts +27 -0
  130. package/tests/instance-patches.spec.ts +25 -0
  131. package/tests/instance.spec.ts +235 -0
  132. package/tests/live/community-plugins.spec.ts +83 -0
  133. package/tests/module-hooks.spec.ts +35 -0
  134. package/tests/module-resolution.spec.ts +265 -0
  135. package/tests/moved-framework.spec.ts +61 -0
  136. package/tests/new-app.spec.ts +132 -0
  137. package/tests/organizer-growth.spec.ts +117 -0
  138. package/tests/pinned-pnpm.spec.ts +34 -0
  139. package/tests/plugin-acryl-workspace-status.spec.ts +63 -0
  140. package/tests/plugin-context.spec.ts +640 -0
  141. package/tests/plugin-doctor.spec.ts +183 -0
  142. package/tests/plugin-enablement-one-store.spec.ts +130 -0
  143. package/tests/plugin-lifecycle-state.spec.ts +169 -0
  144. package/tests/profile-layout.spec.ts +58 -0
  145. package/tests/profile-owner.spec.ts +38 -0
  146. package/tests/profile-repair/profile-repair.spec.ts +231 -0
  147. package/tests/profile-resolution-port.spec.ts +30 -0
  148. package/tests/profile-resolution-service.spec.ts +273 -0
  149. package/tests/profile-resolution-swap.spec.ts +69 -0
  150. package/tests/profile-resolution.spec.ts +2535 -0
  151. package/tests/profile.spec.ts +70 -0
  152. package/tests/project-registry.spec.ts +81 -0
  153. package/tests/prompt-budget.spec.ts +58 -0
  154. package/tests/real-home-guard.spec.ts +178 -0
  155. package/tests/session-bridge.spec.ts +316 -0
  156. package/tests/start-source.spec.ts +65 -0
  157. package/tests/system-prompt-shape.spec.ts +95 -0
  158. package/tests/three-levels.spec.ts +84 -0
  159. package/tests/tool-gateway.spec.ts +116 -0
  160. package/tests/tool-schemas.spec.ts +41 -0
  161. package/tests/web-favicon.spec.ts +42 -0
  162. package/tests/web-port.spec.ts +38 -0
  163. package/tests/web-startup-hold.spec.ts +79 -0
  164. package/tsconfig.json +24 -0
  165. package/tsdown.config.ts +2 -0
  166. package/vitest.config.ts +18 -0
  167. package/README.md +0 -3
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Real Loader activation of the extracted `dsh` engine (spec 028): the
3
+ * pinned Harness `acryl` profile, mounted through `createAcrylEngineHost`
4
+ * instead of `bootAcrylHarnessProfile`'s own Cordis root. Mirrors
5
+ * `tests/profile.spec.ts`'s fixture pattern (the working, now-fixed
6
+ * real-profile-boot path) rather than a synthetic noop plugin, so this
7
+ * proves the real extraction, not just the mounting primitive.
8
+ */
9
+ import { existsSync, realpathSync, writeFileSync } from 'node:fs'
10
+ import { mkdtemp, rm } from 'node:fs/promises'
11
+ import { createRequire, findPackageJSON } from 'node:module'
12
+ import { tmpdir } from 'node:os'
13
+ import { dirname, join } from 'node:path'
14
+ import {
15
+ DEFAULT_PROFILE_BUNDLES,
16
+ initProfile,
17
+ loadProfile,
18
+ resolveProfileDir,
19
+ } from '@deepseek-ai/dsh-app-boot'
20
+ import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
21
+ import { afterEach, describe, expect, it } from 'vitest'
22
+ import {
23
+ createDshEngineDefinition,
24
+ createDshEngineDefinitionFromComposition,
25
+ createWebEngineDefinition,
26
+ createProfileRuntimeResolution,
27
+ } from '../src/engine-dsh.ts'
28
+ import { createAcrylEngineHost } from '../src/engine-host.ts'
29
+ import { codingCapabilities } from '@acryldev/coding-capabilities'
30
+
31
+ const dshInstallAnchor = createRequire(import.meta.url).resolve('@deepseek-ai/dsh/package.json')
32
+
33
+ const temporaryHomes: string[] = []
34
+ const initialDshHome = process.env.DSH_HOME
35
+
36
+ afterEach(async () => {
37
+ // Assigning undefined would store the string "undefined" and the next boot would create a ./undefined profile directory.
38
+ if (initialDshHome === undefined) delete process.env.DSH_HOME
39
+ else process.env.DSH_HOME = initialDshHome
40
+ await Promise.all(temporaryHomes.splice(0).map(home => rm(home, { force: true, recursive: true })))
41
+ })
42
+
43
+
44
+ async function freshDshHome(): Promise<string> {
45
+ const home = await mkdtemp(join(tmpdir(), 'acryl-engine-dsh-'))
46
+ temporaryHomes.push(home)
47
+ process.env.DSH_HOME = home
48
+ return home
49
+ }
50
+
51
+ describe('the extracted dsh engine, mounted under createAcrylEngineHost', () => {
52
+ it('boots the pinned profile in the host tree, not a second Cordis root', async () => {
53
+ await freshDshHome()
54
+ const host = await createAcrylEngineHost({
55
+ engines: [createDshEngineDefinition('acryl-test', codingCapabilities)],
56
+ initialEngine: 'dsh',
57
+ })
58
+ try {
59
+ expect(host.currentEngine()).toBe('dsh')
60
+ // Same shared tree the host itself created the Loader on - not a
61
+ // second root the way bootAcrylHarnessProfile's boot() would create.
62
+ expect(host.ctx.get('sessions')).toBeDefined()
63
+ expect(host.ctx.get('agents')).toBeDefined()
64
+ expect(host.ctx.get('authorization')).toBeDefined()
65
+ // The roster is real, not just a composed row: the `agent-presets` root
66
+ // the capability declares resolves to the pinned package's own `presets/`
67
+ // directory and the service actually reads it. A root that does not exist
68
+ // scans as empty (`scanRoot` treats ENOENT as no presets), so asserting
69
+ // the row alone would pass on a roster with nothing in it.
70
+ const presets = await host.ctx.get('agentPresets')?.list()
71
+ expect(presets?.map(preset => preset.id).sort()).toEqual([
72
+ 'cordis',
73
+ 'minimal',
74
+ 'ptc',
75
+ 'standard',
76
+ ])
77
+ } finally {
78
+ await host.dispose()
79
+ }
80
+ })
81
+
82
+ it('tears down the whole profile tree when the engine host disposes', async () => {
83
+ await freshDshHome()
84
+ const host = await createAcrylEngineHost({
85
+ engines: [createDshEngineDefinition('acryl-test', codingCapabilities)],
86
+ initialEngine: 'dsh',
87
+ })
88
+ expect(host.ctx.get('sessions')).toBeDefined()
89
+ await host.dispose()
90
+ // Disposal removed the whole Loader tree - the fork Cordis handed the
91
+ // dsh engine plugin no longer resolves any of the profile's services.
92
+ expect(host.ctx.get('sessions')).toBeUndefined()
93
+ })
94
+
95
+ it('rejects an empty profile name before any Loader activation', () => {
96
+ expect(() => createDshEngineDefinition('')).toThrow('ACRYL dsh engine profile must not be empty')
97
+ expect(() => createDshEngineDefinition(' ')).toThrow('ACRYL dsh engine profile must not be empty')
98
+ })
99
+
100
+ it('re-mounts cleanly after swapping away and back - no duplicate tool/log-exporter registration', async () => {
101
+ await freshDshHome()
102
+ const host = await createAcrylEngineHost({
103
+ engines: [
104
+ createDshEngineDefinition('acryl-test', codingCapabilities),
105
+ { id: 'other', plugin: () => {} },
106
+ ],
107
+ initialEngine: 'dsh',
108
+ })
109
+ try {
110
+ expect(host.ctx.get('sessions')).toBeDefined()
111
+ await host.select('other')
112
+ expect(host.ctx.get('sessions')).toBeUndefined()
113
+ // If installAcrylWorkspaceStatusTool's ctx.tools.register() call were
114
+ // not disposed on the first unmount (the exact class of bug fixed in
115
+ // engine-dsh.ts), this second mount's register() call would throw a
116
+ // duplicate-registration error and this select() would reject.
117
+ await expect(host.select('dsh')).resolves.toBeUndefined()
118
+ expect(host.ctx.get('sessions')).toBeDefined()
119
+ } finally {
120
+ await host.dispose()
121
+ }
122
+ })
123
+ })
124
+
125
+ describe('CLI/TUI flavor booting a profile another surface already initialized (spec 034 T008)', () => {
126
+ it('does not throw duplicate loader entry id when --profile names an existing web-flavored profile', async () => {
127
+ await freshDshHome()
128
+ const installPackageUrl = new URL('../package.json', import.meta.url).href
129
+ // First, initialize the 'web' profile directory with its own richer
130
+ // template (dsh-web-app), which already composes agent-presets/persona/
131
+ // session-stats natively - exactly what a real Desktop/Web profile looks
132
+ // like on disk (`acryl plugin list --profile desktop`'s real-world
133
+ // reproduction, spec 034 tasks.md T008).
134
+ const webHost = await createAcrylEngineHost({
135
+ engines: [createWebEngineDefinition(installPackageUrl, codingCapabilities)],
136
+ initialEngine: 'dsh',
137
+ prepare: hostCtx => {
138
+ provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} })
139
+ },
140
+ })
141
+ await webHost.dispose()
142
+
143
+ // Now boot the SAME on-disk profile directory through the CLI/TUI's own
144
+ // generic --profile flavor. Before the fix, ACRYL's own tui-only
145
+ // agent-roster insert collided with the row the web bundle already
146
+ // composed, throwing `duplicate loader entry id: agent-preset-registry` at boot.
147
+ const cliHost = await createAcrylEngineHost({
148
+ engines: [createDshEngineDefinition('web', codingCapabilities)],
149
+ initialEngine: 'dsh',
150
+ })
151
+ try {
152
+ expect(cliHost.currentEngine()).toBe('dsh')
153
+ expect(cliHost.ctx.get('sessions')).toBeDefined()
154
+ const entries = [...cliHost.ctx.loader.entries()]
155
+ const agentPresetsRows = entries.filter(candidate => candidate.options.id === 'agent-preset-registry')
156
+ expect(agentPresetsRows).toHaveLength(1)
157
+ } finally {
158
+ await cliHost.dispose()
159
+ }
160
+ })
161
+ })
162
+
163
+ describe('the web engine entry point, mounted under createAcrylEngineHost', () => {
164
+ it('boots the pinned web profile in the host tree, with shared authorization and a token-authenticated connection', async () => {
165
+ await freshDshHome()
166
+ // web-startup's own plugin (@deepseek-ai/dsh-web-app) throws on activation
167
+ // without ctx.cmdlineArgs/ctx.appExit - provideCmdline is not optional
168
+ // plumbing for a real boot, matching how acryl-web/src/serve.ts always
169
+ // supplies it via createAcrylEngineHost's prepare hook.
170
+ const installPackageUrl = new URL('../package.json', import.meta.url).href
171
+ const host = await createAcrylEngineHost({
172
+ engines: [createWebEngineDefinition(installPackageUrl, codingCapabilities)],
173
+ initialEngine: 'dsh',
174
+ prepare: hostCtx => {
175
+ provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} })
176
+ },
177
+ })
178
+ try {
179
+ expect(host.currentEngine()).toBe('dsh')
180
+ expect(host.ctx.get('authorization')).toBeDefined()
181
+ // Proves the brand swap and the profile-template fix together: a
182
+ // fresh profile now actually mounts dsh-client-connection, and its
183
+ // authenticatedUrl carries a real token.
184
+ const url = host.ctx.get('connection')?.authenticatedUrl('http://127.0.0.1:3080')
185
+ expect(new URL(url ?? '').searchParams.get('token')).toBeTruthy()
186
+
187
+ // materializeProfilePackage's actual effect: a real symlink from the
188
+ // fresh profile's own node_modules to the acryl-web installation's
189
+ // resolved copy of @acryldev/brand-client - not just "no error was
190
+ // thrown while resolving it".
191
+ const profile = loadProfile('web', 'web', dshInstallAnchor)
192
+ const linkPath = join(profile.dir, 'node_modules', '@acryldev/brand-client')
193
+ expect(existsSync(linkPath)).toBe(true)
194
+ const installManifest = findPackageJSON('@acryldev/brand-client', codingCapabilities.anchors[0])
195
+ expect(installManifest).toBeDefined()
196
+ expect(realpathSync.native(linkPath)).toBe(realpathSync.native(dirname(installManifest as string)))
197
+
198
+ // The composed Loader tree actually carries the swap, not just a
199
+ // resolvable package sitting unused on disk: the stock DeepSeek row is
200
+ // disabled and the ACRYL row is enabled.
201
+ const entries = [...host.ctx.loader.entries()]
202
+ const officialBrand = entries.find(candidate => candidate.options.id === 'ui-brand-official')
203
+ const acrylBrand = entries.find(candidate => candidate.options.id === 'ui-acryl')
204
+ expect(officialBrand?.options.disabled).toBe(true)
205
+ expect(acrylBrand?.options.name).toBe('@acryldev/brand-client')
206
+ expect(acrylBrand?.options.disabled).toBeFalsy()
207
+
208
+ // The served shell HTML's <title> is a pinned dsh-web-frontend build
209
+ // artifact, outside the Cordis Client slot system the brand-swap patch
210
+ // above covers - reproduced directly: a real served index still read
211
+ // "DeepSeek Harness" after that patch landed. mountDshEngine registers
212
+ // a webServer.tapIndex() rewrite for the web surface specifically;
213
+ // exercise the real service's real renderIndex(), not a mocked string
214
+ // replace, so a future WebServer change that renames/removes tapIndex
215
+ // fails loud here.
216
+ const rendered = host.ctx.get('webServer')?.renderIndex(
217
+ '<!doctype html><html><head><title>DeepSeek Harness</title></head><body></body></html>',
218
+ )
219
+ expect(rendered).toContain('<title>ACRYL</title>')
220
+ expect(rendered).not.toContain('DeepSeek Harness')
221
+ } finally {
222
+ await host.dispose()
223
+ }
224
+ })
225
+ })
226
+
227
+ describe('the composition-based dsh engine entry point (for a surface with its own profile pipeline)', () => {
228
+ it('mounts an externally-resolved rootConfig/patches without doing its own profile resolution - the shape Desktop\'s prepareDesktopProfile() produces', async () => {
229
+ await freshDshHome()
230
+ const profileDirectory = resolveProfileDir('acryl-test')
231
+ initProfile(profileDirectory, DEFAULT_PROFILE_BUNDLES)
232
+ const profile = loadProfile('acryl', 'acryl-test', dshInstallAnchor)
233
+ const rootConfig = join(profile.dir, 'cordis.yml')
234
+ writeFileSync(rootConfig, '[]\n')
235
+ const patches = structuredClone([...profile.layers.flatMap(layer => layer.patches), ...profile.patches])
236
+
237
+ const host = await createAcrylEngineHost({
238
+ engines: [createDshEngineDefinitionFromComposition({
239
+ rootConfig,
240
+ patches,
241
+ surface: 'desktop',
242
+ // DSH 0.2 answers bare-package imports from the profile's package table, which a surface with its own pipeline supplies.
243
+ runtimeResolution: await createProfileRuntimeResolution(profile),
244
+ })],
245
+ initialEngine: 'dsh',
246
+ })
247
+ try {
248
+ expect(host.ctx.get('sessions')).toBeDefined()
249
+ expect(host.ctx.get('agents')).toBeDefined()
250
+ } finally {
251
+ await host.dispose()
252
+ }
253
+ })
254
+
255
+ it('never mounts DeepSeek\'s product analytics, which upstream switches on for a profile named desktop', async () => {
256
+ await freshDshHome()
257
+ const profileDirectory = resolveProfileDir('acryl-test')
258
+ initProfile(profileDirectory, DEFAULT_PROFILE_BUNDLES)
259
+ const profile = loadProfile('acryl', 'acryl-test', dshInstallAnchor)
260
+ const rootConfig = join(profile.dir, 'cordis.yml')
261
+ writeFileSync(rootConfig, '[]\n')
262
+ // The two rows as DSH's Web bundle composes them for Desktop's profile: enabled, the Host one reporting to DeepSeek's collector.
263
+ const upstreamAnalytics = {
264
+ insert: [
265
+ { id: 'desktop-product-telemetry', name: '@deepseek-ai/dsh-host-product-telemetry-otel', disabled: false, config: { serviceName: 'deepseek-harness-desktop' } },
266
+ { id: 'product-analytics', name: '@deepseek-ai/dsh-client-product-analytics', disabled: false, config: { enabled: true } },
267
+ ],
268
+ }
269
+ const patches = structuredClone([...profile.layers.flatMap(layer => layer.patches), ...profile.patches, upstreamAnalytics])
270
+
271
+ const host = await createAcrylEngineHost({
272
+ engines: [createDshEngineDefinitionFromComposition({
273
+ rootConfig,
274
+ patches,
275
+ surface: 'desktop',
276
+ runtimeResolution: await createProfileRuntimeResolution(profile),
277
+ })],
278
+ initialEngine: 'dsh',
279
+ })
280
+ try {
281
+ const entries = [...host.ctx.loader.entries()]
282
+ for (const id of ['desktop-product-telemetry', 'product-analytics']) {
283
+ expect(entries.find(entry => entry.options.id === id)?.options.disabled, id).toBe(true)
284
+ }
285
+ expect(host.ctx.get('productTelemetry' as never)).toBeUndefined()
286
+ } finally {
287
+ await host.dispose()
288
+ }
289
+ })
290
+
291
+ it('rejects an empty surface name before any Loader activation', () => {
292
+ expect(() => createDshEngineDefinitionFromComposition({ rootConfig: '/x/cordis.yml', patches: [], surface: '' }))
293
+ .toThrow('ACRYL dsh engine surface must not be empty')
294
+ })
295
+ })
296
+
297
+ describe('live configuration and engine reactivation on the web engine (spec 001 R26/R27)', () => {
298
+ async function mountWeb() {
299
+ await freshDshHome()
300
+ const installPackageUrl = new URL('../package.json', import.meta.url).href
301
+ return await createAcrylEngineHost({
302
+ engines: [createWebEngineDefinition(installPackageUrl, codingCapabilities), { id: 'other', plugin: () => {} }],
303
+ initialEngine: 'dsh',
304
+ prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
305
+ })
306
+ }
307
+
308
+ it('applies a Settings write from the first attempt and keeps ACRYL\'s own rows through the reload it triggers', async () => {
309
+ const host = await mountWeb()
310
+ try {
311
+ const settings = host.ctx.get('settings')
312
+ expect(settings).toBeDefined()
313
+ const rowsBefore = [...host.ctx.loader.entries()].length
314
+ // The first-run acknowledgement is the first write a user makes; it used to fail once (the reload re-enabled HMR) and succeed only on a retry.
315
+ await settings?.mutate('ui-settings-general', [{ op: 'set', path: ['welcomeNoticeVersion'], value: '2026-09-28.1' }])
316
+ expect(settings?.describe().find(row => row.ns === 'ui-settings-general')?.value).toMatchObject({ welcomeNoticeVersion: '2026-09-28.1' })
317
+ // ACRYL's in-memory rows came back after the reload instead of being dropped, and module HMR stayed off.
318
+ expect(host.ctx.get('acrylSettings')).toBeDefined()
319
+ expect([...host.ctx.loader.entries()].length).toBe(rowsBefore)
320
+ const hmr = [...host.ctx.loader.entries()].find(entry => entry.options.id === 'hmr')
321
+ expect(hmr?.disabled).toBe(true)
322
+ } finally {
323
+ await host.dispose()
324
+ }
325
+ }, 60_000)
326
+
327
+ it('swaps away and back and then disposes without hanging', async () => {
328
+ const host = await mountWeb()
329
+ await host.select('other')
330
+ expect(host.ctx.get('sessions')).toBeUndefined()
331
+ await host.select('dsh')
332
+ expect(host.ctx.get('sessions')).toBeDefined()
333
+ const outcome = await Promise.race([
334
+ host.dispose().then(() => 'disposed'),
335
+ new Promise<string>(resolve => setTimeout(() => { resolve('hung') }, 20_000)),
336
+ ])
337
+ expect(outcome).toBe('disposed')
338
+ }, 60_000)
339
+ })
340
+
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Spike (spec 028 Phase 2 reconciliation, 2026-09-11): proves `mountRootInclude`
3
+ * can compose a full profile-shaped Include tree *inside* one engine row of
4
+ * `createAcrylEngineHost`, instead of the second Cordis root
5
+ * `bootAcrylHarnessProfile`/`boot()` would create. This is the primitive the
6
+ * real `dsh` engine plugin extraction depends on - verified here with a real
7
+ * Loader activation before it is trusted in the extraction itself.
8
+ */
9
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
10
+ import { tmpdir } from 'node:os'
11
+ import { dirname, join } from 'node:path'
12
+ import { pathToFileURL } from 'node:url'
13
+ import type { Context } from '@deepseek-ai/cordis'
14
+ import { mountRootInclude } from '@deepseek-ai/dsh-app-boot'
15
+ import { afterEach, describe, expect, it } from 'vitest'
16
+ import { createAcrylEngineHost, type AcrylEngineDefinition } from '../src/engine-host.ts'
17
+
18
+ const roots: string[] = []
19
+ afterEach(() => {
20
+ for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
21
+ })
22
+
23
+ /** A minimal profile: one noop plugin, mounted through a real `cordis.yml`. */
24
+ function profileFixture(): string {
25
+ const dir = mkdtempSync(join(tmpdir(), 'acryl-engine-mount-root-include-'))
26
+ roots.push(dir)
27
+ writeFileSync(join(dir, 'noop.mjs'), [
28
+ "import { appendFileSync } from 'node:fs'",
29
+ 'export const name = "noop"',
30
+ `export function apply(ctx) { appendFileSync(${JSON.stringify(join(dir, 'log.txt'))}, 'mount\\n'); ctx.effect(() => () => { appendFileSync(${JSON.stringify(join(dir, 'log.txt'))}, 'unmount\\n') }) }`,
31
+ '',
32
+ ].join('\n'))
33
+ writeFileSync(join(dir, 'cordis.yml'), '- id: noop\n name: ./noop.mjs\n')
34
+ return dir
35
+ }
36
+
37
+ function lines(dir: string): string[] {
38
+ try {
39
+ return readFileSync(join(dir, 'log.txt'), 'utf8').trim().split('\n')
40
+ } catch {
41
+ return []
42
+ }
43
+ }
44
+
45
+ function mountedEngine(configPath: string): AcrylEngineDefinition {
46
+ return {
47
+ id: 'dsh',
48
+ plugin: async (ctx: Context) => {
49
+ ctx.baseUrl = pathToFileURL(dirname(configPath)).href + '/'
50
+ const entry = await mountRootInclude(ctx, configPath)
51
+ // mountRootInclude creates its Include row at the Loader's own top
52
+ // level (it has no `parent` parameter) - it is not automatically
53
+ // scoped to this plugin's own fiber the way ctx.effect() resources
54
+ // are, so this engine plugin must own and remove it explicitly.
55
+ if (entry !== undefined) {
56
+ ctx.effect(() => () => { void ctx.loader.remove(entry.options.id) })
57
+ }
58
+ },
59
+ }
60
+ }
61
+
62
+ describe('mountRootInclude nested inside one acryl-engine row', () => {
63
+ it('composes a profile-shaped Include tree as a child of the engine row, not a second root', async () => {
64
+ const dir = profileFixture()
65
+ const host = await createAcrylEngineHost({
66
+ engines: [mountedEngine(join(dir, 'cordis.yml'))],
67
+ initialEngine: 'dsh',
68
+ })
69
+ try {
70
+ const entries = [...host.ctx.loader.entries()]
71
+ const noop = entries.find(entry => entry.options.name === './noop.mjs')
72
+ expect(noop?.fiber).toBeDefined()
73
+ expect(lines(dir)).toEqual(['mount'])
74
+ } finally {
75
+ await host.dispose()
76
+ }
77
+ expect(lines(dir)).toEqual(['mount', 'unmount'])
78
+ })
79
+
80
+ it('tears down the nested Include tree when the engine row is swapped away', async () => {
81
+ const dir = profileFixture()
82
+ const host = await createAcrylEngineHost({
83
+ engines: [
84
+ mountedEngine(join(dir, 'cordis.yml')),
85
+ { id: 'other', plugin: () => {} },
86
+ ],
87
+ initialEngine: 'dsh',
88
+ })
89
+ try {
90
+ expect(lines(dir)).toEqual(['mount'])
91
+ await host.select('other')
92
+ expect(lines(dir)).toEqual(['mount', 'unmount'])
93
+ } finally {
94
+ await host.dispose()
95
+ }
96
+ })
97
+
98
+ it('re-mounts cleanly after swapping away and back - no builtins.include collision', async () => {
99
+ const dir = profileFixture()
100
+ const host = await createAcrylEngineHost({
101
+ engines: [
102
+ mountedEngine(join(dir, 'cordis.yml')),
103
+ { id: 'other', plugin: () => {} },
104
+ ],
105
+ initialEngine: 'dsh',
106
+ })
107
+ try {
108
+ await host.select('other')
109
+ await host.select('dsh')
110
+ const entries = [...host.ctx.loader.entries()]
111
+ const noop = entries.find(entry => entry.options.name === './noop.mjs')
112
+ expect(noop?.fiber).toBeDefined()
113
+ expect(lines(dir)).toEqual(['mount', 'unmount', 'mount'])
114
+ } finally {
115
+ await host.dispose()
116
+ }
117
+ })
118
+ })
@@ -0,0 +1,176 @@
1
+ import { Context, Service } from '@deepseek-ai/cordis'
2
+ import { afterEach, describe, expect, it } from 'vitest'
3
+ import { IsolationRequiredError } from '../src/instance/index.ts'
4
+ import {
5
+ createAcrylEngineHost,
6
+ type AcrylEngineDefinition,
7
+ } from '../src/engine-host.ts'
8
+
9
+ declare module '@deepseek-ai/cordis' {
10
+ interface Context {
11
+ testEngine: TestEngine
12
+ }
13
+ }
14
+
15
+ class TestEngine extends Service {
16
+ constructor(ctx: Context, readonly id: string) {
17
+ super(ctx, 'testEngine')
18
+ }
19
+ }
20
+
21
+ function engine(id: string, events: string[]): AcrylEngineDefinition {
22
+ return {
23
+ id,
24
+ plugin: class extends TestEngine {
25
+ constructor(ctx: Context) {
26
+ super(ctx, id)
27
+ ctx.effect(() => {
28
+ events.push(`start:${id}`)
29
+ return () => { events.push(`stop:${id}`) }
30
+ })
31
+ }
32
+ },
33
+ }
34
+ }
35
+
36
+ describe('createAcrylEngineHost isolation', () => {
37
+ it('refuses to start when an isolated home is required and none is pinned, before any engine mounts', async () => {
38
+ const saved = { ...process.env }
39
+ for (const key of ['ACRYL_HOME', 'DSH_HOME']) delete process.env[key]
40
+ process.env.ACRYL_REQUIRE_ISOLATED_HOME = '1'
41
+ const events: string[] = []
42
+ try {
43
+ await expect(createAcrylEngineHost({ engines: [engine('one', events)], initialEngine: 'one' })).rejects.toBeInstanceOf(IsolationRequiredError)
44
+ expect(events).toEqual([])
45
+ } finally {
46
+ for (const key of Object.keys(process.env)) if (!(key in saved)) delete process.env[key]
47
+ Object.assign(process.env, saved)
48
+ }
49
+ })
50
+ })
51
+
52
+ describe('createAcrylEngineHost', () => {
53
+ const hosts: Awaited<ReturnType<typeof createAcrylEngineHost>>[] = []
54
+
55
+ afterEach(async () => {
56
+ await Promise.all(hosts.splice(0).map(host => host.dispose()))
57
+ })
58
+
59
+ it('loads the selected engine through one stable Loader row', async () => {
60
+ const events: string[] = []
61
+ const host = await createAcrylEngineHost({
62
+ engines: [engine('dsh', events), engine('pi', events)],
63
+ initialEngine: 'dsh',
64
+ })
65
+ hosts.push(host)
66
+
67
+ expect(host.ctx.testEngine.id).toBe('dsh')
68
+ expect(host.currentEngine()).toBe('dsh')
69
+ expect(events).toEqual(['start:dsh'])
70
+ })
71
+
72
+ it('replaces the engine and reactivates a dependent consumer', async () => {
73
+ const events: string[] = []
74
+ const host = await createAcrylEngineHost({
75
+ engines: [engine('dsh', events), engine('pi', events)],
76
+ initialEngine: 'dsh',
77
+ })
78
+ hosts.push(host)
79
+ let activations = 0
80
+ let disposals = 0
81
+ const consumer = host.ctx.plugin({
82
+ inject: ['testEngine'],
83
+ apply(ctx) {
84
+ activations += 1
85
+ ctx.effect(() => () => { disposals += 1 })
86
+ },
87
+ })
88
+ await consumer
89
+
90
+ await host.select('pi')
91
+
92
+ expect(host.ctx.testEngine.id).toBe('pi')
93
+ expect(host.currentEngine()).toBe('pi')
94
+ expect(activations).toBe(2)
95
+ expect(disposals).toBe(1)
96
+ expect(events).toEqual(['start:dsh', 'stop:dsh', 'start:pi'])
97
+ })
98
+
99
+ it('keeps the active engine when selection names no registered provider', async () => {
100
+ const events: string[] = []
101
+ const host = await createAcrylEngineHost({
102
+ engines: [engine('dsh', events)],
103
+ initialEngine: 'dsh',
104
+ })
105
+ hosts.push(host)
106
+
107
+ await expect(host.select('pi')).rejects.toThrow('unknown ACRYL engine: pi')
108
+
109
+ expect(host.ctx.testEngine.id).toBe('dsh')
110
+ expect(events).toEqual(['start:dsh'])
111
+ })
112
+
113
+ it('runs prepare on the bare root before any engine mounts, so its registrations are visible to the mounted engine', async () => {
114
+ const events: string[] = []
115
+ const host = await createAcrylEngineHost({
116
+ engines: [engine('dsh', events)],
117
+ initialEngine: 'dsh',
118
+ prepare(ctx) {
119
+ events.push('prepare')
120
+ ctx.provide('testSurfaceService', 'surface-value')
121
+ },
122
+ })
123
+ hosts.push(host)
124
+
125
+ expect(events).toEqual(['prepare', 'start:dsh'])
126
+ expect(host.ctx.get('testSurfaceService')).toBe('surface-value')
127
+ })
128
+
129
+ it('surfaces a synchronous prepare failure as host preparation, before any engine mounts', async () => {
130
+ const events: string[] = []
131
+ await expect(createAcrylEngineHost({
132
+ engines: [engine('dsh', events)],
133
+ initialEngine: 'dsh',
134
+ prepare() { throw new Error('surface setup failed') },
135
+ })).rejects.toThrow('surface setup failed')
136
+
137
+ expect(events).toEqual([])
138
+ })
139
+
140
+ it('behaves exactly as before when prepare is omitted', async () => {
141
+ const events: string[] = []
142
+ const host = await createAcrylEngineHost({
143
+ engines: [engine('dsh', events)],
144
+ initialEngine: 'dsh',
145
+ })
146
+ hosts.push(host)
147
+
148
+ expect(events).toEqual(['start:dsh'])
149
+ })
150
+
151
+ it('gives the host-owned engine row a resolution base URL, the same property dsh-client-modules reads for every Loader entry', async () => {
152
+ // dsh-client-modules (Desktop/Web's client-bundle composer, absent from
153
+ // the CLI/TUI profile - which is why no other test in this file caught
154
+ // this) reads `entry.parent.tree.ctx.baseUrl` for every Loader entry and
155
+ // throws if it is undefined. That property is a one-time snapshot
156
+ // EntryTree's constructor takes of `ctx.baseUrl` when the Loader plugin
157
+ // activates - reproduced directly (RED) as `undefined` for the
158
+ // host-owned "acryl-engine-<id>" row before HOST_ROOT_BASE_URL existed.
159
+ const events: string[] = []
160
+ const host = await createAcrylEngineHost({
161
+ engines: [engine('dsh', events)],
162
+ initialEngine: 'dsh',
163
+ })
164
+ hosts.push(host)
165
+
166
+ const entry = [...host.ctx.loader.entries()].find(candidate => candidate.options.name === 'cordis:acryl-engine-dsh')
167
+ expect(entry).toBeDefined()
168
+ expect((entry as { parent: { tree: { ctx: { baseUrl?: string } } } }).parent.tree.ctx.baseUrl).toBeDefined()
169
+ })
170
+ })
171
+
172
+ declare module '@deepseek-ai/cordis' {
173
+ interface Context {
174
+ testSurfaceService: string
175
+ }
176
+ }