@easy-web/core 1.4.1 → 1.6.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/README.md +42 -1
- package/dist/contracts/capabilities.d.ts +38 -0
- package/dist/contracts/capabilities.d.ts.map +1 -1
- package/dist/contracts/content-composition.d.ts +144 -0
- package/dist/contracts/content-composition.d.ts.map +1 -0
- package/dist/contracts/content-composition.js +143 -0
- package/dist/contracts/content-composition.js.map +1 -0
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/traits.d.ts +98 -0
- package/dist/contracts/traits.d.ts.map +1 -0
- package/dist/contracts/traits.js +84 -0
- package/dist/contracts/traits.js.map +1 -0
- package/dist/demo/demo-content.d.ts +37 -0
- package/dist/demo/demo-content.d.ts.map +1 -0
- package/dist/demo/demo-content.js +171 -0
- package/dist/demo/demo-content.js.map +1 -0
- package/dist/demo/index.d.ts +3 -0
- package/dist/demo/index.d.ts.map +1 -0
- package/dist/demo/index.js +3 -0
- package/dist/demo/index.js.map +1 -0
- package/dist/demo/legal-shells.d.ts +18 -0
- package/dist/demo/legal-shells.d.ts.map +1 -0
- package/dist/demo/legal-shells.js +40 -0
- package/dist/demo/legal-shells.js.map +1 -0
- package/dist/i18n/cli-catalogs.d.ts +42 -0
- package/dist/i18n/cli-catalogs.d.ts.map +1 -0
- package/dist/i18n/cli-catalogs.js +29 -0
- package/dist/i18n/cli-catalogs.js.map +1 -0
- package/dist/i18n/create-localization.d.ts +37 -0
- package/dist/i18n/create-localization.d.ts.map +1 -0
- package/dist/i18n/create-localization.js +68 -0
- package/dist/i18n/create-localization.js.map +1 -0
- package/dist/i18n/explicit-formatters.d.ts +20 -0
- package/dist/i18n/explicit-formatters.d.ts.map +1 -0
- package/dist/i18n/explicit-formatters.js +18 -0
- package/dist/i18n/explicit-formatters.js.map +1 -0
- package/dist/i18n/index.d.ts +4 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/locale-inputs.d.ts +18 -0
- package/dist/i18n/locale-inputs.d.ts.map +1 -0
- package/dist/i18n/locale-inputs.js +73 -0
- package/dist/i18n/locale-inputs.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/recipes/admission.d.ts +161 -0
- package/dist/recipes/admission.d.ts.map +1 -0
- package/dist/recipes/admission.js +85 -0
- package/dist/recipes/admission.js.map +1 -0
- package/dist/recipes/graph.d.ts +101 -0
- package/dist/recipes/graph.d.ts.map +1 -0
- package/dist/recipes/graph.js +166 -0
- package/dist/recipes/graph.js.map +1 -0
- package/dist/recipes/index.d.ts +9 -0
- package/dist/recipes/index.d.ts.map +1 -0
- package/dist/recipes/index.js +9 -0
- package/dist/recipes/index.js.map +1 -0
- package/dist/recipes/mermaid.d.ts +3 -0
- package/dist/recipes/mermaid.d.ts.map +1 -0
- package/dist/recipes/mermaid.js +79 -0
- package/dist/recipes/mermaid.js.map +1 -0
- package/dist/recipes/registry.d.ts +82 -0
- package/dist/recipes/registry.d.ts.map +1 -0
- package/dist/recipes/registry.js +40 -0
- package/dist/recipes/registry.js.map +1 -0
- package/dist/recipes/schema.d.ts +129 -0
- package/dist/recipes/schema.d.ts.map +1 -0
- package/dist/recipes/schema.js +41 -0
- package/dist/recipes/schema.js.map +1 -0
- package/dist/recipes/serialize.d.ts +20 -0
- package/dist/recipes/serialize.d.ts.map +1 -0
- package/dist/recipes/serialize.js +56 -0
- package/dist/recipes/serialize.js.map +1 -0
- package/dist/recipes/shell-recipe.d.ts +59 -0
- package/dist/recipes/shell-recipe.d.ts.map +1 -0
- package/dist/recipes/shell-recipe.js +145 -0
- package/dist/recipes/shell-recipe.js.map +1 -0
- package/dist/recipes/types.d.ts +72 -0
- package/dist/recipes/types.d.ts.map +1 -0
- package/dist/recipes/types.js +13 -0
- package/dist/recipes/types.js.map +1 -0
- package/dist/schemas/galleries.d.ts +2 -2
- package/package.json +17 -1
- package/src/components/DemoLegalShell.astro +36 -0
- package/src/contracts/__tests__/content-composition.test.ts +170 -0
- package/src/contracts/capabilities.ts +49 -0
- package/src/contracts/content-composition.ts +176 -0
- package/src/contracts/index.ts +2 -0
- package/src/contracts/traits.ts +107 -0
- package/src/demo/__tests__/demo-content.test.ts +107 -0
- package/src/demo/demo-content.ts +210 -0
- package/src/demo/index.ts +2 -0
- package/src/demo/legal-shells.ts +52 -0
- package/src/i18n/__tests__/create-localization.test.ts +138 -0
- package/src/i18n/__tests__/explicit-formatters.test.ts +82 -0
- package/src/i18n/cli-catalogs.ts +44 -0
- package/src/i18n/create-localization.ts +67 -0
- package/src/i18n/explicit-formatters.ts +36 -0
- package/src/i18n/index.ts +4 -0
- package/src/i18n/locale-inputs.ts +73 -0
- package/src/index.ts +1 -0
- package/src/recipes/__tests__/graph.test.ts +139 -0
- package/src/recipes/__tests__/protocol.test.ts +180 -0
- package/src/recipes/__tests__/serialize.test.ts +128 -0
- package/src/recipes/__tests__/shell-recipe.test.ts +75 -0
- package/src/recipes/admission.ts +77 -0
- package/src/recipes/graph.ts +244 -0
- package/src/recipes/index.ts +8 -0
- package/src/recipes/mermaid.ts +75 -0
- package/src/recipes/registry.ts +48 -0
- package/src/recipes/schema.ts +53 -0
- package/src/recipes/serialize.ts +77 -0
- package/src/recipes/shell-recipe.ts +162 -0
- package/src/recipes/types.ts +63 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { z } from 'astro/zod';
|
|
3
|
+
import {
|
|
4
|
+
createRecipeAdmissionSchema, recipeMetadataDescriptorSchema, recipeMetadataJsonSchema,
|
|
5
|
+
recipeMetadataSchema, recipeRegistryManifestSchema,
|
|
6
|
+
} from '../index.js';
|
|
7
|
+
import type { RecipeMetadata, RecipeRegistryPin } from '../index.js';
|
|
8
|
+
|
|
9
|
+
const integrity = `sha512-${'A'.repeat(86)}==`;
|
|
10
|
+
const otherIntegrity = `sha512-${'B'.repeat(86)}==`;
|
|
11
|
+
|
|
12
|
+
function fixture() {
|
|
13
|
+
const generate = vi.fn(() => ({ files: [] }));
|
|
14
|
+
const validate = vi.fn(() => []);
|
|
15
|
+
const recipe = {
|
|
16
|
+
id: 'shell', version: '1.5.0', protocolVersion: 1,
|
|
17
|
+
compatibleCliRange: '^0.1.0', compatibleRuntimeRange: '^1.5.0',
|
|
18
|
+
provides: ['shell'], requires: [], conflicts: [],
|
|
19
|
+
order: { priority: 0, key: 'shell' },
|
|
20
|
+
optionsSchema: z.strictObject({ title: z.string() }),
|
|
21
|
+
outputContributions: [{ kind: 'file', id: 'shell.layout', target: 'src/layouts/Base.astro' }],
|
|
22
|
+
validators: [{ id: 'shell.options', phase: 'options', validate }], generate,
|
|
23
|
+
} satisfies RecipeMetadata<{ title: string }>;
|
|
24
|
+
const pin = {
|
|
25
|
+
packageName: '@easy-web/core', version: '1.5.0', integrity, exportPath: './recipes/shell',
|
|
26
|
+
} satisfies RecipeRegistryPin;
|
|
27
|
+
const artifact = { recipe, receipt: { source: 'bundled', pin, verifiedIntegrity: integrity } };
|
|
28
|
+
const input = { registry: { protocolVersion: 1, recipes: [pin] }, artifacts: [artifact] };
|
|
29
|
+
const schema = createRecipeAdmissionSchema({
|
|
30
|
+
cliVersion: '0.1.0', runtimeVersion: '1.5.0',
|
|
31
|
+
// Bounded fake policy; production semver syntax/satisfaction belongs to todo 4.
|
|
32
|
+
satisfies: (version, range) => range === `^${version}`,
|
|
33
|
+
});
|
|
34
|
+
return { generate, validate, recipe, pin, artifact, input, schema };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('recipe protocol admission', () => {
|
|
38
|
+
it('admits valid capability combinations without running hooks', () => {
|
|
39
|
+
// Given
|
|
40
|
+
const f = fixture();
|
|
41
|
+
const pin = { ...f.pin, exportPath: './recipes/navigation' };
|
|
42
|
+
const input = {
|
|
43
|
+
registry: { ...f.input.registry, recipes: [f.pin, pin] },
|
|
44
|
+
artifacts: [f.artifact, {
|
|
45
|
+
receipt: { ...f.artifact.receipt, pin },
|
|
46
|
+
recipe: { ...f.recipe, id: 'navigation', provides: ['Linkable'], requires: ['shell'] },
|
|
47
|
+
}],
|
|
48
|
+
};
|
|
49
|
+
// When
|
|
50
|
+
const result = f.schema.safeParse(input);
|
|
51
|
+
// Then
|
|
52
|
+
expect(result.success).toBe(true);
|
|
53
|
+
expect(f.generate).not.toHaveBeenCalled();
|
|
54
|
+
expect(f.validate).not.toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it.each([
|
|
58
|
+
['duplicate-provider-id', { id: 'navigation', provides: ['shell'], requires: [] }],
|
|
59
|
+
['missing-requirement', { id: 'navigation', provides: ['Linkable'], requires: ['HasImage'] }],
|
|
60
|
+
['dependency-cycle', { id: 'navigation', provides: ['Linkable'], requires: ['shell'] }],
|
|
61
|
+
['conflicting-capability', { id: 'navigation', provides: ['Linkable'], requires: [], conflicts: ['shell'] }],
|
|
62
|
+
])('rejects %s before generation', (code, patch) => {
|
|
63
|
+
// Given
|
|
64
|
+
const f = fixture();
|
|
65
|
+
const pin = { ...f.pin, exportPath: './recipes/navigation' };
|
|
66
|
+
const input = {
|
|
67
|
+
registry: { ...f.input.registry, recipes: [f.pin, pin] },
|
|
68
|
+
artifacts: [{ ...f.artifact, recipe: {
|
|
69
|
+
...f.recipe, requires: code === 'dependency-cycle' ? ['Linkable'] : [],
|
|
70
|
+
} }, {
|
|
71
|
+
receipt: { ...f.artifact.receipt, pin }, recipe: { ...f.recipe, ...patch },
|
|
72
|
+
}],
|
|
73
|
+
};
|
|
74
|
+
// When
|
|
75
|
+
const result = f.schema.safeParse(input);
|
|
76
|
+
// Then
|
|
77
|
+
expect(result.success).toBe(false);
|
|
78
|
+
if (!result.success) expect(result.error.issues.map((issue) => issue.message)).toContain(code);
|
|
79
|
+
expect(f.generate).not.toHaveBeenCalled();
|
|
80
|
+
expect(f.validate).not.toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it.each([
|
|
84
|
+
['protocol version', { protocolVersion: 2 }],
|
|
85
|
+
['invalid shape', { provides: 'shell' }],
|
|
86
|
+
['invalid generation hook', { generate: 'direct' }],
|
|
87
|
+
['invalid option schema', { optionsSchema: {} }],
|
|
88
|
+
['invalid validator', { validators: [{ id: 'shell.options', phase: 'options', validate: 42 }] }],
|
|
89
|
+
['CLI compatibility range', { compatibleCliRange: '^9.0.0' }],
|
|
90
|
+
['runtime compatibility range', { compatibleRuntimeRange: '^2.0.0' }],
|
|
91
|
+
['invalid semver range', { compatibleRuntimeRange: 'not-semver' }],
|
|
92
|
+
['artifact version', { version: '1.6.0' }],
|
|
93
|
+
['self requirement', { requires: ['shell'] }],
|
|
94
|
+
])('rejects incompatible or malformed %s before generation', (_name, patch) => {
|
|
95
|
+
// Given
|
|
96
|
+
const f = fixture();
|
|
97
|
+
const input = { ...f.input, artifacts: [{ ...f.artifact, recipe: { ...f.recipe, ...patch } }] };
|
|
98
|
+
// When
|
|
99
|
+
const result = f.schema.safeParse(input);
|
|
100
|
+
// Then
|
|
101
|
+
expect(result.success).toBe(false);
|
|
102
|
+
expect(f.generate).not.toHaveBeenCalled();
|
|
103
|
+
expect(f.validate).not.toHaveBeenCalled();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it.each([
|
|
107
|
+
['tampered integrity', { verifiedIntegrity: otherIntegrity }],
|
|
108
|
+
['target node_modules', { source: 'target-node-modules' }],
|
|
109
|
+
['third-party package', { pin: { packageName: '@other/recipe' } }],
|
|
110
|
+
['unregistered first-party package', { pin: { packageName: '@easy-web/unregistered' } }],
|
|
111
|
+
['non-pinned export', { pin: { exportPath: './recipes/other' } }],
|
|
112
|
+
['non-pinned version', { pin: { version: '1.6.0' } }],
|
|
113
|
+
['non-pinned integrity', { pin: { integrity: otherIntegrity }, verifiedIntegrity: otherIntegrity }],
|
|
114
|
+
])('rejects %s receipts before generation', (_name, patch) => {
|
|
115
|
+
// Given
|
|
116
|
+
const f = fixture();
|
|
117
|
+
const receipt = { ...f.artifact.receipt, ...patch, pin: { ...f.pin, ...patch.pin } };
|
|
118
|
+
// When
|
|
119
|
+
const result = f.schema.safeParse({ ...f.input, artifacts: [{ ...f.artifact, receipt }] });
|
|
120
|
+
// Then
|
|
121
|
+
expect(result.success).toBe(false);
|
|
122
|
+
expect(f.generate).not.toHaveBeenCalled();
|
|
123
|
+
expect(f.validate).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('recipe descriptor and registry schemas', () => {
|
|
128
|
+
it('accepts a serializable projection independently of executable metadata', () => {
|
|
129
|
+
// Given
|
|
130
|
+
const f = fixture();
|
|
131
|
+
const descriptor = {
|
|
132
|
+
...f.recipe, generate: 'direct', optionsSchema: z.toJSONSchema(f.recipe.optionsSchema),
|
|
133
|
+
validators: [{ id: 'shell.options', phase: 'options' }],
|
|
134
|
+
};
|
|
135
|
+
// When
|
|
136
|
+
const result = recipeMetadataDescriptorSchema.safeParse(JSON.parse(JSON.stringify(descriptor)));
|
|
137
|
+
// Then
|
|
138
|
+
expect(result.success).toBe(true);
|
|
139
|
+
expect(recipeMetadataJsonSchema.properties?.['protocolVersion']).toMatchObject({ const: 1 });
|
|
140
|
+
expect(recipeMetadataJsonSchema.additionalProperties).toBe(false);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('keeps the parsed options schema capable of rejecting invalid options', () => {
|
|
144
|
+
// Given
|
|
145
|
+
const f = fixture();
|
|
146
|
+
// When
|
|
147
|
+
const recipe = recipeMetadataSchema.parse(f.recipe);
|
|
148
|
+
// Then
|
|
149
|
+
expect(recipe.optionsSchema.safeParse({ title: 42 }).success).toBe(false);
|
|
150
|
+
expect(recipe.optionsSchema.safeParse({ title: 'Example' }).success).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it.each([
|
|
154
|
+
['range instead of exact version', { version: '^1.5.0' }],
|
|
155
|
+
['malformed version', { version: '01.5.0' }],
|
|
156
|
+
['malformed integrity', { integrity: 'sha512-invalid' }],
|
|
157
|
+
['path traversal', { exportPath: './../recipe' }],
|
|
158
|
+
['absolute export', { exportPath: 'C:/target/node_modules/recipe' }],
|
|
159
|
+
])('rejects registry %s', (_name, patch) => {
|
|
160
|
+
// Given
|
|
161
|
+
const f = fixture();
|
|
162
|
+
// When
|
|
163
|
+
const result = recipeRegistryManifestSchema.safeParse({
|
|
164
|
+
...f.input.registry, recipes: [{ ...f.pin, ...patch }],
|
|
165
|
+
});
|
|
166
|
+
// Then
|
|
167
|
+
expect(result.success).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('rejects ambiguous duplicate pins', () => {
|
|
171
|
+
// Given
|
|
172
|
+
const f = fixture();
|
|
173
|
+
// When
|
|
174
|
+
const result = recipeRegistryManifestSchema.safeParse({
|
|
175
|
+
...f.input.registry, recipes: [f.pin, { ...f.pin, version: '1.6.0' }],
|
|
176
|
+
});
|
|
177
|
+
// Then
|
|
178
|
+
expect(result.success).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { z } from 'astro/zod';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import type { ResolvedCapabilityGraph } from '../graph.js';
|
|
4
|
+
import { resolveCapabilityGraph } from '../graph.js';
|
|
5
|
+
import { serializeCapabilityGraphMermaid } from '../mermaid.js';
|
|
6
|
+
import { serializeCapabilityGraphJson, toCapabilityGraphDocument } from '../serialize.js';
|
|
7
|
+
import type { RecipeMetadata, RecipeOutputContribution } from '../types.js';
|
|
8
|
+
|
|
9
|
+
type RecipeFixtureOptions = {
|
|
10
|
+
readonly provides?: readonly string[];
|
|
11
|
+
readonly requires?: readonly string[];
|
|
12
|
+
readonly priority?: number;
|
|
13
|
+
readonly contributions?: readonly RecipeOutputContribution[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function recipe(id: string, options: RecipeFixtureOptions = {}): RecipeMetadata {
|
|
17
|
+
return {
|
|
18
|
+
id,
|
|
19
|
+
version: '1.5.0',
|
|
20
|
+
protocolVersion: 1,
|
|
21
|
+
compatibleCliRange: '^0.1.0',
|
|
22
|
+
compatibleRuntimeRange: '^1.5.0',
|
|
23
|
+
provides: options.provides ?? [id],
|
|
24
|
+
requires: options.requires ?? [],
|
|
25
|
+
conflicts: [],
|
|
26
|
+
order: { priority: options.priority ?? 0, key: id },
|
|
27
|
+
optionsSchema: z.strictObject({}),
|
|
28
|
+
outputContributions: options.contributions ?? [],
|
|
29
|
+
validators: [],
|
|
30
|
+
generate: vi.fn(() => ({ files: [] })),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fixtures = [
|
|
35
|
+
recipe('shell', {
|
|
36
|
+
priority: 10,
|
|
37
|
+
contributions: [
|
|
38
|
+
{ kind: 'route', id: 'page.contact', target: '/contact/' },
|
|
39
|
+
{ kind: 'file', id: 'shell.layout', target: 'src/layouts/Base.astro' },
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
42
|
+
recipe('article', {
|
|
43
|
+
provides: ['content.article'],
|
|
44
|
+
requires: ['shell'],
|
|
45
|
+
contributions: [{ kind: 'content', id: 'content.article', target: 'primary' }],
|
|
46
|
+
}),
|
|
47
|
+
recipe('gallery', {
|
|
48
|
+
provides: ['content.gallery'],
|
|
49
|
+
requires: ['content.article'],
|
|
50
|
+
contributions: [{ kind: 'content', id: 'content.gallery', target: 'additional' }],
|
|
51
|
+
}),
|
|
52
|
+
recipe('navigation', {
|
|
53
|
+
contributions: [{ kind: 'binding', id: 'binding.navigation', target: 'page.contact' }],
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
function serializeRecipes(recipes: readonly RecipeMetadata[]): string {
|
|
58
|
+
const graph = resolveCapabilityGraph(recipes);
|
|
59
|
+
expect(graph.ok).toBe(true);
|
|
60
|
+
if (!graph.ok) throw new Error(graph.error.code);
|
|
61
|
+
const document = toCapabilityGraphDocument(graph.value);
|
|
62
|
+
expect(document.ok).toBe(true);
|
|
63
|
+
if (!document.ok) throw new Error(document.error.code);
|
|
64
|
+
return serializeCapabilityGraphJson(document.value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function minimalGraph(target: string): ResolvedCapabilityGraph {
|
|
68
|
+
return {
|
|
69
|
+
recipes: [],
|
|
70
|
+
capabilities: [],
|
|
71
|
+
requirements: [],
|
|
72
|
+
contributions: [{
|
|
73
|
+
kind: 'route', id: 'page.contact', target,
|
|
74
|
+
provenance: { contributedBy: 'shell', recipeVersion: '1.5.0', inclusion: { kind: 'direct' } },
|
|
75
|
+
}],
|
|
76
|
+
fixedPages: [],
|
|
77
|
+
contentTypes: { additional: [] },
|
|
78
|
+
adaptations: [],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
describe('capability graph serialization', () => {
|
|
83
|
+
it('projects a resolved graph into the versioned JSON document shape', () => {
|
|
84
|
+
const parsed = JSON.parse(serializeRecipes(fixtures)) as Record<string, unknown>;
|
|
85
|
+
|
|
86
|
+
expect(Object.keys(parsed)).toEqual([
|
|
87
|
+
'schemaVersion', 'recipes', 'capabilities', 'requirements',
|
|
88
|
+
'contentTypes', 'fixedPages', 'bindings', 'adaptations',
|
|
89
|
+
]);
|
|
90
|
+
expect(parsed.schemaVersion).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('produces byte-identical JSON for shuffled recipe inputs', () => {
|
|
94
|
+
const permutations = [fixtures, [...fixtures].reverse(), [fixtures[2]!, fixtures[0]!, fixtures[3]!, fixtures[1]!]];
|
|
95
|
+
|
|
96
|
+
const serialized = permutations.map(serializeRecipes);
|
|
97
|
+
|
|
98
|
+
expect(serialized[1]).toBe(serialized[0]);
|
|
99
|
+
expect(serialized[2]).toBe(serialized[0]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('serializes the document as a Mermaid flowchart', () => {
|
|
103
|
+
const graph = resolveCapabilityGraph(fixtures);
|
|
104
|
+
expect(graph.ok).toBe(true);
|
|
105
|
+
if (!graph.ok) return;
|
|
106
|
+
const document = toCapabilityGraphDocument(graph.value);
|
|
107
|
+
expect(document.ok).toBe(true);
|
|
108
|
+
if (!document.ok) return;
|
|
109
|
+
|
|
110
|
+
const mermaid = serializeCapabilityGraphMermaid(document.value);
|
|
111
|
+
|
|
112
|
+
expect(mermaid.startsWith('flowchart TD')).toBe(true);
|
|
113
|
+
expect(mermaid).toContain('-->');
|
|
114
|
+
for (const fixture of fixtures) expect(mermaid).toContain(fixture.id);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('rejects a graph document containing a private value', () => {
|
|
118
|
+
const result = toCapabilityGraphDocument(minimalGraph('someone@example.com'));
|
|
119
|
+
|
|
120
|
+
expect(result).toMatchObject({ ok: false, error: { code: 'private-value-detected' } });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('accepts an ordinary route target', () => {
|
|
124
|
+
const result = toCapabilityGraphDocument(minimalGraph('/contact/'));
|
|
125
|
+
|
|
126
|
+
expect(result.ok).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import corePackage from '../../../package.json' with { type: 'json' };
|
|
3
|
+
import { buildShellFiles, shellRecipe } from '../shell-recipe.js';
|
|
4
|
+
|
|
5
|
+
const CONTRIBUTION_FILE_PATH: Record<string, string> = {
|
|
6
|
+
'shell.astro-config': 'astro.config.mjs',
|
|
7
|
+
'shell.dependencies': 'package.json',
|
|
8
|
+
'shell.pnpm-workspace': 'pnpm-workspace.yaml',
|
|
9
|
+
'shell.base-layout': 'src/layouts/Base.astro',
|
|
10
|
+
'shell.home': 'src/pages/index.astro',
|
|
11
|
+
'shell.404': 'src/pages/404.astro',
|
|
12
|
+
'shell.localized-paths': 'src/lib/localized-paths.ts',
|
|
13
|
+
'shell.robots': 'public/robots.txt',
|
|
14
|
+
'shell.gitignore': '.gitignore',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('shell recipe', () => {
|
|
18
|
+
it('generates a file for every declared contribution', () => {
|
|
19
|
+
const files = buildShellFiles({});
|
|
20
|
+
const filePaths = new Set(files.map((file) => file.path));
|
|
21
|
+
|
|
22
|
+
for (const contribution of shellRecipe.outputContributions) {
|
|
23
|
+
const expectedPath = CONTRIBUTION_FILE_PATH[contribution.id];
|
|
24
|
+
expect(expectedPath, `missing file-path mapping for ${contribution.id}`).toBeDefined();
|
|
25
|
+
expect(filePaths.has(expectedPath!), `missing generated file for ${contribution.id} at ${expectedPath}`).toBe(true);
|
|
26
|
+
}
|
|
27
|
+
expect(files.length).toBe(shellRecipe.outputContributions.length);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('wires the SEO integration into astro.config.mjs', () => {
|
|
31
|
+
const files = buildShellFiles({});
|
|
32
|
+
const config = files.find((file) => file.path === 'astro.config.mjs')!;
|
|
33
|
+
expect(config.content).toContain('easyWebSeo');
|
|
34
|
+
expect(config.content).toContain('replace-with-your-domain.example');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('sets noIndex true in config when the option is enabled', () => {
|
|
38
|
+
const files = buildShellFiles({ noIndex: true });
|
|
39
|
+
const config = files.find((file) => file.path === 'astro.config.mjs')!;
|
|
40
|
+
expect(config.content).toContain('noIndex: true');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('never emits a real domain', () => {
|
|
44
|
+
const files = buildShellFiles({});
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
expect(file.content).not.toMatch(/ismaili\.de|harleyrentflorida|party200|tv-1927/);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('gitignores node_modules', () => {
|
|
51
|
+
const files = buildShellFiles({});
|
|
52
|
+
const gitignore = files.find((file) => file.path === '.gitignore')!;
|
|
53
|
+
expect(gitignore.content).toContain('node_modules');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('keeps the generated Astro range inside the core peer range', () => {
|
|
57
|
+
const files = buildShellFiles({});
|
|
58
|
+
const manifestFile = files.find((file) => file.path === 'package.json')!;
|
|
59
|
+
const manifest = JSON.parse(manifestFile.content) as { dependencies: { astro: string } };
|
|
60
|
+
const generatedMinimum = Number(/^\^(\d+)\./.exec(manifest.dependencies.astro)?.[1]);
|
|
61
|
+
const peerBounds = /^>=(\d+)\.0\.0 <(\d+)\.0\.0$/.exec(corePackage.peerDependencies.astro);
|
|
62
|
+
|
|
63
|
+
expect(peerBounds, 'core Astro peer range must retain explicit major bounds').not.toBeNull();
|
|
64
|
+
expect(generatedMinimum).toBeGreaterThanOrEqual(Number(peerBounds![1]));
|
|
65
|
+
expect(generatedMinimum).toBeLessThan(Number(peerBounds![2]));
|
|
66
|
+
expect(manifest.dependencies.astro).toBe('^7.3.5');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('allows required dependency builds under pnpm 11', () => {
|
|
70
|
+
const files = buildShellFiles({});
|
|
71
|
+
const workspace = files.find((file) => file.path === 'pnpm-workspace.yaml')!;
|
|
72
|
+
|
|
73
|
+
expect(workspace.content).toBe('allowBuilds:\n esbuild: true\n sharp: true\n');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'astro/zod';
|
|
2
|
+
import { recipeArtifactReceiptSchema, recipeRegistryManifestSchema } from './registry.js';
|
|
3
|
+
import { recipeMetadataSchema } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface RecipeCompatibilityPolicy {
|
|
6
|
+
readonly cliVersion: string;
|
|
7
|
+
readonly runtimeVersion: string;
|
|
8
|
+
/** Return false for invalid semver ranges as well as out-of-range versions. */
|
|
9
|
+
readonly satisfies: (version: string, range: string) => boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const recipeAdmissionInputSchema = z.strictObject({
|
|
13
|
+
registry: recipeRegistryManifestSchema,
|
|
14
|
+
artifacts: z.array(z.strictObject({
|
|
15
|
+
receipt: recipeArtifactReceiptSchema,
|
|
16
|
+
recipe: recipeMetadataSchema,
|
|
17
|
+
}).readonly()).readonly(),
|
|
18
|
+
}).readonly();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pure admission only: checks an explicitly selected set, never selects dependencies,
|
|
22
|
+
* sorts recipes, emits a capability graph, imports sources or invokes any hook.
|
|
23
|
+
* Receipts cannot prove byte integrity: the trusted loader must hash BEFORE import.
|
|
24
|
+
*/
|
|
25
|
+
export function createRecipeAdmissionSchema(policy: RecipeCompatibilityPolicy) {
|
|
26
|
+
return recipeAdmissionInputSchema.superRefine(({ registry, artifacts }, context) => {
|
|
27
|
+
const fail = (message: string, index: number) => context.addIssue({
|
|
28
|
+
code: 'custom', message, path: ['artifacts', index],
|
|
29
|
+
});
|
|
30
|
+
const providers = new Map<string, number>();
|
|
31
|
+
const ids = new Set<string>();
|
|
32
|
+
for (const [index, { recipe, receipt }] of artifacts.entries()) {
|
|
33
|
+
const pinned = registry.recipes.some((pin) =>
|
|
34
|
+
pin.packageName === receipt.pin.packageName && pin.version === receipt.pin.version &&
|
|
35
|
+
pin.integrity === receipt.pin.integrity && pin.exportPath === receipt.pin.exportPath);
|
|
36
|
+
if (!pinned) fail('source-outside-pinned-set', index);
|
|
37
|
+
if (receipt.verifiedIntegrity !== receipt.pin.integrity) fail('artifact-integrity-mismatch', index);
|
|
38
|
+
if (recipe.version !== receipt.pin.version) fail('recipe-version-mismatch', index);
|
|
39
|
+
if (!policy.satisfies(policy.cliVersion, recipe.compatibleCliRange)) fail('incompatible-cli-range', index);
|
|
40
|
+
if (!policy.satisfies(policy.runtimeVersion, recipe.compatibleRuntimeRange)) fail('incompatible-runtime-range', index);
|
|
41
|
+
if (ids.has(recipe.id)) fail('duplicate-recipe-id', index);
|
|
42
|
+
ids.add(recipe.id);
|
|
43
|
+
for (const capability of recipe.provides) {
|
|
44
|
+
if (providers.has(capability)) fail('duplicate-provider-id', index);
|
|
45
|
+
providers.set(capability, index);
|
|
46
|
+
}
|
|
47
|
+
for (const field of ['requires', 'conflicts'] as const) {
|
|
48
|
+
if (new Set(recipe[field]).size !== recipe[field].length) fail(`duplicate-${field}`, index);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const [index, { recipe }] of artifacts.entries()) {
|
|
52
|
+
for (const requirement of recipe.requires) {
|
|
53
|
+
if (!providers.has(requirement)) fail('missing-requirement', index);
|
|
54
|
+
}
|
|
55
|
+
for (const conflict of recipe.conflicts) {
|
|
56
|
+
if (providers.has(conflict)) fail('conflicting-capability', index);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Reachability validation, not topological ordering or a graph resolver.
|
|
60
|
+
const complete = new Set<number>();
|
|
61
|
+
const active = new Set<number>();
|
|
62
|
+
const visit = (index: number): void => {
|
|
63
|
+
if (active.has(index)) { fail('dependency-cycle', index); return; }
|
|
64
|
+
if (complete.has(index)) return;
|
|
65
|
+
const artifact = artifacts[index];
|
|
66
|
+
if (!artifact) return;
|
|
67
|
+
active.add(index);
|
|
68
|
+
for (const requirement of artifact.recipe.requires) {
|
|
69
|
+
const provider = providers.get(requirement);
|
|
70
|
+
if (provider !== undefined) visit(provider);
|
|
71
|
+
}
|
|
72
|
+
active.delete(index);
|
|
73
|
+
complete.add(index);
|
|
74
|
+
};
|
|
75
|
+
for (const index of artifacts.keys()) visit(index);
|
|
76
|
+
});
|
|
77
|
+
}
|