@workos/oagen-emitters 0.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/.github/workflows/ci.yml +20 -0
- package/.github/workflows/lint-pr-title.yml +16 -0
- package/.github/workflows/lint.yml +21 -0
- package/.github/workflows/release-please.yml +28 -0
- package/.github/workflows/release.yml +32 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.husky/pre-push +1 -0
- package/.node-version +1 -0
- package/.oxfmtrc.json +10 -0
- package/.oxlintrc.json +29 -0
- package/.vscode/settings.json +11 -0
- package/LICENSE.txt +21 -0
- package/README.md +123 -0
- package/commitlint.config.ts +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2158 -0
- package/docs/endpoint-coverage.md +275 -0
- package/docs/sdk-architecture/node.md +355 -0
- package/oagen.config.ts +51 -0
- package/package.json +83 -0
- package/renovate.json +26 -0
- package/smoke/sdk-dotnet.ts +903 -0
- package/smoke/sdk-elixir.ts +771 -0
- package/smoke/sdk-go.ts +948 -0
- package/smoke/sdk-kotlin.ts +799 -0
- package/smoke/sdk-node.ts +516 -0
- package/smoke/sdk-php.ts +699 -0
- package/smoke/sdk-python.ts +738 -0
- package/smoke/sdk-ruby.ts +723 -0
- package/smoke/sdk-rust.ts +774 -0
- package/src/compat/extractors/dotnet.ts +8 -0
- package/src/compat/extractors/elixir.ts +8 -0
- package/src/compat/extractors/go.ts +8 -0
- package/src/compat/extractors/kotlin.ts +8 -0
- package/src/compat/extractors/node.ts +8 -0
- package/src/compat/extractors/php.ts +8 -0
- package/src/compat/extractors/python.ts +8 -0
- package/src/compat/extractors/ruby.ts +8 -0
- package/src/compat/extractors/rust.ts +8 -0
- package/src/index.ts +1 -0
- package/src/node/client.ts +356 -0
- package/src/node/common.ts +203 -0
- package/src/node/config.ts +70 -0
- package/src/node/enums.ts +87 -0
- package/src/node/errors.ts +205 -0
- package/src/node/fixtures.ts +139 -0
- package/src/node/index.ts +57 -0
- package/src/node/manifest.ts +23 -0
- package/src/node/models.ts +323 -0
- package/src/node/naming.ts +96 -0
- package/src/node/resources.ts +380 -0
- package/src/node/serializers.ts +286 -0
- package/src/node/tests.ts +336 -0
- package/src/node/type-map.ts +56 -0
- package/src/node/utils.ts +164 -0
- package/test/compat/extractors/node.test.ts +145 -0
- package/test/fixtures/sample-sdk-node/package.json +7 -0
- package/test/fixtures/sample-sdk-node/src/client.ts +24 -0
- package/test/fixtures/sample-sdk-node/src/index.ts +4 -0
- package/test/fixtures/sample-sdk-node/src/models.ts +28 -0
- package/test/fixtures/sample-sdk-node/tsconfig.json +13 -0
- package/test/node/client.test.ts +165 -0
- package/test/node/enums.test.ts +128 -0
- package/test/node/errors.test.ts +65 -0
- package/test/node/models.test.ts +301 -0
- package/test/node/naming.test.ts +212 -0
- package/test/node/resources.test.ts +260 -0
- package/test/node/serializers.test.ts +206 -0
- package/test/node/type-map.test.ts +127 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +8 -0
- package/vitest.config.ts +4 -0
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ruby SDK smoke test -- captures wire-level HTTP exchanges from the generated
|
|
3
|
+
* WorkOS Ruby SDK via a local proxy and outputs SmokeResults JSON for diff comparison.
|
|
4
|
+
*
|
|
5
|
+
* Uses a batched approach: generates ONE Ruby script that calls ALL operations
|
|
6
|
+
* sequentially, eliminating per-operation cold start overhead.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* npx tsx smoke/sdk-ruby.ts --spec ../openapi-spec/spec/open-api-spec.yaml --sdk-path ./sdk-ruby
|
|
10
|
+
*
|
|
11
|
+
* Requires API_KEY or WORKOS_API_KEY env var.
|
|
12
|
+
* Requires `ruby` to be available on $PATH.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync, writeFileSync, existsSync, mkdtempSync } from 'node:fs';
|
|
16
|
+
import { resolve, join } from 'node:path';
|
|
17
|
+
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http';
|
|
18
|
+
import { request as httpsRequest } from 'node:https';
|
|
19
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
20
|
+
import { tmpdir } from 'node:os';
|
|
21
|
+
import {
|
|
22
|
+
parseSpec,
|
|
23
|
+
planOperations,
|
|
24
|
+
planWaves,
|
|
25
|
+
generatePayload,
|
|
26
|
+
generateQueryParams,
|
|
27
|
+
IdRegistry,
|
|
28
|
+
delay,
|
|
29
|
+
parseCliArgs,
|
|
30
|
+
loadSmokeConfig,
|
|
31
|
+
getExpectedStatusCodes,
|
|
32
|
+
isUnexpectedStatus,
|
|
33
|
+
toSnakeCase,
|
|
34
|
+
SERVICE_PROPERTY_MAP,
|
|
35
|
+
} from '@workos/oagen/smoke';
|
|
36
|
+
import type { CapturedExchange, SmokeResults, ExchangeProvenance, OperationWave } from '@workos/oagen/smoke';
|
|
37
|
+
import type { Operation } from '@workos/oagen';
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Types
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
interface ManifestEntry {
|
|
44
|
+
sdkMethod: string;
|
|
45
|
+
service: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface CapturedRequest {
|
|
49
|
+
method: string;
|
|
50
|
+
path: string;
|
|
51
|
+
queryParams: Record<string, string>;
|
|
52
|
+
body: unknown | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface CapturedResponse {
|
|
56
|
+
status: number;
|
|
57
|
+
body: unknown | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface ProxyCapture {
|
|
61
|
+
request: CapturedRequest;
|
|
62
|
+
response: CapturedResponse;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Method resolution
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
interface MethodResolution {
|
|
70
|
+
service: string;
|
|
71
|
+
method: string;
|
|
72
|
+
tier: ExchangeProvenance['resolutionTier'];
|
|
73
|
+
confidence: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Manifest loading
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
function loadManifest(sdkPath: string): Map<string, ManifestEntry> | null {
|
|
81
|
+
const manifestPath = resolve(sdkPath, 'smoke-manifest.json');
|
|
82
|
+
if (!existsSync(manifestPath)) {
|
|
83
|
+
console.warn(`Warning: No smoke-manifest.json found at ${manifestPath}`);
|
|
84
|
+
console.warn(' Method resolution will rely on heuristic tiers -- most operations may be skipped.');
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const raw = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
88
|
+
const manifest = new Map<string, ManifestEntry>();
|
|
89
|
+
for (const [httpKey, entry] of Object.entries(raw)) {
|
|
90
|
+
manifest.set(httpKey, entry as ManifestEntry);
|
|
91
|
+
}
|
|
92
|
+
return manifest;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Method resolution
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
function resolveMethod(
|
|
100
|
+
op: Operation,
|
|
101
|
+
irService: string,
|
|
102
|
+
manifest: Map<string, ManifestEntry> | null,
|
|
103
|
+
): MethodResolution | null {
|
|
104
|
+
const httpKey = `${op.httpMethod.toUpperCase()} ${op.path}`;
|
|
105
|
+
|
|
106
|
+
// Tier 0: Manifest match (primary for generated SDKs)
|
|
107
|
+
if (manifest) {
|
|
108
|
+
const entry = manifest.get(httpKey);
|
|
109
|
+
if (entry) {
|
|
110
|
+
return {
|
|
111
|
+
service: entry.service,
|
|
112
|
+
method: entry.sdkMethod,
|
|
113
|
+
tier: 'manifest',
|
|
114
|
+
confidence: 1.0,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Tier 1: Exact match -- IR operation name in snake_case
|
|
120
|
+
const sdkProp = SERVICE_PROPERTY_MAP[irService] || toSnakeCase(irService);
|
|
121
|
+
const exactName = toSnakeCase(op.name);
|
|
122
|
+
return {
|
|
123
|
+
service: sdkProp,
|
|
124
|
+
method: exactName,
|
|
125
|
+
tier: 'exact',
|
|
126
|
+
confidence: 0.8,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Proxy server
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
function startProxy(
|
|
135
|
+
apiHost: string,
|
|
136
|
+
apiKey: string,
|
|
137
|
+
captures: ProxyCapture[],
|
|
138
|
+
): Promise<{ port: number; close: () => Promise<void> }> {
|
|
139
|
+
return new Promise((resolvePromise) => {
|
|
140
|
+
const server = createServer((req: IncomingMessage, res: ServerResponse) => {
|
|
141
|
+
const chunks: Buffer[] = [];
|
|
142
|
+
|
|
143
|
+
req.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
144
|
+
req.on('end', () => {
|
|
145
|
+
const rawBody = Buffer.concat(chunks).toString('utf-8');
|
|
146
|
+
const url = new URL(req.url || '/', `http://localhost`);
|
|
147
|
+
const method = (req.method || 'GET').toUpperCase();
|
|
148
|
+
const path = url.pathname;
|
|
149
|
+
const queryParams: Record<string, string> = {};
|
|
150
|
+
url.searchParams.forEach((v, k) => {
|
|
151
|
+
queryParams[k] = v;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
let reqBody: unknown = null;
|
|
155
|
+
if (rawBody) {
|
|
156
|
+
try {
|
|
157
|
+
reqBody = JSON.parse(rawBody);
|
|
158
|
+
} catch {
|
|
159
|
+
reqBody = rawBody;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const capturedReq: CapturedRequest = { method, path, queryParams, body: reqBody };
|
|
164
|
+
|
|
165
|
+
// Forward to real API
|
|
166
|
+
const forwardHeaders: Record<string, string> = {
|
|
167
|
+
authorization: `Bearer ${apiKey}`,
|
|
168
|
+
'content-type': req.headers['content-type'] || 'application/json',
|
|
169
|
+
'user-agent': req.headers['user-agent'] || 'workos-ruby-smoke',
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (rawBody) {
|
|
173
|
+
forwardHeaders['content-length'] = Buffer.byteLength(rawBody).toString();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const forwardReq = httpsRequest(
|
|
177
|
+
{
|
|
178
|
+
hostname: apiHost,
|
|
179
|
+
port: 443,
|
|
180
|
+
path: req.url,
|
|
181
|
+
method,
|
|
182
|
+
headers: forwardHeaders,
|
|
183
|
+
},
|
|
184
|
+
(forwardRes) => {
|
|
185
|
+
const respChunks: Buffer[] = [];
|
|
186
|
+
forwardRes.on('data', (chunk: Buffer) => respChunks.push(chunk));
|
|
187
|
+
forwardRes.on('end', () => {
|
|
188
|
+
const respRaw = Buffer.concat(respChunks).toString('utf-8');
|
|
189
|
+
const status = forwardRes.statusCode || 500;
|
|
190
|
+
|
|
191
|
+
let respBody: unknown = null;
|
|
192
|
+
if (respRaw) {
|
|
193
|
+
try {
|
|
194
|
+
respBody = JSON.parse(respRaw);
|
|
195
|
+
} catch {
|
|
196
|
+
respBody = respRaw;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
captures.push({
|
|
201
|
+
request: capturedReq,
|
|
202
|
+
response: { status, body: respBody },
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Send response back to Ruby SDK
|
|
206
|
+
res.writeHead(status, {
|
|
207
|
+
'content-type': forwardRes.headers['content-type'] || 'application/json',
|
|
208
|
+
});
|
|
209
|
+
res.end(respRaw);
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
forwardReq.on('error', (err) => {
|
|
215
|
+
console.error(`Proxy forward error: ${err.message}`);
|
|
216
|
+
captures.push({
|
|
217
|
+
request: capturedReq,
|
|
218
|
+
response: { status: 502, body: { error: err.message } },
|
|
219
|
+
});
|
|
220
|
+
res.writeHead(502, { 'content-type': 'application/json' });
|
|
221
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
if (rawBody) {
|
|
225
|
+
forwardReq.write(rawBody);
|
|
226
|
+
}
|
|
227
|
+
forwardReq.end();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Listen on a random port
|
|
232
|
+
server.listen(0, '127.0.0.1', () => {
|
|
233
|
+
const addr = server.address();
|
|
234
|
+
const port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
235
|
+
resolvePromise({
|
|
236
|
+
port,
|
|
237
|
+
close: () =>
|
|
238
|
+
new Promise<void>((r) => {
|
|
239
|
+
server.close(() => r());
|
|
240
|
+
}),
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
// Ruby literal helper
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
/** Convert a JS value to a Ruby literal string */
|
|
251
|
+
function rubyLiteral(value: unknown): string {
|
|
252
|
+
if (value === null || value === undefined) return 'nil';
|
|
253
|
+
if (typeof value === 'string') return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
254
|
+
if (typeof value === 'number') return String(value);
|
|
255
|
+
if (typeof value === 'boolean') return value ? 'true' : 'false';
|
|
256
|
+
if (Array.isArray(value)) {
|
|
257
|
+
return `[${value.map((v) => rubyLiteral(v)).join(', ')}]`;
|
|
258
|
+
}
|
|
259
|
+
if (typeof value === 'object') {
|
|
260
|
+
const entries = Object.entries(value as Record<string, unknown>);
|
|
261
|
+
const pairs = entries.map(([k, v]) => `${k}: ${rubyLiteral(v)}`);
|
|
262
|
+
return `{ ${pairs.join(', ')} }`;
|
|
263
|
+
}
|
|
264
|
+
return String(value);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
// Batched Ruby script generation
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
|
|
271
|
+
interface PlannedCall {
|
|
272
|
+
index: number;
|
|
273
|
+
op: Operation;
|
|
274
|
+
irService: string;
|
|
275
|
+
resolution: MethodResolution;
|
|
276
|
+
pathParams: Record<string, string>;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Build a single Ruby script that calls ALL planned operations sequentially.
|
|
281
|
+
* Each call is wrapped with JSONL markers on $stderr for correlation.
|
|
282
|
+
*/
|
|
283
|
+
function buildBatchedRubyScript(sdkPath: string, proxyPort: number, calls: PlannedCall[], spec: any): string {
|
|
284
|
+
const lines: string[] = [];
|
|
285
|
+
|
|
286
|
+
// Preamble -- loaded once
|
|
287
|
+
lines.push(`$LOAD_PATH.unshift(File.join("${sdkPath}", "lib"))`);
|
|
288
|
+
lines.push(`require "workos"`);
|
|
289
|
+
lines.push(`require "json"`);
|
|
290
|
+
lines.push('');
|
|
291
|
+
lines.push(`client = Workos::Client.new(`);
|
|
292
|
+
lines.push(` api_key: ENV["WORKOS_API_KEY"],`);
|
|
293
|
+
lines.push(` base_url: "http://127.0.0.1:${proxyPort}"`);
|
|
294
|
+
lines.push(`)`);
|
|
295
|
+
lines.push('');
|
|
296
|
+
|
|
297
|
+
for (const call of calls) {
|
|
298
|
+
const { index, op, resolution, pathParams } = call;
|
|
299
|
+
|
|
300
|
+
// Marker: start
|
|
301
|
+
lines.push(`$stderr.puts "OAGEN_CALL_START:${index}"`);
|
|
302
|
+
lines.push(`$stderr.flush`);
|
|
303
|
+
|
|
304
|
+
// Build method call arguments
|
|
305
|
+
const argParts: string[] = [];
|
|
306
|
+
|
|
307
|
+
for (const p of op.pathParams) {
|
|
308
|
+
const value = pathParams[p.name];
|
|
309
|
+
argParts.push(rubyLiteral(value));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (op.requestBody) {
|
|
313
|
+
const payload = generatePayload(op, spec);
|
|
314
|
+
if (payload) {
|
|
315
|
+
argParts.push(rubyLiteral(payload));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!op.requestBody && op.queryParams.some((p) => p.required)) {
|
|
320
|
+
const queryOpts = generateQueryParams(op, spec);
|
|
321
|
+
if (Object.keys(queryOpts).length > 0) {
|
|
322
|
+
argParts.push(rubyLiteral(queryOpts));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (op.pagination) {
|
|
327
|
+
argParts.push(`{ limit: 1 }`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
lines.push('begin');
|
|
331
|
+
lines.push(` result = client.${resolution.service}.${resolution.method}(${argParts.join(', ')})`);
|
|
332
|
+
lines.push(` $stderr.puts "OAGEN_CALL_OK:${index}"`);
|
|
333
|
+
lines.push('rescue => e');
|
|
334
|
+
lines.push(` $stderr.puts "OAGEN_CALL_ERROR:${index}:#{e.class}: #{e.message}"`);
|
|
335
|
+
lines.push('end');
|
|
336
|
+
|
|
337
|
+
// Marker: end
|
|
338
|
+
lines.push(`$stderr.puts "OAGEN_CALL_END:${index}"`);
|
|
339
|
+
lines.push(`$stderr.flush`);
|
|
340
|
+
|
|
341
|
+
// Small sleep to let proxy settle
|
|
342
|
+
lines.push('sleep 0.05');
|
|
343
|
+
lines.push('');
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return lines.join('\n');
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// ---------------------------------------------------------------------------
|
|
350
|
+
// Main
|
|
351
|
+
// ---------------------------------------------------------------------------
|
|
352
|
+
|
|
353
|
+
async function main(): Promise<void> {
|
|
354
|
+
const { spec: specPath, sdkPath, smokeConfig } = parseCliArgs();
|
|
355
|
+
|
|
356
|
+
if (!sdkPath) {
|
|
357
|
+
console.error('--sdk-path is required');
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const apiKey = process.env.WORKOS_API_KEY || process.env.API_KEY;
|
|
362
|
+
if (!apiKey) {
|
|
363
|
+
console.error('API key required. Set WORKOS_API_KEY or API_KEY env var.');
|
|
364
|
+
process.exit(1);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Verify ruby is available
|
|
368
|
+
try {
|
|
369
|
+
execFileSync('ruby', ['--version'], { stdio: 'pipe' });
|
|
370
|
+
} catch {
|
|
371
|
+
console.error('Ruby is required but not found on $PATH.');
|
|
372
|
+
process.exit(1);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Load config
|
|
376
|
+
loadSmokeConfig(smokeConfig);
|
|
377
|
+
|
|
378
|
+
// Parse spec
|
|
379
|
+
console.log('Parsing spec...');
|
|
380
|
+
const spec = await parseSpec(specPath);
|
|
381
|
+
console.log(`Spec: ${spec.name} v${spec.version}`);
|
|
382
|
+
|
|
383
|
+
// Load manifest
|
|
384
|
+
const manifest = loadManifest(sdkPath);
|
|
385
|
+
|
|
386
|
+
const baseUrl = process.env.WORKOS_BASE_URL || spec.baseUrl;
|
|
387
|
+
const apiHost = new URL(baseUrl).hostname;
|
|
388
|
+
|
|
389
|
+
// Start proxy
|
|
390
|
+
const captures: ProxyCapture[] = [];
|
|
391
|
+
const proxy = await startProxy(apiHost, apiKey, captures);
|
|
392
|
+
console.log(`Proxy listening on 127.0.0.1:${proxy.port}`);
|
|
393
|
+
|
|
394
|
+
// Plan operations
|
|
395
|
+
const groups = planOperations(spec);
|
|
396
|
+
const ids = new IdRegistry();
|
|
397
|
+
const exchanges: CapturedExchange[] = [];
|
|
398
|
+
const tmpDir = mkdtempSync(join(tmpdir(), 'oagen-ruby-smoke-'));
|
|
399
|
+
|
|
400
|
+
let successCount = 0;
|
|
401
|
+
let errorCount = 0;
|
|
402
|
+
let skipCount = 0;
|
|
403
|
+
let unexpectedCount = 0;
|
|
404
|
+
|
|
405
|
+
// Use wave-based planning: execute parameterless ops first, extract IDs,
|
|
406
|
+
// then plan the next wave of ops whose path params are now resolvable.
|
|
407
|
+
let globalCallIndex = 0;
|
|
408
|
+
|
|
409
|
+
const waveIterator = planWaves(groups, ids, (op, irService) => {
|
|
410
|
+
const resolution = resolveMethod(op, irService, manifest);
|
|
411
|
+
return resolution !== null;
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
let waveNumber = 0;
|
|
415
|
+
let waveResult = waveIterator.next();
|
|
416
|
+
|
|
417
|
+
while (!waveResult.done) {
|
|
418
|
+
const wave: OperationWave = waveResult.value;
|
|
419
|
+
waveNumber++;
|
|
420
|
+
|
|
421
|
+
// Build planned calls for this wave, resolving methods
|
|
422
|
+
const plannedCalls: PlannedCall[] = [];
|
|
423
|
+
const waveSkipped: Array<{ op: Operation; irService: string; reason: string }> = [];
|
|
424
|
+
|
|
425
|
+
for (const { op, irService, pathParams } of wave.calls) {
|
|
426
|
+
const resolution = resolveMethod(op, irService, manifest);
|
|
427
|
+
if (!resolution) {
|
|
428
|
+
waveSkipped.push({ op, irService, reason: 'No matching SDK method' });
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
plannedCalls.push({
|
|
432
|
+
index: globalCallIndex++,
|
|
433
|
+
op,
|
|
434
|
+
irService,
|
|
435
|
+
resolution,
|
|
436
|
+
pathParams,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Record skipped exchanges for this wave
|
|
441
|
+
for (const skip of waveSkipped) {
|
|
442
|
+
exchanges.push(makeSkippedExchange(skip.op, skip.irService, skip.reason));
|
|
443
|
+
skipCount++;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (plannedCalls.length === 0) {
|
|
447
|
+
waveResult = waveIterator.next();
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
console.log(`\n=== Wave ${waveNumber} (${plannedCalls.length} operations) ===`);
|
|
452
|
+
|
|
453
|
+
// Generate batched Ruby script for this wave
|
|
454
|
+
const rubyScript = buildBatchedRubyScript(resolve(sdkPath), proxy.port, plannedCalls, spec);
|
|
455
|
+
|
|
456
|
+
const scriptPath = join(tmpDir, `smoke_wave_${waveNumber}.rb`);
|
|
457
|
+
writeFileSync(scriptPath, rubyScript);
|
|
458
|
+
|
|
459
|
+
// Execute the batched script
|
|
460
|
+
const callResults = new Map<
|
|
461
|
+
number,
|
|
462
|
+
{
|
|
463
|
+
captureIndexBefore: number;
|
|
464
|
+
captureIndexAfter: number;
|
|
465
|
+
error?: string;
|
|
466
|
+
startTime: number;
|
|
467
|
+
endTime: number;
|
|
468
|
+
}
|
|
469
|
+
>();
|
|
470
|
+
|
|
471
|
+
let currentCallIndex = -1;
|
|
472
|
+
let currentCallStart = Date.now();
|
|
473
|
+
let currentCapturesBefore = 0;
|
|
474
|
+
|
|
475
|
+
try {
|
|
476
|
+
await new Promise<void>((resolvePromise, rejectPromise) => {
|
|
477
|
+
const child = spawn('ruby', [scriptPath], {
|
|
478
|
+
env: {
|
|
479
|
+
...process.env,
|
|
480
|
+
WORKOS_API_KEY: apiKey,
|
|
481
|
+
WORKOS_BASE_URL: `http://127.0.0.1:${proxy.port}`,
|
|
482
|
+
},
|
|
483
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const timeout = setTimeout(() => {
|
|
487
|
+
child.kill('SIGKILL');
|
|
488
|
+
rejectPromise(new Error('Batch Ruby script timed out after 300s'));
|
|
489
|
+
}, 300_000);
|
|
490
|
+
|
|
491
|
+
let stderrBuf = '';
|
|
492
|
+
|
|
493
|
+
child.stderr.on('data', (data: Buffer) => {
|
|
494
|
+
stderrBuf += data.toString();
|
|
495
|
+
const lines = stderrBuf.split('\n');
|
|
496
|
+
stderrBuf = lines.pop() || '';
|
|
497
|
+
|
|
498
|
+
for (const line of lines) {
|
|
499
|
+
const trimmed = line.trim();
|
|
500
|
+
if (trimmed.startsWith('OAGEN_CALL_START:')) {
|
|
501
|
+
const idx = parseInt(trimmed.slice('OAGEN_CALL_START:'.length), 10);
|
|
502
|
+
currentCallIndex = idx;
|
|
503
|
+
currentCallStart = Date.now();
|
|
504
|
+
currentCapturesBefore = captures.length;
|
|
505
|
+
} else if (trimmed.startsWith('OAGEN_CALL_OK:')) {
|
|
506
|
+
const idx = parseInt(trimmed.slice('OAGEN_CALL_OK:'.length), 10);
|
|
507
|
+
if (callResults.has(idx)) continue;
|
|
508
|
+
callResults.set(idx, {
|
|
509
|
+
captureIndexBefore: currentCapturesBefore,
|
|
510
|
+
captureIndexAfter: captures.length,
|
|
511
|
+
startTime: currentCallStart,
|
|
512
|
+
endTime: Date.now(),
|
|
513
|
+
});
|
|
514
|
+
} else if (trimmed.startsWith('OAGEN_CALL_ERROR:')) {
|
|
515
|
+
const rest = trimmed.slice('OAGEN_CALL_ERROR:'.length);
|
|
516
|
+
const colonIdx = rest.indexOf(':');
|
|
517
|
+
const idx = parseInt(rest.slice(0, colonIdx), 10);
|
|
518
|
+
const errMsg = rest.slice(colonIdx + 1);
|
|
519
|
+
if (callResults.has(idx)) continue;
|
|
520
|
+
callResults.set(idx, {
|
|
521
|
+
captureIndexBefore: currentCapturesBefore,
|
|
522
|
+
captureIndexAfter: captures.length,
|
|
523
|
+
error: errMsg,
|
|
524
|
+
startTime: currentCallStart,
|
|
525
|
+
endTime: Date.now(),
|
|
526
|
+
});
|
|
527
|
+
} else if (trimmed.startsWith('OAGEN_CALL_END:')) {
|
|
528
|
+
const idx = parseInt(trimmed.slice('OAGEN_CALL_END:'.length), 10);
|
|
529
|
+
const existing = callResults.get(idx);
|
|
530
|
+
if (existing) {
|
|
531
|
+
existing.captureIndexAfter = captures.length;
|
|
532
|
+
existing.endTime = Date.now();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
child.on('close', () => {
|
|
539
|
+
clearTimeout(timeout);
|
|
540
|
+
if (stderrBuf.trim()) {
|
|
541
|
+
const trimmed = stderrBuf.trim();
|
|
542
|
+
if (trimmed.startsWith('OAGEN_CALL_END:') && currentCallIndex >= 0) {
|
|
543
|
+
const existing = callResults.get(currentCallIndex);
|
|
544
|
+
if (existing) {
|
|
545
|
+
existing.captureIndexAfter = captures.length;
|
|
546
|
+
existing.endTime = Date.now();
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
resolvePromise();
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
child.on('error', (err) => {
|
|
554
|
+
clearTimeout(timeout);
|
|
555
|
+
rejectPromise(err);
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
} catch (err) {
|
|
559
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
560
|
+
console.error(`Batch execution error: ${message}`);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
await delay(200);
|
|
564
|
+
|
|
565
|
+
// Process results for this wave — extract IDs so the next wave can use them
|
|
566
|
+
for (const call of plannedCalls) {
|
|
567
|
+
const { index, op, irService, resolution } = call;
|
|
568
|
+
const isTopLevel = op.pathParams.length === 0;
|
|
569
|
+
const result = callResults.get(index);
|
|
570
|
+
|
|
571
|
+
if (!result) {
|
|
572
|
+
exchanges.push({
|
|
573
|
+
...makeSkippedExchange(op, irService, 'Call did not execute (batch script may have failed)'),
|
|
574
|
+
outcome: 'api-error',
|
|
575
|
+
durationMs: 0,
|
|
576
|
+
});
|
|
577
|
+
errorCount++;
|
|
578
|
+
console.log(` x ${op.name} -- did not execute`);
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const elapsed = result.endTime - result.startTime;
|
|
583
|
+
|
|
584
|
+
if (result.captureIndexAfter <= result.captureIndexBefore) {
|
|
585
|
+
if (result.error) {
|
|
586
|
+
exchanges.push({
|
|
587
|
+
...makeSkippedExchange(op, irService, result.error),
|
|
588
|
+
outcome: 'api-error',
|
|
589
|
+
durationMs: elapsed,
|
|
590
|
+
});
|
|
591
|
+
errorCount++;
|
|
592
|
+
console.log(` x ${op.name} -- ${result.error.split('\n')[0]}`);
|
|
593
|
+
} else {
|
|
594
|
+
exchanges.push(makeSkippedExchange(op, irService, 'No HTTP capture'));
|
|
595
|
+
skipCount++;
|
|
596
|
+
console.log(` SKIP ${op.name} -- no HTTP capture`);
|
|
597
|
+
}
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const capture = captures[result.captureIndexAfter - 1];
|
|
602
|
+
const exchange = buildExchange(op, irService, capture, elapsed, resolution);
|
|
603
|
+
|
|
604
|
+
if (result.error) {
|
|
605
|
+
exchange.error = result.error;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// Extract IDs from response (critical: feeds the next wave)
|
|
609
|
+
ids.extractAndStore(irService, capture.response.body, isTopLevel);
|
|
610
|
+
|
|
611
|
+
if (exchange.unexpectedStatus) {
|
|
612
|
+
unexpectedCount++;
|
|
613
|
+
console.log(` ! ${op.name} -> ${capture.response.status} (unexpected)`);
|
|
614
|
+
} else if (exchange.outcome === 'api-error') {
|
|
615
|
+
errorCount++;
|
|
616
|
+
console.log(` x ${op.name} -> ${capture.response.status}`);
|
|
617
|
+
} else {
|
|
618
|
+
successCount++;
|
|
619
|
+
console.log(` ok ${op.name} -> ${capture.response.status} (${elapsed}ms)`);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
exchanges.push(exchange);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// Advance to the next wave (IDs from this wave are now in the registry)
|
|
626
|
+
waveResult = waveIterator.next();
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Record any operations that could never be resolved
|
|
630
|
+
if (waveResult.done && waveResult.value) {
|
|
631
|
+
for (const unresolved of waveResult.value) {
|
|
632
|
+
exchanges.push(makeSkippedExchange(unresolved.operation, unresolved.service, 'Missing path param IDs'));
|
|
633
|
+
skipCount++;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
await proxy.close();
|
|
638
|
+
console.log('Proxy stopped.');
|
|
639
|
+
|
|
640
|
+
// Clean up temp directory
|
|
641
|
+
try {
|
|
642
|
+
const { rmSync } = await import('node:fs');
|
|
643
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
644
|
+
} catch {
|
|
645
|
+
// Ignore cleanup errors
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Write results
|
|
649
|
+
const results: SmokeResults = {
|
|
650
|
+
source: 'sdk-ruby',
|
|
651
|
+
timestamp: new Date().toISOString(),
|
|
652
|
+
specVersion: spec.version,
|
|
653
|
+
exchanges,
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
const outputPath = `smoke-results-sdk-ruby.json`;
|
|
657
|
+
writeFileSync(outputPath, JSON.stringify(results, null, 2));
|
|
658
|
+
console.log(`\nResults written to ${outputPath}`);
|
|
659
|
+
|
|
660
|
+
// Summary
|
|
661
|
+
const total = exchanges.length;
|
|
662
|
+
console.log(`\n=== Summary ===`);
|
|
663
|
+
console.log(` Total: ${total}`);
|
|
664
|
+
console.log(` Success: ${successCount}`);
|
|
665
|
+
console.log(` API errors: ${errorCount}`);
|
|
666
|
+
console.log(` Skipped: ${skipCount}`);
|
|
667
|
+
if (unexpectedCount > 0) {
|
|
668
|
+
console.log(` Unexpected: ${unexpectedCount}`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// ---------------------------------------------------------------------------
|
|
673
|
+
// Helpers
|
|
674
|
+
// ---------------------------------------------------------------------------
|
|
675
|
+
|
|
676
|
+
function makeSkippedExchange(op: Operation, service: string, reason: string): CapturedExchange {
|
|
677
|
+
return {
|
|
678
|
+
operationId: op.name,
|
|
679
|
+
service,
|
|
680
|
+
operationName: op.name,
|
|
681
|
+
request: { method: op.httpMethod.toUpperCase(), path: op.path, queryParams: {}, body: null },
|
|
682
|
+
response: { status: 0, body: null },
|
|
683
|
+
outcome: 'skipped',
|
|
684
|
+
error: reason,
|
|
685
|
+
durationMs: 0,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function buildExchange(
|
|
690
|
+
op: Operation,
|
|
691
|
+
service: string,
|
|
692
|
+
capture: ProxyCapture,
|
|
693
|
+
durationMs: number,
|
|
694
|
+
resolution: MethodResolution,
|
|
695
|
+
): CapturedExchange {
|
|
696
|
+
const status = capture.response.status;
|
|
697
|
+
const expectedCodes = getExpectedStatusCodes(op);
|
|
698
|
+
const unexpected = isUnexpectedStatus(status, op);
|
|
699
|
+
|
|
700
|
+
return {
|
|
701
|
+
operationId: op.name,
|
|
702
|
+
service,
|
|
703
|
+
operationName: op.name,
|
|
704
|
+
request: capture.request,
|
|
705
|
+
response: capture.response,
|
|
706
|
+
outcome: status >= 200 && status < 300 ? 'success' : 'api-error',
|
|
707
|
+
unexpectedStatus: unexpected || undefined,
|
|
708
|
+
expectedStatusCodes: expectedCodes,
|
|
709
|
+
durationMs,
|
|
710
|
+
provenance: {
|
|
711
|
+
resolutionTier: resolution.tier,
|
|
712
|
+
resolutionConfidence: resolution.confidence,
|
|
713
|
+
sdkMethodName: `${resolution.service}.${resolution.method}`,
|
|
714
|
+
captureIndex: 0,
|
|
715
|
+
totalCaptures: 1,
|
|
716
|
+
},
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
main().catch((err) => {
|
|
721
|
+
console.error('Fatal error:', err);
|
|
722
|
+
process.exit(1);
|
|
723
|
+
});
|