@copilotkit/aimock 1.8.0 → 1.10.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.
Files changed (120) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +19 -17
  4. package/dist/a2a-types.d.ts.map +1 -1
  5. package/dist/bedrock-converse.cjs +6 -4
  6. package/dist/bedrock-converse.cjs.map +1 -1
  7. package/dist/bedrock-converse.d.cts.map +1 -1
  8. package/dist/bedrock-converse.d.ts.map +1 -1
  9. package/dist/bedrock-converse.js +7 -5
  10. package/dist/bedrock-converse.js.map +1 -1
  11. package/dist/bedrock.cjs +6 -4
  12. package/dist/bedrock.cjs.map +1 -1
  13. package/dist/bedrock.d.cts.map +1 -1
  14. package/dist/bedrock.d.ts.map +1 -1
  15. package/dist/bedrock.js +7 -5
  16. package/dist/bedrock.js.map +1 -1
  17. package/dist/cli.cjs +10 -4
  18. package/dist/cli.cjs.map +1 -1
  19. package/dist/cli.js +10 -4
  20. package/dist/cli.js.map +1 -1
  21. package/dist/cohere.cjs +3 -2
  22. package/dist/cohere.cjs.map +1 -1
  23. package/dist/cohere.d.cts.map +1 -1
  24. package/dist/cohere.d.ts.map +1 -1
  25. package/dist/cohere.js +4 -3
  26. package/dist/cohere.js.map +1 -1
  27. package/dist/embeddings.cjs +3 -2
  28. package/dist/embeddings.cjs.map +1 -1
  29. package/dist/embeddings.d.cts.map +1 -1
  30. package/dist/embeddings.d.ts.map +1 -1
  31. package/dist/embeddings.js +4 -3
  32. package/dist/embeddings.js.map +1 -1
  33. package/dist/gemini.cjs +105 -30
  34. package/dist/gemini.cjs.map +1 -1
  35. package/dist/gemini.d.cts.map +1 -1
  36. package/dist/gemini.d.ts.map +1 -1
  37. package/dist/gemini.js +106 -31
  38. package/dist/gemini.js.map +1 -1
  39. package/dist/helpers.cjs +150 -14
  40. package/dist/helpers.cjs.map +1 -1
  41. package/dist/helpers.d.cts.map +1 -1
  42. package/dist/helpers.d.ts.map +1 -1
  43. package/dist/helpers.js +147 -15
  44. package/dist/helpers.js.map +1 -1
  45. package/dist/index.cjs +1 -0
  46. package/dist/index.d.cts +2 -2
  47. package/dist/index.d.ts +2 -2
  48. package/dist/index.js +2 -2
  49. package/dist/journal.cjs +26 -9
  50. package/dist/journal.cjs.map +1 -1
  51. package/dist/journal.d.cts +10 -5
  52. package/dist/journal.d.cts.map +1 -1
  53. package/dist/journal.d.ts +10 -5
  54. package/dist/journal.d.ts.map +1 -1
  55. package/dist/journal.js +26 -10
  56. package/dist/journal.js.map +1 -1
  57. package/dist/llmock.cjs +2 -2
  58. package/dist/llmock.cjs.map +1 -1
  59. package/dist/llmock.d.cts +1 -1
  60. package/dist/llmock.d.ts +1 -1
  61. package/dist/llmock.js +2 -2
  62. package/dist/llmock.js.map +1 -1
  63. package/dist/messages.cjs +192 -2
  64. package/dist/messages.cjs.map +1 -1
  65. package/dist/messages.d.cts.map +1 -1
  66. package/dist/messages.d.ts.map +1 -1
  67. package/dist/messages.js +193 -3
  68. package/dist/messages.js.map +1 -1
  69. package/dist/ollama.cjs +6 -4
  70. package/dist/ollama.cjs.map +1 -1
  71. package/dist/ollama.d.cts.map +1 -1
  72. package/dist/ollama.d.ts.map +1 -1
  73. package/dist/ollama.js +7 -5
  74. package/dist/ollama.js.map +1 -1
  75. package/dist/recorder.cjs +23 -21
  76. package/dist/recorder.cjs.map +1 -1
  77. package/dist/recorder.js +23 -21
  78. package/dist/recorder.js.map +1 -1
  79. package/dist/responses.cjs +250 -126
  80. package/dist/responses.cjs.map +1 -1
  81. package/dist/responses.d.cts.map +1 -1
  82. package/dist/responses.d.ts.map +1 -1
  83. package/dist/responses.js +251 -127
  84. package/dist/responses.js.map +1 -1
  85. package/dist/server.cjs +42 -5
  86. package/dist/server.cjs.map +1 -1
  87. package/dist/server.d.cts.map +1 -1
  88. package/dist/server.d.ts.map +1 -1
  89. package/dist/server.js +43 -6
  90. package/dist/server.js.map +1 -1
  91. package/dist/stream-collapse.cjs +48 -40
  92. package/dist/stream-collapse.cjs.map +1 -1
  93. package/dist/stream-collapse.d.cts.map +1 -1
  94. package/dist/stream-collapse.d.ts.map +1 -1
  95. package/dist/stream-collapse.js +48 -40
  96. package/dist/stream-collapse.js.map +1 -1
  97. package/dist/types.d.cts +11 -1
  98. package/dist/types.d.cts.map +1 -1
  99. package/dist/types.d.ts +11 -1
  100. package/dist/types.d.ts.map +1 -1
  101. package/dist/vector-types.d.ts.map +1 -1
  102. package/dist/ws-gemini-live.cjs +4 -2
  103. package/dist/ws-gemini-live.cjs.map +1 -1
  104. package/dist/ws-gemini-live.d.cts +1 -0
  105. package/dist/ws-gemini-live.d.ts +1 -0
  106. package/dist/ws-gemini-live.js +4 -2
  107. package/dist/ws-gemini-live.js.map +1 -1
  108. package/dist/ws-realtime.cjs +4 -2
  109. package/dist/ws-realtime.cjs.map +1 -1
  110. package/dist/ws-realtime.d.cts +1 -0
  111. package/dist/ws-realtime.d.ts +1 -0
  112. package/dist/ws-realtime.js +4 -2
  113. package/dist/ws-realtime.js.map +1 -1
  114. package/dist/ws-responses.cjs +4 -2
  115. package/dist/ws-responses.cjs.map +1 -1
  116. package/dist/ws-responses.d.cts +1 -0
  117. package/dist/ws-responses.d.ts +1 -0
  118. package/dist/ws-responses.js +4 -2
  119. package/dist/ws-responses.js.map +1 -1
  120. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { buildEmbeddingResponse, buildTextChunks, buildToolCallChunks, flattenHeaders, generateDeterministicEmbedding, generateId, generateMessageId, generateToolCallId, generateToolUseId, isEmbeddingResponse } from "./helpers.js";
2
2
  import { createJsonRpcDispatcher } from "./jsonrpc.js";
3
3
  import { A2AMock } from "./a2a-mock.js";
4
- import { Journal } from "./journal.js";
4
+ import { DEFAULT_TEST_ID, Journal } from "./journal.js";
5
5
  import { getTextContent, matchFixture } from "./router.js";
6
6
  import { loadFixtureFile, loadFixturesFromDir, validateFixtures } from "./fixture-loader.js";
7
7
  import { calculateDelay, delay, writeErrorResponse, writeSSEStream } from "./sse-writer.js";
@@ -36,4 +36,4 @@ import { VectorMock } from "./vector-mock.js";
36
36
  import { loadConfig, startFromConfig } from "./config-loader.js";
37
37
  import { createMockSuite } from "./suite.js";
38
38
 
39
- export { A2AMock, Journal, LLMock, Logger, MCPMock, VectorMock, WebSocketConnection, applyChaos, bedrockToCompletionRequest, buildEmbeddingResponse, buildTextChunks, buildTextStreamEvents, buildToolCallChunks, buildToolCallStreamEvents, calculateDelay, cohereToCompletionRequest, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse, computeAcceptKey, converseToCompletionRequest, createInterruptionSignal, createJsonRpcDispatcher, createMetricsRegistry, createMockSuite, createServer, delay, encodeEventStreamFrame, encodeEventStreamMessage, evaluateChaos, flattenHeaders, generateDeterministicEmbedding, generateId, generateMessageId, generateToolCallId, generateToolUseId, getTextContent, handleBedrock, handleBedrockStream, handleCohere, handleConverse, handleConverseStream, handleEmbeddings, handleGemini, handleMessages, handleModeration, handleOllama, handleOllamaGenerate, handleRerank, handleResponses, handleSearch, handleWebSocketGeminiLive, handleWebSocketRealtime, handleWebSocketResponses, isEmbeddingResponse, loadConfig, loadFixtureFile, loadFixturesFromDir, matchFixture, normalizePathLabel, ollamaToCompletionRequest, proxyAndRecord, resolveUpstreamUrl, startFromConfig, upgradeToWebSocket, validateFixtures, writeErrorResponse, writeEventStream, writeNDJSONStream, writeSSEStream };
39
+ export { A2AMock, DEFAULT_TEST_ID, Journal, LLMock, Logger, MCPMock, VectorMock, WebSocketConnection, applyChaos, bedrockToCompletionRequest, buildEmbeddingResponse, buildTextChunks, buildTextStreamEvents, buildToolCallChunks, buildToolCallStreamEvents, calculateDelay, cohereToCompletionRequest, collapseAnthropicSSE, collapseBedrockEventStream, collapseCohereSSE, collapseGeminiSSE, collapseOllamaNDJSON, collapseOpenAISSE, collapseStreamingResponse, computeAcceptKey, converseToCompletionRequest, createInterruptionSignal, createJsonRpcDispatcher, createMetricsRegistry, createMockSuite, createServer, delay, encodeEventStreamFrame, encodeEventStreamMessage, evaluateChaos, flattenHeaders, generateDeterministicEmbedding, generateId, generateMessageId, generateToolCallId, generateToolUseId, getTextContent, handleBedrock, handleBedrockStream, handleCohere, handleConverse, handleConverseStream, handleEmbeddings, handleGemini, handleMessages, handleModeration, handleOllama, handleOllamaGenerate, handleRerank, handleResponses, handleSearch, handleWebSocketGeminiLive, handleWebSocketRealtime, handleWebSocketResponses, isEmbeddingResponse, loadConfig, loadFixtureFile, loadFixturesFromDir, matchFixture, normalizePathLabel, ollamaToCompletionRequest, proxyAndRecord, resolveUpstreamUrl, startFromConfig, upgradeToWebSocket, validateFixtures, writeErrorResponse, writeEventStream, writeNDJSONStream, writeSSEStream };
package/dist/journal.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  const require_helpers = require('./helpers.cjs');
2
2
 
