@rawsql-ts/ztd-cli 0.15.0 → 0.17.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 (153) hide show
  1. package/README.md +38 -25
  2. package/dist/commands/init.d.ts +13 -0
  3. package/dist/commands/init.js +372 -118
  4. package/dist/commands/init.js.map +1 -1
  5. package/dist/commands/lint.d.ts +4 -4
  6. package/dist/commands/lint.js +60 -40
  7. package/dist/commands/lint.js.map +1 -1
  8. package/dist/commands/ztdConfig.d.ts +2 -2
  9. package/dist/commands/ztdConfig.js +26 -12
  10. package/dist/commands/ztdConfig.js.map +1 -1
  11. package/dist/utils/optionalDependencies.d.ts +35 -0
  12. package/dist/utils/optionalDependencies.js +96 -0
  13. package/dist/utils/optionalDependencies.js.map +1 -0
  14. package/package.json +18 -10
  15. package/templates/AGENTS.md +36 -296
  16. package/templates/README.md +12 -237
  17. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
  18. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
  19. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
  20. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
  21. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
  22. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
  23. package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
  24. package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
  25. package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
  26. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
  27. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
  28. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
  29. package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
  30. package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
  31. package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
  32. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
  33. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
  34. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
  35. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
  36. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
  37. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
  38. package/templates/dist/mapper-core/src/index.d.ts +160 -0
  39. package/templates/dist/mapper-core/src/index.js +637 -0
  40. package/templates/dist/mapper-core/src/index.js.map +1 -0
  41. package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
  42. package/templates/dist/testkit-core/src/errors/index.js +111 -0
  43. package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
  44. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
  45. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
  46. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
  47. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
  48. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
  49. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
  50. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
  51. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
  52. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
  53. package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
  54. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
  55. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
  56. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
  57. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
  58. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
  59. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
  60. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
  61. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
  62. package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
  63. package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
  64. package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
  65. package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
  66. package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
  67. package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
  68. package/templates/dist/testkit-core/src/index.d.ts +17 -0
  69. package/templates/dist/testkit-core/src/index.js +47 -0
  70. package/templates/dist/testkit-core/src/index.js.map +1 -0
  71. package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
  72. package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
  73. package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
  74. package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
  75. package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
  76. package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
  77. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
  78. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
  79. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
  80. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
  81. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
  82. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
  83. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
  84. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
  85. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
  86. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
  87. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
  88. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
  89. package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
  90. package/templates/dist/testkit-core/src/types/index.js +3 -0
  91. package/templates/dist/testkit-core/src/types/index.js.map +1 -0
  92. package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
  93. package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
  94. package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
  95. package/templates/dist/writer-core/src/index.d.ts +34 -0
  96. package/templates/dist/writer-core/src/index.js +115 -0
  97. package/templates/dist/writer-core/src/index.js.map +1 -0
  98. package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
  99. package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
  100. package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
  101. package/templates/dist/ztd-cli/templates/src/db/sql-client.ts +24 -0
  102. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
  103. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
  104. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
  105. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
  106. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
  107. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
  108. package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
  109. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
  110. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
  111. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
  112. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
  113. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
  114. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
  115. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
  116. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
  117. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
  118. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
  119. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
  120. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
  121. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
  122. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -0
  123. package/templates/src/AGENTS.md +26 -0
  124. package/templates/src/catalog/AGENTS.md +37 -0
  125. package/templates/src/catalog/runtime/AGENTS.md +75 -0
  126. package/templates/src/catalog/runtime/_coercions.ts +1 -0
  127. package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
  128. package/templates/src/catalog/specs/AGENTS.md +48 -0
  129. package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
  130. package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
  131. package/templates/src/db/sql-client.ts +5 -5
  132. package/templates/src/jobs/AGENTS.md +26 -0
  133. package/templates/src/jobs/README.md +3 -0
  134. package/templates/src/repositories/AGENTS.md +118 -0
  135. package/templates/src/repositories/tables/AGENTS.md +94 -0
  136. package/templates/src/repositories/tables/README.md +3 -0
  137. package/templates/src/repositories/views/AGENTS.md +25 -0
  138. package/templates/src/repositories/views/README.md +3 -0
  139. package/templates/src/sql/AGENTS.md +77 -0
  140. package/templates/src/sql/README.md +6 -0
  141. package/templates/tests/AGENTS.md +43 -129
  142. package/templates/tests/generated/AGENTS.md +16 -0
  143. package/templates/tests/smoke.test.ts +5 -0
  144. package/templates/tests/smoke.validation.test.ts +34 -0
  145. package/templates/tests/support/AGENTS.md +26 -0
  146. package/templates/tests/support/global-setup.ts +8 -23
  147. package/templates/tests/support/testkit-client.ts +13 -741
  148. package/templates/tests/ztd-layout.generated.ts +0 -2
  149. package/templates/tsconfig.json +9 -3
  150. package/templates/ztd/AGENTS.md +11 -142
  151. package/templates/ztd/README.md +4 -82
  152. package/templates/ztd/ddl/AGENTS.md +34 -0
  153. package/templates/ztd/ddl/demo.sql +74 -0
