MCPcopy Create free account
hub / github.com/CopilotKit/aimock / entryToFixture

Function entryToFixture

src/fixture-loader.ts:71–120  ·  view source on GitHub ↗
(entry: FixtureFileEntry, logger?: Logger)

Source from the content-addressed store, hash-verified

69}
70
71export function entryToFixture(entry: FixtureFileEntry, logger?: Logger): Fixture {
72 const fixture: Fixture = {
73 match: {
74 userMessage: entry.match.userMessage,
75 systemMessage: entry.match.systemMessage,
76 inputText: entry.match.inputText,
77 toolCallId: entry.match.toolCallId,
78 toolName: entry.match.toolName,
79 model: entry.match.model,
80 responseFormat: entry.match.responseFormat,
81 endpoint: entry.match.endpoint,
82 ...(entry.match.sequenceIndex !== undefined && { sequenceIndex: entry.match.sequenceIndex }),
83 ...(entry.match.turnIndex !== undefined && {
84 turnIndex: entry.match.turnIndex,
85 }),
86 ...(entry.match.hasToolResult !== undefined && {
87 hasToolResult: entry.match.hasToolResult,
88 }),
89 ...(entry.match.context !== undefined && { context: entry.match.context }),
90 },
91 response: normalizeResponse(entry.response),
92 ...(entry.latency !== undefined && { latency: entry.latency }),
93 ...(entry.chunkSize !== undefined && { chunkSize: entry.chunkSize }),
94 ...(entry.truncateAfterChunks !== undefined && {
95 truncateAfterChunks: entry.truncateAfterChunks,
96 }),
97 ...(entry.disconnectAfterMs !== undefined && { disconnectAfterMs: entry.disconnectAfterMs }),
98 ...(entry.streamingProfile !== undefined && { streamingProfile: entry.streamingProfile }),
99 ...(entry.recordedTimings !== undefined && { recordedTimings: entry.recordedTimings }),
100 ...(entry.replaySpeed != null && { replaySpeed: entry.replaySpeed }),
101 ...(entry.chaos !== undefined && { chaos: entry.chaos }),
102 ...(entry.metadata !== undefined && { metadata: entry.metadata }),
103 };
104
105 // Sanitize recordedTimings to guard against NaN or negative values that
106 // would silently degrade replay timing calculations.
107 if (fixture.recordedTimings) {
108 const rt = fixture.recordedTimings;
109 if (!Number.isFinite(rt.ttftMs) || rt.ttftMs < 0) rt.ttftMs = 0;
110 rt.interChunkDelaysMs = rt.interChunkDelaysMs.filter((d) => Number.isFinite(d) && d >= 0);
111 if (!Number.isFinite(rt.totalDurationMs) || rt.totalDurationMs < 0) rt.totalDurationMs = 0;
112 }
113
114 if (fixture.replaySpeed != null && fixture.replaySpeed <= 0) {
115 logger?.warn(`Fixture replaySpeed must be positive, got ${fixture.replaySpeed}. Ignoring.`);
116 delete fixture.replaySpeed;
117 }
118
119 return fixture;
120}
121
122// Logging helper — uses logger if provided, falls back to console.warn.
123function warn(logger: Logger | undefined, msg: string, ...rest: unknown[]): void {

Calls 2

normalizeResponseFunction · 0.85
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…