@enactprotocol/shared 1.2.13 → 2.0.1
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 +44 -0
- package/dist/config.d.ts +164 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +386 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +15 -5
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -8
- package/dist/constants.js.map +1 -0
- package/dist/execution/command.d.ts +102 -0
- package/dist/execution/command.d.ts.map +1 -0
- package/dist/execution/command.js +262 -0
- package/dist/execution/command.js.map +1 -0
- package/dist/execution/index.d.ts +12 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +17 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/runtime.d.ts +82 -0
- package/dist/execution/runtime.d.ts.map +1 -0
- package/dist/execution/runtime.js +273 -0
- package/dist/execution/runtime.js.map +1 -0
- package/dist/execution/types.d.ts +306 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +14 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/validation.d.ts +43 -0
- package/dist/execution/validation.d.ts.map +1 -0
- package/dist/execution/validation.js +430 -0
- package/dist/execution/validation.js.map +1 -0
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -25
- package/dist/index.js.map +1 -0
- package/dist/manifest/index.d.ts +7 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +10 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/loader.d.ts +76 -0
- package/dist/manifest/loader.d.ts.map +1 -0
- package/dist/manifest/loader.js +146 -0
- package/dist/manifest/loader.js.map +1 -0
- package/dist/manifest/parser.d.ts +64 -0
- package/dist/manifest/parser.d.ts.map +1 -0
- package/dist/manifest/parser.js +135 -0
- package/dist/manifest/parser.js.map +1 -0
- package/dist/manifest/validator.d.ts +95 -0
- package/dist/manifest/validator.d.ts.map +1 -0
- package/dist/manifest/validator.js +258 -0
- package/dist/manifest/validator.js.map +1 -0
- package/dist/paths.d.ts +57 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +93 -0
- package/dist/paths.js.map +1 -0
- package/dist/registry.d.ts +73 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +147 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolver.d.ts +89 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +282 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/manifest.d.ts +201 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/manifest.js +13 -0
- package/dist/types/manifest.js.map +1 -0
- package/dist/types.d.ts +5 -132
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -3
- package/dist/types.js.map +1 -0
- package/dist/utils/fs.d.ts +105 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +233 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +102 -25
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +214 -57
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/version.d.ts +60 -2
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +255 -31
- package/dist/utils/version.js.map +1 -0
- package/package.json +16 -58
- package/src/config.ts +510 -0
- package/src/constants.ts +36 -0
- package/src/execution/command.ts +314 -0
- package/src/execution/index.ts +73 -0
- package/src/execution/runtime.ts +308 -0
- package/src/execution/types.ts +379 -0
- package/src/execution/validation.ts +508 -0
- package/src/index.ts +238 -30
- package/src/manifest/index.ts +36 -0
- package/src/manifest/loader.ts +187 -0
- package/src/manifest/parser.ts +173 -0
- package/src/manifest/validator.ts +309 -0
- package/src/paths.ts +108 -0
- package/src/registry.ts +219 -0
- package/src/resolver.ts +345 -0
- package/src/types/index.ts +30 -0
- package/src/types/manifest.ts +255 -0
- package/src/types.ts +5 -188
- package/src/utils/fs.ts +281 -0
- package/src/utils/logger.ts +270 -59
- package/src/utils/version.ts +304 -36
- package/tests/config.test.ts +515 -0
- package/tests/execution/command.test.ts +317 -0
- package/tests/execution/validation.test.ts +384 -0
- package/tests/fixtures/invalid-tool.yaml +4 -0
- package/tests/fixtures/valid-tool.md +62 -0
- package/tests/fixtures/valid-tool.yaml +40 -0
- package/tests/index.test.ts +8 -0
- package/tests/manifest/loader.test.ts +291 -0
- package/tests/manifest/parser.test.ts +345 -0
- package/tests/manifest/validator.test.ts +394 -0
- package/tests/manifest-types.test.ts +358 -0
- package/tests/paths.test.ts +153 -0
- package/tests/registry.test.ts +231 -0
- package/tests/resolver.test.ts +272 -0
- package/tests/utils/fs.test.ts +388 -0
- package/tests/utils/logger.test.ts +480 -0
- package/tests/utils/version.test.ts +390 -0
- package/tsconfig.json +12 -0
- package/dist/LocalToolResolver.d.ts +0 -84
- package/dist/LocalToolResolver.js +0 -353
- package/dist/api/enact-api.d.ts +0 -130
- package/dist/api/enact-api.js +0 -428
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.js +0 -2
- package/dist/api/types.d.ts +0 -103
- package/dist/api/types.js +0 -1
- package/dist/core/DaggerExecutionProvider.d.ts +0 -169
- package/dist/core/DaggerExecutionProvider.js +0 -1029
- package/dist/core/DirectExecutionProvider.d.ts +0 -23
- package/dist/core/DirectExecutionProvider.js +0 -406
- package/dist/core/EnactCore.d.ts +0 -162
- package/dist/core/EnactCore.js +0 -597
- package/dist/core/NativeExecutionProvider.d.ts +0 -9
- package/dist/core/NativeExecutionProvider.js +0 -16
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -3
- package/dist/exec/index.d.ts +0 -3
- package/dist/exec/index.js +0 -3
- package/dist/exec/logger.d.ts +0 -11
- package/dist/exec/logger.js +0 -57
- package/dist/exec/validate.d.ts +0 -5
- package/dist/exec/validate.js +0 -167
- package/dist/lib/enact-direct.d.ts +0 -150
- package/dist/lib/enact-direct.js +0 -159
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/index.js +0 -1
- package/dist/security/index.d.ts +0 -3
- package/dist/security/index.js +0 -3
- package/dist/security/security.d.ts +0 -23
- package/dist/security/security.js +0 -137
- package/dist/security/sign.d.ts +0 -103
- package/dist/security/sign.js +0 -666
- package/dist/security/verification-enforcer.d.ts +0 -53
- package/dist/security/verification-enforcer.js +0 -204
- package/dist/services/McpCoreService.d.ts +0 -98
- package/dist/services/McpCoreService.js +0 -124
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/utils/config.d.ts +0 -111
- package/dist/utils/config.js +0 -342
- package/dist/utils/env-loader.d.ts +0 -54
- package/dist/utils/env-loader.js +0 -270
- package/dist/utils/help.d.ts +0 -36
- package/dist/utils/help.js +0 -248
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/index.js +0 -7
- package/dist/utils/silent-monitor.d.ts +0 -67
- package/dist/utils/silent-monitor.js +0 -242
- package/dist/utils/timeout.d.ts +0 -5
- package/dist/utils/timeout.js +0 -23
- package/dist/web/env-manager-server.d.ts +0 -29
- package/dist/web/env-manager-server.js +0 -367
- package/dist/web/index.d.ts +0 -1
- package/dist/web/index.js +0 -1
- package/src/LocalToolResolver.ts +0 -424
- package/src/api/enact-api.ts +0 -604
- package/src/api/index.ts +0 -2
- package/src/api/types.ts +0 -114
- package/src/core/DaggerExecutionProvider.ts +0 -1357
- package/src/core/DirectExecutionProvider.ts +0 -484
- package/src/core/EnactCore.ts +0 -847
- package/src/core/index.ts +0 -3
- package/src/exec/index.ts +0 -3
- package/src/exec/logger.ts +0 -63
- package/src/exec/validate.ts +0 -238
- package/src/lib/enact-direct.ts +0 -254
- package/src/lib/index.ts +0 -1
- package/src/services/McpCoreService.ts +0 -201
- package/src/services/index.ts +0 -1
- package/src/utils/config.ts +0 -438
- package/src/utils/env-loader.ts +0 -370
- package/src/utils/help.ts +0 -257
- package/src/utils/index.ts +0 -7
- package/src/utils/silent-monitor.ts +0 -328
- package/src/utils/timeout.ts +0 -26
- package/src/web/env-manager-server.ts +0 -465
- package/src/web/index.ts +0 -1
- package/src/web/static/app.js +0 -663
- package/src/web/static/index.html +0 -117
- package/src/web/static/style.css +0 -291
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
ManifestParseError,
|
|
4
|
+
detectFormat,
|
|
5
|
+
extractFrontmatter,
|
|
6
|
+
parseManifest,
|
|
7
|
+
parseManifestAuto,
|
|
8
|
+
parseYaml,
|
|
9
|
+
} from "../../src/manifest/parser";
|
|
10
|
+
|
|
11
|
+
describe("manifest parser", () => {
|
|
12
|
+
describe("parseYaml", () => {
|
|
13
|
+
test("parses valid YAML object", () => {
|
|
14
|
+
const yaml = `
|
|
15
|
+
name: org/tool
|
|
16
|
+
description: A test tool
|
|
17
|
+
version: "1.0.0"
|
|
18
|
+
`;
|
|
19
|
+
const result = parseYaml(yaml);
|
|
20
|
+
expect(result.name).toBe("org/tool");
|
|
21
|
+
expect(result.description).toBe("A test tool");
|
|
22
|
+
expect(result.version).toBe("1.0.0");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("parses nested YAML", () => {
|
|
26
|
+
const yaml = `
|
|
27
|
+
name: org/tool
|
|
28
|
+
inputSchema:
|
|
29
|
+
type: object
|
|
30
|
+
properties:
|
|
31
|
+
name:
|
|
32
|
+
type: string
|
|
33
|
+
`;
|
|
34
|
+
const result = parseYaml(yaml);
|
|
35
|
+
expect(result.inputSchema).toBeDefined();
|
|
36
|
+
const schema = result.inputSchema as Record<string, unknown>;
|
|
37
|
+
expect(schema.type).toBe("object");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("parses arrays in YAML", () => {
|
|
41
|
+
const yaml = `
|
|
42
|
+
tags:
|
|
43
|
+
- text
|
|
44
|
+
- analysis
|
|
45
|
+
- nlp
|
|
46
|
+
`;
|
|
47
|
+
const result = parseYaml(yaml);
|
|
48
|
+
expect(result.tags).toEqual(["text", "analysis", "nlp"]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("throws ManifestParseError on invalid YAML", () => {
|
|
52
|
+
const invalidYaml = `
|
|
53
|
+
name: [unclosed bracket
|
|
54
|
+
`;
|
|
55
|
+
expect(() => parseYaml(invalidYaml)).toThrow(ManifestParseError);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("throws ManifestParseError on empty content", () => {
|
|
59
|
+
expect(() => parseYaml("")).toThrow(ManifestParseError);
|
|
60
|
+
expect(() => parseYaml(" \n \n ")).toThrow(ManifestParseError);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("throws ManifestParseError on null YAML", () => {
|
|
64
|
+
expect(() => parseYaml("null")).toThrow(ManifestParseError);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("throws ManifestParseError on array YAML", () => {
|
|
68
|
+
const arrayYaml = `
|
|
69
|
+
- item1
|
|
70
|
+
- item2
|
|
71
|
+
`;
|
|
72
|
+
expect(() => parseYaml(arrayYaml)).toThrow(ManifestParseError);
|
|
73
|
+
expect(() => parseYaml(arrayYaml)).toThrow("must be an object");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("throws ManifestParseError on primitive YAML", () => {
|
|
77
|
+
expect(() => parseYaml("just a string")).toThrow(ManifestParseError);
|
|
78
|
+
expect(() => parseYaml("42")).toThrow(ManifestParseError);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("extractFrontmatter", () => {
|
|
83
|
+
test("extracts frontmatter and body from valid markdown", () => {
|
|
84
|
+
const content = `---
|
|
85
|
+
name: org/tool
|
|
86
|
+
description: Test
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
# Tool Documentation
|
|
90
|
+
|
|
91
|
+
This is the body.
|
|
92
|
+
`;
|
|
93
|
+
const result = extractFrontmatter(content);
|
|
94
|
+
expect(result).not.toBeNull();
|
|
95
|
+
expect(result?.frontmatter).toContain("name: org/tool");
|
|
96
|
+
expect(result?.body).toContain("# Tool Documentation");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("handles empty body", () => {
|
|
100
|
+
const content = `---
|
|
101
|
+
name: org/tool
|
|
102
|
+
---
|
|
103
|
+
`;
|
|
104
|
+
const result = extractFrontmatter(content);
|
|
105
|
+
expect(result).not.toBeNull();
|
|
106
|
+
expect(result?.frontmatter).toBe("name: org/tool");
|
|
107
|
+
expect(result?.body).toBe("");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("handles multiline frontmatter", () => {
|
|
111
|
+
const content = `---
|
|
112
|
+
name: org/tool
|
|
113
|
+
description: >
|
|
114
|
+
A very long description
|
|
115
|
+
that spans multiple lines
|
|
116
|
+
tags:
|
|
117
|
+
- one
|
|
118
|
+
- two
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
Body content here.
|
|
122
|
+
`;
|
|
123
|
+
const result = extractFrontmatter(content);
|
|
124
|
+
expect(result).not.toBeNull();
|
|
125
|
+
expect(result?.frontmatter).toContain("name: org/tool");
|
|
126
|
+
expect(result?.frontmatter).toContain("tags:");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("returns null for missing frontmatter", () => {
|
|
130
|
+
const content = `# Just Markdown
|
|
131
|
+
|
|
132
|
+
No frontmatter here.
|
|
133
|
+
`;
|
|
134
|
+
const result = extractFrontmatter(content);
|
|
135
|
+
expect(result).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("returns null for unclosed frontmatter", () => {
|
|
139
|
+
const content = `---
|
|
140
|
+
name: org/tool
|
|
141
|
+
description: No closing delimiter
|
|
142
|
+
`;
|
|
143
|
+
const result = extractFrontmatter(content);
|
|
144
|
+
expect(result).toBeNull();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("handles Windows line endings (CRLF)", () => {
|
|
148
|
+
const content = "---\r\nname: org/tool\r\n---\r\n\r\nBody here.";
|
|
149
|
+
const result = extractFrontmatter(content);
|
|
150
|
+
expect(result).not.toBeNull();
|
|
151
|
+
expect(result?.frontmatter).toBe("name: org/tool");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("parseManifest", () => {
|
|
156
|
+
describe("YAML format", () => {
|
|
157
|
+
test("parses valid YAML manifest", () => {
|
|
158
|
+
const yaml = `
|
|
159
|
+
name: org/tool
|
|
160
|
+
description: A test tool
|
|
161
|
+
`;
|
|
162
|
+
const result = parseManifest(yaml, "yaml");
|
|
163
|
+
expect(result.manifest.name).toBe("org/tool");
|
|
164
|
+
expect(result.manifest.description).toBe("A test tool");
|
|
165
|
+
expect(result.format).toBe("yaml");
|
|
166
|
+
expect(result.body).toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("parses complete YAML manifest", () => {
|
|
170
|
+
const yaml = `
|
|
171
|
+
enact: "2.0.0"
|
|
172
|
+
name: acme/utils/greeter
|
|
173
|
+
description: Greets users
|
|
174
|
+
version: "1.0.0"
|
|
175
|
+
from: node:18-alpine
|
|
176
|
+
command: "echo 'Hello \${name}'"
|
|
177
|
+
timeout: 30s
|
|
178
|
+
license: MIT
|
|
179
|
+
tags:
|
|
180
|
+
- greeting
|
|
181
|
+
- utility
|
|
182
|
+
inputSchema:
|
|
183
|
+
type: object
|
|
184
|
+
properties:
|
|
185
|
+
name:
|
|
186
|
+
type: string
|
|
187
|
+
required:
|
|
188
|
+
- name
|
|
189
|
+
`;
|
|
190
|
+
const result = parseManifest(yaml, "yaml");
|
|
191
|
+
expect(result.manifest.enact).toBe("2.0.0");
|
|
192
|
+
expect(result.manifest.name).toBe("acme/utils/greeter");
|
|
193
|
+
expect(result.manifest.from).toBe("node:18-alpine");
|
|
194
|
+
expect(result.manifest.tags).toContain("greeting");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("throws on empty YAML", () => {
|
|
198
|
+
expect(() => parseManifest("", "yaml")).toThrow(ManifestParseError);
|
|
199
|
+
expect(() => parseManifest("", "yaml")).toThrow("empty");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("throws on invalid YAML", () => {
|
|
203
|
+
const invalidYaml = "name: [\nunbalanced";
|
|
204
|
+
expect(() => parseManifest(invalidYaml, "yaml")).toThrow(ManifestParseError);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("Markdown format", () => {
|
|
209
|
+
test("parses valid markdown with frontmatter", () => {
|
|
210
|
+
const md = `---
|
|
211
|
+
name: org/tool
|
|
212
|
+
description: A test tool
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
# Tool Name
|
|
216
|
+
|
|
217
|
+
Documentation here.
|
|
218
|
+
`;
|
|
219
|
+
const result = parseManifest(md, "md");
|
|
220
|
+
expect(result.manifest.name).toBe("org/tool");
|
|
221
|
+
expect(result.format).toBe("md");
|
|
222
|
+
expect(result.body).toContain("# Tool Name");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("parses markdown with empty body", () => {
|
|
226
|
+
const md = `---
|
|
227
|
+
name: org/tool
|
|
228
|
+
description: Test
|
|
229
|
+
---
|
|
230
|
+
`;
|
|
231
|
+
const result = parseManifest(md, "md");
|
|
232
|
+
expect(result.manifest.name).toBe("org/tool");
|
|
233
|
+
expect(result.body).toBeUndefined(); // Empty string becomes undefined
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("throws on missing frontmatter", () => {
|
|
237
|
+
const md = `# Just Markdown
|
|
238
|
+
|
|
239
|
+
No frontmatter here.
|
|
240
|
+
`;
|
|
241
|
+
expect(() => parseManifest(md, "md")).toThrow(ManifestParseError);
|
|
242
|
+
expect(() => parseManifest(md, "md")).toThrow("frontmatter");
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("throws on empty frontmatter", () => {
|
|
246
|
+
const md = `---
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
Body only.
|
|
250
|
+
`;
|
|
251
|
+
expect(() => parseManifest(md, "md")).toThrow(ManifestParseError);
|
|
252
|
+
expect(() => parseManifest(md, "md")).toThrow("frontmatter");
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("throws on invalid YAML in frontmatter", () => {
|
|
256
|
+
const md = `---
|
|
257
|
+
name: [unclosed
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
Body here.
|
|
261
|
+
`;
|
|
262
|
+
expect(() => parseManifest(md, "md")).toThrow(ManifestParseError);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe("detectFormat", () => {
|
|
268
|
+
test("detects .yaml extension", () => {
|
|
269
|
+
expect(detectFormat("enact.yaml")).toBe("yaml");
|
|
270
|
+
expect(detectFormat("tool.yaml")).toBe("yaml");
|
|
271
|
+
expect(detectFormat("/path/to/enact.yaml")).toBe("yaml");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("detects .yml extension", () => {
|
|
275
|
+
expect(detectFormat("enact.yml")).toBe("yaml");
|
|
276
|
+
expect(detectFormat("/path/to/tool.yml")).toBe("yaml");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("detects .md extension", () => {
|
|
280
|
+
expect(detectFormat("enact.md")).toBe("md");
|
|
281
|
+
expect(detectFormat("tool.md")).toBe("md");
|
|
282
|
+
expect(detectFormat("/path/to/enact.md")).toBe("md");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("is case insensitive", () => {
|
|
286
|
+
expect(detectFormat("enact.YAML")).toBe("yaml");
|
|
287
|
+
expect(detectFormat("enact.YML")).toBe("yaml");
|
|
288
|
+
expect(detectFormat("enact.MD")).toBe("md");
|
|
289
|
+
expect(detectFormat("enact.Md")).toBe("md");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("throws on unknown extension", () => {
|
|
293
|
+
expect(() => detectFormat("enact.txt")).toThrow(ManifestParseError);
|
|
294
|
+
expect(() => detectFormat("enact.json")).toThrow(ManifestParseError);
|
|
295
|
+
expect(() => detectFormat("enact")).toThrow(ManifestParseError);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("parseManifestAuto", () => {
|
|
300
|
+
test("parses YAML file automatically", () => {
|
|
301
|
+
const yaml = `
|
|
302
|
+
name: org/tool
|
|
303
|
+
description: Test
|
|
304
|
+
`;
|
|
305
|
+
const result = parseManifestAuto(yaml, "enact.yaml");
|
|
306
|
+
expect(result.manifest.name).toBe("org/tool");
|
|
307
|
+
expect(result.format).toBe("yaml");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("parses Markdown file automatically", () => {
|
|
311
|
+
const md = `---
|
|
312
|
+
name: org/tool
|
|
313
|
+
description: Test
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
# Docs
|
|
317
|
+
`;
|
|
318
|
+
const result = parseManifestAuto(md, "enact.md");
|
|
319
|
+
expect(result.manifest.name).toBe("org/tool");
|
|
320
|
+
expect(result.format).toBe("md");
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("throws on unknown file type", () => {
|
|
324
|
+
expect(() => parseManifestAuto("content", "file.txt")).toThrow(ManifestParseError);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe("ManifestParseError", () => {
|
|
329
|
+
test("has correct name", () => {
|
|
330
|
+
const error = new ManifestParseError("test error");
|
|
331
|
+
expect(error.name).toBe("ManifestParseError");
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test("preserves original error", () => {
|
|
335
|
+
const original = new Error("original");
|
|
336
|
+
const error = new ManifestParseError("wrapped", original);
|
|
337
|
+
expect(error.originalError).toBe(original);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("message is preserved", () => {
|
|
341
|
+
const error = new ManifestParseError("custom message");
|
|
342
|
+
expect(error.message).toBe("custom message");
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
});
|