@@ -0,0 +1,77 @@
1
+ # src/sql AGENTS
2
+
3
+ This directory contains SQL assets executed at runtime.
4
+
5
+ ## Runtime classification
6
+
7
+ - This is a runtime directory.
8
+ - SQL files are loaded and executed by repositories or catalog runtime.
9
+
10
+ ## Ownership (important)
11
+
12
+ - SQL expresses domain intent and is human-owned by default.
13
+ - AI may propose changes, but MUST NOT alter semantics or intent without explicit human instruction.
14
+ - If a human explicitly writes or edits SQL, the human decision always takes precedence.
15
+
16
+ ## Parameter binding (required)
17
+
18
+ - SQL assets MUST use named parameters (":name" form).
19
+ - Positional parameters ("$1", "$2", ...) are forbidden in SQL assets.
20
+ - Conversion from named to indexed parameters is a runtime responsibility.
21
+
22
+ ## DTO independence (critical)
23
+
24
+ - SQL MUST NOT depend on DTO shapes.
25
+ - CamelCase aliases (e.g. `as "userId"`) are forbidden.
26
+ - SQL should return database-oriented column names (typically snake_case).
27
+ - Mapping to DTOs is the responsibility of repositories or catalog runtime.
28
+
29
+ ## CRUD quality bar (tables) (important)
30
+
31
+ For simple CRUD SQL under table-oriented areas:
32
+ - Prefer the most direct and idiomatic SQL.
33
+ - Do NOT encode driver limitations into SQL.
34
+ - Avoid unnecessary CTEs or counting tricks.
35
+
36
+ Examples of discouraged patterns for simple CRUD:
37
+ - `with updated as (...) select count(*) ...`
38
+ - returning values only to compute affected rows
39
+
40
+ Affected-row handling belongs to repositories/runtime, not SQL.
41
+
42
+ ## CUD and RETURNING policy
43
+
44
+ - INSERT SQL MAY use `RETURNING` only for identifier columns (and optionally DB-generated columns required by contract).
45
+ - INSERT SQL MUST NOT return full rows or DTO-shaped payloads.
46
+ - UPDATE SQL MUST NOT use `RETURNING`.
47
+ - DELETE SQL MUST NOT use `RETURNING`.
48
+ - SQL MUST NOT use `RETURNING` to emulate affected-row detection.
49
+ - If affected-row counts are unavailable from the driver/runtime, treat UPDATE/DELETE verification as unsupported at the driver boundary.
50
+
51
+ ## Safety rules (critical)
52
+
53
+ - UPDATE and DELETE MUST include a WHERE clause.
54
+ - SQL MUST NOT rely on follow-up SELECTs in repositories to ensure correctness.
55
+ - A missing or incorrect WHERE clause is a SQL bug and MUST surface via tests.
56
+
57
+ ## Naming conventions (recommended)
58
+
59
+ Prefer SQL-idiomatic verbs for CRUD assets:
60
+ - insert_<entity>.sql
61
+ - select_<entity>_by_<key>.sql
62
+ - select_<entities>.sql
63
+ - update_<entity>.sql
64
+ - delete_<entity>.sql
65
+
66
+ Avoid ambiguous verbs like "create" / "get" in SQL filenames by default.
67
+
68
+ ## General SQL rules
69
+
70
+ - Use explicit column lists.
71
+ - Avoid `select *` unless explicitly justified.
72
+ - Prefer stable ordering when result order matters.
73
+
74
+ ## Boundaries
75
+
76
+ - Do not place TypeScript code in this directory.
77
+ - Query contracts live in "src/catalog/specs".
@@ -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,148 +1,62 @@
1
- # AGENTS: ZTD Test Guidelines
1
+ # tests AGENTS
2
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.
3
+ This directory contains verification code.
5
4
 
6
- ---
5
+ ## Runtime classification
7
6
 
8
- ## Default execution mode (important)
7
+ - This is a non-runtime directory.
8
+ - Code here is never part of application runtime.
9
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.
10
+ ## Core principles
21
11
 
