@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,183 @@
1
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import { afterEach, describe, expect, it } from 'vitest'
5
+ import type { PluginLifecycleEntryView, PluginLifecycleSnapshot } from '@acryldev/control'
6
+ import { diagnosePluginLifecycle } from '../src/plugin-doctor.ts'
7
+
8
+ const roots: string[] = []
9
+
10
+ afterEach(() => {
11
+ for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
12
+ })
13
+
14
+ function tempDir(prefix: string): string {
15
+ const root = mkdtempSync(join(tmpdir(), prefix))
16
+ roots.push(root)
17
+ return root
18
+ }
19
+
20
+ /** A profile directory with the given `dsh.profile.bundles` list. */
21
+ function profileDir(bundles: readonly string[]): string {
22
+ const dir = tempDir('dsh-doctor-profile-')
23
+ writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'acryl-profile', dsh: { profile: { bundles } } }))
24
+ return dir
25
+ }
26
+
27
+ function statePath(contents?: string): string {
28
+ const dir = tempDir('dsh-doctor-state-')
29
+ const path = join(dir, 'plugin-lifecycle', 'state.json')
30
+ if (contents !== undefined) {
31
+ mkdirSync(join(dir, 'plugin-lifecycle'), { recursive: true })
32
+ writeFileSync(path, contents)
33
+ }
34
+ return path
35
+ }
36
+
37
+ function entry(
38
+ entryId: string,
39
+ overrides: Partial<PluginLifecycleEntryView> = {},
40
+ ): PluginLifecycleEntryView {
41
+ return {
42
+ entryId,
43
+ moduleName: 'acryl-plugin',
44
+ enabled: true,
45
+ hostPhase: 'active',
46
+ mutable: true,
47
+ protectedReason: null,
48
+ dependents: [],
49
+ ...overrides,
50
+ }
51
+ }
52
+
53
+ function snapshot(entries: readonly PluginLifecycleEntryView[]): PluginLifecycleSnapshot {
54
+ return { entries }
55
+ }
56
+
57
+ function disabledState(profileName: string, entryIds: readonly string[]): string {
58
+ return JSON.stringify({ version: 1, profiles: [{ profileName, disabledEntries: entryIds }] })
59
+ }
60
+
61
+ describe('diagnosePluginLifecycle', () => {
62
+ it('reports a healthy profile with no findings', () => {
63
+ const report = diagnosePluginLifecycle({
64
+ profileName: 'acryl',
65
+ profileDir: profileDir([]),
66
+ statePath: statePath(),
67
+ snapshot: snapshot([entry('include:ui-acryl')]),
68
+ })
69
+
70
+ expect(report).toMatchObject({
71
+ profileName: 'acryl',
72
+ pluginCount: 1,
73
+ findings: [],
74
+ })
75
+ expect(report.statePath).toContain('plugin-lifecycle')
76
+ })
77
+
78
+ it('accepts an override written as a patch id for a composed entry', () => {
79
+ const report = diagnosePluginLifecycle({
80
+ profileName: 'acryl',
81
+ profileDir: profileDir([]),
82
+ statePath: statePath(disabledState('acryl', ['ui-acryl'])),
83
+ snapshot: snapshot([entry('include:ui-acryl')]),
84
+ })
85
+
86
+ expect(report.findings).toEqual([])
87
+ })
88
+
89
+ it('warns about an override that outlived its entry', () => {
90
+ const report = diagnosePluginLifecycle({
91
+ profileName: 'acryl',
92
+ profileDir: profileDir([]),
93
+ statePath: statePath(disabledState('acryl', ['include:removed-plugin'])),
94
+ snapshot: snapshot([entry('include:ui-acryl')]),
95
+ })
96
+
97
+ expect(report.findings).toEqual([
98
+ expect.objectContaining({ severity: 'warning', code: 'stale-override', entryId: 'include:removed-plugin' }),
99
+ ])
100
+ })
101
+
102
+ it('warns about an override on an entry the user does not control', () => {
103
+ const report = diagnosePluginLifecycle({
104
+ profileName: 'acryl',
105
+ profileDir: profileDir([]),
106
+ statePath: statePath(disabledState('acryl', ['include:ui-brand-official'])),
107
+ snapshot: snapshot([
108
+ entry('include:ui-brand-official', { mutable: false, protectedReason: 'compatibility mode' }),
109
+ ]),
110
+ })
111
+
112
+ expect(report.findings).toEqual([
113
+ expect.objectContaining({ severity: 'warning', code: 'unmanaged-override' }),
114
+ ])
115
+ })
116
+
117
+ it('ignores another profile\'s overrides', () => {
118
+ const report = diagnosePluginLifecycle({
119
+ profileName: 'acryl',
120
+ profileDir: profileDir([]),
121
+ statePath: statePath(disabledState('desktop', ['include:gone'])),
122
+ snapshot: snapshot([entry('include:ui-acryl')]),
123
+ })
124
+
125
+ expect(report.findings).toEqual([])
126
+ })
127
+
128
+ it('fails closed when the override file cannot be parsed', () => {
129
+ const report = diagnosePluginLifecycle({
130
+ profileName: 'acryl',
131
+ profileDir: profileDir([]),
132
+ statePath: statePath('{ not json'),
133
+ snapshot: snapshot([entry('include:ui-acryl')]),
134
+ })
135
+
136
+ expect(report.findings).toEqual([
137
+ expect.objectContaining({ severity: 'error', code: 'state-unreadable' }),
138
+ ])
139
+ })
140
+
141
+ it('warns when a user bundle composes nothing, and errors when it cannot resolve', () => {
142
+ const dir = profileDir(['acryl-dsh-editor-plugin', 'acryl-plugin-gone'])
143
+ const report = diagnosePluginLifecycle({
144
+ profileName: 'acryl',
145
+ profileDir: dir,
146
+ statePath: statePath(),
147
+ snapshot: snapshot([entry('include:ui-acryl', { moduleName: '@acryldev/dsh-client-ui-brand-acryl' })]),
148
+ resolvePackageJson: packageName => {
149
+ if (packageName === 'acryl-plugin-gone') throw new Error('Cannot find module')
150
+ return join(dir, 'node_modules', packageName, 'package.json')
151
+ },
152
+ })
153
+
154
+ expect(report.findings).toEqual([
155
+ expect.objectContaining({ severity: 'warning', code: 'bundle-not-composed', entryId: 'acryl-dsh-editor-plugin' }),
156
+ expect.objectContaining({ severity: 'error', code: 'bundle-missing', entryId: 'acryl-plugin-gone' }),
157
+ ])
158
+ })
159
+
160
+ it('matches a composed row whose module name is a subpath of the bundle', () => {
161
+ const report = diagnosePluginLifecycle({
162
+ profileName: 'acryl',
163
+ profileDir: profileDir(['acryl-dsh-editor-plugin']),
164
+ statePath: statePath(),
165
+ snapshot: snapshot([entry('include:dsh-editor', { moduleName: 'acryl-dsh-editor-plugin/dist/host.js' })]),
166
+ resolvePackageJson: () => '/x/package.json',
167
+ })
168
+
169
+ expect(report.findings).toEqual([])
170
+ })
171
+
172
+ it('never treats a base template bundle as user-mutable', () => {
173
+ const report = diagnosePluginLifecycle({
174
+ profileName: 'acryl',
175
+ profileDir: profileDir(['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']),
176
+ statePath: statePath(),
177
+ snapshot: snapshot([]),
178
+ resolvePackageJson: () => { throw new Error('should not be asked') },
179
+ })
180
+
181
+ expect(report.findings).toEqual([])
182
+ })
183
+ })
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Spec 001 T089: one store for enabling and disabling a plugin. A plugin is switched from DSH's own Plugins page (`pluginManager`, ACRYL's
3
+ * subclass in its row) and from ACRYL's Lifecycle tab (`acrPluginLifecycle`), with an app restart between every step, on a real Web engine in a
4
+ * throwaway home. Before T089 the two wrote two files, and a disable written by either kept the plugin off whatever the other said.
5
+ */
6
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
7
+ import { mkdtemp, rm } from 'node:fs/promises'
8
+ import { tmpdir } from 'node:os'
9
+ import { join } from 'node:path'
10
+ import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
11
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest'
12
+ import { isSeq, parseDocument } from 'yaml'
13
+ import { createWebEngineDefinition } from '../src/engine-dsh.ts'
14
+ import { createAcrylEngineHost } from '../src/engine-host.ts'
15
+ import { resolvePluginLifecycleStatePath } from '../src/plugin-lifecycle-state.ts'
16
+ import { codingCapabilities } from '@acryldev/coding-capabilities'
17
+
18
+ const ENTRY = 'include:t089-probe'
19
+
20
+ interface ManagerRow { entryId: string; enabled: boolean; patchId?: string; readOnlyReason?: string }
21
+ interface Manager {
22
+ installBundle(spec: string): Promise<{ application: string; error?: unknown }>
23
+ listPlugins(): Promise<ManagerRow[]>
24
+ setPluginEnabled(id: string, enabled: boolean): Promise<{ application: string; changed: boolean; error?: unknown }>
25
+ }
26
+ interface Lifecycle { setEnabled(entryId: string, enabled: boolean): Promise<unknown>; snapshot(): { entries: { entryId: string; enabled: boolean; mutable: boolean }[] } }
27
+
28
+ let home: string
29
+ const initialDshHome = process.env['DSH_HOME']
30
+
31
+ beforeAll(async () => {
32
+ home = await mkdtemp(join(tmpdir(), 'acryl-t089-'))
33
+ process.env['DSH_HOME'] = join(home, 'dsh')
34
+ })
35
+ afterAll(async () => {
36
+ if (initialDshHome === undefined) delete process.env['DSH_HOME']
37
+ else process.env['DSH_HOME'] = initialDshHome
38
+ await rm(home, { recursive: true, force: true })
39
+ })
40
+
41
+ /** One app start: boot, run `body` against both pages' services, shut down. */
42
+ async function start<T>(body: (pages: { manager: Manager; lifecycle: Lifecycle; profileDir: string }) => Promise<T>): Promise<T> {
43
+ const host = await createAcrylEngineHost({
44
+ engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
45
+ initialEngine: 'dsh',
46
+ prepare: ctx => { provideCmdline(ctx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
47
+ })
48
+ try {
49
+ return await body({
50
+ manager: host.ctx.get('pluginManager' as never) as unknown as Manager,
51
+ lifecycle: host.ctx.get('acrPluginLifecycle' as never) as unknown as Lifecycle,
52
+ profileDir: join(process.env['DSH_HOME'] ?? '', 'profiles', 'web'),
53
+ })
54
+ } finally {
55
+ await host.dispose()
56
+ }
57
+ }
58
+
59
+ async function row(manager: Manager): Promise<ManagerRow | undefined> {
60
+ return (await manager.listPlugins()).find(candidate => candidate.entryId === ENTRY)
61
+ }
62
+
63
+ function profilePatch(profileDir: string): string {
64
+ const path = join(profileDir, 'cordis.patch.yml')
65
+ return existsSync(path) ? readFileSync(path, 'utf8') : ''
66
+ }
67
+
68
+ function stored(): string[] {
69
+ const path = resolvePluginLifecycleStatePath(process.env['DSH_HOME'])
70
+ if (!existsSync(path)) return []
71
+ return (JSON.parse(readFileSync(path, 'utf8')) as { profiles: { disabledEntries: string[] }[] }).profiles.flatMap(profile => profile.disabledEntries)
72
+ }
73
+
74
+ describe('T089: one enable/disable store for both plugin pages', () => {
75
+ it('a plugin switched from either page, across restarts, is in the state the last switch left it', async () => {
76
+ const bundle = join(home, 't089-probe')
77
+ mkdirSync(bundle)
78
+ writeFileSync(join(bundle, 'package.json'), `${JSON.stringify({ name: 't089-probe', version: '1.0.0', type: 'module', main: './index.js', dsh: { bundle: { patch: './cordis.patch.yml' } } }, null, 2)}\n`)
79
+ writeFileSync(join(bundle, 'index.js'), "export const name = 't089-probe'\nexport function apply() {}\n")
80
+ writeFileSync(join(bundle, 'cordis.patch.yml'), '- insert:\n - id: t089-probe\n name: t089-probe\n')
81
+
82
+ const installed = await start(({ manager }) => manager.installBundle(bundle))
83
+ expect(installed.error).toBeUndefined()
84
+
85
+ // DSH's page lists ACRYL's row as one it can switch, and its switch is kept in ACRYL's store, not in the profile patch.
86
+ await start(async ({ manager, lifecycle, profileDir }) => {
87
+ const before = await row(manager)
88
+ expect(before).toMatchObject({ enabled: true, patchId: 't089-probe' })
89
+ expect(before?.readOnlyReason).toBeUndefined()
90
+ expect(await manager.setPluginEnabled(ENTRY, false)).toMatchObject({ application: 'applied', changed: true })
91
+ expect(lifecycle.snapshot().entries.find(entry => entry.entryId === ENTRY)?.enabled).toBe(false)
92
+ expect(stored()).toEqual([ENTRY])
93
+ expect(profilePatch(profileDir)).not.toMatch(/disabled/u)
94
+ })
95
+
96
+ // Restart: still off; ACRYL's tab switches it on.
97
+ await start(async ({ manager, lifecycle }) => {
98
+ expect((await row(manager))?.enabled).toBe(false)
99
+ await lifecycle.setEnabled(ENTRY, true)
100
+ expect(stored()).toEqual([])
101
+ })
102
+
103
+ // Restart: on. A disable the old DSH page wrote into the profile patch, as installed apps have them.
104
+ const profileDir = await start(async ({ manager, profileDir }) => {
105
+ expect((await row(manager))?.enabled).toBe(true)
106
+ return profileDir
107
+ })
108
+ // Written as DSH's own writer does (`plugin-manager/src/patch.ts`: the YAML document's `add`), with a comment a person left above it.
109
+ const legacy = parseDocument(profilePatch(profileDir) || '[]\n')
110
+ const disable = legacy.createNode({ id: 't089-probe', disabled: true })
111
+ disable.commentBefore = ' switched off on the old Plugins page'
112
+ legacy.add(disable)
113
+ if (isSeq(legacy.contents)) legacy.contents.flow = false
114
+ writeFileSync(join(profileDir, 'cordis.patch.yml'), String(legacy))
115
+
116
+ // Restart: off, from that old disable; DSH's page switches it on, which clears it, comments kept.
117
+ await start(async ({ manager }) => {
118
+ expect((await row(manager))?.enabled).toBe(false)
119
+ expect(await manager.setPluginEnabled(ENTRY, true)).toMatchObject({ application: 'applied', changed: true })
120
+ expect(profilePatch(profileDir)).not.toMatch(/disabled: true/u)
121
+ expect(profilePatch(profileDir)).toMatch(/# switched off on the old Plugins page/u)
122
+ })
123
+
124
+ // Restart: on, and both pages agree.
125
+ await start(async ({ manager, lifecycle }) => {
126
+ expect((await row(manager))?.enabled).toBe(true)
127
+ expect(lifecycle.snapshot().entries.find(entry => entry.entryId === ENTRY)).toMatchObject({ enabled: true, mutable: true })
128
+ })
129
+ }, 300_000)
130
+ })
@@ -0,0 +1,169 @@
1
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { tmpdir } from 'node:os'
3
+ import { dirname, join, resolve } from 'node:path'
4
+ import { afterEach, describe, expect, it } from 'vitest'
5
+ import {
6
+ clearProfilePatchDisable,
7
+ pluginLifecyclePatches,
8
+ readDisabledPluginLifecycleEntries,
9
+ resolvePluginLifecycleStatePath,
10
+ setPluginLifecycleEntryEnabled,
11
+ } from '../src/plugin-lifecycle-state.ts'
12
+
13
+ const roots: string[] = []
14
+
15
+ afterEach(() => {
16
+ for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
17
+ })
18
+
19
+ function statePath(): string {
20
+ const root = mkdtempSync(join(tmpdir(), 'dsh-plugin-lifecycle-'))
21
+ roots.push(root)
22
+ return join(root, 'state', 'lifecycle.json')
23
+ }
24
+
25
+ describe('plugin lifecycle state', () => {
26
+ it('resolves one override file per engine home, shared by every surface', () => {
27
+ // The profile, not the surface, owns the overrides (spec 034, FR-003): a
28
+ // CLI, Web, and Desktop process booting the same engine home must read and
29
+ // write the same file.
30
+ expect(resolvePluginLifecycleStatePath('/home/u/.acryl/.dsh'))
31
+ .toBe(join('/home/u/.acryl/.dsh', 'plugin-lifecycle', 'state.json'))
32
+
33
+ const previous = { ACRYL_HOME: process.env.ACRYL_HOME, DSH_HOME: process.env.DSH_HOME }
34
+ try {
35
+ delete process.env.DSH_HOME
36
+ process.env.ACRYL_HOME = '/tmp/acryl-home'
37
+ expect(resolvePluginLifecycleStatePath())
38
+ .toBe(join(resolve('/tmp/acryl-home'), '.dsh', 'plugin-lifecycle', 'state.json'))
39
+
40
+ // An isolated or dev run sets only DSH_HOME. Resolving it from the ACRYL
41
+ // root instead would write overrides into the operator's real install.
42
+ delete process.env.ACRYL_HOME
43
+ process.env.DSH_HOME = '/tmp/acryl-dev/.dsh'
44
+ expect(resolvePluginLifecycleStatePath())
45
+ .toBe(join(resolve('/tmp/acryl-dev/.dsh'), 'plugin-lifecycle', 'state.json'))
46
+ } finally {
47
+ if (previous.ACRYL_HOME === undefined) delete process.env.ACRYL_HOME
48
+ else process.env.ACRYL_HOME = previous.ACRYL_HOME
49
+ if (previous.DSH_HOME === undefined) delete process.env.DSH_HOME
50
+ else process.env.DSH_HOME = previous.DSH_HOME
51
+ }
52
+ })
53
+
54
+ it('treats a missing state file as no overrides', () => {
55
+ const path = statePath()
56
+ expect([...readDisabledPluginLifecycleEntries({ profileName: 'desktop', statePath: path })]).toEqual([])
57
+ expect(pluginLifecyclePatches({ profileName: 'desktop', statePath: path }, new Set(['acryl-development-canvas']))).toEqual([])
58
+ })
59
+
60
+ it('persists a managed disable and removes it on enable', async () => {
61
+ const path = statePath()
62
+ const bootstrap = { profileName: 'desktop', statePath: path }
63
+
64
+ await setPluginLifecycleEntryEnabled(
65
+ bootstrap,
66
+ 'include:acryl-development-canvas',
67
+ false,
68
+ )
69
+
70
+ expect([...readDisabledPluginLifecycleEntries(bootstrap)]).toEqual([
71
+ 'include:acryl-development-canvas',
72
+ ])
73
+ expect(pluginLifecyclePatches(bootstrap, new Set(['acryl-development-canvas']))).toEqual([{
74
+ id: 'acryl-development-canvas',
75
+ disabled: true,
76
+ }])
77
+ expect(JSON.parse(readFileSync(path, 'utf8'))).toEqual({
78
+ version: 1,
79
+ profiles: [{
80
+ profileName: 'desktop',
81
+ disabledEntries: ['include:acryl-development-canvas'],
82
+ }],
83
+ })
84
+
85
+ await setPluginLifecycleEntryEnabled(
86
+ bootstrap,
87
+ 'include:acryl-development-canvas',
88
+ true,
89
+ )
90
+ expect([...readDisabledPluginLifecycleEntries(bootstrap)]).toEqual([])
91
+ expect(JSON.parse(readFileSync(path, 'utf8'))).toEqual({ version: 1, profiles: [] })
92
+ })
93
+
94
+ it('keeps profile overrides isolated', async () => {
95
+ const path = statePath()
96
+ await setPluginLifecycleEntryEnabled(
97
+ { profileName: 'work', statePath: path },
98
+ 'include:acryl-development-canvas',
99
+ false,
100
+ )
101
+
102
+ expect(pluginLifecyclePatches({ profileName: 'desktop', statePath: path }, new Set(['acryl-development-canvas']))).toEqual([])
103
+ expect(pluginLifecyclePatches({ profileName: 'work', statePath: path }, new Set(['acryl-development-canvas']))).toHaveLength(1)
104
+ })
105
+
106
+ it('keeps any well-formed entry id, drops malformed ones, fails closed on corruption', async () => {
107
+ const path = statePath()
108
+ mkdirSync(join(path, '..'), { recursive: true })
109
+
110
+ // The mutable set is derived at runtime from the profile bundle list, not
111
+ // from this file, so a disabled id for any plugin the user added is kept -
112
+ // it is not restricted to a hard-coded allowlist. A structurally invalid
113
+ // string (bad charset, over length) is dropped so it cannot reach the
114
+ // Loader as a patch id.
115
+ writeFileSync(path, JSON.stringify({
116
+ version: 1,
117
+ profiles: [{
118
+ profileName: 'desktop',
119
+ disabledEntries: [
120
+ 'include:cordis-plugin-graph',
121
+ 'include:acryl-development-canvas',
122
+ 'include:has spaces',
123
+ ],
124
+ }],
125
+ }))
126
+ expect([...readDisabledPluginLifecycleEntries({ profileName: 'desktop', statePath: path })].sort())
127
+ .toEqual(['include:acryl-development-canvas', 'include:cordis-plugin-graph'])
128
+
129
+ // A non-string element is genuine corruption and still throws.
130
+ writeFileSync(path, JSON.stringify({
131
+ version: 1,
132
+ profiles: [{ profileName: 'desktop', disabledEntries: [42] }],
133
+ }))
134
+ expect(() => readDisabledPluginLifecycleEntries({ profileName: 'desktop', statePath: path }))
135
+ .toThrow('disabledEntries')
136
+
137
+ writeFileSync(path, JSON.stringify({ version: 1, profiles: [], extra: true }))
138
+ expect(() => readDisabledPluginLifecycleEntries({ profileName: 'desktop', statePath: path }))
139
+ .toThrow('version or profiles')
140
+
141
+ writeFileSync(path, JSON.stringify({
142
+ version: 1,
143
+ profiles: [{ profileName: 'desktop', disabledEntries: [], extra: true }],
144
+ }))
145
+ expect(() => readDisabledPluginLifecycleEntries({ profileName: 'desktop', statePath: path }))
146
+ .toThrow('profile name')
147
+
148
+ await expect(setPluginLifecycleEntryEnabled(
149
+ { profileName: 'desktop', statePath: path },
150
+ 'has spaces and slashes//',
151
+ false,
152
+ )).rejects.toThrow('malformed')
153
+ })
154
+
155
+
156
+
157
+ it('composes no disable for a row the profile does not have, and keeps it stored for when the plugin comes back (spec 048 T014)', async () => {
158
+ // The Development Canvas is a Market plugin: a home that disabled it and then uninstalled it booted with
159
+ // `patch: entry "desktop-development-canvas" not found` on every start.
160
+ const path = statePath()
161
+ mkdirSync(dirname(path), { recursive: true })
162
+ writeFileSync(path, JSON.stringify({ version: 1, profiles: [{ profileName: 'desktop', disabledEntries: ['include:desktop-development-canvas', 'include:other'] }] }))
163
+ const persistence = { profileName: 'desktop', statePath: path }
164
+ expect(pluginLifecyclePatches(persistence, new Set(['other', 'desktop-shell']))).toEqual([{ id: 'other', disabled: true }])
165
+ expect([...readDisabledPluginLifecycleEntries(persistence)]).toEqual(['include:acryl-development-canvas', 'include:other'])
166
+ expect(pluginLifecyclePatches(persistence, new Set(['acryl-development-canvas', 'other'])))
167
+ .toEqual([{ id: 'acryl-development-canvas', disabled: true }, { id: 'other', disabled: true }])
168
+ })
169
+ })
@@ -0,0 +1,58 @@
1
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import { parse } from 'yaml'
5
+ import { afterEach, describe, expect, it } from 'vitest'
6
+ import { reconcileProfileLayout } from '../src/profile-layout.ts'
7
+
8
+ const dirs: string[] = []
9
+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) })
10
+
11
+ function profile(recorded: Record<string, unknown> | undefined, workspace: string | undefined): string {
12
+ const dir = mkdtempSync(join(tmpdir(), 'acryl-layout-'))
13
+ dirs.push(dir)
14
+ if (recorded !== undefined) {
15
+ mkdirSync(join(dir, 'node_modules'))
16
+ // pnpm >= 10 writes JSON, older pnpm writes YAML; both are YAML documents.
17
+ writeFileSync(join(dir, 'node_modules', '.modules.yaml'), JSON.stringify(recorded))
18
+ }
19
+ if (workspace !== undefined) writeFileSync(join(dir, 'pnpm-workspace.yaml'), workspace)
20
+ return dir
21
+ }
22
+ const read = (dir: string): Record<string, unknown> => parse(readFileSync(join(dir, 'pnpm-workspace.yaml'), 'utf8')) as Record<string, unknown>
23
+
24
+ describe('reconcileProfileLayout', () => {
25
+ it('pins a recorded isolated layout over a workspace file that asks for hoisted', () => {
26
+ const dir = profile({ nodeLinker: 'isolated' }, 'packages:\n - .\n# keep me\nnodeLinker: hoisted\n')
27
+ expect(reconcileProfileLayout(dir)).toEqual([{ key: 'nodeLinker', from: 'hoisted', to: 'isolated' }])
28
+ expect(read(dir)['nodeLinker']).toBe('isolated')
29
+ expect(readFileSync(join(dir, 'pnpm-workspace.yaml'), 'utf8')).toContain('# keep me')
30
+ })
31
+
32
+ it('treats an absent nodeLinker as isolated and pins a recorded hoisted layout', () => {
33
+ const dir = profile({ nodeLinker: 'hoisted' }, 'packages:\n - .\n')
34
+ reconcileProfileLayout(dir)
35
+ expect(read(dir)['nodeLinker']).toBe('hoisted')
36
+ })
37
+
38
+ it('pins the recorded publicHoistPattern, including an empty one, and reads YAML-format records', () => {
39
+ const dir = profile(undefined, 'packages:\n - .\n')
40
+ mkdirSync(join(dir, 'node_modules'))
41
+ writeFileSync(join(dir, 'node_modules', '.modules.yaml'), 'nodeLinker: isolated\npublicHoistPattern:\n - "*eslint*"\n - "*prettier*"\n')
42
+ expect(reconcileProfileLayout(dir).map(change => change.key)).toEqual(['publicHoistPattern'])
43
+ expect(read(dir)['publicHoistPattern']).toEqual(['*eslint*', '*prettier*'])
44
+ const empty = profile({ nodeLinker: 'isolated', publicHoistPattern: [] }, 'packages:\n - .\n')
45
+ reconcileProfileLayout(empty)
46
+ expect(read(empty)['publicHoistPattern']).toEqual([])
47
+ })
48
+
49
+ it('is idempotent and leaves agreeing or unlaid-out profiles untouched', () => {
50
+ const dir = profile({ nodeLinker: 'isolated', publicHoistPattern: ['*eslint*'] }, 'packages:\n - .\nnodeLinker: isolated\npublicHoistPattern:\n - "*eslint*"\n')
51
+ expect(reconcileProfileLayout(dir)).toEqual([])
52
+ const before = readFileSync(join(dir, 'pnpm-workspace.yaml'), 'utf8')
53
+ expect(reconcileProfileLayout(dir)).toEqual([])
54
+ expect(readFileSync(join(dir, 'pnpm-workspace.yaml'), 'utf8')).toBe(before)
55
+ expect(reconcileProfileLayout(profile(undefined, 'packages:\n - .\n'))).toEqual([])
56
+ expect(reconcileProfileLayout(profile({ nodeLinker: 'hoisted' }, undefined))).toEqual([])
57
+ })
58
+ })
@@ -0,0 +1,38 @@
1
+ /** One profile, one live installation (spec 036): the guard that would have stopped a worktree run from re-linking a running app's profile. */
2
+ import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { afterEach, describe, expect, it } from 'vitest'
6
+ import { PROFILE_OWNER_FILE, ProfileInUseError, claimProfile } from '../src/profile-owner.ts'
7
+
8
+ const dirs: string[] = []
9
+ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { force: true, recursive: true }) })
10
+ const profile = (): string => { const dir = mkdtempSync(join(tmpdir(), 'acryl-owner-')); dirs.push(dir); return dir }
11
+
12
+ describe('claimProfile', () => {
13
+ it('a different installation cannot take a profile whose owner is running, and is told who holds it', () => {
14
+ const dir = profile()
15
+ claimProfile(dir, '/installs/main', 100, () => true)
16
+ expect(() => claimProfile(dir, '/installs/worktree', 200, () => true)).toThrow(ProfileInUseError)
17
+ expect(() => claimProfile(dir, '/installs/worktree', 200, () => true)).toThrow(/\/installs\/main, pid 100/)
18
+ expect(JSON.parse(readFileSync(join(dir, PROFILE_OWNER_FILE), 'utf8')).installRoot).toBe('/installs/main') // untouched
19
+ })
20
+
21
+ it('the same installation may always boot it (a Web server and a CLI of one checkout)', () => {
22
+ const dir = profile()
23
+ claimProfile(dir, '/installs/main', 100, () => true)
24
+ expect(() => claimProfile(dir, '/installs/main', 101, () => true)).not.toThrow()
25
+ })
26
+
27
+ it('a stopped or crashed owner is taken over', () => {
28
+ const dir = profile()
29
+ claimProfile(dir, '/installs/main', 100, () => true)
30
+ claimProfile(dir, '/installs/worktree', 200, () => false)
31
+ expect(JSON.parse(readFileSync(join(dir, PROFILE_OWNER_FILE), 'utf8'))).toMatchObject({ installRoot: '/installs/worktree', pid: 200 })
32
+ })
33
+
34
+ it('a missing or unreadable owner file is no owner', () => {
35
+ const dir = profile()
36
+ expect(() => claimProfile(dir, '/installs/a', 1, () => true)).not.toThrow()
37
+ })
38
+ })