@voxgig/sdkgen 0.45.0 → 1.0.1
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/bin/voxgig-sdkgen +1 -1
- package/package.json +3 -3
- package/project/.sdk/src/cmp/go/Entity_go.ts +2 -2
- package/project/.sdk/src/cmp/go/Main_go.ts +8 -4
- package/project/.sdk/src/cmp/go/Package_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeExplanation_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeInstall_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +2 -2
- package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +2 -2
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +204 -33
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +37 -6
- package/project/.sdk/src/cmp/go/Test_go.ts +2 -2
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +21 -4
- package/project/.sdk/src/cmp/lua/Package_lua.ts +9 -2
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +154 -21
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +25 -1
- package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +20 -4
- package/project/.sdk/src/cmp/php/Package_php.ts +7 -1
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +153 -20
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +25 -1
- package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +17 -3
- package/project/.sdk/src/cmp/py/Package_py.ts +8 -1
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +146 -19
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +25 -1
- package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +19 -4
- package/project/.sdk/src/cmp/rb/Package_rb.ts +9 -2
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +154 -21
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +25 -1
- package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +19 -3
- package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +145 -22
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +59 -1
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +8 -1
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +8 -2
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +21 -1
- package/project/.sdk/tm/go/feature/test_feature.go +51 -3
- package/project/.sdk/tm/go/test/runner_test.go +106 -6
- package/project/.sdk/tm/go/test/sdk-test-control.json +19 -0
- package/project/.sdk/tm/go/utility/fetcher.go +10 -0
- package/project/.sdk/tm/go/utility/make_url.go +12 -0
- package/project/.sdk/tm/lua/feature/test_feature.lua +41 -3
- package/project/.sdk/tm/lua/test/runner.lua +74 -0
- package/project/.sdk/tm/lua/test/sdk-test-control.json +19 -0
- package/project/.sdk/tm/lua/utility/fetcher.lua +13 -0
- package/project/.sdk/tm/lua/utility/make_url.lua +16 -0
- package/project/.sdk/tm/php/feature/TestFeature.php +185 -43
- package/project/.sdk/tm/php/test/Runner.php +62 -0
- package/project/.sdk/tm/php/test/sdk-test-control.json +19 -0
- package/project/.sdk/tm/php/utility/Fetcher.php +132 -9
- package/project/.sdk/tm/php/utility/MakeUrl.php +16 -0
- package/project/.sdk/tm/py/feature/test_feature.py +35 -3
- package/project/.sdk/tm/py/test/runner.py +60 -0
- package/project/.sdk/tm/py/test/sdk-test-control.json +19 -0
- package/project/.sdk/tm/py/utility/fetcher.py +13 -0
- package/project/.sdk/tm/py/utility/make_url.py +13 -0
- package/project/.sdk/tm/rb/feature/test_feature.rb +36 -3
- package/project/.sdk/tm/rb/test/runner.rb +46 -0
- package/project/.sdk/tm/rb/test/sdk-test-control.json +19 -0
- package/project/.sdk/tm/rb/utility/fetcher.rb +49 -28
- package/project/.sdk/tm/rb/utility/make_url.rb +16 -0
- package/project/.sdk/tm/ts/test/sdk-test-control.json +19 -0
- package/project/.sdk/tm/ts/test/utility.ts +120 -2
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared utility functions for unit tests
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* This module provides common helper functions used across unit tests
|
|
5
5
|
* for creating test data, transformations, validations, and environment overrides.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import * as Fs from 'node:fs'
|
|
9
|
+
import * as Path from 'node:path'
|
|
10
|
+
|
|
11
|
+
|
|
8
12
|
// Creates a new step data structure within the data model
|
|
9
13
|
function makeStepData(dm: Record<string, any>, stepname: string): Record<string, any> {
|
|
10
14
|
dm.s[stepname] = {
|
|
@@ -76,11 +80,125 @@ function envOverride(m: Record<string, any>) {
|
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
|
|
83
|
+
// Loads sdk-test-control.json (cached). Returns an empty-skip object if
|
|
84
|
+
// the file is missing or unparsable so tests never crash on a bad config.
|
|
85
|
+
type TestControl = {
|
|
86
|
+
version?: number
|
|
87
|
+
test?: {
|
|
88
|
+
skip?: {
|
|
89
|
+
live?: { direct?: any[], entityOp?: any[] }
|
|
90
|
+
unit?: { direct?: any[], entityOp?: any[] }
|
|
91
|
+
}
|
|
92
|
+
live?: { delayMs?: number }
|
|
93
|
+
[k: string]: any
|
|
94
|
+
}
|
|
95
|
+
[k: string]: any
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let _testControlCache: TestControl | null = null
|
|
99
|
+
|
|
100
|
+
function loadTestControl(): TestControl {
|
|
101
|
+
if (_testControlCache) return _testControlCache
|
|
102
|
+
const ctrlPath = Path.resolve(__dirname, '../test/sdk-test-control.json')
|
|
103
|
+
try {
|
|
104
|
+
_testControlCache = JSON.parse(Fs.readFileSync(ctrlPath, 'utf8')) as TestControl
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
_testControlCache = {
|
|
108
|
+
version: 1,
|
|
109
|
+
test: { skip: { live: { direct: [], entityOp: [] }, unit: { direct: [], entityOp: [] } } }
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return _testControlCache!
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
// Returns the skip decision for a given test name from sdk-test-control.json.
|
|
117
|
+
// `kind` is 'direct' (matches by `test` field) or 'entityOp' (matches by
|
|
118
|
+
// `entity` + `op`). `mode` is 'live' or 'unit'.
|
|
119
|
+
function isControlSkipped(
|
|
120
|
+
kind: 'direct' | 'entityOp',
|
|
121
|
+
name: string,
|
|
122
|
+
mode: 'live' | 'unit'
|
|
123
|
+
): { skip: boolean, reason?: string } {
|
|
124
|
+
const ctrl = loadTestControl()
|
|
125
|
+
const list = ctrl?.test?.skip?.[mode]?.[kind] ?? []
|
|
126
|
+
for (const e of list) {
|
|
127
|
+
if (kind === 'direct' && e?.test === name) {
|
|
128
|
+
return { skip: true, reason: e.reason }
|
|
129
|
+
}
|
|
130
|
+
if (kind === 'entityOp') {
|
|
131
|
+
const key = (e?.entity ?? '') + '.' + (e?.op ?? '')
|
|
132
|
+
if (key === name) return { skip: true, reason: e.reason }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { skip: false }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// Skips the current test if sdk-test-control.json lists it. Returns true
|
|
140
|
+
// when skipped (caller should `return` immediately).
|
|
141
|
+
function maybeSkipControl(
|
|
142
|
+
t: any,
|
|
143
|
+
kind: 'direct' | 'entityOp',
|
|
144
|
+
name: string,
|
|
145
|
+
live: boolean
|
|
146
|
+
): boolean {
|
|
147
|
+
const decision = isControlSkipped(kind, name, live ? 'live' : 'unit')
|
|
148
|
+
if (decision.skip) {
|
|
149
|
+
t.skip(decision.reason || 'skipped via sdk-test-control.json')
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
return false
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// Skips the current live test when required idmap keys aren't supplied.
|
|
157
|
+
// Generated tests call this when they would otherwise pass `undefined`
|
|
158
|
+
// values into a path/query param and 4xx the request.
|
|
159
|
+
function skipIfMissingIds(t: any, setup: any, requiredKeys: string[]): boolean {
|
|
160
|
+
if (!setup.live) return false
|
|
161
|
+
const missing = requiredKeys.filter(k => null == setup.idmap?.[k])
|
|
162
|
+
if (missing.length > 0) {
|
|
163
|
+
t.skip(`live test needs ${missing.join(', ')} via *_ENTID env var (synthetic IDs only)`)
|
|
164
|
+
return true
|
|
165
|
+
}
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
// Per-test live pacing delay (ms). Read from sdk-test-control.json
|
|
171
|
+
// `test.live.delayMs`; defaults to 500ms if absent or invalid.
|
|
172
|
+
function liveDelayMs(): number {
|
|
173
|
+
const ctrl = loadTestControl()
|
|
174
|
+
const v = ctrl?.test?.live?.delayMs
|
|
175
|
+
return ('number' === typeof v && v >= 0) ? v : 500
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
// afterEach hook helper for live pacing. Generated tests register this
|
|
180
|
+
// via `afterEach(liveDelay(<envVar>))`; it sleeps `liveDelayMs()` only
|
|
181
|
+
// when the SDK's *_TEST_LIVE env var is set.
|
|
182
|
+
function liveDelay(liveEnvVar: string): () => Promise<void> {
|
|
183
|
+
return async () => {
|
|
184
|
+
if ('TRUE' === process.env[liveEnvVar]) {
|
|
185
|
+
await new Promise(r => setTimeout(r, liveDelayMs()))
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
79
191
|
export {
|
|
80
192
|
makeStepData,
|
|
81
193
|
makeMatch,
|
|
82
194
|
makeReqdata,
|
|
83
195
|
makeValid,
|
|
84
196
|
makeCtrl,
|
|
85
|
-
envOverride
|
|
197
|
+
envOverride,
|
|
198
|
+
loadTestControl,
|
|
199
|
+
isControlSkipped,
|
|
200
|
+
maybeSkipControl,
|
|
201
|
+
skipIfMissingIds,
|
|
202
|
+
liveDelayMs,
|
|
203
|
+
liveDelay,
|
|
86
204
|
}
|