@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.
- package/LICENSE +49 -0
- 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
- package/README.md +0 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T043 (spec 001): the DeepSeek Harness chat is optional. Booted from the `acryl.agents` Blueprint the Web engine keeps its frame (web server, session
|
|
3
|
+
* store, client, workspace, terminals, Agent Control) with the chat's agent and model rows off, nothing FAILED, and the same live host brings the chat
|
|
4
|
+
* back by editing three rows. This is the real Loader on the real DSH profile, not a stub.
|
|
5
|
+
*/
|
|
6
|
+
import { mkdtemp, rm } from 'node:fs/promises'
|
|
7
|
+
import { tmpdir } from 'node:os'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
10
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
11
|
+
import { DSH_CHAT_ROW_IDS } from '../src/blueprint/index.ts'
|
|
12
|
+
import { createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
13
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
14
|
+
import { codingCapabilities } from '@acryldev/coding-capabilities'
|
|
15
|
+
|
|
16
|
+
const STATES = ['PENDING', 'LOADING', 'ACTIVE', 'FAILED', 'UNLOADING', 'DISPOSED']
|
|
17
|
+
const homes: string[] = []
|
|
18
|
+
const saved = { home: process.env.DSH_HOME, blueprint: process.env.ACRYL_BLUEPRINT }
|
|
19
|
+
|
|
20
|
+
afterEach(async () => {
|
|
21
|
+
for (const [key, variable] of [['home', 'DSH_HOME'], ['blueprint', 'ACRYL_BLUEPRINT']] as const) {
|
|
22
|
+
if (saved[key] === undefined) delete process.env[variable]
|
|
23
|
+
else process.env[variable] = saved[key]
|
|
24
|
+
}
|
|
25
|
+
await Promise.all(homes.splice(0).map(home => rm(home, { force: true, recursive: true })))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
type Host = Awaited<ReturnType<typeof createAcrylEngineHost>>
|
|
29
|
+
|
|
30
|
+
async function boot(blueprint: string): Promise<Host> {
|
|
31
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-optional-'))
|
|
32
|
+
homes.push(home)
|
|
33
|
+
process.env.DSH_HOME = home
|
|
34
|
+
process.env.ACRYL_BLUEPRINT = blueprint
|
|
35
|
+
return createAcrylEngineHost({
|
|
36
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
37
|
+
initialEngine: 'dsh',
|
|
38
|
+
prepare: ctx => { provideCmdline(ctx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function states(host: Host): Map<string, string> {
|
|
43
|
+
return new Map([...host.ctx.loader.entries()].map(entry => [entry.options.id ?? '', STATES[entry.fiber?.state as number] ?? 'NONE']))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function settle(host: Host): Promise<void> {
|
|
47
|
+
await host.ctx.loader.await()
|
|
48
|
+
await new Promise(resolve => setTimeout(resolve, 500))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe('the DSH chat is optional (T043)', () => {
|
|
52
|
+
it('keeps the frame alive with the chat off, parks only chat consumers, and brings the chat back live', async () => {
|
|
53
|
+
const host = await boot('acryl.agents')
|
|
54
|
+
try {
|
|
55
|
+
await settle(host)
|
|
56
|
+
const off = states(host)
|
|
57
|
+
for (const id of DSH_CHAT_ROW_IDS) expect(off.get(id), id).not.toBe('ACTIVE')
|
|
58
|
+
// The frame: the server, the session store, the client, the terminals and ACRYL's own rows.
|
|
59
|
+
for (const id of ['web', 'session', 'session-persistence-jsonl', 'terminal-controller', 'workspace-controller', 'acryl-workspace', 'acryl-agent-control', 'tools']) {
|
|
60
|
+
expect(off.get(id), id).toBe('ACTIVE')
|
|
61
|
+
}
|
|
62
|
+
// Rows that need the chat wait (PENDING) instead of failing; Cordis reactivates them when it returns.
|
|
63
|
+
expect([...off].filter(([, state]) => state === 'FAILED')).toEqual([])
|
|
64
|
+
expect(off.get('session-controller')).toBe('PENDING')
|
|
65
|
+
const parked = [...off].filter(([, state]) => state === 'PENDING').map(([id]) => id)
|
|
66
|
+
|
|
67
|
+
// Chat back on: three row edits on the same live host, no restart.
|
|
68
|
+
for (const entry of host.ctx.loader.entries()) {
|
|
69
|
+
if (DSH_CHAT_ROW_IDS.includes(entry.options.id ?? '')) entry.update({ disabled: false })
|
|
70
|
+
}
|
|
71
|
+
await settle(host)
|
|
72
|
+
const on = states(host)
|
|
73
|
+
for (const id of DSH_CHAT_ROW_IDS) expect(on.get(id), id).toBe('ACTIVE')
|
|
74
|
+
expect(on.get('session-controller')).toBe('ACTIVE')
|
|
75
|
+
expect([...on].filter(([, state]) => state === 'FAILED')).toEqual([])
|
|
76
|
+
expect(parked.length).toBeGreaterThan(0)
|
|
77
|
+
} finally {
|
|
78
|
+
await host.dispose()
|
|
79
|
+
}
|
|
80
|
+
}, 120_000)
|
|
81
|
+
})
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Real-engine proof for the Extension Context Pack examples (spec 037): every host example is mounted on the
|
|
3
|
+
* real web engine's live Context and reaches the state its header declares. A client-only half is not mounted
|
|
4
|
+
* here (it needs a browser); the sidebar-tab and header-action bundles were exercised in a real browser.
|
|
5
|
+
*/
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { mkdtemp, rm } from 'node:fs/promises'
|
|
8
|
+
import { tmpdir } from 'node:os'
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
10
|
+
import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
11
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
12
|
+
import { createWebEngineDefinition } from '../src/engine-dsh.ts'
|
|
13
|
+
import { createAcrylEngineHost } from '../src/engine-host.ts'
|
|
14
|
+
import { captureSystemPrompt } from '../src/system-prompt-capture.ts'
|
|
15
|
+
import { codingCapabilities } from '@acryldev/coding-capabilities'
|
|
16
|
+
|
|
17
|
+
const examples = new URL('../../../plugins/plugin-context/example-plugins/packages/', import.meta.url)
|
|
18
|
+
const temporaryHomes: string[] = []
|
|
19
|
+
const initialDshHome = process.env.DSH_HOME
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
// Assigning undefined would store the string "undefined" and the next boot would create a ./undefined profile directory.
|
|
23
|
+
if (initialDshHome === undefined) delete process.env.DSH_HOME
|
|
24
|
+
else process.env.DSH_HOME = initialDshHome
|
|
25
|
+
await Promise.all(temporaryHomes.splice(0).map(home => rm(home, { force: true, recursive: true })))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
async function bootHost() {
|
|
29
|
+
const home = await mkdtemp(join(tmpdir(), 'acryl-examples-'))
|
|
30
|
+
temporaryHomes.push(home)
|
|
31
|
+
process.env.DSH_HOME = home
|
|
32
|
+
return createAcrylEngineHost({
|
|
33
|
+
engines: [createWebEngineDefinition(new URL('../package.json', import.meta.url).href, codingCapabilities)],
|
|
34
|
+
initialEngine: 'dsh',
|
|
35
|
+
prepare: hostCtx => { provideCmdline(hostCtx, { args: ['--no-open', '--port', '0'], exit: () => {} }) },
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const load = async (dir: string) => import(pathToFileURL(join(fileURLToPath(new URL(dir, examples)), 'index.js')).href) as Promise<Record<string, unknown>>
|
|
40
|
+
// ASCII-only fixtures: strip SGR colour codes and count characters.
|
|
41
|
+
const visibleWidth = (line: string): number => line.replace(/\u001b\[[0-9;]*m/gu, '').length
|
|
42
|
+
const STATES = ['PENDING', 'LOADING', 'ACTIVE', 'FAILED', 'UNLOADING', 'DISPOSED']
|
|
43
|
+
const stateOf = (fiber: { state: number | string }): string => (typeof fiber.state === 'number' ? STATES[fiber.state] : fiber.state) ?? String(fiber.state)
|
|
44
|
+
const settle = () => new Promise(resolve => setTimeout(resolve, 50))
|
|
45
|
+
|
|
46
|
+
describe('extension pack examples on the real web engine', () => {
|
|
47
|
+
it('mounts each single-package host example to its declared state', async () => {
|
|
48
|
+
const host = await bootHost()
|
|
49
|
+
try {
|
|
50
|
+
const cases: Array<[string, string, unknown?]> = [
|
|
51
|
+
['lifecycle-function-basic', 'ACTIVE'],
|
|
52
|
+
['lifecycle-function-hot-shim', 'ACTIVE'],
|
|
53
|
+
['event-hook-basic', 'ACTIVE'],
|
|
54
|
+
['tool-basic', 'ACTIVE'],
|
|
55
|
+
['prompt-contribution-basic', 'ACTIVE'],
|
|
56
|
+
['skill-provider-basic', 'ACTIVE'],
|
|
57
|
+
['host-route-basic', 'ACTIVE'],
|
|
58
|
+
['llm-adapter-echo', 'ACTIVE'],
|
|
59
|
+
['generated-capability-template', 'ACTIVE'],
|
|
60
|
+
['chat-command-basic', 'ACTIVE'],
|
|
61
|
+
['tui-command-basic', 'ACTIVE'], // optional ctx.get('tuiCommands'): a no-op off the terminal
|
|
62
|
+
['desktop-main-profile-info', 'ACTIVE'],
|
|
63
|
+
]
|
|
64
|
+
for (const [dir, expected] of cases) {
|
|
65
|
+
const mod = await load(dir)
|
|
66
|
+
const fiber = host.ctx.plugin(mod as never) as { state: number }
|
|
67
|
+
// Wait for the expected state rather than a fixed moment: loading a plugin's module is a real import, which is slower on some file systems (Windows).
|
|
68
|
+
for (const deadline = Date.now() + 10_000; Date.now() < deadline;) {
|
|
69
|
+
await settle()
|
|
70
|
+
if (stateOf(fiber) === expected) break
|
|
71
|
+
}
|
|
72
|
+
expect(`${dir}:${stateOf(fiber)}`).toBe(`${dir}:${expected}`)
|
|
73
|
+
}
|
|
74
|
+
} finally { await host.dispose() }
|
|
75
|
+
}, 60_000)
|
|
76
|
+
|
|
77
|
+
it('provider then consumer: PENDING until the service exists', async () => {
|
|
78
|
+
const host = await bootHost()
|
|
79
|
+
try {
|
|
80
|
+
const consumer = host.ctx.plugin(await load('service-consumer-greeter') as never) as { state: number }
|
|
81
|
+
await settle()
|
|
82
|
+
expect(stateOf(consumer)).toBe('PENDING')
|
|
83
|
+
const provider = host.ctx.plugin(await load('service-provider-greeter') as never) as { state: number }
|
|
84
|
+
await settle()
|
|
85
|
+
expect(stateOf(provider)).toBe('ACTIVE')
|
|
86
|
+
expect(stateOf(consumer)).toBe('ACTIVE')
|
|
87
|
+
} finally { await host.dispose() }
|
|
88
|
+
}, 60_000)
|
|
89
|
+
|
|
90
|
+
it('three-role capability: consumer follows a provider swap', async () => {
|
|
91
|
+
const host = await bootHost()
|
|
92
|
+
try {
|
|
93
|
+
const consumer = host.ctx.plugin(await load('capability-swap-consumer') as never) as { state: number }
|
|
94
|
+
await settle()
|
|
95
|
+
expect(stateOf(consumer)).toBe('PENDING')
|
|
96
|
+
const loud = host.ctx.plugin(await load('capability-swap-provider-loud') as never) as { state: number; dispose(): void }
|
|
97
|
+
await settle()
|
|
98
|
+
expect([stateOf(loud), stateOf(consumer)]).toEqual(['ACTIVE', 'ACTIVE'])
|
|
99
|
+
expect((host.ctx as unknown as { speller: { shout(t: string): string } }).speller.shout('hi')).toBe('HI!')
|
|
100
|
+
loud.dispose()
|
|
101
|
+
await settle()
|
|
102
|
+
const quiet = host.ctx.plugin(await load('capability-swap-provider-quiet') as never) as { state: number }
|
|
103
|
+
await settle()
|
|
104
|
+
expect([stateOf(quiet), stateOf(consumer)]).toEqual(['ACTIVE', 'ACTIVE'])
|
|
105
|
+
expect((host.ctx as unknown as { speller: { shout(t: string): string } }).speller.shout('HI')).toBe('hi...')
|
|
106
|
+
} finally { await host.dispose() }
|
|
107
|
+
}, 60_000)
|
|
108
|
+
|
|
109
|
+
it('host-route: the route is served on the real socket through the router mount, and leaves with the plugin', async () => {
|
|
110
|
+
const host = await bootHost()
|
|
111
|
+
try {
|
|
112
|
+
const fiber = host.ctx.plugin(await load('host-route-basic') as never) as { state: number, dispose(): Promise<unknown> }
|
|
113
|
+
for (const deadline = Date.now() + 10_000; Date.now() < deadline && stateOf(fiber) !== 'ACTIVE';) await settle()
|
|
114
|
+
expect(stateOf(fiber)).toBe('ACTIVE')
|
|
115
|
+
const { port } = host.ctx.get('webServer' as never) as { port: number }
|
|
116
|
+
const hello = await fetch(`http://127.0.0.1:${String(port)}/api/example/hello`)
|
|
117
|
+
expect([hello.status, await hello.text()]).toEqual([200, 'ok'])
|
|
118
|
+
await fiber.dispose()
|
|
119
|
+
expect((await fetch(`http://127.0.0.1:${String(port)}/api/example/hello`)).status).not.toBe(200)
|
|
120
|
+
} finally { await host.dispose() }
|
|
121
|
+
}, 60_000)
|
|
122
|
+
|
|
123
|
+
it('config-schema: a valid config mounts, an out-of-range one fails before apply', async () => {
|
|
124
|
+
const host = await bootHost()
|
|
125
|
+
try {
|
|
126
|
+
const good = host.ctx.plugin(await load('config-schema-basic') as never, { intervalMs: 500 } as never) as { state: number }
|
|
127
|
+
await settle()
|
|
128
|
+
expect(stateOf(good)).toBe('ACTIVE')
|
|
129
|
+
const bad = host.ctx.plugin(await load('config-schema-basic') as never, { intervalMs: 10 } as never) as { state: number }
|
|
130
|
+
await settle()
|
|
131
|
+
expect(stateOf(bad)).toBe('FAILED')
|
|
132
|
+
} finally { await host.dispose() }
|
|
133
|
+
}, 60_000)
|
|
134
|
+
|
|
135
|
+
it('settings-section: mounts with a config and registers its namespace when a settings service exists', async () => {
|
|
136
|
+
const host = await bootHost()
|
|
137
|
+
try {
|
|
138
|
+
const fiber = host.ctx.plugin(await load('settings-section-basic') as never, { greeting: 'Hi', loud: true } as never) as { state: number }
|
|
139
|
+
await settle()
|
|
140
|
+
expect(stateOf(fiber)).toBe('ACTIVE')
|
|
141
|
+
} finally { await host.dispose() }
|
|
142
|
+
}, 60_000)
|
|
143
|
+
|
|
144
|
+
it('web-page-branding: the served index gets the title, favicon and style rows', async () => {
|
|
145
|
+
const host = await bootHost()
|
|
146
|
+
try {
|
|
147
|
+
const fiber = host.ctx.plugin(await load('web-page-branding') as never) as { state: number }
|
|
148
|
+
await settle()
|
|
149
|
+
expect(stateOf(fiber)).toBe('ACTIVE')
|
|
150
|
+
const server = host.ctx.get('webServer' as never) as { renderIndex(html: string): string }
|
|
151
|
+
const html = server.renderIndex('<!doctype html><html><head><title>DeepSeek Harness</title></head><body></body></html>')
|
|
152
|
+
expect(html).toContain('<title>My Studio</title>')
|
|
153
|
+
expect(html).toContain('rel="icon"')
|
|
154
|
+
expect(html).toContain('background:#1a1410')
|
|
155
|
+
} finally { await host.dispose() }
|
|
156
|
+
}, 60_000)
|
|
157
|
+
|
|
158
|
+
it('tui-overlay-themed: never renders a line wider than the terminal, and closes on escape', async () => {
|
|
159
|
+
const mod = await load('tui-overlay-themed') as { buildOverlay(close: () => void): { render(width: number): string[]; handleInput(data: string): void } }
|
|
160
|
+
let closed = 0
|
|
161
|
+
const overlay = mod.buildOverlay(() => { closed += 1 })
|
|
162
|
+
for (const width of [12, 24, 40, 80, 200]) {
|
|
163
|
+
for (const line of overlay.render(width)) expect(visibleWidth(line)).toBeLessThanOrEqual(width)
|
|
164
|
+
}
|
|
165
|
+
overlay.handleInput('\x1b')
|
|
166
|
+
expect(closed).toBe(1)
|
|
167
|
+
const host = await bootHost()
|
|
168
|
+
try {
|
|
169
|
+
const fiber = host.ctx.plugin(mod as never) as { state: number }
|
|
170
|
+
await settle()
|
|
171
|
+
expect(stateOf(fiber)).toBe('ACTIVE') // a no-op where there is no tuiCommands service
|
|
172
|
+
} finally { await host.dispose() }
|
|
173
|
+
}, 60_000)
|
|
174
|
+
|
|
175
|
+
it('ui-library.tui-gallery (spec 038-ui-component-library): renders within every width, walks its tabs and settings with the keyboard, resets through a dialog', async () => {
|
|
176
|
+
const mod = await load('tui-ui-library') as { buildGallery(theme: unknown, close: () => void): { render(width: number): string[]; handleInput(data: string): boolean } }
|
|
177
|
+
const theme = { mode: 'dark', color: () => (text: string) => text } // uncolored so visible width is the string length
|
|
178
|
+
let closed = 0
|
|
179
|
+
const gallery = mod.buildGallery(theme, () => { closed += 1 })
|
|
180
|
+
for (const width of [12, 24, 40, 80, 200]) for (const line of gallery.render(width)) expect(visibleWidth(line)).toBeLessThanOrEqual(width)
|
|
181
|
+
const text = () => gallery.render(80).join('\n')
|
|
182
|
+
expect(text()).toContain('Card with a form')
|
|
183
|
+
gallery.handleInput('\t') // Tab: Settings form
|
|
184
|
+
expect(text()).toContain('Permission'); expect(text()).toContain('Workspace Write')
|
|
185
|
+
gallery.handleInput('\x1b[C') // right on the focused SelectField: next option
|
|
186
|
+
expect(text()).toContain('Full access')
|
|
187
|
+
gallery.handleInput('\x1b[B') // down: Appearance row
|
|
188
|
+
gallery.handleInput('\x1b[C') // right: Segmented moves off System
|
|
189
|
+
expect(text()).toMatch(/\[ Light \]/u)
|
|
190
|
+
gallery.handleInput('r'); expect(text()).toContain('Reset settings?')
|
|
191
|
+
gallery.handleInput('y'); expect(text()).not.toContain('Reset settings?'); expect(text()).toContain('[ System ]')
|
|
192
|
+
gallery.handleInput('\t'); expect(text()).toContain('primary') // Colors tab
|
|
193
|
+
gallery.handleInput('\x1b'); expect(closed).toBe(1)
|
|
194
|
+
const host = await bootHost()
|
|
195
|
+
try {
|
|
196
|
+
const fiber = host.ctx.plugin(mod as never) as { state: number }
|
|
197
|
+
await settle()
|
|
198
|
+
expect(stateOf(fiber)).toBe('ACTIVE') // a no-op where there is no tuiCommands service
|
|
199
|
+
} finally { await host.dispose() }
|
|
200
|
+
}, 60_000)
|
|
201
|
+
|
|
202
|
+
it('prompt-assemble-hook: the assembled prompt gains the example section and keeps every other section', async () => {
|
|
203
|
+
const host = await bootHost()
|
|
204
|
+
try {
|
|
205
|
+
const systemPrompt = host.ctx.get('systemPrompt' as never) as unknown as { assemble(): Promise<{ sections: Array<{ name: string }> }> }
|
|
206
|
+
const before = (await systemPrompt.assemble()).sections.map(s => s.name)
|
|
207
|
+
const fiber = host.ctx.plugin(await load('prompt-assemble-hook') as never) as { state: number }
|
|
208
|
+
await settle()
|
|
209
|
+
expect(stateOf(fiber)).toBe('ACTIVE')
|
|
210
|
+
const after = (await systemPrompt.assemble()).sections.map(s => s.name)
|
|
211
|
+
expect(after).toContain('example:note')
|
|
212
|
+
for (const name of before) expect(after).toContain(name)
|
|
213
|
+
} finally { await host.dispose() }
|
|
214
|
+
}, 60_000)
|
|
215
|
+
|
|
216
|
+
it('lifecycle-hooks-observer: the pre-step, request and stream waterfalls fire during a real turn and pass through', async () => {
|
|
217
|
+
process.env.DEEPSEEK_API_KEY = 'dummy-key-for-lifecycle-hooks'
|
|
218
|
+
const host = await bootHost()
|
|
219
|
+
try {
|
|
220
|
+
const fiber = host.ctx.plugin(await load('lifecycle-hooks-observer') as never) as { state: number }
|
|
221
|
+
await settle()
|
|
222
|
+
expect(stateOf(fiber)).toBe('ACTIVE')
|
|
223
|
+
const captured = await captureSystemPrompt(host.ctx, { profile: 'web', selectStandardPreset: true })
|
|
224
|
+
// The turn was fully assembled (system prompt present) although the hooks sat in the middle of the chain: nothing was cut out.
|
|
225
|
+
expect(captured.system.length).toBeGreaterThan(100)
|
|
226
|
+
const probe = host.ctx.get('acrylLifecycleProbe' as never) as unknown as { counts(): { preStep: number; request: number; stream: number } }
|
|
227
|
+
const counts = probe.counts()
|
|
228
|
+
expect(counts.preStep).toBeGreaterThan(0)
|
|
229
|
+
expect(counts.request).toBeGreaterThan(0)
|
|
230
|
+
expect(counts.stream).toBeGreaterThan(0)
|
|
231
|
+
} finally { await host.dispose() }
|
|
232
|
+
}, 90_000)
|
|
233
|
+
|
|
234
|
+
it('tool-policy-hook: a blocked tool is denied with the reason, another tool still runs', async () => {
|
|
235
|
+
const host = await bootHost()
|
|
236
|
+
try {
|
|
237
|
+
const tools = host.ctx.get('tools' as never) as unknown as {
|
|
238
|
+
register(definition: unknown): () => void
|
|
239
|
+
execute(input: { callId: string; name: string; arguments: unknown; signal: AbortSignal }): Promise<{ isError?: boolean; kind?: string; content?: Array<{ type: string; text?: string }> } & Record<string, unknown>>
|
|
240
|
+
}
|
|
241
|
+
const make = (toolName: string) => ({
|
|
242
|
+
name: toolName,
|
|
243
|
+
description: `example tool ${toolName}`,
|
|
244
|
+
parameters: {},
|
|
245
|
+
output: { schema: { type: 'string' }, render: (_args: unknown, value: string) => [{ type: 'text', text: value }] },
|
|
246
|
+
async execute() { return `${toolName} ran` },
|
|
247
|
+
})
|
|
248
|
+
const { defineTool } = await import('@deepseek-ai/dsh-tools')
|
|
249
|
+
tools.register(defineTool(make('example_allowed') as never))
|
|
250
|
+
tools.register(defineTool(make('example_forbidden') as never))
|
|
251
|
+
const fiber = host.ctx.plugin(await load('tool-policy-hook') as never, {} as never) as { state: number }
|
|
252
|
+
await settle()
|
|
253
|
+
expect(stateOf(fiber)).toBe('ACTIVE')
|
|
254
|
+
const allowed = await tools.execute({ callId: 'c1', name: 'example_allowed', arguments: {}, signal: new AbortController().signal })
|
|
255
|
+
const denied = await tools.execute({ callId: 'c2', name: 'example_forbidden', arguments: {}, signal: new AbortController().signal })
|
|
256
|
+
expect(JSON.stringify(allowed)).toContain('example_allowed ran')
|
|
257
|
+
expect(JSON.stringify(denied)).toContain('blocked by the ACRYL example tool policy')
|
|
258
|
+
expect(JSON.stringify(denied)).not.toContain('example_forbidden ran')
|
|
259
|
+
} finally { await host.dispose() }
|
|
260
|
+
}, 90_000)
|
|
261
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ported from DeepSeek Harness, packages/boot/app-boot/tests/hooks-thread-stack.ts at dsh-v0.2.0-rc.2 (639ed01539, MIT, Copyright (c) 2026 DeepSeek;
|
|
3
|
+
* see THIRD_PARTY_NOTICES.md). Unchanged.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Node resolver errors with the stack property that Node's module-hooks thread returns. */
|
|
7
|
+
|
|
8
|
+
import { registerHooks, type ModuleHooks } from 'node:module'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Register a synchronous resolve hook that rethrows Node's resolver errors with the `stack` property an
|
|
12
|
+
* asynchronous `module.register()` hook chain returns: Node serializes the error on its hooks thread, and the
|
|
13
|
+
* main thread receives the stack accessor as a read-only configurable data property.
|
|
14
|
+
* @returns the hook registration, which the test deregisters.
|
|
15
|
+
*/
|
|
16
|
+
export function registerHooksThreadStacks(): ModuleHooks {
|
|
17
|
+
return registerHooks({
|
|
18
|
+
resolve(specifier, context, nextResolve) {
|
|
19
|
+
try {
|
|
20
|
+
return nextResolve(specifier, context)
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error instanceof Error) Object.defineProperty(error, 'stack', { value: error.stack, writable: false })
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
import { composeEntries } from '@deepseek-ai/dsh-app-boot'
|
|
4
|
+
import { instancePatches } from '../src/engine-dsh.ts'
|
|
5
|
+
import { defaultInstance, pinnedInstance } from '../src/instance/index.ts'
|
|
6
|
+
|
|
7
|
+
describe('the patches an app instance contributes', () => {
|
|
8
|
+
it('adds nothing for the default instance, whose first workspace stays in the OS Documents folder', () => {
|
|
9
|
+
expect(instancePatches(defaultInstance('/home/someone'))).toEqual([])
|
|
10
|
+
expect(instancePatches(undefined)).toEqual([])
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('points the chat workspace of any other instance at its own documents folder', () => {
|
|
14
|
+
const instance = pinnedInstance('/tmp/acryl-run')
|
|
15
|
+
expect(instancePatches(instance)).toEqual([{ id: 'workspace-controller', config: { documentsDirectory: join('/tmp/acryl-run', 'documents') } }])
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('merges into the workspace controller row where the surface composes one, and is ignored where it does not', () => {
|
|
19
|
+
const patches = [...instancePatches(pinnedInstance('/tmp/acryl-run'))]
|
|
20
|
+
const withController = composeEntries([[{ insert: [{ id: 'workspace-controller', name: '@deepseek-ai/dsh-api-workspace-controller' }] }], patches])
|
|
21
|
+
expect(withController).toEqual([{ id: 'workspace-controller', name: '@deepseek-ai/dsh-api-workspace-controller', config: { documentsDirectory: join('/tmp/acryl-run', 'documents') } }])
|
|
22
|
+
const without = composeEntries([[{ insert: [{ id: 'other', name: 'other-package' }] }], patches])
|
|
23
|
+
expect(without).toEqual([{ id: 'other', name: 'other-package' }])
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app-instance module (spec 036, "Self-containment"): Bulkheads built from one Abstract Factory per kind of app, chosen once by the selector, handed
|
|
3
|
+
* across processes by one environment contract, and guarded by a Pessimistic Offline Lock and a Registry.
|
|
4
|
+
*/
|
|
5
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { tmpdir } from 'node:os'
|
|
7
|
+
import { join, resolve } from 'node:path'
|
|
8
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
9
|
+
import {
|
|
10
|
+
AppInstanceError,
|
|
11
|
+
DEFAULT_WEB_PORT,
|
|
12
|
+
IsolationRequiredError,
|
|
13
|
+
LockHeldError,
|
|
14
|
+
acquireLock,
|
|
15
|
+
announce,
|
|
16
|
+
appFolder,
|
|
17
|
+
defaultInstance,
|
|
18
|
+
instanceEnvironment,
|
|
19
|
+
listRunning,
|
|
20
|
+
managedApp,
|
|
21
|
+
onlineSecretPath,
|
|
22
|
+
readOnlineSecret,
|
|
23
|
+
releaseLock,
|
|
24
|
+
removeOnlineSecret,
|
|
25
|
+
selectInstance,
|
|
26
|
+
stablePort,
|
|
27
|
+
writeOnlineSecret,
|
|
28
|
+
withdraw,
|
|
29
|
+
type AppInstance,
|
|
30
|
+
} from '../src/instance/index.ts'
|
|
31
|
+
|
|
32
|
+
const dirs: string[] = []
|
|
33
|
+
afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { force: true, recursive: true }) })
|
|
34
|
+
const temp = (): string => { const dir = realpathSync(mkdtempSync(join(tmpdir(), 'acryl-instance-'))); dirs.push(dir); return dir }
|
|
35
|
+
const app = (root: string, name: string): string => { const dir = join(root, name); mkdirSync(dir, { recursive: true }); writeFileSync(join(dir, 'blend.yaml'), 'x'); return dir }
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Every resource of a family that another app must never share. The Web port is not one: an app's port is a first try spread over the app range,
|
|
39
|
+
* and it scans to the next free one, so two apps whose ids hash to the same start still run side by side (checked separately below).
|
|
40
|
+
*/
|
|
41
|
+
const footprint = (instance: AppInstance): string[] => [instance.home, instance.dshHome, instance.userDataName, instance.userDataDir, instance.runLockFile, instance.projectScope ?? '(shared)']
|
|
42
|
+
|
|
43
|
+
describe('the families', () => {
|
|
44
|
+
it('two apps share nothing, even when their folders have the same name', () => {
|
|
45
|
+
const root = temp()
|
|
46
|
+
const a = appFolder(app(join(root, 'a'), 'orbit'), root)
|
|
47
|
+
const b = appFolder(app(join(root, 'b'), 'orbit'), root)
|
|
48
|
+
const music = appFolder(app(root, 'music-editor'), root)
|
|
49
|
+
const all = [a, b, music, defaultInstance(root)]
|
|
50
|
+
for (let i = 0; i < all.length; i += 1) for (let j = i + 1; j < all.length; j += 1) {
|
|
51
|
+
const shared = footprint(all[i]!).filter(value => footprint(all[j]!).includes(value))
|
|
52
|
+
expect(shared, `${all[i]!.id} and ${all[j]!.id}`).toEqual([])
|
|
53
|
+
}
|
|
54
|
+
for (const instance of [a, b, music]) {
|
|
55
|
+
expect(instance.webPort.scan).toBe(true)
|
|
56
|
+
expect(instance.webPort.start).toBe(stablePort(instance.id))
|
|
57
|
+
expect(instance.webPort.start).not.toBe(DEFAULT_WEB_PORT)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('only the default instance uses ~/.acryl and port 3080', () => {
|
|
62
|
+
const osHome = temp()
|
|
63
|
+
expect(selectInstance({ env: {}, osHome })).toMatchObject({ kind: 'default', home: join(osHome, '.acryl'), webPort: { start: 3080, scan: false } })
|
|
64
|
+
expect(selectInstance({ env: {}, osHome, development: true }).home).toBe(join(osHome, '.acryl-dev'))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('a managed app is unique by name; an app folder elsewhere gets a digest of its path', () => {
|
|
68
|
+
const osHome = temp()
|
|
69
|
+
expect(managedApp('orbit', osHome).id).toBe('orbit')
|
|
70
|
+
for (const escape of ['../x', 'a/b', '..']) expect(() => managedApp(escape, osHome), escape).toThrow(AppInstanceError)
|
|
71
|
+
expect(appFolder(app(join(osHome, '.acryl-instances'), 'orbit'), osHome).kind).toBe('managed')
|
|
72
|
+
expect(appFolder(app(osHome, 'orbit'), osHome).id).toMatch(/^orbit-[0-9a-f]{4}$/u)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('the default workspace folder', () => {
|
|
77
|
+
it('only the default instance (the installed app) uses the OS Documents folder; every other instance keeps it inside its own home', () => {
|
|
78
|
+
const root = temp()
|
|
79
|
+
expect(selectInstance({ env: {}, osHome: root }).documentsDirectory).toBeUndefined()
|
|
80
|
+
const pinned = selectInstance({ env: { ACRYL_HOME: join(root, 'x') }, osHome: root })
|
|
81
|
+
expect(pinned.documentsDirectory).toBe(join(root, 'x', 'documents'))
|
|
82
|
+
expect(selectInstance({ env: {}, osHome: root, development: true }).documentsDirectory).toBe(join(root, '.acryl-dev', 'documents'))
|
|
83
|
+
const folder = app(root, 'ledger')
|
|
84
|
+
expect(selectInstance({ env: { ACRYL_HOME: folder }, osHome: root }).documentsDirectory).toBe(join(folder, 'documents'))
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('survives the refinements a child process hands back (port, scope, user-data name)', () => {
|
|
88
|
+
const root = temp()
|
|
89
|
+
const refined = selectInstance({ env: { ACRYL_HOME: join(root, 'x'), ACRYL_WEB_PORT: '4100', ACRYL_INSTANCE: 'scope-a', ACRYL_LOCAL_PRODUCT_NAME: 'Name' }, osHome: root })
|
|
90
|
+
expect(refined.documentsDirectory).toBe(join(root, 'x', 'documents'))
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
describe('selectInstance precedence', () => {
|
|
95
|
+
it('ACRYL_HOME with a definition is an app, without one a pinned home, and it outranks an ambient DSH_HOME', () => {
|
|
96
|
+
const root = temp()
|
|
97
|
+
const folder = app(root, 'ledger')
|
|
98
|
+
expect(selectInstance({ env: { ACRYL_HOME: folder, DSH_HOME: '/ambient' }, osHome: root })).toMatchObject({ kind: 'app', dshHome: join(folder, '.dsh') })
|
|
99
|
+
expect(selectInstance({ env: { ACRYL_HOME: '/tmp/pinned', DSH_HOME: '/ambient' }, osHome: root })).toMatchObject({ kind: 'pinned', home: resolve('/tmp/pinned'), dshHome: join(resolve('/tmp/pinned'), '.dsh') })
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('a legacy DSH_HOME moves the ACRYL home with it instead of leaving state in the shared ~/.acryl', () => {
|
|
103
|
+
expect(selectInstance({ env: { DSH_HOME: '/x/.dsh' }, osHome: '/h' })).toMatchObject({ home: resolve('/x'), dshHome: resolve('/x/.dsh') })
|
|
104
|
+
expect(selectInstance({ env: { DSH_HOME: '/tmp/d' }, osHome: '/h' })).toMatchObject({ home: resolve('/tmp/d'), dshHome: resolve('/tmp/d') })
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('a git worktree checkout gets its own home, port and Electron app; the main checkout does not', () => {
|
|
108
|
+
const root = temp()
|
|
109
|
+
const main = join(root, 'acryl'); mkdirSync(join(main, '.git'), { recursive: true })
|
|
110
|
+
const worktree = join(root, '036-Feature'); mkdirSync(worktree); writeFileSync(join(worktree, '.git'), 'gitdir: x\n')
|
|
111
|
+
expect(selectInstance({ env: {}, osHome: root, checkout: main }).kind).toBe('default')
|
|
112
|
+
expect(selectInstance({ env: {}, osHome: root, checkout: worktree })).toMatchObject({ kind: 'worktree', home: join(root, '.acryl-worktrees', '036-Feature'), webPort: { start: 3081, scan: true }, userDataName: 'ACRYL Development 036-Feature', projectScope: 'worktree-036-feature' })
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('ACRYL_WEB_PORT sets a start port and fails loudly when invalid', () => {
|
|
116
|
+
expect(selectInstance({ env: { ACRYL_WEB_PORT: '4000' }, osHome: '/h' }).webPort).toEqual({ start: 4000, scan: true })
|
|
117
|
+
for (const bad of ['80', 'abc', '70000']) expect(() => selectInstance({ env: { ACRYL_WEB_PORT: bad }, osHome: '/h' }), bad).toThrow(AppInstanceError)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('ACRYL_WEB_HOST and ACRYL_WEB_TRUSTED_HOSTS open the Web server beyond loopback, and nothing else does', () => {
|
|
121
|
+
expect(selectInstance({ env: {}, osHome: '/h' }).webAccess).toEqual({ host: '127.0.0.1', trustedHosts: [] })
|
|
122
|
+
const container = selectInstance({ env: { ACRYL_HOME: '/data/acryl', ACRYL_WEB_HOST: '0.0.0.0', ACRYL_WEB_TRUSTED_HOSTS: ' ws-1.example.com , ws-1.example.com:8443,' }, osHome: '/h' })
|
|
123
|
+
expect(container.webAccess).toEqual({ host: '0.0.0.0', trustedHosts: ['ws-1.example.com', 'ws-1.example.com:8443'] })
|
|
124
|
+
expect(selectInstance({ env: { ACRYL_WEB_TRUSTED_HOSTS: 'proxy.local' }, osHome: '/h' }).webAccess).toEqual({ host: '127.0.0.1', trustedHosts: ['proxy.local'] })
|
|
125
|
+
for (const bad of ['192.168.1.5', 'localhost', 'all']) expect(() => selectInstance({ env: { ACRYL_WEB_HOST: bad }, osHome: '/h' }), bad).toThrow(AppInstanceError)
|
|
126
|
+
for (const bad of ['http://x.example.com', 'x.example.com/path', 'Upper.Example.com']) expect(() => selectInstance({ env: { ACRYL_WEB_TRUSTED_HOSTS: bad }, osHome: '/h' }), bad).toThrow(AppInstanceError)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
describe('the isolation requirement (ACRYL_REQUIRE_ISOLATED_HOME)', () => {
|
|
131
|
+
const require = { ACRYL_REQUIRE_ISOLATED_HOME: '1' }
|
|
132
|
+
|
|
133
|
+
it('refuses every instance that was not pinned by the caller: the default, the development app, a worktree, a managed app', () => {
|
|
134
|
+
const root = temp()
|
|
135
|
+
const worktree = join(root, 'wt'); mkdirSync(worktree); writeFileSync(join(worktree, '.git'), 'gitdir: x\n')
|
|
136
|
+
expect(() => selectInstance({ env: { ...require }, osHome: root })).toThrow(IsolationRequiredError)
|
|
137
|
+
expect(() => selectInstance({ env: { ...require }, osHome: root, development: true })).toThrow(IsolationRequiredError)
|
|
138
|
+
expect(() => selectInstance({ env: { ...require }, osHome: root, checkout: worktree })).toThrow(IsolationRequiredError)
|
|
139
|
+
expect(() => selectInstance({ env: { ...require, ACRYL_HOME: join(root, '.acryl-instances', 'ledger') }, osHome: root })).toThrow(IsolationRequiredError)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('refuses a pinned home that lies inside a real ACRYL or DSH home, including one set through DSH_HOME alone', () => {
|
|
143
|
+
const root = temp()
|
|
144
|
+
for (const inner of ['.acryl', '.acryl/.dsh', '.acryl-dev', '.acryl-worktrees/x', '.dsh/profiles']) {
|
|
145
|
+
expect(() => selectInstance({ env: { ...require, ACRYL_HOME: join(root, inner) }, osHome: root }), inner).toThrow(IsolationRequiredError)
|
|
146
|
+
}
|
|
147
|
+
expect(() => selectInstance({ env: { ...require, DSH_HOME: join(root, '.dsh') }, osHome: root })).toThrow(/real/u)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('admits an explicitly pinned throwaway home and an app folder outside the real homes', () => {
|
|
151
|
+
const root = temp()
|
|
152
|
+
const elsewhere = temp()
|
|
153
|
+
expect(selectInstance({ env: { ...require, ACRYL_HOME: join(elsewhere, 'home') }, osHome: root })).toMatchObject({ kind: 'pinned' })
|
|
154
|
+
expect(selectInstance({ env: { ...require, DSH_HOME: join(elsewhere, 'engine') }, osHome: root })).toMatchObject({ kind: 'pinned' })
|
|
155
|
+
expect(selectInstance({ env: { ...require, ACRYL_HOME: app(elsewhere, 'ledger') }, osHome: root })).toMatchObject({ kind: 'app' })
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('changes nothing when the variable is unset or blank, so ordinary launches keep their homes', () => {
|
|
159
|
+
const root = temp()
|
|
160
|
+
expect(selectInstance({ env: {}, osHome: root }).kind).toBe('default')
|
|
161
|
+
expect(selectInstance({ env: { ACRYL_REQUIRE_ISOLATED_HOME: ' ' }, osHome: root }).kind).toBe('default')
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
describe('the environment contract', () => {
|
|
166
|
+
it('hands every kind across a process boundary unchanged, and adds nothing for the default', () => {
|
|
167
|
+
const root = temp()
|
|
168
|
+
const worktree = join(root, 'wt'); mkdirSync(worktree); writeFileSync(join(worktree, '.git'), 'gitdir: x\n')
|
|
169
|
+
const cases: AppInstance[] = [
|
|
170
|
+
appFolder(app(root, 'stage-sound'), root),
|
|
171
|
+
selectInstance({ env: {}, osHome: root, checkout: worktree }),
|
|
172
|
+
selectInstance({ env: { DSH_HOME: '/tmp/engine' }, osHome: root }),
|
|
173
|
+
selectInstance({ env: { ACRYL_HOME: '/tmp/pinned' }, osHome: root }),
|
|
174
|
+
selectInstance({ env: { ACRYL_HOME: '/tmp/container', ACRYL_WEB_HOST: '0.0.0.0', ACRYL_WEB_TRUSTED_HOSTS: 'ws-1.example.com' }, osHome: root }),
|
|
175
|
+
]
|
|
176
|
+
for (const parent of cases) {
|
|
177
|
+
const child = selectInstance({ env: { DSH_HOME: '/ambient/should/lose', ...instanceEnvironment(parent) }, osHome: root })
|
|
178
|
+
expect(footprint(child), parent.kind).toEqual(footprint(parent))
|
|
179
|
+
expect(child.webAccess, parent.kind).toEqual(parent.webAccess)
|
|
180
|
+
}
|
|
181
|
+
expect(instanceEnvironment(defaultInstance(root))).toEqual({})
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
describe('Pessimistic Offline Lock', () => {
|
|
186
|
+
it('shows its holder, refuses a live one, admits a compatible one, and takes over a stale one', () => {
|
|
187
|
+
const file = join(temp(), 'lock.json')
|
|
188
|
+
acquireLock(file, { pid: 10, installRoot: '/a' }, { alive: () => true })
|
|
189
|
+
expect(() => acquireLock(file, { pid: 20 }, { alive: () => true })).toThrow(LockHeldError)
|
|
190
|
+
expect(() => acquireLock(file, { pid: 20 }, { alive: () => true, compatible: holder => holder.installRoot === '/a' })).not.toThrow()
|
|
191
|
+
acquireLock(file, { pid: 30 }, { alive: () => false })
|
|
192
|
+
expect(JSON.parse(readFileSync(file, 'utf8')).pid).toBe(30)
|
|
193
|
+
releaseLock(file, 99)
|
|
194
|
+
expect(JSON.parse(readFileSync(file, 'utf8')).pid).toBe(30)
|
|
195
|
+
releaseLock(file, 30)
|
|
196
|
+
expect(() => readFileSync(file)).toThrow()
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
describe('online channel secret (spec 041 TB30)', () => {
|
|
201
|
+
it('is absent until written, then readable back, private, and gone after removal', () => {
|
|
202
|
+
const home = temp()
|
|
203
|
+
expect(readOnlineSecret(home)).toBeUndefined()
|
|
204
|
+
const secret = writeOnlineSecret(home)
|
|
205
|
+
expect(secret).toMatch(/^[0-9a-f]{48}$/)
|
|
206
|
+
expect(readOnlineSecret(home)).toBe(secret)
|
|
207
|
+
if (process.platform !== 'win32') {
|
|
208
|
+
expect(statSync(onlineSecretPath(home)).mode & 0o777).toBe(0o600)
|
|
209
|
+
}
|
|
210
|
+
removeOnlineSecret(home)
|
|
211
|
+
expect(readOnlineSecret(home)).toBeUndefined()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('writes a fresh secret each time (a restart rotates it, TB03)', () => {
|
|
215
|
+
const home = temp()
|
|
216
|
+
const first = writeOnlineSecret(home)
|
|
217
|
+
const second = writeOnlineSecret(home)
|
|
218
|
+
expect(second).not.toBe(first)
|
|
219
|
+
expect(readOnlineSecret(home)).toBe(second)
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe('Registry of running apps', () => {
|
|
224
|
+
it('lists live announcements and drops dead ones', () => {
|
|
225
|
+
const osHome = temp()
|
|
226
|
+
const a = appFolder(app(osHome, 'a-app'), osHome)
|
|
227
|
+
const b = appFolder(app(osHome, 'b-app'), osHome)
|
|
228
|
+
announce(osHome, a, { pid: 1, surface: 'web', port: 3101 })
|
|
229
|
+
announce(osHome, b, { pid: 2, surface: 'desktop' })
|
|
230
|
+
expect(listRunning(osHome, pid => pid === 1).map(entry => entry.id)).toEqual([a.id])
|
|
231
|
+
expect(listRunning(osHome, () => true).map(entry => entry.id)).toEqual([a.id]) // b's dead entry was removed on the previous read
|
|
232
|
+
withdraw(osHome, a, 1)
|
|
233
|
+
expect(listRunning(osHome, () => true)).toEqual([])
|
|
234
|
+
})
|
|
235
|
+
})
|