@http-forge/core 1.0.3 → 1.0.4
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/dist/index.d.ts +1 -1
- package/dist/index.js +122 -116
- package/dist/index.mjs +127 -121
- package/dist/infrastructure/collection/agents-md.d.ts +1 -1
- package/dist/infrastructure/collection/folder-io.d.ts +6 -0
- package/dist/infrastructure/script/interfaces.d.ts +11 -2
- package/dist/infrastructure/script/request-script-session.d.ts +3 -3
- package/dist/infrastructure/script/script-utils.d.ts +18 -1
- package/dist/templates/AGENTS.md +23 -22
- package/dist/types/types.d.ts +5 -3
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* user customizations are never silently lost.
|
|
15
15
|
*/
|
|
16
16
|
/** Current template version. Bump when `buildAgentsMdContent()` changes. */
|
|
17
|
-
export declare const AGENTS_MD_VERSION =
|
|
17
|
+
export declare const AGENTS_MD_VERSION = 6;
|
|
18
18
|
export declare const AGENTS_MD_FILENAME = "AGENTS.md";
|
|
19
19
|
export declare const AGENTS_MD_BACKUP_FILENAME = "AGENTS.md.bak";
|
|
20
20
|
/** Absolute path of the guide inside a `.http-forge/` directory. */
|
|
@@ -41,6 +41,8 @@ export declare const SCRIPTS_DIR = "scripts";
|
|
|
41
41
|
export interface ScriptsData {
|
|
42
42
|
preRequest?: string;
|
|
43
43
|
postResponse?: string;
|
|
44
|
+
preRequestPath?: string;
|
|
45
|
+
postResponsePath?: string;
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Read scripts from a scripts/ directory.
|
|
@@ -50,6 +52,10 @@ export declare function readScriptsFromDir(scriptsPath: string): ScriptsData | u
|
|
|
50
52
|
/**
|
|
51
53
|
* Write scripts to a scripts/ directory.
|
|
52
54
|
* If a script is empty/undefined, the corresponding file is deleted.
|
|
55
|
+
*
|
|
56
|
+
* The passed object is updated with the absolute file paths (and stale paths
|
|
57
|
+
* are cleared) so in-memory objects stay consistent with disk immediately
|
|
58
|
+
* after a save, mirroring `readScriptsFromDir` at load time.
|
|
53
59
|
*/
|
|
54
60
|
export declare function writeScriptsToDir(scriptsPath: string, scripts: ScriptsData): Promise<void>;
|
|
55
61
|
/**
|
|
@@ -171,6 +171,15 @@ export interface IScriptExecutor {
|
|
|
171
171
|
*/
|
|
172
172
|
endRun?(): void;
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* A script segment with its source code and filename for debugging.
|
|
176
|
+
* Each segment is executed as its own `vm.Script` so file-based breakpoints
|
|
177
|
+
* resolve to the file the user opened. Inline scripts use a synthetic filename.
|
|
178
|
+
*/
|
|
179
|
+
export interface ScriptSource {
|
|
180
|
+
code: string;
|
|
181
|
+
filename: string;
|
|
182
|
+
}
|
|
174
183
|
/**
|
|
175
184
|
* Request Script Session Interface
|
|
176
185
|
* Represents a shared VM context for a single request's pre-request and post-response scripts
|
|
@@ -180,11 +189,11 @@ export interface IRequestScriptSession {
|
|
|
180
189
|
/**
|
|
181
190
|
* Execute pre-request scripts in the shared session
|
|
182
191
|
*/
|
|
183
|
-
executePreRequest(script:
|
|
192
|
+
executePreRequest(script: ScriptSource | ScriptSource[]): Promise<PreRequestScriptResult>;
|
|
184
193
|
/**
|
|
185
194
|
* Update the session with response data and execute post-response scripts
|
|
186
195
|
*/
|
|
187
|
-
executePostResponse(script:
|
|
196
|
+
executePostResponse(script: ScriptSource | ScriptSource[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
|
|
188
197
|
/**
|
|
189
198
|
* Clean up the session (optional - for resource management)
|
|
190
199
|
*/
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import * as vm from 'vm';
|
|
11
11
|
import { SandboxTimers } from './async-drain';
|
|
12
|
-
import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, PreRequestScriptContext, PreRequestScriptResult, ResponseContext } from './interfaces';
|
|
12
|
+
import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, PreRequestScriptContext, PreRequestScriptResult, ResponseContext, ScriptSource } from './interfaces';
|
|
13
13
|
/**
|
|
14
14
|
* Dependencies injected from ScriptExecutor
|
|
15
15
|
* Interface Segregation: Only the methods needed by the session
|
|
@@ -76,12 +76,12 @@ export declare class RequestScriptSession implements IRequestScriptSession {
|
|
|
76
76
|
/**
|
|
77
77
|
* Execute pre-request scripts in the shared session
|
|
78
78
|
*/
|
|
79
|
-
executePreRequest(script:
|
|
79
|
+
executePreRequest(script: ScriptSource | ScriptSource[]): Promise<PreRequestScriptResult>;
|
|
80
80
|
/**
|
|
81
81
|
* Execute post-response scripts in the shared session
|
|
82
82
|
* The response data is injected into the existing VM context
|
|
83
83
|
*/
|
|
84
|
-
executePostResponse(script:
|
|
84
|
+
executePostResponse(script: ScriptSource | ScriptSource[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
|
|
85
85
|
/**
|
|
86
86
|
* Compare two RequestBody objects for equality
|
|
87
87
|
*/
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Single Responsibility: Pure utility functions for script execution
|
|
5
5
|
* These are stateless helper functions with no side effects
|
|
6
6
|
*/
|
|
7
|
-
import { TestAssertion } from '../../types/types';
|
|
7
|
+
import { RequestScripts, TestAssertion } from '../../types/types';
|
|
8
8
|
import { Cookie } from '../cookie/interfaces';
|
|
9
|
+
import type { ScriptSource } from './interfaces';
|
|
9
10
|
/**
|
|
10
11
|
* Console message structure for script output
|
|
11
12
|
*/
|
|
@@ -13,6 +14,22 @@ export interface ConsoleMessage {
|
|
|
13
14
|
level: 'log' | 'info' | 'warn' | 'error';
|
|
14
15
|
args: any[];
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert string | string[] to ScriptSource[] for execution.
|
|
19
|
+
* Inline scripts (tests, flow nodes, webview drafts) have no real file, so they
|
|
20
|
+
* get a synthetic filename; file-based callers should build ScriptSource
|
|
21
|
+
* objects with the real absolute path instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toScriptSources(script: string | string[] | undefined | null, defaultFilename: string): ScriptSource[];
|
|
24
|
+
/**
|
|
25
|
+
* Build the ScriptSource[] for one phase of a RequestScripts object.
|
|
26
|
+
*
|
|
27
|
+
* File-backed scripts carry the absolute path recorded by the loader
|
|
28
|
+
* (`preRequestPath` / `postResponsePath`), so breakpoints resolve to the file
|
|
29
|
+
* the user edited. Callers must not synthesize a filename when a real path is
|
|
30
|
+
* available; the synthetic fallback only covers inline/draft scripts.
|
|
31
|
+
*/
|
|
32
|
+
export declare function requestScriptSources(scripts: RequestScripts | undefined, phase: 'preRequest' | 'postResponse'): ScriptSource[];
|
|
16
33
|
/**
|
|
17
34
|
* Concatenate multiple scripts into one program.
|
|
18
35
|
*
|
package/dist/templates/AGENTS.md
CHANGED
|
@@ -8,6 +8,25 @@ This folder is the **HTTP Forge workspace root**. Do not create a nested `.http-
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
+
## Contents
|
|
12
|
+
|
|
13
|
+
- [Quick Reference](#quick-reference) — commands, paths, syntax, globals
|
|
14
|
+
- [Decision Tree](#decision-tree) — CLI vs MCP routing
|
|
15
|
+
- [Workflow](#workflow-design--discover--generate--edit--run--report--fix)
|
|
16
|
+
- [Folder Structure](#folder-structure)
|
|
17
|
+
- [Business Knowledge](#business-knowledge-httpforgeknowledge) / [Same-Workspace Code and Docs](#same-workspace-code-and-docs--read-before-generating)
|
|
18
|
+
- [JSON Schemas](#json-schemas)
|
|
19
|
+
- [Authoring by Direct File Editing](#authoring-by-direct-file-editing)
|
|
20
|
+
- [Test Generation Best Practices](#test-generation-best-practices)
|
|
21
|
+
- [AI Test Generation](#ai-test-generation)
|
|
22
|
+
- [Scripts & Assertions](#scripts--assertions)
|
|
23
|
+
- [Recipes](#recipes-step-by-step)
|
|
24
|
+
- [How AI Should Run Tests](#how-ai-should-run-tests)
|
|
25
|
+
- [Debugging Scripts](#debugging-scripts)
|
|
26
|
+
- [Documentation](#documentation)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
11
30
|
## Quick Reference
|
|
12
31
|
|
|
13
32
|
### Most-used commands
|
|
@@ -25,7 +44,7 @@ http-forge drift --path <project>
|
|
|
25
44
|
### Key paths
|
|
26
45
|
```
|
|
27
46
|
assets/collections/{slug}/request.json — request definition
|
|
28
|
-
assets/collections/{slug}/scripts/post-response
|
|
47
|
+
assets/collections/{slug}/scripts/*.js — pre-request / post-response scripts
|
|
29
48
|
assets/environments/{env}.json — environment variables
|
|
30
49
|
assets/suites/{name}.suite.json — test suite
|
|
31
50
|
.http-forge/knowledge/**/*.md — business context for AI
|
|
@@ -102,7 +121,7 @@ Drop markdown files into `.http-forge/knowledge/` (any depth). All `*.md` files
|
|
|
102
121
|
|
|
103
122
|
---
|
|
104
123
|
|
|
105
|
-
## Code
|
|
124
|
+
## Same-Workspace Code and Docs — Read Before Generating
|
|
106
125
|
|
|
107
126
|
Before generating tests, read the workspace for requirements:
|
|
108
127
|
1. `README.md`, `docs/**`, `openapi.*` — contracts and ACs.
|
|
@@ -207,12 +226,6 @@ pm.test('Has required fields', () => {
|
|
|
207
226
|
- `pm.request` (method, url, body, headers), `pm.response` (code, status, body, headers, cookies, responseTime)
|
|
208
227
|
- Legacy: `postman.setGlobalVariable()`, `postman.setEnvironmentVariable()`, `postman.getResponseHeader()`
|
|
209
228
|
|
|
210
|
-
### Template syntax
|
|
211
|
-
- `{{variableName}}` — variable
|
|
212
|
-
- `{{value | upper | trim}}` — filter chain
|
|
213
|
-
- `{{$guid}}`, `{{$timestamp}}` — dynamic variables
|
|
214
|
-
- `{{variable | date:'YYYY-MM-DD'}}` — filter with argument
|
|
215
|
-
|
|
216
229
|
---
|
|
217
230
|
|
|
218
231
|
## Recipes (step-by-step)
|
|
@@ -277,19 +290,7 @@ pm.test('Has id', () => pm.expect(pm.response.json()).to.have.property('id'));
|
|
|
277
290
|
**Rule:** Never use MCP/CLI to discover structure — read JSON files directly.
|
|
278
291
|
|
|
279
292
|
### CLI commands
|
|
280
|
-
|
|
281
|
-
http-forge run collection <name> --env <env> --json
|
|
282
|
-
http-forge run suite <name> --json
|
|
283
|
-
http-forge run request <name> --collection <ref> --json
|
|
284
|
-
http-forge run folder <path> --collection <ref> --json
|
|
285
|
-
http-forge discover --path <project> --output json
|
|
286
|
-
http-forge generate-suite --path <project> --collection <ref> [--run]
|
|
287
|
-
http-forge architect "intent" --apply
|
|
288
|
-
http-forge qa --path <project> --collection <ref> --base-url <url>
|
|
289
|
-
http-forge drift --path <project>
|
|
290
|
-
http-forge refresh-agents-md --apply
|
|
291
|
-
```
|
|
292
|
-
Add `--include report` for HTML report. Add `--exit-code` for CI.
|
|
293
|
+
See Quick Reference above for the full list. Add `--include report` for HTML report. Add `--exit-code` for CI.
|
|
293
294
|
|
|
294
295
|
### MCP tools
|
|
295
296
|
- **Execution:** `run_request`, `run_folder`, `run_collection`, `run_suite` (add `async: true`)
|
|
@@ -310,4 +311,4 @@ Add `--include report` for HTML report. Add `--exit-code` for CI.
|
|
|
310
311
|
|
|
311
312
|
Key docs: https://github.com/hsl1230/http-forge/tree/main/docs/user-guide
|
|
312
313
|
Script API types: `.http-forge/assets/http-forge-globals.d.ts`
|
|
313
|
-
|
|
314
|
+
|
package/dist/types/types.d.ts
CHANGED
|
@@ -117,6 +117,10 @@ export interface UnifiedRequest {
|
|
|
117
117
|
export interface CollectionScripts {
|
|
118
118
|
preRequest?: string;
|
|
119
119
|
postResponse?: string;
|
|
120
|
+
/** Absolute file path of pre-request.js (for debugging / source mapping). */
|
|
121
|
+
preRequestPath?: string;
|
|
122
|
+
/** Absolute file path of post-response.js (for debugging / source mapping). */
|
|
123
|
+
postResponsePath?: string;
|
|
120
124
|
}
|
|
121
125
|
/**
|
|
122
126
|
* Collection authentication configuration
|
|
@@ -749,9 +753,7 @@ export interface RequestAuth {
|
|
|
749
753
|
/**
|
|
750
754
|
* Request scripts configuration
|
|
751
755
|
*/
|
|
752
|
-
export interface RequestScripts {
|
|
753
|
-
preRequest?: string;
|
|
754
|
-
postResponse?: string;
|
|
756
|
+
export interface RequestScripts extends CollectionScripts {
|
|
755
757
|
}
|
|
756
758
|
/**
|
|
757
759
|
* Collection request - the on-disk/storage format
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@http-forge/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Headless Postman-compatible API testing engine for Node.js, CI/CD, OpenAPI workflows, and HTTP Forge automation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|