@rawsql-ts/ztd-cli 0.16.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.
- package/README.md +33 -20
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.js +372 -127
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +4 -4
- package/dist/commands/lint.js +60 -40
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/ztdConfig.d.ts +2 -2
- package/dist/commands/ztdConfig.js +26 -12
- package/dist/commands/ztdConfig.js.map +1 -1
- package/dist/utils/optionalDependencies.d.ts +35 -0
- package/dist/utils/optionalDependencies.js +96 -0
- package/dist/utils/optionalDependencies.js.map +1 -0
- package/package.json +16 -9
- package/templates/AGENTS.md +36 -309
- package/templates/README.md +12 -215
- package/templates/dist/ztd-cli/templates/src/db/sql-client.ts +24 -0
- package/templates/src/AGENTS.md +26 -0
- package/templates/src/catalog/AGENTS.md +37 -0
- package/templates/src/catalog/runtime/AGENTS.md +75 -0
- package/templates/src/catalog/runtime/_coercions.ts +1 -0
- package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
- package/templates/src/catalog/specs/AGENTS.md +48 -0
- package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
- package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
- package/templates/src/db/sql-client.ts +5 -5
- package/templates/src/jobs/AGENTS.md +26 -0
- package/templates/src/jobs/README.md +3 -0
- package/templates/src/repositories/AGENTS.md +118 -0
- package/templates/src/repositories/tables/AGENTS.md +94 -0
- package/templates/src/repositories/tables/README.md +3 -0
- package/templates/src/repositories/views/AGENTS.md +25 -0
- package/templates/src/repositories/views/README.md +3 -0
- package/templates/src/sql/AGENTS.md +77 -0
- package/templates/src/sql/README.md +6 -0
- package/templates/tests/AGENTS.md +43 -150
- package/templates/tests/generated/AGENTS.md +16 -0
- package/templates/tests/smoke.test.ts +5 -0
- package/templates/tests/smoke.validation.test.ts +34 -0
- package/templates/tests/support/AGENTS.md +26 -0
- package/templates/tests/support/global-setup.ts +8 -23
- package/templates/tests/support/testkit-client.ts +13 -741
- package/templates/tsconfig.json +8 -1
- package/templates/ztd/AGENTS.md +11 -67
- package/templates/ztd/README.md +4 -13
- package/templates/ztd/ddl/AGENTS.md +34 -0
- package/templates/ztd/ddl/demo.sql +74 -0
- package/templates/src/repositories/user-accounts.ts +0 -179
- package/templates/tests/user-profiles.test.ts +0 -161
- package/templates/tests/writer-constraints.test.ts +0 -32
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# src/repositories/tables AGENTS
|
|
2
|
+
|
|
3
|
+
This directory contains simple CRUD-style repositories.
|
|
4
|
+
|
|
5
|
+
## Runtime classification
|
|
6
|
+
|
|
7
|
+
- This is a runtime directory.
|
|
8
|
+
- Code here executes SQL and returns application-facing results.
|
|
9
|
+
|
|
10
|
+
## Responsibilities
|
|
11
|
+
|
|
12
|
+
- Execute SQL assets using defined contracts.
|
|
13
|
+
- Perform explicit mapping from SQL rows to DTOs.
|
|
14
|
+
- Enforce CUD semantics at the application boundary (including "0 rows" handling).
|
|
15
|
+
|
|
16
|
+
## Contract ownership (important)
|
|
17
|
+
|
|
18
|
+
- Input parameter types and DTO shapes are defined in specs ("src/catalog/specs").
|
|
19
|
+
- Repositories MUST NOT invent or modify contracts.
|
|
20
|
+
- Repositories may adapt SQL results into DTOs, but must not redefine the contract.
|
|
21
|
+
|
|
22
|
+
## SQL usage rules (tables CRUD quality bar)
|
|
23
|
+
|
|
24
|
+
- Repositories in this folder MUST treat SQL assets as human-maintained, idiomatic SQL.
|
|
25
|
+
- Do not require SQL assets to implement driver-specific behaviors.
|
|
26
|
+
- If a driver does not provide affected-row counts for UPDATE/DELETE, fail fast as unsupported.
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
- Prefer a plain UPDATE statement in SQL.
|
|
30
|
+
- Do not force SQL to return `affected_count` via CTE tricks.
|
|
31
|
+
|
|
32
|
+
## CUD behavior rules
|
|
33
|
+
|
|
34
|
+
### CREATE (INSERT)
|
|
35
|
+
|
|
36
|
+
Default:
|
|
37
|
+
- SQL MUST use `insert ... returning <primary_key>` when a generated key is needed.
|
|
38
|
+
- Repository CREATE MUST return identifier only (scalar) per contract.
|
|
39
|
+
- Repository CREATE MUST NOT perform a follow-up SELECT for DTO return shaping.
|
|
40
|
+
- SQL MUST NOT return full rows or DTO-shaped payloads.
|
|
41
|
+
|
|
42
|
+
Exception:
|
|
43
|
+
- If a CREATE endpoint must return DTO, the spec MUST explicitly require it by human instruction.
|
|
44
|
+
- Without that explicit contract, identifier-only return is mandatory.
|
|
45
|
+
|
|
46
|
+
### UPDATE
|
|
47
|
+
|
|
48
|
+
Default:
|
|
49
|
+
- SQL: plain UPDATE without RETURNING.
|
|
50
|
+
- Repository: determine success by affected row count when available.
|
|
51
|
+
|
|
52
|
+
Driver variability handling:
|
|
53
|
+
- If affected row count is unavailable:
|
|
54
|
+
- Treat UPDATE verification as unsupported for that driver/runtime.
|
|
55
|
+
- Throw an explicit error.
|
|
56
|
+
- Do not add fallback checks or workaround logic in repositories.
|
|
57
|
+
- Do not push this variability down into SQL assets.
|
|
58
|
+
|
|
59
|
+
0-row rule (important):
|
|
60
|
+
- Treat "0 rows updated" as a meaningful condition.
|
|
61
|
+
- Default behavior is to surface it clearly (often an error), per spec.
|
|
62
|
+
|
|
63
|
+
### DELETE
|
|
64
|
+
|
|
65
|
+
Default:
|
|
66
|
+
- SQL: plain DELETE without RETURNING.
|
|
67
|
+
- Repository: determine success by affected row count when available.
|
|
68
|
+
|
|
69
|
+
Driver variability handling:
|
|
70
|
+
- If affected row count is unavailable:
|
|
71
|
+
- Treat DELETE verification as unsupported for that driver/runtime.
|
|
72
|
+
- Throw an explicit error.
|
|
73
|
+
- Do not add fallback checks or workaround logic in repositories.
|
|
74
|
+
|
|
75
|
+
0-row rule (important):
|
|
76
|
+
- Treat "0 rows deleted" as a meaningful condition, per spec.
|
|
77
|
+
|
|
78
|
+
## Patch updates (important)
|
|
79
|
+
|
|
80
|
+
- Avoid ambiguous patterns such as `coalesce(param, column)` by default.
|
|
81
|
+
- Contracts should distinguish:
|
|
82
|
+
- "not provided"
|
|
83
|
+
- "explicitly set to null"
|
|
84
|
+
- If patch semantics are needed, implement them explicitly via:
|
|
85
|
+
- separate SQL variants, or
|
|
86
|
+
- explicit contract types that preserve intent.
|
|
87
|
+
|
|
88
|
+
## Testing rule (required)
|
|
89
|
+
|
|
90
|
+
- Every public repository method MUST be covered by tests.
|
|
91
|
+
- Tests should verify:
|
|
92
|
+
- correct mapping behavior
|
|
93
|
+
- correct "0 rows" behavior for UPDATE/DELETE
|
|
94
|
+
- correct error surfaces (do not silently succeed)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# src/repositories/views AGENTS
|
|
2
|
+
|
|
3
|
+
This folder is for complex read-only queries.
|
|
4
|
+
|
|
5
|
+
## Scope
|
|
6
|
+
|
|
7
|
+
- Complex SELECT queries (joins, aggregations, window functions).
|
|
8
|
+
- Read models that are not 1:1 with a single table.
|
|
9
|
+
|
|
10
|
+
## Allowed
|
|
11
|
+
|
|
12
|
+
- Multi-table joins and aggregations.
|
|
13
|
+
- Purpose-built DTOs for read models.
|
|
14
|
+
- Validation at the boundary (catalog validator or repository-level validator).
|
|
15
|
+
|
|
16
|
+
## Forbidden
|
|
17
|
+
|
|
18
|
+
- INSERT/UPDATE/DELETE in this folder by default.
|
|
19
|
+
- Hidden write side-effects.
|
|
20
|
+
|
|
21
|
+
## Guidance
|
|
22
|
+
|
|
23
|
+
- Keep query intent clear in naming.
|
|
24
|
+
- Document cardinality assumptions (one, many, optional).
|
|
25
|
+
- Prefer stable ordering if tests rely on order.
|
|
@@ -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".
|
|
@@ -1,169 +1,62 @@
|
|
|
1
|
-
# AGENTS
|
|
1
|
+
# tests AGENTS
|
|
2
2
|
|
|
3
|
-
This
|
|
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
|
-
|
|
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.
|
|
7
|
+
- This is a non-runtime directory.
|
|
8
|
+
- Code here is never part of application runtime.
|
|
26
9
|
|
|
27
|
-
|
|
10
|
+
## Core principles
|
|
28
11
|
|
|
29
|
-
|
|
12
|
+
- This project uses ZTD (Zero Table Dependency).
|
|
13
|
+
- DDL and fixtures define the test world.
|
|
14
|
+
- Tests must be deterministic and parallel-safe.
|
|
30
15
|
|
|
31
|
-
|
|
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/`.
|
|
16
|
+
## What to test (important)
|
|
36
17
|
|
|
37
|
-
|
|
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
|
|
38
24
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
category_id: number;
|
|
42
|
-
parent_id: number | null;
|
|
43
|
-
name: string;
|
|
44
|
-
};
|
|
45
|
-
```
|
|
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.
|
|
46
27
|
|
|
47
|
-
|
|
48
|
-
- Regenerate generated artifacts (`npx ztd ztd-config`), or
|
|
49
|
-
- Export the correct type from `src/`.
|
|
28
|
+
## CUD test policy (important)
|
|
50
29
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
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.
|
|
54
37
|
|
|
55
|
-
|
|
38
|
+
## Generated artifacts
|
|
56
39
|
|
|
57
|
-
|
|
40
|
+
- "tests/generated/" is auto-generated.
|
|
41
|
+
- Do not edit generated files by hand.
|
|
42
|
+
- Regenerate before debugging type errors.
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
- Do not write tests that depend on state accumulating across multiple repository calls.
|
|
44
|
+
## Boundaries
|
|
61
45
|
|
|
62
|
-
|
|
63
|
-
-
|
|
64
|
-
- Calling multiple repository methods assuming earlier calls affected the database
|
|
46
|
+
- Tests may import from "src/".
|
|
47
|
+
- Runtime code under "src/" MUST NOT import from "tests/" or "tests/generated/".
|
|
65
48
|
|
|
66
|
-
|
|
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
|
|
49
|
+
## Test runner requirements (required)
|
|
71
50
|
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
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.
|
|
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.
|
|
77
54
|
|
|
78
|
-
|
|
55
|
+
Do not add tests that assume manual setup steps.
|
|
79
56
|
|
|
80
|
-
##
|
|
57
|
+
## Initialization invariant
|
|
81
58
|
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
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
|
|
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,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
|
-
*
|
|
7
|
-
*
|
|
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
|
|
15
|
-
|
|
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
|
-
|