@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.cjs +46 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -8
- package/dist/index.d.ts +22 -8
- package/dist/index.js +46 -28
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var messages = require('@langchain/core/messages');
|
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
var core = require('@agentforge/core');
|
|
7
7
|
var tty = require('tty');
|
|
8
|
+
var util = require('util');
|
|
8
9
|
|
|
9
10
|
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
@@ -18750,31 +18751,38 @@ var ConversationSimulator = class {
|
|
|
18750
18751
|
function createConversationSimulator(agent, config2) {
|
|
18751
18752
|
return new ConversationSimulator(agent, config2);
|
|
18752
18753
|
}
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18754
|
+
var ROOT_SNAPSHOT_DIFF_KEY = "$root";
|
|
18755
|
+
function createSnapshotObject() {
|
|
18756
|
+
return /* @__PURE__ */ Object.create(null);
|
|
18757
|
+
}
|
|
18758
|
+
function isPlainSnapshotObject(value) {
|
|
18759
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
18760
|
+
return false;
|
|
18758
18761
|
}
|
|
18759
|
-
|
|
18760
|
-
|
|
18762
|
+
const prototype = Object.getPrototypeOf(value);
|
|
18763
|
+
return prototype === Object.prototype || prototype === null;
|
|
18764
|
+
}
|
|
18765
|
+
function normalizeValue(value, config2) {
|
|
18766
|
+
const valueToNormalize = config2.normalizer ? config2.normalizer(value) : value;
|
|
18767
|
+
if (valueToNormalize === null || valueToNormalize === void 0) {
|
|
18768
|
+
return valueToNormalize;
|
|
18761
18769
|
}
|
|
18762
|
-
if (config2.normalizeTimestamps &&
|
|
18770
|
+
if (config2.normalizeTimestamps && valueToNormalize instanceof Date) {
|
|
18763
18771
|
return "[TIMESTAMP]";
|
|
18764
18772
|
}
|
|
18765
|
-
if (config2.normalizeTimestamps && typeof
|
|
18766
|
-
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(
|
|
18773
|
+
if (config2.normalizeTimestamps && typeof valueToNormalize === "string") {
|
|
18774
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(valueToNormalize)) {
|
|
18767
18775
|
return "[TIMESTAMP]";
|
|
18768
18776
|
}
|
|
18769
18777
|
}
|
|
18770
|
-
if (config2.normalizeIds && typeof
|
|
18771
|
-
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
18778
|
+
if (config2.normalizeIds && typeof valueToNormalize === "string") {
|
|
18779
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(valueToNormalize)) {
|
|
18772
18780
|
return "[UUID]";
|
|
18773
18781
|
}
|
|
18774
18782
|
}
|
|
18775
|
-
if (
|
|
18776
|
-
const normalized =
|
|
18777
|
-
for (const [key, val] of Object.entries(
|
|
18783
|
+
if (isPlainSnapshotObject(valueToNormalize)) {
|
|
18784
|
+
const normalized = createSnapshotObject();
|
|
18785
|
+
for (const [key, val] of Object.entries(valueToNormalize)) {
|
|
18778
18786
|
if (config2.excludeFields?.includes(key)) {
|
|
18779
18787
|
continue;
|
|
18780
18788
|
}
|
|
@@ -18785,10 +18793,10 @@ function normalizeValue(value, config2) {
|
|
|
18785
18793
|
}
|
|
18786
18794
|
return normalized;
|
|
18787
18795
|
}
|
|
18788
|
-
if (Array.isArray(
|
|
18789
|
-
return
|
|
18796
|
+
if (Array.isArray(valueToNormalize)) {
|
|
18797
|
+
return valueToNormalize.map((item) => normalizeValue(item, config2));
|
|
18790
18798
|
}
|
|
18791
|
-
return
|
|
18799
|
+
return valueToNormalize;
|
|
18792
18800
|
}
|
|
18793
18801
|
function createSnapshot(state, config2 = {}) {
|
|
18794
18802
|
return normalizeValue(state, {
|
|
@@ -18804,35 +18812,45 @@ function assertMatchesSnapshot(state, config2) {
|
|
|
18804
18812
|
function createMessageSnapshot(messages, config2) {
|
|
18805
18813
|
return messages.map((msg) => ({
|
|
18806
18814
|
type: msg._getType(),
|
|
18807
|
-
content: msg.content
|
|
18815
|
+
content: normalizeValue(msg.content, {
|
|
18816
|
+
normalizeTimestamps: true,
|
|
18817
|
+
normalizeIds: true,
|
|
18818
|
+
...config2
|
|
18819
|
+
})
|
|
18808
18820
|
}));
|
|
18809
18821
|
}
|
|
18810
18822
|
function assertMessagesMatchSnapshot(messages, config2) {
|
|
18811
|
-
const snapshot = createMessageSnapshot(messages);
|
|
18823
|
+
const snapshot = createMessageSnapshot(messages, config2);
|
|
18812
18824
|
globalExpect(snapshot).toMatchSnapshot();
|
|
18813
18825
|
}
|
|
18814
18826
|
function compareStates(state1, state2, config2) {
|
|
18815
18827
|
const snapshot1 = createSnapshot(state1, config2);
|
|
18816
18828
|
const snapshot2 = createSnapshot(state2, config2);
|
|
18817
|
-
return
|
|
18829
|
+
return util.isDeepStrictEqual(snapshot1, snapshot2);
|
|
18818
18830
|
}
|
|
18819
18831
|
function createStateDiff(state1, state2, config2) {
|
|
18820
18832
|
const snapshot1 = createSnapshot(state1, config2);
|
|
18821
18833
|
const snapshot2 = createSnapshot(state2, config2);
|
|
18822
18834
|
const diff2 = {
|
|
18823
|
-
added:
|
|
18824
|
-
removed:
|
|
18825
|
-
changed:
|
|
18835
|
+
added: createSnapshotObject(),
|
|
18836
|
+
removed: createSnapshotObject(),
|
|
18837
|
+
changed: /* @__PURE__ */ Object.create(null)
|
|
18826
18838
|
};
|
|
18839
|
+
if (!isPlainSnapshotObject(snapshot1) || !isPlainSnapshotObject(snapshot2)) {
|
|
18840
|
+
if (!util.isDeepStrictEqual(snapshot1, snapshot2)) {
|
|
18841
|
+
diff2.changed[ROOT_SNAPSHOT_DIFF_KEY] = { from: snapshot1, to: snapshot2 };
|
|
18842
|
+
}
|
|
18843
|
+
return diff2;
|
|
18844
|
+
}
|
|
18827
18845
|
for (const [key, value] of Object.entries(snapshot2)) {
|
|
18828
|
-
if (!(key
|
|
18846
|
+
if (!Object.hasOwn(snapshot1, key)) {
|
|
18829
18847
|
diff2.added[key] = value;
|
|
18830
|
-
} else if (
|
|
18848
|
+
} else if (!util.isDeepStrictEqual(snapshot1[key], value)) {
|
|
18831
18849
|
diff2.changed[key] = { from: snapshot1[key], to: value };
|
|
18832
18850
|
}
|
|
18833
18851
|
}
|
|
18834
18852
|
for (const key of Object.keys(snapshot1)) {
|
|
18835
|
-
if (!(key
|
|
18853
|
+
if (!Object.hasOwn(snapshot2, key)) {
|
|
18836
18854
|
diff2.removed[key] = snapshot1[key];
|
|
18837
18855
|
}
|
|
18838
18856
|
}
|
|
@@ -19121,6 +19139,7 @@ chai/index.js:
|
|
|
19121
19139
|
exports.AgentTestRunner = AgentTestRunner;
|
|
19122
19140
|
exports.ConversationSimulator = ConversationSimulator;
|
|
19123
19141
|
exports.MockLLM = MockLLM;
|
|
19142
|
+
exports.ROOT_SNAPSHOT_DIFF_KEY = ROOT_SNAPSHOT_DIFF_KEY;
|
|
19124
19143
|
exports.StateBuilder = StateBuilder;
|
|
19125
19144
|
exports.assertAlternatingMessages = assertAlternatingMessages;
|
|
19126
19145
|
exports.assertCompletesWithin = assertCompletesWithin;
|