@slates/test 1.0.0-rc.4 → 1.0.0-rc.6

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 CHANGED
@@ -42,6 +42,24 @@ module.exports = __toCommonJS(index_exports);
42
42
  var import_client = require("@slates/client");
43
43
  var import_profiles = require("@slates/profiles");
44
44
  var import_promises = require("fs/promises");
45
+ var selectProfileAuth = (profile, authMethodId) => {
46
+ if (!profile || !authMethodId) {
47
+ return profile;
48
+ }
49
+ let selectedAuth = profile.auth[authMethodId];
50
+ if (!selectedAuth) {
51
+ let availableAuthMethods = Object.keys(profile.auth);
52
+ throw new Error(
53
+ `No stored authentication found for auth method "${authMethodId}" in profile "${profile.name}".` + (availableAuthMethods.length > 0 ? ` Available auth methods: ${availableAuthMethods.join(", ")}.` : " No auth methods are stored for this profile.")
54
+ );
55
+ }
56
+ return {
57
+ ...profile,
58
+ auth: {
59
+ [selectedAuth.authMethodId]: selectedAuth
60
+ }
61
+ };
62
+ };
45
63
  var getVitestExpect = () => {
46
64
  let maybeExpect = globalThis.expect;
47
65
  if (!maybeExpect) {
@@ -58,10 +76,15 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
58
76
  storePath: parsed.storePath,
59
77
  rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
60
78
  });
61
- let profile2 = store2.getProfile(opts.profile ?? parsed.profileId ?? null);
79
+ let authMethodId2 = parsed.authMethodId ?? null;
80
+ let profile2 = selectProfileAuth(
81
+ store2.getProfile(opts.profile ?? parsed.profileId ?? null),
82
+ authMethodId2
83
+ );
62
84
  return {
63
85
  integration: parsed.integration ?? store2.scope?.key ?? null,
64
86
  profileId: profile2?.id ?? parsed.profileId ?? null,
87
+ authMethodId: authMethodId2,
65
88
  profile: profile2,
66
89
  rootDir: parsed.rootDir ?? store2.rootDir,
67
90
  storePath: parsed.storePath,
@@ -73,10 +96,12 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
73
96
  rootDir: process.env.SLATES_STORE_ROOT_DIR
74
97
  }) : await (0, import_profiles.openSlatesCliStore)({ cwd: opts.cwd });
75
98
  let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
76
- let profile = store.getProfile(profileId);
99
+ let authMethodId = null;
100
+ let profile = selectProfileAuth(store.getProfile(profileId), authMethodId);
77
101
  return {
78
102
  integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
79
103
  profileId: profile?.id ?? null,
104
+ authMethodId,
80
105
  profile,
81
106
  rootDir: store.rootDir,
82
107
  storePath: store.storePath,
@@ -179,10 +204,16 @@ var expectSlateContract = async (d) => {
179
204
  expect(contract.authMethods.map((method) => method.id)).toEqual(d.authMethodIds);
180
205
  }
181
206
  for (let tool of d.tools ?? []) {
182
- expectActionMatches(contract.tools.find((action) => action.id === tool.id), tool);
207
+ expectActionMatches(
208
+ contract.tools.find((action) => action.id === tool.id),
209
+ tool
210
+ );
183
211
  }
184
212
  for (let trigger of d.triggers ?? []) {
185
- expectActionMatches(contract.triggers.find((action) => action.id === trigger.id), trigger);
213
+ expectActionMatches(
214
+ contract.triggers.find((action) => action.id === trigger.id),
215
+ trigger
216
+ );
186
217
  }
187
218
  return contract;
188
219
  };
