@glassly/miniapp-cli 0.1.0-beta.3
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 +248 -0
- package/package.json +49 -0
- package/schema/miniapp.schema.json +269 -0
- package/src/api.ts +10 -0
- package/src/build-helpers.test.ts +104 -0
- package/src/build-helpers.ts +357 -0
- package/src/build.ts +67 -0
- package/src/dev-server.test.ts +138 -0
- package/src/dev-server.ts +454 -0
- package/src/dev.ts +348 -0
- package/src/hardware.ts +163 -0
- package/src/lan.test.ts +84 -0
- package/src/lan.ts +161 -0
- package/src/manifest-format.ts +121 -0
- package/src/manifest-mutate.test.ts +191 -0
- package/src/manifest-mutate.ts +213 -0
- package/src/manifest-wizard.ts +218 -0
- package/src/manifest.test.ts +376 -0
- package/src/manifest.ts +412 -0
- package/src/pack.ts +131 -0
- package/src/permission-hints.ts +40 -0
- package/src/permission.ts +142 -0
- package/src/qr.test.ts +81 -0
- package/src/qr.ts +119 -0
- package/src/regenerate-schema.ts +6 -0
- package/src/release.ts +265 -0
- package/src/schema.test.ts +64 -0
- package/src/schema.ts +258 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// `glassly manifest` — interactive top-level wizard.
|
|
2
|
+
//
|
|
3
|
+
// Uses the same mutation backend as the object-verb subcommands, so behavior
|
|
4
|
+
// is identical. Loop-driven: read manifest, prompt for an action, mutate,
|
|
5
|
+
// persist, loop.
|
|
6
|
+
|
|
7
|
+
import * as p from "@clack/prompts"
|
|
8
|
+
import {ALLOWED_HARDWARE_LEVELS, ALLOWED_HARDWARE_TYPES, ALLOWED_PERMISSIONS} from "./manifest.js"
|
|
9
|
+
import {
|
|
10
|
+
addHardware,
|
|
11
|
+
addPermission,
|
|
12
|
+
listHardware,
|
|
13
|
+
listPermissions,
|
|
14
|
+
Manifest,
|
|
15
|
+
MutateError,
|
|
16
|
+
removeHardware,
|
|
17
|
+
removePermission,
|
|
18
|
+
} from "./manifest-mutate.js"
|
|
19
|
+
import {formatLoadError, formatWriteError, loadManifest, writeManifest} from "./manifest-format.js"
|
|
20
|
+
import {hardwareDescription, permissionDescription} from "./permission-hints.js"
|
|
21
|
+
|
|
22
|
+
export async function runManifestWizard(): Promise<void> {
|
|
23
|
+
p.intro("Glassly miniapp manifest editor")
|
|
24
|
+
|
|
25
|
+
const loaded = loadManifest(process.cwd())
|
|
26
|
+
if (!loaded.ok) {
|
|
27
|
+
p.cancel(formatLoadError(loaded.error))
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
let {path, manifest} = loaded.value
|
|
31
|
+
// Stage updates locally; persist after each mutation so Ctrl-C never loses
|
|
32
|
+
// a confirmed change. (Matches the spec's note: don't batch.)
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
let _initialPath = path
|
|
35
|
+
|
|
36
|
+
while (true) {
|
|
37
|
+
const action = await p.select({
|
|
38
|
+
message: "What would you like to do?",
|
|
39
|
+
options: [
|
|
40
|
+
{value: "permissions", label: "Edit permissions", hint: `${listPermissions(manifest).length} declared`},
|
|
41
|
+
{value: "hardware", label: "Edit hardware requirements", hint: `${listHardware(manifest).length} declared`},
|
|
42
|
+
{value: "show", label: "Show current manifest"},
|
|
43
|
+
{value: "done", label: "Done"},
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
if (p.isCancel(action) || action === "done") break
|
|
47
|
+
|
|
48
|
+
if (action === "show") {
|
|
49
|
+
p.note(JSON.stringify(manifest, null, 2), "miniapp.json")
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (action === "permissions") {
|
|
54
|
+
manifest = await editPermissions(manifest)
|
|
55
|
+
const w = writeManifest(path, manifest)
|
|
56
|
+
if (!w.ok) {
|
|
57
|
+
p.cancel(formatWriteError(w.error))
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (action === "hardware") {
|
|
64
|
+
manifest = await editHardware(manifest)
|
|
65
|
+
const w = writeManifest(path, manifest)
|
|
66
|
+
if (!w.ok) {
|
|
67
|
+
p.cancel(formatWriteError(w.error))
|
|
68
|
+
process.exit(1)
|
|
69
|
+
}
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
p.outro("Saved miniapp.json ✨")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function editPermissions(manifest: Manifest): Promise<Manifest> {
|
|
78
|
+
const sub = await p.select({
|
|
79
|
+
message: "Permissions",
|
|
80
|
+
options: [
|
|
81
|
+
{value: "add", label: "Add a permission"},
|
|
82
|
+
{value: "remove", label: "Remove a permission"},
|
|
83
|
+
{value: "back", label: "Back"},
|
|
84
|
+
],
|
|
85
|
+
})
|
|
86
|
+
if (p.isCancel(sub) || sub === "back") return manifest
|
|
87
|
+
|
|
88
|
+
if (sub === "add") {
|
|
89
|
+
const declared = new Set(listPermissions(manifest).map((perm) => perm.type))
|
|
90
|
+
const available = ALLOWED_PERMISSIONS.filter((perm) => !declared.has(perm))
|
|
91
|
+
if (available.length === 0) {
|
|
92
|
+
p.note("All permissions are already declared.", "Permissions")
|
|
93
|
+
return manifest
|
|
94
|
+
}
|
|
95
|
+
const picked = await p.multiselect({
|
|
96
|
+
message: "Which permission(s) to add?",
|
|
97
|
+
required: false,
|
|
98
|
+
options: available.map((perm) => ({value: perm, label: perm, hint: permissionDescription(perm)})),
|
|
99
|
+
})
|
|
100
|
+
if (p.isCancel(picked)) return manifest
|
|
101
|
+
let updated = manifest
|
|
102
|
+
for (const type of picked as readonly string[]) {
|
|
103
|
+
const desc = await p.text({
|
|
104
|
+
message: `Description for ${type} (optional):`,
|
|
105
|
+
placeholder: "(skip)",
|
|
106
|
+
})
|
|
107
|
+
if (p.isCancel(desc)) return updated
|
|
108
|
+
const opts = typeof desc === "string" && desc.trim() ? {description: desc.trim()} : undefined
|
|
109
|
+
try {
|
|
110
|
+
updated = addPermission(updated, type, opts)
|
|
111
|
+
} catch (e) {
|
|
112
|
+
if (e instanceof MutateError) {
|
|
113
|
+
p.note(e.message, "Skipped")
|
|
114
|
+
} else {
|
|
115
|
+
throw e
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return updated
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (sub === "remove") {
|
|
123
|
+
const declared = listPermissions(manifest)
|
|
124
|
+
if (declared.length === 0) {
|
|
125
|
+
p.note("No permissions to remove.", "Permissions")
|
|
126
|
+
return manifest
|
|
127
|
+
}
|
|
128
|
+
const picked = await p.select({
|
|
129
|
+
message: "Which permission to remove?",
|
|
130
|
+
options: declared.map((perm) => ({value: perm.type, label: perm.type})),
|
|
131
|
+
})
|
|
132
|
+
if (p.isCancel(picked)) return manifest
|
|
133
|
+
try {
|
|
134
|
+
return removePermission(manifest, picked as string)
|
|
135
|
+
} catch (e) {
|
|
136
|
+
if (e instanceof MutateError) {
|
|
137
|
+
p.note(e.message, "Skipped")
|
|
138
|
+
}
|
|
139
|
+
return manifest
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return manifest
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function editHardware(manifest: Manifest): Promise<Manifest> {
|
|
147
|
+
const sub = await p.select({
|
|
148
|
+
message: "Hardware requirements",
|
|
149
|
+
options: [
|
|
150
|
+
{value: "add", label: "Add a hardware requirement"},
|
|
151
|
+
{value: "remove", label: "Remove a hardware requirement"},
|
|
152
|
+
{value: "back", label: "Back"},
|
|
153
|
+
],
|
|
154
|
+
})
|
|
155
|
+
if (p.isCancel(sub) || sub === "back") return manifest
|
|
156
|
+
|
|
157
|
+
if (sub === "add") {
|
|
158
|
+
const declared = new Set(listHardware(manifest).map((h) => h.type))
|
|
159
|
+
const available = ALLOWED_HARDWARE_TYPES.filter((h) => !declared.has(h))
|
|
160
|
+
if (available.length === 0) {
|
|
161
|
+
p.note("All hardware types are already declared.", "Hardware")
|
|
162
|
+
return manifest
|
|
163
|
+
}
|
|
164
|
+
const type = await p.select({
|
|
165
|
+
message: "Which hardware?",
|
|
166
|
+
options: available.map((h) => ({value: h, label: h, hint: hardwareDescription(h)})),
|
|
167
|
+
})
|
|
168
|
+
if (p.isCancel(type)) return manifest
|
|
169
|
+
|
|
170
|
+
const level = await p.select({
|
|
171
|
+
message: "Required or optional?",
|
|
172
|
+
options: ALLOWED_HARDWARE_LEVELS.map((l) => ({
|
|
173
|
+
value: l,
|
|
174
|
+
label: l,
|
|
175
|
+
hint:
|
|
176
|
+
l === "REQUIRED"
|
|
177
|
+
? "Glasses without this hardware can't run the app"
|
|
178
|
+
: "Glasses without this hardware still run the app (degraded)",
|
|
179
|
+
})),
|
|
180
|
+
})
|
|
181
|
+
if (p.isCancel(level)) return manifest
|
|
182
|
+
|
|
183
|
+
const desc = await p.text({
|
|
184
|
+
message: "Description (optional):",
|
|
185
|
+
placeholder: "(skip)",
|
|
186
|
+
})
|
|
187
|
+
if (p.isCancel(desc)) return manifest
|
|
188
|
+
const opts = typeof desc === "string" && desc.trim() ? {description: desc.trim()} : undefined
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
return addHardware(manifest, type as string, level as string, opts)
|
|
192
|
+
} catch (e) {
|
|
193
|
+
if (e instanceof MutateError) p.note(e.message, "Skipped")
|
|
194
|
+
return manifest
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (sub === "remove") {
|
|
199
|
+
const declared = listHardware(manifest)
|
|
200
|
+
if (declared.length === 0) {
|
|
201
|
+
p.note("No hardware requirements to remove.", "Hardware")
|
|
202
|
+
return manifest
|
|
203
|
+
}
|
|
204
|
+
const picked = await p.select({
|
|
205
|
+
message: "Which hardware to remove?",
|
|
206
|
+
options: declared.map((h) => ({value: h.type, label: `${h.type} (${h.level})`})),
|
|
207
|
+
})
|
|
208
|
+
if (p.isCancel(picked)) return manifest
|
|
209
|
+
try {
|
|
210
|
+
return removeHardware(manifest, picked as string)
|
|
211
|
+
} catch (e) {
|
|
212
|
+
if (e instanceof MutateError) p.note(e.message, "Skipped")
|
|
213
|
+
return manifest
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return manifest
|
|
218
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import {describe, expect, test} from 'bun:test';
|
|
2
|
+
import {validateManifest} from './manifest';
|
|
3
|
+
|
|
4
|
+
const minimalValid = {
|
|
5
|
+
packageName: 'com.example.app',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
name: 'Example',
|
|
8
|
+
hardwareRequirements: [{type: 'DISPLAY', level: 'REQUIRED'}],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('validateManifest', () => {
|
|
12
|
+
test('accepts a minimal valid manifest', () => {
|
|
13
|
+
const {valid, errors} = validateManifest(minimalValid);
|
|
14
|
+
expect(valid).toBe(true);
|
|
15
|
+
expect(errors).toEqual([]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('rejects non-object input', () => {
|
|
19
|
+
expect(validateManifest(null).valid).toBe(false);
|
|
20
|
+
expect(validateManifest('not an object').valid).toBe(false);
|
|
21
|
+
expect(validateManifest(42).valid).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('required top-level fields', () => {
|
|
25
|
+
test('packageName must be a non-empty string', () => {
|
|
26
|
+
const {errors} = validateManifest({...minimalValid, packageName: ''});
|
|
27
|
+
expect(errors.some((e) => e.includes('packageName'))).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('version must be a non-empty string', () => {
|
|
31
|
+
const {errors} = validateManifest({...minimalValid, version: ''});
|
|
32
|
+
expect(errors.some((e) => e.includes('version'))).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('name must be a non-empty string', () => {
|
|
36
|
+
const {errors} = validateManifest({...minimalValid, name: undefined});
|
|
37
|
+
expect(errors.some((e) => e.includes('name'))).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('hardwareRequirements (required)', () => {
|
|
42
|
+
test('missing field fails with a helpful message', () => {
|
|
43
|
+
const m = {...minimalValid} as Record<string, unknown>;
|
|
44
|
+
delete m.hardwareRequirements;
|
|
45
|
+
const {valid, errors} = validateManifest(m);
|
|
46
|
+
expect(valid).toBe(false);
|
|
47
|
+
expect(errors.some((e) => e.includes('hardwareRequirements is required'))).toBe(true);
|
|
48
|
+
expect(errors.some((e) => e.includes('DISPLAY'))).toBe(true); // listed example
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('empty array is allowed', () => {
|
|
52
|
+
const {valid} = validateManifest({...minimalValid, hardwareRequirements: []});
|
|
53
|
+
expect(valid).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('non-array fails', () => {
|
|
57
|
+
const {errors} = validateManifest({
|
|
58
|
+
...minimalValid,
|
|
59
|
+
hardwareRequirements: 'DISPLAY' as unknown as never,
|
|
60
|
+
});
|
|
61
|
+
expect(errors.some((e) => e.includes('must be an array'))).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('unknown hardware type is rejected', () => {
|
|
65
|
+
const {errors} = validateManifest({
|
|
66
|
+
...minimalValid,
|
|
67
|
+
hardwareRequirements: [{type: 'BRAINWAVE', level: 'REQUIRED'}],
|
|
68
|
+
});
|
|
69
|
+
expect(errors.some((e) => e.includes('unknown hardware "BRAINWAVE"'))).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('unknown level is rejected', () => {
|
|
73
|
+
const {errors} = validateManifest({
|
|
74
|
+
...minimalValid,
|
|
75
|
+
hardwareRequirements: [{type: 'DISPLAY', level: 'MAYBE'}],
|
|
76
|
+
});
|
|
77
|
+
expect(errors.some((e) => e.includes('unknown level "MAYBE"'))).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('EXIST cannot be declared by authors', () => {
|
|
81
|
+
const {errors} = validateManifest({
|
|
82
|
+
...minimalValid,
|
|
83
|
+
hardwareRequirements: [{type: 'EXIST', level: 'REQUIRED'}],
|
|
84
|
+
});
|
|
85
|
+
// EXIST is omitted from ALLOWED_HARDWARE_TYPES; it's injected at runtime.
|
|
86
|
+
expect(errors.some((e) => e.includes('unknown hardware "EXIST"'))).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('entry must be an object', () => {
|
|
90
|
+
const {errors} = validateManifest({
|
|
91
|
+
...minimalValid,
|
|
92
|
+
hardwareRequirements: ['DISPLAY'] as unknown as never,
|
|
93
|
+
});
|
|
94
|
+
expect(errors.some((e) => e.includes('must be an object'))).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('description must be a string if set', () => {
|
|
98
|
+
const {errors} = validateManifest({
|
|
99
|
+
...minimalValid,
|
|
100
|
+
hardwareRequirements: [{type: 'DISPLAY', level: 'REQUIRED', description: 42}],
|
|
101
|
+
});
|
|
102
|
+
expect(errors.some((e) => e.includes('description'))).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('all real-world types accepted', () => {
|
|
106
|
+
const all = ['CAMERA', 'DISPLAY', 'MICROPHONE', 'SPEAKER', 'IMU', 'BUTTON', 'LIGHT', 'WIFI'];
|
|
107
|
+
const {valid} = validateManifest({
|
|
108
|
+
...minimalValid,
|
|
109
|
+
hardwareRequirements: all.map((type) => ({type, level: 'OPTIONAL'})),
|
|
110
|
+
});
|
|
111
|
+
expect(valid).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('permissions (now validates objects, not strings)', () => {
|
|
116
|
+
test('string entries are rejected (pre-existing bug fixed)', () => {
|
|
117
|
+
const {errors} = validateManifest({
|
|
118
|
+
...minimalValid,
|
|
119
|
+
permissions: ['MICROPHONE'] as unknown as never,
|
|
120
|
+
});
|
|
121
|
+
expect(errors.some((e) => e.includes('must be an object'))).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('valid object entry passes', () => {
|
|
125
|
+
const {valid} = validateManifest({
|
|
126
|
+
...minimalValid,
|
|
127
|
+
permissions: [{type: 'MICROPHONE', description: 'For transcription'}],
|
|
128
|
+
});
|
|
129
|
+
expect(valid).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('unknown permission type is rejected', () => {
|
|
133
|
+
const {errors} = validateManifest({
|
|
134
|
+
...minimalValid,
|
|
135
|
+
permissions: [{type: 'TELEPATHY'}],
|
|
136
|
+
});
|
|
137
|
+
expect(errors.some((e) => e.includes('unknown permission "TELEPATHY"'))).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('missing type field is rejected', () => {
|
|
141
|
+
const {errors} = validateManifest({
|
|
142
|
+
...minimalValid,
|
|
143
|
+
permissions: [{description: 'oops'}],
|
|
144
|
+
});
|
|
145
|
+
expect(errors.some((e) => e.includes('permissions[0].type'))).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('bad required type is rejected', () => {
|
|
149
|
+
const {errors} = validateManifest({
|
|
150
|
+
...minimalValid,
|
|
151
|
+
permissions: [{type: 'MICROPHONE', required: 'yes'}],
|
|
152
|
+
});
|
|
153
|
+
expect(errors.some((e) => e.includes('required'))).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('permissions is optional', () => {
|
|
157
|
+
const m = {...minimalValid} as Record<string, unknown>;
|
|
158
|
+
delete m.permissions;
|
|
159
|
+
const {valid} = validateManifest(m);
|
|
160
|
+
expect(valid).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('Two-layer fields (sdkVersion / minHostVersion / entry / type)', () => {
|
|
165
|
+
test('accepts a two-layer manifest with full two-layer fields', () => {
|
|
166
|
+
const {valid, errors} = validateManifest({
|
|
167
|
+
...minimalValid,
|
|
168
|
+
sdkVersion: '0.2.0',
|
|
169
|
+
minHostVersion: '1.42.0',
|
|
170
|
+
entry: {background: 'dist/background/index.js', ui: 'dist/ui/index.html'},
|
|
171
|
+
type: 'standard',
|
|
172
|
+
});
|
|
173
|
+
expect(errors).toEqual([]);
|
|
174
|
+
expect(valid).toBe(true);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('sdkVersion must be a non-empty string when set', () => {
|
|
178
|
+
const {errors} = validateManifest({...minimalValid, sdkVersion: ''});
|
|
179
|
+
expect(errors.some((e) => e.includes('sdkVersion'))).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('minHostVersion must be a non-empty string when set', () => {
|
|
183
|
+
const {errors} = validateManifest({...minimalValid, minHostVersion: 42});
|
|
184
|
+
expect(errors.some((e) => e.includes('minHostVersion'))).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('entry.background is required when entry is set', () => {
|
|
188
|
+
const {errors} = validateManifest({...minimalValid, entry: {ui: 'dist/ui/index.html'}});
|
|
189
|
+
expect(errors.some((e) => e.includes('entry.background'))).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('entry.ui must be a string when set', () => {
|
|
193
|
+
const {errors} = validateManifest({
|
|
194
|
+
...minimalValid,
|
|
195
|
+
entry: {background: 'dist/background/index.js', ui: 42},
|
|
196
|
+
});
|
|
197
|
+
expect(errors.some((e) => e.includes('entry.ui'))).toBe(true);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('entry must be an object (not array, not string)', () => {
|
|
201
|
+
const {errors} = validateManifest({...minimalValid, entry: 'dist/index.js'});
|
|
202
|
+
expect(errors.some((e) => e.includes('entry'))).toBe(true);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('type must be "standard" or "background" when set', () => {
|
|
206
|
+
const {errors} = validateManifest({...minimalValid, type: 'weird'});
|
|
207
|
+
expect(errors.some((e) => e.includes('type'))).toBe(true);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('type accepts "dashboard" miniapps and a boolean alwaysOn', () => {
|
|
211
|
+
expect(validateManifest({...minimalValid, type: 'dashboard', alwaysOn: true}).valid).toBe(true);
|
|
212
|
+
const {errors} = validateManifest({...minimalValid, alwaysOn: 'yes'});
|
|
213
|
+
expect(errors.some((e) => e.includes('alwaysOn'))).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('type accepts "background" miniapps', () => {
|
|
217
|
+
const {valid} = validateManifest({...minimalValid, type: 'background'});
|
|
218
|
+
expect(valid).toBe(true);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('manifests without two-layer fields still validate (legacy single-layer)', () => {
|
|
222
|
+
const {valid, errors} = validateManifest(minimalValid);
|
|
223
|
+
expect(errors).toEqual([]);
|
|
224
|
+
expect(valid).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('actions', () => {
|
|
229
|
+
test('accepts a well-formed action with typed parameters', () => {
|
|
230
|
+
const {valid, errors} = validateManifest({
|
|
231
|
+
...minimalValid,
|
|
232
|
+
actions: [
|
|
233
|
+
{
|
|
234
|
+
id: 'add_todo',
|
|
235
|
+
description: 'Add an item to the user\'s todo list.',
|
|
236
|
+
parameters: {
|
|
237
|
+
type: 'object',
|
|
238
|
+
properties: {
|
|
239
|
+
text: {type: 'string', description: 'The todo text'},
|
|
240
|
+
tags: {type: 'array', items: {type: 'string'}},
|
|
241
|
+
},
|
|
242
|
+
required: ['text'],
|
|
243
|
+
},
|
|
244
|
+
outputSchema: {
|
|
245
|
+
type: 'object',
|
|
246
|
+
properties: {
|
|
247
|
+
ok: {type: 'boolean'},
|
|
248
|
+
message: {type: 'string'},
|
|
249
|
+
},
|
|
250
|
+
required: ['ok'],
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
});
|
|
255
|
+
expect(errors).toEqual([]);
|
|
256
|
+
expect(valid).toBe(true);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('rejects a non-object output schema', () => {
|
|
260
|
+
const {valid, errors} = validateManifest({
|
|
261
|
+
...minimalValid,
|
|
262
|
+
actions: [{id: 'go', description: 'x', outputSchema: 'not-a-schema'}],
|
|
263
|
+
});
|
|
264
|
+
expect(valid).toBe(false);
|
|
265
|
+
expect(errors.some((e) => e.includes('outputSchema'))).toBe(true);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('accepts an action with no parameters', () => {
|
|
269
|
+
const {valid} = validateManifest({
|
|
270
|
+
...minimalValid,
|
|
271
|
+
actions: [{id: 'snooze', description: 'Snooze the current reminder.'}],
|
|
272
|
+
});
|
|
273
|
+
expect(valid).toBe(true);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('rejects an id that breaks the pattern', () => {
|
|
277
|
+
const {valid, errors} = validateManifest({
|
|
278
|
+
...minimalValid,
|
|
279
|
+
actions: [{id: 'Add-Todo', description: 'x'}],
|
|
280
|
+
});
|
|
281
|
+
expect(valid).toBe(false);
|
|
282
|
+
expect(errors.some((e) => e.includes('actions[0].id'))).toBe(true);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('rejects duplicate action ids', () => {
|
|
286
|
+
const {valid, errors} = validateManifest({
|
|
287
|
+
...minimalValid,
|
|
288
|
+
actions: [
|
|
289
|
+
{id: 'go', description: 'one'},
|
|
290
|
+
{id: 'go', description: 'two'},
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
expect(valid).toBe(false);
|
|
294
|
+
expect(errors.some((e) => e.includes('duplicated'))).toBe(true);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test('rejects a missing/empty description', () => {
|
|
298
|
+
const {valid, errors} = validateManifest({
|
|
299
|
+
...minimalValid,
|
|
300
|
+
actions: [{id: 'go', description: ' '}],
|
|
301
|
+
});
|
|
302
|
+
expect(valid).toBe(false);
|
|
303
|
+
expect(errors.some((e) => e.includes('description'))).toBe(true);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('rejects "integer" param type (use "number")', () => {
|
|
307
|
+
const {valid, errors} = validateManifest({
|
|
308
|
+
...minimalValid,
|
|
309
|
+
actions: [
|
|
310
|
+
{id: 'go', description: 'x', parameters: {type: 'object', properties: {n: {type: 'integer'}}}},
|
|
311
|
+
],
|
|
312
|
+
});
|
|
313
|
+
expect(valid).toBe(false);
|
|
314
|
+
expect(errors.some((e) => e.includes('.type must be one of'))).toBe(true);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('rejects an array param without items.type', () => {
|
|
318
|
+
const {valid, errors} = validateManifest({
|
|
319
|
+
...minimalValid,
|
|
320
|
+
actions: [
|
|
321
|
+
{id: 'go', description: 'x', parameters: {type: 'object', properties: {a: {type: 'array'}}}},
|
|
322
|
+
],
|
|
323
|
+
});
|
|
324
|
+
expect(valid).toBe(false);
|
|
325
|
+
expect(errors.some((e) => e.includes('items.type'))).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
describe('store fields (tagline, tags)', () => {
|
|
329
|
+
test('accepts a tagline and known tags', () => {
|
|
330
|
+
const {valid, errors} = validateManifest({
|
|
331
|
+
...minimalValid,
|
|
332
|
+
tagline: 'Read scripts on your glasses',
|
|
333
|
+
tags: ['productivity', 'ai'],
|
|
334
|
+
});
|
|
335
|
+
expect(valid).toBe(true);
|
|
336
|
+
expect(errors).toEqual([]);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test('accepts unknown slug tags', () => {
|
|
340
|
+
const {valid} = validateManifest({...minimalValid, tags: ['home-automation']});
|
|
341
|
+
expect(valid).toBe(true);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('rejects a tagline over 80 characters', () => {
|
|
345
|
+
const {valid, errors} = validateManifest({...minimalValid, tagline: 'x'.repeat(81)});
|
|
346
|
+
expect(valid).toBe(false);
|
|
347
|
+
expect(errors.some((e) => e.includes('tagline must be 80'))).toBe(true);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test('rejects a blank or multi-line tagline', () => {
|
|
351
|
+
expect(validateManifest({...minimalValid, tagline: ' '}).valid).toBe(false);
|
|
352
|
+
expect(validateManifest({...minimalValid, tagline: 'a\nb'}).valid).toBe(false);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test('rejects more than five tags', () => {
|
|
356
|
+
const {errors} = validateManifest({...minimalValid, tags: ['a', 'b', 'c', 'd', 'e', 'f']});
|
|
357
|
+
expect(errors.some((e) => e.includes('5 entries or fewer'))).toBe(true);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('rejects non-slug tags', () => {
|
|
361
|
+
const {errors} = validateManifest({...minimalValid, tags: ['Productivity', 'a b', '-lead']});
|
|
362
|
+
expect(errors.filter((e) => e.includes('lowercase slug')).length).toBe(3);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test('rejects duplicate tags and non-string entries', () => {
|
|
366
|
+
const {errors} = validateManifest({...minimalValid, tags: ['ai', 'ai', 3]});
|
|
367
|
+
expect(errors.some((e) => e.includes('duplicated'))).toBe(true);
|
|
368
|
+
expect(errors.some((e) => e.includes('tags[2] must be a string'))).toBe(true);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('rejects a non-array tags value', () => {
|
|
372
|
+
const {errors} = validateManifest({...minimalValid, tags: 'ai'});
|
|
373
|
+
expect(errors.some((e) => e.includes('tags must be an array'))).toBe(true);
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
});
|