@acryldev/manifest 0.0.0-stage → 0.1.0
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 +21 -0
- package/app-plugins.ts +86 -0
- package/index.ts +645 -0
- package/lib/app-plugins.js +61 -0
- package/lib/app-plugins.js.map +1 -0
- package/lib/index.js +408 -0
- package/lib/index.js.map +1 -0
- package/lib/lock.js +87 -0
- package/lib/lock.js.map +1 -0
- package/lib/snapshot.js +231 -0
- package/lib/snapshot.js.map +1 -0
- package/lib/types/app-plugins.d.ts +18 -0
- package/lib/types/index.d.ts +119 -0
- package/lib/types/lock.d.ts +7 -0
- package/lib/types/snapshot.d.ts +35 -0
- package/lib/types/tsdown.config.d.ts +2 -0
- package/lib/types/upgrade-cli.d.ts +1 -0
- package/lib/types/upgrade.d.ts +20 -0
- package/lock.ts +115 -0
- package/package.json +54 -3
- package/plugin.json +19 -0
- package/snapshot.ts +275 -0
- package/test/blend-manifest.v1alpha1.schema.json +238 -0
- package/test/lock.test.ts +82 -0
- package/test/manifest.test.ts +332 -0
- package/test/snapshot.test.ts +184 -0
- package/test/upgrade-cli.test.ts +123 -0
- package/test/upgrade.test.ts +158 -0
- package/tsconfig.json +21 -0
- package/tsdown.config.ts +23 -0
- package/upgrade-cli.ts +70 -0
- package/upgrade.ts +97 -0
- package/README.md +0 -3
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://acryl.dev/schemas/blends/blend-manifest.v1alpha1.schema.json",
|
|
4
|
+
"title": "ACRYL BLEND manifest (v1alpha1)",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["apiVersion", "kind", "metadata", "spec"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"apiVersion": {
|
|
10
|
+
"const": "blends.acryl.dev/v1alpha1"
|
|
11
|
+
},
|
|
12
|
+
"kind": {
|
|
13
|
+
"enum": ["Blueprint", "Blend"]
|
|
14
|
+
},
|
|
15
|
+
"metadata": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"additionalProperties": false,
|
|
18
|
+
"required": ["id", "name", "version"],
|
|
19
|
+
"properties": {
|
|
20
|
+
"id": {
|
|
21
|
+
"$ref": "#/$defs/definition-id"
|
|
22
|
+
},
|
|
23
|
+
"name": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"minLength": 1
|
|
26
|
+
},
|
|
27
|
+
"version": {
|
|
28
|
+
"$ref": "#/$defs/semver"
|
|
29
|
+
},
|
|
30
|
+
"category": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
},
|
|
33
|
+
"description": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"license": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"minLength": 1,
|
|
39
|
+
"description": "SPDX license id, or a free-form statement such as 'Proprietary'."
|
|
40
|
+
},
|
|
41
|
+
"visibility": {
|
|
42
|
+
"enum": ["private", "public"],
|
|
43
|
+
"description": "Who may see this definition. A private app is never pushed to a public remote or published to a registry."
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"spec": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"additionalProperties": false,
|
|
50
|
+
"required": ["runtime"],
|
|
51
|
+
"properties": {
|
|
52
|
+
"runtime": {
|
|
53
|
+
"const": "cordis"
|
|
54
|
+
},
|
|
55
|
+
"extends": {
|
|
56
|
+
"$ref": "#/$defs/definition-id"
|
|
57
|
+
},
|
|
58
|
+
"lineage": {
|
|
59
|
+
"$ref": "#/$defs/lineage"
|
|
60
|
+
},
|
|
61
|
+
"rows": {
|
|
62
|
+
"type": "array",
|
|
63
|
+
"items": {
|
|
64
|
+
"$ref": "#/$defs/row-with-name"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"overrides": {
|
|
68
|
+
"type": "array",
|
|
69
|
+
"items": {
|
|
70
|
+
"$ref": "#/$defs/row-without-required-name"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"parameters": {
|
|
74
|
+
"type": "object",
|
|
75
|
+
"additionalProperties": {
|
|
76
|
+
"$ref": "#/$defs/parameter-declaration"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"$defs": {
|
|
83
|
+
"definition-id": {
|
|
84
|
+
"type": "string",
|
|
85
|
+
"pattern": "^[a-z0-9]+(\\.[a-z0-9-]+)+$"
|
|
86
|
+
},
|
|
87
|
+
"semver": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
|
|
90
|
+
},
|
|
91
|
+
"config": {
|
|
92
|
+
"type": "object"
|
|
93
|
+
},
|
|
94
|
+
"row-with-name": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"required": ["id", "name"],
|
|
98
|
+
"properties": {
|
|
99
|
+
"id": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"minLength": 1
|
|
102
|
+
},
|
|
103
|
+
"name": {
|
|
104
|
+
"type": "string",
|
|
105
|
+
"minLength": 1
|
|
106
|
+
},
|
|
107
|
+
"config": {
|
|
108
|
+
"$ref": "#/$defs/config"
|
|
109
|
+
},
|
|
110
|
+
"disabled": {
|
|
111
|
+
"oneOf": [
|
|
112
|
+
{
|
|
113
|
+
"type": "boolean"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"$ref": "#/$defs/js-expr-marker"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"row-without-required-name": {
|
|
123
|
+
"type": "object",
|
|
124
|
+
"additionalProperties": false,
|
|
125
|
+
"required": ["id"],
|
|
126
|
+
"properties": {
|
|
127
|
+
"id": {
|
|
128
|
+
"type": "string",
|
|
129
|
+
"minLength": 1
|
|
130
|
+
},
|
|
131
|
+
"name": {
|
|
132
|
+
"type": "string",
|
|
133
|
+
"minLength": 1
|
|
134
|
+
},
|
|
135
|
+
"config": {
|
|
136
|
+
"$ref": "#/$defs/config"
|
|
137
|
+
},
|
|
138
|
+
"disabled": {
|
|
139
|
+
"oneOf": [
|
|
140
|
+
{
|
|
141
|
+
"type": "boolean"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"$ref": "#/$defs/js-expr-marker"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"lineage": {
|
|
151
|
+
"type": "object",
|
|
152
|
+
"additionalProperties": false,
|
|
153
|
+
"required": ["blueprint", "blueprintVersion"],
|
|
154
|
+
"properties": {
|
|
155
|
+
"blueprint": {
|
|
156
|
+
"$ref": "#/$defs/definition-id"
|
|
157
|
+
},
|
|
158
|
+
"blueprintVersion": {
|
|
159
|
+
"$ref": "#/$defs/semver"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"parameter-declaration": {
|
|
164
|
+
"type": "object",
|
|
165
|
+
"additionalProperties": false,
|
|
166
|
+
"required": ["type", "default"],
|
|
167
|
+
"properties": {
|
|
168
|
+
"type": {
|
|
169
|
+
"enum": ["string", "number", "boolean"]
|
|
170
|
+
},
|
|
171
|
+
"default": true
|
|
172
|
+
},
|
|
173
|
+
"allOf": [
|
|
174
|
+
{
|
|
175
|
+
"if": {
|
|
176
|
+
"properties": {
|
|
177
|
+
"type": {
|
|
178
|
+
"const": "string"
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"required": ["type"]
|
|
182
|
+
},
|
|
183
|
+
"then": {
|
|
184
|
+
"properties": {
|
|
185
|
+
"default": {
|
|
186
|
+
"type": "string"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"if": {
|
|
193
|
+
"properties": {
|
|
194
|
+
"type": {
|
|
195
|
+
"const": "number"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
"required": ["type"]
|
|
199
|
+
},
|
|
200
|
+
"then": {
|
|
201
|
+
"properties": {
|
|
202
|
+
"default": {
|
|
203
|
+
"type": "number"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"if": {
|
|
210
|
+
"properties": {
|
|
211
|
+
"type": {
|
|
212
|
+
"const": "boolean"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"required": ["type"]
|
|
216
|
+
},
|
|
217
|
+
"then": {
|
|
218
|
+
"properties": {
|
|
219
|
+
"default": {
|
|
220
|
+
"type": "boolean"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
"js-expr-marker": {
|
|
228
|
+
"type": "object",
|
|
229
|
+
"additionalProperties": false,
|
|
230
|
+
"required": ["__jsExpr"],
|
|
231
|
+
"properties": {
|
|
232
|
+
"__jsExpr": {
|
|
233
|
+
"type": "string"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { afterEach, test } from 'node:test'
|
|
6
|
+
import { LOCK_FILE, writeLock } from '../lock.ts'
|
|
7
|
+
|
|
8
|
+
const dirs: string[] = []
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const BLEND = `apiVersion: blends.acryl.dev/v1alpha1
|
|
14
|
+
kind: Blueprint
|
|
15
|
+
metadata: { id: acme.shop, name: shop, version: 1.0.0 }
|
|
16
|
+
spec:
|
|
17
|
+
runtime: cordis
|
|
18
|
+
parameters:
|
|
19
|
+
title: { type: string, default: Shop }
|
|
20
|
+
rows:
|
|
21
|
+
- id: greeter
|
|
22
|
+
name: greeter
|
|
23
|
+
config: { text: "{{parameters.title}}" }
|
|
24
|
+
- id: off
|
|
25
|
+
name: greeter
|
|
26
|
+
disabled: true
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
function app() {
|
|
30
|
+
const dir = mkdtempSync(join(tmpdir(), 'lock-test-'))
|
|
31
|
+
dirs.push(dir)
|
|
32
|
+
writeFileSync(join(dir, 'blend.yaml'), BLEND)
|
|
33
|
+
mkdirSync(join(dir, 'src', 'plugins', 'greeter'), { recursive: true })
|
|
34
|
+
writeFileSync(
|
|
35
|
+
join(dir, 'src', 'plugins', 'greeter', 'index.ts'),
|
|
36
|
+
'export const name = "greeter"\n',
|
|
37
|
+
)
|
|
38
|
+
mkdirSync(join(dir, 'extensions', 'clock'), { recursive: true })
|
|
39
|
+
writeFileSync(join(dir, 'extensions', 'clock', 'index.ts'), 'export const name = "clock"\n')
|
|
40
|
+
return dir
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test('the lock is blend.lock.json formatVersion 3: origin digest, resolved parameters and rows, and a local module per plugin and extension', () => {
|
|
44
|
+
const dir = app()
|
|
45
|
+
const locked = writeLock(dir)
|
|
46
|
+
assert.equal(LOCK_FILE, 'blend.lock.json')
|
|
47
|
+
assert.equal(locked.formatVersion, 3)
|
|
48
|
+
assert.deepEqual(
|
|
49
|
+
{ id: locked.origin.id, kind: locked.origin.kind, version: locked.origin.version },
|
|
50
|
+
{ id: 'acme.shop', kind: 'Blueprint', version: '1.0.0' },
|
|
51
|
+
)
|
|
52
|
+
assert.match(locked.origin.digest, /^[0-9a-f]{64}$/)
|
|
53
|
+
assert.deepEqual(locked.parameters, { title: 'Shop' })
|
|
54
|
+
assert.deepEqual(
|
|
55
|
+
locked.rows.map((row) => row.id),
|
|
56
|
+
['greeter', 'off'],
|
|
57
|
+
)
|
|
58
|
+
assert.deepEqual(
|
|
59
|
+
locked.modules.map((module) => [module.name, module.origin, module.source]),
|
|
60
|
+
[
|
|
61
|
+
['clock', 'local', 'extensions/clock'],
|
|
62
|
+
['greeter', 'local', 'src/plugins/greeter'],
|
|
63
|
+
],
|
|
64
|
+
)
|
|
65
|
+
for (const module of locked.modules) assert.match(module.digest ?? '', /^sha256:[0-9a-f]{64}$/)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('the same app gives the same bytes, and a changed plugin changes its digest only', () => {
|
|
69
|
+
const dir = app()
|
|
70
|
+
writeLock(dir)
|
|
71
|
+
const first = readFileSync(join(dir, LOCK_FILE), 'utf8')
|
|
72
|
+
writeLock(dir)
|
|
73
|
+
assert.equal(readFileSync(join(dir, LOCK_FILE), 'utf8'), first)
|
|
74
|
+
writeFileSync(join(dir, 'extensions', 'clock', 'index.ts'), 'export const name = "clock2"\n')
|
|
75
|
+
const changed = writeLock(dir)
|
|
76
|
+
const before = JSON.parse(first).modules
|
|
77
|
+
const same = (name: string) =>
|
|
78
|
+
before.find((m: { name: string }) => m.name === name).digest ===
|
|
79
|
+
changed.modules.find((m) => m.name === name)?.digest
|
|
80
|
+
assert.equal(same('greeter'), true)
|
|
81
|
+
assert.equal(same('clock'), false)
|
|
82
|
+
})
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { afterEach, test } from 'node:test'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
8
|
+
import { Ajv2020 } from 'ajv/dist/2020.js'
|
|
9
|
+
import { parse } from 'yaml'
|
|
10
|
+
import { compose, loadManifest, ManifestError, validate } from '../index.ts'
|
|
11
|
+
|
|
12
|
+
const dirs: string[] = []
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
function file(text: string) {
|
|
18
|
+
const dir = mkdtempSync(join(tmpdir(), 'manifest-test-'))
|
|
19
|
+
dirs.push(dir)
|
|
20
|
+
const path = join(dir, 'blend.yaml')
|
|
21
|
+
writeFileSync(path, text)
|
|
22
|
+
return path
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const GOOD = `apiVersion: blends.acryl.dev/v1alpha1
|
|
26
|
+
kind: Blueprint
|
|
27
|
+
metadata: { id: acrylblends.shop, name: shop, version: 1.0.0 }
|
|
28
|
+
spec:
|
|
29
|
+
runtime: cordis
|
|
30
|
+
parameters:
|
|
31
|
+
greeting: { type: string, default: hello }
|
|
32
|
+
port: { type: number, default: 3000 }
|
|
33
|
+
rows:
|
|
34
|
+
- id: greeter
|
|
35
|
+
name: greeter
|
|
36
|
+
config: { text: "{{parameters.greeting}}, world", port: "{{parameters.port}}" }
|
|
37
|
+
- id: second-greeter
|
|
38
|
+
name: greeter
|
|
39
|
+
disabled: true
|
|
40
|
+
`
|
|
41
|
+
|
|
42
|
+
test('resolves parameters: a whole token keeps its type, an embedded one renders as text', () => {
|
|
43
|
+
const manifest = loadManifest(file(GOOD), { known: ['greeter'], values: { greeting: 'hi' } })
|
|
44
|
+
assert.deepEqual(manifest.plugins[0], {
|
|
45
|
+
id: 'greeter',
|
|
46
|
+
use: 'greeter',
|
|
47
|
+
config: { text: 'hi, world', port: 3000 },
|
|
48
|
+
})
|
|
49
|
+
assert.equal(manifest.plugins[1]?.use, 'greeter')
|
|
50
|
+
assert.match(manifest.digest, /^[0-9a-f]{64}$/)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('reports every problem with a path and a code, never a bare "invalid"', () => {
|
|
54
|
+
const problems = validate(
|
|
55
|
+
{
|
|
56
|
+
apiVersion: 'blends.acryl.dev/v1alpha1',
|
|
57
|
+
kind: 'Blueprint',
|
|
58
|
+
metadata: { id: 'Shop', name: '', version: '1', surprise: 1 },
|
|
59
|
+
spec: {
|
|
60
|
+
runtime: 'cordis',
|
|
61
|
+
parameters: {
|
|
62
|
+
unused: { type: 'string', default: 'x' },
|
|
63
|
+
wrong: { type: 'number', default: 'nope' },
|
|
64
|
+
described: { type: 'string', default: 'x', description: 'not in the format' },
|
|
65
|
+
},
|
|
66
|
+
rows: [
|
|
67
|
+
{
|
|
68
|
+
id: 'a',
|
|
69
|
+
name: 'a',
|
|
70
|
+
config: { x: '{{parameters.missing}} {{parameters.wrong}} {{parameters.described}}' },
|
|
71
|
+
},
|
|
72
|
+
{ id: 'a', name: 'ghost', extra: 1 },
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
extra: true,
|
|
76
|
+
},
|
|
77
|
+
['a'],
|
|
78
|
+
).map((d) => `${d.code} ${d.path}`)
|
|
79
|
+
assert.deepEqual(problems.sort(), [
|
|
80
|
+
'dangling-parameter-reference spec.rows[0].config.x',
|
|
81
|
+
'duplicate-row-id spec.rows[1].id',
|
|
82
|
+
'parameter-type-mismatch spec.parameters.wrong.default',
|
|
83
|
+
'schema-error extra',
|
|
84
|
+
'schema-error metadata.id',
|
|
85
|
+
'schema-error metadata.name',
|
|
86
|
+
'schema-error metadata.surprise',
|
|
87
|
+
'schema-error metadata.version',
|
|
88
|
+
'schema-error spec.parameters.described.description',
|
|
89
|
+
'schema-error spec.rows[1].extra',
|
|
90
|
+
'unknown-plugin spec.rows[1].name',
|
|
91
|
+
'unused-parameter spec.parameters.unused',
|
|
92
|
+
])
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
/** A Blueprint and a Blend made from it, as files, with a lookup by definition id. */
|
|
96
|
+
const BLUEPRINT = `apiVersion: blends.acryl.dev/v1alpha1
|
|
97
|
+
kind: Blueprint
|
|
98
|
+
metadata: { id: acme.shop, name: Shop, version: 1.0.0 }
|
|
99
|
+
spec:
|
|
100
|
+
runtime: cordis
|
|
101
|
+
parameters:
|
|
102
|
+
host: { type: string, default: 127.0.0.1 }
|
|
103
|
+
rows:
|
|
104
|
+
- id: http
|
|
105
|
+
name: http
|
|
106
|
+
- id: routes
|
|
107
|
+
name: routes
|
|
108
|
+
config: { title: base, tags: [a] }
|
|
109
|
+
- id: server
|
|
110
|
+
name: server
|
|
111
|
+
config: { hostname: "{{parameters.host}}", port: 3000 }
|
|
112
|
+
`
|
|
113
|
+
const BLEND = `apiVersion: blends.acryl.dev/v1alpha1
|
|
114
|
+
kind: Blend
|
|
115
|
+
metadata: { id: me.my-shop, name: my-shop, version: 0.1.0 }
|
|
116
|
+
spec:
|
|
117
|
+
runtime: cordis
|
|
118
|
+
lineage: { blueprint: acme.shop, blueprintVersion: 1.0.0 }
|
|
119
|
+
parameters:
|
|
120
|
+
port: { type: number, default: 8080 }
|
|
121
|
+
overrides:
|
|
122
|
+
- id: server
|
|
123
|
+
config: { port: "{{parameters.port}}" }
|
|
124
|
+
- id: routes
|
|
125
|
+
disabled: true
|
|
126
|
+
rows:
|
|
127
|
+
- id: cache
|
|
128
|
+
name: cache
|
|
129
|
+
`
|
|
130
|
+
|
|
131
|
+
function blendWith(blueprint: string, blend: string) {
|
|
132
|
+
const dir = mkdtempSync(join(tmpdir(), 'manifest-test-'))
|
|
133
|
+
dirs.push(dir)
|
|
134
|
+
writeFileSync(join(dir, 'shop.yaml'), blueprint)
|
|
135
|
+
writeFileSync(join(dir, 'blend.yaml'), blend)
|
|
136
|
+
return {
|
|
137
|
+
blend: join(dir, 'blend.yaml'),
|
|
138
|
+
blueprints: (id: string) => (id === 'acme.shop' ? join(dir, 'shop.yaml') : undefined),
|
|
139
|
+
dir,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
test('a Blend resolves over its Blueprint: inherited rows first, overrides merged by id, own rows after', () => {
|
|
144
|
+
const { blend, blueprints } = blendWith(BLUEPRINT, BLEND)
|
|
145
|
+
const resolved = loadManifest(blend, {
|
|
146
|
+
getBlueprint: blueprints,
|
|
147
|
+
known: ['http', 'routes', 'server', 'cache'],
|
|
148
|
+
})
|
|
149
|
+
assert.deepEqual(resolved.plugins, [
|
|
150
|
+
{ id: 'http', use: 'http' },
|
|
151
|
+
{ id: 'routes', use: 'routes', config: { title: 'base', tags: ['a'] }, disabled: true },
|
|
152
|
+
// a shallow merge: the override sets port (and takes the Blend's parameter), the parent's hostname is kept, with the parent's default
|
|
153
|
+
{ id: 'server', use: 'server', config: { hostname: '127.0.0.1', port: 8080 } },
|
|
154
|
+
{ id: 'cache', use: 'cache' },
|
|
155
|
+
])
|
|
156
|
+
assert.deepEqual(resolved.values, { port: 8080 })
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test("the Blend's own parameters apply to its overrides, and the parent keeps its defaults", () => {
|
|
160
|
+
const { blend, blueprints } = blendWith(BLUEPRINT, BLEND)
|
|
161
|
+
const resolved = loadManifest(blend, { getBlueprint: blueprints, values: { port: 9000 } })
|
|
162
|
+
assert.equal(resolved.plugins.find((row) => row.id === 'server')?.config?.port, 9000)
|
|
163
|
+
assert.equal(resolved.plugins.find((row) => row.id === 'server')?.config?.hostname, '127.0.0.1')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const codes = (run: () => unknown) => {
|
|
167
|
+
try {
|
|
168
|
+
run()
|
|
169
|
+
} catch (error) {
|
|
170
|
+
return error instanceof ManifestError
|
|
171
|
+
? error.diagnostics.map((d) => `${d.code} ${d.path}`).sort()
|
|
172
|
+
: [String(error)]
|
|
173
|
+
}
|
|
174
|
+
return []
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
test('Blend rules: lineage, parent, overrides and collisions are each a diagnostic with a path', () => {
|
|
178
|
+
const noLineage = BLEND.replace(
|
|
179
|
+
' lineage: { blueprint: acme.shop, blueprintVersion: 1.0.0 }\n',
|
|
180
|
+
'',
|
|
181
|
+
)
|
|
182
|
+
assert.deepEqual(
|
|
183
|
+
codes(() => loadManifest(blendWith(BLUEPRINT, noLineage).blend)),
|
|
184
|
+
['blend-without-lineage spec.lineage', 'overrides-without-parent spec.overrides'],
|
|
185
|
+
)
|
|
186
|
+
const _blueprintWithLineage = BLUEPRINT.replace(
|
|
187
|
+
' runtime: cordis\n',
|
|
188
|
+
' runtime: cordis\n lineage: { blueprint: acme.base, blueprintVersion: 1.0.0 }\n',
|
|
189
|
+
)
|
|
190
|
+
assert.deepEqual(
|
|
191
|
+
codes(() =>
|
|
192
|
+
loadManifest(blendWith(BLUEPRINT, BLEND.replace('kind: Blend', 'kind: Blueprint')).blend),
|
|
193
|
+
),
|
|
194
|
+
['blueprint-with-lineage spec.lineage', 'overrides-without-parent spec.overrides'],
|
|
195
|
+
)
|
|
196
|
+
const mismatch = BLEND.replace(
|
|
197
|
+
' runtime: cordis\n',
|
|
198
|
+
' runtime: cordis\n extends: acme.other\n',
|
|
199
|
+
)
|
|
200
|
+
assert.deepEqual(
|
|
201
|
+
codes(() =>
|
|
202
|
+
loadManifest(blendWith(BLUEPRINT, mismatch).blend, { getBlueprint: () => undefined }),
|
|
203
|
+
),
|
|
204
|
+
['lineage-extends-mismatch spec.extends', 'parent-not-supplied spec.extends'],
|
|
205
|
+
)
|
|
206
|
+
const { blend } = blendWith(BLUEPRINT, BLEND)
|
|
207
|
+
assert.deepEqual(
|
|
208
|
+
codes(() => loadManifest(blend)),
|
|
209
|
+
['parent-not-supplied spec.lineage.blueprint'],
|
|
210
|
+
)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('an override of a row the parent does not have, and an own row that reuses a parent id, are reported', () => {
|
|
214
|
+
const bad = BLEND.replace(
|
|
215
|
+
' - id: routes\n disabled: true',
|
|
216
|
+
' - id: ghost\n disabled: true',
|
|
217
|
+
).replace(' - id: cache\n name: cache', ' - id: http\n name: http')
|
|
218
|
+
const { blend, blueprints } = blendWith(BLUEPRINT, bad)
|
|
219
|
+
assert.deepEqual(
|
|
220
|
+
codes(() => loadManifest(blend, { getBlueprint: blueprints })),
|
|
221
|
+
['insert-id-collision spec.rows[0].id', 'override-unknown-id spec.overrides[1].id'],
|
|
222
|
+
)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test('a cycle in the chain, an invalid parent and an inherited row with no plugin are all reported', () => {
|
|
226
|
+
const dir = mkdtempSync(join(tmpdir(), 'manifest-test-'))
|
|
227
|
+
dirs.push(dir)
|
|
228
|
+
const a = `apiVersion: blends.acryl.dev/v1alpha1\nkind: Blueprint\nmetadata: { id: acme.a, name: a, version: 1.0.0 }\nspec: { runtime: cordis, extends: acme.b }\n`
|
|
229
|
+
const b = a
|
|
230
|
+
.replace('acme.a, name: a', 'acme.b, name: b')
|
|
231
|
+
.replace('extends: acme.b', 'extends: acme.a')
|
|
232
|
+
writeFileSync(join(dir, 'a.yaml'), a)
|
|
233
|
+
writeFileSync(join(dir, 'b.yaml'), b)
|
|
234
|
+
const lookup = (id: string) =>
|
|
235
|
+
({ 'acme.a': join(dir, 'a.yaml'), 'acme.b': join(dir, 'b.yaml') })[id]
|
|
236
|
+
const root = join(dir, 'blend.yaml')
|
|
237
|
+
writeFileSync(
|
|
238
|
+
root,
|
|
239
|
+
a.replace('acme.a, name: a', 'me.app, name: app').replace('extends: acme.b', 'extends: acme.a'),
|
|
240
|
+
)
|
|
241
|
+
assert.ok(
|
|
242
|
+
codes(() => loadManifest(root, { getBlueprint: lookup })).some((entry) =>
|
|
243
|
+
entry.startsWith('parent-cycle'),
|
|
244
|
+
),
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
writeFileSync(join(dir, 'broken.yaml'), 'kind: nope\n')
|
|
248
|
+
const broken = codes(() =>
|
|
249
|
+
loadManifest(blendWith(BLUEPRINT, BLEND).blend, {
|
|
250
|
+
getBlueprint: () => join(dir, 'broken.yaml'),
|
|
251
|
+
}),
|
|
252
|
+
)
|
|
253
|
+
assert.ok(broken.length > 0 && broken.every((entry) => entry.includes("parent 'acme.shop': ")))
|
|
254
|
+
|
|
255
|
+
const { blend, blueprints } = blendWith(BLUEPRINT, BLEND)
|
|
256
|
+
assert.deepEqual(
|
|
257
|
+
codes(() =>
|
|
258
|
+
loadManifest(blend, { getBlueprint: blueprints, known: ['http', 'routes', 'cache'] }),
|
|
259
|
+
),
|
|
260
|
+
["unknown-plugin resolved row 'server'"],
|
|
261
|
+
)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
test('loadManifest throws every diagnostic at once, including a bad override', () => {
|
|
265
|
+
assert.throws(
|
|
266
|
+
() =>
|
|
267
|
+
loadManifest(file(GOOD), {
|
|
268
|
+
known: ['greeter'],
|
|
269
|
+
values: { port: 'eighty' as never, nothing: 1 },
|
|
270
|
+
}),
|
|
271
|
+
(error: unknown) =>
|
|
272
|
+
error instanceof ManifestError &&
|
|
273
|
+
error.diagnostics
|
|
274
|
+
.map((d) => d.code)
|
|
275
|
+
.sort()
|
|
276
|
+
.join() === 'parameter-override-unknown,parameter-type-mismatch',
|
|
277
|
+
)
|
|
278
|
+
assert.throws(() => loadManifest(file('kind: [unclosed')), /parse-error|not a valid app manifest/)
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
test('compose mounts enabled rows in order with their config, and runtime overrides win', async () => {
|
|
282
|
+
const seen: Array<[string, unknown]> = []
|
|
283
|
+
const greeter = {
|
|
284
|
+
name: 'greeter',
|
|
285
|
+
apply: (_: Context, config: unknown) => void seen.push(['greeter', config]),
|
|
286
|
+
}
|
|
287
|
+
const manifest = loadManifest(file(GOOD), { known: ['greeter'] })
|
|
288
|
+
const root = new Context()
|
|
289
|
+
const fibers = await compose(root, manifest, { greeter }, { greeter: { port: 0 } })
|
|
290
|
+
assert.equal(fibers.length, 1)
|
|
291
|
+
assert.deepEqual(seen, [['greeter', { text: 'hello, world', port: 0 }]])
|
|
292
|
+
for (const fiber of fibers) await fiber.dispose()
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
/** The proof that a manifest is a Blend: ACRYL's own JSON schema (copied from runtime/blends-core, MIT) accepts it. */
|
|
296
|
+
const schema = JSON.parse(
|
|
297
|
+
readFileSync(
|
|
298
|
+
fileURLToPath(new URL('./blend-manifest.v1alpha1.schema.json', import.meta.url)),
|
|
299
|
+
'utf8',
|
|
300
|
+
),
|
|
301
|
+
)
|
|
302
|
+
const accepts = new Ajv2020({ allErrors: true }).compile(schema)
|
|
303
|
+
|
|
304
|
+
test("a manifest this plugin accepts is a valid ACRYL blend.yaml: the test fixture and both templates pass ACRYL's schema", () => {
|
|
305
|
+
assert.equal(accepts(parse(GOOD)), true, JSON.stringify(accepts.errors))
|
|
306
|
+
const templates = fileURLToPath(
|
|
307
|
+
new URL('../../../framework/packages/cli/templates/', import.meta.url),
|
|
308
|
+
)
|
|
309
|
+
for (const template of readdirSync(templates)) {
|
|
310
|
+
const text = readFileSync(join(templates, template, 'blend.yaml'), 'utf8').replaceAll(
|
|
311
|
+
'__APP_NAME__',
|
|
312
|
+
'my-app',
|
|
313
|
+
)
|
|
314
|
+
const document = parse(text)
|
|
315
|
+
assert.equal(accepts(document), true, `${template}: ${JSON.stringify(accepts.errors)}`)
|
|
316
|
+
assert.deepEqual(validate(document), [], template)
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
test("ACRYL's schema accepts a Blend too", () => {
|
|
321
|
+
assert.equal(accepts(parse(BLEND)), true, JSON.stringify(accepts.errors))
|
|
322
|
+
assert.equal(accepts(parse(BLUEPRINT)), true, JSON.stringify(accepts.errors))
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
test('and the schema rejects what this plugin rejects, so the two agree on a document with an unknown field', () => {
|
|
326
|
+
const document = parse(GOOD)
|
|
327
|
+
document.spec.parameters.greeting.description = 'not allowed'
|
|
328
|
+
assert.equal(accepts(document), false)
|
|
329
|
+
assert.ok(
|
|
330
|
+
validate(document, ['greeter']).some((d) => d.path === 'spec.parameters.greeting.description'),
|
|
331
|
+
)
|
|
332
|
+
})
|