@specdest/devkit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/catalog/README.md +11 -0
  2. package/catalog/modules/backend-convex/manifest.json +14 -0
  3. package/catalog/modules/backend-convex-expo/manifest.json +11 -0
  4. package/catalog/modules/backend-supabase/manifest.json +15 -0
  5. package/catalog/modules/backend-supabase-expo/manifest.json +11 -0
  6. package/catalog/modules/checker-runtime/config.ts +24 -0
  7. package/catalog/modules/checker-runtime/fs.ts +47 -0
  8. package/catalog/modules/checker-runtime/manifest.json +23 -0
  9. package/catalog/modules/devflow/.agents/skills/devflow/SKILL.md +33 -0
  10. package/catalog/modules/devflow/.devflow.json +10 -0
  11. package/catalog/modules/devflow/manifest.json +35 -0
  12. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/SKILL.md +85 -0
  13. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/activeScenario.mjs +130 -0
  14. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/checkLocalEnvironment.mjs +7 -0
  15. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/completeActiveScenario.mjs +36 -0
  16. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/createActiveScenario.mjs +143 -0
  17. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/localEnvironment.mjs +43 -0
  18. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/prompt.mjs +25 -0
  19. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runActiveScenario.mjs +66 -0
  20. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runAuthoringScenario.mjs +146 -0
  21. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seed.mjs +56 -0
  22. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seedActiveScenario.mjs +6 -0
  23. package/catalog/modules/e2e-playwright/docs/e2e-playwright/README.md +103 -0
  24. package/catalog/modules/e2e-playwright/manifest.json +206 -0
  25. package/catalog/modules/e2e-playwright/playwright.e2e.config.ts +39 -0
  26. package/catalog/modules/e2e-playwright/tests/e2e/support/e2ePlaywrightFlow.ts +107 -0
  27. package/catalog/modules/e2e-playwright/tests/e2e/support/fixtures.ts +27 -0
  28. package/catalog/modules/local-log/AGENTS.local-log.md +13 -0
  29. package/catalog/modules/local-log/docs/features/local-logging/README.md +70 -0
  30. package/catalog/modules/local-log/manifest.json +39 -0
  31. package/catalog/modules/local-log/tmp/logs/.gitignore +2 -0
  32. package/catalog/modules/local-log/tools/local-log/README.md +47 -0
  33. package/catalog/modules/local-log/tools/local-log/local-log.mjs +241 -0
  34. package/catalog/modules/stack-common-vite/manifest.json +16 -0
  35. package/catalog/modules/stack-expo-convex/manifest.json +31 -0
  36. package/catalog/modules/stack-expo-supabase/manifest.json +44 -0
  37. package/catalog/modules/stack-vite-convex/manifest.json +32 -0
  38. package/catalog/modules/stack-vite-supabase/manifest.json +45 -0
  39. package/catalog/rules/abac-permissions-convex/SKILL.md +17 -0
  40. package/catalog/rules/abac-permissions-convex/check.ts +86 -0
  41. package/catalog/rules/abac-permissions-convex/manifest.json +35 -0
  42. package/catalog/rules/abac-permissions-supabase/SKILL.md +17 -0
  43. package/catalog/rules/abac-permissions-supabase/check.ts +86 -0
  44. package/catalog/rules/abac-permissions-supabase/manifest.json +35 -0
  45. package/catalog/rules/convex-multi-presentation/SKILL.md +48 -0
  46. package/catalog/rules/convex-multi-presentation/boundary-test-baseline.json +3 -0
  47. package/catalog/rules/convex-multi-presentation/check.ts +271 -0
  48. package/catalog/rules/convex-multi-presentation/manifest.json +45 -0
  49. package/catalog/rules/convex-multi-presentation/policy.ts +261 -0
  50. package/catalog/rules/design-rules/SKILL.md +12 -0
  51. package/catalog/rules/design-rules/check.ts +83 -0
  52. package/catalog/rules/design-rules/config.json +5 -0
  53. package/catalog/rules/design-rules/manifest.json +40 -0
  54. package/catalog/rules/e2e-test-rules/SKILL.md +46 -0
  55. package/catalog/rules/e2e-test-rules/check.ts +144 -0
  56. package/catalog/rules/e2e-test-rules/config.json +32 -0
  57. package/catalog/rules/e2e-test-rules/manifest.json +40 -0
  58. package/catalog/rules/error-handling-rules/SKILL.md +21 -0
  59. package/catalog/rules/error-handling-rules/check.ts +72 -0
  60. package/catalog/rules/error-handling-rules/manifest.json +35 -0
  61. package/catalog/rules/layers-and-contracts/SKILL.md +36 -0
  62. package/catalog/rules/layers-and-contracts/check.ts +265 -0
  63. package/catalog/rules/layers-and-contracts/manifest.json +35 -0
  64. package/catalog/rules/layers-and-contracts-convex/SKILL.md +49 -0
  65. package/catalog/rules/layers-and-contracts-convex/check.ts +288 -0
  66. package/catalog/rules/layers-and-contracts-convex/manifest.json +40 -0
  67. package/catalog/rules/layers-and-contracts-convex/policy.ts +68 -0
  68. package/catalog/rules/layers-and-contracts-supabase/SKILL.md +52 -0
  69. package/catalog/rules/layers-and-contracts-supabase/check.ts +370 -0
  70. package/catalog/rules/layers-and-contracts-supabase/manifest.json +40 -0
  71. package/catalog/rules/layers-and-contracts-supabase/policy.ts +68 -0
  72. package/catalog/rules/module-size-rules/SKILL.md +5 -0
  73. package/catalog/rules/module-size-rules/check.ts +143 -0
  74. package/catalog/rules/module-size-rules/config.json +6 -0
  75. package/catalog/rules/module-size-rules/manifest.json +40 -0
  76. package/catalog/rules/module-size-rules-convex/SKILL.md +5 -0
  77. package/catalog/rules/module-size-rules-convex/check.ts +145 -0
  78. package/catalog/rules/module-size-rules-convex/config.json +6 -0
  79. package/catalog/rules/module-size-rules-convex/manifest.json +40 -0
  80. package/catalog/rules/module-size-rules-supabase/SKILL.md +5 -0
  81. package/catalog/rules/module-size-rules-supabase/check.ts +145 -0
  82. package/catalog/rules/module-size-rules-supabase/config.json +12 -0
  83. package/catalog/rules/module-size-rules-supabase/manifest.json +40 -0
  84. package/catalog/rules/mutation-command-rules/SKILL.md +15 -0
  85. package/catalog/rules/mutation-command-rules/check.ts +29 -0
  86. package/catalog/rules/mutation-command-rules/config.json +19 -0
  87. package/catalog/rules/mutation-command-rules/manifest.json +40 -0
  88. package/catalog/rules/nearby-contracts/SKILL.md +18 -0
  89. package/catalog/rules/nearby-contracts/check.ts +137 -0
  90. package/catalog/rules/nearby-contracts/config.json +10 -0
  91. package/catalog/rules/nearby-contracts/manifest.json +40 -0
  92. package/catalog/rules/no-raw-click-buttons/SKILL.md +5 -0
  93. package/catalog/rules/no-raw-click-buttons/check.ts +36 -0
  94. package/catalog/rules/no-raw-click-buttons/manifest.json +35 -0
  95. package/catalog/rules/public-api-export-barrels/SKILL.md +45 -0
  96. package/catalog/rules/public-api-export-barrels/check.ts +72 -0
  97. package/catalog/rules/public-api-export-barrels/config.json +4 -0
  98. package/catalog/rules/public-api-export-barrels/manifest.json +40 -0
  99. package/catalog/rules/route-tree-fresh/SKILL.md +16 -0
  100. package/catalog/rules/route-tree-fresh/check.ts +64 -0
  101. package/catalog/rules/route-tree-fresh/manifest.json +35 -0
  102. package/catalog/rules/strict-typescript/SKILL.md +3 -0
  103. package/catalog/rules/strict-typescript/check.ts +111 -0
  104. package/catalog/rules/strict-typescript/manifest.json +35 -0
  105. package/catalog/rules/supabase-contracts/SKILL.md +3 -0
  106. package/catalog/rules/supabase-contracts/check.ts +171 -0
  107. package/catalog/rules/supabase-contracts/manifest.json +35 -0
  108. package/catalog/rules/supabase-declarative-schema/SKILL.md +30 -0
  109. package/catalog/rules/supabase-declarative-schema/check.ts +261 -0
  110. package/catalog/rules/supabase-declarative-schema/config.json +8 -0
  111. package/catalog/rules/supabase-declarative-schema/manifest.json +40 -0
  112. package/catalog/rules/tanstack-form-rules/SKILL.md +11 -0
  113. package/catalog/rules/tanstack-form-rules/check.ts +57 -0
  114. package/catalog/rules/tanstack-form-rules/manifest.json +35 -0
  115. package/catalog/rules/unit-test-rules/SKILL.md +55 -0
  116. package/catalog/rules/unit-test-rules/check.ts +131 -0
  117. package/catalog/rules/unit-test-rules/config.json +22 -0
  118. package/catalog/rules/unit-test-rules/manifest.json +40 -0
  119. package/catalog/rules/unit-test-rules-convex/SKILL.md +41 -0
  120. package/catalog/rules/unit-test-rules-convex/check.ts +417 -0
  121. package/catalog/rules/unit-test-rules-convex/manifest.json +35 -0
  122. package/catalog/rules/unit-test-rules-supabase/SKILL.md +40 -0
  123. package/catalog/rules/unit-test-rules-supabase/check.ts +491 -0
  124. package/catalog/rules/unit-test-rules-supabase/manifest.json +35 -0
  125. package/catalog/rules/workstation-controller-rules/SKILL.md +22 -0
  126. package/catalog/rules/workstation-controller-rules/check.ts +107 -0
  127. package/catalog/rules/workstation-controller-rules/manifest.json +35 -0
  128. package/package.json +22 -0
  129. package/src/catalog-snapshot.js +39 -0
  130. package/src/catalog.js +117 -0
  131. package/src/cli.js +11 -0
  132. package/src/index.js +30 -0
  133. package/src/installer-primitives.js +198 -0
  134. package/src/project-operations.js +126 -0
  135. package/src/setup-requirements.js +82 -0
  136. package/src/shared-file.js +131 -0
  137. package/src/sync-core.js +276 -0