22
- ---
12
+ - This project uses ZTD (Zero Table Dependency).
13
+ - DDL and fixtures define the test world.
14
+ - Tests must be deterministic and parallel-safe.
23
15
 
24
- ## Use generated types only (important)
16
+ ## What to test (important)
25
17
 
26
- - Do **not** define ad-hoc or duplicate test models.
27
- - For table-shaped rows, always import types from:
28
- - `tests/generated/ztd-row-map.generated.ts`
29
- - For application-facing return values:
30
- - Use DTO or domain model types already defined in `src/`.
18
+ - Catalog specs are first-class test targets.
19
+ - Tests should verify:
20
+ - SQL executes under ZTD rewriting
21
+ - mapping behavior
22
+ - validation success and failure
23
+ - DTO shape and semantics
31
24
 
32
- Forbidden example:
25
+ - Tests MUST NOT enforce repository behavior that contradicts repository contracts.
26
+ - Tests MUST NOT require follow-up SELECTs after UPDATE or DELETE by default.
33
27
 
34
- ```typescript
35
- type CategoryTestRow = {
36
- category_id: number;
37
- parent_id: number | null;
38
- name: string;
39
- };
40
- ```
28
+ ## CUD test policy (important)
41
29
 
42
- If a required type is missing:
43
- - Regenerate generated artifacts (`npx ztd ztd-config`), or
44
- - Export the correct type from `src/`.
30
+ - UPDATE and DELETE success/failure MUST be verified via affected-row information
31
+ (e.g. rowCount or equivalent).
32
+ - Tests MUST NOT assume UPDATE/DELETE return DTOs.
33
+ - If the driver cannot report affected rows, CUD verification is unsupported and
34
+ tests MUST fail fast.
35
+ - CREATE tests for table repositories MUST expect identifier-only returns by default.
36
+ - Tests MUST NOT require repository follow-up SELECT after CREATE unless the catalog spec explicitly requires DTO return.
45
37
 
46
- Do not invent substitute models.
38
+ ## Generated artifacts
47
39
 
48
- ---
40
+ - "tests/generated/" is auto-generated.
41
+ - Do not edit generated files by hand.
42
+ - Regenerate before debugging type errors.
49
43
 
50
- ## Stateless test design (important)
44
+ ## Boundaries
51
45
 
52
- - ZTD tests are **stateless by design**.
53
- - Do not write tests that depend on state accumulating across multiple repository calls.
46
+ - Tests may import from "src/".
47
+ - Runtime code under "src/" MUST NOT import from "tests/" or "tests/generated/".
54
48
 
55
- Forbidden patterns include:
56
- - Updating the same record in multiple steps and verifying later state
57
- - Calling multiple repository methods assuming earlier calls affected the database
49
+ ## Test runner requirements (required)
58
50
 
59
- Preferred patterns:
60
- - Verify results returned by a single statement
61
- - Verify `RETURNING` values
62
- - Verify affected row counts
63
- - Verify query output produced by the same call being tested
51
+ - A test runner configuration (e.g. vitest.config.ts) MUST exist.
52
+ - Tests MUST be executable with a single command (e.g. `pnpm test`).
53
+ - Missing test runner configuration is considered a setup error.
64
54
 
65
- If behavior depends on transactions, isolation, or shared mutable state:
66
- - That test does not belong in ZTD unit tests.
67
- - Move it to an integration test and explicitly request Traditional mode.
55
+ Do not add tests that assume manual setup steps.
68
56
 
69
- ---
57
+ ## Initialization invariant
70
58
 
