@mastra/server-adapters-test-suite 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @mastra/server-adapters-test-suite
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - `server.auth.authorize(path, method, user, context)` can now call `context.get('requestContext')` and `context.get('mastra')` on the Express, Fastify, Koa and Elysia adapters, as it already could on Hono. Values an app sets on the request context in `authorize` now reach route handlers on every adapter. ([#29069](https://github.com/mastra-ai/mastra/pull/29069))
8
+
9
+ ```ts
10
+ authorize: async (path, method, user, context) => {
11
+ context.get('requestContext').set('tenantId', user.orgId); // read it in any route handler
12
+ return appAuthorize(path, method, user, context);
13
+ };
14
+ ```
15
+
16
+ - Updated dependencies [[`47a6cd8`](https://github.com/mastra-ai/mastra/commit/47a6cd82e5261f56e6eb181b252cda09c3fa4966), [`0a553f0`](https://github.com/mastra-ai/mastra/commit/0a553f0f6ff4150fa5d9897b53824a647f7ddd1e), [`7c242c5`](https://github.com/mastra-ai/mastra/commit/7c242c55c565e9c447ab74a6f529612f0030f061), [`99ca92b`](https://github.com/mastra-ai/mastra/commit/99ca92b60272063a5cb978628e5d286f86c37d4d), [`ba602f5`](https://github.com/mastra-ai/mastra/commit/ba602f5f4622d6a3e6beb6d2741e3d19efe57ca9), [`4d3ebbd`](https://github.com/mastra-ai/mastra/commit/4d3ebbd304509acb118f319e8467fc932079e715), [`0900c20`](https://github.com/mastra-ai/mastra/commit/0900c20592db49a330f467eff5c119212f26603d), [`96853ee`](https://github.com/mastra-ai/mastra/commit/96853ee84f5060710339ef672d302ae139674443), [`9e1f7df`](https://github.com/mastra-ai/mastra/commit/9e1f7df61216f9b21a044acb7dd2498af60f1a5f), [`2d01b00`](https://github.com/mastra-ai/mastra/commit/2d01b00f0d5a74c731de46ab15358ccdc1649b59), [`642c62f`](https://github.com/mastra-ai/mastra/commit/642c62fee331eab32abc24d9af85f05221b5fe5e), [`4253a7d`](https://github.com/mastra-ai/mastra/commit/4253a7d27900a7f7f703fda33856c7becad68934), [`8751dd7`](https://github.com/mastra-ai/mastra/commit/8751dd7f56eefe40d8ce57b6d44df415cadbda4f), [`c7d27f6`](https://github.com/mastra-ai/mastra/commit/c7d27f650bc336af4b1a3ff3ff8346482cc79af9), [`a4d1537`](https://github.com/mastra-ai/mastra/commit/a4d1537e8bac1d3634059bdbc843d787f1ac91f2), [`5a37eef`](https://github.com/mastra-ai/mastra/commit/5a37eefdafb239ccc6514018113f3fb1a025ce9b), [`fcf50d9`](https://github.com/mastra-ai/mastra/commit/fcf50d9cc1c16d265724700b1aed3435c63c3072), [`41dc481`](https://github.com/mastra-ai/mastra/commit/41dc481f1b3509ec6c2a06e63caaa4f630cafa80), [`500edeb`](https://github.com/mastra-ai/mastra/commit/500edeb84e7ec665b5af26e99fced33cf3c85bfd), [`76d8c88`](https://github.com/mastra-ai/mastra/commit/76d8c88c20d540c94c9955c133a1c664b1a05369), [`de1b638`](https://github.com/mastra-ai/mastra/commit/de1b638b2f8aedc57664e2faf10cd936f6c55e92), [`8bea966`](https://github.com/mastra-ai/mastra/commit/8bea9662c5d89c248c7311fc6cca6523d552af5d), [`96853ee`](https://github.com/mastra-ai/mastra/commit/96853ee84f5060710339ef672d302ae139674443), [`682e8f3`](https://github.com/mastra-ai/mastra/commit/682e8f3e44473a5b1f608d1c4ae3a5b8fa46b563), [`0a553f0`](https://github.com/mastra-ai/mastra/commit/0a553f0f6ff4150fa5d9897b53824a647f7ddd1e), [`01524b2`](https://github.com/mastra-ai/mastra/commit/01524b22db5adb7dfdfe4950190918202338d9bd), [`697ea99`](https://github.com/mastra-ai/mastra/commit/697ea99ae93f6dae203cab0f059bc5f9d8316c1e), [`01524b2`](https://github.com/mastra-ai/mastra/commit/01524b22db5adb7dfdfe4950190918202338d9bd), [`c17855e`](https://github.com/mastra-ai/mastra/commit/c17855e2bf21fa9dc71e2a8c77a2f622695b634b), [`f3265d8`](https://github.com/mastra-ai/mastra/commit/f3265d856d8834a5712e732fab5f81c367052b7a), [`cbe76c0`](https://github.com/mastra-ai/mastra/commit/cbe76c0d76e5543866f918fd41041c4d73a1a172), [`f21823d`](https://github.com/mastra-ai/mastra/commit/f21823d20466cab4afb42e401aa33be5561993cf), [`01524b2`](https://github.com/mastra-ai/mastra/commit/01524b22db5adb7dfdfe4950190918202338d9bd), [`f21823d`](https://github.com/mastra-ai/mastra/commit/f21823d20466cab4afb42e401aa33be5561993cf), [`f51fad8`](https://github.com/mastra-ai/mastra/commit/f51fad8a054b382e00370c3eecc4a40c6e58d8f6), [`7ad1918`](https://github.com/mastra-ai/mastra/commit/7ad1918a72a1961bbcbd23b4a615ecd7943e98ab), [`f3265d8`](https://github.com/mastra-ai/mastra/commit/f3265d856d8834a5712e732fab5f81c367052b7a), [`01524b2`](https://github.com/mastra-ai/mastra/commit/01524b22db5adb7dfdfe4950190918202338d9bd), [`01524b2`](https://github.com/mastra-ai/mastra/commit/01524b22db5adb7dfdfe4950190918202338d9bd), [`f21823d`](https://github.com/mastra-ai/mastra/commit/f21823d20466cab4afb42e401aa33be5561993cf), [`234d7a3`](https://github.com/mastra-ai/mastra/commit/234d7a3ee6b84d9f7481649b137aea9f66ce8dae), [`19ca27a`](https://github.com/mastra-ai/mastra/commit/19ca27a666fb68cd309eace86cb488166858713f), [`234d7a3`](https://github.com/mastra-ai/mastra/commit/234d7a3ee6b84d9f7481649b137aea9f66ce8dae), [`234d7a3`](https://github.com/mastra-ai/mastra/commit/234d7a3ee6b84d9f7481649b137aea9f66ce8dae), [`d67a35d`](https://github.com/mastra-ai/mastra/commit/d67a35d034d9b5d5a345a083eb8acafcd57cf01a), [`f21823d`](https://github.com/mastra-ai/mastra/commit/f21823d20466cab4afb42e401aa33be5561993cf), [`ba50b06`](https://github.com/mastra-ai/mastra/commit/ba50b064243c9e8c389968c14e734af95f7cac76), [`f3265d8`](https://github.com/mastra-ai/mastra/commit/f3265d856d8834a5712e732fab5f81c367052b7a), [`f21823d`](https://github.com/mastra-ai/mastra/commit/f21823d20466cab4afb42e401aa33be5561993cf), [`f21823d`](https://github.com/mastra-ai/mastra/commit/f21823d20466cab4afb42e401aa33be5561993cf), [`4d2dbf5`](https://github.com/mastra-ai/mastra/commit/4d2dbf509e2394361cf96aa9a001ce8758782dfc), [`4d2dbf5`](https://github.com/mastra-ai/mastra/commit/4d2dbf509e2394361cf96aa9a001ce8758782dfc), [`6f384d6`](https://github.com/mastra-ai/mastra/commit/6f384d6e068b63f69bdd905fda0d4df2cf00e8f4), [`eddb060`](https://github.com/mastra-ai/mastra/commit/eddb0605db3f0be107e5ea392c7a407675303185), [`3015ac8`](https://github.com/mastra-ai/mastra/commit/3015ac82d0cb06e1f2332dba9376de842bfe517e), [`eddb060`](https://github.com/mastra-ai/mastra/commit/eddb0605db3f0be107e5ea392c7a407675303185), [`76d8c88`](https://github.com/mastra-ai/mastra/commit/76d8c88c20d540c94c9955c133a1c664b1a05369), [`db9a817`](https://github.com/mastra-ai/mastra/commit/db9a81797fe0aa11c38326ed2d217624b0c76521), [`b623db8`](https://github.com/mastra-ai/mastra/commit/b623db8204d097b87531733200975075be60e203), [`61d08dd`](https://github.com/mastra-ai/mastra/commit/61d08dd6302bc892f0c7b81705e1b7064b466462), [`49e59f2`](https://github.com/mastra-ai/mastra/commit/49e59f251e45de082262e3892b599f48c1ddb413), [`c7d27f6`](https://github.com/mastra-ai/mastra/commit/c7d27f650bc336af4b1a3ff3ff8346482cc79af9), [`fa0d2b4`](https://github.com/mastra-ai/mastra/commit/fa0d2b4da23cb276cf74c723d4f588dddd0cd23c), [`4168b42`](https://github.com/mastra-ai/mastra/commit/4168b42f0d810c40e077ceac9e252d03b657a9c9), [`0900c20`](https://github.com/mastra-ai/mastra/commit/0900c20592db49a330f467eff5c119212f26603d), [`ba602f5`](https://github.com/mastra-ai/mastra/commit/ba602f5f4622d6a3e6beb6d2741e3d19efe57ca9), [`642c62f`](https://github.com/mastra-ai/mastra/commit/642c62fee331eab32abc24d9af85f05221b5fe5e), [`49d3efd`](https://github.com/mastra-ai/mastra/commit/49d3efd65c8f43675eb058e6328c502598eaacb6), [`b3b2cd2`](https://github.com/mastra-ai/mastra/commit/b3b2cd292a314ed4b422dd055f8d1580c781860a), [`7ad1918`](https://github.com/mastra-ai/mastra/commit/7ad1918a72a1961bbcbd23b4a615ecd7943e98ab), [`e6b6811`](https://github.com/mastra-ai/mastra/commit/e6b6811a956c8823dc40007c10781b514aa8b68d), [`cd6088d`](https://github.com/mastra-ai/mastra/commit/cd6088d0d69a4c22f788d833ace45bf69da35b3a), [`ebf8a9a`](https://github.com/mastra-ai/mastra/commit/ebf8a9a1370105fd6bcc5706711203236a1993ff), [`5f337d4`](https://github.com/mastra-ai/mastra/commit/5f337d4423bf4a923d54ea2cd2de142d8f8b6fa6), [`99ca92b`](https://github.com/mastra-ai/mastra/commit/99ca92b60272063a5cb978628e5d286f86c37d4d), [`96b1bfb`](https://github.com/mastra-ai/mastra/commit/96b1bfbf5051cfdd7f00c7f62a04f2d938be2bec), [`ead7272`](https://github.com/mastra-ai/mastra/commit/ead727266d200b9321482ef9057aa2cdf0e63b77)]:
17
+ - @mastra/core@1.82.0
18
+ - @mastra/server@1.82.0
19
+ - @mastra/mcp@2.8.0
20
+
21
+ ## 0.2.1-alpha.0
22
+
23
+ ### Patch Changes
24
+
25
+ - `server.auth.authorize(path, method, user, context)` can now call `context.get('requestContext')` and `context.get('mastra')` on the Express, Fastify, Koa and Elysia adapters, as it already could on Hono. Values an app sets on the request context in `authorize` now reach route handlers on every adapter. ([#29069](https://github.com/mastra-ai/mastra/pull/29069))
26
+
27
+ ```ts
28
+ authorize: async (path, method, user, context) => {
29
+ context.get('requestContext').set('tenantId', user.orgId); // read it in any route handler
30
+ return appAuthorize(path, method, user, context);
31
+ };
32
+ ```
33
+
34
+ - Updated dependencies [[`0a553f0`](https://github.com/mastra-ai/mastra/commit/0a553f0f6ff4150fa5d9897b53824a647f7ddd1e), [`99ca92b`](https://github.com/mastra-ai/mastra/commit/99ca92b60272063a5cb978628e5d286f86c37d4d), [`ba602f5`](https://github.com/mastra-ai/mastra/commit/ba602f5f4622d6a3e6beb6d2741e3d19efe57ca9), [`4d3ebbd`](https://github.com/mastra-ai/mastra/commit/4d3ebbd304509acb118f319e8467fc932079e715), [`a4d1537`](https://github.com/mastra-ai/mastra/commit/a4d1537e8bac1d3634059bdbc843d787f1ac91f2), [`5a37eef`](https://github.com/mastra-ai/mastra/commit/5a37eefdafb239ccc6514018113f3fb1a025ce9b), [`41dc481`](https://github.com/mastra-ai/mastra/commit/41dc481f1b3509ec6c2a06e63caaa4f630cafa80), [`500edeb`](https://github.com/mastra-ai/mastra/commit/500edeb84e7ec665b5af26e99fced33cf3c85bfd), [`8bea966`](https://github.com/mastra-ai/mastra/commit/8bea9662c5d89c248c7311fc6cca6523d552af5d), [`0a553f0`](https://github.com/mastra-ai/mastra/commit/0a553f0f6ff4150fa5d9897b53824a647f7ddd1e), [`697ea99`](https://github.com/mastra-ai/mastra/commit/697ea99ae93f6dae203cab0f059bc5f9d8316c1e), [`cbe76c0`](https://github.com/mastra-ai/mastra/commit/cbe76c0d76e5543866f918fd41041c4d73a1a172), [`eddb060`](https://github.com/mastra-ai/mastra/commit/eddb0605db3f0be107e5ea392c7a407675303185), [`eddb060`](https://github.com/mastra-ai/mastra/commit/eddb0605db3f0be107e5ea392c7a407675303185), [`49e59f2`](https://github.com/mastra-ai/mastra/commit/49e59f251e45de082262e3892b599f48c1ddb413), [`ba602f5`](https://github.com/mastra-ai/mastra/commit/ba602f5f4622d6a3e6beb6d2741e3d19efe57ca9), [`b3b2cd2`](https://github.com/mastra-ai/mastra/commit/b3b2cd292a314ed4b422dd055f8d1580c781860a), [`99ca92b`](https://github.com/mastra-ai/mastra/commit/99ca92b60272063a5cb978628e5d286f86c37d4d)]:
35
+ - @mastra/core@1.82.0-alpha.0
36
+ - @mastra/server@1.82.0-alpha.0
37
+ - @mastra/mcp@2.8.0-alpha.0
38
+
3
39
  ## 0.2.0
4
40
 
5
41
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export { createHttpLoggingTestSuite, type HttpLoggingTestSuiteConfig } from './h
9
9
  export { createBodyLimitTestSuite, type BodyLimitTestSuiteConfig } from './body-limit-test-suite.js';
10
10
  export { createCustomRouteFGATestSuite, type CustomRouteFGATestSuiteConfig } from './custom-route-fga-test-suite.js';
11
11
  export { createDefaultTestContext, createStreamWithSensitiveData, createStreamWithUnserializableChunk, expectSerializedStreamChunks, consumeSSEStream, } from './test-helpers.js';
12
+ export { createKnowledgeRoutesTestSuite, type KnowledgeRoutesTestSuiteConfig } from './knowledge-routes-test-suite.js';
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,6BAA6B,EAAE,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC5G,OAAO,EAAE,gCAAgC,EAAE,KAAK,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AACrH,YAAY,EACV,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,KAAK,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,wBAAwB,EAAE,KAAK,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,EAAE,0BAA0B,EAAE,KAAK,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACxG,OAAO,EAAE,wBAAwB,EAAE,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,6BAA6B,EAAE,KAAK,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAElH,OAAO,EACL,wBAAwB,EACxB,6BAA6B,EAC7B,mCAAmC,EACnC,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,6BAA6B,EAAE,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC5G,OAAO,EAAE,gCAAgC,EAAE,KAAK,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AACrH,YAAY,EACV,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,KAAK,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,wBAAwB,EAAE,KAAK,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,EAAE,0BAA0B,EAAE,KAAK,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACxG,OAAO,EAAE,wBAAwB,EAAE,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,6BAA6B,EAAE,KAAK,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAElH,OAAO,EACL,wBAAwB,EACxB,6BAA6B,EAC7B,mCAAmC,EACnC,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,8BAA8B,EAAE,KAAK,8BAA8B,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
2
2
  import { registerApiRoute } from "@mastra/core/server";
3
3
  import { handleError } from "@mastra/server/handlers/error";
4
- import { HTTPException, SERVER_ROUTES, WorkflowRegistry, createRoute, serializeStreamChunk } from "@mastra/server/server-adapter";
4
+ import { HTTPException, KNOWLEDGE_ROUTES, MASTRA_KNOWLEDGE_PRINCIPALS_KEY, SERVER_ROUTES, WorkflowRegistry, createRoute, serializeStreamChunk } from "@mastra/server/server-adapter";
5
5
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
6
6
  import * as zod from "zod";
7
7
  import { z } from "zod";
@@ -32,6 +32,7 @@ import { MCPServerBase } from "@mastra/core/mcp";
32
32
  import { RequestContext } from "@mastra/core/request-context";
33
33
  import { standardSchemaToJSONSchema } from "@mastra/core/schema";
34
34
  import { z as z$2 } from "zod/v4";
35
+ import { Knowledge } from "@mastra/core/knowledge";
35
36
  // src/route-test-utils.ts
36
37
  /**
37
38
  * Normalizes a route path to ensure consistent formatting.
@@ -348,6 +349,7 @@ function getDefaultValidPathParams(route) {
348
349
  if (route.path.includes(":serverId")) params.serverId = "test-server-1";
349
350
  if (route.path.includes(":toolId") && route.path.includes("/mcp/")) params.toolId = "getWeather";
350
351
  if (route.path.includes(":eventName")) params.eventName = "ticket.created";
352
+ if (route.path.includes(":taskKey")) params.taskKey = "test-task-key";
351
353
  if (route.path.includes(":workspaceId")) params.workspaceId = "test-workspace";
352
354
  if (route.path.includes(":skillName")) params.skillName = "test-skill";
353
355
  if (route.path.includes(":referencePath")) params.referencePath = "test-reference.md";
@@ -498,12 +500,10 @@ function createRouteTestSuite(config) {
498
500
  });
499
501
  }
500
502
  // src/test-helpers.ts
501
- if (process.env.VITEST) {
502
- vi.mock("@mastra/core/vector");
503
- vi.mock("zod", async (importOriginal) => {
504
- return { ...await importOriginal() };
505
- });
506
- }
503
+ vi.mock("@mastra/core/vector");
504
+ vi.mock("zod", async (importOriginal) => {
505
+ return { ...await importOriginal() };
506
+ });
507
507
  const z$3 = zod;
508
508
  /**
509
509
  * Creates a test agent with all common mocks configured
@@ -1486,6 +1486,7 @@ function parseDatesInResponse(data, schema, currentPath = []) {
1486
1486
  }
1487
1487
  return data;
1488
1488
  }
1489
+ const registerTemporaryWorkflows = WorkflowRegistry.registerTemporaryWorkflows.bind(WorkflowRegistry);
1489
1490
  async function setupWorkflowRegistryMocks(workflows, mastra) {
1490
1491
  for (const workflow of Object.values(workflows)) {
1491
1492
  workflow.__registerMastra(mastra);
@@ -1498,20 +1499,8 @@ async function setupWorkflowRegistryMocks(workflows, mastra) {
1498
1499
  });
1499
1500
  await mockWorkflowRun(workflow);
1500
1501
  }
1501
- vi.spyOn(WorkflowRegistry, "registerTemporaryWorkflows").mockImplementation(() => {
1502
- for (const [id, workflow] of Object.entries(workflows)) {
1503
- if (mastra) {
1504
- workflow.__registerMastra(mastra);
1505
- workflow.__registerPrimitives({
1506
- logger: mastra.getLogger(),
1507
- storage: mastra.getStorage(),
1508
- agents: mastra.listAgents(),
1509
- tts: mastra.getTTS(),
1510
- vectors: mastra.listVectors()
1511
- });
1512
- }
1513
- WorkflowRegistry["additionalWorkflows"][id] = workflow;
1514
- }
1502
+ vi.spyOn(WorkflowRegistry, "registerTemporaryWorkflows").mockImplementation((_workflows, requestMastra) => {
1503
+ registerTemporaryWorkflows(workflows, requestMastra ?? mastra);
1515
1504
  });
1516
1505
  }
1517
1506
  function createLog(args) {
@@ -2168,6 +2157,10 @@ function createRouteAdapterTestSuite(config) {
2168
2157
  "/background-tasks/stream",
2169
2158
  "/agents/:agentId/observe",
2170
2159
  "/mcp/:serverId/events/:eventName/stream",
2160
+ "/mcp/:serverId/tasks/find",
2161
+ "/mcp/:serverId/tasks/:taskKey/cancel",
2162
+ "/mcp/:serverId/tasks/:taskKey/input",
2163
+ "/background-tasks/:backgroundTaskId/resume",
2171
2164
  "/agents/:agentId/recover",
2172
2165
  "/agents/:agentId/runs/:runId/abort",
2173
2166
  "/agents/:agentId/plans/file",
@@ -5632,6 +5625,103 @@ function createCustomRouteFGATestSuite(config) {
5632
5625
  });
5633
5626
  });
5634
5627
  }
5635
- export { consumeSSEStream, createBodyLimitTestSuite, createCustomRouteFGATestSuite, createDefaultTestContext, createDurableDisconnectTestSuite, createHttpLoggingTestSuite, createMCPRouteTestSuite, createMCPTransportTestSuite, createMultipartTestSuite, createRouteAdapterTestSuite, createStreamWithSensitiveData, createStreamWithUnserializableChunk, createStructuredWakeTestSuite, expectSerializedStreamChunks };
5628
+ // src/knowledge-routes-test-suite.ts
5629
+ /**
5630
+ * The opt-in Knowledge routes on every adapter: RBAC `knowledge:read` gates them, the Knowledge principals
5631
+ * `authorize` sets through `context.get('requestContext')` reach the handler (no mapping is refused), and a
5632
+ * repeated query param (`scopeId`) arrives as a list.
5633
+ */
5634
+ function createKnowledgeRoutesTestSuite(config) {
5635
+ const { suiteName = "Knowledge routes", startServer } = config;
5636
+ describe(suiteName, () => {
5637
+ let close;
5638
+ afterEach(async () => {
5639
+ await close?.();
5640
+ close = void 0;
5641
+ });
5642
+ const setup = async () => {
5643
+ const knowledge = new Knowledge({
5644
+ id: "kb",
5645
+ scopes: {},
5646
+ storage: new InMemoryStore({ id: "kb" })
5647
+ });
5648
+ const store = await knowledge.getStorage();
5649
+ const provenance = { author: "test" };
5650
+ const scopes = {};
5651
+ for (const [team, page] of [
5652
+ ["support", "Payments runbook"],
5653
+ ["eng", "Payments service"],
5654
+ ["sales", "Payments pricing"]
5655
+ ]) {
5656
+ const { scope } = await store.materializeScope({
5657
+ address: `team:${team}`,
5658
+ declaration: "team:$teamId",
5659
+ name: team,
5660
+ provenance
5661
+ });
5662
+ scopes[team] = scope.id;
5663
+ await store.createPage({
5664
+ parentId: scope.id,
5665
+ name: page,
5666
+ provenance
5667
+ });
5668
+ }
5669
+ const permissions = {
5670
+ "reader-token": ["knowledge:read"],
5671
+ "unmapped-token": ["knowledge:read"],
5672
+ "other-token": []
5673
+ };
5674
+ const mastra = new Mastra({
5675
+ logger: false,
5676
+ knowledge: { main: knowledge },
5677
+ server: { apiRoutes: [...KNOWLEDGE_ROUTES] }
5678
+ });
5679
+ const originalGetServer = mastra.getServer.bind(mastra);
5680
+ mastra.getServer = () => ({
5681
+ ...originalGetServer(),
5682
+ rbac: {
5683
+ getRoles: async () => ["member"],
5684
+ getPermissions: async (user) => permissions[user.id] ?? []
5685
+ },
5686
+ auth: {
5687
+ authenticateToken: async (token) => token in permissions ? { id: token } : null,
5688
+ authorize: async (_path, _method, user, context) => {
5689
+ if (user.id === "reader-token") context.get("requestContext").set(MASTRA_KNOWLEDGE_PRINCIPALS_KEY, "all");
5690
+ return true;
5691
+ }
5692
+ }
5693
+ });
5694
+ const server = await startServer(mastra);
5695
+ close = server.close;
5696
+ const get = (path, token) => server.request(`/api/knowledge/main${path}`, token ? { headers: { authorization: `Bearer ${token}` } } : {});
5697
+ return {
5698
+ get,
5699
+ scopes
5700
+ };
5701
+ };
5702
+ it("serves a reader authorize mapped to Knowledge principals and refuses everyone else", async () => {
5703
+ const { get } = await setup();
5704
+ const roots = await get("/tree", "reader-token");
5705
+ expect(roots.status).toBe(200);
5706
+ const body = await roots.json();
5707
+ expect(body.pages.map((page) => page.name).sort()).toEqual([
5708
+ "eng",
5709
+ "sales",
5710
+ "support"
5711
+ ]);
5712
+ expect((await get("/tree", "unmapped-token")).status).toBe(403);
5713
+ expect((await get("/tree", "other-token")).status).toBe(403);
5714
+ expect((await get("/tree")).status).toBe(401);
5715
+ });
5716
+ it("reads a repeated scopeId param as a list", async () => {
5717
+ const { get, scopes } = await setup();
5718
+ const res = await get(`/search?q=payments&scopeId=${scopes.support}&scopeId=${scopes.eng}`, "reader-token");
5719
+ expect(res.status).toBe(200);
5720
+ const body = await res.json();
5721
+ expect(body.results.map((hit) => hit.page.name).sort()).toEqual(["Payments runbook", "Payments service"]);
5722
+ });
5723
+ });
5724
+ }
5725
+ export { consumeSSEStream, createBodyLimitTestSuite, createCustomRouteFGATestSuite, createDefaultTestContext, createDurableDisconnectTestSuite, createHttpLoggingTestSuite, createKnowledgeRoutesTestSuite, createMCPRouteTestSuite, createMCPTransportTestSuite, createMultipartTestSuite, createRouteAdapterTestSuite, createStreamWithSensitiveData, createStreamWithUnserializableChunk, createStructuredWakeTestSuite, expectSerializedStreamChunks };
5636
5726
 
5637
5727
  //# sourceMappingURL=index.js.map