@jterrazz/test 6.5.1 → 7.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.
package/dist/index.cjs CHANGED
@@ -670,18 +670,32 @@ var SpecificationBuilder = class {
670
670
  * Uses MSW under the hood. Intercepts are queued — multiple calls with the
671
671
  * same trigger fire sequentially (first match consumed first).
672
672
  *
673
- * @param trigger - What to match (use openai.chat(), anthropic.messages(), http.get(), etc.)
674
- * @param response - What to return (use openai.response(), http.json(), etc.)
673
+ * @param trigger - What to match (use openai.agent(), http.get(), etc.)
674
+ * @param response - What to return: an InterceptResponse object, or a filename
675
+ * from `intercepts/` (JSON loaded and auto-wrapped by the trigger).
675
676
  *
676
677
  * @example
677
- * spec('pipeline')
678
- * .intercept(openai.chat(), openai.response({ categories: ['TECH'] }))
679
- * .intercept(openai.chat(), openai.response({ headline: 'AI News' }))
680
- * .exec('process')
681
- * .run();
678
+ * // With inline response
679
+ * .intercept(openai.agent({...}), openai.reply({ categories: ['TECH'] }))
680
+ *
681
+ * // With JSON fixture file (loaded from intercepts/ directory)
682
+ * .intercept(openai.agent({...}), 'ingest-tech.json')
683
+ * .intercept(http.get(url), 'world-news-tech.json')
682
684
  */
683
685
  intercept(trigger, response) {
684
- this.intercepts.push({
686
+ if (typeof response === "string") {
687
+ const slashIndex = response.indexOf("/");
688
+ if (slashIndex === -1) throw new Error(`.intercept(): file path must be 'adapter/filename.json' (e.g. 'openai/ingest-tech.json'), got '${response}'`);
689
+ const adapterName = response.slice(0, slashIndex);
690
+ if (adapterName !== trigger.adapter) throw new Error(`.intercept(): adapter mismatch - trigger uses '${trigger.adapter}' but file path starts with '${adapterName}/'`);
691
+ const filePath = (0, node_path.resolve)(this.testDir, "intercepts", response);
692
+ const data = JSON.parse((0, node_fs.readFileSync)(filePath, "utf8"));
693
+ const resolved = trigger.wrap(data);
694
+ this.intercepts.push({
695
+ trigger,
696
+ response: resolved
697
+ });
698
+ } else this.intercepts.push({
685
699
  trigger,
686
700
  response
687
701
  });