@rawsql-ts/ztd-cli 0.16.0 → 0.19.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 (242) hide show
  1. package/README.md +532 -353
  2. package/package.json +35 -17
  3. package/templates/.editorconfig +16 -16
  4. package/templates/.prettierignore +2 -2
  5. package/templates/.prettierrc +24 -24
  6. package/templates/AGENTS.md +30 -325
  7. package/templates/CONTEXT.md +11 -0
  8. package/templates/CONTEXT.webapi.md +11 -0
  9. package/templates/DESIGN.md +17 -0
  10. package/templates/DEV_NOTES.md +14 -0
  11. package/templates/PROMPT_DOGFOOD.webapi.md +49 -0
  12. package/templates/README.md +46 -217
  13. package/templates/README.webapi.md +38 -0
  14. package/templates/scripts/local-source-guard.mjs +189 -0
  15. package/templates/src/AGENTS.md +26 -0
  16. package/templates/src/application/AGENTS.md +15 -0
  17. package/templates/src/application/README.md +6 -0
  18. package/templates/src/catalog/AGENTS.md +28 -0
  19. package/templates/src/catalog/runtime/AGENTS.md +28 -0
  20. package/templates/src/catalog/runtime/_coercions.local-source.ts +30 -0
  21. package/templates/src/catalog/runtime/_coercions.ts +30 -0
  22. package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
  23. package/templates/src/catalog/specs/AGENTS.md +41 -0
  24. package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
  25. package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
  26. package/templates/src/db/sql-client-adapters.ts +32 -0
  27. package/templates/src/db/sql-client.ts +24 -24
  28. package/templates/src/domain/AGENTS.md +15 -0
  29. package/templates/src/domain/README.md +6 -0
  30. package/templates/src/infrastructure/AGENTS.md +14 -0
  31. package/templates/src/infrastructure/README.md +6 -0
  32. package/templates/src/infrastructure/db/AGENTS.md +14 -0
  33. package/templates/src/infrastructure/db/sql-client-adapters.ts +34 -0
  34. package/templates/src/infrastructure/db/sql-client.ts +24 -0
  35. package/templates/src/infrastructure/persistence/AGENTS.md +18 -0
  36. package/templates/src/infrastructure/persistence/README.md +8 -0
  37. package/templates/src/infrastructure/persistence/repositories/AGENTS.md +17 -0
  38. package/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md +20 -0
  39. package/templates/src/infrastructure/persistence/repositories/tables/README.md +5 -0
  40. package/templates/src/infrastructure/persistence/repositories/views/AGENTS.md +16 -0
  41. package/templates/src/infrastructure/persistence/repositories/views/README.md +5 -0
  42. package/templates/src/infrastructure/telemetry/AGENTS.md +14 -0
  43. package/templates/src/infrastructure/telemetry/consoleRepositoryTelemetry.ts +66 -0
  44. package/templates/src/infrastructure/telemetry/repositoryTelemetry.ts +26 -0
  45. package/templates/src/infrastructure/telemetry/types.ts +48 -0
  46. package/templates/src/jobs/AGENTS.md +25 -0
  47. package/templates/src/jobs/README.md +3 -0
  48. package/templates/src/local/sql-contract.ts +1 -0
  49. package/templates/src/presentation/AGENTS.md +15 -0
  50. package/templates/src/presentation/http/AGENTS.md +15 -0
  51. package/templates/src/presentation/http/README.md +6 -0
  52. package/templates/src/repositories/AGENTS.md +30 -0
  53. package/templates/src/repositories/tables/AGENTS.md +29 -0
  54. package/templates/src/repositories/tables/README.md +5 -0
  55. package/templates/src/repositories/views/AGENTS.md +25 -0
  56. package/templates/src/repositories/views/README.md +5 -0
  57. package/templates/src/sql/AGENTS.md +30 -0
  58. package/templates/src/sql/README.md +6 -0
  59. package/templates/tests/AGENTS.md +29 -169
  60. package/templates/tests/generated/AGENTS.md +23 -0
  61. package/templates/tests/smoke.test.ts +25 -0
  62. package/templates/tests/smoke.validation.test.ts +34 -0
  63. package/templates/tests/support/AGENTS.md +24 -0
  64. package/templates/tests/support/global-setup.ts +15 -30
  65. package/templates/tests/support/testkit-client.ts +14 -742
  66. package/templates/tests/support/testkit-client.webapi.ts +14 -0
  67. package/templates/tests/ztd-layout.generated.ts +6 -6
  68. package/templates/tsconfig.json +15 -8
  69. package/templates/vitest.config.ts +13 -13
  70. package/templates/ztd/AGENTS.md +23 -74
  71. package/templates/ztd/README.md +6 -15
  72. package/templates/ztd/ddl/AGENTS.md +26 -0
  73. package/templates/ztd/ddl/demo.sql +74 -0
  74. package/LICENSE +0 -21
  75. package/dist/commands/ddl.d.ts +0 -7
  76. package/dist/commands/ddl.js +0 -118
  77. package/dist/commands/ddl.js.map +0 -1
  78. package/dist/commands/diff.d.ts +0 -10
  79. package/dist/commands/diff.js +0 -38
  80. package/dist/commands/diff.js.map +0 -1
  81. package/dist/commands/genEntities.d.ts +0 -6
  82. package/dist/commands/genEntities.js +0 -50
  83. package/dist/commands/genEntities.js.map +0 -1
  84. package/dist/commands/init.d.ts +0 -66
  85. package/dist/commands/init.js +0 -838
  86. package/dist/commands/init.js.map +0 -1
  87. package/dist/commands/lint.d.ts +0 -59
  88. package/dist/commands/lint.js +0 -338
  89. package/dist/commands/lint.js.map +0 -1
  90. package/dist/commands/options.d.ts +0 -9
  91. package/dist/commands/options.js +0 -48
  92. package/dist/commands/options.js.map +0 -1
  93. package/dist/commands/pull.d.ts +0 -10
  94. package/dist/commands/pull.js +0 -105
  95. package/dist/commands/pull.js.map +0 -1
  96. package/dist/commands/ztdConfig.d.ts +0 -23
  97. package/dist/commands/ztdConfig.js +0 -202
  98. package/dist/commands/ztdConfig.js.map +0 -1
  99. package/dist/commands/ztdConfigCommand.d.ts +0 -5
  100. package/dist/commands/ztdConfigCommand.js +0 -157
  101. package/dist/commands/ztdConfigCommand.js.map +0 -1
  102. package/dist/index.d.ts +0 -2
  103. package/dist/index.js +0 -22
  104. package/dist/index.js.map +0 -1
  105. package/dist/utils/agents.d.ts +0 -1
  106. package/dist/utils/agents.js +0 -48
  107. package/dist/utils/agents.js.map +0 -1
  108. package/dist/utils/collectSqlFiles.d.ts +0 -9
  109. package/dist/utils/collectSqlFiles.js +0 -58
  110. package/dist/utils/collectSqlFiles.js.map +0 -1
  111. package/dist/utils/connectionSummary.d.ts +0 -3
  112. package/dist/utils/connectionSummary.js +0 -29
  113. package/dist/utils/connectionSummary.js.map +0 -1
  114. package/dist/utils/dbConnection.d.ts +0 -29
  115. package/dist/utils/dbConnection.js +0 -210
  116. package/dist/utils/dbConnection.js.map +0 -1
  117. package/dist/utils/fs.d.ts +0 -1
  118. package/dist/utils/fs.js +0 -12
  119. package/dist/utils/fs.js.map +0 -1
  120. package/dist/utils/normalizePulledSchema.d.ts +0 -12
  121. package/dist/utils/normalizePulledSchema.js +0 -213
  122. package/dist/utils/normalizePulledSchema.js.map +0 -1
  123. package/dist/utils/pgDump.d.ts +0 -11
  124. package/dist/utils/pgDump.js +0 -55
  125. package/dist/utils/pgDump.js.map +0 -1
  126. package/dist/utils/sqlLintHelpers.d.ts +0 -18
  127. package/dist/utils/sqlLintHelpers.js +0 -270
  128. package/dist/utils/sqlLintHelpers.js.map +0 -1
  129. package/dist/utils/typeMapper.d.ts +0 -4
  130. package/dist/utils/typeMapper.js +0 -76
  131. package/dist/utils/typeMapper.js.map +0 -1
  132. package/dist/utils/ztdProjectConfig.d.ts +0 -40
  133. package/dist/utils/ztdProjectConfig.js +0 -167
  134. package/dist/utils/ztdProjectConfig.js.map +0 -1
  135. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +0 -38
  136. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +0 -117
  137. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +0 -1
  138. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +0 -4
  139. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +0 -71
  140. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +0 -1
  141. package/templates/dist/drivers/pg-testkit/src/index.d.ts +0 -5
  142. package/templates/dist/drivers/pg-testkit/src/index.js +0 -11
  143. package/templates/dist/drivers/pg-testkit/src/index.js.map +0 -1
  144. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +0 -3
  145. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +0 -79
  146. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +0 -1
  147. package/templates/dist/drivers/pg-testkit/src/types.d.ts +0 -69
  148. package/templates/dist/drivers/pg-testkit/src/types.js +0 -3
  149. package/templates/dist/drivers/pg-testkit/src/types.js.map +0 -1
  150. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +0 -15
  151. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +0 -34
  152. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +0 -1
  153. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +0 -12
  154. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +0 -53
  155. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +0 -1
  156. package/templates/dist/mapper-core/src/index.d.ts +0 -160
  157. package/templates/dist/mapper-core/src/index.js +0 -637
  158. package/templates/dist/mapper-core/src/index.js.map +0 -1
  159. package/templates/dist/testkit-core/src/errors/index.d.ts +0 -49
  160. package/templates/dist/testkit-core/src/errors/index.js +0 -111
  161. package/templates/dist/testkit-core/src/errors/index.js.map +0 -1
  162. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +0 -5
  163. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +0 -29
  164. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +0 -1
  165. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +0 -37
  166. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +0 -182
  167. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +0 -1
  168. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +0 -20
  169. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +0 -121
  170. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +0 -1
  171. package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +0 -51
  172. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +0 -199
  173. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +0 -1
  174. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +0 -10
  175. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +0 -28
  176. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +0 -1
  177. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +0 -18
  178. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +0 -80
  179. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +0 -1
  180. package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +0 -59
  181. package/templates/dist/testkit-core/src/fixtures/ddlLint.js +0 -489
  182. package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +0 -1
  183. package/templates/dist/testkit-core/src/fixtures/naming.d.ts +0 -1
  184. package/templates/dist/testkit-core/src/fixtures/naming.js +0 -6
  185. package/templates/dist/testkit-core/src/fixtures/naming.js.map +0 -1
  186. package/templates/dist/testkit-core/src/index.d.ts +0 -17
  187. package/templates/dist/testkit-core/src/index.js +0 -47
  188. package/templates/dist/testkit-core/src/index.js.map +0 -1
  189. package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +0 -8
  190. package/templates/dist/testkit-core/src/logger/NoopLogger.js +0 -16
  191. package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +0 -1
  192. package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +0 -57
  193. package/templates/dist/testkit-core/src/provider/TestkitProvider.js +0 -149
  194. package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +0 -1
  195. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +0 -43
  196. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +0 -473
  197. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +0 -1
  198. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +0 -9
  199. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +0 -38
  200. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +0 -1
  201. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +0 -42
  202. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +0 -298
  203. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +0 -1
  204. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +0 -12
  205. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +0 -63
  206. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +0 -1
  207. package/templates/dist/testkit-core/src/types/index.d.ts +0 -69
  208. package/templates/dist/testkit-core/src/types/index.js +0 -3
  209. package/templates/dist/testkit-core/src/types/index.js.map +0 -1
  210. package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +0 -28
  211. package/templates/dist/testkit-core/src/utils/queryHelpers.js +0 -81
  212. package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +0 -1
  213. package/templates/dist/writer-core/src/index.d.ts +0 -34
  214. package/templates/dist/writer-core/src/index.js +0 -115
  215. package/templates/dist/writer-core/src/index.js.map +0 -1
  216. package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +0 -20
  217. package/templates/dist/ztd-cli/templates/src/db/sql-client.js +0 -3
  218. package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +0 -1
  219. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +0 -36
  220. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +0 -85
  221. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +0 -1
  222. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +0 -20
  223. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +0 -33
  224. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +0 -1
  225. package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +0 -10
  226. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +0 -29
  227. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +0 -1
  228. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +0 -66
  229. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +0 -552
  230. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +0 -1
  231. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +0 -1
  232. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +0 -82
  233. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +0 -1
  234. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +0 -1
  235. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +0 -29
  236. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +0 -1
  237. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +0 -7
  238. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +0 -10
  239. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +0 -1
  240. package/templates/src/repositories/user-accounts.ts +0 -179
  241. package/templates/tests/user-profiles.test.ts +0 -161
  242. package/templates/tests/writer-constraints.test.ts +0 -32
