@copilotkit/aimock 1.43.0 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +46 -0
- package/README.md +14 -2
- package/dist/agui-handler.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +31 -5
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.d.cts.map +1 -1
- package/dist/aimock-cli.d.ts.map +1 -1
- package/dist/aimock-cli.js +31 -5
- package/dist/aimock-cli.js.map +1 -1
- package/dist/bedrock-converse.cjs +344 -43
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +345 -44
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +195 -42
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts.map +1 -1
- package/dist/bedrock.js +196 -43
- package/dist/bedrock.js.map +1 -1
- package/dist/chaos.cjs +9 -5
- package/dist/chaos.cjs.map +1 -1
- package/dist/chaos.d.cts.map +1 -1
- package/dist/chaos.d.ts.map +1 -1
- package/dist/chaos.js +10 -7
- package/dist/chaos.js.map +1 -1
- package/dist/cli.cjs +238 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +242 -13
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +159 -72
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +160 -73
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +63 -5
- package/dist/config-loader.cjs.map +1 -1
- package/dist/config-loader.d.cts +37 -4
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts +37 -4
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +63 -5
- package/dist/config-loader.js.map +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +6 -2
- package/dist/constants.d.ts +6 -2
- package/dist/constants.js +8 -1
- package/dist/constants.js.map +1 -1
- package/dist/echo-text.cjs +65 -0
- package/dist/echo-text.cjs.map +1 -0
- package/dist/echo-text.d.cts +22 -0
- package/dist/echo-text.d.cts.map +1 -0
- package/dist/echo-text.d.ts +22 -0
- package/dist/echo-text.d.ts.map +1 -0
- package/dist/echo-text.js +65 -0
- package/dist/echo-text.js.map +1 -0
- package/dist/embeddings.cjs +18 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +1 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +1 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +18 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/fakes-plugin.cjs +131 -0
- package/dist/fakes-plugin.cjs.map +1 -0
- package/dist/fakes-plugin.d.cts +23 -0
- package/dist/fakes-plugin.d.cts.map +1 -0
- package/dist/fakes-plugin.d.ts +23 -0
- package/dist/fakes-plugin.d.ts.map +1 -0
- package/dist/fakes-plugin.js +127 -0
- package/dist/fakes-plugin.js.map +1 -0
- package/dist/files.cjs +9 -11
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +10 -13
- package/dist/files.js.map +1 -1
- package/dist/fine-tuning.cjs +1 -19
- package/dist/fine-tuning.cjs.map +1 -1
- package/dist/fine-tuning.d.cts.map +1 -1
- package/dist/fine-tuning.d.ts.map +1 -1
- package/dist/fine-tuning.js +2 -20
- package/dist/fine-tuning.js.map +1 -1
- package/dist/fixture-loader-services.cjs +116 -0
- package/dist/fixture-loader-services.cjs.map +1 -0
- package/dist/fixture-loader-services.d.cts +48 -0
- package/dist/fixture-loader-services.d.cts.map +1 -0
- package/dist/fixture-loader-services.d.ts +48 -0
- package/dist/fixture-loader-services.d.ts.map +1 -0
- package/dist/fixture-loader-services.js +114 -0
- package/dist/fixture-loader-services.js.map +1 -0
- package/dist/fixture-loader.cjs +552 -29
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts +140 -2
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts +140 -2
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +542 -31
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-embeddings.cjs +42 -2
- package/dist/gemini-embeddings.cjs.map +1 -1
- package/dist/gemini-embeddings.js +43 -3
- package/dist/gemini-embeddings.js.map +1 -1
- package/dist/gemini-interactions.cjs +288 -52
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.d.cts.map +1 -1
- package/dist/gemini-interactions.d.ts.map +1 -1
- package/dist/gemini-interactions.js +289 -53
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +234 -38
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +235 -39
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +1157 -12
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +85 -4
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +85 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +1113 -14
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +3 -2
- package/dist/images.cjs.map +1 -1
- package/dist/images.js +3 -2
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +39 -1
- package/dist/index.d.cts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +11 -4
- package/dist/jest.cjs +43 -14
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +47 -5
- package/dist/jest.d.cts.map +1 -1
- package/dist/jest.d.ts +47 -5
- package/dist/jest.d.ts.map +1 -1
- package/dist/jest.js +45 -16
- package/dist/jest.js.map +1 -1
- package/dist/journal.cjs +155 -13
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts +54 -4
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts +54 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +155 -13
- package/dist/journal.js.map +1 -1
- package/dist/live-sanitize.cjs +4 -32
- package/dist/live-sanitize.cjs.map +1 -1
- package/dist/live-sanitize.js +4 -32
- package/dist/live-sanitize.js.map +1 -1
- package/dist/llmock.cjs +204 -39
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +51 -1
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +51 -1
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +206 -41
- package/dist/llmock.js.map +1 -1
- package/dist/mcp-fakes-mount.cjs +217 -0
- package/dist/mcp-fakes-mount.cjs.map +1 -0
- package/dist/mcp-fakes-mount.js +211 -0
- package/dist/mcp-fakes-mount.js.map +1 -0
- package/dist/mcp-fakes-report.cjs +111 -0
- package/dist/mcp-fakes-report.cjs.map +1 -0
- package/dist/mcp-fakes-report.d.cts +40 -0
- package/dist/mcp-fakes-report.d.cts.map +1 -0
- package/dist/mcp-fakes-report.d.ts +40 -0
- package/dist/mcp-fakes-report.d.ts.map +1 -0
- package/dist/mcp-fakes-report.js +107 -0
- package/dist/mcp-fakes-report.js.map +1 -0
- package/dist/mcp-fakes.cjs +1942 -0
- package/dist/mcp-fakes.cjs.map +1 -0
- package/dist/mcp-fakes.d.cts +504 -0
- package/dist/mcp-fakes.d.cts.map +1 -0
- package/dist/mcp-fakes.d.ts +504 -0
- package/dist/mcp-fakes.d.ts.map +1 -0
- package/dist/mcp-fakes.js +1937 -0
- package/dist/mcp-fakes.js.map +1 -0
- package/dist/mcp-handler.cjs +534 -27
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.d.cts +49 -0
- package/dist/mcp-handler.d.cts.map +1 -0
- package/dist/mcp-handler.d.ts +49 -0
- package/dist/mcp-handler.d.ts.map +1 -0
- package/dist/mcp-handler.js +530 -28
- package/dist/mcp-handler.js.map +1 -1
- package/dist/mcp-mock.cjs +326 -47
- package/dist/mcp-mock.cjs.map +1 -1
- package/dist/mcp-mock.d.cts +97 -1
- package/dist/mcp-mock.d.cts.map +1 -1
- package/dist/mcp-mock.d.ts +97 -1
- package/dist/mcp-mock.d.ts.map +1 -1
- package/dist/mcp-mock.js +327 -48
- package/dist/mcp-mock.js.map +1 -1
- package/dist/mcp-recorder.cjs +1224 -0
- package/dist/mcp-recorder.cjs.map +1 -0
- package/dist/mcp-recorder.d.cts +108 -0
- package/dist/mcp-recorder.d.cts.map +1 -0
- package/dist/mcp-recorder.d.ts +108 -0
- package/dist/mcp-recorder.d.ts.map +1 -0
- package/dist/mcp-recorder.js +1215 -0
- package/dist/mcp-recorder.js.map +1 -0
- package/dist/mcp-stub.cjs +5 -1
- package/dist/mcp-stub.d.cts +3 -1
- package/dist/mcp-stub.d.ts +3 -1
- package/dist/mcp-stub.js +3 -1
- package/dist/mcp-types.d.cts +6 -0
- package/dist/mcp-types.d.ts +6 -0
- package/dist/message-text.cjs +192 -0
- package/dist/message-text.cjs.map +1 -0
- package/dist/message-text.d.cts +31 -0
- package/dist/message-text.d.cts.map +1 -0
- package/dist/message-text.d.ts +31 -0
- package/dist/message-text.d.ts.map +1 -0
- package/dist/message-text.js +184 -0
- package/dist/message-text.js.map +1 -0
- package/dist/messages.cjs +400 -56
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +401 -58
- package/dist/messages.js.map +1 -1
- package/dist/metrics.cjs +46 -66
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.cts +14 -6
- package/dist/metrics.d.cts.map +1 -1
- package/dist/metrics.d.ts +14 -6
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +32 -40
- package/dist/metrics.js.map +1 -1
- package/dist/misbehavior.cjs +1523 -0
- package/dist/misbehavior.cjs.map +1 -0
- package/dist/misbehavior.d.cts +43 -0
- package/dist/misbehavior.d.cts.map +1 -0
- package/dist/misbehavior.d.ts +43 -0
- package/dist/misbehavior.d.ts.map +1 -0
- package/dist/misbehavior.js +1511 -0
- package/dist/misbehavior.js.map +1 -0
- package/dist/ollama.cjs +315 -113
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +316 -114
- package/dist/ollama.js.map +1 -1
- package/dist/openapi.cjs +3405 -0
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +30 -0
- package/dist/openapi.d.cts.map +1 -0
- package/dist/openapi.d.ts +30 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +3404 -0
- package/dist/openapi.js.map +1 -0
- package/dist/openrouter-video.cjs +4 -4
- package/dist/openrouter-video.cjs.map +1 -1
- package/dist/openrouter-video.d.cts.map +1 -1
- package/dist/openrouter-video.d.ts.map +1 -1
- package/dist/openrouter-video.js +4 -4
- package/dist/openrouter-video.js.map +1 -1
- package/dist/record-sanitize.cjs +231 -0
- package/dist/record-sanitize.cjs.map +1 -0
- package/dist/record-sanitize.js +224 -0
- package/dist/record-sanitize.js.map +1 -0
- package/dist/recorder.cjs +115 -6
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts +2 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts +2 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +116 -8
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +701 -166
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +5 -13
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +5 -13
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +699 -169
- package/dist/responses.js.map +1 -1
- package/dist/route-registry.cjs +951 -0
- package/dist/route-registry.cjs.map +1 -0
- package/dist/route-registry.d.cts +33 -0
- package/dist/route-registry.d.cts.map +1 -0
- package/dist/route-registry.d.ts +33 -0
- package/dist/route-registry.d.ts.map +1 -0
- package/dist/route-registry.js +866 -0
- package/dist/route-registry.js.map +1 -0
- package/dist/router.cjs +24 -2
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +25 -4
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +1159 -264
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +4 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1067 -172
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +4 -2
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.js +4 -2
- package/dist/speech.js.map +1 -1
- package/dist/stream-collapse.cjs +236 -34
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +39 -4
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +39 -4
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +235 -35
- package/dist/stream-collapse.js.map +1 -1
- package/dist/suite.cjs +1 -1
- package/dist/suite.js +1 -1
- package/dist/transcription.cjs +2 -2
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.cts.map +1 -1
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +2 -2
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs +18 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +516 -5
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +516 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/validate-cli.cjs +123 -33
- package/dist/validate-cli.cjs.map +1 -1
- package/dist/validate-cli.js +125 -35
- package/dist/validate-cli.js.map +1 -1
- package/dist/vector-stores.cjs +1180 -0
- package/dist/vector-stores.cjs.map +1 -0
- package/dist/vector-stores.d.cts +106 -0
- package/dist/vector-stores.d.cts.map +1 -0
- package/dist/vector-stores.d.ts +106 -0
- package/dist/vector-stores.d.ts.map +1 -0
- package/dist/vector-stores.js +1164 -0
- package/dist/vector-stores.js.map +1 -0
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/version.cjs +45 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +44 -0
- package/dist/version.js.map +1 -0
- package/dist/video.cjs +19 -0
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +19 -0
- package/dist/video.js.map +1 -1
- package/dist/vitest.cjs +77 -16
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +38 -5
- package/dist/vitest.d.cts.map +1 -1
- package/dist/vitest.d.ts +38 -5
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +78 -17
- package/dist/vitest.js.map +1 -1
- package/dist/watcher.cjs +6 -2
- package/dist/watcher.cjs.map +1 -1
- package/dist/watcher.js +6 -2
- package/dist/watcher.js.map +1 -1
- package/dist/ws-gemini-live.cjs +210 -101
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +9 -3
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts +9 -3
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +211 -102
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +175 -62
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts +8 -3
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts +8 -3
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +176 -63
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +121 -16
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts +8 -12
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts +8 -12
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +123 -18
- package/dist/ws-responses.js.map +1 -1
- package/package.json +13 -2
- package/skills/write-fixtures/SKILL.md +179 -21
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { MCP_FAKES_DEFAULT_TEST_ID } from "./mcp-fakes.js";
|
|
2
|
+
import { AimockFakesReportError, formatFakesReport } from "./mcp-fakes-report.js";
|
|
3
|
+
|
|
4
|
+
//#region src/fakes-plugin.ts
|
|
5
|
+
/** TI1/TI2 separator: space, U+203A, space. */
|
|
6
|
+
const TEST_ID_SEPARATOR = " › ";
|
|
7
|
+
const FAKES_REPORT_MODES = [
|
|
8
|
+
"off",
|
|
9
|
+
"warn",
|
|
10
|
+
"fail"
|
|
11
|
+
];
|
|
12
|
+
/** The `fakesReport` option, checked: an unknown mode fails `beforeAll`. */
|
|
13
|
+
function fakesReportMode(mode) {
|
|
14
|
+
if (mode === void 0) return "off";
|
|
15
|
+
if (!FAKES_REPORT_MODES.includes(mode)) throw new Error(`useAimock(): fakesReport must be one of ${FAKES_REPORT_MODES.map((m) => JSON.stringify(m)).join(", ")}; got ${JSON.stringify(mode)}`);
|
|
16
|
+
return mode;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The URL and headers that reach the fakes scoped to `testId` (and
|
|
20
|
+
* `opts.context`) at `opts.mount`. `URLSearchParams` writes a space as `+`,
|
|
21
|
+
* which the mount reads back as a space in the query.
|
|
22
|
+
*/
|
|
23
|
+
function fakesTarget(url, testId, opts = {}) {
|
|
24
|
+
const mount = opts.mount ?? "/mcp";
|
|
25
|
+
const query = new URLSearchParams({ testId });
|
|
26
|
+
const headers = { "X-Test-Id": encodeURIComponent(testId) };
|
|
27
|
+
if (opts.context) {
|
|
28
|
+
query.set("context", opts.context);
|
|
29
|
+
headers["X-AIMock-Context"] = encodeURIComponent(opts.context);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
testId,
|
|
33
|
+
mcpUrl: `${url}${mount}?${query.toString()}`,
|
|
34
|
+
headers
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** RP6: read `GET /__aimock/mcp/fakes/report` for one identity. */
|
|
38
|
+
async function fetchFakesReport(url, testId, context) {
|
|
39
|
+
const query = new URLSearchParams();
|
|
40
|
+
if (testId !== null) query.set("testId", testId);
|
|
41
|
+
if (context !== null) query.set("context", context);
|
|
42
|
+
const res = await fetch(`${url}/__aimock/mcp/fakes/report?${query.toString()}`);
|
|
43
|
+
if (!res.ok) throw new Error(`aimock fakes report: HTTP ${res.status} ${await res.text()}`);
|
|
44
|
+
return await res.json();
|
|
45
|
+
}
|
|
46
|
+
function identityKey(testId, context) {
|
|
47
|
+
return `${testId ?? ""}\u0000${context ?? ""}`;
|
|
48
|
+
}
|
|
49
|
+
/** Per-`useAimock` state shared by the Vitest and Jest adapters. */
|
|
50
|
+
var FakesPluginState = class {
|
|
51
|
+
registered = /* @__PURE__ */ new Map();
|
|
52
|
+
/** RP7 (b): id of the last journal entry when the test started (C2). */
|
|
53
|
+
marker = null;
|
|
54
|
+
constructor(mode) {
|
|
55
|
+
this.mode = mode;
|
|
56
|
+
}
|
|
57
|
+
/** Start of a test, after the match-count reset. */
|
|
58
|
+
beforeEach(llm) {
|
|
59
|
+
this.registered.clear();
|
|
60
|
+
this.marker = llm.getLastRequest()?.id ?? null;
|
|
61
|
+
}
|
|
62
|
+
/** RP7 (a): `fakesFor` registers the identity for the current test. */
|
|
63
|
+
register(testId, context) {
|
|
64
|
+
this.registered.set(identityKey(testId, context), {
|
|
65
|
+
testId,
|
|
66
|
+
context
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* RP7 (a) and (b): the registered identities, plus every (test id, context)
|
|
71
|
+
* an MCP request carried since the marker. If the marker entry is gone
|
|
72
|
+
* (FIFO cap or a cleared journal), every remaining entry is newer.
|
|
73
|
+
*/
|
|
74
|
+
identities(llm) {
|
|
75
|
+
const all = llm.getRequests();
|
|
76
|
+
const at = this.marker === null ? -1 : all.findIndex((e) => e.id === this.marker);
|
|
77
|
+
const newer = at >= 0 ? all.slice(at + 1) : all;
|
|
78
|
+
const out = new Map(this.registered);
|
|
79
|
+
for (const entry of newer) {
|
|
80
|
+
if (entry.service !== "mcp" || entry.testId === void 0) continue;
|
|
81
|
+
const testId = entry.testId === MCP_FAKES_DEFAULT_TEST_ID ? null : entry.testId;
|
|
82
|
+
const context = entry.context ?? null;
|
|
83
|
+
out.set(identityKey(testId, context), {
|
|
84
|
+
testId,
|
|
85
|
+
context
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return [...out.values()];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* End of a test, before the next reset: read each identity's report.
|
|
92
|
+
* Under `"fail"`, a report with `ok: false` throws `AimockFakesReportError`
|
|
93
|
+
* (the first failing report, with every failing report's text); under
|
|
94
|
+
* `"warn"`, the text goes to `console.warn`. An unconsumed entry two
|
|
95
|
+
* reports share (an entry scoped by test id only, checked with and without
|
|
96
|
+
* a context) is listed once.
|
|
97
|
+
*/
|
|
98
|
+
async afterEach(llm, url) {
|
|
99
|
+
if (this.mode === "off") return;
|
|
100
|
+
const failing = [];
|
|
101
|
+
const lines = [];
|
|
102
|
+
const unconsumedSeen = /* @__PURE__ */ new Set();
|
|
103
|
+
for (const id of this.identities(llm)) {
|
|
104
|
+
const report = await fetchFakesReport(url, id.testId, id.context);
|
|
105
|
+
if (report.ok) continue;
|
|
106
|
+
failing.push(report);
|
|
107
|
+
for (const line of formatFakesReport(report).split("\n")) {
|
|
108
|
+
if (line.startsWith(" unconsumed: ")) {
|
|
109
|
+
if (unconsumedSeen.has(line)) continue;
|
|
110
|
+
unconsumedSeen.add(line);
|
|
111
|
+
}
|
|
112
|
+
lines.push(line);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (failing.length === 0) return;
|
|
116
|
+
const text = lines.join("\n");
|
|
117
|
+
if (this.mode === "warn") {
|
|
118
|
+
console.warn(text);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw new AimockFakesReportError(failing[0], text);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { FakesPluginState, TEST_ID_SEPARATOR, fakesReportMode, fakesTarget, fetchFakesReport };
|
|
127
|
+
//# sourceMappingURL=fakes-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fakes-plugin.js","names":[],"sources":["../src/fakes-plugin.ts"],"sourcesContent":["/**\n * The MCP fakes part of the Vitest and Jest plugins (record-replay RP7, TI):\n * `fakesFor` targets, the per-test fake report check in `afterEach`, and the\n * state both adapters share. The default test id itself is built by each\n * adapter (TI1 Vitest, TI2 Jest), and it is used only by the fakes helpers\n * (TI4): nothing here tags LLM or control traffic.\n */\nimport type { LLMock } from \"./llmock.js\";\nimport {\n AimockFakesReportError,\n formatFakesReport,\n type McpFakesReport,\n} from \"./mcp-fakes-report.js\";\nimport { MCP_FAKES_DEFAULT_TEST_ID } from \"./mcp-fakes.js\";\n\n/** RP7: what `afterEach` does with a failing report. `\"off\"` is the default. */\nexport type FakesReportMode = \"off\" | \"warn\" | \"fail\";\n\n/** RP7: what `fakesFor` returns, for an MCP client. */\nexport interface FakesTarget {\n /** The test id the URL and headers carry (explicit, or the inferred default). */\n testId: string;\n /** The mount URL with `?testId=` (and `&context=`). */\n mcpUrl: string;\n /** The matching `X-Test-Id` / `X-AIMock-Context` headers, URI-encoded. */\n headers: Record<string, string>;\n}\n\nexport interface FakesForOptions {\n /** The context the fake blocks are scoped to. */\n context?: string;\n /** The MCP mount path (default `\"/mcp\"`). */\n mount?: string;\n}\n\n/** TI1/TI2 separator: space, U+203A, space. */\nexport const TEST_ID_SEPARATOR = \" › \";\n\nconst FAKES_REPORT_MODES: readonly FakesReportMode[] = [\"off\", \"warn\", \"fail\"];\n\n/** The `fakesReport` option, checked: an unknown mode fails `beforeAll`. */\nexport function fakesReportMode(mode: FakesReportMode | undefined): FakesReportMode {\n if (mode === undefined) return \"off\";\n if (!FAKES_REPORT_MODES.includes(mode)) {\n throw new Error(\n `useAimock(): fakesReport must be one of ${FAKES_REPORT_MODES.map((m) => JSON.stringify(m)).join(\", \")}; got ${JSON.stringify(mode)}`,\n );\n }\n return mode;\n}\n\n/**\n * The URL and headers that reach the fakes scoped to `testId` (and\n * `opts.context`) at `opts.mount`. `URLSearchParams` writes a space as `+`,\n * which the mount reads back as a space in the query.\n */\nexport function fakesTarget(url: string, testId: string, opts: FakesForOptions = {}): FakesTarget {\n const mount = opts.mount ?? \"/mcp\";\n const query = new URLSearchParams({ testId });\n const headers: Record<string, string> = { \"X-Test-Id\": encodeURIComponent(testId) };\n if (opts.context) {\n query.set(\"context\", opts.context);\n headers[\"X-AIMock-Context\"] = encodeURIComponent(opts.context);\n }\n return { testId, mcpUrl: `${url}${mount}?${query.toString()}`, headers };\n}\n\n/** RP6: read `GET /__aimock/mcp/fakes/report` for one identity. */\nexport async function fetchFakesReport(\n url: string,\n testId: string | null,\n context: string | null,\n): Promise<McpFakesReport> {\n const query = new URLSearchParams();\n if (testId !== null) query.set(\"testId\", testId);\n if (context !== null) query.set(\"context\", context);\n const res = await fetch(`${url}/__aimock/mcp/fakes/report?${query.toString()}`);\n if (!res.ok) {\n throw new Error(`aimock fakes report: HTTP ${res.status} ${await res.text()}`);\n }\n return (await res.json()) as McpFakesReport;\n}\n\n/** One identity the report checks; `null` means none supplied. */\nexport interface FakesIdentity {\n testId: string | null;\n context: string | null;\n}\n\nfunction identityKey(testId: string | null, context: string | null): string {\n return `${testId ?? \"\"}\\u0000${context ?? \"\"}`;\n}\n\n/** Per-`useAimock` state shared by the Vitest and Jest adapters. */\nexport class FakesPluginState {\n private readonly registered = new Map<string, FakesIdentity>();\n /** RP7 (b): id of the last journal entry when the test started (C2). */\n private marker: string | null = null;\n\n constructor(readonly mode: FakesReportMode) {}\n\n /** Start of a test, after the match-count reset. */\n beforeEach(llm: LLMock): void {\n this.registered.clear();\n this.marker = llm.getLastRequest()?.id ?? null;\n }\n\n /** RP7 (a): `fakesFor` registers the identity for the current test. */\n register(testId: string, context: string | null): void {\n this.registered.set(identityKey(testId, context), { testId, context });\n }\n\n /**\n * RP7 (a) and (b): the registered identities, plus every (test id, context)\n * an MCP request carried since the marker. If the marker entry is gone\n * (FIFO cap or a cleared journal), every remaining entry is newer.\n */\n identities(llm: LLMock): FakesIdentity[] {\n const all = llm.getRequests();\n const at = this.marker === null ? -1 : all.findIndex((e) => e.id === this.marker);\n const newer = at >= 0 ? all.slice(at + 1) : all;\n const out = new Map(this.registered);\n for (const entry of newer) {\n if (entry.service !== \"mcp\" || entry.testId === undefined) continue;\n const testId = entry.testId === MCP_FAKES_DEFAULT_TEST_ID ? null : entry.testId;\n const context = entry.context ?? null;\n out.set(identityKey(testId, context), { testId, context });\n }\n return [...out.values()];\n }\n\n /**\n * End of a test, before the next reset: read each identity's report.\n * Under `\"fail\"`, a report with `ok: false` throws `AimockFakesReportError`\n * (the first failing report, with every failing report's text); under\n * `\"warn\"`, the text goes to `console.warn`. An unconsumed entry two\n * reports share (an entry scoped by test id only, checked with and without\n * a context) is listed once.\n */\n async afterEach(llm: LLMock, url: string): Promise<void> {\n if (this.mode === \"off\") return;\n const failing: McpFakesReport[] = [];\n const lines: string[] = [];\n const unconsumedSeen = new Set<string>();\n for (const id of this.identities(llm)) {\n const report = await fetchFakesReport(url, id.testId, id.context);\n if (report.ok) continue;\n failing.push(report);\n for (const line of formatFakesReport(report).split(\"\\n\")) {\n if (line.startsWith(\" unconsumed: \")) {\n if (unconsumedSeen.has(line)) continue;\n unconsumedSeen.add(line);\n }\n lines.push(line);\n }\n }\n if (failing.length === 0) return;\n const text = lines.join(\"\\n\");\n if (this.mode === \"warn\") {\n console.warn(text);\n return;\n }\n throw new AimockFakesReportError(failing[0], text);\n }\n}\n"],"mappings":"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"}
|
package/dist/files.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
2
|
const require_helpers = require('./helpers.cjs');
|
|
3
3
|
const require_chaos = require('./chaos.cjs');
|
|
4
|
+
const require_vector_stores = require('./vector-stores.cjs');
|
|
4
5
|
let node_crypto = require("node:crypto");
|
|
5
6
|
|
|
6
7
|
//#region src/files.ts
|
|
@@ -274,6 +275,10 @@ function clearFileStore() {
|
|
|
274
275
|
fileStore.clear();
|
|
275
276
|
fileContents.clear();
|
|
276
277
|
}
|
|
278
|
+
/** The original upload name, without exposing mutable file metadata. */
|
|
279
|
+
function getStoredFileName(id) {
|
|
280
|
+
return fileStore.get(id)?.filename;
|
|
281
|
+
}
|
|
277
282
|
/**
|
|
278
283
|
* The stored bytes for one file, as the very `Buffer` this module holds — so a
|
|
279
284
|
* test can assert on what it RETAINS (`buffer.byteLength`), not just on what it
|
|
@@ -849,15 +854,6 @@ async function handleFilesCreate(req, res, raw, journal, defaults, setCorsHeader
|
|
|
849
854
|
const FILES_LIST_MAX_LIMIT = 1e4;
|
|
850
855
|
const FILES_LIST_DEFAULT_LIMIT = FILES_LIST_MAX_LIMIT;
|
|
851
856
|
/**
|
|
852
|
-
* An unsigned decimal integer literal and nothing else — no sign, no exponent,
|
|
853
|
-
* no radix prefix, no surrounding whitespace. See {@link parseListQuery} for
|
|
854
|
-
* what each of those would otherwise be silently accepted as.
|
|
855
|
-
*
|
|
856
|
-
* A long digit run is still safe to hand to `Number()`: it stays finite and
|
|
857
|
-
* integral, so it fails the range check below rather than the type check.
|
|
858
|
-
*/
|
|
859
|
-
const DECIMAL_INTEGER_RE = /^[0-9]+$/;
|
|
860
|
-
/**
|
|
861
857
|
* The single non-empty value of a list query parameter, or the 400 it earns.
|
|
862
858
|
*
|
|
863
859
|
* ONE rule for all four of `limit`, `order`, `after` and `purpose`, because the
|
|
@@ -928,8 +924,8 @@ function parseListQuery(rawUrl) {
|
|
|
928
924
|
if (!rawLimit.ok) return { error: rawLimit.error };
|
|
929
925
|
let limit = FILES_LIST_DEFAULT_LIMIT;
|
|
930
926
|
if (rawLimit.value !== null) {
|
|
931
|
-
const parsed =
|
|
932
|
-
if (
|
|
927
|
+
const parsed = require_helpers.parseStrictIntegerText(rawLimit.value);
|
|
928
|
+
if (parsed === null || parsed < 1 || parsed > FILES_LIST_MAX_LIMIT) return { error: `Invalid parameter: 'limit' must be an integer between 1 and ${FILES_LIST_MAX_LIMIT}` };
|
|
933
929
|
limit = parsed;
|
|
934
930
|
}
|
|
935
931
|
const rawAfter = singleParam(params, "after");
|
|
@@ -1047,6 +1043,7 @@ async function handleFilesDelete(req, res, fileId, journal, defaults, setCorsHea
|
|
|
1047
1043
|
}
|
|
1048
1044
|
fileStore.delete(fileId);
|
|
1049
1045
|
fileContents.delete(fileId);
|
|
1046
|
+
require_vector_stores.removeVectorStoreFile(fileId);
|
|
1050
1047
|
writeJson(res, 200, {
|
|
1051
1048
|
id: fileId,
|
|
1052
1049
|
object: "file",
|
|
@@ -1062,6 +1059,7 @@ exports.FILES_BODY_OVERSIZED = FILES_BODY_OVERSIZED;
|
|
|
1062
1059
|
exports.FILES_MAX_BYTES = FILES_MAX_BYTES;
|
|
1063
1060
|
exports.clearFileStore = clearFileStore;
|
|
1064
1061
|
exports.getStoredFileBytes = getStoredFileBytes;
|
|
1062
|
+
exports.getStoredFileName = getStoredFileName;
|
|
1065
1063
|
exports.handleFilesContent = handleFilesContent;
|
|
1066
1064
|
exports.handleFilesCreate = handleFilesCreate;
|
|
1067
1065
|
exports.handleFilesDelete = handleFilesDelete;
|