@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.
- package/README.md +38 -25
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.js +372 -118
- 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 +18 -10
- package/templates/AGENTS.md +36 -296
- package/templates/README.md +12 -237
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
- package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
- package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
- package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
- package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
- package/templates/dist/mapper-core/src/index.d.ts +160 -0
- package/templates/dist/mapper-core/src/index.js +637 -0
- package/templates/dist/mapper-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
- package/templates/dist/testkit-core/src/errors/index.js +111 -0
- package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
- package/templates/dist/testkit-core/src/index.d.ts +17 -0
- package/templates/dist/testkit-core/src/index.js +47 -0
- package/templates/dist/testkit-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
- package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
- package/templates/dist/testkit-core/src/types/index.js +3 -0
- package/templates/dist/testkit-core/src/types/index.js.map +1 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
- package/templates/dist/writer-core/src/index.d.ts +34 -0
- package/templates/dist/writer-core/src/index.js +115 -0
- package/templates/dist/writer-core/src/index.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.ts +24 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -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 -129
- 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/tests/ztd-layout.generated.ts +0 -2
- package/templates/tsconfig.json +9 -3
- package/templates/ztd/AGENTS.md +11 -142
- package/templates/ztd/README.md +4 -82
- package/templates/ztd/ddl/AGENTS.md +34 -0
- 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".
|
|
@@ -1,148 +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
|
-
|
|
7
|
+
- This is a non-runtime directory.
|
|
8
|
+
- Code here is never part of application runtime.
|
|
9
9
|
|
|
10
|
-
|
|
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
|
-
##
|
|
16
|
+
## What to test (important)
|
|
25
17
|
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
-
|
|
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
|
-
|
|
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
|
-
##
|
|
44
|
+
## Boundaries
|
|
51
45
|
|
|
52
|
-
-
|
|
53
|
-
-
|
|
46
|
+
- Tests may import from "src/".
|
|
47
|
+
- Runtime code under "src/" MUST NOT import from "tests/" or "tests/generated/".
|
|
54
48
|
|
|
55
|
-
|
|
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
|
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
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,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
|
-
|