@http-forge/core 1.0.3 → 1.0.5

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.
@@ -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 = 5;
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. */
@@ -36,6 +36,12 @@ export declare class FolderCollectionStore implements ICollectionStore {
36
36
  private cache;
37
37
  private slugToIdMap;
38
38
  private idToSlugMap;
39
+ /**
40
+ * Lazily-derived item id → on-disk directory path index, per collection.
41
+ * Built from the in-memory tree (no extra disk I/O) so resolving a path for
42
+ * one item does not re-scan the whole collection folder for every lookup.
43
+ */
44
+ private itemPathIndex;
39
45
  /**
40
46
  * When true, `loadRequestFromDir` delegates to the light loader
41
47
  * (metadata only). Set only inside `loadAllLight()`; never left on.
@@ -235,6 +241,17 @@ export declare class FolderCollectionStore implements ICollectionStore {
235
241
  */
236
242
  private sortItemsByOrder;
237
243
  private findItemPath;
244
+ /**
245
+ * Resolve an item directory from the in-memory tree using a per-collection
246
+ * id→path index. The index is derived (no disk I/O) and rebuilt when a
247
+ * cached path disappears after a move/rename.
248
+ */
249
+ private findIndexedItemPath;
250
+ /**
251
+ * Build the id→directory index for one collection from its in-memory tree.
252
+ * Uses `idToSlugMap` for each segment, matching the names written on disk.
253
+ */
254
+ private buildItemPathIndex;
238
255
  /**
239
256
  * Build the on-disk slug path (root → item) for the given item id by walking the
240
257
  * in-memory collection tree. Each segment is resolved via idToSlugMap so it matches
@@ -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: string | string[]): Promise<PreRequestScriptResult>;
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: string | string[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
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: string | string[]): Promise<PreRequestScriptResult>;
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: string | string[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
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
  *
@@ -193,6 +193,11 @@ export declare class TestSuiteStore implements ITestSuiteStore {
193
193
  slug?: string;
194
194
  description?: string;
195
195
  }>;
196
+ /**
197
+ * Index a collection's request items by id from the in-memory tree only.
198
+ * Never triggers heavy-field hydration — used for display resolution.
199
+ */
200
+ private indexRequestsById;
196
201
  /**
197
202
  * Get selected requests in order
198
203
  * Always resolves fresh from collection service to ensure latest data
@@ -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.js — assertions (pm.test)
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 & Docs in Same Workspace
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
+
@@ -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",
3
+ "version": "1.0.5",
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",
@@ -107,7 +107,7 @@
107
107
  "@types/uuid": "^9.0.7",
108
108
  "@types/ws": "^8.18.2",
109
109
  "esbuild": "0.28.2",
110
- "rimraf": "^5.0.5",
110
+ "rimraf": "^6.1.4",
111
111
  "tsup": "^8.0.1",
112
112
  "typescript": "^5.3.0",
113
113
  "vitest": "^4.1.9"
@@ -120,5 +120,8 @@
120
120
  "homepage": "https://github.com/hsl1230/http-forge.core",
121
121
  "bugs": {
122
122
  "url": "https://github.com/hsl1230/http-forge.core/issues"
123
+ },
124
+ "allowScripts": {
125
+ "esbuild@0.28.2": true
123
126
  }
124
127
  }