Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions bin/fastedge-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,43 @@ function resolveAppRoot(startPath) {
return dir;
}

process.env.WORKSPACE_PATH = resolveAppRoot(
process.argv[2] ? resolve(process.argv[2]) : process.cwd()
);
// Parse `--project-dir <path>` / `--project-dir=<path>` and strip it from argv
// before the server import, so the server's own arg handling doesn't see it.
// When set, it overrides the positional fallback for resolveAppRoot — useful
// when running from a nested sandbox (e.g. `cd fastedge-test && npm run debug`
// with the project root one directory up).
function extractProjectDirFlag(argv) {
for (let i = 2; i < argv.length; i++) {
const a = argv[i];
if (a === "--project-dir" || a === "-C") {
const value = argv[i + 1];
if (!value) {
console.error(`Error: ${a} requires a path argument.`);
process.exit(2);
}
argv.splice(i, 2);
return value;
}
const eq = a.startsWith("--project-dir=")
? a.slice("--project-dir=".length)
: a.startsWith("-C=")
? a.slice("-C=".length)
: null;
if (eq !== null) {
argv.splice(i, 1);
return eq;
}
}
return null;
}

const projectDirFlag = extractProjectDirFlag(process.argv);
const startPath = projectDirFlag
? resolve(projectDirFlag)
: process.argv[2]
? resolve(process.argv[2])
: process.cwd();

process.env.WORKSPACE_PATH = resolveAppRoot(startPath);

import("../dist/server.js");
112 changes: 56 additions & 56 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ The port can be overridden via the `PORT` environment variable. The active port

The `POST /api/execute`, `POST /api/send`, and `POST /api/config` endpoints accept an optional `X-Source` request header that tags the origin of the operation in WebSocket broadcast events.

| Value | Description |
| ------------ | ------------------------------------------------------- |
| `ui` | Request originated from the web UI (default if omitted) |
| `ai_agent` | Request originated from an AI agent |
| `api` | Request originated from direct API usage |
| `system` | Request originated from an automated system |
| Value | Description |
| ---------- | ------------------------------------------------------- |
| `ui` | Request originated from the web UI (default if omitted) |
| `ai_agent` | Request originated from an AI agent |
| `api` | Request originated from direct API usage |
| `system` | Request originated from an automated system |

