@specdest/devkit 0.4.5 → 0.4.8
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 +34 -4
- package/dist/npm/canonical-project-operations.d.ts +5 -0
- package/dist/npm/canonical-project-operations.js +5 -0
- package/dist/npm/canonical-project.d.ts +10 -0
- package/dist/npm/canonical-project.js +109 -0
- package/dist/npm/canonical-source.d.ts +14 -0
- package/dist/npm/canonical-source.js +216 -0
- package/dist/npm/catalog-snapshot.d.ts +47 -0
- package/dist/npm/catalog-snapshot.js +28 -0
- package/dist/npm/cli.d.ts +2 -0
- package/dist/npm/cli.js +15 -0
- package/dist/npm/commands.d.ts +9 -0
- package/dist/npm/commands.js +157 -0
- package/dist/npm/flow.d.ts +48 -0
- package/dist/npm/flow.js +396 -0
- package/dist/npm/fuzz.d.ts +138 -0
- package/dist/npm/fuzz.js +327 -0
- package/dist/npm/git-catalog.d.ts +39 -0
- package/dist/npm/git-catalog.js +190 -0
- package/dist/npm/index.d.ts +5 -0
- package/dist/npm/index.js +22 -0
- package/dist/npm/installer-primitives.d.ts +3 -0
- package/dist/npm/installer-primitives.js +50 -0
- package/dist/npm/predefined-packages/abac.d.ts +2 -0
- package/dist/npm/predefined-packages/abac.js +22 -0
- package/dist/npm/predefined-packages/auth.d.ts +2 -0
- package/dist/npm/predefined-packages/auth.js +21 -0
- package/dist/npm/predefined-packages/convex.d.ts +2 -0
- package/dist/npm/predefined-packages/convex.js +53 -0
- package/dist/npm/predefined-packages/expo.d.ts +2 -0
- package/dist/npm/predefined-packages/expo.js +84 -0
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
- package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
- package/dist/npm/predefined-packages/health.d.ts +10 -0
- package/dist/npm/predefined-packages/health.js +52 -0
- package/dist/npm/predefined-packages/husky.d.ts +2 -0
- package/dist/npm/predefined-packages/husky.js +57 -0
- package/dist/npm/predefined-packages/index.d.ts +11 -0
- package/dist/npm/predefined-packages/index.js +56 -0
- package/dist/npm/predefined-packages/install.d.ts +19 -0
- package/dist/npm/predefined-packages/install.js +85 -0
- package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
- package/dist/npm/predefined-packages/local-logging.js +17 -0
- package/dist/npm/predefined-packages/logging.d.ts +2 -0
- package/dist/npm/predefined-packages/logging.js +21 -0
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
- package/dist/npm/predefined-packages/nps.d.ts +2 -0
- package/dist/npm/predefined-packages/nps.js +32 -0
- package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
- package/dist/npm/predefined-packages/oxfmt.js +22 -0
- package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
- package/dist/npm/predefined-packages/oxlint.js +35 -0
- package/dist/npm/predefined-packages/package-json.d.ts +3 -0
- package/dist/npm/predefined-packages/package-json.js +61 -0
- package/dist/npm/predefined-packages/payments.d.ts +2 -0
- package/dist/npm/predefined-packages/payments.js +31 -0
- package/dist/npm/predefined-packages/playwright.d.ts +2 -0
- package/dist/npm/predefined-packages/playwright.js +35 -0
- package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
- package/dist/npm/predefined-packages/project-signals.js +39 -0
- package/dist/npm/predefined-packages/registry.d.ts +3 -0
- package/dist/npm/predefined-packages/registry.js +63 -0
- package/dist/npm/predefined-packages/resolver.d.ts +8 -0
- package/dist/npm/predefined-packages/resolver.js +35 -0
- package/dist/npm/predefined-packages/sentry.d.ts +2 -0
- package/dist/npm/predefined-packages/sentry.js +29 -0
- package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
- package/dist/npm/predefined-packages/shadcn.js +23 -0
- package/dist/npm/predefined-packages/storybook.d.ts +2 -0
- package/dist/npm/predefined-packages/storybook.js +25 -0
- package/dist/npm/predefined-packages/stryker.d.ts +2 -0
- package/dist/npm/predefined-packages/stryker.js +48 -0
- package/dist/npm/predefined-packages/supabase.d.ts +2 -0
- package/dist/npm/predefined-packages/supabase.js +84 -0
- package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
- package/dist/npm/predefined-packages/tailwind.js +18 -0
- package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-form.js +19 -0
- package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-query.js +15 -0
- package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-router.js +18 -0
- package/dist/npm/predefined-packages/types.d.ts +31 -0
- package/dist/npm/predefined-packages/types.js +1 -0
- package/dist/npm/predefined-packages/vite.d.ts +2 -0
- package/dist/npm/predefined-packages/vite.js +123 -0
- package/dist/npm/predefined-packages/vitest.d.ts +2 -0
- package/dist/npm/predefined-packages/vitest.js +20 -0
- package/dist/npm/predefined-packages/zod.d.ts +2 -0
- package/dist/npm/predefined-packages/zod.js +18 -0
- package/dist/npm/project-check.d.ts +6 -0
- package/dist/npm/project-check.js +87 -0
- package/dist/npm/project-context.d.ts +42 -0
- package/dist/npm/project-context.js +192 -0
- package/dist/npm/project-rules.d.ts +22 -0
- package/dist/npm/project-rules.js +66 -0
- package/dist/npm/project-runtime.d.ts +18 -0
- package/dist/npm/project-runtime.js +27 -0
- package/dist/npm/project-status.d.ts +32 -0
- package/dist/npm/project-status.js +56 -0
- package/dist/npm/project-sync.d.ts +7 -0
- package/dist/npm/project-sync.js +135 -0
- package/dist/npm/remote-installer.d.ts +4 -0
- package/dist/npm/remote-installer.js +312 -0
- package/dist/npm/state.d.ts +14 -0
- package/dist/npm/state.js +182 -0
- package/package.json +10 -7
- package/src/canonical-project-operations.js +0 -433
- package/src/canonical-project.js +0 -136
- package/src/canonical-source.js +0 -250
- package/src/catalog-snapshot.js +0 -39
- package/src/catalog.js +0 -117
- package/src/cli.js +0 -14
- package/src/fuzz.js +0 -291
- package/src/git-catalog.js +0 -177
- package/src/index.js +0 -36
- package/src/installer-primitives.js +0 -198
- package/src/project-operations.js +0 -189
- package/src/project-targeting.js +0 -48
- package/src/remote-installer.js +0 -479
- package/src/rule-profile.js +0 -61
- package/src/setup-requirements.js +0 -82
- package/src/shared-file.js +0 -131
- package/src/sync-core.js +0 -390
package/src/fuzz.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { readdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join, relative, resolve } from 'node:path';
|
|
4
|
-
import { registerHooks } from 'node:module';
|
|
5
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
-
|
|
7
|
-
import fc from 'fast-check';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_SUFFIXES = ['.input.schema.ts', '.output.schema.ts', '.form.schema.ts', '.callbackInput.schema.ts'];
|
|
10
|
-
const CONFIG_PATH = '.specdest/fuzz.json';
|
|
11
|
-
const DEFAULT_SEED = 20260914;
|
|
12
|
-
|
|
13
|
-
function schemaDef(schema) {
|
|
14
|
-
return schema?._zod?.def ?? schema?._def ?? schema?.def;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function schemaType(schema) {
|
|
18
|
-
return schemaDef(schema)?.type ?? schema?.type;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function isSchema(value) {
|
|
22
|
-
return value && typeof value.safeParse === 'function' && typeof schemaType(value) === 'string';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function unwrap(schema) {
|
|
26
|
-
const type = schemaType(schema);
|
|
27
|
-
if (type === 'optional' || type === 'nullable' || type === 'default' || type === 'catch') {
|
|
28
|
-
return unwrap(schemaDef(schema).innerType);
|
|
29
|
-
}
|
|
30
|
-
return schema;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function boundsFor(schema) {
|
|
34
|
-
const bounds = {
|
|
35
|
-
minLength: Number.isFinite(schema?.minLength) ? schema.minLength : undefined,
|
|
36
|
-
maxLength: Number.isFinite(schema?.maxLength) ? schema.maxLength : undefined,
|
|
37
|
-
minValue: Number.isFinite(schema?.minValue) ? schema.minValue : undefined,
|
|
38
|
-
maxValue: Number.isFinite(schema?.maxValue) ? schema.maxValue : undefined,
|
|
39
|
-
};
|
|
40
|
-
for (const check of schemaDef(schema)?.checks ?? []) {
|
|
41
|
-
const def = check?._zod?.def ?? check?.def;
|
|
42
|
-
if (def?.check === 'min_length') bounds.minLength = def.minimum;
|
|
43
|
-
if (def?.check === 'max_length') bounds.maxLength = def.maximum;
|
|
44
|
-
if (def?.check === 'greater_than' && def.inclusive) bounds.minValue = def.value;
|
|
45
|
-
if (def?.check === 'less_than' && def.inclusive) bounds.maxValue = def.value;
|
|
46
|
-
}
|
|
47
|
-
return bounds;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function zodArbitrary(schema) {
|
|
51
|
-
const type = schemaType(schema);
|
|
52
|
-
const def = schemaDef(schema);
|
|
53
|
-
if (type === 'optional') return fc.option(zodArbitrary(def.innerType), { nil: undefined });
|
|
54
|
-
if (type === 'nullable') return fc.option(zodArbitrary(def.innerType), { nil: null });
|
|
55
|
-
if (type === 'string') {
|
|
56
|
-
const { minLength = 0, maxLength = 32 } = boundsFor(schema);
|
|
57
|
-
return fc.string({ minLength, maxLength: Math.min(maxLength, 64) }).filter((value) => schema.safeParse(value).success);
|
|
58
|
-
}
|
|
59
|
-
if (type === 'number') {
|
|
60
|
-
const { minValue = -1000, maxValue = 1000 } = boundsFor(schema);
|
|
61
|
-
return fc.double({ min: minValue, max: maxValue, noNaN: true, noDefaultInfinity: true }).filter((value) => schema.safeParse(value).success);
|
|
62
|
-
}
|
|
63
|
-
if (type === 'boolean') return fc.boolean();
|
|
64
|
-
if (type === 'enum') return fc.constantFrom(...Object.values(def.entries));
|
|
65
|
-
if (type === 'array') {
|
|
66
|
-
const { minLength = 0, maxLength = 4 } = boundsFor(schema);
|
|
67
|
-
return fc.array(zodArbitrary(def.element), { minLength, maxLength: Math.min(maxLength, 8) }).filter((value) => schema.safeParse(value).success);
|
|
68
|
-
}
|
|
69
|
-
if (type === 'object') {
|
|
70
|
-
const shape = typeof def.shape === 'function' ? def.shape() : def.shape;
|
|
71
|
-
const shapeEntries = Object.entries(shape ?? {});
|
|
72
|
-
const entries = shapeEntries.map(([key, child]) => [key, zodArbitrary(child)]);
|
|
73
|
-
const requiredKeys = shapeEntries.filter(([, child]) => schemaType(child) !== 'optional').map(([key]) => key);
|
|
74
|
-
return fc.record(Object.fromEntries(entries), { requiredKeys })
|
|
75
|
-
.filter((value) => schema.safeParse(value).success);
|
|
76
|
-
}
|
|
77
|
-
throw new Error(`Unsupported Zod schema type: ${type ?? 'unknown'}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function getAtPath(value, path) {
|
|
81
|
-
return path.reduce((current, key) => current?.[key], value);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function setAtPath(value, path, replacement, omit = false) {
|
|
85
|
-
if (!path.length) return replacement;
|
|
86
|
-
const clone = Array.isArray(value) ? [...value] : { ...value };
|
|
87
|
-
const [head, ...tail] = path;
|
|
88
|
-
if (!tail.length && omit) delete clone[head];
|
|
89
|
-
else clone[head] = setAtPath(value?.[head], tail, replacement, omit);
|
|
90
|
-
return clone;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function semanticCases(schema) {
|
|
94
|
-
const base = unwrap(schema);
|
|
95
|
-
const type = schemaType(base);
|
|
96
|
-
const bounds = boundsFor(base);
|
|
97
|
-
if (type === 'string') {
|
|
98
|
-
const cases = [['empty string', ''], ['single-space string', ' '], ['whitespace-only string', ' ']];
|
|
99
|
-
if (Number.isFinite(bounds.minLength)) cases.push(['minimum-length string', 'x'.repeat(bounds.minLength)]);
|
|
100
|
-
if (Number.isFinite(bounds.maxLength)) cases.push(['maximum-length string', 'x'.repeat(Math.min(bounds.maxLength, 128))]);
|
|
101
|
-
return cases;
|
|
102
|
-
}
|
|
103
|
-
if (type === 'number') {
|
|
104
|
-
const cases = [['zero', 0], ['NaN', Number.NaN]];
|
|
105
|
-
if (Number.isFinite(bounds.minValue)) cases.push(['minimum number', bounds.minValue]);
|
|
106
|
-
if (Number.isFinite(bounds.maxValue)) cases.push(['maximum number', bounds.maxValue]);
|
|
107
|
-
return cases;
|
|
108
|
-
}
|
|
109
|
-
if (type === 'boolean') return [['false', false]];
|
|
110
|
-
if (type === 'array') return [['empty array', []], ['array containing null', [null]], ['array containing undefined', [undefined]]];
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function collectLeaves(schema, path = []) {
|
|
115
|
-
const def = schemaDef(schema);
|
|
116
|
-
const type = schemaType(schema);
|
|
117
|
-
if (type === 'optional' || type === 'nullable') return collectLeaves(def.innerType, path).map((leaf) => ({ ...leaf, wrappers: [type, ...(leaf.wrappers ?? [])] }));
|
|
118
|
-
if (type === 'object') {
|
|
119
|
-
const shape = typeof def.shape === 'function' ? def.shape() : def.shape;
|
|
120
|
-
return Object.entries(shape ?? {}).flatMap(([key, child]) => collectLeaves(child, [...path, key]));
|
|
121
|
-
}
|
|
122
|
-
return [{ path, schema, wrappers: [] }];
|
|
123
|
-
}
|
|
124
|
-
function semanticConcern(leaf, label, accepted) {
|
|
125
|
-
if (!accepted) return null;
|
|
126
|
-
if (schemaType(unwrap(leaf.schema)) === 'string' && /empty|space|whitespace/u.test(label)) {
|
|
127
|
-
return 'empty/whitespace strings are accepted';
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function amplifySchema(schema, sample) {
|
|
133
|
-
const cases = [];
|
|
134
|
-
for (const leaf of collectLeaves(schema)) {
|
|
135
|
-
for (const [label, replacement] of semanticCases(leaf.schema)) {
|
|
136
|
-
const value = setAtPath(sample, leaf.path, replacement);
|
|
137
|
-
const accepted = schema.safeParse(value).success;
|
|
138
|
-
cases.push({ path: leaf.path.join('.'), label, value: replacement, accepted, concern: semanticConcern(leaf, label, accepted) });
|
|
139
|
-
}
|
|
140
|
-
if (schemaType(unwrap(leaf.schema)) === 'array') {
|
|
141
|
-
const current = getAtPath(sample, leaf.path);
|
|
142
|
-
if (Array.isArray(current) && current.length) {
|
|
143
|
-
const arrayCases = [['array item removal', current.slice(1)], ['duplicate array item', [current[0], ...current]]];
|
|
144
|
-
if (current.length > 1) arrayCases.push(['array reordering', [...current].reverse()]);
|
|
145
|
-
for (const [label, replacement] of arrayCases) {
|
|
146
|
-
const value = setAtPath(sample, leaf.path, replacement);
|
|
147
|
-
cases.push({ path: leaf.path.join('.'), label, value: replacement, accepted: schema.safeParse(value).success, concern: null });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (leaf.path.length) {
|
|
152
|
-
for (const [label, replacement, omit] of [['null', null, false], ['undefined', undefined, false], ['omitted property', undefined, true]]) {
|
|
153
|
-
const value = setAtPath(sample, leaf.path, replacement, omit);
|
|
154
|
-
cases.push({ path: leaf.path.join('.'), label, value: replacement, accepted: schema.safeParse(value).success, concern: null });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return cases;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function fuzzSchema(schema, { seed = DEFAULT_SEED, numRuns = 50 } = {}) {
|
|
162
|
-
let arbitrary;
|
|
163
|
-
try {
|
|
164
|
-
arbitrary = zodArbitrary(schema);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
return { status: 'unsupported', reason: error.message };
|
|
167
|
-
}
|
|
168
|
-
let lastCases = [];
|
|
169
|
-
const property = fc.property(arbitrary, (sample) => {
|
|
170
|
-
lastCases = amplifySchema(schema, sample);
|
|
171
|
-
return !lastCases.some((item) => item.concern);
|
|
172
|
-
});
|
|
173
|
-
const result = fc.check(property, { seed, numRuns });
|
|
174
|
-
if (!result.failed) return { status: 'pass', seed, cases: lastCases };
|
|
175
|
-
const sample = result.counterexample?.[0];
|
|
176
|
-
const cases = sample === undefined ? lastCases : amplifySchema(schema, sample);
|
|
177
|
-
return {
|
|
178
|
-
status: 'fail',
|
|
179
|
-
seed,
|
|
180
|
-
path: result.counterexamplePath,
|
|
181
|
-
counterexample: cases.find((item) => item.concern),
|
|
182
|
-
cases,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async function walk(dir) {
|
|
187
|
-
const found = [];
|
|
188
|
-
let entries = [];
|
|
189
|
-
try { entries = await readdir(dir, { withFileTypes: true }); } catch { return found; }
|
|
190
|
-
for (const entry of entries) {
|
|
191
|
-
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
|
|
192
|
-
const path = join(dir, entry.name);
|
|
193
|
-
if (entry.isDirectory()) found.push(...await walk(path));
|
|
194
|
-
else if (DEFAULT_SUFFIXES.some((suffix) => entry.name.endsWith(suffix))) found.push(path);
|
|
195
|
-
}
|
|
196
|
-
return found;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function readConfig(projectRoot) {
|
|
200
|
-
try {
|
|
201
|
-
const text = await readFile(join(projectRoot, CONFIG_PATH), 'utf8');
|
|
202
|
-
const config = JSON.parse(text);
|
|
203
|
-
if (config.schemaVersion !== 1 || !Array.isArray(config.targets)) throw new Error(`${CONFIG_PATH} must use schemaVersion 1 and a targets array`);
|
|
204
|
-
return config;
|
|
205
|
-
} catch (error) {
|
|
206
|
-
if (error?.code === 'ENOENT') return null;
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export async function discoverFuzzTargets(projectRoot) {
|
|
212
|
-
const config = await readConfig(projectRoot);
|
|
213
|
-
if (config) return config.targets.map((target) => ({ module: resolve(projectRoot, target.module), exports: target.exports ?? null }));
|
|
214
|
-
const files = [...await walk(join(projectRoot, 'src')), ...await walk(join(projectRoot, 'supabase', 'functions'))];
|
|
215
|
-
return files.map((module) => ({ module, exports: null }));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function resolveProjectSpecifier(specifier, parentURL, projectRoot) {
|
|
219
|
-
let base;
|
|
220
|
-
if (specifier.startsWith('@/')) base = resolve(projectRoot, 'src', specifier.slice(2));
|
|
221
|
-
else if ((specifier.startsWith('./') || specifier.startsWith('../')) && parentURL?.startsWith('file:')) {
|
|
222
|
-
base = resolve(dirname(fileURLToPath(parentURL)), specifier);
|
|
223
|
-
} else return null;
|
|
224
|
-
const candidates = [base, ...['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'].map((ext) => `${base}${ext}`),
|
|
225
|
-
...['.ts', '.tsx', '.js', '.jsx'].map((ext) => join(base, `index${ext}`))];
|
|
226
|
-
return candidates.find((candidate) => existsSync(candidate)) ?? null;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async function loadTarget(target, projectRoot) {
|
|
230
|
-
const hooks = registerHooks({
|
|
231
|
-
resolve(specifier, context, nextResolve) {
|
|
232
|
-
const resolved = resolveProjectSpecifier(specifier, context.parentURL, projectRoot);
|
|
233
|
-
return resolved ? nextResolve(pathToFileURL(resolved).href, context) : nextResolve(specifier, context);
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
try {
|
|
237
|
-
const loaded = await import(pathToFileURL(target.module).href);
|
|
238
|
-
return Object.entries(loaded)
|
|
239
|
-
.filter(([name, value]) => (!target.exports || target.exports.includes(name)) && isSchema(value))
|
|
240
|
-
.map(([name, schema]) => ({ name, schema }));
|
|
241
|
-
} finally {
|
|
242
|
-
hooks.deregister();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function formatValue(value) {
|
|
246
|
-
if (value === undefined) return 'undefined';
|
|
247
|
-
if (typeof value === 'number' && Number.isNaN(value)) return 'NaN';
|
|
248
|
-
return JSON.stringify(value);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export async function runFuzz(projectRoot, { seed = DEFAULT_SEED } = {}) {
|
|
252
|
-
const targets = await discoverFuzzTargets(projectRoot);
|
|
253
|
-
const results = [];
|
|
254
|
-
for (const target of targets) {
|
|
255
|
-
let schemas;
|
|
256
|
-
try {
|
|
257
|
-
schemas = await loadTarget(target, projectRoot);
|
|
258
|
-
} catch (error) {
|
|
259
|
-
results.push({ status: 'unsupported', module: target.module, name: '*', reason: `unable to load module: ${error.message}` });
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (!schemas.length) {
|
|
263
|
-
results.push({ status: 'unsupported', module: target.module, name: '*', reason: 'no exported Zod schema found' });
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
for (const { name, schema } of schemas) results.push({ module: target.module, name, ...fuzzSchema(schema, { seed }) });
|
|
267
|
-
}
|
|
268
|
-
return { seed, targets, results, failed: results.filter((item) => item.status === 'fail'), unsupported: results.filter((item) => item.status === 'unsupported') };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function createFuzzCommandHandler(projectRoot = process.cwd()) {
|
|
272
|
-
return async (args, io) => {
|
|
273
|
-
if (args.length) { io.stderr.write('Usage: specdest fuzz\n'); return 2; }
|
|
274
|
-
const result = await runFuzz(projectRoot);
|
|
275
|
-
for (const item of result.failed) {
|
|
276
|
-
const counterexample = item.counterexample;
|
|
277
|
-
const label = `${item.name}${counterexample?.path ? `.${counterexample.path}` : ''}`;
|
|
278
|
-
io.stderr.write(`FAIL ${label}\n\n`);
|
|
279
|
-
io.stderr.write(`Unexpected behavior for amplified value:\n${formatValue(counterexample?.value)}\n\n`);
|
|
280
|
-
io.stderr.write(`Related semantic concern:\n${counterexample?.concern ?? 'fuzz property failed'}\n\n`);
|
|
281
|
-
io.stderr.write(`Reproduce: seed=${item.seed}${item.path ? ` path=${item.path}` : ''}\n`);
|
|
282
|
-
io.stderr.write(`Module: ${relative(projectRoot, item.module)}\n\n`);
|
|
283
|
-
}
|
|
284
|
-
for (const item of result.unsupported) io.stderr.write(`SKIP ${relative(projectRoot, item.module)} ${item.name}: ${item.reason}\n`);
|
|
285
|
-
if (!result.results.length) io.stdout.write('Fuzz: no contract targets found.\n');
|
|
286
|
-
else if (!result.failed.length) io.stdout.write(`Fuzz: ${result.results.length - result.unsupported.length} passed; ${result.unsupported.length} skipped.\n`);
|
|
287
|
-
return result.failed.length ? 1 : 0;
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export const FUZZ_DEFAULT_SEED = DEFAULT_SEED;
|
package/src/git-catalog.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { readdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
|
|
5
|
-
const sha256 = (value) => createHash('sha256').update(value).digest('hex');
|
|
6
|
-
|
|
7
|
-
const legacyImplementationFamilies = new Map([
|
|
8
|
-
['abac-permissions-supabase', ['abac-permissions-convex', 'abac-permissions-supabase']],
|
|
9
|
-
['layers-and-contracts', ['layers-and-contracts', 'layers-and-contracts-convex', 'layers-and-contracts-supabase']],
|
|
10
|
-
['unit-test-rules', ['unit-test-rules', 'unit-test-rules-convex', 'unit-test-rules-supabase']],
|
|
11
|
-
['unit-test-rules-supabase', ['unit-test-rules', 'unit-test-rules-convex', 'unit-test-rules-supabase']],
|
|
12
|
-
]);
|
|
13
|
-
|
|
14
|
-
function legacyImplementationIds(manifest) {
|
|
15
|
-
const implementation = manifest.checker?.implementation;
|
|
16
|
-
if (!implementation || implementation === manifest.id) return [];
|
|
17
|
-
return legacyImplementationFamilies.get(implementation) ?? [implementation];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function moduleFiles(root) {
|
|
21
|
-
const files = [];
|
|
22
|
-
const walk = async (dir, prefix = '') => {
|
|
23
|
-
for (const entry of (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
24
|
-
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
25
|
-
if (entry.isDirectory()) await walk(join(dir, entry.name), relative);
|
|
26
|
-
else if (entry.isFile()) files.push({ path: relative, content: await readFile(join(dir, entry.name), 'utf8') });
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
await walk(root);
|
|
30
|
-
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function title(content, id) {
|
|
34
|
-
return content.match(/^#\s+(.+)$/mu)?.[1]?.trim() || id;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function summary(content, fallback) {
|
|
38
|
-
const normalized = String(content ?? '').replace(/\r\n?/gu, '\n');
|
|
39
|
-
const intent = normalized.match(/(?:^|\n)## Intent\s*\n+([^#][\s\S]*?)(?=\n## |$)/u)?.[1]?.trim();
|
|
40
|
-
const source = intent || normalized
|
|
41
|
-
.split('\n')
|
|
42
|
-
.map((line) => line.trim())
|
|
43
|
-
.find((line) => line && !line.startsWith('#')) || fallback;
|
|
44
|
-
return source
|
|
45
|
-
.replace(/^\*\*Rule:\*\*\s*/u, '')
|
|
46
|
-
.replace(/\s+/gu, ' ')
|
|
47
|
-
.slice(0, 240)
|
|
48
|
-
.trim();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function canonicalVersion(manifest) {
|
|
52
|
-
const version = String(manifest.version ?? '');
|
|
53
|
-
if (!/^\d+\.\d+\.\d+$/u.test(version)) {
|
|
54
|
-
throw new Error(`Canonical catalog entry requires SemVer version: ${manifest.id}`);
|
|
55
|
-
}
|
|
56
|
-
return version;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function catalogKind(manifest) {
|
|
60
|
-
const kind = manifest.kind ?? 'rule';
|
|
61
|
-
if (!['rule', 'module'].includes(kind)) throw new Error(`Invalid canonical kind: ${manifest.id}`);
|
|
62
|
-
return kind;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function notApplicableRuleIds(manifest) {
|
|
66
|
-
if (!Array.isArray(manifest.notApplicableRuleIds)) return undefined;
|
|
67
|
-
return [...new Set(manifest.notApplicableRuleIds.map(String))].sort();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function projectProfiles(manifest) {
|
|
71
|
-
if (!manifest.projectProfiles) return undefined;
|
|
72
|
-
if (typeof manifest.projectProfiles !== 'object' || Array.isArray(manifest.projectProfiles)) {
|
|
73
|
-
throw new Error(`Invalid projectProfiles: ${manifest.id}`);
|
|
74
|
-
}
|
|
75
|
-
return Object.fromEntries(Object.entries(manifest.projectProfiles).sort(([a], [b]) => a.localeCompare(b)).map(
|
|
76
|
-
([name, definition]) => {
|
|
77
|
-
if (!definition || !Array.isArray(definition.ruleIds) || definition.ruleIds.length === 0) {
|
|
78
|
-
throw new Error(`Invalid project profile: ${manifest.id}:${name}`);
|
|
79
|
-
}
|
|
80
|
-
return [name, { ruleIds: [...new Set(definition.ruleIds.map(String))].sort() }];
|
|
81
|
-
},
|
|
82
|
-
));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function stringList(value) {
|
|
86
|
-
if (!Array.isArray(value) || value.length === 0) return undefined;
|
|
87
|
-
return [...new Set(value.map(String))].sort();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function applicableStacks(manifest) {
|
|
91
|
-
if (manifest.scope !== 'Stack-specific') return undefined;
|
|
92
|
-
if (!Array.isArray(manifest.applicableStacks) || manifest.applicableStacks.length === 0) {
|
|
93
|
-
throw new Error(`Stack-specific rule requires applicableStacks: ${manifest.id}`);
|
|
94
|
-
}
|
|
95
|
-
return [...new Set(manifest.applicableStacks.map(String))].sort();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function buildGitCatalog({ modulesRoot, repositoryRevision = 'working-tree' }) {
|
|
99
|
-
const directories = (await readdir(modulesRoot, { withFileTypes: true }))
|
|
100
|
-
.filter((entry) => entry.isDirectory())
|
|
101
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
102
|
-
const modules = [];
|
|
103
|
-
for (const directory of directories) {
|
|
104
|
-
const root = join(modulesRoot, directory.name);
|
|
105
|
-
const files = await moduleFiles(root);
|
|
106
|
-
const manifestFile = files.find((file) => file.path === 'manifest.json');
|
|
107
|
-
if (!manifestFile) throw new Error(`Missing manifest.json: ${directory.name}`);
|
|
108
|
-
const manifest = JSON.parse(manifestFile.content);
|
|
109
|
-
if (manifest.id !== directory.name) throw new Error(`Module id/path mismatch: ${directory.name}`);
|
|
110
|
-
modules.push({ files, manifest, ownContentHash: sha256(JSON.stringify(files)) });
|
|
111
|
-
}
|
|
112
|
-
const canonicalCheckHash = modules.find(({ manifest }) => manifest.id === 'canonical-check')?.ownContentHash ?? null;
|
|
113
|
-
const entries = [];
|
|
114
|
-
for (const { files, manifest, ownContentHash } of modules) {
|
|
115
|
-
const contentHash = manifest.checker?.path && canonicalCheckHash
|
|
116
|
-
? sha256(JSON.stringify({ ownContentHash, canonicalCheckHash }))
|
|
117
|
-
: ownContentHash;
|
|
118
|
-
const guidance = files.find((file) => /(^|\/)rule\.md$/u.test(file.path) || /(^|\/)SKILL\.md$/u.test(file.path))?.content ?? '';
|
|
119
|
-
const kind = catalogKind(manifest);
|
|
120
|
-
entries.push({
|
|
121
|
-
id: manifest.id,
|
|
122
|
-
kind,
|
|
123
|
-
version: canonicalVersion(manifest),
|
|
124
|
-
name: title(guidance, manifest.id),
|
|
125
|
-
content: guidance,
|
|
126
|
-
...(kind === 'rule' ? { summary: summary(guidance, manifest.name ?? manifest.id) } : {}),
|
|
127
|
-
...(kind === 'rule' && manifest.category ? { category: String(manifest.category) } : {}),
|
|
128
|
-
...(kind === 'rule' && manifest.scope ? { scope: String(manifest.scope) } : {}),
|
|
129
|
-
group: kind === 'rule' ? 'Rules' : 'Modules',
|
|
130
|
-
order: entries.length + 1,
|
|
131
|
-
source: 'private-devkit-git',
|
|
132
|
-
revision: repositoryRevision,
|
|
133
|
-
contentHash,
|
|
134
|
-
...(kind === 'rule' ? { legacyInstalledIds: legacyImplementationIds(manifest) } : {}),
|
|
135
|
-
...(kind === 'rule' ? { enforcement: String(manifest.enforcement ?? 'guidance') } : {}),
|
|
136
|
-
...(kind === 'rule' && applicableStacks(manifest) ? { applicableStacks: applicableStacks(manifest) } : {}),
|
|
137
|
-
...(kind === 'rule' && stringList(manifest.requiredCapabilities) ? { requiredCapabilities: stringList(manifest.requiredCapabilities) } : {}),
|
|
138
|
-
...(kind === 'rule' && manifest.ai ? { ai: manifest.ai } : {}),
|
|
139
|
-
...(kind === 'rule' && manifest.verification ? { verification: manifest.verification } : {}),
|
|
140
|
-
...(kind === 'rule' && stringList(manifest.composedOf) ? { composedOf: stringList(manifest.composedOf) } : {}),
|
|
141
|
-
...(kind === 'module' && notApplicableRuleIds(manifest)
|
|
142
|
-
? { notApplicableRuleIds: notApplicableRuleIds(manifest) }
|
|
143
|
-
: {}),
|
|
144
|
-
...(kind === 'module' && projectProfiles(manifest)
|
|
145
|
-
? { projectProfiles: projectProfiles(manifest) }
|
|
146
|
-
: {}),
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const ruleIds = new Set(entries.filter((entry) => entry.kind === 'rule').map((entry) => entry.id));
|
|
150
|
-
for (const entry of entries) {
|
|
151
|
-
for (const ruleId of entry.notApplicableRuleIds ?? []) {
|
|
152
|
-
if (!ruleIds.has(ruleId)) throw new Error(`Unknown not-applicable rule: ${entry.id}:${ruleId}`);
|
|
153
|
-
}
|
|
154
|
-
for (const [profileName, definition] of Object.entries(entry.projectProfiles ?? {})) {
|
|
155
|
-
for (const ruleId of definition.ruleIds) {
|
|
156
|
-
if (!ruleIds.has(ruleId)) throw new Error(`Unknown project-profile rule: ${entry.id}:${profileName}:${ruleId}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
for (const childId of entry.composedOf ?? []) {
|
|
160
|
-
if (!ruleIds.has(childId)) throw new Error(`Unknown composed rule: ${entry.id}:${childId}`);
|
|
161
|
-
if (childId === entry.id) throw new Error(`Rule cannot compose itself: ${entry.id}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const composition = new Map(entries.filter((entry) => entry.kind === 'rule').map((entry) => [entry.id, entry.composedOf ?? []]));
|
|
165
|
-
const visiting = new Set();
|
|
166
|
-
const visited = new Set();
|
|
167
|
-
const visit = (id) => {
|
|
168
|
-
if (visiting.has(id)) throw new Error(`Rule composition cycle: ${id}`);
|
|
169
|
-
if (visited.has(id)) return;
|
|
170
|
-
visiting.add(id);
|
|
171
|
-
for (const childId of composition.get(id) ?? []) visit(childId);
|
|
172
|
-
visiting.delete(id);
|
|
173
|
-
visited.add(id);
|
|
174
|
-
};
|
|
175
|
-
for (const id of composition.keys()) visit(id);
|
|
176
|
-
return { schemaVersion: 1, package: { name: '@specdest/devkit', version: repositoryRevision }, entries };
|
|
177
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export * from './catalog.js';
|
|
2
|
-
export * from './canonical-source.js';
|
|
3
|
-
export * from './canonical-project.js';
|
|
4
|
-
export * from './canonical-project-operations.js';
|
|
5
|
-
export * from './installer-primitives.js';
|
|
6
|
-
export * from './project-operations.js';
|
|
7
|
-
export * from './rule-profile.js';
|
|
8
|
-
export * from './remote-installer.js';
|
|
9
|
-
export * from './setup-requirements.js';
|
|
10
|
-
export * from './shared-file.js';
|
|
11
|
-
export * from './sync-core.js';
|
|
12
|
-
export * from './fuzz.js';
|
|
13
|
-
|
|
14
|
-
export const COMMAND_NAMES = ['status', 'sync', 'check', 'rules', 'ai-instruction', 'doctor', 'fuzz'];
|
|
15
|
-
|
|
16
|
-
const HELP = `Usage: specdest <command> [options]\n\nCommands:\n status [--refresh] [--json] Show canonical applicability/install status\n sync Refresh catalog/cache and install/update applicable rules\n check [--refresh] [--staged | --files <path...>] Run canonical checks, optionally targeted\n rules [options] Load applicable rule guidance for AI/task context\n ai-instruction Print the minimal AI bootstrap instruction\n doctor Diagnose project/cache setup\n fuzz Dynamically fuzz Zod contract semantics\n`;
|
|
17
|
-
|
|
18
|
-
export async function runCli(argv, io = process, handlers = {}) {
|
|
19
|
-
const [command, ...args] = argv;
|
|
20
|
-
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
21
|
-
io.stdout.write(HELP);
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
24
|
-
if (!COMMAND_NAMES.includes(command)) {
|
|
25
|
-
io.stderr.write(`Unknown command: ${command}\n\n${HELP}`);
|
|
26
|
-
return 2;
|
|
27
|
-
}
|
|
28
|
-
const handler = handlers[command];
|
|
29
|
-
if (!handler) {
|
|
30
|
-
io.stderr.write(`specdest ${command} is not implemented yet.\n`);
|
|
31
|
-
return 2;
|
|
32
|
-
}
|
|
33
|
-
return await handler(args, io);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export * from './catalog-snapshot.js';
|