71
- ## Fixtures (important)
72
-
73
- - Fixtures originate from `ztd/ddl/`.
74
- - Keep fixtures minimal and intention-revealing.
75
- - Do not add rows or columns unrelated to the test intent.
76
- - Do not simulate application-side logic in fixtures.
77
- - Fixtures must satisfy non-nullable columns and required constraints derived from DDL.
78
-
79
- ---
80
-
81
- ## Assertions (important)
82
-
83
- - Assert only on relevant fields.
84
- - Do not assert implicit ordering unless the repository contract explicitly guarantees it
85
- (e.g. the query includes a defined `ORDER BY`).
86
- - Do not assert specific values of auto-generated IDs.
87
- - Assert existence, type, cardinality, or relative differences instead.
88
-
89
- ---
90
-
91
- ## Repository boundaries (important)
92
-
93
- - Tests should verify observable behavior of repository methods.
94
- - Do not duplicate SQL logic or business rules inside tests.
95
- - Do not test internal helper functions or private implementation details.
96
- - Tests must match the repository method contract exactly
97
- (return type, nullability, and error behavior).
98
-
99
- ---
100
-
101
- ## Test helper and resource lifecycle (important)
102
-
103
- - Any test helper that creates a client, connection, or testkit instance
104
- **must guarantee cleanup**.
105
- - Always close resources using `try/finally` or a dedicated helper
106
- (e.g. `withRepository`).
107
- - Do not rely on test success paths to release resources.
108
-
109
- ---
110
-
111
- ## Test file conventions (important)
112
-
113
- - Do not assume Vitest globals are available.
114
- - Explicitly import `describe`, `it`, and `expect` from `vitest`
115
- unless the project explicitly documents global usage.
116
- - Avoid implicit `any` in tests and helpers.
117
- - Explicitly type fixtures and helper parameters
118
- (e.g. `Parameters<typeof createTestkitClient>[0]`).
119
-
120
- ---
121
-
122
- ## Edit boundaries
123
-
124
- - Tests are shared ownership: humans and AI may both edit.
125
- - However:
126
- - Do not redefine models.
127
- - Do not change schema assumptions.
128
- - Do not edit `ztd/ddl`, `ztd/domain-specs`, or `ztd/enums` from tests.
129
-
130
- ---
131
-
132
- ## Conflict resolution
133
-
134
- - If test requirements conflict with ZTD constraints:
135
- - Stop and ask for clarification.
136
- - Do not silently switch modes or weaken assertions.
137
-
138
- ---
139
-
140
- ## Guiding principle
141
-
142
- ZTD tests exist to validate **repository behavior derived from SQL semantics in isolation**.
143
- They are not integration tests, migration tests, or transaction tests.
144
-
145
- Prefer:
146
- - Clear intent
147
- - Single observation point
148
- - Deterministic outcomes
59
+ - The initial project state MUST include:
60
+ - test runner configuration
61
+ - at least one executable test file
62
+ - The initial test run MUST pass or fail only due to user-written logic, not setup.
@@ -0,0 +1,16 @@
1
+ # tests/generated AGENTS
2
+
3
+ This directory contains generated files.
4
+
5
+ ## Non-negotiable
6
+
7
+ - Do not edit any file in this directory by hand.
8
+ - Do not commit generated artifacts unless the repository explicitly requires it.
9
+
10
+ ## Regeneration
11
+
12
+ If files are missing or stale, regenerate using the project command.
13
+ Example:
14
+ - "npx ztd ztd-config"
15
+
16
+ If TypeScript reports missing modules referencing generated files, regenerate first.
@@ -0,0 +1,5 @@
1
+ import { expect, test } from 'vitest';
2
+
3
+ test('smoke: template test runner is wired', () => {
4
+ expect(true).toBe(true);
5
+ });
@@ -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,26 @@
1
+ # tests/support AGENTS
2
+
3
+ This folder contains shared test infrastructure.
4
+
5
+ ## Scope
6
+
7
+ - global setup and teardown
8
+ - test clients and helpers for execution
9
+ - environment/bootstrap logic
10
+
11
+ ## Rules
12
+
13
+ - Keep helpers minimal and explicit.
14
+ - Prefer stable interfaces used across tests.
15
+ - Do not place business rules here.
16
+
17
+ ## Boundaries
18
+
19
+ - Support code may import from "src/" as needed.
20
+ - Runtime code under "src/" MUST NOT import from this folder.
21
+
22
+ ## Changes
23
+
24
+ When modifying global setup or shared clients:
25
+ - Re-run a representative subset of tests and at least one full run when feasible.
26
+ - Watch for parallelism and resource lifecycle issues.
@@ -1,30 +1,15 @@
1
- import { PostgreSqlContainer } from '@testcontainers/postgresql';
2
-
3
1
  /**
4
2
  * Vitest global setup.
5
3
  *
6
- * ZTD tests are safe to run in parallel against a single Postgres instance because pg-testkit
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.
4
+ * This hook warns when DATABASE_URL is missing so the developer remembers to
5
+ * install an adapter or provide a connection before running SQL-backed tests.
11
6
  */
12
7
  export default async function globalSetup() {
13
- const configuredUrl = process.env.DATABASE_URL;
14
- if (configuredUrl && configuredUrl.length > 0) {
15
- return () => undefined;
8
+ const configuredUrl = process.env.DATABASE_URL?.trim();
9
+ if (!configuredUrl) {
10
+ console.warn(
11
+ 'DATABASE_URL is not configured. Install a database adapter or set DATABASE_URL before running SQL-backed tests.',
12
+ );
16
13
  }
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
- };
14
+ return () => undefined;
29
15
  }
30
-