```http
X-Source: ai_agent
Expand Down Expand Up @@ -179,11 +179,11 @@ curl -X POST http://localhost:5179/api/load \

**Error Responses**

| Status | Condition |
| ------ | ------------------------------------------------------------------------------------------------------------ |
| `400` | Validation failed, missing both `wasmPath` and `wasmBase64`, invalid path, or path does not end in `.wasm` |
| `400` | `httpPort` is specified and already in use (HTTP-WASM only) |
| `500` | WASM load failed or runner initialization error |
| Status | Condition |
| ------ | ----------------------------------------------------------------------------------------------------------- |
| `400` | Validation failed, missing both `wasmPath` and `wasmBase64`, invalid path, or path does not end in `.wasm` |
| `400` | `httpPort` is specified and already in use (HTTP-WASM only) |
| `500` | WASM load failed or runner initialization error |

---

Expand Down Expand Up @@ -417,10 +417,10 @@ curl -X POST http://localhost:5179/api/execute \

**Error Responses**

| Status | Condition |
| ------ | ----------------------------------------------------------------------------------------------- |
| `400` | No WASM module loaded, or missing `path`/`url` for HTTP-WASM, or missing `url` for Proxy-WASM |
| `500` | Execution failed |
| Status | Condition |
| ------ | ---------------------------------------------------------------------------------------------- |
| `400` | No WASM module loaded, or missing `path`/`url` for HTTP-WASM, or missing `url` for Proxy-WASM |
| `500` | Execution failed |

---

Expand Down Expand Up @@ -529,10 +529,10 @@ curl -X POST http://localhost:5179/api/call \

**Error Responses**

| Status | Condition |
| ------ | --------------------------------------------------------------------------------------- |
| `400` | Validation failed (invalid hook name, missing `properties`), or no WASM module loaded |
| `500` | Hook execution failed |
| Status | Condition |
| ------ | -------------------------------------------------------------------------------------- |
| `400` | Validation failed (invalid hook name, missing `properties`), or no WASM module loaded |
| `500` | Hook execution failed |

---

Expand Down Expand Up @@ -652,10 +652,10 @@ curl -X POST http://localhost:5179/api/send \

**Error Responses**

| Status | Condition |
| ------ | ----------------------------------------------------------------------------- |
| `400` | Validation failed (missing `url` or `properties`), or no WASM module loaded |
| `500` | Execution failed |
| Status | Condition |
| ------ | ---------------------------------------------------------------------------- |
| `400` | Validation failed (missing `url` or `properties`), or no WASM module loaded |
| `500` | Execution failed |

---

Expand Down Expand Up @@ -744,9 +744,9 @@ curl http://localhost:5179/api/config

**Error Responses**

| Status | Condition |
| ------ | ------------------------------------------- |
| `404` | `fastedge-config.test.json` does not exist |
| Status | Condition |
| ------ | ------------------------------------------ |
| `404` | `fastedge-config.test.json` does not exist |

---

Expand Down Expand Up @@ -805,10 +805,10 @@ curl -X POST http://localhost:5179/api/config \

**Error Responses**

| Status | Condition |
| ------ | ---------------------------------------------------------------------------------------- |
| `400` | Validation failed (missing `config.appType`, `config.request`, or `config.properties`) |
| `500` | File write failed |
| Status | Condition |
| ------ | --------------------------------------------------------------------------------------- |
| `400` | Validation failed (missing `config.appType`, `config.request`, or `config.properties`) |
| `500` | File write failed |

---

Expand Down Expand Up @@ -863,10 +863,10 @@ curl -X POST http://localhost:5179/api/config/save-as \

**Error Responses**

| Status | Condition |
| ------ | ---------------------------------------- |
| `400` | Missing `config` or `filePath` |
| `500` | File write or directory creation failed |
| Status | Condition |
| ------ | --------------------------------------- |
| `400` | Missing `config` or `filePath` |
| `500` | File write or directory creation failed |

---

Expand All @@ -886,23 +886,23 @@ Returns the JSON Schema document with `Content-Type: application/json`.

#### Request Schemas

| Name | Description |
| -------------- | ------------------------------------------- |
| `api-load` | Request body schema for `POST /api/load` |
| `api-send` | Request body schema for `POST /api/send` |
| `api-call` | Request body schema for `POST /api/call` |
| `api-config` | Request body schema for `POST /api/config` |
| Name | Description |
| ------------ | ------------------------------------------ |
| `api-load` | Request body schema for `POST /api/load` |
| `api-send` | Request body schema for `POST /api/send` |
| `api-call` | Request body schema for `POST /api/call` |
| `api-config` | Request body schema for `POST /api/config` |

#### Response / Type Schemas

| Name | Description |
| ----------------------- | -------------------------------------------------------------- |
| `fastedge-config.test` | Schema for `fastedge-config.test.json` config files |
| `hook-result` | Shape of a single `HookResult` object |
| `hook-call` | Shape of a `HookCall` input object |
| `full-flow-result` | Shape of the `FullFlowResult` returned by full-flow endpoints |
| `http-request` | Shape of an `HttpRequest` for HTTP-WASM execution |
| `http-response` | Shape of an `HttpResponse` returned by HTTP-WASM execution |
| Name | Description |
| ---------------------- | ------------------------------------------------------------- |
| `fastedge-config.test` | Schema for `fastedge-config.test.json` config files |
| `hook-result` | Shape of a single `HookResult` object |
| `hook-call` | Shape of a `HookCall` input object |
| `full-flow-result` | Shape of the `FullFlowResult` returned by full-flow endpoints |
| `http-request` | Shape of an `HttpRequest` for HTTP-WASM execution |
| `http-response` | Shape of an `HttpResponse` returned by HTTP-WASM execution |

**Example**

Expand Down Expand Up @@ -932,9 +932,9 @@ curl http://localhost:5179/api/schema/fastedge-config.test

**Error Responses**

| Status | Condition |
| ------ | ---------------------- |
| `404` | Schema name not found |
| Status | Condition |
| ------ | --------------------- |
| `404` | Schema name not found |

---

Expand All @@ -953,11 +953,11 @@ When a request body fails schema validation (Zod), `error` is the flattened Zod

**Common status codes**

| Status | Meaning |
| ------ | ---------------------------------------------------------------------------------------------- |
| `400` | Invalid request body, missing required fields, or precondition not met (e.g. no WASM loaded) |
| `404` | Resource not found (config file, schema file) |
| `500` | Internal server error during execution or I/O |
| Status | Meaning |
| ------ | --------------------------------------------------------------------------------------------- |
| `400` | Invalid request body, missing required fields, or precondition not met (e.g. no WASM loaded) |
| `404` | Resource not found (config file, schema file) |
| `500` | Internal server error during execution or I/O |

---

Expand Down
42 changes: 31 additions & 11 deletions docs/DEBUGGER.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ Runs the FastEdge debugger HTTP server, which hosts the web UI, REST API, and We

## CLI Usage

The package exposes a `fastedge-debug` binary. Run it with `npx` without installing:
The package exposes a single binary, `fastedge-debug`. Run it with `npx` after installing `@gcoredev/fastedge-test` in your project:

```bash
npx @gcoredev/fastedge-test
npx fastedge-debug
```

Or using the explicit binary name:
If the package isn't installed yet, the explicit form fetches and runs it in one shot:

```bash
npx fastedge-debug
npx -p @gcoredev/fastedge-test fastedge-debug
```

> The shorthand `npx @gcoredev/fastedge-test` happens to work today because the package declares exactly one `bin` entry, and npx falls back to it when no name is given. Prefer the explicit `fastedge-debug` form — it stays correct if a second binary is ever added.

Once started, the server listens on `http://localhost:5179` by default and logs the bound address to stderr.