package/dist/index.d.cts CHANGED
@@ -6,6 +6,7 @@ import { SlatesProfileRecord } from '@slates/profiles';
6
6
  interface SlatesRuntimeContext {
7
7
  integration: string | null;
8
8
  profileId: string | null;
9
+ authMethodId: string | null;
9
10
  profile: SlatesProfileRecord | null;
10
11
  rootDir: string;
11
12
  storePath: string;
@@ -52,7 +53,7 @@ declare let expectToolCall: (d: {
52
53
  url: string;
53
54
  } | {
54
55
  type: "content";
55
- encoding: "base64" | "utf-8";
56
+ encoding: "utf-8" | "base64";
56
57
  content: string;
57
58
  };
58
59
  mimeType?: string | undefined;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import { SlatesProfileRecord } from '@slates/profiles';
6
6
  interface SlatesRuntimeContext {
7
7
  integration: string | null;
8
8
  profileId: string | null;
9
+ authMethodId: string | null;
9
10
  profile: SlatesProfileRecord | null;
10
11
  rootDir: string;
11
12
  storePath: string;
@@ -52,7 +53,7 @@ declare let expectToolCall: (d: {
52
53
  url: string;
53
54
  } | {
54
55
  type: "content";
55
- encoding: "base64" | "utf-8";
56
+ encoding: "utf-8" | "base64";
56
57
  content: string;
57
58
  };
58
59
  mimeType?: string | undefined;
@@ -9,6 +9,24 @@ import {
9
9
  openSlatesCliStore
10
10
  } from "@slates/profiles";
11
11
  import { readFile } from "fs/promises";
12
+ var selectProfileAuth = (profile, authMethodId) => {
13
+ if (!profile || !authMethodId) {
14
+ return profile;
15
+ }
16
+ let selectedAuth = profile.auth[authMethodId];
17
+ if (!selectedAuth) {
18
+ let availableAuthMethods = Object.keys(profile.auth);
19
+ throw new Error(
20
+ `No stored authentication found for auth method "${authMethodId}" in profile "${profile.name}".` + (availableAuthMethods.length > 0 ? ` Available auth methods: ${availableAuthMethods.join(", ")}.` : " No auth methods are stored for this profile.")
21
+ );
22
+ }
23
+ return {
24
+ ...profile,
25
+ auth: {
26
+ [selectedAuth.authMethodId]: selectedAuth
27
+ }
28
+ };
29
+ };
12
30
  var getVitestExpect = () => {
13
31
  let maybeExpect = globalThis.expect;
14
32
  if (!maybeExpect) {
@@ -25,10 +43,15 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
25
43
  storePath: parsed.storePath,
26
44
  rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
27
45
  });
28
- let profile2 = store2.getProfile(opts.profile ?? parsed.profileId ?? null);
46
+ let authMethodId2 = parsed.authMethodId ?? null;
47
+ let profile2 = selectProfileAuth(
48
+ store2.getProfile(opts.profile ?? parsed.profileId ?? null),
49
+ authMethodId2
50
+ );
29
51
  return {
30
52
  integration: parsed.integration ?? store2.scope?.key ?? null,
31
53
  profileId: profile2?.id ?? parsed.profileId ?? null,
54
+ authMethodId: authMethodId2,
32
55
  profile: profile2,
33
56
  rootDir: parsed.rootDir ?? store2.rootDir,
34
57
  storePath: parsed.storePath,
@@ -40,10 +63,12 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
40
63
  rootDir: process.env.SLATES_STORE_ROOT_DIR
41
64
  }) : await openSlatesCliStore({ cwd: opts.cwd });
42
65
  let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
43
- let profile = store.getProfile(profileId);
66
+ let authMethodId = null;
67
+ let profile = selectProfileAuth(store.getProfile(profileId), authMethodId);
44
68
  return {
45
69
  integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
46
70
  profileId: profile?.id ?? null,
71
+ authMethodId,
47
72
  profile,
48
73
  rootDir: store.rootDir,
49
74
  storePath: store.storePath,
@@ -146,10 +171,16 @@ var expectSlateContract = async (d) => {
146
171
  expect(contract.authMethods.map((method) => method.id)).toEqual(d.authMethodIds);
147
172
  }
148
173
  for (let tool of d.tools ?? []) {
149
- expectActionMatches(contract.tools.find((action) => action.id === tool.id), tool);
174
+ expectActionMatches(
175
+ contract.tools.find((action) => action.id === tool.id),
176
+ tool
177
+ );
150
178
  }
151
179
  for (let trigger of d.triggers ?? []) {
152
- expectActionMatches(contract.triggers.find((action) => action.id === trigger.id), trigger);
180
+ expectActionMatches(
181
+ contract.triggers.find((action) => action.id === trigger.id),
182
+ trigger
183
+ );
153
184
  }
154
185
  return contract;
155
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/test",
3
- "version": "1.0.0-rc.4",
3
+ "version": "1.0.0-rc.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,11 +40,11 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@lowerdeck/testing-tools": "latest",
43
- "@slates/client": "1.0.0-rc.6",
44
- "@slates/profiles": "1.0.0-rc.4"
43
+ "@slates/client": "1.0.0-rc.8",
44
+ "@slates/profiles": "1.0.0-rc.6"
45
45
  },
46
46
  "devDependencies": {
47
- "@slates/provider": "1.0.0-rc.10",
47
+ "@slates/provider": "1.0.0-rc.12",
48
48
  "@slates/tsconfig": "1.0.0-rc.1",
49
49
  "typescript": "5.8.2",
50
50
  "vitest": "^3.1.2",
package/src/index.test.ts CHANGED
@@ -40,6 +40,7 @@ afterEach(async () => {
40
40
  delete process.env.SLATES_INTEGRATION;
41
41
  delete process.env.SLATES_PROFILE_ID;
42
42
  delete process.env.SLATES_STORE_PATH;
43
+ delete process.env.SLATES_STORE_ROOT_DIR;
43
44
  delete process.env.SLATES_TEST_CONTEXT_PATH;
44
45
  await Promise.all(tempDirs.splice(0).map(dir => rm(dir, { recursive: true, force: true })));
45
46
  });
@@ -304,6 +305,66 @@ describe('@slates/test', () => {
304
305
  expect(context.storePath).toBe(store.storePath);
305
306
  });
306
307
 
308
+ it('loads only the selected auth method from the runtime context', async () => {
309
+ let cwd = await createTempDir();
310
+ let store = await openSlatesCliStore({
311
+ cwd,
312
+ scope: {
313
+ key: 'integrations/demo',
314
+ name: 'demo'
315
+ }
316
+ });
317
+ let profile = store.upsertProfile({
318
+ name: 'Demo',
319
+ target: {
320
+ type: 'local',
321
+ entry: './demo-slate.mjs',
322
+ exportName: 'provider'
323
+ }
324
+ });
325
+ store.upsertAuth(profile.id, {
326
+ authMethodId: 'oauth',
327
+ authMethodName: 'Bot OAuth',
328
+ authType: 'auth.oauth',
329
+ input: {},
330
+ output: {
331
+ token: 'bot-token'
332
+ },
333
+ scopes: ['chat:write']
334
+ });
335
+ store.upsertAuth(profile.id, {
336
+ authMethodId: 'user_oauth',
337
+ authMethodName: 'User OAuth',
338
+ authType: 'auth.oauth',
339
+ input: {},
340
+ output: {
341
+ token: 'user-token'
342
+ },
343
+ scopes: ['search:read']
344
+ });
345
+ await store.save();
346
+
347
+ let runtimeContextPath = path.join(cwd, 'runtime.json');
348
+ await writeFile(
349
+ runtimeContextPath,
350
+ JSON.stringify({
351
+ integration: 'integrations/demo',
352
+ profileId: profile.id,
353
+ authMethodId: 'user_oauth',
354
+ storePath: store.storePath,
355
+ cliDir: store.dirPath
356
+ }),
357
+ 'utf-8'
358
+ );
359
+
360
+ process.env.SLATES_TEST_CONTEXT_PATH = runtimeContextPath;
361
+
362
+ let context = await loadSlatesRuntimeContext({ cwd });
363
+ expect(context.authMethodId).toBe('user_oauth');
364
+ expect(Object.keys(context.profile?.auth ?? {})).toEqual(['user_oauth']);
365
+ expect(context.profile?.auth.user_oauth?.output.token).toBe('user-token');
366
+ });
367
+
307
368
  it('creates local slate clients and asserts provider contracts', async () => {
308
369
  let client = createLocalSlateTestClient({
309
370
  slate: createDemoSlate(),
package/src/runtime.ts CHANGED
@@ -14,6 +14,7 @@ import { readFile } from 'fs/promises';
14
14
  export interface SlatesRuntimeContext {
15
15
  integration: string | null;
16
16
  profileId: string | null;
17
+ authMethodId: string | null;
17
18
  profile: SlatesProfileRecord | null;
18
19
  rootDir: string;
19
20
  storePath: string;
@@ -24,6 +25,30 @@ export type SlatesTestClient = ReturnType<typeof createSlatesClient>;
24
25
 
25
26
  type LocalSlate = Parameters<typeof createLocalSlateTransport>[0]['slate'];
26
27
 
28
+ let selectProfileAuth = (profile: SlatesProfileRecord | null, authMethodId: string | null) => {
29
+ if (!profile || !authMethodId) {
30
+ return profile;
31
+ }
32
+
33
+ let selectedAuth = profile.auth[authMethodId];
34
+ if (!selectedAuth) {
35
+ let availableAuthMethods = Object.keys(profile.auth);
36
+ throw new Error(
37
+ `No stored authentication found for auth method "${authMethodId}" in profile "${profile.name}".` +
38
+ (availableAuthMethods.length > 0
39
+ ? ` Available auth methods: ${availableAuthMethods.join(', ')}.`
40
+ : ' No auth methods are stored for this profile.')
41
+ );
42
+ }
43
+
44
+ return {
45
+ ...profile,
46
+ auth: {
47
+ [selectedAuth.authMethodId]: selectedAuth
48
+ }
49
+ };
50
+ };
51
+
27
52
  export interface ExpectedSlateAction {
28
53
  id: string;
29
54
  name?: string;
@@ -34,8 +59,9 @@ export interface ExpectedSlateAction {
34
59
  }
35
60
 
36
61
  export let getVitestExpect = () => {
37
- let maybeExpect = (globalThis as typeof globalThis & { expect?: typeof import('vitest').expect })
38
- .expect;
62
+ let maybeExpect = (
63
+ globalThis as typeof globalThis & { expect?: typeof import('vitest').expect }
64
+ ).expect;
39
65
 
40
66
  if (!maybeExpect) {
41
67
  throw new Error('Vitest expect is not available in the current runtime.');
@@ -56,6 +82,7 @@ export let loadSlatesRuntimeContext = async (
56
82
  let parsed = JSON.parse(raw) as {
57
83
  integration?: string | null;
58
84
  profileId: string | null;
85
+ authMethodId?: string | null;
59
86
  rootDir?: string;
60
87
  storePath: string;
61
88
  cliDir: string;
@@ -64,11 +91,16 @@ export let loadSlatesRuntimeContext = async (
64
91
  storePath: parsed.storePath,
65
92
  rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
66
93
  });
67
- let profile = store.getProfile(opts.profile ?? parsed.profileId ?? null);
94
+ let authMethodId = parsed.authMethodId ?? null;
95
+ let profile = selectProfileAuth(
96
+ store.getProfile(opts.profile ?? parsed.profileId ?? null),
97
+ authMethodId
98
+ );
68
99
 
69
100
  return {
70
101
  integration: parsed.integration ?? store.scope?.key ?? null,
71
102
  profileId: profile?.id ?? parsed.profileId ?? null,
103
+ authMethodId,
72
104
  profile,
73
105
  rootDir: parsed.rootDir ?? store.rootDir,
74
106
  storePath: parsed.storePath,
@@ -83,11 +115,13 @@ export let loadSlatesRuntimeContext = async (
83
115
  })
84
116
  : await openSlatesCliStore({ cwd: opts.cwd });
85
117
  let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
86
- let profile = store.getProfile(profileId);
118
+ let authMethodId = null;
119
+ let profile = selectProfileAuth(store.getProfile(profileId), authMethodId);
87
120
 
88
121
  return {
89
122
  integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
90
123
  profileId: profile?.id ?? null,
124
+ authMethodId,
91
125
  profile,
92
126
  rootDir: store.rootDir,
93
127
  storePath: store.storePath,
@@ -176,7 +210,10 @@ export let getSlateContract = async (client: SlatesTestClient) => {
176
210
  };
177
211
  };
178
212
 
179
- let expectActionMatches = (actual: Record<string, any> | undefined, expected: ExpectedSlateAction) => {
213
+ let expectActionMatches = (
214
+ actual: Record<string, any> | undefined,
215
+ expected: ExpectedSlateAction
216
+ ) => {
180
217
  let expect = getVitestExpect();
181
218
  expect(actual).toBeTruthy();
182
219
  expect(actual?.id).toBe(expected.id);
@@ -243,11 +280,17 @@ export let expectSlateContract = async (d: {
243
280
  }
244
281
 
245
282
  for (let tool of d.tools ?? []) {
246
- expectActionMatches(contract.tools.find(action => action.id === tool.id), tool);
283
+ expectActionMatches(
284
+ contract.tools.find(action => action.id === tool.id),
285
+ tool
286
+ );
247
287
  }
248
288
 
249
289
  for (let trigger of d.triggers ?? []) {
250
- expectActionMatches(contract.triggers.find(action => action.id === trigger.id), trigger);
290
+ expectActionMatches(
291
+ contract.triggers.find(action => action.id === trigger.id),
292
+ trigger
293
+ );
251
294
  }
252
295
 
253
296
  return contract;