@@ -0,0 +1,30 @@
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/repositories`.
3
+ - Defines runtime repository responsibilities for SQL execution orchestration.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Repositories MUST load SQL assets from `src/sql` through shared loader infrastructure.
8
+ - Repositories MUST use catalog runtime helpers (`ensure*`, `map*`) for input/output validation.
9
+ - Repository CUD behavior MUST follow contract rules for `RETURNING`, rowCount handling, and explicit unsupported-driver failures.
10
+ - Repository modules MUST reference SQL by stable logical keys.
11
+ - Repository constructors SHOULD accept an optional telemetry dependency from `src/infrastructure/telemetry/repositoryTelemetry.ts`.
12
+ - Public repository methods MUST be covered by tests.
13
+
14
+ ## ALLOWED
15
+ - SELECT methods MAY return `T | null` or `T[]` according to contract cardinality.
16
+
17
+ ## PROHIBITED
18
+ - Embedding business rules or contract inference in repositories.
19
+ - Inline SQL strings or ad-hoc SQL file path resolution.
20
+ - Follow-up SELECT workarounds to emulate CUD success semantics.
21
+
22
+ # Mandatory Workflow
23
+ - Repository changes MUST run tests covering mapping, rowCount behavior, and error surfaces.
24
+
25
+ # Hygiene
26
+ - Error messages MUST include operation identifiers and relevant parameters.
27
+
28
+ # References
29
+ - Tables repository policy: [./tables/AGENTS.md](./tables/AGENTS.md)
30
+ - Views repository policy: [./views/AGENTS.md](./views/AGENTS.md)
@@ -0,0 +1,29 @@
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/repositories/tables`.
3
+ - Defines table-oriented CRUD repository contract behavior.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - CREATE SQL MUST use identifier-focused `RETURNING` when generated keys are required.
8
+ - CREATE repository methods MUST return identifier-only results by default.
9
+ - UPDATE and DELETE MUST rely on affected-row counts where available.
10
+ - `rowCount === 0` conditions MUST surface explicitly according to contract behavior.
11
+ - Patch contracts MUST distinguish omitted fields from explicit null values.
12
+ - Public repository methods MUST be test-covered for mapping and CUD error behavior.
13
+
14
+ ## ALLOWED
15
+ - DTO-returning CREATE behavior MAY be implemented only when explicitly required by human-authored spec.
16
+
17
+ ## PROHIBITED
18
+ - UPDATE/DELETE `RETURNING`-based success emulation.
19
+ - Follow-up SELECT workarounds for CUD verification.
20
+ - Ambiguous patch patterns that hide omitted-vs-null intent.
21
+
22
+ # Mandatory Workflow
23
+ - Table repository changes MUST run tests for affected-row handling and explicit failure surfaces.
24
+
25
+ # Hygiene
26
+ - Keep SQL assets idiomatic and driver-neutral for table CRUD paths.
27
+
28
+ # References
29
+ - Parent repository policy: [../AGENTS.md](../AGENTS.md)
@@ -0,0 +1,5 @@
1
+ # Table Repositories
2
+
3
+ Write-focused repositories that execute CRUD SQL from `src/sql`.
4
+
5
+ Accept an optional telemetry hook from `src/infrastructure/telemetry/repositoryTelemetry.ts` and default it through `resolveRepositoryTelemetry(...)` so applications can replace the sink without editing repository internals.
@@ -0,0 +1,25 @@
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/repositories/views`.
3
+ - Defines read-model repository behavior for complex SELECT-only queries.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Queries in this subtree MUST remain read-only.
8
+ - Read-model DTO validation MUST run at repository/catalog boundaries.
9
+ - Query naming MUST make cardinality assumptions explicit.
10
+
11
+ ## ALLOWED
12
+ - Multi-table joins, aggregations, and purpose-built read DTOs MAY be used.
13
+
14
+ ## PROHIBITED
15
+ - INSERT/UPDATE/DELETE behavior in this subtree.
16
+ - Hidden write side effects in read-model query paths.
17
+
18
+ # Mandatory Workflow
19
+ - View repository changes MUST run tests for DTO validation and result ordering assumptions.
20
+
21
+ # Hygiene
22
+ - Preserve explicit ordering whenever test behavior depends on row order.
23
+
24
+ # References
25
+ - Parent repository policy: [../AGENTS.md](../AGENTS.md)
@@ -0,0 +1,5 @@
1
+ # View Repositories
2
+
3
+ Read-only repositories backed by SELECT SQL in `src/sql`.
4
+
5
+ Accept an optional telemetry hook from `src/infrastructure/telemetry/repositoryTelemetry.ts` and default it through `resolveRepositoryTelemetry(...)` so applications can bridge structured events into their own logging stack.
@@ -0,0 +1,30 @@
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/sql`.
3
+ - Defines SQL asset contract rules for runtime execution.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - SQL assets MUST use named parameters (`:name`).
8
+ - SQL assets MUST stay DTO-independent and use database-oriented column naming.
9
+ - UPDATE and DELETE statements MUST include WHERE clauses.
10
+ - SQL files MUST remain explicit enough for repository/runtime mapping contracts.
11
+ - CUD `RETURNING` behavior MUST follow repository contract rules.
12
+
13
+ ## ALLOWED
14
+ - INSERT SQL MAY use `RETURNING` for identifiers and required DB-generated contract columns.
15
+
16
+ ## PROHIBITED
17
+ - Positional placeholders in SQL asset files.
18
+ - DTO camelCase aliasing inside SQL assets.
19
+ - UPDATE/DELETE `RETURNING` usage.
20
+ - SQL-side emulation of affected-row verification behavior.
21
+
22
+ # Mandatory Workflow
23
+ - SQL asset changes MUST run tests that execute the changed SQL via catalog/repository paths.
24
+
25
+ # Hygiene
26
+ - Keep SQL filenames stable and unambiguous for CRUD intent.
27
+ - Avoid `select *` unless explicitly justified by contract behavior.
28
+
29
+ # References
30
+ - Parent runtime policy: [../AGENTS.md](../AGENTS.md)
@@ -0,0 +1,6 @@
1
+ # SQL Files
2
+
3
+ Store SQL statements by table or domain in subfolders.
4
+
5
+ - Use named parameters (for example `:id`).
6
+ - Keep SQL in files; repositories should load them.
@@ -1,169 +1,29 @@
1
- # AGENTS: ZTD Test Guidelines
2
-
3
- This file defines **rules and boundaries for writing tests under `tests/`**.
4
- Tests are a shared workspace for humans and AI, but must respect ZTD-specific constraints.
5
-
6
- ---
7
-
8
- ## Default execution mode (important)
9
-
10
- - The default execution mode for tests is **ZTD**.
11
- - ZTD tests run through the new `createTestkitProvider` helper, which keeps a single
12
- shared backend connection per worker and wraps each scenario in a rollback
13
- transaction by default.
14
- - Do not switch to Traditional mode unless explicitly instructed by a human.
15
- - Do not set `ZTD_EXECUTION_MODE=traditional` or pass `{ mode: "traditional" }` to `createTestkitClient()` without explicit instruction.
16
- - When you need session-level changes (temporary tables, `SET` commands, etc.), opt
17
- into per-test isolation via `provider.perTest()` or by passing `{ strategy:
18
- 'perTest' }` to `provider.withRepositoryFixture`. Shared mode otherwise keeps the
19
- default behavior fast and deterministic.
20
- - If instructions are ambiguous, assume ZTD mode and proceed.
21
- - Tests MUST NOT mix ZTD mode and Traditional mode within the same test suite.
22
- - Traditional mode is reserved for integration-style validation; it is not a convenience or performance workaround.
23
- - Every repository/test change must be followed by `pnpm --filter <package> test` (substitute the real template package name).
24
- - `tests/support/global-setup.ts` already uses `@testcontainers/postgresql`, so a disposable Postgres container spins up automatically whenever `DATABASE_URL` is absent.
25
- - If the suite fails, resolve the failure and rerun until it succeeds before considering the change complete.
26
-
27
- ---
28
-
29
- ## Use generated types only (important)
30
-
31
- - Do **not** define ad-hoc or duplicate test models.
32
- - For table-shaped rows, always import types from:
33
- - `tests/generated/ztd-row-map.generated.ts`
34
- - For application-facing return values:
35
- - Use DTO or domain model types already defined in `src/`.
36
-
37
- Forbidden example:
38
-
39
- ```typescript
40
- type CategoryTestRow = {
41
- category_id: number;
42
- parent_id: number | null;
43
- name: string;
44
- };
45
- ```
46
-
47
- If a required type is missing:
48
- - Regenerate generated artifacts (`npx ztd ztd-config`), or
49
- - Export the correct type from `src/`.
50
-
51
- Do not invent substitute models.
52
- - Tests MUST treat `tests/generated/ztd-row-map.generated.ts` as the single source of truth for table-shaped rows.
53
- - If a column exists in the database but not in the row map, the schema is considered outdated until regenerated.
54
-
55
- ---
56
-
57
- ## Stateless test design (important)
58
-
59
- - ZTD tests are **stateless by design**.
60
- - Do not write tests that depend on state accumulating across multiple repository calls.
61
-
62
- Forbidden patterns include:
63
- - Updating the same record in multiple steps and verifying later state
64
- - Calling multiple repository methods assuming earlier calls affected the database
65
-
66
- Preferred patterns:
67
- - Verify results returned by a single statement
68
- - Verify `RETURNING` values
69
- - Verify affected row counts
70
- - Verify query output produced by the same call being tested
71
-
72
- If behavior depends on transactions, isolation, or shared mutable state:
73
- - That test does not belong in ZTD unit tests.
74
- - Move it to an integration test and explicitly request Traditional mode.
75
- - A single repository method call is the maximum scope of observation in ZTD tests.
76
- - Tests that validate cross-call effects, workflows, or lifecycle transitions do not belong in ZTD tests.
77
-
78
- ---
79
-
80
- ## Fixtures (important)
81
-
82
- - Fixtures originate from `ztd/ddl/`.
83
- - Keep fixtures minimal and intention-revealing.
84
- - Do not add rows or columns unrelated to the test intent.
85
- - Do not simulate application-side logic in fixtures.
86
- - Fixtures must satisfy non-nullable columns and required constraints derived from DDL.
87
- - Fixtures MUST NOT encode business rules, defaults, or derived values.
88
- - Fixtures exist only to satisfy schema constraints and make SQL executable.
89
-
90
- ---
91
-
92
- ## Assertions (important)
93
-
94
- - Assert only on relevant fields.
95
- - Do not assert implicit ordering unless the repository contract explicitly guarantees it
96
- (e.g. the query includes a defined `ORDER BY`).
97
- - Do not assert specific values of auto-generated IDs.
98
- - Assert existence, type, cardinality, or relative differences instead.
99
-
100
- ---
101
-
102
- ## Repository boundaries (important)
103
-
104
- - Tests should verify observable behavior of repository methods.
105
- - Do not duplicate SQL logic or business rules inside tests.
106
- - Do not test internal helper functions or private implementation details.
107
- - Tests must match the repository method contract exactly
108
- (return type, nullability, and error behavior).
109
- - Tests MUST NOT compensate for mapper or writer limitations by reimplementing logic in the test itself.
110
-
111
- ---
112
-
113
- ## Test helper and resource lifecycle (important)
114
-
115
- - Any test helper that creates a client, connection, or testkit instance
116
- **must guarantee cleanup**.
117
- - Always close resources using `try/finally` or a dedicated helper
118
- (e.g. `withRepository`).
119
- - Do not rely on test success paths to release resources.
120
-
121
- ---
122
-
123
- ## Test file conventions (important)
124
-
125
- - Do not assume Vitest globals are available.
126
- - Explicitly import `describe`, `it`, and `expect` from `vitest`
127
- unless the project explicitly documents global usage.
128
- - Avoid implicit `any` in tests and helpers.
129
- - Explicitly type fixtures and helper parameters
130
- (e.g. `Parameters<typeof createTestkitClient>[0]`).
131
-
132
- ---
133
-
134
- ## Edit boundaries
135
-
136
- - Tests are shared ownership: humans and AI may both edit.
137
- - However:
138
- - Do not redefine models.
139
- - Do not change schema assumptions.
140
- - Do not edit `ztd/ddl`. `ztd/ddl` is the only authoritative `ztd` directory; do not create or assume additional `ztd` subdirectories without explicit instruction.
141
- - The only authoritative source for tests is `ztd/ddl`.
142
- - Tests may fail when `ztd/` definitions change; tests MUST be updated to reflect those changes, not the other way around.
143
-
144
- ---
145
-
146
- ## Conflict resolution
147
-
148
- - If test requirements conflict with ZTD constraints:
149
- - Stop and ask for clarification.
150
- - Do not silently switch modes or weaken assertions.
151
-
152
- ---
153
-
154
- ## Writer metadata guardrail (template-specific)
155
-
156
- - `tests/writer-constraints.test.ts` reads `userAccountWriterColumnSets` together with `tests/generated/ztd-row-map.generated.ts` to ensure every writer column actually exists on `public.user_account`.
157
- - Run `npx ztd ztd-config` before executing the template tests so the generated row map reflects your current schema changes.
158
- - When new columns appear in the writer helpers, adjust `userAccountWriterColumnSets`, rerun the row-map generator, and update the constraint test expectations.
159
- - These tests exist to enforce column correctness at test time so writer helpers remain runtime-safe and schema-agnostic.
160
-
161
- ## Guiding principle
162
-
163
- ZTD tests exist to validate **repository behavior derived from SQL semantics in isolation**.
164
- They are not integration tests, migration tests, or transaction tests.
165
-
166
- Prefer:
167
- - Clear intent
168
- - Single observation point
169
- - Deterministic outcomes
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/tests`.
3
+ - Defines verification contract for ZTD template-generated test code.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Tests MUST verify SQL execution under ZTD rewrite, mapping behavior, validation paths, and DTO shape semantics.
8
+ - CUD tests MUST verify UPDATE/DELETE via affected-row signals.
9
+ - CREATE tests for table repositories MUST expect identifier-only returns unless spec explicitly requires DTO return.
10
+ - Test runner configuration MUST exist and support single-command execution.
11
+ - Initial template state MUST include at least one executable test.
12
+
13
+ ## ALLOWED
14
+ - Tests MAY import runtime modules from `src/`.
15
+
16
+ ## PROHIBITED
17
+ - Runtime imports from `tests/` or `tests/generated/`.
18
+ - Tests that require repository follow-up SELECT behavior contradicting repository contracts.
19
+ - Manual edits to generated artifacts.
20
+
21
+ # Mandatory Workflow
22
+ - Test changes MUST run affected test suites and confirm test-runner configuration remains valid.
23
+
24
+ # Hygiene
25
+ - Regenerate `tests/generated` artifacts before diagnosing missing generated module errors.
26
+
27
+ # References
28
+ - Generated tests policy: [./generated/AGENTS.md](./generated/AGENTS.md)
29
+ - Shared support policy: [./support/AGENTS.md](./support/AGENTS.md)
@@ -0,0 +1,23 @@
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/tests/generated`.
3
+ - Governs generated test artifacts.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Missing or stale generated files MUST be regenerated using project generation commands.
8
+
9
+ ## ALLOWED
10
+ - Generated artifacts MAY be regenerated via `npx ztd ztd-config`.
11
+
12
+ ## PROHIBITED
13
+ - Manual edits to files in this directory.
14
+ - Committing generated artifacts when repository policy does not require them.
15
+
16
+ # Mandatory Workflow
17
+ - Run generation commands before diagnosing generated-module type errors.
18
+
19
+ # Hygiene
20
+ - Keep generated output reproducible from project tooling.
21
+
22
+ # References
23
+ - Parent tests policy: [../AGENTS.md](../AGENTS.md)
@@ -0,0 +1,25 @@
1
+ import { expect, test } from 'vitest';
2
+
3
+ import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
4
+ import { createTestkitClient } from './support/testkit-client';
5
+
6
+ test('smoke: runtime contract wiring is usable before SQL-backed tests exist', () => {
7
+ const output = ensureSmokeOutput({
8
+ id: 1,
9
+ createdAt: '2025-01-01T00:00:00.000Z',
10
+ });
11
+
12
+ expect(output.id).toBe(1);
13
+ expect(output.createdAt).toBeInstanceOf(Date);
14
+ expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
15
+ });
16
+
17
+ test('smoke: SqlClient seam is either wired or fails with an actionable message', async () => {
18
+ try {
19
+ const client = await createTestkitClient();
20
+ expect(typeof client.query).toBe('function');
21
+ } catch (error) {
22
+ const message = error instanceof Error ? error.message : String(error);
23
+ expect(message).toContain('Provide a SqlClient implementation here');
24
+ }
25
+ });
@@ -0,0 +1,34 @@
1
+ import { expect, test } from 'vitest';
2
+
3
+ import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
4
+
5
+ test('validator invariant smoke passes for valid runtime output', () => {
6
+ const output = ensureSmokeOutput({
7
+ id: 1,
8
+ createdAt: new Date('2025-01-01T00:00:00.000Z')
9
+ });
10
+
11
+ expect(output).toEqual({
12
+ id: 1,
13
+ createdAt: new Date('2025-01-01T00:00:00.000Z')
14
+ });
15
+ });
16
+
17
+ test('validator invariant smoke normalizes valid timestamp strings', () => {
18
+ const output = ensureSmokeOutput({
19
+ id: 1,
20
+ createdAt: '2025-01-01T00:00:00.000Z'
21
+ });
22
+
23
+ expect(output.createdAt).toBeInstanceOf(Date);
24
+ expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
25
+ });
26
+
27
+ test('validator invariant smoke fails for invalid runtime output', () => {
28
+ expect(() =>
29
+ ensureSmokeOutput({
30
+ id: 1,
31
+ createdAt: 'not-a-date'
32
+ })
33
+ ).toThrow(/Invalid timestamp string/);
34
+ });
@@ -0,0 +1,24 @@
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/tests/support`.
3
+ - Defines shared test infrastructure contracts.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Shared support helpers MUST stay minimal and explicit.
8
+ - Shared support code MUST avoid business-rule ownership.
9
+ - Runtime code under `src/` MUST NOT import from this folder.
10
+
11
+ ## ALLOWED
12
+ - Support helpers MAY import from `src/`.
13
+
14
+ ## PROHIBITED
15
+ - Embedding domain business logic into support infrastructure.
16
+
17
+ # Mandatory Workflow
18
+ - Global setup/support changes MUST run representative subset tests and at least one full test run.
19
+
20
+ # Hygiene
21
+ - Validate resource lifecycle and parallelism behavior after support-layer changes.
22
+
23
+ # References
24
+ - Parent tests policy: [../AGENTS.md](../AGENTS.md)
@@ -1,30 +1,15 @@
1
- import { PostgreSqlContainer } from '@testcontainers/postgresql';
2
-
3
- /**
4
- * Vitest global setup.
5
- *
6
- * ZTD tests are safe to run in parallel against a single Postgres instance because testkit-postgres
7
- * rewrites CRUD into fixture-backed SELECT queries (no physical tables are created/mutated).
8
- *
9
- * This setup starts exactly one disposable Postgres container when DATABASE_URL is not provided,
10
- * and shares the resulting DATABASE_URL with all Vitest workers.
11
- */
12
- export default async function globalSetup() {
13
- const configuredUrl = process.env.DATABASE_URL;
14
- if (configuredUrl && configuredUrl.length > 0) {
15
- return () => undefined;
16
- }
17
-
18
- const container = new PostgreSqlContainer('postgres:18-alpine')
19
- .withDatabase('ztd_playground')
20
- .withUsername('postgres')
21
- .withPassword('postgres');
22
-
23
- const started = await container.start();
24
- process.env.DATABASE_URL = started.getConnectionUri();
25
-
26
- return async () => {
27
- await started.stop();
28
- };
29
- }
30
-
1
+ /**
2
+ * Vitest global setup.
3
+ *
4
+ * This hook warns when ZTD_TEST_DATABASE_URL is missing so the developer remembers
5
+ * to provide the ZTD-owned test database connection before running SQL-backed tests.
6
+ */
7
+ export default async function globalSetup() {
8
+ const configuredUrl = process.env.ZTD_TEST_DATABASE_URL?.trim();
9
+ if (!configuredUrl) {
10
+ console.warn(
11
+ 'ZTD_TEST_DATABASE_URL is not configured. SQL-backed tests will need a driver plus a ZTD-owned test database connection before they can run.',
12
+ );
13
+ }
14
+ return () => undefined;
15
+ }