@@ -0,0 +1,417 @@
1
+ // oxlint-disable no-console no-await-in-loop
2
+ const violations: string[] = [];
3
+ const requiredDataDisplayStories = ["Empty", "Loading", "MinimumData", "FullData"] as const;
4
+ const requiredFormStories = [
5
+ { name: "EmptyDisplay", label: "empty display", submitsValues: false },
6
+ { name: "EmptySubmit", label: "empty submit", submitsValues: true, allowsNoSubmit: true },
7
+ {
8
+ name: "MinimalRightDataSubmit",
9
+ label: "minimal right data submit",
10
+ submitsValues: true,
11
+ },
12
+ {
13
+ name: "AllFieldRightDataSubmit",
14
+ label: "all field right data submit",
15
+ submitsValues: true,
16
+ },
17
+ {
18
+ name: "AllFieldBadDataSubmit",
19
+ label: "all field bad data submit",
20
+ submitsValues: true,
21
+ allowsNoSubmit: true,
22
+ },
23
+ {
24
+ name: "FullInitialValueDisplay",
25
+ label: "full initial value display",
26
+ submitsValues: false,
27
+ },
28
+ ] as const;
29
+ const zodSchemaFactories = [
30
+ "object",
31
+ "string",
32
+ "number",
33
+ "boolean",
34
+ "array",
35
+ "enum",
36
+ "union",
37
+ "discriminatedUnion",
38
+ "record",
39
+ "tuple",
40
+ "literal",
41
+ "nativeEnum",
42
+ "date",
43
+ "coerce",
44
+ "preprocess",
45
+ "custom",
46
+ "instanceof",
47
+ "promise",
48
+ "map",
49
+ "set",
50
+ "bigint",
51
+ "any",
52
+ "unknown",
53
+ "never",
54
+ ] as const;
55
+
56
+ async function exists(path: string): Promise<boolean> {
57
+ try {
58
+ await Deno.stat(path);
59
+ return true;
60
+ } catch {
61
+ return false;
62
+ }
63
+ }
64
+
65
+ async function* walk(dir: string): AsyncGenerator<string> {
66
+ try {
67
+ for await (const entry of Deno.readDir(dir)) {
68
+ const path = dir + "/" + entry.name;
69
+ if (entry.isDirectory) yield* walk(path);
70
+ if (entry.isFile) yield path;
71
+ }
72
+ } catch {
73
+ return;
74
+ }
75
+ }
76
+
77
+ function isImplementation(file: string): boolean {
78
+ return (
79
+ /\.(ts|tsx)$/.test(file) &&
80
+ !file.endsWith(".test.ts") &&
81
+ !file.endsWith(".test.tsx") &&
82
+ !file.endsWith(".stories.tsx") &&
83
+ !file.endsWith(".input.schema.ts") &&
84
+ !file.endsWith(".output.schema.ts") &&
85
+ !file.endsWith(".callbackInput.schema.ts") &&
86
+ !file.endsWith(".form.schema.ts") &&
87
+ !file.endsWith("routeTree.gen.ts")
88
+ );
89
+ }
90
+
91
+ function isRouteUiComponent(file: string): boolean {
92
+ return file.includes("/-components/ui/") && file.endsWith(".tsx") && isImplementation(file);
93
+ }
94
+
95
+ function isSharedUiComponent(file: string): boolean {
96
+ return (
97
+ file.startsWith("src/components/general/") && file.endsWith(".tsx") && isImplementation(file)
98
+ );
99
+ }
100
+
101
+ function isUiComponent(file: string): boolean {
102
+ return isRouteUiComponent(file) || isSharedUiComponent(file);
103
+ }
104
+
105
+ function isPageDataDisplayUi(file: string, source: string): boolean {
106
+ if (!file.startsWith("src/routes/") || !file.includes("/-components/ui/")) {
107
+ return false;
108
+ }
109
+ return (
110
+ /\bdata\./u.test(source) ||
111
+ /\bitems\./u.test(source) ||
112
+ /\brows\./u.test(source) ||
113
+ source.includes("<table")
114
+ );
115
+ }
116
+
117
+ function isPageFormUi(file: string, source: string): boolean {
118
+ return (
119
+ file.startsWith("src/routes/") && file.includes("/-components/ui/") && /<form\b/u.test(source)
120
+ );
121
+ }
122
+
123
+ function hasStoryExport(storyText: string, storyName: string): boolean {
124
+ return storyText.includes(`export const ${storyName}`);
125
+ }
126
+
127
+ function storyExportBlock(storyText: string, storyName: string): string | null {
128
+ const start = storyText.indexOf(`export const ${storyName}`);
129
+ if (start < 0) return null;
130
+ const rest = storyText.slice(start + `export const ${storyName}`.length);
131
+ const next = rest.search(/\nexport const \w+\b|\nexport default\b/u);
132
+ return next < 0
133
+ ? storyText.slice(start)
134
+ : storyText.slice(start, start + `export const ${storyName}`.length + next);
135
+ }
136
+
137
+ function storyPathFor(file: string): string {
138
+ return file.replace(/\.tsx$/, ".stories.tsx");
139
+ }
140
+
141
+ function inputSchemaPathFor(file: string): string {
142
+ return file.replace(/\.tsx$/, ".input.schema.ts");
143
+ }
144
+
145
+ function hasVisiblePlayAssertion(storyText: string): boolean {
146
+ return (
147
+ storyText.includes("expect(") &&
148
+ (storyText.includes("getByRole(") ||
149
+ storyText.includes("findByRole(") ||
150
+ storyText.includes("getByText(") ||
151
+ storyText.includes("findByText(") ||
152
+ storyText.includes("getByLabelText(") ||
153
+ storyText.includes("findByLabelText(") ||
154
+ storyText.includes("getByPlaceholderText(") ||
155
+ storyText.includes("findByPlaceholderText(") ||
156
+ storyText.includes("getByTestId(") ||
157
+ storyText.includes("findByTestId("))
158
+ );
159
+ }
160
+
161
+ function isStorybookFile(file: string): boolean {
162
+ return file.endsWith(".stories.tsx");
163
+ }
164
+
165
+ function importsZod(text: string): boolean {
166
+ return /from\s+["']zod["']/u.test(text);
167
+ }
168
+
169
+ function definesLocalZodSchema(text: string): boolean {
170
+ return zodSchemaFactories.some((factory) =>
171
+ new RegExp(`\\bz\\.${factory}\\s*\\(`, "u").test(text),
172
+ );
173
+ }
174
+
175
+ function schemaImportSpecs(text: string): string[] {
176
+ const specs: string[] = [];
177
+ for (const match of text.matchAll(/from\s+["']([^"']*\.schema)["']/gu)) {
178
+ if (match[1]) specs.push(match[1]);
179
+ }
180
+ for (const match of text.matchAll(/import\(["']([^"']*\.schema)["']\)/gu)) {
181
+ if (match[1]) specs.push(match[1]);
182
+ }
183
+ return specs;
184
+ }
185
+
186
+ function isStorybookOnlySchemaSpec(spec: string): boolean {
187
+ return (
188
+ spec.includes("story.schema") ||
189
+ spec.includes("stories.schema") ||
190
+ spec.includes("storybook.schema") ||
191
+ spec.includes("__stories__") ||
192
+ spec.includes("storybook/")
193
+ );
194
+ }
195
+
196
+ function importsProductionSchema(text: string): boolean {
197
+ return schemaImportSpecs(text).some(
198
+ (spec) => spec.length > 0 && !isStorybookOnlySchemaSpec(spec),
199
+ );
200
+ }
201
+
202
+ function importsStorybookOnlySchema(text: string): boolean {
203
+ return schemaImportSpecs(text).some((spec) => spec.length > 0 && isStorybookOnlySchemaSpec(spec));
204
+ }
205
+
206
+ function usesSchemaParse(text: string): boolean {
207
+ return (
208
+ /\b\w*schema\w*\.(safeParse|parse)\s*\(/iu.test(text) ||
209
+ /\b\w*Schema\w*\.(safeParse|parse)\s*\(/u.test(text)
210
+ );
211
+ }
212
+
213
+ function hasSchemaBackedArgs(storyText: string): boolean {
214
+ return importsProductionSchema(storyText) && usesSchemaParse(storyText);
215
+ }
216
+
217
+ function hasStoryPlay(storyText: string, storyName: string, storyBlock: string): boolean {
218
+ return /\bplay\s*:/u.test(storyBlock) || storyText.includes(`${storyName}.play`);
219
+ }
220
+
221
+ function hasSubmitInteraction(storyBlock: string): boolean {
222
+ return (
223
+ /\buserEvent\b/u.test(storyBlock) &&
224
+ /\.(click|type|clear|selectOptions|keyboard)\s*\(/u.test(storyBlock)
225
+ );
226
+ }
227
+
228
+ function hasExactSubmitValueAssertion(storyBlock: string): boolean {
229
+ return (
230
+ /\btoStrictEqual\s*\(/u.test(storyBlock) || /\btoHaveBeenCalledWith\s*\(/u.test(storyBlock)
231
+ );
232
+ }
233
+
234
+ function hasNoSubmitAssertion(storyBlock: string): boolean {
235
+ return /\bnot\.toHaveBeenCalled\s*\(\s*\)/u.test(storyBlock);
236
+ }
237
+
238
+ function hasLenientValueMatcher(storyBlock: string): boolean {
239
+ return (
240
+ /\b(objectContaining|arrayContaining)\s*\(/u.test(storyBlock) ||
241
+ /\bexpect\.(any|anything)\s*\(/u.test(storyBlock)
242
+ );
243
+ }
244
+
245
+ function testPathFor(file: string): string {
246
+ return file.replace(/\.(ts|tsx)$/, ".test.$1");
247
+ }
248
+
249
+ function basenameWithoutExtension(file: string): string {
250
+ return (
251
+ file
252
+ .split("/")
253
+ .at(-1)
254
+ ?.replace(/\.(ts|tsx)$/, "") ?? file
255
+ );
256
+ }
257
+
258
+ async function readAllTests(root: string): Promise<string> {
259
+ const texts: string[] = [];
260
+ for await (const file of walk(root)) {
261
+ if (file.endsWith(".test.ts") || file.endsWith(".test.tsx")) {
262
+ texts.push(await Deno.readTextFile(file));
263
+ }
264
+ }
265
+ return texts.join("\n");
266
+ }
267
+
268
+ if (!(await exists("src"))) violations.push("missing src directory");
269
+ if (!(await exists(".storybook/main.ts"))) {
270
+ violations.push("missing Storybook config: .storybook/main.ts");
271
+ }
272
+ if (!(await exists(".storybook/vitest.setup.ts"))) {
273
+ violations.push("missing Storybook Vitest setup: .storybook/vitest.setup.ts");
274
+ }
275
+
276
+ const routeTests = await readAllTests("src/routes");
277
+
278
+ for await (const file of walk("src")) {
279
+ if (isStorybookFile(file)) {
280
+ const storyText = await Deno.readTextFile(file);
281
+ if (importsZod(storyText) || definesLocalZodSchema(storyText)) {
282
+ violations.push(
283
+ file +
284
+ ": Storybook stories must use real production Zod schemas; do not import zod or define story-local schemas",
285
+ );
286
+ }
287
+ if (importsStorybookOnlySchema(storyText)) {
288
+ violations.push(file + ": Storybook stories must not import storybook-only schema files");
289
+ }
290
+ }
291
+
292
+ if (isUiComponent(file)) {
293
+ const storyPath = storyPathFor(file);
294
+ if (!(await exists(storyPath))) {
295
+ violations.push(file + ": UI components must have a colocated Storybook story: " + storyPath);
296
+ continue;
297
+ }
298
+
299
+ const sourceText = await Deno.readTextFile(file);
300
+ const storyText = await Deno.readTextFile(storyPath);
301
+ if (!/\bplay\s*:/u.test(storyText) && !/\.play\s*=/u.test(storyText)) {
302
+ violations.push(storyPath + ": Storybook stories must include a play test");
303
+ }
304
+ if (/story contract|placeholder story/iu.test(storyText)) {
305
+ violations.push(
306
+ storyPath + ": Storybook stories must render the real UI, not a placeholder contract",
307
+ );
308
+ }
309
+ if (!hasVisiblePlayAssertion(storyText)) {
310
+ violations.push(
311
+ storyPath + ": Storybook play tests must assert visible UI with Testing Library queries",
312
+ );
313
+ }
314
+ if (isPageDataDisplayUi(file, sourceText)) {
315
+ const missingStories = requiredDataDisplayStories.filter(
316
+ (storyName) => !hasStoryExport(storyText, storyName),
317
+ );
318
+ if (missingStories.length > 0) {
319
+ violations.push(
320
+ storyPath +
321
+ ": data display UI stories must export Empty, Loading, MinimumData, and FullData. Missing: " +
322
+ missingStories.join(", "),
323
+ );
324
+ }
325
+ }
326
+ if (await exists(inputSchemaPathFor(file))) {
327
+ if (!hasSchemaBackedArgs(storyText)) {
328
+ violations.push(
329
+ storyPath +
330
+ ": Storybook stories for schema-backed UI must import a production schema and parse args or fixtures through it",
331
+ );
332
+ }
333
+ }
334
+ if (isPageFormUi(file, sourceText) && sourceText.includes("<DevFormFillButtons")) {
335
+ for (const contract of requiredFormStories) {
336
+ const storyBlock = storyExportBlock(storyText, contract.name);
337
+ if (!storyBlock) {
338
+ violations.push(
339
+ storyPath +
340
+ `: page-local form stories must export ${contract.name} (${contract.label})`,
341
+ );
342
+ continue;
343
+ }
344
+ if (!hasStoryPlay(storyText, contract.name, storyBlock)) {
345
+ violations.push(
346
+ storyPath + `: ${contract.name} must include its own Storybook play test`,
347
+ );
348
+ }
349
+ if (!contract.submitsValues) continue;
350
+ if (!hasSubmitInteraction(storyBlock)) {
351
+ violations.push(
352
+ storyPath + `: ${contract.name} must submit through a userEvent play interaction`,
353
+ );
354
+ }
355
+ const assertsOneSubmit = /\btoHaveBeenCalledTimes\s*\(\s*1\s*\)/u.test(storyBlock);
356
+ const assertsNoSubmit = hasNoSubmitAssertion(storyBlock);
357
+ if (
358
+ !assertsOneSubmit &&
359
+ !("allowsNoSubmit" in contract && contract.allowsNoSubmit && assertsNoSubmit)
360
+ ) {
361
+ violations.push(
362
+ storyPath +
363
+ `: ${contract.name} must assert either exactly one submit call or, for invalid values, no submit call`,
364
+ );
365
+ }
366
+ if (assertsOneSubmit && !hasExactSubmitValueAssertion(storyBlock)) {
367
+ violations.push(
368
+ storyPath +
369
+ `: ${contract.name} must assert exact submitted values with toStrictEqual or toHaveBeenCalledWith`,
370
+ );
371
+ }
372
+ if (hasLenientValueMatcher(storyBlock)) {
373
+ violations.push(
374
+ storyPath +
375
+ `: ${contract.name} must not use lenient value matchers for submitted values`,
376
+ );
377
+ }
378
+ }
379
+ }
380
+ }
381
+
382
+ if (!isImplementation(file)) continue;
383
+
384
+ if (file.includes("/-components/container/") && file.endsWith(".tsx")) {
385
+ const testPath = testPathFor(file);
386
+ const boundaryTestPath = file.replace(/\.tsx$/u, ".boundary.test.tsx");
387
+ if (!(await exists(testPath)) && !(await exists(boundaryTestPath))) {
388
+ violations.push(
389
+ file +
390
+ ": container components must have a colocated unit/component test: " +
391
+ testPath +
392
+ " or " +
393
+ boundaryTestPath,
394
+ );
395
+ }
396
+ }
397
+
398
+ if (file.includes("/-components/ui-hooks/") && file.endsWith(".ts")) {
399
+ const testPath = testPathFor(file);
400
+ if (!(await exists(testPath))) {
401
+ violations.push(file + ": UI hooks must have a colocated unit test: " + testPath);
402
+ }
403
+ }
404
+
405
+ if (file.includes("/-components/data-hooks/") && file.endsWith(".ts")) {
406
+ const name = basenameWithoutExtension(file);
407
+ if (!routeTests.includes(name)) {
408
+ violations.push(file + ": data hooks must be referenced by a route-layer unit test");
409
+ }
410
+ }
411
+ }
412
+
413
+ if (violations.length) {
414
+ console.error(violations.join("\n"));
415
+ Deno.exit(1);
416
+ }
417
+ console.log("unit-test-rules ok");
@@ -0,0 +1,35 @@
1
+ {
2
+ "id": "unit-test-rules-convex",
3
+ "kind": "rule",
4
+ "version": "1.0.1",
5
+ "requires": [
6
+ "checker-runtime"
7
+ ],
8
+ "artifacts": [
9
+ {
10
+ "kind": "managed-file",
11
+ "path": ".agents/skills/unit-test-rules/SKILL.md",
12
+ "source": "SKILL.md"
13
+ },
14
+ {
15
+ "kind": "managed-file",
16
+ "path": ".agents/skills/unit-test-rules/check.ts",
17
+ "source": "check.ts"
18
+ },
19
+ {
20
+ "kind": "shared-markdown-section",
21
+ "path": "AGENTS.md",
22
+ "heading": "## Specdest backend rule: unit-test-rules",
23
+ "body": "Use `.agents/skills/unit-test-rules/SKILL.md` for this backend-specific rule. Run `deno run --allow-read .agents/skills/unit-test-rules/check.ts` before handoff."
24
+ }
25
+ ],
26
+ "obsolete": [],
27
+ "check": {
28
+ "command": [
29
+ "deno",
30
+ "run",
31
+ "--allow-read",
32
+ ".agents/skills/unit-test-rules/check.ts"
33
+ ]
34
+ }
35
+ }
@@ -0,0 +1,40 @@
1
+ # Unit test rules
2
+
3
+ Unit tests should verify one file's responsibility only. Layer tests should use
4
+ input contract -> layer logic -> output contract.
5
+
6
+ ## Enforced coverage
7
+
8
+ The checker at `check.ts` enforces these generated-project rules:
9
+
10
+ - Route UI components under `src/**/{-components,_components}/ui/` and public wrappers under `src/components/general/` must have a colocated Storybook story. Bulk generated shadcn primitives under `src/components/ui/` are exempt until adopted as application-facing wrappers.
11
+ - UI stories must include a `play` test with visible Testing Library assertions
12
+ so component states are executable, not only visual examples.
13
+ - UI stories must render the real component, not placeholder contract text.
14
+ - Enforced route/public UI stories must not import `zod`, define story-local Zod schemas, or
15
+ import storybook-only schema files such as `story.schema`, `stories.schema`,
16
+ or `storybook.schema`. Generic component-library demo stories outside these governed UI surfaces are exempt.
17
+ - Schema-backed UI stories must import production `*.schema` files and parse
18
+ args or fixtures through the real schema with `.parse()` or `.safeParse()`.
19
+ - Page-local UI components that display data collections and own a loading state must include these
20
+ Storybook states: `Empty`, `Loading`, `MinimumData`, and `FullData`.
21
+ - Page-local forms using `DevFormFillButtons` must export `EmptyDisplay`, `EmptySubmit`, `MinimalRightDataSubmit`, `AllFieldRightDataSubmit`, `AllFieldBadDataSubmit`, and `FullInitialValueDisplay`.
22
+ - Every required form story must have its own `play` test. Submit stories must
23
+ submit through `userEvent`; valid-submit stories assert exactly one submit call and compare the
24
+ complete submitted value object with `toStrictEqual` or
25
+ `toHaveBeenCalledWith`; do not use lenient matchers such as
26
+ `objectContaining`, `arrayContaining`, `expect.any`, or `expect.anything` for
27
+ submitted values. Invalid-submit stories must assert zero submit calls.
28
+ - Container components under `src/**/{-components,_components}/container/` must have colocated
29
+ unit/component tests.
30
+ - UI hooks under `src/**/{-components,_components}/ui-hooks/` must have colocated unit tests.
31
+ - Data hooks under `src/**/{-components,_components}/data-hooks/` must be referenced by
32
+ route-layer unit tests.
33
+ - DAL query and mutation files under `src/dal/**/{queries,mutations}/` must be
34
+ referenced by DAL unit or contract tests.
35
+
36
+ ## Script wiring
37
+
38
+ Run `nps lint.unitTestRules` for this checker directly. It is also part of
39
+ `nps lint.raw`, so `nps lint`, `nps check`, and the generated Husky pre-commit
40
+ hook all enforce these rules.