@bitclaw/loadtest 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -0
  3. package/dist/__fixtures__/configs.d.ts +8 -0
  4. package/dist/__fixtures__/configs.d.ts.map +1 -0
  5. package/dist/__fixtures__/configs.js +75 -0
  6. package/dist/__fixtures__/results.d.ts +13 -0
  7. package/dist/__fixtures__/results.d.ts.map +1 -0
  8. package/dist/__fixtures__/results.js +121 -0
  9. package/dist/auth/session.d.ts +18 -0
  10. package/dist/auth/session.d.ts.map +1 -0
  11. package/dist/auth/session.js +58 -0
  12. package/dist/cli/commands/report.d.ts +6 -0
  13. package/dist/cli/commands/report.d.ts.map +1 -0
  14. package/dist/cli/commands/report.js +46 -0
  15. package/dist/cli/commands/run.d.ts +6 -0
  16. package/dist/cli/commands/run.d.ts.map +1 -0
  17. package/dist/cli/commands/run.js +97 -0
  18. package/dist/cli.d.ts +3 -0
  19. package/dist/cli.d.ts.map +1 -0
  20. package/dist/cli.js +12 -0
  21. package/dist/config/defaults.d.ts +77 -0
  22. package/dist/config/defaults.d.ts.map +1 -0
  23. package/dist/config/defaults.js +60 -0
  24. package/dist/config/loader.d.ts +14 -0
  25. package/dist/config/loader.d.ts.map +1 -0
  26. package/dist/config/loader.js +56 -0
  27. package/dist/index.d.ts +14 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +16 -0
  30. package/dist/reports/formatter.d.ts +18 -0
  31. package/dist/reports/formatter.d.ts.map +1 -0
  32. package/dist/reports/formatter.js +99 -0
  33. package/dist/runner/bun-runner.d.ts +21 -0
  34. package/dist/runner/bun-runner.d.ts.map +1 -0
  35. package/dist/runner/bun-runner.js +140 -0
  36. package/dist/runner/k6-runner.d.ts +12 -0
  37. package/dist/runner/k6-runner.d.ts.map +1 -0
  38. package/dist/runner/k6-runner.js +80 -0
  39. package/dist/types.d.ts +97 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +6 -0
  42. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Chavez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @bitclaw/loadtest
