@slates/test 1.0.0-rc.3 → 1.0.0-rc.4
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/config.cjs +31 -0
- package/dist/config.d.cts +6 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.module.js +6 -0
- package/dist/index.cjs +33 -13
- package/dist/index.d.cts +42 -4
- package/dist/index.d.ts +42 -4
- package/dist/index.module.js +30 -13
- package/package.json +17 -9
- package/src/config.ts +5 -0
- package/src/index.test.ts +87 -3
- package/src/index.ts +1 -332
- package/src/runtime.ts +352 -0
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/config.ts
|
|
21
|
+
var config_exports = {};
|
|
22
|
+
__export(config_exports, {
|
|
23
|
+
createSlatesVitestConfig: () => createSlatesVitestConfig
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(config_exports);
|
|
26
|
+
var import_testing_tools = require("@lowerdeck/testing-tools");
|
|
27
|
+
var createSlatesVitestConfig = (config = {}) => (0, import_testing_tools.createVitestConfig)(config);
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
createSlatesVitestConfig
|
|
31
|
+
});
|
package/dist/config.d.ts
ADDED
package/dist/index.cjs
CHANGED
|
@@ -22,25 +22,27 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
createLocalSlateTestClient: () => createLocalSlateTestClient,
|
|
24
24
|
createSlatesTestClient: () => createSlatesTestClient,
|
|
25
|
-
createSlatesVitestConfig: () => createSlatesVitestConfig,
|
|
26
25
|
expectSlateContract: () => expectSlateContract,
|
|
27
26
|
expectSlateError: () => expectSlateError,
|
|
28
27
|
expectToolCall: () => expectToolCall,
|
|
29
28
|
getSlateContract: () => getSlateContract,
|
|
29
|
+
getVitestExpect: () => getVitestExpect,
|
|
30
30
|
handleSlateTriggerWebhook: () => handleSlateTriggerWebhook,
|
|
31
31
|
loadSlatesProfile: () => loadSlatesProfile,
|
|
32
32
|
loadSlatesRuntimeContext: () => loadSlatesRuntimeContext,
|
|
33
33
|
mapSlateTriggerEvent: () => mapSlateTriggerEvent,
|
|
34
|
+
pollSlateTriggerEvents: () => pollSlateTriggerEvents,
|
|
34
35
|
registerSlateTriggerWebhook: () => registerSlateTriggerWebhook,
|
|
35
36
|
unregisterSlateTriggerWebhook: () => unregisterSlateTriggerWebhook,
|
|
36
37
|
withSlateProfile: () => withSlateProfile
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
// src/runtime.ts
|
|
40
42
|
var import_client = require("@slates/client");
|
|
41
43
|
var import_profiles = require("@slates/profiles");
|
|
42
44
|
var import_promises = require("fs/promises");
|
|
43
|
-
var
|
|
45
|
+
var getVitestExpect = () => {
|
|
44
46
|
let maybeExpect = globalThis.expect;
|
|
45
47
|
if (!maybeExpect) {
|
|
46
48
|
throw new Error("Vitest expect is not available in the current runtime.");
|
|
@@ -52,23 +54,31 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
|
|
|
52
54
|
if (runtimeContextPath) {
|
|
53
55
|
let raw = await (0, import_promises.readFile)(runtimeContextPath, "utf-8");
|
|
54
56
|
let parsed = JSON.parse(raw);
|
|
55
|
-
let store2 = await (0, import_profiles.openSlatesCliStore)({
|
|
57
|
+
let store2 = await (0, import_profiles.openSlatesCliStore)({
|
|
58
|
+
storePath: parsed.storePath,
|
|
59
|
+
rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
|
|
60
|
+
});
|
|
56
61
|
let profile2 = store2.getProfile(opts.profile ?? parsed.profileId ?? null);
|
|
57
62
|
return {
|
|
58
63
|
integration: parsed.integration ?? store2.scope?.key ?? null,
|
|
59
64
|
profileId: profile2?.id ?? parsed.profileId ?? null,
|
|
60
65
|
profile: profile2,
|
|
66
|
+
rootDir: parsed.rootDir ?? store2.rootDir,
|
|
61
67
|
storePath: parsed.storePath,
|
|
62
68
|
cliDir: parsed.cliDir
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
|
-
let store = process.env.SLATES_STORE_PATH ? await (0, import_profiles.openSlatesCliStore)({
|
|
71
|
+
let store = process.env.SLATES_STORE_PATH ? await (0, import_profiles.openSlatesCliStore)({
|
|
72
|
+
storePath: process.env.SLATES_STORE_PATH,
|
|
73
|
+
rootDir: process.env.SLATES_STORE_ROOT_DIR
|
|
74
|
+
}) : await (0, import_profiles.openSlatesCliStore)({ cwd: opts.cwd });
|
|
66
75
|
let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
|
|
67
76
|
let profile = store.getProfile(profileId);
|
|
68
77
|
return {
|
|
69
78
|
integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
|
|
70
79
|
profileId: profile?.id ?? null,
|
|
71
80
|
profile,
|
|
81
|
+
rootDir: store.rootDir,
|
|
72
82
|
storePath: store.storePath,
|
|
73
83
|
cliDir: store.dirPath
|
|
74
84
|
};
|
|
@@ -85,7 +95,10 @@ var createSlatesTestClient = async (opts = {}) => {
|
|
|
85
95
|
if (!context.profile) {
|
|
86
96
|
throw new Error("No Slates profile is available for the current test context.");
|
|
87
97
|
}
|
|
88
|
-
let store = await (0, import_profiles.openSlatesCliStore)({
|
|
98
|
+
let store = await (0, import_profiles.openSlatesCliStore)({
|
|
99
|
+
storePath: context.storePath,
|
|
100
|
+
rootDir: context.rootDir
|
|
101
|
+
});
|
|
89
102
|
return (0, import_profiles.createSlatesClientFromProfile)(context.profile, { cwd: opts.cwd, store });
|
|
90
103
|
};
|
|
91
104
|
var withSlateProfile = async (profileName, cb) => {
|
|
@@ -93,7 +106,7 @@ var withSlateProfile = async (profileName, cb) => {
|
|
|
93
106
|
return cb({ profile });
|
|
94
107
|
};
|
|
95
108
|
var expectToolCall = async (d) => {
|
|
96
|
-
let expect =
|
|
109
|
+
let expect = getVitestExpect();
|
|
97
110
|
let client = d.client ?? await createSlatesTestClient({ profile: d.profile });
|
|
98
111
|
let result = await client.invokeTool(d.toolId, d.input);
|
|
99
112
|
if (d.output) {
|
|
@@ -123,7 +136,7 @@ var getSlateContract = async (client) => {
|
|
|
123
136
|
};
|
|
124
137
|
};
|
|
125
138
|
var expectActionMatches = (actual, expected) => {
|
|
126
|
-
let expect =
|
|
139
|
+
let expect = getVitestExpect();
|
|
127
140
|
expect(actual).toBeTruthy();
|
|
128
141
|
expect(actual?.id).toBe(expected.id);
|
|
129
142
|
if (expected.name !== void 0) {
|
|
@@ -145,7 +158,7 @@ var expectActionMatches = (actual, expected) => {
|
|
|
145
158
|
}
|
|
146
159
|
};
|
|
147
160
|
var expectSlateContract = async (d) => {
|
|
148
|
-
let expect =
|
|
161
|
+
let expect = getVitestExpect();
|
|
149
162
|
let contract = await getSlateContract(d.client);
|
|
150
163
|
if (d.provider) {
|
|
151
164
|
expect(contract.provider.id).toBe(d.provider.id);
|
|
@@ -174,6 +187,13 @@ var expectSlateContract = async (d) => {
|
|
|
174
187
|
return contract;
|
|
175
188
|
};
|
|
176
189
|
var registerSlateTriggerWebhook = async (d) => d.client.registerTriggerWebhook(d.triggerId, d.webhookBaseUrl);
|
|
190
|
+
var pollSlateTriggerEvents = async (d) => {
|
|
191
|
+
d.client.ensureSession();
|
|
192
|
+
return d.client.request("slates/action.trigger.poll_events", {
|
|
193
|
+
actionId: d.triggerId,
|
|
194
|
+
state: d.state ?? null
|
|
195
|
+
});
|
|
196
|
+
};
|
|
177
197
|
var handleSlateTriggerWebhook = async (d) => d.client.handleTriggerWebhook({
|
|
178
198
|
actionId: d.triggerId,
|
|
179
199
|
url: d.url,
|
|
@@ -189,7 +209,7 @@ var unregisterSlateTriggerWebhook = async (d) => d.client.unregisterTriggerWebho
|
|
|
189
209
|
state: d.state
|
|
190
210
|
});
|
|
191
211
|
var mapSlateTriggerEvent = async (d) => {
|
|
192
|
-
let expect =
|
|
212
|
+
let expect = getVitestExpect();
|
|
193
213
|
let result = await d.client.mapTriggerEvent(d.triggerId, d.input);
|
|
194
214
|
if (d.type !== void 0) {
|
|
195
215
|
expect(result.type).toBe(d.type);
|
|
@@ -200,7 +220,7 @@ var mapSlateTriggerEvent = async (d) => {
|
|
|
200
220
|
return result;
|
|
201
221
|
};
|
|
202
222
|
var expectSlateError = async (run, expected) => {
|
|
203
|
-
let expect =
|
|
223
|
+
let expect = getVitestExpect();
|
|
204
224
|
try {
|
|
205
225
|
await (typeof run === "function" ? run() : run);
|
|
206
226
|
} catch (error) {
|
|
@@ -220,20 +240,20 @@ var expectSlateError = async (run, expected) => {
|
|
|
220
240
|
}
|
|
221
241
|
throw new Error("Expected the operation to fail, but it completed successfully.");
|
|
222
242
|
};
|
|
223
|
-
var createSlatesVitestConfig = (config = {}) => (0, import_testing_tools.createVitestConfig)(config);
|
|
224
243
|
// Annotate the CommonJS export names for ESM import in node:
|
|
225
244
|
0 && (module.exports = {
|
|
226
245
|
createLocalSlateTestClient,
|
|
227
246
|
createSlatesTestClient,
|
|
228
|
-
createSlatesVitestConfig,
|
|
229
247
|
expectSlateContract,
|
|
230
248
|
expectSlateError,
|
|
231
249
|
expectToolCall,
|
|
232
250
|
getSlateContract,
|
|
251
|
+
getVitestExpect,
|
|
233
252
|
handleSlateTriggerWebhook,
|
|
234
253
|
loadSlatesProfile,
|
|
235
254
|
loadSlatesRuntimeContext,
|
|
236
255
|
mapSlateTriggerEvent,
|
|
256
|
+
pollSlateTriggerEvents,
|
|
237
257
|
registerSlateTriggerWebhook,
|
|
238
258
|
unregisterSlateTriggerWebhook,
|
|
239
259
|
withSlateProfile
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as vite from 'vite';
|
|
2
1
|
import * as _slates_client from '@slates/client';
|
|
3
2
|
import { createSlatesClient, createLocalSlateTransport, SlatesProtocolClientOptions } from '@slates/client';
|
|
4
|
-
import
|
|
3
|
+
import * as vitest from 'vitest';
|
|
5
4
|
import { SlatesProfileRecord } from '@slates/profiles';
|
|
6
5
|
|
|
7
6
|
interface SlatesRuntimeContext {
|
|
8
7
|
integration: string | null;
|
|
9
8
|
profileId: string | null;
|
|
10
9
|
profile: SlatesProfileRecord | null;
|
|
10
|
+
rootDir: string;
|
|
11
11
|
storePath: string;
|
|
12
12
|
cliDir: string;
|
|
13
13
|
}
|
|
@@ -21,6 +21,7 @@ interface ExpectedSlateAction {
|
|
|
21
21
|
destructive?: boolean;
|
|
22
22
|
invocationType?: 'polling' | 'webhook';
|
|
23
23
|
}
|
|
24
|
+
declare let getVitestExpect: () => vitest.ExpectStatic;
|
|
24
25
|
declare let loadSlatesRuntimeContext: (opts?: {
|
|
25
26
|
cwd?: string;
|
|
26
27
|
profile?: string | null;
|
|
@@ -221,6 +222,7 @@ declare let getSlateContract: (client: SlatesTestClient) => Promise<{
|
|
|
221
222
|
id: string;
|
|
222
223
|
title: string;
|
|
223
224
|
description?: string | undefined;
|
|
225
|
+
defaultChecked?: boolean | undefined;
|
|
224
226
|
}[] | undefined;
|
|
225
227
|
}[];
|
|
226
228
|
configSchema: Record<string, any>;
|
|
@@ -368,6 +370,7 @@ declare let expectSlateContract: (d: {
|
|
|
368
370
|
id: string;
|
|
369
371
|
title: string;
|
|
370
372
|
description?: string | undefined;
|
|
373
|
+
defaultChecked?: boolean | undefined;
|
|
371
374
|
}[] | undefined;
|
|
372
375
|
}[];
|
|
373
376
|
configSchema: Record<string, any>;
|
|
@@ -408,6 +411,42 @@ declare let registerSlateTriggerWebhook: (d: {
|
|
|
408
411
|
} | undefined;
|
|
409
412
|
}[] | undefined;
|
|
410
413
|
}>;
|
|
414
|
+
declare let pollSlateTriggerEvents: (d: {
|
|
415
|
+
client: SlatesTestClient;
|
|
416
|
+
triggerId: string;
|
|
417
|
+
state?: any;
|
|
418
|
+
}) => Promise<{
|
|
419
|
+
inputs: Record<string, any>[];
|
|
420
|
+
updatedState?: any;
|
|
421
|
+
requestTraces?: {
|
|
422
|
+
startedAt: string;
|
|
423
|
+
durationMs: number;
|
|
424
|
+
request: {
|
|
425
|
+
method: string;
|
|
426
|
+
url: string;
|
|
427
|
+
headers?: Record<string, string> | undefined;
|
|
428
|
+
body?: {
|
|
429
|
+
text: string;
|
|
430
|
+
contentType?: string | undefined;
|
|
431
|
+
truncated?: boolean | undefined;
|
|
432
|
+
} | undefined;
|
|
433
|
+
};
|
|
434
|
+
response?: {
|
|
435
|
+
status: number;
|
|
436
|
+
statusText?: string | undefined;
|
|
437
|
+
headers?: Record<string, string> | undefined;
|
|
438
|
+
body?: {
|
|
439
|
+
text: string;
|
|
440
|
+
contentType?: string | undefined;
|
|
441
|
+
truncated?: boolean | undefined;
|
|
442
|
+
} | undefined;
|
|
443
|
+
} | undefined;
|
|
444
|
+
error?: {
|
|
445
|
+
message: string;
|
|
446
|
+
code?: string | undefined;
|
|
447
|
+
} | undefined;
|
|
448
|
+
}[] | undefined;
|
|
449
|
+
}>;
|
|
411
450
|
declare let handleSlateTriggerWebhook: (d: {
|
|
412
451
|
client: SlatesTestClient;
|
|
413
452
|
triggerId: string;
|
|
@@ -524,6 +563,5 @@ declare let mapSlateTriggerEvent: (d: {
|
|
|
524
563
|
}[] | undefined;
|
|
525
564
|
}>;
|
|
526
565
|
declare let expectSlateError: (run: Promise<unknown> | (() => Promise<unknown>), expected: Record<string, any> | string | RegExp) => Promise<unknown>;
|
|
527
|
-
declare let createSlatesVitestConfig: (config?: Parameters<typeof createVitestConfig>[0]) => vite.UserConfig;
|
|
528
566
|
|
|
529
|
-
export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient,
|
|
567
|
+
export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient, expectSlateContract, expectSlateError, expectToolCall, getSlateContract, getVitestExpect, handleSlateTriggerWebhook, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, pollSlateTriggerEvents, registerSlateTriggerWebhook, unregisterSlateTriggerWebhook, withSlateProfile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as vite from 'vite';
|
|
2
1
|
import * as _slates_client from '@slates/client';
|
|
3
2
|
import { createSlatesClient, createLocalSlateTransport, SlatesProtocolClientOptions } from '@slates/client';
|
|
4
|
-
import
|
|
3
|
+
import * as vitest from 'vitest';
|
|
5
4
|
import { SlatesProfileRecord } from '@slates/profiles';
|
|
6
5
|
|
|
7
6
|
interface SlatesRuntimeContext {
|
|
8
7
|
integration: string | null;
|
|
9
8
|
profileId: string | null;
|
|
10
9
|
profile: SlatesProfileRecord | null;
|
|
10
|
+
rootDir: string;
|
|
11
11
|
storePath: string;
|
|
12
12
|
cliDir: string;
|
|
13
13
|
}
|
|
@@ -21,6 +21,7 @@ interface ExpectedSlateAction {
|
|
|
21
21
|
destructive?: boolean;
|
|
22
22
|
invocationType?: 'polling' | 'webhook';
|
|
23
23
|
}
|
|
24
|
+
declare let getVitestExpect: () => vitest.ExpectStatic;
|
|
24
25
|
declare let loadSlatesRuntimeContext: (opts?: {
|
|
25
26
|
cwd?: string;
|
|
26
27
|
profile?: string | null;
|
|
@@ -221,6 +222,7 @@ declare let getSlateContract: (client: SlatesTestClient) => Promise<{
|
|
|
221
222
|
id: string;
|
|
222
223
|
title: string;
|
|
223
224
|
description?: string | undefined;
|
|
225
|
+
defaultChecked?: boolean | undefined;
|
|
224
226
|
}[] | undefined;
|
|
225
227
|
}[];
|
|
226
228
|
configSchema: Record<string, any>;
|
|
@@ -368,6 +370,7 @@ declare let expectSlateContract: (d: {
|
|
|
368
370
|
id: string;
|
|
369
371
|
title: string;
|
|
370
372
|
description?: string | undefined;
|
|
373
|
+
defaultChecked?: boolean | undefined;
|
|
371
374
|
}[] | undefined;
|
|
372
375
|
}[];
|
|
373
376
|
configSchema: Record<string, any>;
|
|
@@ -408,6 +411,42 @@ declare let registerSlateTriggerWebhook: (d: {
|
|
|
408
411
|
} | undefined;
|
|
409
412
|
}[] | undefined;
|
|
410
413
|
}>;
|
|
414
|
+
declare let pollSlateTriggerEvents: (d: {
|
|
415
|
+
client: SlatesTestClient;
|
|
416
|
+
triggerId: string;
|
|
417
|
+
state?: any;
|
|
418
|
+
}) => Promise<{
|
|
419
|
+
inputs: Record<string, any>[];
|
|
420
|
+
updatedState?: any;
|
|
421
|
+
requestTraces?: {
|
|
422
|
+
startedAt: string;
|
|
423
|
+
durationMs: number;
|
|
424
|
+
request: {
|
|
425
|
+
method: string;
|
|
426
|
+
url: string;
|
|
427
|
+
headers?: Record<string, string> | undefined;
|
|
428
|
+
body?: {
|
|
429
|
+
text: string;
|
|
430
|
+
contentType?: string | undefined;
|
|
431
|
+
truncated?: boolean | undefined;
|
|
432
|
+
} | undefined;
|
|
433
|
+
};
|
|
434
|
+
response?: {
|
|
435
|
+
status: number;
|
|
436
|
+
statusText?: string | undefined;
|
|
437
|
+
headers?: Record<string, string> | undefined;
|
|
438
|
+
body?: {
|
|
439
|
+
text: string;
|
|
440
|
+
contentType?: string | undefined;
|
|
441
|
+
truncated?: boolean | undefined;
|
|
442
|
+
} | undefined;
|
|
443
|
+
} | undefined;
|
|
444
|
+
error?: {
|
|
445
|
+
message: string;
|
|
446
|
+
code?: string | undefined;
|
|
447
|
+
} | undefined;
|
|
448
|
+
}[] | undefined;
|
|
449
|
+
}>;
|
|
411
450
|
declare let handleSlateTriggerWebhook: (d: {
|
|
412
451
|
client: SlatesTestClient;
|
|
413
452
|
triggerId: string;
|
|
@@ -524,6 +563,5 @@ declare let mapSlateTriggerEvent: (d: {
|
|
|
524
563
|
}[] | undefined;
|
|
525
564
|
}>;
|
|
526
565
|
declare let expectSlateError: (run: Promise<unknown> | (() => Promise<unknown>), expected: Record<string, any> | string | RegExp) => Promise<unknown>;
|
|
527
|
-
declare let createSlatesVitestConfig: (config?: Parameters<typeof createVitestConfig>[0]) => vite.UserConfig;
|
|
528
566
|
|
|
529
|
-
export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient,
|
|
567
|
+
export { type ExpectedSlateAction, type SlatesRuntimeContext, type SlatesTestClient, createLocalSlateTestClient, createSlatesTestClient, expectSlateContract, expectSlateError, expectToolCall, getSlateContract, getVitestExpect, handleSlateTriggerWebhook, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, pollSlateTriggerEvents, registerSlateTriggerWebhook, unregisterSlateTriggerWebhook, withSlateProfile };
|
package/dist/index.module.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import { createVitestConfig } from "@lowerdeck/testing-tools";
|
|
1
|
+
// src/runtime.ts
|
|
3
2
|
import {
|
|
4
3
|
createLocalSlateTransport,
|
|
5
4
|
createSlatesClient,
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
openSlatesCliStore
|
|
11
10
|
} from "@slates/profiles";
|
|
12
11
|
import { readFile } from "fs/promises";
|
|
13
|
-
var
|
|
12
|
+
var getVitestExpect = () => {
|
|
14
13
|
let maybeExpect = globalThis.expect;
|
|
15
14
|
if (!maybeExpect) {
|
|
16
15
|
throw new Error("Vitest expect is not available in the current runtime.");
|
|
@@ -22,23 +21,31 @@ var loadSlatesRuntimeContext = async (opts = {}) => {
|
|
|
22
21
|
if (runtimeContextPath) {
|
|
23
22
|
let raw = await readFile(runtimeContextPath, "utf-8");
|
|
24
23
|
let parsed = JSON.parse(raw);
|
|
25
|
-
let store2 = await openSlatesCliStore({
|
|
24
|
+
let store2 = await openSlatesCliStore({
|
|
25
|
+
storePath: parsed.storePath,
|
|
26
|
+
rootDir: parsed.rootDir ?? process.env.SLATES_STORE_ROOT_DIR
|
|
27
|
+
});
|
|
26
28
|
let profile2 = store2.getProfile(opts.profile ?? parsed.profileId ?? null);
|
|
27
29
|
return {
|
|
28
30
|
integration: parsed.integration ?? store2.scope?.key ?? null,
|
|
29
31
|
profileId: profile2?.id ?? parsed.profileId ?? null,
|
|
30
32
|
profile: profile2,
|
|
33
|
+
rootDir: parsed.rootDir ?? store2.rootDir,
|
|
31
34
|
storePath: parsed.storePath,
|
|
32
35
|
cliDir: parsed.cliDir
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
|
-
let store = process.env.SLATES_STORE_PATH ? await openSlatesCliStore({
|
|
38
|
+
let store = process.env.SLATES_STORE_PATH ? await openSlatesCliStore({
|
|
39
|
+
storePath: process.env.SLATES_STORE_PATH,
|
|
40
|
+
rootDir: process.env.SLATES_STORE_ROOT_DIR
|
|
41
|
+
}) : await openSlatesCliStore({ cwd: opts.cwd });
|
|
36
42
|
let profileId = opts.profile ?? process.env.SLATES_PROFILE_ID ?? null;
|
|
37
43
|
let profile = store.getProfile(profileId);
|
|
38
44
|
return {
|
|
39
45
|
integration: process.env.SLATES_INTEGRATION ?? store.scope?.key ?? null,
|
|
40
46
|
profileId: profile?.id ?? null,
|
|
41
47
|
profile,
|
|
48
|
+
rootDir: store.rootDir,
|
|
42
49
|
storePath: store.storePath,
|
|
43
50
|
cliDir: store.dirPath
|
|
44
51
|
};
|
|
@@ -55,7 +62,10 @@ var createSlatesTestClient = async (opts = {}) => {
|
|
|
55
62
|
if (!context.profile) {
|
|
56
63
|
throw new Error("No Slates profile is available for the current test context.");
|
|
57
64
|
}
|
|
58
|
-
let store = await openSlatesCliStore({
|
|
65
|
+
let store = await openSlatesCliStore({
|
|
66
|
+
storePath: context.storePath,
|
|
67
|
+
rootDir: context.rootDir
|
|
68
|
+
});
|
|
59
69
|
return createSlatesClientFromProfile(context.profile, { cwd: opts.cwd, store });
|
|
60
70
|
};
|
|
61
71
|
var withSlateProfile = async (profileName, cb) => {
|
|
@@ -63,7 +73,7 @@ var withSlateProfile = async (profileName, cb) => {
|
|
|
63
73
|
return cb({ profile });
|
|
64
74
|
};
|
|
65
75
|
var expectToolCall = async (d) => {
|
|
66
|
-
let expect =
|
|
76
|
+
let expect = getVitestExpect();
|
|
67
77
|
let client = d.client ?? await createSlatesTestClient({ profile: d.profile });
|
|
68
78
|
let result = await client.invokeTool(d.toolId, d.input);
|
|
69
79
|
if (d.output) {
|
|
@@ -93,7 +103,7 @@ var getSlateContract = async (client) => {
|
|
|
93
103
|
};
|
|
94
104
|
};
|
|
95
105
|
var expectActionMatches = (actual, expected) => {
|
|
96
|
-
let expect =
|
|
106
|
+
let expect = getVitestExpect();
|
|
97
107
|
expect(actual).toBeTruthy();
|
|
98
108
|
expect(actual?.id).toBe(expected.id);
|
|
99
109
|
if (expected.name !== void 0) {
|
|
@@ -115,7 +125,7 @@ var expectActionMatches = (actual, expected) => {
|
|
|
115
125
|
}
|
|
116
126
|
};
|
|
117
127
|
var expectSlateContract = async (d) => {
|
|
118
|
-
let expect =
|
|
128
|
+
let expect = getVitestExpect();
|
|
119
129
|
let contract = await getSlateContract(d.client);
|
|
120
130
|
if (d.provider) {
|
|
121
131
|
expect(contract.provider.id).toBe(d.provider.id);
|
|
@@ -144,6 +154,13 @@ var expectSlateContract = async (d) => {
|
|
|
144
154
|
return contract;
|
|
145
155
|
};
|
|
146
156
|
var registerSlateTriggerWebhook = async (d) => d.client.registerTriggerWebhook(d.triggerId, d.webhookBaseUrl);
|
|
157
|
+
var pollSlateTriggerEvents = async (d) => {
|
|
158
|
+
d.client.ensureSession();
|
|
159
|
+
return d.client.request("slates/action.trigger.poll_events", {
|
|
160
|
+
actionId: d.triggerId,
|
|
161
|
+
state: d.state ?? null
|
|
162
|
+
});
|
|
163
|
+
};
|
|
147
164
|
var handleSlateTriggerWebhook = async (d) => d.client.handleTriggerWebhook({
|
|
148
165
|
actionId: d.triggerId,
|
|
149
166
|
url: d.url,
|
|
@@ -159,7 +176,7 @@ var unregisterSlateTriggerWebhook = async (d) => d.client.unregisterTriggerWebho
|
|
|
159
176
|
state: d.state
|
|
160
177
|
});
|
|
161
178
|
var mapSlateTriggerEvent = async (d) => {
|
|
162
|
-
let expect =
|
|
179
|
+
let expect = getVitestExpect();
|
|
163
180
|
let result = await d.client.mapTriggerEvent(d.triggerId, d.input);
|
|
164
181
|
if (d.type !== void 0) {
|
|
165
182
|
expect(result.type).toBe(d.type);
|
|
@@ -170,7 +187,7 @@ var mapSlateTriggerEvent = async (d) => {
|
|
|
170
187
|
return result;
|
|
171
188
|
};
|
|
172
189
|
var expectSlateError = async (run, expected) => {
|
|
173
|
-
let expect =
|
|
190
|
+
let expect = getVitestExpect();
|
|
174
191
|
try {
|
|
175
192
|
await (typeof run === "function" ? run() : run);
|
|
176
193
|
} catch (error) {
|
|
@@ -190,19 +207,19 @@ var expectSlateError = async (run, expected) => {
|
|
|
190
207
|
}
|
|
191
208
|
throw new Error("Expected the operation to fail, but it completed successfully.");
|
|
192
209
|
};
|
|
193
|
-
var createSlatesVitestConfig = (config = {}) => createVitestConfig(config);
|
|
194
210
|
export {
|
|
195
211
|
createLocalSlateTestClient,
|
|
196
212
|
createSlatesTestClient,
|
|
197
|
-
createSlatesVitestConfig,
|
|
198
213
|
expectSlateContract,
|
|
199
214
|
expectSlateError,
|
|
200
215
|
expectToolCall,
|
|
201
216
|
getSlateContract,
|
|
217
|
+
getVitestExpect,
|
|
202
218
|
handleSlateTriggerWebhook,
|
|
203
219
|
loadSlatesProfile,
|
|
204
220
|
loadSlatesRuntimeContext,
|
|
205
221
|
mapSlateTriggerEvent,
|
|
222
|
+
pollSlateTriggerEvents,
|
|
206
223
|
registerSlateTriggerWebhook,
|
|
207
224
|
unregisterSlateTriggerWebhook,
|
|
208
225
|
withSlateProfile
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/test",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -15,10 +15,18 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"source": "src/index.ts",
|
|
17
17
|
"exports": {
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.cjs",
|
|
21
|
+
"import": "./dist/index.module.js",
|
|
22
|
+
"default": "./dist/index.module.js"
|
|
23
|
+
},
|
|
24
|
+
"./config": {
|
|
25
|
+
"types": "./dist/config.d.ts",
|
|
26
|
+
"require": "./dist/config.cjs",
|
|
27
|
+
"import": "./dist/config.module.js",
|
|
28
|
+
"default": "./dist/config.module.js"
|
|
29
|
+
}
|
|
22
30
|
},
|
|
23
31
|
"main": "./dist/index.cjs",
|
|
24
32
|
"module": "./dist/index.module.js",
|
|
@@ -27,16 +35,16 @@
|
|
|
27
35
|
"scripts": {
|
|
28
36
|
"test": "vitest run --passWithNoTests",
|
|
29
37
|
"lint": "prettier src/**/*.ts --check",
|
|
30
|
-
"build": "tsup --config
|
|
38
|
+
"build": "tsup --config tsup.config.ts",
|
|
31
39
|
"typecheck": "tsc --noEmit"
|
|
32
40
|
},
|
|
33
41
|
"dependencies": {
|
|
34
42
|
"@lowerdeck/testing-tools": "latest",
|
|
35
|
-
"@slates/client": "1.0.0-rc.
|
|
36
|
-
"@slates/profiles": "1.0.0-rc.
|
|
43
|
+
"@slates/client": "1.0.0-rc.6",
|
|
44
|
+
"@slates/profiles": "1.0.0-rc.4"
|
|
37
45
|
},
|
|
38
46
|
"devDependencies": {
|
|
39
|
-
"@slates/provider": "1.0.0-rc.
|
|
47
|
+
"@slates/provider": "1.0.0-rc.10",
|
|
40
48
|
"@slates/tsconfig": "1.0.0-rc.1",
|
|
41
49
|
"typescript": "5.8.2",
|
|
42
50
|
"vitest": "^3.1.2",
|