3
3
  //#region src/journal.ts
4
+ /** Sentinel testId used when no explicit test scope is provided. */
5
+ const DEFAULT_TEST_ID = "__default__";
4
6
  /**
5
7
  * Compare two field values, handling RegExp by source+flags rather than reference.
6
8
  */
@@ -17,7 +19,11 @@ function matchCriteriaEqual(a, b) {
17
19
  }
18
20
  var Journal = class {
19
21
  entries = [];
20
- fixtureMatchCounts = /* @__PURE__ */ new Map();
22
+ fixtureMatchCountsByTestId = /* @__PURE__ */ new Map();
23
+ /** Backwards-compatible accessor — returns the default (no testId) count map. */
24
+ get fixtureMatchCounts() {
25
+ return this.getFixtureMatchCountsForTest(DEFAULT_TEST_ID);
26
+ }
21
27
  add(entry) {
22
28
  const full = {
23
29
  id: require_helpers.generateId("req"),
@@ -37,23 +43,33 @@ var Journal = class {
37
43
  findByFixture(fixture) {
38
44
  return this.entries.filter((e) => e.response.fixture === fixture);
39
45
  }
40
- getFixtureMatchCount(fixture) {
41
- return this.fixtureMatchCounts.get(fixture) ?? 0;
46
+ getFixtureMatchCountsForTest(testId) {
47
+ let counts = this.fixtureMatchCountsByTestId.get(testId);
48
+ if (!counts) {
49
+ counts = /* @__PURE__ */ new Map();
50
+ this.fixtureMatchCountsByTestId.set(testId, counts);
51
+ }
52
+ return counts;
53
+ }
54
+ getFixtureMatchCount(fixture, testId = DEFAULT_TEST_ID) {
55
+ return this.getFixtureMatchCountsForTest(testId).get(fixture) ?? 0;
42
56
  }
43
- incrementFixtureMatchCount(fixture, allFixtures) {
44
- this.fixtureMatchCounts.set(fixture, this.getFixtureMatchCount(fixture) + 1);
57
+ incrementFixtureMatchCount(fixture, allFixtures, testId = DEFAULT_TEST_ID) {
58
+ const counts = this.getFixtureMatchCountsForTest(testId);
59
+ counts.set(fixture, (counts.get(fixture) ?? 0) + 1);
45
60
  if (fixture.match.sequenceIndex !== void 0 && allFixtures) for (const sibling of allFixtures) {
46
61
  if (sibling === fixture) continue;
47
62
  if (sibling.match.sequenceIndex === void 0) continue;
48
- if (matchCriteriaEqual(fixture.match, sibling.match)) this.fixtureMatchCounts.set(sibling, this.getFixtureMatchCount(sibling) + 1);
63
+ if (matchCriteriaEqual(fixture.match, sibling.match)) counts.set(sibling, (counts.get(sibling) ?? 0) + 1);
49
64
  }
50
65
  }
51
- clearMatchCounts() {
52
- this.fixtureMatchCounts.clear();
66
+ clearMatchCounts(testId) {
67
+ if (testId !== void 0) this.fixtureMatchCountsByTestId.delete(testId);
68
+ else this.fixtureMatchCountsByTestId.clear();
53
69
  }
54
70
  clear() {
55
71
  this.entries = [];
56
- this.fixtureMatchCounts.clear();
72
+ this.fixtureMatchCountsByTestId.clear();
57
73
  }
58
74
  get size() {
59
75
  return this.entries.length;
@@ -61,5 +77,6 @@ var Journal = class {
61
77
  };
62
78
 
63
79
  //#endregion
80
+ exports.DEFAULT_TEST_ID = DEFAULT_TEST_ID;
64
81
  exports.Journal = Journal;
65
82
  //# sourceMappingURL=journal.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.cjs","names":["generateId"],"sources":["../src/journal.ts"],"sourcesContent":["import { generateId } from \"./helpers.js\";\nimport type { Fixture, FixtureMatch, JournalEntry } from \"./types.js\";\n\n/**\n * Compare two field values, handling RegExp by source+flags rather than reference.\n */\nfunction fieldEqual(a: unknown, b: unknown): boolean {\n if (a instanceof RegExp && b instanceof RegExp)\n return a.source === b.source && a.flags === b.flags;\n return a === b;\n}\n\n/**\n * Check whether two fixture match objects have the same criteria\n * (ignoring sequenceIndex). Used to group sequenced fixtures.\n */\nfunction matchCriteriaEqual(a: FixtureMatch, b: FixtureMatch): boolean {\n return (\n fieldEqual(a.userMessage, b.userMessage) &&\n fieldEqual(a.inputText, b.inputText) &&\n fieldEqual(a.toolCallId, b.toolCallId) &&\n fieldEqual(a.toolName, b.toolName) &&\n fieldEqual(a.model, b.model) &&\n fieldEqual(a.responseFormat, b.responseFormat) &&\n fieldEqual(a.predicate, b.predicate)\n );\n}\n\nexport class Journal {\n private entries: JournalEntry[] = [];\n readonly fixtureMatchCounts: Map<Fixture, number> = new Map();\n\n add(entry: Omit<JournalEntry, \"id\" | \"timestamp\">): JournalEntry {\n const full: JournalEntry = {\n id: generateId(\"req\"),\n timestamp: Date.now(),\n ...entry,\n };\n this.entries.push(full);\n return full;\n }\n\n getAll(opts?: { limit?: number }): JournalEntry[] {\n if (opts?.limit !== undefined) {\n return this.entries.slice(-opts.limit);\n }\n return this.entries.slice();\n }\n\n getLast(): JournalEntry | null {\n return this.entries.length > 0 ? this.entries[this.entries.length - 1] : null;\n }\n\n findByFixture(fixture: Fixture): JournalEntry[] {\n return this.entries.filter((e) => e.response.fixture === fixture);\n }\n\n getFixtureMatchCount(fixture: Fixture): number {\n return this.fixtureMatchCounts.get(fixture) ?? 0;\n }\n\n incrementFixtureMatchCount(fixture: Fixture, allFixtures?: readonly Fixture[]): void {\n this.fixtureMatchCounts.set(fixture, this.getFixtureMatchCount(fixture) + 1);\n // When a sequenced fixture matches, also increment all siblings with matching criteria\n if (fixture.match.sequenceIndex !== undefined && allFixtures) {\n for (const sibling of allFixtures) {\n if (sibling === fixture) continue;\n if (sibling.match.sequenceIndex === undefined) continue;\n if (matchCriteriaEqual(fixture.match, sibling.match)) {\n this.fixtureMatchCounts.set(sibling, this.getFixtureMatchCount(sibling) + 1);\n }\n }\n }\n }\n\n clearMatchCounts(): void {\n this.fixtureMatchCounts.clear();\n }\n\n clear(): void {\n this.entries = [];\n this.fixtureMatchCounts.clear();\n }\n\n get size(): number {\n return this.entries.length;\n }\n}\n"],"mappings":";;;;;;AAMA,SAAS,WAAW,GAAY,GAAqB;AACnD,KAAI,aAAa,UAAU,aAAa,OACtC,QAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;AAChD,QAAO,MAAM;;;;;;AAOf,SAAS,mBAAmB,GAAiB,GAA0B;AACrE,QACE,WAAW,EAAE,aAAa,EAAE,YAAY,IACxC,WAAW,EAAE,WAAW,EAAE,UAAU,IACpC,WAAW,EAAE,YAAY,EAAE,WAAW,IACtC,WAAW,EAAE,UAAU,EAAE,SAAS,IAClC,WAAW,EAAE,OAAO,EAAE,MAAM,IAC5B,WAAW,EAAE,gBAAgB,EAAE,eAAe,IAC9C,WAAW,EAAE,WAAW,EAAE,UAAU;;AAIxC,IAAa,UAAb,MAAqB;CACnB,AAAQ,UAA0B,EAAE;CACpC,AAAS,qCAA2C,IAAI,KAAK;CAE7D,IAAI,OAA6D;EAC/D,MAAM,OAAqB;GACzB,IAAIA,2BAAW,MAAM;GACrB,WAAW,KAAK,KAAK;GACrB,GAAG;GACJ;AACD,OAAK,QAAQ,KAAK,KAAK;AACvB,SAAO;;CAGT,OAAO,MAA2C;AAChD,MAAI,MAAM,UAAU,OAClB,QAAO,KAAK,QAAQ,MAAM,CAAC,KAAK,MAAM;AAExC,SAAO,KAAK,QAAQ,OAAO;;CAG7B,UAA+B;AAC7B,SAAO,KAAK,QAAQ,SAAS,IAAI,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK;;CAG3E,cAAc,SAAkC;AAC9C,SAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,SAAS,YAAY,QAAQ;;CAGnE,qBAAqB,SAA0B;AAC7C,SAAO,KAAK,mBAAmB,IAAI,QAAQ,IAAI;;CAGjD,2BAA2B,SAAkB,aAAwC;AACnF,OAAK,mBAAmB,IAAI,SAAS,KAAK,qBAAqB,QAAQ,GAAG,EAAE;AAE5E,MAAI,QAAQ,MAAM,kBAAkB,UAAa,YAC/C,MAAK,MAAM,WAAW,aAAa;AACjC,OAAI,YAAY,QAAS;AACzB,OAAI,QAAQ,MAAM,kBAAkB,OAAW;AAC/C,OAAI,mBAAmB,QAAQ,OAAO,QAAQ,MAAM,CAClD,MAAK,mBAAmB,IAAI,SAAS,KAAK,qBAAqB,QAAQ,GAAG,EAAE;;;CAMpF,mBAAyB;AACvB,OAAK,mBAAmB,OAAO;;CAGjC,QAAc;AACZ,OAAK,UAAU,EAAE;AACjB,OAAK,mBAAmB,OAAO;;CAGjC,IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ"}
1
+ {"version":3,"file":"journal.cjs","names":["generateId"],"sources":["../src/journal.ts"],"sourcesContent":["import { generateId } from \"./helpers.js\";\nimport type { Fixture, FixtureMatch, JournalEntry } from \"./types.js\";\n\n/** Sentinel testId used when no explicit test scope is provided. */\nexport const DEFAULT_TEST_ID = \"__default__\";\n\n/**\n * Compare two field values, handling RegExp by source+flags rather than reference.\n */\nfunction fieldEqual(a: unknown, b: unknown): boolean {\n if (a instanceof RegExp && b instanceof RegExp)\n return a.source === b.source && a.flags === b.flags;\n return a === b;\n}\n\n/**\n * Check whether two fixture match objects have the same criteria\n * (ignoring sequenceIndex). Used to group sequenced fixtures.\n */\nfunction matchCriteriaEqual(a: FixtureMatch, b: FixtureMatch): boolean {\n return (\n fieldEqual(a.userMessage, b.userMessage) &&\n fieldEqual(a.inputText, b.inputText) &&\n fieldEqual(a.toolCallId, b.toolCallId) &&\n fieldEqual(a.toolName, b.toolName) &&\n fieldEqual(a.model, b.model) &&\n fieldEqual(a.responseFormat, b.responseFormat) &&\n fieldEqual(a.predicate, b.predicate)\n );\n}\n\nexport class Journal {\n private entries: JournalEntry[] = [];\n private readonly fixtureMatchCountsByTestId: Map<string, Map<Fixture, number>> = new Map();\n\n /** Backwards-compatible accessor — returns the default (no testId) count map. */\n get fixtureMatchCounts(): Map<Fixture, number> {\n return this.getFixtureMatchCountsForTest(DEFAULT_TEST_ID);\n }\n\n add(entry: Omit<JournalEntry, \"id\" | \"timestamp\">): JournalEntry {\n const full: JournalEntry = {\n id: generateId(\"req\"),\n timestamp: Date.now(),\n ...entry,\n };\n this.entries.push(full);\n return full;\n }\n\n getAll(opts?: { limit?: number }): JournalEntry[] {\n if (opts?.limit !== undefined) {\n return this.entries.slice(-opts.limit);\n }\n return this.entries.slice();\n }\n\n getLast(): JournalEntry | null {\n return this.entries.length > 0 ? this.entries[this.entries.length - 1] : null;\n }\n\n findByFixture(fixture: Fixture): JournalEntry[] {\n return this.entries.filter((e) => e.response.fixture === fixture);\n }\n\n getFixtureMatchCountsForTest(testId: string): Map<Fixture, number> {\n let counts = this.fixtureMatchCountsByTestId.get(testId);\n if (!counts) {\n counts = new Map();\n this.fixtureMatchCountsByTestId.set(testId, counts);\n }\n return counts;\n }\n\n getFixtureMatchCount(fixture: Fixture, testId = DEFAULT_TEST_ID): number {\n return this.getFixtureMatchCountsForTest(testId).get(fixture) ?? 0;\n }\n\n incrementFixtureMatchCount(\n fixture: Fixture,\n allFixtures?: readonly Fixture[],\n testId = DEFAULT_TEST_ID,\n ): void {\n const counts = this.getFixtureMatchCountsForTest(testId);\n counts.set(fixture, (counts.get(fixture) ?? 0) + 1);\n // When a sequenced fixture matches, also increment all siblings with matching criteria\n if (fixture.match.sequenceIndex !== undefined && allFixtures) {\n for (const sibling of allFixtures) {\n if (sibling === fixture) continue;\n if (sibling.match.sequenceIndex === undefined) continue;\n if (matchCriteriaEqual(fixture.match, sibling.match)) {\n counts.set(sibling, (counts.get(sibling) ?? 0) + 1);\n }\n }\n }\n }\n\n clearMatchCounts(testId?: string): void {\n if (testId !== undefined) {\n this.fixtureMatchCountsByTestId.delete(testId);\n } else {\n this.fixtureMatchCountsByTestId.clear();\n }\n }\n\n clear(): void {\n this.entries = [];\n this.fixtureMatchCountsByTestId.clear();\n }\n\n get size(): number {\n return this.entries.length;\n }\n}\n"],"mappings":";;;;AAIA,MAAa,kBAAkB;;;;AAK/B,SAAS,WAAW,GAAY,GAAqB;AACnD,KAAI,aAAa,UAAU,aAAa,OACtC,QAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;AAChD,QAAO,MAAM;;;;;;AAOf,SAAS,mBAAmB,GAAiB,GAA0B;AACrE,QACE,WAAW,EAAE,aAAa,EAAE,YAAY,IACxC,WAAW,EAAE,WAAW,EAAE,UAAU,IACpC,WAAW,EAAE,YAAY,EAAE,WAAW,IACtC,WAAW,EAAE,UAAU,EAAE,SAAS,IAClC,WAAW,EAAE,OAAO,EAAE,MAAM,IAC5B,WAAW,EAAE,gBAAgB,EAAE,eAAe,IAC9C,WAAW,EAAE,WAAW,EAAE,UAAU;;AAIxC,IAAa,UAAb,MAAqB;CACnB,AAAQ,UAA0B,EAAE;CACpC,AAAiB,6CAAgE,IAAI,KAAK;;CAG1F,IAAI,qBAA2C;AAC7C,SAAO,KAAK,6BAA6B,gBAAgB;;CAG3D,IAAI,OAA6D;EAC/D,MAAM,OAAqB;GACzB,IAAIA,2BAAW,MAAM;GACrB,WAAW,KAAK,KAAK;GACrB,GAAG;GACJ;AACD,OAAK,QAAQ,KAAK,KAAK;AACvB,SAAO;;CAGT,OAAO,MAA2C;AAChD,MAAI,MAAM,UAAU,OAClB,QAAO,KAAK,QAAQ,MAAM,CAAC,KAAK,MAAM;AAExC,SAAO,KAAK,QAAQ,OAAO;;CAG7B,UAA+B;AAC7B,SAAO,KAAK,QAAQ,SAAS,IAAI,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK;;CAG3E,cAAc,SAAkC;AAC9C,SAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,SAAS,YAAY,QAAQ;;CAGnE,6BAA6B,QAAsC;EACjE,IAAI,SAAS,KAAK,2BAA2B,IAAI,OAAO;AACxD,MAAI,CAAC,QAAQ;AACX,4BAAS,IAAI,KAAK;AAClB,QAAK,2BAA2B,IAAI,QAAQ,OAAO;;AAErD,SAAO;;CAGT,qBAAqB,SAAkB,SAAS,iBAAyB;AACvE,SAAO,KAAK,6BAA6B,OAAO,CAAC,IAAI,QAAQ,IAAI;;CAGnE,2BACE,SACA,aACA,SAAS,iBACH;EACN,MAAM,SAAS,KAAK,6BAA6B,OAAO;AACxD,SAAO,IAAI,UAAU,OAAO,IAAI,QAAQ,IAAI,KAAK,EAAE;AAEnD,MAAI,QAAQ,MAAM,kBAAkB,UAAa,YAC/C,MAAK,MAAM,WAAW,aAAa;AACjC,OAAI,YAAY,QAAS;AACzB,OAAI,QAAQ,MAAM,kBAAkB,OAAW;AAC/C,OAAI,mBAAmB,QAAQ,OAAO,QAAQ,MAAM,CAClD,QAAO,IAAI,UAAU,OAAO,IAAI,QAAQ,IAAI,KAAK,EAAE;;;CAM3D,iBAAiB,QAAuB;AACtC,MAAI,WAAW,OACb,MAAK,2BAA2B,OAAO,OAAO;MAE9C,MAAK,2BAA2B,OAAO;;CAI3C,QAAc;AACZ,OAAK,UAAU,EAAE;AACjB,OAAK,2BAA2B,OAAO;;CAGzC,IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ"}
@@ -1,23 +1,28 @@
1
1
  import { Fixture, JournalEntry } from "./types.cjs";
2
2
 
3
3
  //#region src/journal.d.ts
4
+ /** Sentinel testId used when no explicit test scope is provided. */
5
+ declare const DEFAULT_TEST_ID = "__default__";
4
6
  declare class Journal {
5
7
  private entries;
6
- readonly fixtureMatchCounts: Map<Fixture, number>;
8
+ private readonly fixtureMatchCountsByTestId;
9
+ /** Backwards-compatible accessor — returns the default (no testId) count map. */
10
+ get fixtureMatchCounts(): Map<Fixture, number>;
7
11
  add(entry: Omit<JournalEntry, "id" | "timestamp">): JournalEntry;
8
12
  getAll(opts?: {
9
13
  limit?: number;
10
14
  }): JournalEntry[];
11
15
  getLast(): JournalEntry | null;
12
16
  findByFixture(fixture: Fixture): JournalEntry[];
13
- getFixtureMatchCount(fixture: Fixture): number;
14
- incrementFixtureMatchCount(fixture: Fixture, allFixtures?: readonly Fixture[]): void;
15
- clearMatchCounts(): void;
17
+ getFixtureMatchCountsForTest(testId: string): Map<Fixture, number>;
18
+ getFixtureMatchCount(fixture: Fixture, testId?: string): number;
19
+ incrementFixtureMatchCount(fixture: Fixture, allFixtures?: readonly Fixture[], testId?: string): void;
20
+ clearMatchCounts(testId?: string): void;
16
21
  clear(): void;
17
22
  get size(): number;
18
23
  }
19
24
  //# sourceMappingURL=journal.d.ts.map
20
25
 
21
26
  //#endregion
22
- export { Journal };
27
+ export { DEFAULT_TEST_ID, Journal };
23
28
  //# sourceMappingURL=journal.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.d.cts","names":[],"sources":["../src/journal.ts"],"sourcesContent":[],"mappings":";;;cA4Ba,OAAA;;EAAA,SAAA,kBAAO,EAEW,GAFX,CAEe,OAFf,EAAA,MAAA,CAAA;EAAA,GAAA,CAAA,KAAA,EAIP,IAJO,CAIF,YAJE,EAAA,IAAA,GAAA,WAAA,CAAA,CAAA,EAIkC,YAJlC;QAEe,CAAA,KAAA,EAAA;IAAJ,KAAA,CAAA,EAAA,MAAA;MAYM,YAVnB,EAAA;SAAL,CAAA,CAAA,EAiBA,YAjBA,GAAA,IAAA;eAAyC,CAAA,OAAA,EAqB7B,OArB6B,CAAA,EAqBnB,YArBmB,EAAA;sBAUjB,CAAA,OAAA,EAeL,OAfK,CAAA,EAAA,MAAA;4BAOxB,CAAA,OAAA,EAYyB,OAZzB,EAAA,WAAA,CAAA,EAAA,SAYyD,OAZzD,EAAA,CAAA,EAAA,IAAA;kBAIY,CAAA,CAAA,EAAA,IAAA;OAAU,CAAA,CAAA,EAAA,IAAA;MAIH,IAAA,CAAA,CAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"journal.d.cts","names":[],"sources":["../src/journal.ts"],"sourcesContent":[],"mappings":";;;;cAIa,eAAA;AAAA,cA2BA,OAAA,CA3Be;EA2Bf,QAAA,OAAO;EAAA,iBAAA,0BAAA;;MAKQ,kBAAA,CAAA,CAAA,EAAA,GAAA,CAAI,OAAJ,EAAA,MAAA,CAAA;KAIV,CAAA,KAAA,EAAL,IAAK,CAAA,YAAA,EAAA,IAAA,GAAA,WAAA,CAAA,CAAA,EAAoC,YAApC;QAAL,CAAA,KAAA,EAAA;IAAyC,KAAA,CAAA,EAAA,MAAA;MAUjB,YAAA,EAAA;SAOxB,CAAA,CAAA,EAAA,YAAA,GAAA,IAAA;eAIY,CAAA,OAAA,EAAA,OAAA,CAAA,EAAU,YAAV,EAAA;8BAAU,CAAA,MAAA,EAAA,MAAA,CAAA,EAIa,GAJb,CAIiB,OAJjB,EAAA,MAAA,CAAA;sBAIiB,CAAA,OAAA,EASpB,OAToB,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;4BAAJ,CAAA,OAAA,EAcnC,OAdmC,EAAA,WAAA,CAAA,EAAA,SAerB,OAfqB,EAAA,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;kBAShB,CAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;OAKnB,CAAA,CAAA,EAAA,IAAA;MACc,IAAA,CAAA,CAAA,EAAA,MAAA"}
package/dist/journal.d.ts CHANGED
@@ -1,23 +1,28 @@
1
1
  import { Fixture, JournalEntry } from "./types.js";
2
2
 
3
3
  //#region src/journal.d.ts
4
+ /** Sentinel testId used when no explicit test scope is provided. */
5
+ declare const DEFAULT_TEST_ID = "__default__";
4
6
  declare class Journal {
5
7
  private entries;
6
- readonly fixtureMatchCounts: Map<Fixture, number>;
8
+ private readonly fixtureMatchCountsByTestId;
9
+ /** Backwards-compatible accessor — returns the default (no testId) count map. */
10
+ get fixtureMatchCounts(): Map<Fixture, number>;
7
11
  add(entry: Omit<JournalEntry, "id" | "timestamp">): JournalEntry;
8
12
  getAll(opts?: {
9
13
  limit?: number;
10
14
  }): JournalEntry[];
11
15
  getLast(): JournalEntry | null;
12
16
  findByFixture(fixture: Fixture): JournalEntry[];
13
- getFixtureMatchCount(fixture: Fixture): number;
14
- incrementFixtureMatchCount(fixture: Fixture, allFixtures?: readonly Fixture[]): void;
15
- clearMatchCounts(): void;
17
+ getFixtureMatchCountsForTest(testId: string): Map<Fixture, number>;
18
+ getFixtureMatchCount(fixture: Fixture, testId?: string): number;
19
+ incrementFixtureMatchCount(fixture: Fixture, allFixtures?: readonly Fixture[], testId?: string): void;
20
+ clearMatchCounts(testId?: string): void;
16
21
  clear(): void;
17
22
  get size(): number;
18
23
  }
19
24
  //# sourceMappingURL=journal.d.ts.map
20
25
 
21
26
  //#endregion
22
- export { Journal };
27
+ export { DEFAULT_TEST_ID, Journal };
23
28
  //# sourceMappingURL=journal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.d.ts","names":[],"sources":["../src/journal.ts"],"sourcesContent":[],"mappings":";;;cA4Ba,OAAA;;EAAA,SAAA,kBAAO,EAEW,GAFX,CAEe,OAFf,EAAA,MAAA,CAAA;EAAA,GAAA,CAAA,KAAA,EAIP,IAJO,CAIF,YAJE,EAAA,IAAA,GAAA,WAAA,CAAA,CAAA,EAIkC,YAJlC;QAEe,CAAA,KAAA,EAAA;IAAJ,KAAA,CAAA,EAAA,MAAA;MAYM,YAVnB,EAAA;SAAL,CAAA,CAAA,EAiBA,YAjBA,GAAA,IAAA;eAAyC,CAAA,OAAA,EAqB7B,OArB6B,CAAA,EAqBnB,YArBmB,EAAA;sBAUjB,CAAA,OAAA,EAeL,OAfK,CAAA,EAAA,MAAA;4BAOxB,CAAA,OAAA,EAYyB,OAZzB,EAAA,WAAA,CAAA,EAAA,SAYyD,OAZzD,EAAA,CAAA,EAAA,IAAA;kBAIY,CAAA,CAAA,EAAA,IAAA;OAAU,CAAA,CAAA,EAAA,IAAA;MAIH,IAAA,CAAA,CAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"journal.d.ts","names":[],"sources":["../src/journal.ts"],"sourcesContent":[],"mappings":";;;;cAIa,eAAA;AAAA,cA2BA,OAAA,CA3Be;EA2Bf,QAAA,OAAO;EAAA,iBAAA,0BAAA;;MAKQ,kBAAA,CAAA,CAAA,EAAA,GAAA,CAAI,OAAJ,EAAA,MAAA,CAAA;KAIV,CAAA,KAAA,EAAL,IAAK,CAAA,YAAA,EAAA,IAAA,GAAA,WAAA,CAAA,CAAA,EAAoC,YAApC;QAAL,CAAA,KAAA,EAAA;IAAyC,KAAA,CAAA,EAAA,MAAA;MAUjB,YAAA,EAAA;SAOxB,CAAA,CAAA,EAAA,YAAA,GAAA,IAAA;eAIY,CAAA,OAAA,EAAA,OAAA,CAAA,EAAU,YAAV,EAAA;8BAAU,CAAA,MAAA,EAAA,MAAA,CAAA,EAIa,GAJb,CAIiB,OAJjB,EAAA,MAAA,CAAA;sBAIiB,CAAA,OAAA,EASpB,OAToB,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;4BAAJ,CAAA,OAAA,EAcnC,OAdmC,EAAA,WAAA,CAAA,EAAA,SAerB,OAfqB,EAAA,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;kBAShB,CAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;OAKnB,CAAA,CAAA,EAAA,IAAA;MACc,IAAA,CAAA,CAAA,EAAA,MAAA"}
package/dist/journal.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { generateId } from "./helpers.js";
2
2
 
3
3
  //#region src/journal.ts
4
+ /** Sentinel testId used when no explicit test scope is provided. */
5
+ const DEFAULT_TEST_ID = "__default__";
4
6
  /**
5
7
  * Compare two field values, handling RegExp by source+flags rather than reference.
6
8
  */
@@ -17,7 +19,11 @@ function matchCriteriaEqual(a, b) {
17
19
  }
18
20
  var Journal = class {
19
21
  entries = [];
20
- fixtureMatchCounts = /* @__PURE__ */ new Map();
22
+ fixtureMatchCountsByTestId = /* @__PURE__ */ new Map();
23
+ /** Backwards-compatible accessor — returns the default (no testId) count map. */
24
+ get fixtureMatchCounts() {
25
+ return this.getFixtureMatchCountsForTest(DEFAULT_TEST_ID);
26
+ }
21
27
  add(entry) {
22
28
  const full = {
23
29
  id: generateId("req"),
@@ -37,23 +43,33 @@ var Journal = class {
37
43
  findByFixture(fixture) {
38
44
  return this.entries.filter((e) => e.response.fixture === fixture);
39
45
  }
40
- getFixtureMatchCount(fixture) {
41
- return this.fixtureMatchCounts.get(fixture) ?? 0;
46
+ getFixtureMatchCountsForTest(testId) {
47
+ let counts = this.fixtureMatchCountsByTestId.get(testId);
48
+ if (!counts) {
49
+ counts = /* @__PURE__ */ new Map();
50
+ this.fixtureMatchCountsByTestId.set(testId, counts);
51
+ }
52
+ return counts;
53
+ }
54
+ getFixtureMatchCount(fixture, testId = DEFAULT_TEST_ID) {
55
+ return this.getFixtureMatchCountsForTest(testId).get(fixture) ?? 0;
42
56
  }
43
- incrementFixtureMatchCount(fixture, allFixtures) {
44
- this.fixtureMatchCounts.set(fixture, this.getFixtureMatchCount(fixture) + 1);
57
+ incrementFixtureMatchCount(fixture, allFixtures, testId = DEFAULT_TEST_ID) {
58
+ const counts = this.getFixtureMatchCountsForTest(testId);
59
+ counts.set(fixture, (counts.get(fixture) ?? 0) + 1);
45
60
  if (fixture.match.sequenceIndex !== void 0 && allFixtures) for (const sibling of allFixtures) {
46
61
  if (sibling === fixture) continue;
47
62
  if (sibling.match.sequenceIndex === void 0) continue;
48
- if (matchCriteriaEqual(fixture.match, sibling.match)) this.fixtureMatchCounts.set(sibling, this.getFixtureMatchCount(sibling) + 1);
63
+ if (matchCriteriaEqual(fixture.match, sibling.match)) counts.set(sibling, (counts.get(sibling) ?? 0) + 1);
49
64
  }
50
65
  }
51
- clearMatchCounts() {
52
- this.fixtureMatchCounts.clear();
66
+ clearMatchCounts(testId) {
67
+ if (testId !== void 0) this.fixtureMatchCountsByTestId.delete(testId);
68
+ else this.fixtureMatchCountsByTestId.clear();
53
69
  }
54
70
  clear() {
55
71
  this.entries = [];
56
- this.fixtureMatchCounts.clear();
72
+ this.fixtureMatchCountsByTestId.clear();
57
73
  }
58
74
  get size() {
59
75
  return this.entries.length;
@@ -61,5 +77,5 @@ var Journal = class {
61
77
  };
62
78
 
63
79
  //#endregion
64
- export { Journal };
80
+ export { DEFAULT_TEST_ID, Journal };
65
81
  //# sourceMappingURL=journal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.js","names":[],"sources":["../src/journal.ts"],"sourcesContent":["import { generateId } from \"./helpers.js\";\nimport type { Fixture, FixtureMatch, JournalEntry } from \"./types.js\";\n\n/**\n * Compare two field values, handling RegExp by source+flags rather than reference.\n */\nfunction fieldEqual(a: unknown, b: unknown): boolean {\n if (a instanceof RegExp && b instanceof RegExp)\n return a.source === b.source && a.flags === b.flags;\n return a === b;\n}\n\n/**\n * Check whether two fixture match objects have the same criteria\n * (ignoring sequenceIndex). Used to group sequenced fixtures.\n */\nfunction matchCriteriaEqual(a: FixtureMatch, b: FixtureMatch): boolean {\n return (\n fieldEqual(a.userMessage, b.userMessage) &&\n fieldEqual(a.inputText, b.inputText) &&\n fieldEqual(a.toolCallId, b.toolCallId) &&\n fieldEqual(a.toolName, b.toolName) &&\n fieldEqual(a.model, b.model) &&\n fieldEqual(a.responseFormat, b.responseFormat) &&\n fieldEqual(a.predicate, b.predicate)\n );\n}\n\nexport class Journal {\n private entries: JournalEntry[] = [];\n readonly fixtureMatchCounts: Map<Fixture, number> = new Map();\n\n add(entry: Omit<JournalEntry, \"id\" | \"timestamp\">): JournalEntry {\n const full: JournalEntry = {\n id: generateId(\"req\"),\n timestamp: Date.now(),\n ...entry,\n };\n this.entries.push(full);\n return full;\n }\n\n getAll(opts?: { limit?: number }): JournalEntry[] {\n if (opts?.limit !== undefined) {\n return this.entries.slice(-opts.limit);\n }\n return this.entries.slice();\n }\n\n getLast(): JournalEntry | null {\n return this.entries.length > 0 ? this.entries[this.entries.length - 1] : null;\n }\n\n findByFixture(fixture: Fixture): JournalEntry[] {\n return this.entries.filter((e) => e.response.fixture === fixture);\n }\n\n getFixtureMatchCount(fixture: Fixture): number {\n return this.fixtureMatchCounts.get(fixture) ?? 0;\n }\n\n incrementFixtureMatchCount(fixture: Fixture, allFixtures?: readonly Fixture[]): void {\n this.fixtureMatchCounts.set(fixture, this.getFixtureMatchCount(fixture) + 1);\n // When a sequenced fixture matches, also increment all siblings with matching criteria\n if (fixture.match.sequenceIndex !== undefined && allFixtures) {\n for (const sibling of allFixtures) {\n if (sibling === fixture) continue;\n if (sibling.match.sequenceIndex === undefined) continue;\n if (matchCriteriaEqual(fixture.match, sibling.match)) {\n this.fixtureMatchCounts.set(sibling, this.getFixtureMatchCount(sibling) + 1);\n }\n }\n }\n }\n\n clearMatchCounts(): void {\n this.fixtureMatchCounts.clear();\n }\n\n clear(): void {\n this.entries = [];\n this.fixtureMatchCounts.clear();\n }\n\n get size(): number {\n return this.entries.length;\n }\n}\n"],"mappings":";;;;;;AAMA,SAAS,WAAW,GAAY,GAAqB;AACnD,KAAI,aAAa,UAAU,aAAa,OACtC,QAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;AAChD,QAAO,MAAM;;;;;;AAOf,SAAS,mBAAmB,GAAiB,GAA0B;AACrE,QACE,WAAW,EAAE,aAAa,EAAE,YAAY,IACxC,WAAW,EAAE,WAAW,EAAE,UAAU,IACpC,WAAW,EAAE,YAAY,EAAE,WAAW,IACtC,WAAW,EAAE,UAAU,EAAE,SAAS,IAClC,WAAW,EAAE,OAAO,EAAE,MAAM,IAC5B,WAAW,EAAE,gBAAgB,EAAE,eAAe,IAC9C,WAAW,EAAE,WAAW,EAAE,UAAU;;AAIxC,IAAa,UAAb,MAAqB;CACnB,AAAQ,UAA0B,EAAE;CACpC,AAAS,qCAA2C,IAAI,KAAK;CAE7D,IAAI,OAA6D;EAC/D,MAAM,OAAqB;GACzB,IAAI,WAAW,MAAM;GACrB,WAAW,KAAK,KAAK;GACrB,GAAG;GACJ;AACD,OAAK,QAAQ,KAAK,KAAK;AACvB,SAAO;;CAGT,OAAO,MAA2C;AAChD,MAAI,MAAM,UAAU,OAClB,QAAO,KAAK,QAAQ,MAAM,CAAC,KAAK,MAAM;AAExC,SAAO,KAAK,QAAQ,OAAO;;CAG7B,UAA+B;AAC7B,SAAO,KAAK,QAAQ,SAAS,IAAI,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK;;CAG3E,cAAc,SAAkC;AAC9C,SAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,SAAS,YAAY,QAAQ;;CAGnE,qBAAqB,SAA0B;AAC7C,SAAO,KAAK,mBAAmB,IAAI,QAAQ,IAAI;;CAGjD,2BAA2B,SAAkB,aAAwC;AACnF,OAAK,mBAAmB,IAAI,SAAS,KAAK,qBAAqB,QAAQ,GAAG,EAAE;AAE5E,MAAI,QAAQ,MAAM,kBAAkB,UAAa,YAC/C,MAAK,MAAM,WAAW,aAAa;AACjC,OAAI,YAAY,QAAS;AACzB,OAAI,QAAQ,MAAM,kBAAkB,OAAW;AAC/C,OAAI,mBAAmB,QAAQ,OAAO,QAAQ,MAAM,CAClD,MAAK,mBAAmB,IAAI,SAAS,KAAK,qBAAqB,QAAQ,GAAG,EAAE;;;CAMpF,mBAAyB;AACvB,OAAK,mBAAmB,OAAO;;CAGjC,QAAc;AACZ,OAAK,UAAU,EAAE;AACjB,OAAK,mBAAmB,OAAO;;CAGjC,IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ"}
1
+ {"version":3,"file":"journal.js","names":[],"sources":["../src/journal.ts"],"sourcesContent":["import { generateId } from \"./helpers.js\";\nimport type { Fixture, FixtureMatch, JournalEntry } from \"./types.js\";\n\n/** Sentinel testId used when no explicit test scope is provided. */\nexport const DEFAULT_TEST_ID = \"__default__\";\n\n/**\n * Compare two field values, handling RegExp by source+flags rather than reference.\n */\nfunction fieldEqual(a: unknown, b: unknown): boolean {\n if (a instanceof RegExp && b instanceof RegExp)\n return a.source === b.source && a.flags === b.flags;\n return a === b;\n}\n\n/**\n * Check whether two fixture match objects have the same criteria\n * (ignoring sequenceIndex). Used to group sequenced fixtures.\n */\nfunction matchCriteriaEqual(a: FixtureMatch, b: FixtureMatch): boolean {\n return (\n fieldEqual(a.userMessage, b.userMessage) &&\n fieldEqual(a.inputText, b.inputText) &&\n fieldEqual(a.toolCallId, b.toolCallId) &&\n fieldEqual(a.toolName, b.toolName) &&\n fieldEqual(a.model, b.model) &&\n fieldEqual(a.responseFormat, b.responseFormat) &&\n fieldEqual(a.predicate, b.predicate)\n );\n}\n\nexport class Journal {\n private entries: JournalEntry[] = [];\n private readonly fixtureMatchCountsByTestId: Map<string, Map<Fixture, number>> = new Map();\n\n /** Backwards-compatible accessor — returns the default (no testId) count map. */\n get fixtureMatchCounts(): Map<Fixture, number> {\n return this.getFixtureMatchCountsForTest(DEFAULT_TEST_ID);\n }\n\n add(entry: Omit<JournalEntry, \"id\" | \"timestamp\">): JournalEntry {\n const full: JournalEntry = {\n id: generateId(\"req\"),\n timestamp: Date.now(),\n ...entry,\n };\n this.entries.push(full);\n return full;\n }\n\n getAll(opts?: { limit?: number }): JournalEntry[] {\n if (opts?.limit !== undefined) {\n return this.entries.slice(-opts.limit);\n }\n return this.entries.slice();\n }\n\n getLast(): JournalEntry | null {\n return this.entries.length > 0 ? this.entries[this.entries.length - 1] : null;\n }\n\n findByFixture(fixture: Fixture): JournalEntry[] {\n return this.entries.filter((e) => e.response.fixture === fixture);\n }\n\n getFixtureMatchCountsForTest(testId: string): Map<Fixture, number> {\n let counts = this.fixtureMatchCountsByTestId.get(testId);\n if (!counts) {\n counts = new Map();\n this.fixtureMatchCountsByTestId.set(testId, counts);\n }\n return counts;\n }\n\n getFixtureMatchCount(fixture: Fixture, testId = DEFAULT_TEST_ID): number {\n return this.getFixtureMatchCountsForTest(testId).get(fixture) ?? 0;\n }\n\n incrementFixtureMatchCount(\n fixture: Fixture,\n allFixtures?: readonly Fixture[],\n testId = DEFAULT_TEST_ID,\n ): void {\n const counts = this.getFixtureMatchCountsForTest(testId);\n counts.set(fixture, (counts.get(fixture) ?? 0) + 1);\n // When a sequenced fixture matches, also increment all siblings with matching criteria\n if (fixture.match.sequenceIndex !== undefined && allFixtures) {\n for (const sibling of allFixtures) {\n if (sibling === fixture) continue;\n if (sibling.match.sequenceIndex === undefined) continue;\n if (matchCriteriaEqual(fixture.match, sibling.match)) {\n counts.set(sibling, (counts.get(sibling) ?? 0) + 1);\n }\n }\n }\n }\n\n clearMatchCounts(testId?: string): void {\n if (testId !== undefined) {\n this.fixtureMatchCountsByTestId.delete(testId);\n } else {\n this.fixtureMatchCountsByTestId.clear();\n }\n }\n\n clear(): void {\n this.entries = [];\n this.fixtureMatchCountsByTestId.clear();\n }\n\n get size(): number {\n return this.entries.length;\n }\n}\n"],"mappings":";;;;AAIA,MAAa,kBAAkB;;;;AAK/B,SAAS,WAAW,GAAY,GAAqB;AACnD,KAAI,aAAa,UAAU,aAAa,OACtC,QAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE;AAChD,QAAO,MAAM;;;;;;AAOf,SAAS,mBAAmB,GAAiB,GAA0B;AACrE,QACE,WAAW,EAAE,aAAa,EAAE,YAAY,IACxC,WAAW,EAAE,WAAW,EAAE,UAAU,IACpC,WAAW,EAAE,YAAY,EAAE,WAAW,IACtC,WAAW,EAAE,UAAU,EAAE,SAAS,IAClC,WAAW,EAAE,OAAO,EAAE,MAAM,IAC5B,WAAW,EAAE,gBAAgB,EAAE,eAAe,IAC9C,WAAW,EAAE,WAAW,EAAE,UAAU;;AAIxC,IAAa,UAAb,MAAqB;CACnB,AAAQ,UAA0B,EAAE;CACpC,AAAiB,6CAAgE,IAAI,KAA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AAO;MAE9C,MAAK,2BAA2B,OAAO;;CAI3C,QAAc;AACZ,OAAK,UAAU,EAAE;AACjB,OAAK,2BAA2B,OAAO;;CAGzC,IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ"}
package/dist/llmock.cjs CHANGED
@@ -150,8 +150,8 @@ var LLMock = class LLMock {
150
150
  clearRequests() {
151
151
  this.journal.clear();
152
152
  }
153
- resetMatchCounts() {
154
- if (this.serverInstance) this.serverInstance.journal.clearMatchCounts();
153
+ resetMatchCounts(testId) {
154
+ if (this.serverInstance) this.serverInstance.journal.clearMatchCounts(testId);
155
155
  return this;
156
156
  }
157
157
  setChaos(config) {
@@ -1 +1 @@
1
- {"version":3,"file":"llmock.cjs","names":["loadFixtureFile","loadFixturesFromDir","entryToFixture","validateFixtures","createServer"],"sources":["../src/llmock.ts"],"sourcesContent":["import type {\n ChaosConfig,\n EmbeddingFixtureOpts,\n Fixture,\n FixtureFileEntry,\n FixtureMatch,\n FixtureOpts,\n FixtureResponse,\n MockServerOptions,\n Mountable,\n RecordConfig,\n} from \"./types.js\";\nimport { createServer, type ServerInstance } from \"./server.js\";\nimport {\n loadFixtureFile,\n loadFixturesFromDir,\n entryToFixture,\n validateFixtures,\n} from \"./fixture-loader.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n\n constructor(options?: MockServerOptions) {\n this.options = options ?? {};\n }\n\n // ---- Fixture management ----\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(fixture);\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures);\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(fixture);\n return this;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n loadFixtureFile(filePath: string): this {\n this.fixtures.push(...loadFixtureFile(filePath));\n return this;\n }\n\n loadFixtureDir(dirPath: string): this {\n this.fixtures.push(...loadFixturesFromDir(dirPath));\n return this;\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n const entries: FixtureFileEntry[] = typeof input === \"string\" ? JSON.parse(input) : input;\n const converted = entries.map(entryToFixture);\n const issues = validateFixtures(converted);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Uses length = 0 to preserve array reference identity — the running\n // server reads this same array on every request.\n clearFixtures(): this {\n this.fixtures.length = 0;\n return this;\n }\n\n // ---- Convenience ----\n\n on(match: FixtureMatch, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.addFixture({\n match,\n response,\n ...opts,\n });\n }\n\n onMessage(pattern: string | RegExp, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureResponse,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(name: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(id: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * with a `predicate` that always matches (so it fires first) and spliced\n * at the front of the fixture list.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n const errorResponse: FixtureResponse = {\n error: {\n message: errorBody?.message ?? \"Injected error\",\n type: errorBody?.type ?? \"server_error\",\n code: errorBody?.code,\n },\n status,\n };\n const fixture: Fixture = {\n match: { predicate: () => true },\n response: errorResponse,\n };\n // Insert at front so it matches before everything else\n this.fixtures.unshift(fixture);\n // Remove after first match — the journal records it so tests can assert\n const original = fixture.match.predicate!;\n fixture.match.predicate = (req) => {\n const result = original(req);\n if (result) {\n // Defer splice so it doesn't mutate the array while matchFixture iterates it\n queueMicrotask(() => {\n const idx = this.fixtures.indexOf(fixture);\n if (idx !== -1) this.fixtures.splice(idx, 1);\n });\n }\n return result;\n };\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, and baseUrl immediately\n // so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n clearRequests(): void {\n this.journal.clear();\n }\n\n resetMatchCounts(): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts();\n }\n return this;\n }\n\n // ---- Chaos ----\n\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n return this;\n }\n\n clearChaos(): this {\n delete this.options.chaos;\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n reset(): this {\n this.clearFixtures();\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n if (this.serverInstance) {\n this.serverInstance.journal.clear();\n }\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n this.serverInstance = await createServer(this.fixtures, this.options, this.mounts, {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n });\n return this.serverInstance.url;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance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AC1B,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;EAEvC,MAAM,EAAE,WAAW,KAAK;AACxB,QAAM,IAAI,SAAe,SAAS,WAAW;AAC3C,UAAO,OAAO,QAA4B,MAAM,OAAO,IAAI,GAAG,SAAS,CAAE;IACzE;AACF,OAAK,iBAAiB;;CAKxB,IAAI,UAAmB;AACrB,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAO,KAAK,eAAe;;CAG7B,IAAI,MAAc;AAChB,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAO,KAAK,eAAe;;CAG7B,IAAI,UAAkB;AACpB,SAAO,KAAK;;CAGd,IAAI,OAAe;EACjB,MAAM,SAAS,IAAI,IAAI,KAAK,IAAI;AAChC,MAAI,CAAC,OAAO,KACV,OAAM,IAAI,MAAM,oCAAoC,KAAK,MAAM;AAEjE,SAAO,SAAS,OAAO,MAAM,GAAG;;CAKlC,aAAa,OAAO,SAA8C;EAChE,MAAM,WAAW,IAAI,OAAO,QAAQ;AACpC,QAAM,SAAS,OAAO;AACtB,SAAO"}
1
+ {"version":3,"file":"llmock.cjs","names":["loadFixtureFile","loadFixturesFromDir","entryToFixture","validateFixtures","createServer"],"sources":["../src/llmock.ts"],"sourcesContent":["import type {\n ChaosConfig,\n EmbeddingFixtureOpts,\n Fixture,\n FixtureFileEntry,\n FixtureMatch,\n FixtureOpts,\n FixtureResponse,\n MockServerOptions,\n Mountable,\n RecordConfig,\n} from \"./types.js\";\nimport { createServer, type ServerInstance } from \"./server.js\";\nimport {\n loadFixtureFile,\n loadFixturesFromDir,\n entryToFixture,\n validateFixtures,\n} from \"./fixture-loader.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n\n constructor(options?: MockServerOptions) {\n this.options = options ?? {};\n }\n\n // ---- Fixture management ----\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(fixture);\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures);\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(fixture);\n return this;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n loadFixtureFile(filePath: string): this {\n this.fixtures.push(...loadFixtureFile(filePath));\n return this;\n }\n\n loadFixtureDir(dirPath: string): this {\n this.fixtures.push(...loadFixturesFromDir(dirPath));\n return this;\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n const entries: FixtureFileEntry[] = typeof input === \"string\" ? JSON.parse(input) : input;\n const converted = entries.map(entryToFixture);\n const issues = validateFixtures(converted);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Uses length = 0 to preserve array reference identity — the running\n // server reads this same array on every request.\n clearFixtures(): this {\n this.fixtures.length = 0;\n return this;\n }\n\n // ---- Convenience ----\n\n on(match: FixtureMatch, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.addFixture({\n match,\n response,\n ...opts,\n });\n }\n\n onMessage(pattern: string | RegExp, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureResponse,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(name: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(id: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * with a `predicate` that always matches (so it fires first) and spliced\n * at the front of the fixture list.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n const errorResponse: FixtureResponse = {\n error: {\n message: errorBody?.message ?? \"Injected error\",\n type: errorBody?.type ?? \"server_error\",\n code: errorBody?.code,\n },\n status,\n };\n const fixture: Fixture = {\n match: { predicate: () => true },\n response: errorResponse,\n };\n // Insert at front so it matches before everything else\n this.fixtures.unshift(fixture);\n // Remove after first match — the journal records it so tests can assert\n const original = fixture.match.predicate!;\n fixture.match.predicate = (req) => {\n const result = original(req);\n if (result) {\n // Defer splice so it doesn't mutate the array while matchFixture iterates it\n queueMicrotask(() => {\n const idx = this.fixtures.indexOf(fixture);\n if (idx !== -1) this.fixtures.splice(idx, 1);\n });\n }\n return result;\n };\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, and baseUrl immediately\n // so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n clearRequests(): void {\n this.journal.clear();\n }\n\n resetMatchCounts(testId?: string): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts(testId);\n }\n return this;\n }\n\n // ---- Chaos ----\n\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n return this;\n }\n\n clearChaos(): this {\n delete this.options.chaos;\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n reset(): this {\n this.clearFixtures();\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n if (this.serverInstance) {\n this.serverInstance.journal.clear();\n }\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n this.serverInstance = await createServer(this.fixtures, this.options, this.mounts, {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n });\n return this.serverInstance.url;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n"],"mappings":";;;;AAwBA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;CAChE,AAAQ,iBAAwC;CAChD,AAAQ;CAER,YAAY,SAA6B;AACvC,OAAK,UAAU,WAAW,EAAE;;CAK9B,WAAW,SAAwB;AACjC,OAAK,SAAS,KAAK,QAAQ;AAC3B,SAAO;;CAGT,YAAY,UAA2B;AACrC,OAAK,SAAS,KAAK,GAAG,SAAS;AAC/B,SAAO;;CAGT,eAAe,SAAwB;AACrC,OAAK,SAAS,QAAQ,QAAQ;AAC9B,SAAO;;CAGT,cAAkC;AAChC,SAAO,KAAK;;CAGd,gBAAgB,UAAwB;AACtC,OAAK,SAAS,KAAK,GAAGA,uCAAgB,SAAS,CAAC;AAChD,SAAO;;CAGT,eAAe,SAAuB;AACpC,OAAK,SAAS,KAAK,GAAGC,2CAAoB,QAAQ,CAAC;AACnD,SAAO;;;;;;CAOT,oBAAoB,OAA0C;EAE5D,MAAM,aAD8B,OAAO,UAAU,WAAW,KAAK,MAAM,MAAM,GAAG,OAC1D,IAAIC,sCAAe;EAE7C,MAAM,SADSC,wCAAiB,UAAU,CACpB,QAAQ,MAAM,EAAE,aAAa,QAAQ;AAC3D,MAAI,OAAO,SAA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AAmB,SAAS;AACjC,MAAI,KAAK,eACP,MAAK,eAAe,QAAQ,OAAO;AAErC,SAAO;;CAKT,MAAM,QAAyB;AAC7B,MAAI,KAAK,eACP,OAAM,IAAI,MAAM,yBAAyB;AAE3C,OAAK,iBAAiB,MAAMC,4BAAa,KAAK,UAAU,KAAK,SAAS,KAAK,QAAQ;GACjF,QAAQ,KAAK;GACb,QAAQ,KAAK;GACb,YAAY,KAAK;GAClB,CAAC;AACF,SAAO,KAAK,eAAe;;CAG7B,MAAM,OAAsB;AAC1B,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;EAEvC,MAAM,EAAE,WAAW,KAAK;AACxB,QAAM,IAAI,SAAe,SAAS,WAAW;AAC3C,UAAO,OAAO,QAA4B,MAAM,OAAO,IAAI,GAAG,SAAS,CAAE;IACzE;AACF,OAAK,iBAAiB;;CAKxB,IAAI,UAAmB;AACrB,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAO,KAAK,eAAe;;CAG7B,IAAI,MAAc;AAChB,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAO,KAAK,eAAe;;CAG7B,IAAI,UAAkB;AACpB,SAAO,KAAK;;CAGd,IAAI,OAAe;EACjB,MAAM,SAAS,IAAI,IAAI,KAAK,IAAI;AAChC,MAAI,CAAC,OAAO,KACV,OAAM,IAAI,MAAM,oCAAoC,KAAK,MAAM;AAEjE,SAAO,SAAS,OAAO,MAAM,GAAG;;CAKlC,aAAa,OAAO,SAA8C;EAChE,MAAM,WAAW,IAAI,OAAO,QAAQ;AACpC,QAAM,SAAS,OAAO;AACtB,SAAO"}
package/dist/llmock.d.cts CHANGED
@@ -50,7 +50,7 @@ declare class LLMock {
50
50
  getRequests(): JournalEntry[];
51
51
  getLastRequest(): JournalEntry | null;
52
52
  clearRequests(): void;
53
- resetMatchCounts(): this;
53
+ resetMatchCounts(testId?: string): this;
54
54
  setChaos(config: ChaosConfig): this;
55
55
  clearChaos(): this;
56
56
  enableRecording(config: RecordConfig): this;
package/dist/llmock.d.ts CHANGED
@@ -50,7 +50,7 @@ declare class LLMock {
50
50
  getRequests(): JournalEntry[];
51
51
  getLastRequest(): JournalEntry | null;
52
52
  clearRequests(): void;
53
- resetMatchCounts(): this;
53
+ resetMatchCounts(testId?: string): this;
54
54
  setChaos(config: ChaosConfig): this;
55
55
  clearChaos(): this;
56
56
  enableRecording(config: RecordConfig): this;
package/dist/llmock.js CHANGED
@@ -150,8 +150,8 @@ var LLMock = class LLMock {
150
150
  clearRequests() {
151
151
  this.journal.clear();
152
152
  }
153
- resetMatchCounts() {
154
- if (this.serverInstance) this.serverInstance.journal.clearMatchCounts();
153
+ resetMatchCounts(testId) {
154
+ if (this.serverInstance) this.serverInstance.journal.clearMatchCounts(testId);
155
155
  return this;
156
156
  }
157
157
  setChaos(config) {
@@ -1 +1 @@
1
- {"version":3,"file":"llmock.js","names":[],"sources":["../src/llmock.ts"],"sourcesContent":["import type {\n ChaosConfig,\n EmbeddingFixtureOpts,\n Fixture,\n FixtureFileEntry,\n FixtureMatch,\n FixtureOpts,\n FixtureResponse,\n MockServerOptions,\n Mountable,\n RecordConfig,\n} from \"./types.js\";\nimport { createServer, type ServerInstance } from \"./server.js\";\nimport {\n loadFixtureFile,\n loadFixturesFromDir,\n entryToFixture,\n validateFixtures,\n} from \"./fixture-loader.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n\n constructor(options?: MockServerOptions) {\n this.options = options ?? {};\n }\n\n // ---- Fixture management ----\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(fixture);\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures);\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(fixture);\n return this;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n loadFixtureFile(filePath: string): this {\n this.fixtures.push(...loadFixtureFile(filePath));\n return this;\n }\n\n loadFixtureDir(dirPath: string): this {\n this.fixtures.push(...loadFixturesFromDir(dirPath));\n return this;\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n const entries: FixtureFileEntry[] = typeof input === \"string\" ? JSON.parse(input) : input;\n const converted = entries.map(entryToFixture);\n const issues = validateFixtures(converted);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Uses length = 0 to preserve array reference identity — the running\n // server reads this same array on every request.\n clearFixtures(): this {\n this.fixtures.length = 0;\n return this;\n }\n\n // ---- Convenience ----\n\n on(match: FixtureMatch, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.addFixture({\n match,\n response,\n ...opts,\n });\n }\n\n onMessage(pattern: string | RegExp, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureResponse,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(name: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(id: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * with a `predicate` that always matches (so it fires first) and spliced\n * at the front of the fixture list.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n const errorResponse: FixtureResponse = {\n error: {\n message: errorBody?.message ?? \"Injected error\",\n type: errorBody?.type ?? \"server_error\",\n code: errorBody?.code,\n },\n status,\n };\n const fixture: Fixture = {\n match: { predicate: () => true },\n response: errorResponse,\n };\n // Insert at front so it matches before everything else\n this.fixtures.unshift(fixture);\n // Remove after first match — the journal records it so tests can assert\n const original = fixture.match.predicate!;\n fixture.match.predicate = (req) => {\n const result = original(req);\n if (result) {\n // Defer splice so it doesn't mutate the array while matchFixture iterates it\n queueMicrotask(() => {\n const idx = this.fixtures.indexOf(fixture);\n if (idx !== -1) this.fixtures.splice(idx, 1);\n });\n }\n return result;\n };\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, and baseUrl immediately\n // so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n clearRequests(): void {\n this.journal.clear();\n }\n\n resetMatchCounts(): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts();\n }\n return this;\n }\n\n // ---- Chaos ----\n\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n return this;\n }\n\n clearChaos(): this {\n delete this.options.chaos;\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n reset(): this {\n this.clearFixtures();\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n if (this.serverInstance) {\n this.serverInstance.journal.clear();\n }\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n this.serverInstance = await createServer(this.fixtures, this.options, this.mounts, {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n });\n return this.serverInstance.url;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n"],"mappings":";;;;AAwBA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;CAChE,AAAQ,iBAAwC;CAChD,AAAQ;CAER,YAAY,SAA6B;AACvC,OAAK,UAAU,WAAW,EAAE;;CAK9B,WAAW,SAAwB;AACjC,OAAK,SAAS,KAAK,QAAQ;AAC3B,SAAO;;CAGT,YAAY,UAA2B;AACrC,OAAK,SAAS,KAAK,GAAG,SAAS;AAC/B,SAAO;;CAGT,eAAe,SAAwB;AACrC,OAAK,SAAS,QAAQ,QAAQ;AAC9B,SAAO;;CAGT,cAAkC;AAChC,SAAO,KAAK;;CAGd,gBAAgB,UAAwB;AACtC,OAAK,SAAS,KAAK,GAAG,gBAAgB,SAAS,CAAC;AAChD,SAAO;;CAGT,eAAe,SAAuB;AACpC,OAAK,SAAS,KAAK,GAAG,oBAAoB,QAAQ,CAAC;AACnD,SAAO;;;;;;CAOT,oBAAoB,OAA0C;EAE5D,MAAM,aAD8B,OAAO,UAAU,WAAW,KAAK,MAAM,MAAM,GAAG,OAC1D,IAAI,eAAe;EAE7C,MAAM,SADS,iBAAiB,UAAU,CACpB,QAAQ,MAAM,EAAE,aAAa,QAAQ;AAC3D,MAAI,OAAO,SAAS,EAClB,OAAM,IAAI,MAAM,8BAA8B,KAAK,UAAU,OAAO,GAAG;AAEzE,OAAK,SAAS,KAAK,GAAG,UAAU;AAChC,SAAO;;CAKT,gBAAsB;AACpB,OAAK,SAAS,SAAS;AACvB,SAAO;;CAKT,GAAG,OAAqB,UAA2B,MAA0B;AAC3E,SAAO,KAAK,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KAAK;GACb,QAAQ,KAAK;GACb,YAAY,KAAK;GAClB,CAAC;AACF,SAAO,KAAK,eAAe;;CAG7B,MAAM,OAAsB;AAC1B,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;EAEvC,MAAM,EAAE,WAAW,KAAK;AACxB,QAAM,IAAI,SAAe,SAAS,WAAW;AAC3C,UAAO,OAAO,QAA4B,MAAM,OAAO,IAAI,GAAG,SAAS,CAAE;IACzE;AACF,OAAK,iBAAiB;;CAKxB,IAAI,UAAmB;AACrB,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAO,KAAK,eAAe;;CAG7B,IAAI,MAAc;AAChB,MAAI,CAAC,KAAK,eACR,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAO,KAAK,eAAe;;CAG7B,IAAI,UAAkB;AACpB,SAAO,KAAK;;CAGd,IAAI,OAAe;EACjB,MAAM,SAAS,IAAI,IAAI,KAAK,IAAI;AAChC,MAAI,CAAC,OAAO,KACV,OAAM,IAAI,MAAM,oCAAoC,KAAK,MAAM;AAEjE,SAAO,SAAS,OAAO,MAAM,GAAG;;CAKlC,aAAa,OAAO,SAA8C;EAChE,MAAM,WAAW,IAAI,OAAO,QAAQ;AACpC,QAAM,SAAS,OAAO;AACtB,SAAO"}
1
+ {"version":3,"file":"llmock.js","names":[],"sources":["../src/llmock.ts"],"sourcesContent":["import type {\n ChaosConfig,\n EmbeddingFixtureOpts,\n Fixture,\n FixtureFileEntry,\n FixtureMatch,\n FixtureOpts,\n FixtureResponse,\n MockServerOptions,\n Mountable,\n RecordConfig,\n} from \"./types.js\";\nimport { createServer, type ServerInstance } from \"./server.js\";\nimport {\n loadFixtureFile,\n loadFixturesFromDir,\n entryToFixture,\n validateFixtures,\n} from \"./fixture-loader.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n\n constructor(options?: MockServerOptions) {\n this.options = options ?? {};\n }\n\n // ---- Fixture management ----\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(fixture);\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures);\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(fixture);\n return this;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n loadFixtureFile(filePath: string): this {\n this.fixtures.push(...loadFixtureFile(filePath));\n return this;\n }\n\n loadFixtureDir(dirPath: string): this {\n this.fixtures.push(...loadFixturesFromDir(dirPath));\n return this;\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n const entries: FixtureFileEntry[] = typeof input === \"string\" ? JSON.parse(input) : input;\n const converted = entries.map(entryToFixture);\n const issues = validateFixtures(converted);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Uses length = 0 to preserve array reference identity — the running\n // server reads this same array on every request.\n clearFixtures(): this {\n this.fixtures.length = 0;\n return this;\n }\n\n // ---- Convenience ----\n\n on(match: FixtureMatch, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.addFixture({\n match,\n response,\n ...opts,\n });\n }\n\n onMessage(pattern: string | RegExp, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureResponse,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(name: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(id: string, response: FixtureResponse, opts?: FixtureOpts): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * with a `predicate` that always matches (so it fires first) and spliced\n * at the front of the fixture list.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n const errorResponse: FixtureResponse = {\n error: {\n message: errorBody?.message ?? \"Injected error\",\n type: errorBody?.type ?? \"server_error\",\n code: errorBody?.code,\n },\n status,\n };\n const fixture: Fixture = {\n match: { predicate: () => true },\n response: errorResponse,\n };\n // Insert at front so it matches before everything else\n this.fixtures.unshift(fixture);\n // Remove after first match — the journal records it so tests can assert\n const original = fixture.match.predicate!;\n fixture.match.predicate = (req) => {\n const result = original(req);\n if (result) {\n // Defer splice so it doesn't mutate the array while matchFixture iterates it\n queueMicrotask(() => {\n const idx = this.fixtures.indexOf(fixture);\n if (idx !== -1) this.fixtures.splice(idx, 1);\n });\n }\n return result;\n };\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, and baseUrl immediately\n // so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n clearRequests(): void {\n this.journal.clear();\n }\n\n resetMatchCounts(testId?: string): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts(testId);\n }\n return this;\n }\n\n // ---- Chaos ----\n\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n return this;\n }\n\n clearChaos(): this {\n delete this.options.chaos;\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n reset(): this {\n this.clearFixtures();\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n if (this.serverInstance) {\n this.serverInstance.journal.clear();\n }\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n this.serverInstance = await createServer(this.fixtures, this.options, this.mounts, {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n });\n return this.serverInstance.url;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n"],"mappings":";;;;AAwBA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;CAChE,AAAQ,iBAAwC;CAChD,AAAQ;CAER,YAAY,SAA6B;AACvC,OAAK,UAAU,WAAW,EAAE;;CAK9B,WAAW,SAAwB;AACjC,OAAK,SAAS,KAAK,QAAQ;AAC3B,SAAO;;CAGT,YAAY,UAA2B;AACrC,OAAK,SAAS,KAAK,GAAG,SAAS;AAC/B,SAAO;;CAGT,eAAe,SAAwB;AACrC,OAAK,SAAS,QAAQ,QAAQ;AAC9B,SAAO;;CAGT,cAAkC;AAChC,SAAO,KAAK;;CAGd,gBAAgB,UAAwB;AACtC,OAAK,SAAS,KAAK,GAAG,gBAAgB,SAAS,CAAC;AAChD,SAAO;;CAGT,eAAe,SAAuB;AACpC,OAAK,SAAS,KAAK,GAAG,oBAAoB,QAAQ,CAAC;AACnD,SAAO;;;;;;CAOT,oBAAoB,OAA0C;EAE5D,MAAM,aAD8B,OAAO,UAAU,WAAW,KAAK,MAAM,MAAM,GAAG,OAC1D,IAAI,eAAe;EAE7C,MAAM,SADS,iBAAiB,UAAU,CACpB,QAAQ,MAA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