2
+
3
+ Load testing CLI for sqlite-saas apps. Supports both Bun-native and k6 test engines.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # From repo root
9
+ bun run loadtest:bun --app runmist # Quick Bun-native test
10
+ bun run loadtest:k6 --app runmist # Full k6 test
11
+
12
+ # From package directory
13
+ cd packages/loadtest
14
+ bun src/cli.ts run --app runmist --mode quick
15
+ bun src/cli.ts report --app runmist
16
+ ```
17
+
18
+ ## CLI Usage
19
+
20
+ ```bash
21
+ loadtest run [options] # Run load tests
22
+ loadtest report [options] # Generate report from results
23
+ ```
24
+
25
+ ### Run Options
26
+
27
+ | Flag | Default | Description |
28
+ |------|---------|-------------|
29
+ | `--app <name>` | required | App to test (matches `apps/{name}/`) |
30
+ | `--mode <mode>` | `quick` | Test mode: `quick`, `full`, or `stress` |
31
+ | `--engine <engine>` | `bun` | Engine: `bun` (native) or `k6` |
32
+ | `--production` | `false` | Test against production URL |
33
+ | `--public-only` | `false` | Skip authenticated endpoints |
34
+ | `--json` | `false` | Output results as JSON |
35
+ | `--tier <tier>` | — | Hetzner tier for threshold overrides |
36
+
37
+ ## Per-App Configuration
38
+
39
+ Each app defines a `loadtest.config.ts` in its directory:
40
+
41
+ ```typescript
42
+ // apps/runmist/loadtest.config.ts
43
+ import type { AppLoadTestConfig } from '@bitclaw/loadtest'
44
+
45
+ export default {
46
+ appName: 'runmist',
47
+ baseUrl: 'http://localhost:3001',
48
+ productionUrl: 'https://runmist.com',
49
+
50
+ auth: {
51
+ loginEndpoint: '/api/loadtest/auth',
52
+ emailEnvVar: 'LOADTEST_EMAIL',
53
+ passwordEnvVar: 'LOADTEST_PASSWORD',
54
+ sessionCookieName: 'runmist_session',
55
+ },
56
+
57
+ publicEndpoints: [
58
+ { path: '/', method: 'GET' },
59
+ { path: '/api/health', method: 'GET' },
60
+ ],
61
+
62
+ authenticatedEndpoints: [
63
+ { path: '/dashboard', method: 'GET' },
64
+ { path: '/servers', method: 'GET' },
65
+ ],
66
+
67
+ modes: {
68
+ quick: { concurrencyLevels: [1, 5], durationSec: 5, warmupRequests: 10 },
69
+ full: { concurrencyLevels: [1, 5, 10, 25], durationSec: 15, warmupRequests: 50 },
70
+ stress: { concurrencyLevels: [1, 10, 25, 50, 100], durationSec: 30, warmupRequests: 100 },
71
+ },
72
+
73
+ thresholds: {
74
+ p95MaxMs: 50,
75
+ minSuccessRate: 99.5,
76
+ minThroughput: 100,
77
+ tiers: {
78
+ cpx21: { p95MaxMs: 50, minSuccessRate: 99.5, minThroughput: 100 },
79
+ cpx31: { p95MaxMs: 30, minSuccessRate: 99.9, minThroughput: 200 },
80
+ },
81
+ },
82
+ } satisfies AppLoadTestConfig
83
+ ```
84
+
85
+ ## Engines
86
+
87
+ ### Bun-Native (`--engine bun`)
88
+
89
+ Uses Bun's built-in HTTP client for fast, zero-dependency load testing. Best for quick local validation.
90
+
91
+ ### k6 (`--engine k6`)
92
+
93
+ Uses [k6](https://k6.io/) for production-grade load testing with detailed metrics. Requires k6 to be installed. k6 scripts are in `k6/` directory (e.g., `k6/runmist.js`).
94
+
95
+ ## Thresholds
96
+
97
+ Tests can define pass/fail thresholds:
98
+
99
+ - **p95MaxMs** — Maximum acceptable P95 latency
100
+ - **minSuccessRate** — Minimum success rate (0-100%)
101
+ - **minThroughput** — Minimum req/s at lowest concurrency
102
+
103
+ Hetzner tier overrides let you set different thresholds per server type.
104
+
105
+ ## Testing
106
+
107
+ ```bash
108
+ cd packages/loadtest
109
+ bun test
110
+ ```
111
+
112
+ 6 test files covering config loading, runners, auth, and report formatting.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Reusable AppLoadTestConfig and ThresholdConfig test data.
3
+ */
4
+ import type { AppLoadTestConfig, AuthConfig } from '../types';
5
+ export declare const SAMPLE_AUTH_CONFIG: AuthConfig;
6
+ export declare const SAMPLE_CONFIG_WITH_AUTH: AppLoadTestConfig;
7
+ export declare const SAMPLE_CONFIG_PUBLIC_ONLY: AppLoadTestConfig;
8
+ //# sourceMappingURL=configs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/configs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAmB,MAAM,UAAU,CAAC;AAE/E,eAAO,MAAM,kBAAkB,EAAE,UAKhC,CAAC;AAYF,eAAO,MAAM,uBAAuB,EAAE,iBA4BrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,iBA2BvC,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Reusable AppLoadTestConfig and ThresholdConfig test data.
3
+ */
4
+ export const SAMPLE_AUTH_CONFIG = {
5
+ loginEndpoint: '/api/loadtest/auth',
6
+ emailEnvVar: 'LOADTEST_EMAIL',
7
+ passwordEnvVar: 'LOADTEST_PASSWORD',
8
+ sessionCookieName: 'runmist_session'
9
+ };
10
+ const SAMPLE_THRESHOLDS = {
11
+ p95MaxMs: 500,
12
+ minSuccessRate: 95,
13
+ minThroughput: 50,
14
+ tiers: {
15
+ CPX11: { p95MaxMs: 800, minSuccessRate: 90, minThroughput: 30 },
16
+ CPX31: { p95MaxMs: 300, minSuccessRate: 98, minThroughput: 100 }
17
+ }
18
+ };
19
+ export const SAMPLE_CONFIG_WITH_AUTH = {
20
+ appName: 'runmist',
21
+ baseUrl: 'http://localhost:3001',
22
+ productionUrl: 'https://runmist.com',
23
+ auth: SAMPLE_AUTH_CONFIG,
24
+ publicEndpoints: [
25
+ { path: '/login', label: 'Login page' },
26
+ { path: '/', label: 'Landing page' }
27
+ ],
28
+ authenticatedEndpoints: [
29
+ { path: '/dashboard', label: 'Dashboard' },
30
+ { path: '/servers', label: 'Servers' },
31
+ { path: '/settings', label: 'Settings' }
32
+ ],
33
+ modes: {
34
+ quick: { concurrencyLevels: [1, 10], durationSec: 5, warmupRequests: 3 },
35
+ full: {
36
+ concurrencyLevels: [10, 50, 100],
37
+ durationSec: 10,
38
+ warmupRequests: 5
39
+ },
40
+ stress: {
41
+ concurrencyLevels: [50, 100, 200, 500],
42
+ durationSec: 15,
43
+ warmupRequests: 10
44
+ }
45
+ },
46
+ thresholds: SAMPLE_THRESHOLDS
47
+ };
48
+ export const SAMPLE_CONFIG_PUBLIC_ONLY = {
49
+ appName: 'weatherdestination',
50
+ baseUrl: 'http://localhost:3000',
51
+ publicEndpoints: [
52
+ { path: '/', label: 'Home' },
53
+ { path: '/blog', label: 'Blog' },
54
+ { path: '/docs', label: 'Docs' }
55
+ ],
56
+ authenticatedEndpoints: [],
57
+ modes: {
58
+ quick: { concurrencyLevels: [1, 10], durationSec: 5, warmupRequests: 3 },
59
+ full: {
60
+ concurrencyLevels: [10, 50, 100],
61
+ durationSec: 10,
62
+ warmupRequests: 5
63
+ },
64
+ stress: {
65
+ concurrencyLevels: [50, 100, 200, 500],
66
+ durationSec: 15,
67
+ warmupRequests: 10
68
+ }
69
+ },
70
+ thresholds: {
71
+ p95MaxMs: 500,
72
+ minSuccessRate: 99,
73
+ minThroughput: 100
74
+ }
75
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Reusable ScenarioResult and LoadTestResults test data.
3
+ */
4
+ import type { LoadTestResults, ScenarioResult } from '../types';
5
+ export declare const PASSING_SCENARIO: ScenarioResult;
6
+ export declare const FAILING_P95_SCENARIO: ScenarioResult;
7
+ export declare const FAILING_SUCCESS_RATE_SCENARIO: ScenarioResult;
8
+ export declare const FAILING_THROUGHPUT_SCENARIO: ScenarioResult;
9
+ export declare const MULTI_VIOLATION_SCENARIO: ScenarioResult;
10
+ export declare const PASSING_RESULTS: LoadTestResults;
11
+ export declare const FAILING_RESULTS: LoadTestResults;
12
+ export declare const EMPTY_RESULTS: LoadTestResults;
13
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/results.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,gBAAgB,EAAE,cAmB9B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,cAmBlC,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAmB3C,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,cAmBzC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAmBtC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,eAK7B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,eAK7B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,eAK3B,CAAC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Reusable ScenarioResult and LoadTestResults test data.
3
+ */
4
+ export const PASSING_SCENARIO = {
5
+ endpoint: '/dashboard',
6
+ label: 'Dashboard',
7
+ method: 'GET',
8
+ concurrency: 10,
9
+ durationSec: 5,
10
+ totalRequests: 500,
11
+ successCount: 495,
12
+ failCount: 5,
13
+ successRate: 99,
14
+ throughput: 150,
15
+ p50: 80,
16
+ p95: 200,
17
+ p99: 350,
18
+ min: 20,
19
+ max: 450,
20
+ avg: 100,
21
+ statusCodes: { 200: 495, 500: 5 },
22
+ avgBodySize: 1024
23
+ };
24
+ export const FAILING_P95_SCENARIO = {
25
+ endpoint: '/slow',
26
+ label: 'Slow endpoint',
27
+ method: 'GET',
28
+ concurrency: 50,
29
+ durationSec: 5,
30
+ totalRequests: 300,
31
+ successCount: 297,
32
+ failCount: 3,
33
+ successRate: 99,
34
+ throughput: 150,
35
+ p50: 400,
36
+ p95: 900,
37
+ p99: 1200,
38
+ min: 100,
39
+ max: 1500,
40
+ avg: 450,
41
+ statusCodes: { 200: 297, 504: 3 },
42
+ avgBodySize: 2048
43
+ };
44
+ export const FAILING_SUCCESS_RATE_SCENARIO = {
45
+ endpoint: '/flaky',
46
+ label: 'Flaky endpoint',
47
+ method: 'GET',
48
+ concurrency: 10,
49
+ durationSec: 5,
50
+ totalRequests: 200,
51
+ successCount: 170,
52
+ failCount: 30,
53
+ successRate: 85,
54
+ throughput: 150,
55
+ p50: 100,
56
+ p95: 300,
57
+ p99: 400,
58
+ min: 30,
59
+ max: 500,
60
+ avg: 120,
61
+ statusCodes: { 200: 170, 500: 30 },
62
+ avgBodySize: 512
63
+ };
64
+ export const FAILING_THROUGHPUT_SCENARIO = {
65
+ endpoint: '/bottleneck',
66
+ label: 'Bottleneck',
67
+ method: 'GET',
68
+ concurrency: 10,
69
+ durationSec: 5,
70
+ totalRequests: 100,
71
+ successCount: 98,
72
+ failCount: 2,
73
+ successRate: 98,
74
+ throughput: 20,
75
+ p50: 100,
76
+ p95: 300,
77
+ p99: 400,
78
+ min: 30,
79
+ max: 500,
80
+ avg: 120,
81
+ statusCodes: { 200: 98, 503: 2 },
82
+ avgBodySize: 768
83
+ };
84
+ export const MULTI_VIOLATION_SCENARIO = {
85
+ endpoint: '/broken',
86
+ label: 'Broken endpoint',
87
+ method: 'GET',
88
+ concurrency: 100,
89
+ durationSec: 5,
90
+ totalRequests: 100,
91
+ successCount: 60,
92
+ failCount: 40,
93
+ successRate: 60,
94
+ throughput: 20,
95
+ p50: 500,
96
+ p95: 1500,
97
+ p99: 2000,
98
+ min: 200,
99
+ max: 3000,
100
+ avg: 700,
101
+ statusCodes: { 200: 60, 500: 30, 503: 10 },
102
+ avgBodySize: 256
103
+ };
104
+ export const PASSING_RESULTS = {
105
+ baseUrl: 'http://localhost:3001',
106
+ startedAt: '2025-01-01T00:00:00.000Z',
107
+ completedAt: '2025-01-01T00:01:00.000Z',
108
+ scenarios: [PASSING_SCENARIO]
109
+ };
110
+ export const FAILING_RESULTS = {
111
+ baseUrl: 'http://localhost:3001',
112
+ startedAt: '2025-01-01T00:00:00.000Z',
113
+ completedAt: '2025-01-01T00:01:00.000Z',
114
+ scenarios: [FAILING_P95_SCENARIO, FAILING_SUCCESS_RATE_SCENARIO]
115
+ };
116
+ export const EMPTY_RESULTS = {
117
+ baseUrl: 'http://localhost:3001',
118
+ startedAt: '2025-01-01T00:00:00.000Z',
119
+ completedAt: '2025-01-01T00:01:00.000Z',
120
+ scenarios: []
121
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Load test authentication — obtains session cookies from the
3
+ * dedicated /api/loadtest/auth endpoint.
4
+ */
5
+ import type { AuthConfig, SessionState } from '../types';
6
+ /**
7
+ * Authenticate against the dedicated loadtest auth endpoint.
8
+ * Returns the raw Set-Cookie header value for injection into requests.
9
+ */
10
+ export declare function authenticateSession(baseUrl: string, auth: AuthConfig): Promise<SessionState>;
11
+ /**
12
+ * Pre-create a pool of authenticated sessions for high-concurrency tests.
13
+ * Distributes load across multiple sessions so a single token isn't hammered.
14
+ *
15
+ * @param count Number of sessions to create (default: 1 per 20 concurrent workers)
16
+ */
17
+ export declare function createSessionPool(baseUrl: string, auth: AuthConfig, count: number): Promise<SessionState[]>;
18
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/auth/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEzD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,YAAY,CAAC,CAmDvB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,EAAE,CAAC,CASzB"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Load test authentication — obtains session cookies from the
3
+ * dedicated /api/loadtest/auth endpoint.
4
+ */
5
+ /**
6
+ * Authenticate against the dedicated loadtest auth endpoint.
7
+ * Returns the raw Set-Cookie header value for injection into requests.
8
+ */
9
+ export async function authenticateSession(baseUrl, auth) {
10
+ // Use direct credentials if provided, otherwise read from env vars
11
+ const email = auth.credentials?.email ?? process.env[auth.emailEnvVar];
12
+ const password = auth.credentials?.password ?? process.env[auth.passwordEnvVar];
13
+ if (!email || !password) {
14
+ throw new Error(`Missing credentials. Set ${auth.emailEnvVar} and ${auth.passwordEnvVar} env vars.\n` +
15
+ `Example: ${auth.emailEnvVar}=admin@runmist.local ${auth.passwordEnvVar}=runmist123 bun run loadtest ...`);
16
+ }
17
+ const url = `${baseUrl}${auth.loginEndpoint}`;
18
+ const response = await fetch(url, {
19
+ method: 'POST',
20
+ headers: { 'Content-Type': 'application/json' },
21
+ body: JSON.stringify({ email, password }),
22
+ redirect: 'manual'
23
+ });
24
+ if (!response.ok) {
25
+ const body = await response.text().catch(() => '');
26
+ throw new Error(`Auth failed (${response.status}): ${body}\n` +
27
+ `Endpoint: ${url}\n` +
28
+ `Make sure LOADTEST_AUTH_ENABLED=true is set in the app's env.`);
29
+ }
30
+ // Extract session cookie from Set-Cookie header
31
+ const setCookie = response.headers.getSetCookie?.() ?? [];
32
+ const sessionCookie = setCookie.find(c => c.startsWith(`${auth.sessionCookieName}=`));
33
+ if (!sessionCookie) {
34
+ throw new Error(`No ${auth.sessionCookieName} cookie in response.\n` +
35
+ `Set-Cookie headers: ${setCookie.join('; ')}`);
36
+ }
37
+ // Extract just the cookie name=value pair (strip attributes like Path, HttpOnly, etc.)
38
+ const cookieValue = sessionCookie.split(';')[0];
39
+ return {
40
+ cookies: cookieValue,
41
+ authenticated: true
42
+ };
43
+ }
44
+ /**
45
+ * Pre-create a pool of authenticated sessions for high-concurrency tests.
46
+ * Distributes load across multiple sessions so a single token isn't hammered.
47
+ *
48
+ * @param count Number of sessions to create (default: 1 per 20 concurrent workers)
49
+ */
50
+ export async function createSessionPool(baseUrl, auth, count) {
51
+ const poolSize = Math.max(1, count);
52
+ const sessions = [];
53
+ for (let i = 0; i < poolSize; i++) {
54
+ const session = await authenticateSession(baseUrl, auth);
55
+ sessions.push(session);
56
+ }
57
+ return sessions;
58
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * CLI `report` command — display or re-format previous results.
3
+ */
4
+ import type { Command } from 'commander';
5
+ export declare function registerReportCommand(program: Command): void;
6
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/report.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA0C5D"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * CLI `report` command — display or re-format previous results.
3
+ */
4
+ import { readdirSync, readFileSync } from 'node:fs';
5
+ import { dirname, resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const REPO_ROOT = resolve(__dirname, '..', '..', '..', '..', '..');
9
+ export function registerReportCommand(program) {
10
+ program
11
+ .command('report')
12
+ .description('Display results from a previous k6 JSON export')
13
+ .option('--file <path>', 'Path to JSON results file')
14
+ .option('--last', 'Show the most recent results file')
15
+ .action(async (opts) => {
16
+ try {
17
+ let filePath;
18
+ if (opts.file) {
19
+ filePath = resolve(opts.file);
20
+ }
21
+ else if (opts.last) {
22
+ // Find the most recent loadtest-*.json file
23
+ const files = readdirSync(REPO_ROOT)
24
+ .filter(f => f.startsWith('loadtest-') && f.endsWith('.json'))
25
+ .sort()
26
+ .reverse();
27
+ if (files.length === 0) {
28
+ console.error('No loadtest result files found. Run a test with --json first.');
29
+ process.exit(1);
30
+ }
31
+ filePath = resolve(REPO_ROOT, files[0]);
32
+ }
33
+ else {
34
+ console.error('Specify --file <path> or --last');
35
+ process.exit(1);
36
+ return;
37
+ }
38
+ const raw = readFileSync(filePath, 'utf-8');
39
+ JSON.parse(raw);
40
+ }
41
+ catch (error) {
42
+ console.error(`\nError: ${error instanceof Error ? error.message : String(error)}`);
43
+ process.exit(1);
44
+ }
45
+ });
46
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * CLI `run` command — executes load tests against an app.
3
+ */
4
+ import type { Command } from 'commander';
5
+ export declare function registerRunCommand(program: Command): void;
6
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/run.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWzC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsGzD"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * CLI `run` command — executes load tests against an app.
3
+ */
4
+ import { listConfiguredApps, loadConfig } from '../../config/loader';
5
+ import { checkThresholds, formatJson, formatReport } from '../../reports/formatter';
6
+ import { runAppLoadTest } from '../../runner/bun-runner';
7
+ import { runK6Test } from '../../runner/k6-runner';
8
+ export function registerRunCommand(program) {
9
+ program
10
+ .command('run')
11
+ .description('Run load tests against an app')
12
+ .option('--app <name>', 'App to test (e.g., runmist, weatherdestination)')
13
+ .option('--mode <mode>', 'Test mode: quick, full, stress', 'quick')
14
+ .option('--engine <engine>', 'Test engine: bun, k6', 'bun')
15
+ .option('--production', 'Test against production URL', false)
16
+ .option('--public-only', 'Only test public endpoints', false)
17
+ .option('--json', 'Output results as JSON', false)
18
+ .option('--tier <tier>', 'Hetzner tier for threshold comparison (CPX11/21/31/41)')
19
+ .option('--url <url>', 'Override base URL')
20
+ .option('--list', 'List available apps with load test configs')
21
+ .action(async (opts) => {
22
+ try {
23
+ // Handle --list
24
+ if (opts.list) {
25
+ const apps = await listConfiguredApps();
26
+ if (apps.length === 0) {
27
+ process.stdout.write('No apps with load test configs found.\n');
28
+ }
29
+ else {
30
+ process.stdout.write('Apps with load test configs:\n');
31
+ for (const app of apps) {
32
+ process.stdout.write(` ${app}\n`);
33
+ }
34
+ }
35
+ return;
36
+ }
37
+ if (!opts.app) {
38
+ console.error('--app is required. Use --list to see available apps.');
39
+ process.exit(1);
40
+ }
41
+ const mode = opts.mode;
42
+ const engine = opts.engine;
43
+ // Validate mode
44
+ if (!['quick', 'full', 'stress'].includes(mode)) {
45
+ console.error(`Invalid mode "${mode}". Use: quick, full, stress`);
46
+ process.exit(1);
47
+ }
48
+ // Validate engine
49
+ if (!['bun', 'k6'].includes(engine)) {
50
+ console.error(`Invalid engine "${engine}". Use: bun, k6`);
51
+ process.exit(1);
52
+ }
53
+ // Load config
54
+ const config = await loadConfig(opts.app);
55
+ // Determine base URL
56
+ const baseUrl = opts.url ??
57
+ (opts.production && config.productionUrl
58
+ ? config.productionUrl
59
+ : config.baseUrl);
60
+ // Run with selected engine
61
+ if (engine === 'k6') {
62
+ await runK6Test(opts.app, {
63
+ baseUrl,
64
+ email: process.env.LOADTEST_EMAIL,
65
+ password: process.env.LOADTEST_PASSWORD,
66
+ jsonOutput: opts.json
67
+ ? `loadtest-${opts.app}-${Date.now()}.json`
68
+ : undefined
69
+ });
70
+ }
71
+ else {
72
+ const results = await runAppLoadTest(config, mode, {
73
+ publicOnly: opts.publicOnly,
74
+ baseUrl
75
+ });
76
+ if (opts.json) {
77
+ process.stdout.write(`${formatJson(results, config, opts.tier)}\n`);
78
+ }
79
+ else {
80
+ process.stdout.write(`${formatReport(results, config, opts.tier)}\n`);
81
+ }
82
+ // Check thresholds and set exit code
83
+ const thresholds = opts.tier
84
+ ? (config.thresholds.tiers?.[opts.tier] ?? config.thresholds)
85
+ : config.thresholds;
86
+ const check = checkThresholds(results, thresholds);
87
+ if (!check.passed) {
88
+ process.exit(1);
89
+ }
90
+ }
91
+ }
92
+ catch (error) {
93
+ console.error(`\nError: ${error instanceof Error ? error.message : String(error)}`);
94
+ process.exit(1);
95
+ }
96
+ });
97
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { registerReportCommand } from './cli/commands/report';
4
+ import { registerRunCommand } from './cli/commands/run';
5
+ const program = new Command();
6
+ program
7
+ .name('loadtest')
8
+ .description('Load testing CLI for sqlite-saas apps')
9
+ .version('0.1.0');
10
+ registerRunCommand(program);
11
+ registerReportCommand(program);
12
+ program.parse();