@acryldev/harness-runtime 0.0.0-stage → 0.2.12
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.
- package/LICENSE +49 -0
- package/README.md +14 -2
- package/lib/index.mjs +5693 -0
- package/lib/index.mjs.map +1 -0
- package/lib/types/acryl-home.d.ts +81 -0
- package/lib/types/app/new-app.d.ts +65 -0
- package/lib/types/app/start-source.d.ts +47 -0
- package/lib/types/blueprint/blueprint.d.ts +74 -0
- package/lib/types/blueprint/brand-identity.d.ts +26 -0
- package/lib/types/blueprint/compose.d.ts +53 -0
- package/lib/types/blueprint/definition.d.ts +22 -0
- package/lib/types/blueprint/index.d.ts +7 -0
- package/lib/types/blueprint/manifest.d.ts +35 -0
- package/lib/types/blueprint/selection.d.ts +19 -0
- package/lib/types/cli-market-install.d.ts +97 -0
- package/lib/types/cli-market-plugins.d.ts +81 -0
- package/lib/types/coding-capabilities.d.ts +29 -0
- package/lib/types/durable-message.d.ts +18 -0
- package/lib/types/engine-dsh.d.ts +181 -0
- package/lib/types/engine-files.d.ts +8 -0
- package/lib/types/engine-host.d.ts +32 -0
- package/lib/types/engine-tools.d.ts +11 -0
- package/lib/types/index.d.ts +67 -0
- package/lib/types/instance/announce-self.d.ts +38 -0
- package/lib/types/instance/app-instance.d.ts +125 -0
- package/lib/types/instance/index.d.ts +6 -0
- package/lib/types/instance/offline-lock.d.ts +29 -0
- package/lib/types/instance/online-secret.d.ts +29 -0
- package/lib/types/instance/registry.d.ts +26 -0
- package/lib/types/instance/select.d.ts +43 -0
- package/lib/types/module-hooks.d.ts +19 -0
- package/lib/types/module-resolution.d.ts +31 -0
- package/lib/types/package-overlay.d.ts +41 -0
- package/lib/types/pinned-pnpm.d.ts +15 -0
- package/lib/types/plugin-acryl-workspace-status.d.ts +24 -0
- package/lib/types/plugin-doctor.d.ts +49 -0
- package/lib/types/plugin-lifecycle-state.d.ts +92 -0
- package/lib/types/plugin-lifecycle.d.ts +87 -0
- package/lib/types/profile-layout.d.ts +17 -0
- package/lib/types/profile-owner.d.ts +25 -0
- package/lib/types/profile-repair/backup.d.ts +37 -0
- package/lib/types/profile-repair/findings.d.ts +29 -0
- package/lib/types/profile-repair/index.d.ts +9 -0
- package/lib/types/profile-repair/inspector.d.ts +11 -0
- package/lib/types/profile-repair/repair.d.ts +38 -0
- package/lib/types/profile-resolution/moved-framework.d.ts +21 -0
- package/lib/types/profile-resolution/resolver.d.ts +41 -0
- package/lib/types/profile-resolution/service.d.ts +22 -0
- package/lib/types/prompt-budget.d.ts +44 -0
- package/lib/types/session-bridge.d.ts +57 -0
- package/lib/types/session-log-exporter.d.ts +31 -0
- package/lib/types/system-prompt-capture.d.ts +29 -0
- package/lib/types/web-favicon-data.d.ts +5 -0
- package/lib/types/web-favicon.d.ts +23 -0
- package/lib/types/web-market-install.d.ts +114 -0
- package/lib/types/web-market-plugins.d.ts +106 -0
- package/lib/types/web-port.d.ts +15 -0
- package/package.json +211 -3
- package/src/acryl-home.ts +103 -0
- package/src/app/new-app.ts +239 -0
- package/src/app/start-source.ts +110 -0
- package/src/blueprint/blueprint.ts +141 -0
- package/src/blueprint/brand-identity.ts +75 -0
- package/src/blueprint/compose.ts +222 -0
- package/src/blueprint/definition.ts +92 -0
- package/src/blueprint/index.ts +20 -0
- package/src/blueprint/manifest.ts +145 -0
- package/src/blueprint/selection.ts +74 -0
- package/src/cli-market-install.ts +181 -0
- package/src/cli-market-plugins.ts +176 -0
- package/src/coding-capabilities.ts +61 -0
- package/src/durable-message.ts +23 -0
- package/src/engine-dsh.ts +856 -0
- package/src/engine-files.ts +9 -0
- package/src/engine-host.ts +128 -0
- package/src/engine-tools.ts +26 -0
- package/src/index.ts +436 -0
- package/src/instance/announce-self.ts +88 -0
- package/src/instance/app-instance.ts +240 -0
- package/src/instance/index.ts +45 -0
- package/src/instance/offline-lock.ts +71 -0
- package/src/instance/online-secret.ts +55 -0
- package/src/instance/registry.ts +53 -0
- package/src/instance/select.ts +134 -0
- package/src/module-hooks.ts +41 -0
- package/src/module-resolution.ts +187 -0
- package/src/package-overlay.ts +160 -0
- package/src/pinned-pnpm.ts +67 -0
- package/src/plugin-acryl-workspace-status.ts +99 -0
- package/src/plugin-doctor.ts +141 -0
- package/src/plugin-lifecycle-state.ts +347 -0
- package/src/plugin-lifecycle.ts +223 -0
- package/src/profile-layout.ts +97 -0
- package/src/profile-owner.ts +52 -0
- package/src/profile-repair/backup.ts +119 -0
- package/src/profile-repair/findings.ts +43 -0
- package/src/profile-repair/index.ts +10 -0
- package/src/profile-repair/inspector.ts +156 -0
- package/src/profile-repair/repair.ts +137 -0
- package/src/profile-resolution/moved-framework.ts +64 -0
- package/src/profile-resolution/resolver.ts +876 -0
- package/src/profile-resolution/service.ts +99 -0
- package/src/prompt-budget.ts +118 -0
- package/src/session-bridge.ts +350 -0
- package/src/session-log-exporter.ts +68 -0
- package/src/system-prompt-capture.ts +99 -0
- package/src/web-favicon-data.ts +6 -0
- package/src/web-favicon.ts +43 -0
- package/src/web-market-install.ts +206 -0
- package/src/web-market-plugins.ts +215 -0
- package/src/web-port.ts +39 -0
- package/tests/account-callback.spec.ts +173 -0
- package/tests/acryl-home.spec.ts +39 -0
- package/tests/agent-self-hosting.spec.ts +101 -0
- package/tests/announce-self.spec.ts +84 -0
- package/tests/app-lifecycle.spec.ts +99 -0
- package/tests/blank-blueprint.spec.ts +110 -0
- package/tests/blueprint-definition.spec.ts +128 -0
- package/tests/blueprint.spec.ts +138 -0
- package/tests/bulkhead.spec.ts +187 -0
- package/tests/coding-vocabulary.spec.ts +15 -0
- package/tests/dump-system-prompt.spec.ts +65 -0
- package/tests/e2e-real-model.spec.ts +71 -0
- package/tests/e2e-restart-real-model.spec.ts +77 -0
- package/tests/engine-dsh.spec.ts +340 -0
- package/tests/engine-host-mount-root-include.spec.ts +118 -0
- package/tests/engine-host.spec.ts +176 -0
- package/tests/engine-optional.spec.ts +81 -0
- package/tests/extension-examples.spec.ts +261 -0
- package/tests/hooks-thread-stack.ts +27 -0
- package/tests/instance-patches.spec.ts +25 -0
- package/tests/instance.spec.ts +235 -0
- package/tests/live/community-plugins.spec.ts +83 -0
- package/tests/module-hooks.spec.ts +35 -0
- package/tests/module-resolution.spec.ts +265 -0
- package/tests/moved-framework.spec.ts +61 -0
- package/tests/new-app.spec.ts +132 -0
- package/tests/organizer-growth.spec.ts +117 -0
- package/tests/pinned-pnpm.spec.ts +34 -0
- package/tests/plugin-acryl-workspace-status.spec.ts +63 -0
- package/tests/plugin-context.spec.ts +640 -0
- package/tests/plugin-doctor.spec.ts +183 -0
- package/tests/plugin-enablement-one-store.spec.ts +130 -0
- package/tests/plugin-lifecycle-state.spec.ts +169 -0
- package/tests/profile-layout.spec.ts +58 -0
- package/tests/profile-owner.spec.ts +38 -0
- package/tests/profile-repair/profile-repair.spec.ts +231 -0
- package/tests/profile-resolution-port.spec.ts +30 -0
- package/tests/profile-resolution-service.spec.ts +273 -0
- package/tests/profile-resolution-swap.spec.ts +69 -0
- package/tests/profile-resolution.spec.ts +2535 -0
- package/tests/profile.spec.ts +70 -0
- package/tests/project-registry.spec.ts +81 -0
- package/tests/prompt-budget.spec.ts +58 -0
- package/tests/real-home-guard.spec.ts +178 -0
- package/tests/session-bridge.spec.ts +316 -0
- package/tests/start-source.spec.ts +65 -0
- package/tests/system-prompt-shape.spec.ts +95 -0
- package/tests/three-levels.spec.ts +84 -0
- package/tests/tool-gateway.spec.ts +116 -0
- package/tests/tool-schemas.spec.ts +41 -0
- package/tests/web-favicon.spec.ts +42 -0
- package/tests/web-port.spec.ts +38 -0
- package/tests/web-startup-hold.spec.ts +79 -0
- package/tsconfig.json +24 -0
- package/tsdown.config.ts +2 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Real-engine proof for the Extension Context Pack (spec 037): the web engine
|
|
3
|
+
* mounts the plugin, the assembled system prompt carries the docs router with
|
|
4
|
+
* paths that exist on disk, and the install tool the agent needs is registered.
|
|
5
|
+
*/
|
|
6
|
+
import { cpSync, 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 { afterEach, describe, expect, it } from 'vitest'
|
|
12
|
+
import { createDshEngineDefinition, createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
13
|
+
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
14
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
15
|
+
// @ts-expect-error plain JS package
|
|
16
|
+
import { installLocalPlugin, listLocalPlugins, removeLocalPlugin } from '../../../plugins/plugin-context/lib/install.js'
|
|
17
|
+
// @ts-expect-error plain JS package
|
|
18
|
+
import { stagedInfo } from '../../../plugins/plugin-context/lib/reconcile.js'
|
|
19
|
+
// @ts-expect-error plain JS package
|
|
20
|
+
import { hashPackage } from '../../../plugins/plugin-context/lib/stage.js'
|
|
21
|
+
import { createAcrylSessionBridge } from '../src/session-bridge.ts'
|
|
22
|
+
import { fileURLToPath } from 'node:url'
|
|
23
|
+
import { codingCapabilities } from '@acryldev/coding-capabilities'
|
|
24
|
+
|
|
25
|
+
const temporaryHomes: string[] = []
|
|
26
|
+
const initialDshHome = process.env.DSH_HOME
|
|
27
|
+
|
|
28
|
+
afterEach(async () => {
|
|
29
|
+
// Assigning undefined would store the string "undefined" and the next boot would create a ./undefined profile directory.
|
|
30
|
+
if (initialDshHome === undefined) delete process.env.DSH_HOME
|
|
31
|
+
else process.env.DSH_HOME = initialDshHome
|
|
32
|
+
await Promise.all(temporaryHomes.splice(0).map(home => rm(home, { force: true, recursive: true })))
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('extension context on the web engine', () => {
|
|
36
|
+
it('mounts, routes the prompt to docs that exist, and registers the install tool', async () => {
|
|
37
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-plugin-context-'))
|
|
38
|
+
temporaryHomes.push(home)
|
|
39
|
+
process.env.DSH_HOME = home
|
|
40
|
+
const installPackageUrl = new URL('../package.json', import.meta.url).href
|
|
41
|
+
const host = await createAcrylEngineHost({
|
|
42
|
+
engines: [createWebEngineDefinition(installPackageUrl, codingCapabilities)],
|
|
43
|
+
initialEngine: 'dsh',
|
|
44
|
+
prepare: hostCtx => {
|
|
45
|
+
provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} })
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
try {
|
|
49
|
+
const rows = [...host.ctx.loader.entries()]
|
|
50
|
+
expect(rows.some(entry => entry.options.id === 'acryl-plugin-context')).toBe(true)
|
|
51
|
+
// The UI library (spec 038-ui-component-library) is a Loader row on the web engine, so every client bundle can require('@acryl/ui').
|
|
52
|
+
expect(rows.some(entry => entry.options.id === '@acryl/ui')).toBe(true)
|
|
53
|
+
|
|
54
|
+
const context = host.ctx.get('pluginContext' as never) as { root: string } | undefined
|
|
55
|
+
expect(context).toBeDefined()
|
|
56
|
+
expect(existsSync(join(context!.root, 'docs', 'docs.json'))).toBe(true)
|
|
57
|
+
|
|
58
|
+
const assembly = await host.ctx.get('systemPrompt')!.assemble()
|
|
59
|
+
const router = assembly.sections.find(section => section.name === 'acryl:plugin-router')
|
|
60
|
+
expect(router).toBeDefined()
|
|
61
|
+
const text = String((router as { text?: unknown }).text)
|
|
62
|
+
expect(text).toContain(context!.root) // one absolute pack root; the doc paths after it are relative
|
|
63
|
+
expect(text).toContain('docs/README.md')
|
|
64
|
+
expect(text).toContain('acryl_install_plugin')
|
|
65
|
+
expect(existsSync(join(context!.root, 'docs', 'start-here', 'this-runtime.md'))).toBe(true)
|
|
66
|
+
|
|
67
|
+
const toolNames = assembly.tools.map(tool => tool.name)
|
|
68
|
+
expect(toolNames).toEqual(expect.arrayContaining(['acryl_install_plugin', 'acryl_list_plugins', 'acryl_remove_plugin', 'acryl_prepare_publish', 'acryl_verify_plugin', 'acryl_plugin_lookup']))
|
|
69
|
+
} finally {
|
|
70
|
+
await host.dispose()
|
|
71
|
+
}
|
|
72
|
+
}, 60_000)
|
|
73
|
+
|
|
74
|
+
it('mounts on the CLI (tui) engine too', async () => {
|
|
75
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-plugin-context-tui-'))
|
|
76
|
+
temporaryHomes.push(home)
|
|
77
|
+
process.env.DSH_HOME = home
|
|
78
|
+
const host = await createAcrylEngineHost({
|
|
79
|
+
engines: [createDshEngineDefinition('acryl-ext-test', codingCapabilities)],
|
|
80
|
+
initialEngine: 'dsh',
|
|
81
|
+
})
|
|
82
|
+
try {
|
|
83
|
+
const rows = [...host.ctx.loader.entries()]
|
|
84
|
+
expect(rows.some(entry => entry.options.id === 'acryl-plugin-context')).toBe(true)
|
|
85
|
+
const assembly = await host.ctx.get('systemPrompt')!.assemble()
|
|
86
|
+
expect(assembly.sections.some(section => section.name === 'acryl:plugin-router')).toBe(true)
|
|
87
|
+
expect(assembly.tools.map(tool => tool.name)).toEqual(expect.arrayContaining(['acryl_install_plugin']))
|
|
88
|
+
} finally {
|
|
89
|
+
await host.dispose()
|
|
90
|
+
}
|
|
91
|
+
}, 60_000)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
describe('/reload on the web engine', () => {
|
|
95
|
+
it('is registered for a session and re-installs no local plugins when there are none', async () => {
|
|
96
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-reload-'))
|
|
97
|
+
temporaryHomes.push(home)
|
|
98
|
+
process.env.DSH_HOME = home
|
|
99
|
+
const host = await createAcrylEngineHost({
|
|
100
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
101
|
+
initialEngine: 'dsh',
|
|
102
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
103
|
+
})
|
|
104
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'reload', attachment: 'owner', cwd: home })
|
|
105
|
+
try {
|
|
106
|
+
const sessionId = await bridge.open()
|
|
107
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
108
|
+
const commands = host.ctx.get('commands' as never) as {
|
|
109
|
+
list(agent: unknown): Array<{ name: string }>
|
|
110
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
111
|
+
}
|
|
112
|
+
expect(commands.list(agent).map(command => command.name)).toContain('reload')
|
|
113
|
+
const execution = await commands.execute(agent, '/reload', [], new AbortController().signal)
|
|
114
|
+
expect(execution?.result).toMatchObject({ kind: 'success', text: 'No local plugins installed or found in <workspace>/.acryl-plugins/ or the global plugins folder.' })
|
|
115
|
+
} finally {
|
|
116
|
+
await bridge.dispose()
|
|
117
|
+
await host.dispose()
|
|
118
|
+
}
|
|
119
|
+
}, 60_000)
|
|
120
|
+
|
|
121
|
+
it('reports the real surface and profile to the workspace-status tool', async () => {
|
|
122
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-surface-'))
|
|
123
|
+
temporaryHomes.push(home)
|
|
124
|
+
process.env.DSH_HOME = home
|
|
125
|
+
const host = await createAcrylEngineHost({
|
|
126
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
127
|
+
initialEngine: 'dsh',
|
|
128
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
129
|
+
})
|
|
130
|
+
try {
|
|
131
|
+
expect(process.env.ACRYL_SURFACE).toBe('web')
|
|
132
|
+
expect(process.env.ACRYL_PROFILE).toBe('web')
|
|
133
|
+
} finally { await host.dispose() }
|
|
134
|
+
}, 60_000)
|
|
135
|
+
|
|
136
|
+
it('/reload lists a new folder from the session workspace, /reload new installs it, and the prompt then lists it', async () => {
|
|
137
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-discover-'))
|
|
138
|
+
temporaryHomes.push(home)
|
|
139
|
+
process.env.DSH_HOME = home
|
|
140
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-extension-ws-'))
|
|
141
|
+
temporaryHomes.push(workspace)
|
|
142
|
+
const source = fileURLToPath(new URL('../../../plugins/plugin-context/example-plugins/packages/tool-basic/', import.meta.url))
|
|
143
|
+
const target = join(workspace, '.acryl-plugins', 'dropped-tool')
|
|
144
|
+
mkdirSync(join(workspace, '.acryl-plugins'), { recursive: true })
|
|
145
|
+
cpSync(source, target, { recursive: true })
|
|
146
|
+
const host = await createAcrylEngineHost({
|
|
147
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
148
|
+
initialEngine: 'dsh',
|
|
149
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
150
|
+
})
|
|
151
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'discover', attachment: 'owner', cwd: workspace })
|
|
152
|
+
try {
|
|
153
|
+
const sessionId = await bridge.open()
|
|
154
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
155
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
156
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
157
|
+
}
|
|
158
|
+
const before = await (host.ctx.get('systemPrompt' as never) as unknown as { assemble(): Promise<{ contexts: Array<{ name: string; text: string }> }> }).assemble()
|
|
159
|
+
expect(before.contexts.find(c => c.name === 'acryl:installed-plugins')?.text ?? '').toBe('')
|
|
160
|
+
// Plain /reload only LISTS a new folder (it would run with the user's permissions); nothing is installed.
|
|
161
|
+
const listed = await commands.execute(agent, '/reload', [], new AbortController().signal)
|
|
162
|
+
expect(listed?.result.text).toContain('NEW, not installed')
|
|
163
|
+
const stillEmpty = await (host.ctx.get('systemPrompt' as never) as unknown as { assemble(): Promise<{ contexts: Array<{ name: string; text: string }> }> }).assemble()
|
|
164
|
+
expect(stillEmpty.contexts.find(c => c.name === 'acryl:installed-plugins')?.text ?? '').toBe('')
|
|
165
|
+
const execution = await commands.execute(agent, '/reload new', [], new AbortController().signal)
|
|
166
|
+
expect(execution?.result.kind).toBe('success')
|
|
167
|
+
expect(execution?.result.text).toContain('(new)')
|
|
168
|
+
const after = await (host.ctx.get('systemPrompt' as never) as unknown as { assemble(): Promise<{ contexts: Array<{ name: string; text: string }> }> }).assemble()
|
|
169
|
+
const listing = after.contexts.find(c => c.name === 'acryl:installed-plugins')?.text ?? ''
|
|
170
|
+
expect(listing).toContain('acryl-example-tool')
|
|
171
|
+
expect(listing).toContain('dropped-tool')
|
|
172
|
+
} finally {
|
|
173
|
+
await bridge.dispose()
|
|
174
|
+
await host.dispose()
|
|
175
|
+
}
|
|
176
|
+
}, 120_000)
|
|
177
|
+
|
|
178
|
+
it('/reload discovers the GLOBAL scope, installs it on request, and skips an unchanged source (shadowing is covered by the pack unit test)', async () => {
|
|
179
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-global-'))
|
|
180
|
+
temporaryHomes.push(home)
|
|
181
|
+
process.env.DSH_HOME = home // not named .dsh, so the global directory is <home>/extensions
|
|
182
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-extension-global-ws-'))
|
|
183
|
+
temporaryHomes.push(workspace)
|
|
184
|
+
const source = fileURLToPath(new URL('../../../plugins/plugin-context/example-plugins/packages/tool-basic/', import.meta.url))
|
|
185
|
+
cpSync(source, join(home, 'plugins', 'global-tool'), { recursive: true })
|
|
186
|
+
const host = await createAcrylEngineHost({
|
|
187
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
188
|
+
initialEngine: 'dsh',
|
|
189
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
190
|
+
})
|
|
191
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'global', attachment: 'owner', cwd: workspace })
|
|
192
|
+
try {
|
|
193
|
+
const sessionId = await bridge.open()
|
|
194
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
195
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
196
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
197
|
+
}
|
|
198
|
+
const run = async (line: string) => (await commands.execute(agent, line, [], new AbortController().signal))?.result.text ?? ''
|
|
199
|
+
expect(await run('/reload')).toContain('[global]: NEW, not installed')
|
|
200
|
+
expect(await run('/reload new')).toContain('acryl-example-tool [global]: installed (new)')
|
|
201
|
+
// Nothing changed on disk: the second reload does not run the package manager or restart the plugin.
|
|
202
|
+
const again = await run('/reload')
|
|
203
|
+
expect(again).toContain('acryl-example-tool [global]: unchanged')
|
|
204
|
+
expect(again).not.toContain('Reload the page')
|
|
205
|
+
// A project folder is listed with its own scope tag.
|
|
206
|
+
cpSync(source, join(workspace, '.acryl-plugins', 'project-tool'), { recursive: true })
|
|
207
|
+
expect(await run('/reload')).toContain('[project]: NEW, not installed')
|
|
208
|
+
} finally {
|
|
209
|
+
await bridge.dispose()
|
|
210
|
+
await host.dispose()
|
|
211
|
+
}
|
|
212
|
+
}, 180_000)
|
|
213
|
+
|
|
214
|
+
it('the startup pass re-syncs a changed GLOBAL extension by itself, and /reload shows the permissions a NEW one requests', async () => {
|
|
215
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-startup-'))
|
|
216
|
+
temporaryHomes.push(home)
|
|
217
|
+
process.env.DSH_HOME = home // not named .dsh, so the global directory is <home>/extensions
|
|
218
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-extension-startup-ws-'))
|
|
219
|
+
temporaryHomes.push(workspace)
|
|
220
|
+
const source = fileURLToPath(new URL('../../../plugins/plugin-context/example-plugins/packages/tool-basic/', import.meta.url))
|
|
221
|
+
const target = join(home, 'plugins', 'startup-tool')
|
|
222
|
+
cpSync(source, target, { recursive: true })
|
|
223
|
+
const manifestPath = join(target, 'package.json')
|
|
224
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
225
|
+
writeFileSync(manifestPath, JSON.stringify({ ...manifest, acryl: { apiVersion: 1, permissions: ['shell'] } }))
|
|
226
|
+
const boot = () => createAcrylEngineHost({
|
|
227
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
228
|
+
initialEngine: 'dsh',
|
|
229
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
230
|
+
})
|
|
231
|
+
// First run: the human installs it (permissions are shown first), then the app closes.
|
|
232
|
+
let host = await boot()
|
|
233
|
+
let bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'startup-1', attachment: 'owner', cwd: workspace })
|
|
234
|
+
let profileDir: string
|
|
235
|
+
try {
|
|
236
|
+
const sessionId = await bridge.open()
|
|
237
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
238
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
239
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { text?: string } } | undefined>
|
|
240
|
+
}
|
|
241
|
+
const listed = (await commands.execute(agent, '/reload', [], new AbortController().signal))?.result.text ?? ''
|
|
242
|
+
expect(listed).toContain('requests: shell')
|
|
243
|
+
expect((await commands.execute(agent, '/reload new', [], new AbortController().signal))?.result.text).toContain('installed (new)')
|
|
244
|
+
profileDir = (host.ctx.get('desktopProfiles' as never) as { current: { dir: string } }).current.dir
|
|
245
|
+
} finally { await bridge.dispose(); await host.dispose() }
|
|
246
|
+
|
|
247
|
+
// The source changes while the app is closed (an edit, a sync). Booting again must apply it without any command.
|
|
248
|
+
writeFileSync(join(target, 'index.js'), `${readFileSync(join(target, 'index.js'), 'utf8')}\n// changed while closed\n`)
|
|
249
|
+
const inSync = () => {
|
|
250
|
+
const [plugin] = listLocalPlugins(profileDir) as Array<{ installedDir: string; installedFrom: string }>
|
|
251
|
+
return plugin !== undefined && stagedInfo(plugin.installedDir)?.version === hashPackage(plugin.installedFrom)
|
|
252
|
+
}
|
|
253
|
+
expect(inSync()).toBe(false)
|
|
254
|
+
host = await boot()
|
|
255
|
+
bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'startup-2', attachment: 'owner', cwd: workspace })
|
|
256
|
+
try {
|
|
257
|
+
const deadline = Date.now() + 90_000
|
|
258
|
+
while (!inSync() && Date.now() < deadline) await new Promise(resolve => setTimeout(resolve, 500))
|
|
259
|
+
expect(inSync()).toBe(true)
|
|
260
|
+
} finally { await bridge.dispose(); await host.dispose() }
|
|
261
|
+
}, 240_000)
|
|
262
|
+
|
|
263
|
+
it('/blend snapshot captures marketplace and local plugins into the workspace, and /blend verify checks it against its lock', async () => {
|
|
264
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-blend-'))
|
|
265
|
+
temporaryHomes.push(home)
|
|
266
|
+
process.env.DSH_HOME = home
|
|
267
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-extension-blend-ws-'))
|
|
268
|
+
temporaryHomes.push(workspace)
|
|
269
|
+
const source = fileURLToPath(new URL('../../../plugins/plugin-context/example-plugins/packages/tool-basic/', import.meta.url))
|
|
270
|
+
cpSync(source, join(workspace, '.acryl-plugins', 'blend-tool'), { recursive: true })
|
|
271
|
+
const host = await createAcrylEngineHost({
|
|
272
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
273
|
+
initialEngine: 'dsh',
|
|
274
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
275
|
+
})
|
|
276
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'blend', attachment: 'owner', cwd: workspace })
|
|
277
|
+
try {
|
|
278
|
+
const sessionId = await bridge.open()
|
|
279
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
280
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
281
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
282
|
+
}
|
|
283
|
+
const run = async (line: string) => (await commands.execute(agent, line, [], new AbortController().signal))?.result
|
|
284
|
+
expect((await run('/reload new'))?.text).toContain('installed (new)')
|
|
285
|
+
const snapshot = await run('/blend snapshot')
|
|
286
|
+
expect(snapshot?.kind).toBe('success')
|
|
287
|
+
expect(snapshot?.text).toContain('1 local plugin(s) vendored')
|
|
288
|
+
const out = join(workspace, '.acryl', 'blend')
|
|
289
|
+
const lock = JSON.parse(readFileSync(join(out, 'blend.lock.json'), 'utf8'))
|
|
290
|
+
expect(lock.formatVersion).toBe(3)
|
|
291
|
+
expect(lock.modules).toEqual([expect.objectContaining({ name: 'acryl-example-tool', origin: 'local', source: 'plugins/acryl-example-tool' })])
|
|
292
|
+
expect(existsSync(join(out, 'plugins', 'acryl-example-tool', 'index.js'))).toBe(true)
|
|
293
|
+
expect(readFileSync(join(out, 'blend.yaml'), 'utf8')).toContain('name: acryl-example-tool')
|
|
294
|
+
expect((await run('/blend verify'))?.text).toContain('ledger: 1 entries, chain intact') // the capture itself is the first ledger entry
|
|
295
|
+
// From now on this workspace tracks a Blend: a plugin installed later is one line of history.
|
|
296
|
+
cpSync(source, join(workspace, '.acryl-plugins', 'second-tool'), { recursive: true })
|
|
297
|
+
const secondManifest = JSON.parse(readFileSync(join(workspace, '.acryl-plugins', 'second-tool', 'package.json'), 'utf8'))
|
|
298
|
+
writeFileSync(join(workspace, '.acryl-plugins', 'second-tool', 'package.json'), JSON.stringify({ ...secondManifest, name: 'acryl-second-tool' }))
|
|
299
|
+
writeFileSync(join(workspace, '.acryl-plugins', 'second-tool', 'cordis.patch.yml'), '- insert:\n - id: second-tool\n name: acryl-second-tool\n')
|
|
300
|
+
writeFileSync(join(workspace, '.acryl-plugins', 'second-tool', 'index.js'), "export const name = 'acryl-second-tool'\nexport function apply() {}\n") // registers nothing, so it cannot clash with the first tool
|
|
301
|
+
const reloadNew = (await run('/reload new'))?.text
|
|
302
|
+
expect(reloadNew, String(reloadNew)).toContain('installed (new)')
|
|
303
|
+
const ledger = (await run('/blend ledger'))?.text ?? ''
|
|
304
|
+
expect(ledger).toContain('human captured'); expect(ledger).toContain('human installed acryl-second-tool@0.1.0')
|
|
305
|
+
const ledgerFile = join(out, 'ledger.jsonl')
|
|
306
|
+
expect(readFileSync(ledgerFile, 'utf8').trim().split('\n')).toHaveLength(2) // captured, then the install
|
|
307
|
+
// editing history is detected
|
|
308
|
+
const lines = readFileSync(ledgerFile, 'utf8').trim().split('\n')
|
|
309
|
+
writeFileSync(ledgerFile, `${[lines[0].replace('captured', 'applied'), lines[1]].join('\n')}\n`)
|
|
310
|
+
expect((await run('/blend verify'))?.text).toContain('line 2 does not follow line 1')
|
|
311
|
+
writeFileSync(ledgerFile, `${lines.join('\n')}\n`)
|
|
312
|
+
writeFileSync(join(out, 'plugins', 'acryl-example-tool', 'index.js'), '// tampered\n')
|
|
313
|
+
const broken = await run('/blend verify')
|
|
314
|
+
expect(broken?.kind).toBe('error')
|
|
315
|
+
expect(broken?.text).toContain('differs from the locked digest')
|
|
316
|
+
expect((await run('/blend nonsense'))?.kind).toBe('error')
|
|
317
|
+
} finally {
|
|
318
|
+
await bridge.dispose()
|
|
319
|
+
await host.dispose()
|
|
320
|
+
}
|
|
321
|
+
}, 180_000)
|
|
322
|
+
|
|
323
|
+
it('a Blend captured on one app is re-created on a fresh app with /blend apply (round trip)', async () => {
|
|
324
|
+
const boot = () => createAcrylEngineHost({
|
|
325
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
326
|
+
initialEngine: 'dsh',
|
|
327
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
328
|
+
})
|
|
329
|
+
const runner = async (host: Awaited<ReturnType<typeof boot>>, generationId: string, cwd: string) => {
|
|
330
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId, attachment: 'owner', cwd })
|
|
331
|
+
const sessionId = await bridge.open()
|
|
332
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
333
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
334
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
335
|
+
}
|
|
336
|
+
return { bridge, run: async (line: string) => (await commands.execute(agent, line, [], new AbortController().signal))?.result }
|
|
337
|
+
}
|
|
338
|
+
const source = fileURLToPath(new URL('../../../plugins/plugin-context/example-plugins/packages/tool-basic/', import.meta.url))
|
|
339
|
+
|
|
340
|
+
// App A: build a local extension, install it, capture the Blend.
|
|
341
|
+
const homeA = await mkdtemp(join(tmpdir(), 'acryl-blend-a-')); temporaryHomes.push(homeA)
|
|
342
|
+
const wsA = await mkdtemp(join(tmpdir(), 'acryl-blend-a-ws-')); temporaryHomes.push(wsA)
|
|
343
|
+
process.env.DSH_HOME = homeA
|
|
344
|
+
cpSync(source, join(wsA, '.acryl-plugins', 'round-trip'), { recursive: true })
|
|
345
|
+
let host = await boot()
|
|
346
|
+
let session = await runner(host, 'blend-a', wsA)
|
|
347
|
+
try {
|
|
348
|
+
expect((await session.run('/reload new'))?.text).toContain('installed (new)')
|
|
349
|
+
expect((await session.run('/blend snapshot'))?.kind).toBe('success')
|
|
350
|
+
} finally { await session.bridge.dispose(); await host.dispose() }
|
|
351
|
+
|
|
352
|
+
// App B: a different home and a different workspace that only has the captured .acryl/blend directory.
|
|
353
|
+
const homeB = await mkdtemp(join(tmpdir(), 'acryl-blend-b-')); temporaryHomes.push(homeB)
|
|
354
|
+
const wsB = await mkdtemp(join(tmpdir(), 'acryl-blend-b-ws-')); temporaryHomes.push(wsB)
|
|
355
|
+
process.env.DSH_HOME = homeB
|
|
356
|
+
cpSync(join(wsA, '.acryl', 'blend'), join(wsB, '.acryl', 'blend'), { recursive: true })
|
|
357
|
+
host = await boot()
|
|
358
|
+
session = await runner(host, 'blend-b', wsB)
|
|
359
|
+
try {
|
|
360
|
+
expect((await session.run('/reload'))?.text).not.toContain('acryl-example-tool') // nothing installed yet
|
|
361
|
+
const applied = await session.run('/blend apply')
|
|
362
|
+
expect(applied?.kind).toBe('success')
|
|
363
|
+
expect(applied?.text).toContain('acryl-example-tool [local]: installed')
|
|
364
|
+
expect(existsSync(join(wsB, '.acryl-plugins', 'acryl-example-tool', 'index.js'))).toBe(true)
|
|
365
|
+
const again = await session.run('/blend apply')
|
|
366
|
+
expect(again?.text).toContain('acryl-example-tool [local]: unchanged') // idempotent
|
|
367
|
+
expect((await session.run('/reload'))?.text).toContain('acryl-example-tool [project]: unchanged')
|
|
368
|
+
} finally { await session.bridge.dispose(); await host.dispose() }
|
|
369
|
+
}, 300_000)
|
|
370
|
+
|
|
371
|
+
it('host code updates take effect in the running process without a hot shim (automatic reload)', async () => {
|
|
372
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-hot-'))
|
|
373
|
+
temporaryHomes.push(home)
|
|
374
|
+
process.env.DSH_HOME = home
|
|
375
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-extension-hot-ws-'))
|
|
376
|
+
temporaryHomes.push(workspace)
|
|
377
|
+
const dir = join(workspace, '.acryl-plugins', 'probe')
|
|
378
|
+
mkdirSync(dir, { recursive: true })
|
|
379
|
+
const write = (entryText: string, helperText: string, extra = '') => {
|
|
380
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({
|
|
381
|
+
name: 'acryl-probe-hot', version: '0.1.0', type: 'module', main: './index.js',
|
|
382
|
+
exports: { '.': './index.js', './package.json': './package.json' },
|
|
383
|
+
files: ['index.js', 'helper.js', 'cordis.patch.yml'],
|
|
384
|
+
dsh: { bundle: { patch: './cordis.patch.yml' } },
|
|
385
|
+
}))
|
|
386
|
+
writeFileSync(join(dir, 'cordis.patch.yml'), '- insert:\n - id: probe-hot\n name: acryl-probe-hot\n')
|
|
387
|
+
writeFileSync(join(dir, 'helper.js'), `export const text = ${JSON.stringify(helperText)}\n`)
|
|
388
|
+
writeFileSync(join(dir, 'index.js'), [
|
|
389
|
+
"import { text } from './helper.js'",
|
|
390
|
+
"export const name = 'acryl-probe-hot'",
|
|
391
|
+
"export const inject = ['commands']",
|
|
392
|
+
'export function apply(ctx) {',
|
|
393
|
+
" ctx.effect(() => ctx.commands.register({ name: 'probe-hot', description: 'probe', async handler() { return { kind: 'success', text: " + JSON.stringify(entryText) + " + text } } }), 'probe')",
|
|
394
|
+
'}',
|
|
395
|
+
extra,
|
|
396
|
+
].join('\n'))
|
|
397
|
+
}
|
|
398
|
+
write('entry-1:', 'helper-1')
|
|
399
|
+
const host = await createAcrylEngineHost({
|
|
400
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
401
|
+
initialEngine: 'dsh',
|
|
402
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
403
|
+
})
|
|
404
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'hot', attachment: 'owner', cwd: workspace })
|
|
405
|
+
try {
|
|
406
|
+
const sessionId = await bridge.open()
|
|
407
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
408
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
409
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
410
|
+
}
|
|
411
|
+
const services = {
|
|
412
|
+
pnpm: host.ctx.get('desktopPnpm' as never),
|
|
413
|
+
live: host.ctx.get('livePluginActivation' as never),
|
|
414
|
+
profileDir: (host.ctx.get('desktopProfiles' as never) as { current: { dir: string } }).current.dir,
|
|
415
|
+
}
|
|
416
|
+
const first = await installLocalPlugin({ path: dir }, services)
|
|
417
|
+
expect(first).toMatchObject({ ok: true, status: 'active', action: 'installed', hostReload: 'automatic' })
|
|
418
|
+
expect((await commands.execute(agent, '/probe-hot', [], new AbortController().signal))?.result.text).toBe('entry-1:helper-1')
|
|
419
|
+
|
|
420
|
+
// Change BOTH the entry and the file it imports: the running process must pick up both.
|
|
421
|
+
write('entry-2:', 'helper-2')
|
|
422
|
+
const second = await installLocalPlugin({ path: dir }, services)
|
|
423
|
+
expect(second).toMatchObject({ ok: true, status: 'active', action: 'updated', hostReload: 'automatic' })
|
|
424
|
+
expect(second.warning).toBeUndefined()
|
|
425
|
+
expect((await commands.execute(agent, '/probe-hot', [], new AbortController().signal))?.result.text).toBe('entry-2:helper-2')
|
|
426
|
+
|
|
427
|
+
// /reload re-installs from the SOURCE folder (not the staging copy).
|
|
428
|
+
write('entry-3:', 'helper-3')
|
|
429
|
+
const reloaded = await commands.execute(agent, '/reload', [], new AbortController().signal)
|
|
430
|
+
expect(reloaded?.result.text).toContain('acryl-probe-hot [project]: updated')
|
|
431
|
+
expect((await commands.execute(agent, '/probe-hot', [], new AbortController().signal))?.result.text).toBe('entry-3:helper-3')
|
|
432
|
+
} finally {
|
|
433
|
+
await bridge.dispose()
|
|
434
|
+
await host.dispose()
|
|
435
|
+
}
|
|
436
|
+
}, 180_000)
|
|
437
|
+
|
|
438
|
+
it('a plugin that injects dshHomePath goes ACTIVE, and its data folder is under the app home (the state example, no homedir() fallback)', async () => {
|
|
439
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-home-'))
|
|
440
|
+
temporaryHomes.push(home)
|
|
441
|
+
process.env.DSH_HOME = home
|
|
442
|
+
const host = await createAcrylEngineHost({
|
|
443
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
444
|
+
initialEngine: 'dsh',
|
|
445
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
446
|
+
})
|
|
447
|
+
try {
|
|
448
|
+
const services = {
|
|
449
|
+
pnpm: host.ctx.get('desktopPnpm' as never),
|
|
450
|
+
live: host.ctx.get('livePluginActivation' as never),
|
|
451
|
+
profileDir: (host.ctx.get('desktopProfiles' as never) as { current: { dir: string } }).current.dir,
|
|
452
|
+
}
|
|
453
|
+
const example = fileURLToPath(new URL('../../../plugins/plugin-context/example-plugins/packages/state-host-store/', import.meta.url))
|
|
454
|
+
const result = await installLocalPlugin({ path: example }, services)
|
|
455
|
+
expect(result).toMatchObject({ ok: true, status: 'active' })
|
|
456
|
+
const dshHomePath = host.ctx.get('dshHomePath' as never) as unknown as (...parts: string[]) => string
|
|
457
|
+
expect(dshHomePath('plugin-data', 'acryl-example-state-host').startsWith(home)).toBe(true)
|
|
458
|
+
// A real RPC round trip through connection's shared /api handler, as the page's `rpc.call('/api', ...)` sends it: the routes work
|
|
459
|
+
// without `webServer`, which is what makes the example run in stock DSH too (spec 044 S11).
|
|
460
|
+
const connection = host.ctx.get('connection' as never) as unknown as { createSharedFetchHandler(channel: '/api'): { fetch(request: Request): Promise<Response> } }
|
|
461
|
+
const api = connection.createSharedFetchHandler('/api')
|
|
462
|
+
const call = async (endpoint: string, payload: unknown) => {
|
|
463
|
+
const response = await api.fetch(new Request(`http://127.0.0.1/api/acryl-example-state-host/${endpoint}`, {
|
|
464
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
465
|
+
body: JSON.stringify({ type: 'client-request', rpcId: `r-${endpoint}`, method: `acryl-example-state-host/${endpoint}`, payload }),
|
|
466
|
+
}))
|
|
467
|
+
return { status: response.status, body: await response.json() as { type: string; rpcId: string; result: { ok: boolean; value?: { notes: { text: string }[] } } } }
|
|
468
|
+
}
|
|
469
|
+
const added = await call('add', { text: 'kept on the host' })
|
|
470
|
+
expect(added.status).toBe(200)
|
|
471
|
+
expect(added.body).toMatchObject({ type: 'server-response', rpcId: 'r-add', result: { ok: true } })
|
|
472
|
+
expect((await call('list', {})).body.result.value?.notes.map(note => note.text)).toEqual(['kept on the host'])
|
|
473
|
+
expect(readFileSync(dshHomePath('plugin-data', 'acryl-example-state-host', 'notes.json'), 'utf8')).toContain('kept on the host')
|
|
474
|
+
expect((await call('add', { text: '' })).body.result).toMatchObject({ ok: false, error: { message: 'text is required' } })
|
|
475
|
+
} finally {
|
|
476
|
+
await host.dispose()
|
|
477
|
+
}
|
|
478
|
+
}, 180_000)
|
|
479
|
+
|
|
480
|
+
it('a plugin that requires @acryldev/blends/cordis/state in an app without it gets the row live, shared by a second plugin and removed with the last (spec 049 T001)', async () => {
|
|
481
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-module-row-'))
|
|
482
|
+
temporaryHomes.push(home)
|
|
483
|
+
process.env.DSH_HOME = home
|
|
484
|
+
// An app whose Blueprint has no framework kit: nothing mounts `@acryldev/blends/cordis/state` at start.
|
|
485
|
+
const blueprint = join(home, 'no-kit.yaml')
|
|
486
|
+
writeFileSync(blueprint, 'id: test.no-kit\nextends: acryl.blank\nrows: [plugin-context, system-prompt, ui-library, app-save, plugin-hub]\n')
|
|
487
|
+
const previousBlueprint = process.env.ACRYL_BLUEPRINT
|
|
488
|
+
process.env.ACRYL_BLUEPRINT = blueprint
|
|
489
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-module-row-ws-'))
|
|
490
|
+
temporaryHomes.push(workspace)
|
|
491
|
+
// Each plugin counts in a cell of its own and reads the other's: the state is the one shared service, not a copy per plugin.
|
|
492
|
+
const plugin = (id: string, other: string) => {
|
|
493
|
+
const dir = join(workspace, '.acryl-plugins', id)
|
|
494
|
+
mkdirSync(dir, { recursive: true })
|
|
495
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({
|
|
496
|
+
name: `acryl-probe-${id}`, version: '0.1.0', type: 'module', main: './index.js',
|
|
497
|
+
exports: { '.': './index.js', './package.json': './package.json' },
|
|
498
|
+
peerDependencies: { acrylblends: '*' },
|
|
499
|
+
dsh: { bundle: { patch: './cordis.patch.yml' }, requiresAcrylPackages: ['@acryldev/blends/cordis/state'] },
|
|
500
|
+
}))
|
|
501
|
+
writeFileSync(join(dir, 'cordis.patch.yml'), `- insert:\n - id: acryl-probe-${id}\n name: acryl-probe-${id}\n`)
|
|
502
|
+
writeFileSync(join(dir, 'index.js'), [
|
|
503
|
+
`export const name = 'acryl-probe-${id}'`,
|
|
504
|
+
"export const inject = ['state', 'commands']",
|
|
505
|
+
'export function apply(ctx) {',
|
|
506
|
+
` const count = ctx.state.cell('${id}-count', 0)`,
|
|
507
|
+
` ctx.effect(() => ctx.commands.register({ name: 'probe-${id}', description: 'probe', async handler() { count.update(n => n + 1); return { kind: 'success', text: count.get() + ':' + (ctx.state.find('${other}-count')?.get() ?? '-') } } }), 'probe-${id}')`,
|
|
508
|
+
'}',
|
|
509
|
+
].join('\n'))
|
|
510
|
+
return dir
|
|
511
|
+
}
|
|
512
|
+
const first = plugin('first', 'second')
|
|
513
|
+
const second = plugin('second', 'first')
|
|
514
|
+
const host = await createAcrylEngineHost({
|
|
515
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
516
|
+
initialEngine: 'dsh',
|
|
517
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
518
|
+
})
|
|
519
|
+
const bridge = createAcrylSessionBridge(host.ctx, { profile: 'web', generationId: 'module-row', attachment: 'owner', cwd: workspace })
|
|
520
|
+
try {
|
|
521
|
+
const loader = (host.ctx as unknown as { loader: { entries(): Iterable<{ id: string, options: { name: string } }> } }).loader
|
|
522
|
+
const stateRows = () => [...loader.entries()].filter(entry => entry.options.name === '@acryldev/blends/cordis/state').map(entry => entry.id)
|
|
523
|
+
expect(stateRows()).toEqual([])
|
|
524
|
+
const sessionId = await bridge.open()
|
|
525
|
+
const agent = (host.ctx as unknown as { agents: { get(id: unknown): unknown } }).agents.get(SessionId(sessionId))
|
|
526
|
+
const commands = host.ctx.get('commands' as never) as unknown as {
|
|
527
|
+
execute(agent: unknown, line: string, attachments: unknown[], signal: AbortSignal): Promise<{ result: { kind: string; text?: string } } | undefined>
|
|
528
|
+
}
|
|
529
|
+
const run = async (line: string) => (await commands.execute(agent, line, [], new AbortController().signal))?.result.text
|
|
530
|
+
const services = {
|
|
531
|
+
pnpm: host.ctx.get('desktopPnpm' as never),
|
|
532
|
+
live: host.ctx.get('livePluginActivation' as never),
|
|
533
|
+
profileDir: (host.ctx.get('desktopProfiles' as never) as { current: { dir: string } }).current.dir,
|
|
534
|
+
acrylFrameworkPackages: host.ctx.get('acrylFrameworkPackages' as never),
|
|
535
|
+
cwd: workspace,
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
expect(await installLocalPlugin({ path: first }, services)).toMatchObject({ ok: true, status: 'active', action: 'installed' })
|
|
539
|
+
expect(stateRows()).toEqual(['include:@acryldev/blends/cordis/state'])
|
|
540
|
+
expect([await run('/probe-first'), await run('/probe-first')]).toEqual(['1:-', '2:-'])
|
|
541
|
+
|
|
542
|
+
expect(await installLocalPlugin({ path: second }, services)).toMatchObject({ ok: true, status: 'active', action: 'installed' })
|
|
543
|
+
expect(stateRows()).toEqual(['include:@acryldev/blends/cordis/state'])
|
|
544
|
+
expect(await run('/probe-second')).toBe('1:2')
|
|
545
|
+
|
|
546
|
+
expect(await removeLocalPlugin({ package: 'acryl-probe-first' }, services)).toMatchObject({ ok: true })
|
|
547
|
+
expect(stateRows()).toEqual(['include:@acryldev/blends/cordis/state'])
|
|
548
|
+
expect(await run('/probe-second')).toBe('2:-')
|
|
549
|
+
|
|
550
|
+
expect(await removeLocalPlugin({ package: 'acryl-probe-second' }, services)).toMatchObject({ ok: true })
|
|
551
|
+
expect(stateRows()).toEqual([])
|
|
552
|
+
} finally {
|
|
553
|
+
if (previousBlueprint === undefined) delete process.env.ACRYL_BLUEPRINT
|
|
554
|
+
else process.env.ACRYL_BLUEPRINT = previousBlueprint
|
|
555
|
+
await bridge.dispose()
|
|
556
|
+
await host.dispose()
|
|
557
|
+
}
|
|
558
|
+
}, 180_000)
|
|
559
|
+
|
|
560
|
+
it('the module row a plugin got live is composed again at the next start of the same app (spec 049 T001)', async () => {
|
|
561
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-module-restart-'))
|
|
562
|
+
temporaryHomes.push(home)
|
|
563
|
+
process.env.DSH_HOME = home
|
|
564
|
+
const blueprint = join(home, 'no-kit.yaml')
|
|
565
|
+
writeFileSync(blueprint, 'id: test.no-kit\nextends: acryl.blank\nrows: [plugin-context, system-prompt, ui-library, app-save, plugin-hub]\n')
|
|
566
|
+
const previousBlueprint = process.env.ACRYL_BLUEPRINT
|
|
567
|
+
process.env.ACRYL_BLUEPRINT = blueprint
|
|
568
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-module-restart-ws-'))
|
|
569
|
+
temporaryHomes.push(workspace)
|
|
570
|
+
const dir = join(workspace, '.acryl-plugins', 'kept')
|
|
571
|
+
mkdirSync(dir, { recursive: true })
|
|
572
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({
|
|
573
|
+
name: 'acryl-probe-kept', version: '0.1.0', type: 'module', main: './index.js',
|
|
574
|
+
exports: { '.': './index.js', './package.json': './package.json' },
|
|
575
|
+
peerDependencies: { acrylblends: '*' },
|
|
576
|
+
dsh: { bundle: { patch: './cordis.patch.yml' }, requiresAcrylPackages: ['@acryldev/blends/cordis/state'] },
|
|
577
|
+
}))
|
|
578
|
+
writeFileSync(join(dir, 'cordis.patch.yml'), '- insert:\n - id: acryl-probe-kept\n name: acryl-probe-kept\n')
|
|
579
|
+
writeFileSync(join(dir, 'index.js'), "export const name = 'acryl-probe-kept'\nexport const inject = ['state']\nexport function apply(ctx) { ctx.state.cell('kept', 'yes') }\n")
|
|
580
|
+
const boot = () => createAcrylEngineHost({
|
|
581
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
582
|
+
initialEngine: 'dsh',
|
|
583
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
584
|
+
})
|
|
585
|
+
type Live = { loader: { entries(): Iterable<{ options: { name: string }, fiber?: { state: number } }> }, state?: { find(key: string): { get(): unknown } | undefined } }
|
|
586
|
+
const stateRowStates = (ctx: unknown) => [...(ctx as Live).loader.entries()].filter(entry => entry.options.name === '@acryldev/blends/cordis/state').map(entry => entry.fiber?.state)
|
|
587
|
+
try {
|
|
588
|
+
const first = await boot()
|
|
589
|
+
try {
|
|
590
|
+
const services = {
|
|
591
|
+
pnpm: first.ctx.get('desktopPnpm' as never),
|
|
592
|
+
live: first.ctx.get('livePluginActivation' as never),
|
|
593
|
+
profileDir: (first.ctx.get('desktopProfiles' as never) as { current: { dir: string } }).current.dir,
|
|
594
|
+
acrylFrameworkPackages: first.ctx.get('acrylFrameworkPackages' as never),
|
|
595
|
+
cwd: workspace,
|
|
596
|
+
}
|
|
597
|
+
expect(await installLocalPlugin({ path: dir }, services)).toMatchObject({ ok: true, status: 'active' })
|
|
598
|
+
} finally { await first.dispose() }
|
|
599
|
+
const second = await boot()
|
|
600
|
+
try {
|
|
601
|
+
// ACTIVE (2): composed at start from the installed plugin's manifest, not left to a refusal or a missing service.
|
|
602
|
+
expect(stateRowStates(second.ctx)).toEqual([2])
|
|
603
|
+
expect((second.ctx as unknown as Live).state?.find('kept')?.get()).toBe('yes')
|
|
604
|
+
} finally { await second.dispose() }
|
|
605
|
+
} finally {
|
|
606
|
+
if (previousBlueprint === undefined) delete process.env.ACRYL_BLUEPRINT
|
|
607
|
+
else process.env.ACRYL_BLUEPRINT = previousBlueprint
|
|
608
|
+
}
|
|
609
|
+
}, 240_000)
|
|
610
|
+
|
|
611
|
+
it('a staged plugin whose apply throws surfaces its own error and is rolled back', async () => {
|
|
612
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-extension-throw-'))
|
|
613
|
+
temporaryHomes.push(home)
|
|
614
|
+
process.env.DSH_HOME = home
|
|
615
|
+
const workspace = await mkdtemp(join(tmpdir(), 'acryl-extension-throw-ws-'))
|
|
616
|
+
temporaryHomes.push(workspace)
|
|
617
|
+
const dir = join(workspace, '.acryl-plugins', 'thrower')
|
|
618
|
+
mkdirSync(dir, { recursive: true })
|
|
619
|
+
writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'acryl-thrower', version: '0.1.0', type: 'module', main: './index.js', exports: { '.': './index.js', './package.json': './package.json' }, dsh: { bundle: { patch: './cordis.patch.yml' } } }))
|
|
620
|
+
writeFileSync(join(dir, 'cordis.patch.yml'), '- insert:\n - id: thrower\n name: acryl-thrower\n')
|
|
621
|
+
writeFileSync(join(dir, 'index.js'), "export const name = 'acryl-thrower'\nexport function apply() { throw new Error('boom-42 from the plugin') }\n")
|
|
622
|
+
const host = await createAcrylEngineHost({
|
|
623
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
624
|
+
initialEngine: 'dsh',
|
|
625
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
626
|
+
})
|
|
627
|
+
try {
|
|
628
|
+
const services = {
|
|
629
|
+
pnpm: host.ctx.get('desktopPnpm' as never),
|
|
630
|
+
live: host.ctx.get('livePluginActivation' as never),
|
|
631
|
+
profileDir: (host.ctx.get('desktopProfiles' as never) as { current: { dir: string } }).current.dir,
|
|
632
|
+
}
|
|
633
|
+
const result = await installLocalPlugin({ path: dir }, services)
|
|
634
|
+
expect(result.ok).toBe(false)
|
|
635
|
+
expect(result.stage).toBe('activate')
|
|
636
|
+
expect(JSON.stringify(result.errors)).toContain('boom-42 from the plugin')
|
|
637
|
+
expect(result.rolledBack).toBe(true)
|
|
638
|
+
} finally { await host.dispose() }
|
|
639
|
+
}, 120_000)
|
|
640
|
+
})
|