The CLI automatically discovers the workspace root by walking up from the current directory, looking first for an existing `.fastedge-debug/` directory, then for a `package.json` or `Cargo.toml`. The resolved root is used as the base for port file and configuration file placement. Pass a path as the first argument to anchor discovery to a specific starting location:
Expand All @@ -24,6 +26,24 @@ The CLI automatically discovers the workspace root by walking up from the curren
npx fastedge-debug /path/to/my-app
```

### `--project-dir <path>` (or `-C <path>`)

For setups where the CLI is invoked from a subdirectory of the project (for example, a Rust app with a `fastedge-test/` Node sandbox holding the debugger install), pass `--project-dir` to anchor workspace discovery at a different path:

```bash
# From inside fastedge-test/, point the debugger at the parent project root
cd fastedge-test
npx fastedge-debug --project-dir ..
```

The flag accepts both `--project-dir <path>` and `--project-dir=<path>`. `-C` is a short alias. The resolved path then drives `WORKSPACE_PATH` and all config / fixture / dotenv resolution that flows from it, exactly as if the user had invoked the CLI from that directory. The flag is stripped before any remaining positional arguments are forwarded to the server, so you can combine it with a fixture path or other options:

```bash
npx fastedge-debug --project-dir .. ../fixtures/scenario-1.test.json
```
Comment thread
godronus marked this conversation as resolved.

When omitted, behavior is unchanged from prior versions — the positional argument or `process.cwd()` is used as the starting point.

## Programmatic Usage

Import `startServer` from the `./server` export to start the server from your own script or test setup:
Expand Down Expand Up @@ -98,13 +118,13 @@ curl http://localhost:5179/health

## Environment Variables

| Variable | Type | Default | Description |
| -------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------ |
| `PORT` | `number` | unset | Port the HTTP server listens on. Defaults to `5179` when not set. |
| `PROXY_RUNNER_DEBUG` | `"1"` | unset | Enable verbose debug logging for WebSocket and runner activity. |
| `VSCODE_INTEGRATION` | `"true"` | unset | Set to `"true"` when running inside the VSCode extension; enables workspace WASM detection. |
| `WORKSPACE_PATH` | `string` | unset | Absolute path to the workspace root; used as the `.env` file base and for port file placement. |
| `FASTEDGE_RUN_PATH` | `string` | unset | Override the path to the `fastedge-run` CLI binary used to execute WASM modules. |
| Variable | Type | Default | Description |
| -------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------- |
| `PORT` | `number` | unset | Port the HTTP server listens on. Defaults to `5179` when not set. |
| `PROXY_RUNNER_DEBUG` | `"1"` | unset | Enable verbose debug logging for WebSocket and runner activity. |
| `VSCODE_INTEGRATION` | `"true"` | unset | Set to `"true"` when running inside the VSCode extension; enables workspace WASM detection. |
| `WORKSPACE_PATH` | `string` | unset | Absolute path to the workspace root; used as the `.env` file base and for port file placement. |
| `FASTEDGE_RUN_PATH` | `string` | unset | Override the path to the `fastedge-run` CLI binary used to execute WASM modules. |

### Usage examples

Expand Down
Loading
Loading