@gcoredev/fastedge-test 0.0.1-beta.0 → 0.1.0-beta.2
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 +6 -6
- package/bin/fastedge-debug.js +2 -0
- package/dist/fastedge-cli/METADATA.json +1 -3
- package/dist/fastedge-cli/{fastedge-run-linux-x64-unkown → fastedge-run-darwin-arm64} +0 -0
- package/dist/fastedge-cli/fastedge-run-linux-x64 +0 -0
- package/dist/fastedge-cli/fastedge-run.exe +0 -0
- package/dist/frontend/assets/index-CEFjsU8e.js +35 -0
- package/dist/frontend/assets/index-DdlINQc_.css +1 -0
- package/dist/frontend/index.html +2 -2
- package/dist/lib/index.cjs +329 -112
- package/dist/lib/index.js +331 -115
- package/dist/lib/runner/HostFunctions.d.ts +8 -0
- package/dist/lib/runner/HttpWasmRunner.d.ts +34 -14
- package/dist/lib/runner/IStateManager.d.ts +3 -2
- package/dist/lib/runner/IWasmRunner.d.ts +18 -1
- package/dist/lib/runner/NullStateManager.d.ts +1 -0
- package/dist/lib/runner/PortManager.d.ts +17 -19
- package/dist/lib/runner/ProxyWasmRunner.d.ts +7 -0
- package/dist/lib/runner/standalone.d.ts +1 -1
- package/dist/lib/schemas/api.d.ts +8 -2
- package/dist/lib/schemas/config.d.ts +4 -1
- package/dist/lib/test-framework/index.cjs +330 -114
- package/dist/lib/test-framework/index.js +332 -117
- package/dist/lib/test-framework/suite-runner.d.ts +1 -1
- package/dist/server.js +30 -30
- package/docs/API.md +758 -360
- package/docs/DEBUGGER.md +151 -0
- package/docs/INDEX.md +111 -0
- package/docs/RUNNER.md +582 -0
- package/docs/TEST_CONFIG.md +242 -0
- package/docs/TEST_FRAMEWORK.md +384 -284
- package/docs/WEBSOCKET.md +499 -0
- package/docs/quickstart.md +171 -0
- package/llms.txt +72 -14
- package/package.json +17 -6
- package/schemas/api-config.schema.json +12 -5
- package/schemas/api-load.schema.json +11 -6
- package/schemas/{test-config.schema.json → fastedge-config.test.schema.json} +12 -5
- package/dist/fastedge-cli/.gitkeep +0 -0
- package/dist/frontend/assets/index-CnXStFTd.css +0 -1
- package/dist/frontend/assets/index-FR9Oqsow.js +0 -37
- package/docs/HYBRID_LOADING.md +0 -546
- package/docs/LOCAL_SERVER.md +0 -153
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Test Configuration
|
|
2
|
+
|
|
3
|
+
Configuration file reference for `fastedge-config.test.json` — the per-test JSON file that defines the WASM binary, request, response, CDN properties, and environment variable loading for a single test scenario.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Each test scenario is described by a `fastedge-config.test.json` file. The file is validated against a JSON Schema at load time. The test runner (and `loadConfigFile`) applies Zod defaults at runtime, so fields with defaults do not need to be present in the file — but editors validating against the `$schema` URI will flag missing required fields unless you supply them explicitly.
|
|
8
|
+
|
|
9
|
+
**Required fields** (per JSON Schema `required` array): `request` and `properties` at the top level; `method`, `url`, `headers`, and `body` within `request`.
|
|
10
|
+
|
|
11
|
+
**Runtime defaults**: The Zod runtime fills in `method`, `headers`, and `body` if absent, so those fields are optional in practice. Similarly, `properties` defaults to `{}` at runtime even though the JSON Schema marks it required. The JSON Schema marks them as required because it cannot express Zod's default-filling behaviour. Supplying explicit values avoids editor warnings.
|
|
12
|
+
|
|
13
|
+
## Schema Reference
|
|
14
|
+
|
|
15
|
+
### Top-Level Fields
|
|
16
|
+
|
|
17
|
+
| JSON Path | Type | Required (Schema) | Default | Description |
|
|
18
|
+
| ------------------ | --------- | ---------------------------------- | ------- | ------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `$schema` | `string` | No | — | URI pointing to the JSON Schema file for IDE autocompletion and validation. |
|
|
20
|
+
| `description` | `string` | No | — | Human-readable label for this test scenario. |
|
|
21
|
+
| `wasm` | `object` | No | — | WASM binary configuration. Required when running without a programmatic `wasmBuffer`. |
|
|
22
|
+
| `wasm.path` | `string` | Yes (if `wasm` present) | — | Path to the compiled `.wasm` binary, relative to the config file or absolute. |
|
|
23
|
+
| `wasm.description` | `string` | No | — | Human-readable label for the WASM binary. |
|
|
24
|
+
| `request` | `object` | **Yes** | — | Incoming HTTP request to simulate. |
|
|
25
|
+
| `request.method` | `string` | Yes (schema) / runtime default | `"GET"` | HTTP method (e.g. `"GET"`, `"POST"`). |
|
|
26
|
+
| `request.url` | `string` | **Yes** | — | Full URL or path for the simulated request (e.g. `"https://example.com/api"`). |
|
|
27
|
+
| `request.headers` | `object` | Yes (schema) / runtime default | `{}` | Key/value map of request headers. All keys and values must be strings. |
|
|
28
|
+
| `request.body` | `string` | Yes (schema) / runtime default | `""` | Request body as a plain string. Use an empty string for requests with no body. |
|
|
29
|
+
| `response` | `object` | No | — | Mock origin response for CDN mode. Not applicable to HTTP-WASM. |
|
|
30
|
+
| `response.headers` | `object` | Yes (if `response` present) | `{}` | Key/value map of mock origin response headers. |
|
|
31
|
+
| `response.body` | `string` | Yes (if `response` present) | `""` | Mock origin response body as a plain string. |
|
|
32
|
+
| `properties` | `object` | **Yes** (schema) / runtime default | `{}` | CDN property key/value pairs passed to the WASM execution context. Values may be any JSON type. |
|
|
33
|
+
| `dotenv` | `object` | No | — | Dotenv file loading configuration. |
|
|
34
|
+
| `dotenv.enabled` | `boolean` | No | — | Whether to load a `.env` file before execution. |
|
|
35
|
+
| `dotenv.path` | `string` | No | — | Path to the `.env` file. If omitted, resolves `.env` relative to the config file directory. |
|
|
36
|
+
|
|
37
|
+
### Required vs. Default Distinction
|
|
38
|
+
|
|
39
|
+
The JSON Schema's `required` arrays drive editor validation. Fields like `request.method`, `request.headers`, `request.body`, and `properties` appear in the schema's `required` array (or top-level `required`), so a strict JSON Schema validator will flag them as missing. At runtime, the Zod schema fills in their defaults (`"GET"`, `{}`, `""`, and `{}` respectively), so the test runner accepts configs that omit them.
|
|
40
|
+
|
|
41
|
+
To avoid editor warnings while keeping configs concise, either supply the fields explicitly or add the `$schema` field and accept that your editor may warn on omission.
|
|
42
|
+
|
|
43
|
+
## Dotenv Configuration
|
|
44
|
+
|
|
45
|
+
When `dotenv.enabled` is `true`, the runner loads a `.env` file and merges its contents into `process.env` before executing the WASM binary. This allows secrets and environment-specific values to be injected without embedding them in the config file.
|
|
46
|
+
|
|
47
|
+
**File resolution order:**
|
|
48
|
+
1. If `dotenv.path` is set, that path is used (relative to the working directory or absolute).
|
|
49
|
+
2. If `dotenv.path` is omitted, `.env` is resolved relative to the directory containing the config file.
|
|
50
|
+
|
|
51
|
+
**CDN mode**: Properties passed to the WASM context come from the `properties` field in the config. Dotenv variables are available to the Node.js host process but are not automatically injected as CDN properties. To expose a `.env` value as a CDN property, reference `process.env.VAR_NAME` programmatically when constructing the runner config.
|
|
52
|
+
|
|
53
|
+
**HTTP-WASM mode**: Dotenv loading works the same way. The WASM module receives the simulated HTTP request; host environment variables are available to any host-side logic but are not part of the WASM execution context directly.
|
|
54
|
+
|
|
55
|
+
**Security note**: Do not commit `.env` files containing secrets. Add `.env` to `.gitignore` and use `dotenv.enabled: true` with `dotenv.path` pointing to a file that exists only in the local or CI environment.
|
|
56
|
+
|
|
57
|
+
## Examples
|
|
58
|
+
|
|
59
|
+
### Minimal CDN Configuration
|
|
60
|
+
|
|
61
|
+
The smallest valid config. `request` and `properties` are required; all other fields use runtime defaults or are omitted.
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"$schema": "./node_modules/@gcoredev/fastedge-test/schemas/fastedge-config.test.schema.json",
|
|
66
|
+
"wasm": {
|
|
67
|
+
"path": "./dist/handler.wasm"
|
|
68
|
+
},
|
|
69
|
+
"request": {
|
|
70
|
+
"method": "GET",
|
|
71
|
+
"url": "https://example.com/",
|
|
72
|
+
"headers": {},
|
|
73
|
+
"body": ""
|
|
74
|
+
},
|
|
75
|
+
"properties": {}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### CDN with Properties and Secrets
|
|
80
|
+
|
|
81
|
+
A CDN scenario that passes property values to the WASM context and loads secrets from a `.env` file.
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"$schema": "./node_modules/@gcoredev/fastedge-test/schemas/fastedge-config.test.schema.json",
|
|
86
|
+
"description": "CDN handler with feature flags and auth secret",
|
|
87
|
+
"wasm": {
|
|
88
|
+
"path": "./dist/handler.wasm",
|
|
89
|
+
"description": "Production CDN handler"
|
|
90
|
+
},
|
|
91
|
+
"request": {
|
|
92
|
+
"method": "GET",
|
|
93
|
+
"url": "https://example.com/api/data",
|
|
94
|
+
"headers": {
|
|
95
|
+
"accept": "application/json",
|
|
96
|
+
"x-request-id": "test-001"
|
|
97
|
+
},
|
|
98
|
+
"body": ""
|
|
99
|
+
},
|
|
100
|
+
"properties": {
|
|
101
|
+
"FEATURE_FLAG_NEW_CACHE": "true",
|
|
102
|
+
"UPSTREAM_HOST": "origin.example.com",
|
|
103
|
+
"MAX_AGE": 3600
|
|
104
|
+
},
|
|
105
|
+
"dotenv": {
|
|
106
|
+
"enabled": true,
|
|
107
|
+
"path": "./.env.test"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Corresponding `.env.test`:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
API_SECRET=supersecret
|
|
116
|
+
DEBUG_MODE=false
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### HTTP-WASM Configuration
|
|
120
|
+
|
|
121
|
+
An HTTP-WASM scenario simulating a `POST` request with a JSON body. The `response` field is not relevant to HTTP-WASM execution; `properties` is still required by the schema and defaults to `{}` at runtime.
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"$schema": "./node_modules/@gcoredev/fastedge-test/schemas/fastedge-config.test.schema.json",
|
|
126
|
+
"description": "HTTP-WASM POST handler",
|
|
127
|
+
"wasm": {
|
|
128
|
+
"path": "./dist/http-handler.wasm"
|
|
129
|
+
},
|
|
130
|
+
"request": {
|
|
131
|
+
"method": "POST",
|
|
132
|
+
"url": "https://api.example.com/submit",
|
|
133
|
+
"headers": {
|
|
134
|
+
"content-type": "application/json",
|
|
135
|
+
"authorization": "Bearer test-token"
|
|
136
|
+
},
|
|
137
|
+
"body": "{\"key\": \"value\"}"
|
|
138
|
+
},
|
|
139
|
+
"properties": {}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Custom Origin Response
|
|
144
|
+
|
|
145
|
+
A CDN scenario where the mock origin returns a specific response. Use this to test how the WASM handler transforms or conditionally passes through origin responses.
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"$schema": "./node_modules/@gcoredev/fastedge-test/schemas/fastedge-config.test.schema.json",
|
|
150
|
+
"description": "CDN handler with custom mock origin response",
|
|
151
|
+
"wasm": {
|
|
152
|
+
"path": "./dist/handler.wasm"
|
|
153
|
+
},
|
|
154
|
+
"request": {
|
|
155
|
+
"method": "GET",
|
|
156
|
+
"url": "https://example.com/cached-resource",
|
|
157
|
+
"headers": {},
|
|
158
|
+
"body": ""
|
|
159
|
+
},
|
|
160
|
+
"response": {
|
|
161
|
+
"headers": {
|
|
162
|
+
"content-type": "application/json",
|
|
163
|
+
"cache-control": "max-age=86400"
|
|
164
|
+
},
|
|
165
|
+
"body": "{\"status\": \"ok\", \"data\": []}"
|
|
166
|
+
},
|
|
167
|
+
"properties": {
|
|
168
|
+
"CACHE_TTL": 86400
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## IDE Integration
|
|
174
|
+
|
|
175
|
+
Adding `$schema` to your config file enables JSON Schema validation and autocompletion in VSCode and any editor that supports the JSON Language Server.
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
{
|
|
179
|
+
"$schema": "./node_modules/@gcoredev/fastedge-test/schemas/fastedge-config.test.schema.json"
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The schema file is included in the published package at `schemas/fastedge-config.test.schema.json`. The path in `$schema` should be relative to the config file's location.
|
|
184
|
+
|
|
185
|
+
**VSCode**: No additional extensions are needed. The built-in JSON language server resolves `$schema` automatically. You will get:
|
|
186
|
+
- Field name autocompletion
|
|
187
|
+
- Type validation (e.g. strings vs. objects)
|
|
188
|
+
- Inline documentation on hover
|
|
189
|
+
- Errors for unrecognised fields (`additionalProperties: false` is set at every object level)
|
|
190
|
+
|
|
191
|
+
**Other editors**: Any editor using the JSON Language Server (Neovim via `nvim-lspconfig`, IntelliJ IDEA, etc.) will also pick up the schema from the `$schema` field without additional configuration.
|
|
192
|
+
|
|
193
|
+
## Programmatic Usage
|
|
194
|
+
|
|
195
|
+
To load and validate a config file at runtime in a test script:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { loadConfigFile } from "@gcoredev/fastedge-test/test";
|
|
199
|
+
import type { TestConfig } from "@gcoredev/fastedge-test/test";
|
|
200
|
+
|
|
201
|
+
const config: TestConfig = await loadConfigFile("./fastedge-config.test.json");
|
|
202
|
+
|
|
203
|
+
console.log(config.request.url); // string
|
|
204
|
+
console.log(config.properties); // Record<string, unknown>
|
|
205
|
+
console.log(config.wasm?.path); // string | undefined
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`loadConfigFile` reads the file, parses JSON, and validates it through the Zod schema (applying defaults). It throws a descriptive `Error` if the file cannot be read, is not valid JSON, or fails schema validation.
|
|
209
|
+
|
|
210
|
+
The returned `TestConfig` type reflects the Zod-inferred shape after defaults are applied:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
type TestConfig = {
|
|
214
|
+
$schema?: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
wasm?: {
|
|
217
|
+
path: string;
|
|
218
|
+
description?: string;
|
|
219
|
+
};
|
|
220
|
+
request: {
|
|
221
|
+
method: string; // default: "GET"
|
|
222
|
+
url: string;
|
|
223
|
+
headers: Record<string, string>; // default: {}
|
|
224
|
+
body: string; // default: ""
|
|
225
|
+
};
|
|
226
|
+
response?: {
|
|
227
|
+
headers: Record<string, string>; // default: {}
|
|
228
|
+
body: string; // default: ""
|
|
229
|
+
};
|
|
230
|
+
properties: Record<string, unknown>; // default: {}
|
|
231
|
+
dotenv?: {
|
|
232
|
+
enabled?: boolean;
|
|
233
|
+
path?: string;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## See Also
|
|
239
|
+
|
|
240
|
+
- [TEST_FRAMEWORK.md](./TEST_FRAMEWORK.md) — using `loadConfigFile` in test suites, `runFlow`, and the full test framework API
|
|
241
|
+
- [API.md](./API.md) — `GET /api/config` and `POST /api/config` REST endpoints for reading and writing config at runtime
|
|
242
|
+
- [RUNNER.md](./RUNNER.md) — runner configuration and WASM execution options
|