@agentforge/testing 0.16.19 → 0.16.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -673,6 +673,20 @@ declare class ConversationSimulator {
673
673
  */
674
674
  declare function createConversationSimulator(agent: any, config?: ConversationSimulatorConfig): ConversationSimulator;
675
675
 
676
+ type SnapshotObject = Record<string, unknown>;
677
+ interface SnapshotDiff {
678
+ added: SnapshotObject;
679
+ removed: SnapshotObject;
680
+ changed: Record<string, {
681
+ from: unknown;
682
+ to: unknown;
683
+ }>;
684
+ }
685
+ interface MessageSnapshot {
686
+ type: string;
687
+ content: unknown;
688
+ }
689
+ declare const ROOT_SNAPSHOT_DIFF_KEY = "$root";
676
690
  /**
677
691
  * Snapshot configuration
678
692
  */
@@ -696,20 +710,20 @@ interface SnapshotConfig {
696
710
  /**
697
711
  * Custom normalizer function
698
712
  */
699
- normalizer?: (value: any) => any;
713
+ normalizer?: (value: unknown) => unknown;
700
714
  }
701
715
  /**
702
716
  * Create a snapshot of state
703
717
  */
704
- declare function createSnapshot(state: any, config?: SnapshotConfig): any;
718
+ declare function createSnapshot<TState = unknown>(state: TState, config?: SnapshotConfig): unknown;
705
719
  /**
706
720
  * Assert that state matches snapshot
707
721
  */
708
- declare function assertMatchesSnapshot(state: any, config?: SnapshotConfig): void;
722
+ declare function assertMatchesSnapshot<TState = unknown>(state: TState, config?: SnapshotConfig): void;
709
723
  /**
710
724
  * Create a snapshot of messages
711
725
  */
712
- declare function createMessageSnapshot(messages: BaseMessage[], config?: SnapshotConfig): any;
726
+ declare function createMessageSnapshot(messages: BaseMessage[], config?: SnapshotConfig): MessageSnapshot[];
713
727
  /**
714
728
  * Assert that messages match snapshot
715
729
  */
@@ -717,14 +731,14 @@ declare function assertMessagesMatchSnapshot(messages: BaseMessage[], config?: S
717
731
  /**
718
732
  * Compare two states for equality
719
733
  */
720
- declare function compareStates(state1: any, state2: any, config?: SnapshotConfig): boolean;
734
+ declare function compareStates<TState1 = unknown, TState2 = unknown>(state1: TState1, state2: TState2, config?: SnapshotConfig): boolean;
721
735
  /**
722
736
  * Create a diff between two states
723
737
  */
724
- declare function createStateDiff(state1: any, state2: any, config?: SnapshotConfig): any;
738
+ declare function createStateDiff<TState1 = unknown, TState2 = unknown>(state1: TState1, state2: TState2, config?: SnapshotConfig): SnapshotDiff;
725
739
  /**
726
740
  * Assert that state has changed
727
741
  */
728
- declare function assertStateChanged(stateBefore: any, stateAfter: any, expectedChanges: string[], config?: SnapshotConfig): void;
742
+ declare function assertStateChanged<TStateBefore = unknown, TStateAfter = unknown>(stateBefore: TStateBefore, stateAfter: TStateAfter, expectedChanges: string[], config?: SnapshotConfig): void;
729
743
 
730
- export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type AssertedMessage, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, MockLLM, type MockLLMConfig, type MockToolConfig, type PlanningStep, type PlanningTestState, type ReActTestState, type SnapshotConfig, StateBuilder, type TestToolCall, type TestToolResult, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
744
+ export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type AssertedMessage, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, type MessageSnapshot, MockLLM, type MockLLMConfig, type MockToolConfig, type PlanningStep, type PlanningTestState, ROOT_SNAPSHOT_DIFF_KEY, type ReActTestState, type SnapshotConfig, type SnapshotDiff, type SnapshotObject, StateBuilder, type TestToolCall, type TestToolResult, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
package/dist/index.d.ts CHANGED
@@ -673,6 +673,20 @@ declare class ConversationSimulator {
673
673
  */
674
674
  declare function createConversationSimulator(agent: any, config?: ConversationSimulatorConfig): ConversationSimulator;
675
675
 
676
+ type SnapshotObject = Record<string, unknown>;
677
+ interface SnapshotDiff {
678
+ added: SnapshotObject;
679
+ removed: SnapshotObject;
680
+ changed: Record<string, {
681
+ from: unknown;
682
+ to: unknown;
683
+ }>;
684
+ }
685
+ interface MessageSnapshot {
686
+ type: string;
687
+ content: unknown;
688
+ }
689
+ declare const ROOT_SNAPSHOT_DIFF_KEY = "$root";
676
690
  /**
677
691
  * Snapshot configuration
678
692
  */
@@ -696,20 +710,20 @@ interface SnapshotConfig {
696
710
  /**
697
711
  * Custom normalizer function
698
712
  */
699
- normalizer?: (value: any) => any;
713
+ normalizer?: (value: unknown) => unknown;
700
714
  }
701
715
  /**
702
716
  * Create a snapshot of state
703
717
  */
704
- declare function createSnapshot(state: any, config?: SnapshotConfig): any;
718
+ declare function createSnapshot<TState = unknown>(state: TState, config?: SnapshotConfig): unknown;
705
719
  /**
706
720
  * Assert that state matches snapshot
707
721
  */
708
- declare function assertMatchesSnapshot(state: any, config?: SnapshotConfig): void;
722
+ declare function assertMatchesSnapshot<TState = unknown>(state: TState, config?: SnapshotConfig): void;
709
723
  /**
710
724
  * Create a snapshot of messages
711
725
  */
712
- declare function createMessageSnapshot(messages: BaseMessage[], config?: SnapshotConfig): any;
726
+ declare function createMessageSnapshot(messages: BaseMessage[], config?: SnapshotConfig): MessageSnapshot[];
713
727
  /**
714
728
  * Assert that messages match snapshot
715
729
  */
@@ -717,14 +731,14 @@ declare function assertMessagesMatchSnapshot(messages: BaseMessage[], config?: S
717
731
  /**
718
732
  * Compare two states for equality
719
733
  */
720
- declare function compareStates(state1: any, state2: any, config?: SnapshotConfig): boolean;
734
+ declare function compareStates<TState1 = unknown, TState2 = unknown>(state1: TState1, state2: TState2, config?: SnapshotConfig): boolean;
721
735
  /**
722
736
  * Create a diff between two states
723
737
  */
724
- declare function createStateDiff(state1: any, state2: any, config?: SnapshotConfig): any;
738
+ declare function createStateDiff<TState1 = unknown, TState2 = unknown>(state1: TState1, state2: TState2, config?: SnapshotConfig): SnapshotDiff;
725
739
  /**
726
740
  * Assert that state has changed
727
741
  */
728
- declare function assertStateChanged(stateBefore: any, stateAfter: any, expectedChanges: string[], config?: SnapshotConfig): void;
742
+ declare function assertStateChanged<TStateBefore = unknown, TStateAfter = unknown>(stateBefore: TStateBefore, stateAfter: TStateAfter, expectedChanges: string[], config?: SnapshotConfig): void;
729
743
 
730
- export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type AssertedMessage, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, MockLLM, type MockLLMConfig, type MockToolConfig, type PlanningStep, type PlanningTestState, type ReActTestState, type SnapshotConfig, StateBuilder, type TestToolCall, type TestToolResult, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
744
+ export { type AgentTestConfig, type AgentTestResult, AgentTestRunner, type AssertedMessage, type ConversationResult, ConversationSimulator, type ConversationSimulatorConfig, type MessageSnapshot, MockLLM, type MockLLMConfig, type MockToolConfig, type PlanningStep, type PlanningTestState, ROOT_SNAPSHOT_DIFF_KEY, type ReActTestState, type SnapshotConfig, type SnapshotDiff, type SnapshotObject, StateBuilder, type TestToolCall, type TestToolResult, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { HumanMessage, AIMessage, SystemMessage, BaseMessage } from '@langchain/
3
3
  import { z } from 'zod';
4
4
  import { toolBuilder, ToolCategory } from '@agentforge/core';
5
5
  import { isatty } from 'tty';
6
+ import { isDeepStrictEqual } from 'util';
6
7
 
7
8
  var __create = Object.create;
8
9
  var __defProp = Object.defineProperty;
@@ -18748,31 +18749,38 @@ var ConversationSimulator = class {
18748
18749
  function createConversationSimulator(agent, config2) {
18749
18750
  return new ConversationSimulator(agent, config2);
18750
18751
  }
18751
-
18752
- // src/runners/snapshot-testing.ts
18753
- function normalizeValue(value, config2) {
18754
- if (value === null || value === void 0) {
18755
- return value;
18752
+ var ROOT_SNAPSHOT_DIFF_KEY = "$root";
18753
+ function createSnapshotObject() {
18754
+ return /* @__PURE__ */ Object.create(null);
18755
+ }
18756
+ function isPlainSnapshotObject(value) {
18757
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
18758
+ return false;
18756
18759
  }
18757
- if (config2.normalizer) {
18758
- return config2.normalizer(value);
18760
+ const prototype = Object.getPrototypeOf(value);
18761
+ return prototype === Object.prototype || prototype === null;
18762
+ }
18763
+ function normalizeValue(value, config2) {
18764
+ const valueToNormalize = config2.normalizer ? config2.normalizer(value) : value;
18765
+ if (valueToNormalize === null || valueToNormalize === void 0) {
18766
+ return valueToNormalize;
18759
18767
  }
18760
- if (config2.normalizeTimestamps && value instanceof Date) {
18768
+ if (config2.normalizeTimestamps && valueToNormalize instanceof Date) {
18761
18769
  return "[TIMESTAMP]";
18762
18770
  }
18763
- if (config2.normalizeTimestamps && typeof value === "string") {
18764
- if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(value)) {
18771
+ if (config2.normalizeTimestamps && typeof valueToNormalize === "string") {
18772
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(valueToNormalize)) {
18765
18773
  return "[TIMESTAMP]";
18766
18774
  }
18767
18775
  }
18768
- if (config2.normalizeIds && typeof value === "string") {
18769
- if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value)) {
18776
+ if (config2.normalizeIds && typeof valueToNormalize === "string") {
18777
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(valueToNormalize)) {
18770
18778
  return "[UUID]";
18771
18779
  }
18772
18780
  }
18773
- if (typeof value === "object" && !Array.isArray(value)) {
18774
- const normalized = {};
18775
- for (const [key, val] of Object.entries(value)) {
18781
+ if (isPlainSnapshotObject(valueToNormalize)) {
18782
+ const normalized = createSnapshotObject();
18783
+ for (const [key, val] of Object.entries(valueToNormalize)) {
18776
18784
  if (config2.excludeFields?.includes(key)) {
18777
18785
  continue;
18778
18786
  }
@@ -18783,10 +18791,10 @@ function normalizeValue(value, config2) {
18783
18791
  }
18784
18792
  return normalized;
18785
18793
  }
18786
- if (Array.isArray(value)) {
18787
- return value.map((item) => normalizeValue(item, config2));
18794
+ if (Array.isArray(valueToNormalize)) {
18795
+ return valueToNormalize.map((item) => normalizeValue(item, config2));
18788
18796
  }
18789
- return value;
18797
+ return valueToNormalize;
18790
18798
  }
18791
18799
  function createSnapshot(state, config2 = {}) {
18792
18800
  return normalizeValue(state, {
@@ -18802,35 +18810,45 @@ function assertMatchesSnapshot(state, config2) {
18802
18810
  function createMessageSnapshot(messages, config2) {
18803
18811
  return messages.map((msg) => ({
18804
18812
  type: msg._getType(),
18805
- content: msg.content
18813
+ content: normalizeValue(msg.content, {
18814
+ normalizeTimestamps: true,
18815
+ normalizeIds: true,
18816
+ ...config2
18817
+ })
18806
18818
  }));
18807
18819
  }
18808
18820
  function assertMessagesMatchSnapshot(messages, config2) {
18809
- const snapshot = createMessageSnapshot(messages);
18821
+ const snapshot = createMessageSnapshot(messages, config2);
18810
18822
  globalExpect(snapshot).toMatchSnapshot();
18811
18823
  }
18812
18824
  function compareStates(state1, state2, config2) {
18813
18825
  const snapshot1 = createSnapshot(state1, config2);
18814
18826
  const snapshot2 = createSnapshot(state2, config2);
18815
- return JSON.stringify(snapshot1) === JSON.stringify(snapshot2);
18827
+ return isDeepStrictEqual(snapshot1, snapshot2);
18816
18828
  }
18817
18829
  function createStateDiff(state1, state2, config2) {
18818
18830
  const snapshot1 = createSnapshot(state1, config2);
18819
18831
  const snapshot2 = createSnapshot(state2, config2);
18820
18832
  const diff2 = {
18821
- added: {},
18822
- removed: {},
18823
- changed: {}
18833
+ added: createSnapshotObject(),
18834
+ removed: createSnapshotObject(),
18835
+ changed: /* @__PURE__ */ Object.create(null)
18824
18836
  };
18837
+ if (!isPlainSnapshotObject(snapshot1) || !isPlainSnapshotObject(snapshot2)) {
18838
+ if (!isDeepStrictEqual(snapshot1, snapshot2)) {
18839
+ diff2.changed[ROOT_SNAPSHOT_DIFF_KEY] = { from: snapshot1, to: snapshot2 };
18840
+ }
18841
+ return diff2;
18842
+ }
18825
18843
  for (const [key, value] of Object.entries(snapshot2)) {
18826
- if (!(key in snapshot1)) {
18844
+ if (!Object.hasOwn(snapshot1, key)) {
18827
18845
  diff2.added[key] = value;
18828
- } else if (JSON.stringify(snapshot1[key]) !== JSON.stringify(value)) {
18846
+ } else if (!isDeepStrictEqual(snapshot1[key], value)) {
18829
18847
  diff2.changed[key] = { from: snapshot1[key], to: value };
18830
18848
  }
18831
18849
  }
18832
18850
  for (const key of Object.keys(snapshot1)) {
18833
- if (!(key in snapshot2)) {
18851
+ if (!Object.hasOwn(snapshot2, key)) {
18834
18852
  diff2.removed[key] = snapshot1[key];
18835
18853
  }
18836
18854
  }
@@ -19116,6 +19134,6 @@ chai/index.js:
19116
19134
  *)
19117
19135
  */
19118
19136
 
19119
- export { AgentTestRunner, ConversationSimulator, MockLLM, StateBuilder, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
19137
+ export { AgentTestRunner, ConversationSimulator, MockLLM, ROOT_SNAPSHOT_DIFF_KEY, StateBuilder, assertAlternatingMessages, assertCompletesWithin, assertHasKeys, assertInRange, assertIsMessage, assertIterationsWithinLimit, assertLastMessageContains, assertMatchesSnapshot, assertMessageContains, assertMessagesMatchSnapshot, assertNotEmpty, assertStateChanged, assertStateHasFields, assertStateSnapshot, assertThrowsWithMessage, assertToolCalled, calculatorTool, compareStates, complexReasoningConversation, createAgentTestRunner, createCalculatorTool, createConversation, createConversationSimulator, createConversationState, createConversationWithSystem, createDelayedTool, createEchoLLM, createEchoTool, createErrorLLM, createErrorTool, createMessageSnapshot, createMockLLM, createMockTool, createPlanningState, createReActState, createSnapshot, createStateBuilder, createStateDiff, databaseQueryTool, errorHandlingConversation, fileReaderTool, getToolByName, getToolsByCategory, longContextConversation, multiTurnConversation, sampleData, sampleTools, searchTool, simpleGreeting, timeTool, toolUsageConversation, weatherTool };
19120
19138
  //# sourceMappingURL=index.js.map
19121
19139
  //# sourceMappingURL=index.js.map