@output.ai/core 0.5.5 → 0.5.7
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/LICENSE +201 -0
- package/bin/healthcheck.mjs +36 -0
- package/bin/healthcheck.spec.js +90 -0
- package/package.json +10 -6
- package/src/interface/evaluation_result.d.ts +13 -0
- package/src/interface/evaluation_result.js +13 -0
- package/src/interface/index.js +8 -1
- package/src/interface/workflow.d.ts +1 -1
- package/src/interface/workflow.js +5 -5
- package/src/interface/workflow.spec.js +0 -28
- package/src/utils/index.d.ts +8 -0
- package/src/utils/resolve_invocation_dir.js +2 -0
- package/src/utils/utils.js +7 -0
- package/src/worker/bundler_options.js +11 -0
- package/src/worker/catalog_workflow/workflow.js +4 -0
- package/src/worker/webpack_loaders/tools.js +38 -14
- package/src/worker/webpack_loaders/tools.spec.js +69 -0
- package/src/worker/webpack_loaders/workflow_rewriter/collect_target_imports.spec.js +42 -35
- package/src/worker/webpack_loaders/workflow_validator/index.spec.js +10 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Healthcheck
|
|
5
|
+
|
|
6
|
+
Send a "ping" query to the catalog workflow; exit with 0 if result is "pong", 1 otherwise.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Connection, Client } from '@temporalio/client';
|
|
10
|
+
|
|
11
|
+
const address = process.env.TEMPORAL_ADDRESS;
|
|
12
|
+
const namespace = process.env.TEMPORAL_NAMESPACE ?? 'default';
|
|
13
|
+
const apiKey = process.env.TEMPORAL_API_KEY;
|
|
14
|
+
const catalogId = process.env.OUTPUT_CATALOG_ID ?? 'main';
|
|
15
|
+
|
|
16
|
+
const state = { connection: null };
|
|
17
|
+
|
|
18
|
+
const code = await ( async () => {
|
|
19
|
+
try {
|
|
20
|
+
state.connection = await Connection.connect( { address, tls: Boolean( apiKey ), apiKey } );
|
|
21
|
+
const client = new Client( { connection: state.connection, namespace } );
|
|
22
|
+
const handle = client.workflow.getHandle( catalogId );
|
|
23
|
+
const response = await handle.query( 'ping' );
|
|
24
|
+
console.log( `Query response: ${response}` );
|
|
25
|
+
return response === 'pong' ? 0 : 1;
|
|
26
|
+
} catch ( error ) {
|
|
27
|
+
console.error( 'Healthcheck error', error );
|
|
28
|
+
return 1;
|
|
29
|
+
} finally {
|
|
30
|
+
if ( state.connection ) {
|
|
31
|
+
await state.connection.close().catch( () => {} );
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} )();
|
|
35
|
+
|
|
36
|
+
process.exit( code );
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const closeMock = vi.fn().mockResolvedValue( undefined );
|
|
4
|
+
const connectionMock = { close: closeMock };
|
|
5
|
+
|
|
6
|
+
const queryMock = vi.fn();
|
|
7
|
+
const getHandleMock = vi.fn().mockReturnValue( { query: queryMock } );
|
|
8
|
+
const ClientMock = vi.fn().mockImplementation( () => ( {
|
|
9
|
+
workflow: { getHandle: getHandleMock }
|
|
10
|
+
} ) );
|
|
11
|
+
const connectMock = vi.fn().mockResolvedValue( connectionMock );
|
|
12
|
+
|
|
13
|
+
vi.mock( '@temporalio/client', () => ( {
|
|
14
|
+
Connection: { connect: connectMock },
|
|
15
|
+
Client: ClientMock
|
|
16
|
+
} ) );
|
|
17
|
+
|
|
18
|
+
describe( 'bin/healthcheck', () => {
|
|
19
|
+
const exitMock = vi.fn();
|
|
20
|
+
const originalExit = process.exit;
|
|
21
|
+
|
|
22
|
+
beforeEach( () => {
|
|
23
|
+
vi.clearAllMocks();
|
|
24
|
+
process.exit = exitMock;
|
|
25
|
+
process.env.TEMPORAL_ADDRESS = 'localhost:7233';
|
|
26
|
+
process.env.TEMPORAL_NAMESPACE = 'default';
|
|
27
|
+
process.env.OUTPUT_CATALOG_ID = 'test-catalog';
|
|
28
|
+
delete process.env.TEMPORAL_API_KEY;
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
afterEach( () => {
|
|
32
|
+
process.exit = originalExit;
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
it( 'exits 0 when catalog ping returns "pong"', async () => {
|
|
36
|
+
queryMock.mockResolvedValue( 'pong' );
|
|
37
|
+
vi.resetModules();
|
|
38
|
+
await import( './healthcheck.mjs' );
|
|
39
|
+
expect( connectMock ).toHaveBeenCalledWith( {
|
|
40
|
+
address: 'localhost:7233',
|
|
41
|
+
tls: false,
|
|
42
|
+
apiKey: undefined
|
|
43
|
+
} );
|
|
44
|
+
expect( ClientMock ).toHaveBeenCalledWith( { connection: connectionMock, namespace: 'default' } );
|
|
45
|
+
expect( getHandleMock ).toHaveBeenCalledWith( 'test-catalog' );
|
|
46
|
+
expect( queryMock ).toHaveBeenCalledWith( 'ping' );
|
|
47
|
+
expect( exitMock ).toHaveBeenCalledWith( 0 );
|
|
48
|
+
expect( closeMock ).toHaveBeenCalled();
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
it( 'uses TLS and apiKey when TEMPORAL_API_KEY is set', async () => {
|
|
52
|
+
process.env.TEMPORAL_API_KEY = 'secret';
|
|
53
|
+
queryMock.mockResolvedValue( 'pong' );
|
|
54
|
+
vi.resetModules();
|
|
55
|
+
await import( './healthcheck.mjs' );
|
|
56
|
+
expect( connectMock ).toHaveBeenCalledWith( {
|
|
57
|
+
address: 'localhost:7233',
|
|
58
|
+
tls: true,
|
|
59
|
+
apiKey: 'secret'
|
|
60
|
+
} );
|
|
61
|
+
expect( exitMock ).toHaveBeenCalledWith( 0 );
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
it( 'uses default namespace and catalog id when env unset', async () => {
|
|
65
|
+
delete process.env.TEMPORAL_NAMESPACE;
|
|
66
|
+
delete process.env.OUTPUT_CATALOG_ID;
|
|
67
|
+
queryMock.mockResolvedValue( 'pong' );
|
|
68
|
+
vi.resetModules();
|
|
69
|
+
await import( './healthcheck.mjs' );
|
|
70
|
+
expect( ClientMock ).toHaveBeenCalledWith( { connection: connectionMock, namespace: 'default' } );
|
|
71
|
+
expect( getHandleMock ).toHaveBeenCalledWith( 'main' );
|
|
72
|
+
expect( exitMock ).toHaveBeenCalledWith( 0 );
|
|
73
|
+
} );
|
|
74
|
+
|
|
75
|
+
it( 'exits 1 when catalog ping returns non-pong', async () => {
|
|
76
|
+
queryMock.mockResolvedValue( 'nope' );
|
|
77
|
+
vi.resetModules();
|
|
78
|
+
await import( './healthcheck.mjs' );
|
|
79
|
+
expect( exitMock ).toHaveBeenCalledWith( 1 );
|
|
80
|
+
expect( closeMock ).toHaveBeenCalled();
|
|
81
|
+
} );
|
|
82
|
+
|
|
83
|
+
it( 'exits 1 when query throws', async () => {
|
|
84
|
+
queryMock.mockRejectedValue( new Error( 'connection refused' ) );
|
|
85
|
+
vi.resetModules();
|
|
86
|
+
await import( './healthcheck.mjs' );
|
|
87
|
+
expect( exitMock ).toHaveBeenCalledWith( 1 );
|
|
88
|
+
expect( closeMock ).toHaveBeenCalled();
|
|
89
|
+
} );
|
|
90
|
+
} );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@output.ai/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "The core module of the output framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,10 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"bin": {
|
|
25
25
|
"output-worker": "./bin/worker.sh",
|
|
26
|
-
"outputai": "./bin/worker.sh"
|
|
27
|
-
|
|
28
|
-
"scripts": {
|
|
29
|
-
"worker": "node ./src/worker/index.js"
|
|
26
|
+
"outputai": "./bin/worker.sh",
|
|
27
|
+
"output-healthcheck": "./bin/healthcheck.mjs"
|
|
30
28
|
},
|
|
31
29
|
"dependencies": {
|
|
32
30
|
"@aws-sdk/client-s3": "3.913.0",
|
|
@@ -34,6 +32,9 @@
|
|
|
34
32
|
"@babel/parser": "7.28.4",
|
|
35
33
|
"@babel/traverse": "7.28.4",
|
|
36
34
|
"@babel/types": "7.28.4",
|
|
35
|
+
"@temporalio/activity": "1.13.1",
|
|
36
|
+
"@temporalio/client": "1.13.1",
|
|
37
|
+
"@temporalio/common": "1.13.1",
|
|
37
38
|
"@temporalio/worker": "1.13.1",
|
|
38
39
|
"@temporalio/workflow": "1.13.1",
|
|
39
40
|
"redis": "5.8.3",
|
|
@@ -55,5 +56,8 @@
|
|
|
55
56
|
"#async_storage": "./src/async_storage.js",
|
|
56
57
|
"#temporal_options": "./src/temporal_options.js",
|
|
57
58
|
"#internal_activities": "./src/internal_activities/index.js"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"worker": "node ./src/worker/index.js"
|
|
58
62
|
}
|
|
59
|
-
}
|
|
63
|
+
}
|
|
@@ -158,3 +158,16 @@ export class EvaluationBooleanResult extends EvaluationResult {
|
|
|
158
158
|
*/
|
|
159
159
|
constructor( args: EvaluationResultArgs<boolean> );
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* An evaluation result where the value is a verdict (pass, partial, fail)
|
|
164
|
+
* @extends EvaluationResult
|
|
165
|
+
*/
|
|
166
|
+
export class EvaluationVerdictResult extends EvaluationResult {
|
|
167
|
+
/**
|
|
168
|
+
* @constructor
|
|
169
|
+
* @param args - See {@link EvaluationResultArgs} for full parameter documentation.
|
|
170
|
+
* @param args.value - The verdict: 'pass', 'partial', or 'fail'.
|
|
171
|
+
*/
|
|
172
|
+
constructor( args: EvaluationResultArgs<'pass' | 'partial' | 'fail'> );
|
|
173
|
+
}
|
|
@@ -200,3 +200,16 @@ export class EvaluationBooleanResult extends EvaluationResult {
|
|
|
200
200
|
export class EvaluationNumberResult extends EvaluationResult {
|
|
201
201
|
static valueSchema = z.number();
|
|
202
202
|
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* An evaluation result that uses a verdict value (pass, partial, fail)
|
|
206
|
+
* @extends EvaluationResult
|
|
207
|
+
* @property {'pass' | 'partial' | 'fail'} value - The evaluation verdict
|
|
208
|
+
* @constructor
|
|
209
|
+
* @param {object} args
|
|
210
|
+
* @param {'pass' | 'partial' | 'fail'} args.value - The verdict value
|
|
211
|
+
* @see EvaluationResult#constructor for other parameters (confidence, reasoning)
|
|
212
|
+
*/
|
|
213
|
+
export class EvaluationVerdictResult extends EvaluationResult {
|
|
214
|
+
static valueSchema = z.enum( [ 'pass', 'partial', 'fail' ] );
|
|
215
|
+
};
|
package/src/interface/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EvaluationStringResult,
|
|
3
|
+
EvaluationNumberResult,
|
|
4
|
+
EvaluationBooleanResult,
|
|
5
|
+
EvaluationVerdictResult,
|
|
6
|
+
EvaluationFeedback
|
|
7
|
+
} from './evaluation_result.js';
|
|
2
8
|
import { evaluator } from './evaluator.js';
|
|
3
9
|
import { step } from './step.js';
|
|
4
10
|
import { workflow } from './workflow.js';
|
|
@@ -12,6 +18,7 @@ export {
|
|
|
12
18
|
EvaluationNumberResult,
|
|
13
19
|
EvaluationStringResult,
|
|
14
20
|
EvaluationBooleanResult,
|
|
21
|
+
EvaluationVerdictResult,
|
|
15
22
|
EvaluationFeedback,
|
|
16
23
|
executeInParallel,
|
|
17
24
|
sendHttpRequest,
|
|
@@ -75,8 +75,7 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
|
|
|
75
75
|
// validation comes after setting memo to have that info already set for interceptor even if validations fail
|
|
76
76
|
validateWithSchema( inputSchema, input, `Workflow ${name} input` );
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
const output = await fn.call( {
|
|
78
|
+
const dispatchers = {
|
|
80
79
|
invokeStep: async ( stepName, input, options ) => steps[`${name}#${stepName}`]( input, options ),
|
|
81
80
|
invokeSharedStep: async ( stepName, input, options ) => steps[`${SHARED_STEP_PREFIX}#${stepName}`]( input, options ),
|
|
82
81
|
invokeEvaluator: async ( evaluatorName, input, options ) => steps[`${name}#${evaluatorName}`]( input, options ),
|
|
@@ -90,7 +89,7 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
|
|
|
90
89
|
* @param {object} extra
|
|
91
90
|
* @param {boolean} extra.detached
|
|
92
91
|
* @param {import('@temporalio/workflow').ActivityOptions} extra.options
|
|
93
|
-
* @returns
|
|
92
|
+
* @returns {Promise<unknown>}
|
|
94
93
|
*/
|
|
95
94
|
startWorkflow: async ( childName, input, extra = {} ) =>
|
|
96
95
|
executeChild( childName, {
|
|
@@ -100,11 +99,12 @@ export function workflow( { name, description, inputSchema, outputSchema, fn, op
|
|
|
100
99
|
memo: {
|
|
101
100
|
executionContext,
|
|
102
101
|
parentId: workflowId,
|
|
103
|
-
// new configuration for activities of the child workflow, this will be omitted so it will use what that workflow have defined
|
|
104
102
|
...( extra?.options?.activityOptions && { activityOptions: deepMerge( activityOptions, extra.options.activityOptions ) } )
|
|
105
103
|
}
|
|
106
104
|
} )
|
|
107
|
-
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const output = await fn.call( dispatchers, input, context );
|
|
108
108
|
|
|
109
109
|
validateWithSchema( outputSchema, output, `Workflow ${name} output` );
|
|
110
110
|
|
|
@@ -447,34 +447,6 @@ describe( 'workflow()', () => {
|
|
|
447
447
|
} );
|
|
448
448
|
} );
|
|
449
449
|
|
|
450
|
-
describe( 'context.control', () => {
|
|
451
|
-
it( 'exposes info.workflowId and control/info namespaces when not in workflow context', async () => {
|
|
452
|
-
inWorkflowContextMock.mockReturnValue( false );
|
|
453
|
-
const { workflow } = await import( './workflow.js' );
|
|
454
|
-
|
|
455
|
-
const wf = workflow( {
|
|
456
|
-
name: 'control_wf',
|
|
457
|
-
description: 'Control',
|
|
458
|
-
inputSchema: z.object( {} ),
|
|
459
|
-
outputSchema: z.object( {
|
|
460
|
-
workflowId: z.string(),
|
|
461
|
-
hasControl: z.boolean(),
|
|
462
|
-
hasInfo: z.boolean()
|
|
463
|
-
} ),
|
|
464
|
-
fn: async ( _, context ) => ( {
|
|
465
|
-
workflowId: context.info?.workflowId,
|
|
466
|
-
hasControl: 'control' in context,
|
|
467
|
-
hasInfo: 'info' in context
|
|
468
|
-
} )
|
|
469
|
-
} );
|
|
470
|
-
|
|
471
|
-
const result = await wf( {} );
|
|
472
|
-
expect( result.workflowId ).toBe( 'test-workflow' );
|
|
473
|
-
expect( result.hasControl ).toBe( true );
|
|
474
|
-
expect( result.hasInfo ).toBe( true );
|
|
475
|
-
} );
|
|
476
|
-
} );
|
|
477
|
-
|
|
478
450
|
describe( 'error handling (root workflow)', () => {
|
|
479
451
|
it( 'rethrows error from fn and rejects with same message', async () => {
|
|
480
452
|
const { workflow } = await import( './workflow.js' );
|
package/src/utils/index.d.ts
CHANGED
|
@@ -33,6 +33,14 @@ export function throws( error: Error ): void;
|
|
|
33
33
|
*/
|
|
34
34
|
export function setMetadata( target: object, value: object ): void;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Read metadata previously attached via setMetadata.
|
|
38
|
+
*
|
|
39
|
+
* @param target - The function or object to read metadata from.
|
|
40
|
+
* @returns The metadata object, or null if none is attached.
|
|
41
|
+
*/
|
|
42
|
+
export function getMetadata( target: Function ): { name: string; description?: string; type?: string } | null;
|
|
43
|
+
|
|
36
44
|
/** Represents a {Response} serialized to plain object */
|
|
37
45
|
export type SerializedFetchResponse = {
|
|
38
46
|
/** The response url */
|
|
@@ -8,8 +8,10 @@ const transformSeparators = path => path.replaceAll( '/', SEP );
|
|
|
8
8
|
const defaultIgnorePaths = [
|
|
9
9
|
'/@output.ai/core/',
|
|
10
10
|
'/@output.ai/llm/',
|
|
11
|
+
'/@output.ai/evals/',
|
|
11
12
|
'/sdk/core/',
|
|
12
13
|
'/sdk/llm/',
|
|
14
|
+
'/sdk/evals/',
|
|
13
15
|
'node:internal/',
|
|
14
16
|
'evalmachine.',
|
|
15
17
|
'webpack/bootstrap'
|
package/src/utils/utils.js
CHANGED
|
@@ -37,6 +37,13 @@ export const throws = e => {
|
|
|
37
37
|
export const setMetadata = ( target, values ) =>
|
|
38
38
|
Object.defineProperty( target, METADATA_ACCESS_SYMBOL, { value: values, writable: false, enumerable: false, configurable: false } );
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Read metadata previously attached via setMetadata
|
|
42
|
+
* @param {Function} target
|
|
43
|
+
* @returns {object|null}
|
|
44
|
+
*/
|
|
45
|
+
export const getMetadata = target => target[METADATA_ACCESS_SYMBOL] ?? null;
|
|
46
|
+
|
|
40
47
|
/**
|
|
41
48
|
* Returns true if string value is stringbool and true
|
|
42
49
|
* @param {string} v
|
|
@@ -6,6 +6,17 @@ const workerDir = __dirname; // sdk/core/src/worker
|
|
|
6
6
|
const interfaceDir = join( __dirname, '..', 'interface' );
|
|
7
7
|
|
|
8
8
|
export const webpackConfigHook = config => {
|
|
9
|
+
// Prefer the "output-workflow-bundle" export condition when resolving packages.
|
|
10
|
+
// Packages that transitively depend on Node.js built-ins (which can't exist in the
|
|
11
|
+
// Temporal workflow bundle) can provide an alternative entry point under this condition
|
|
12
|
+
// that excludes the offending code paths. Packages without this condition fall through
|
|
13
|
+
// to the standard "import" / "module" / "default" conditions as normal.
|
|
14
|
+
config.resolve = config.resolve ?? {};
|
|
15
|
+
config.resolve.conditionNames = [
|
|
16
|
+
'output-workflow-bundle',
|
|
17
|
+
...( config.resolve.conditionNames ?? [ 'import', 'module', 'webpack', 'default' ] )
|
|
18
|
+
];
|
|
19
|
+
|
|
9
20
|
config.module = config.module ?? { };
|
|
10
21
|
config.module.rules = config.module.rules ?? [];
|
|
11
22
|
|
|
@@ -10,8 +10,12 @@ import { defineQuery, setHandler, condition, defineUpdate } from '@temporalio/wo
|
|
|
10
10
|
export default async function catalogWorkflow( catalog ) {
|
|
11
11
|
const state = { canEnd: false };
|
|
12
12
|
|
|
13
|
+
// Returns the catalog
|
|
13
14
|
setHandler( defineQuery( 'get' ), () => catalog );
|
|
14
15
|
|
|
16
|
+
// Politely respond to a ping
|
|
17
|
+
setHandler( defineQuery( 'ping' ), () => 'pong' );
|
|
18
|
+
|
|
15
19
|
// Listen to this update to complete the workflow
|
|
16
20
|
setHandler( defineUpdate( 'complete' ), () => state.canEnd = true );
|
|
17
21
|
|
|
@@ -295,19 +295,46 @@ export const resolveNameFromOptions = ( optionsNode, consts, errorMessagePrefix
|
|
|
295
295
|
throw new Error( `${errorMessagePrefix}: Missing required name property` ); // No name field found
|
|
296
296
|
};
|
|
297
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Resolve a name from the first argument of a factory call.
|
|
300
|
+
* Handles two patterns:
|
|
301
|
+
* - String literal first arg: `verify('name', fn)` → returns 'name'
|
|
302
|
+
* - Identifier referencing top-level const: `verify(NAME, fn)` → resolves const
|
|
303
|
+
* - Object with name property: `evaluator({ name: '...' })` → delegates to resolveNameFromOptions
|
|
304
|
+
*
|
|
305
|
+
* @param {import('@babel/types').Expression} argNode - First argument to the factory call.
|
|
306
|
+
* @param {Map<string,string>} consts - Top-level const string bindings.
|
|
307
|
+
* @param {string} errorMessagePrefix - Prefix used when throwing validation errors.
|
|
308
|
+
* @returns {string} Resolved name.
|
|
309
|
+
* @throws {Error} When name is missing or not a supported static form.
|
|
310
|
+
*/
|
|
311
|
+
export const resolveNameFromArg = ( argNode, consts, errorMessagePrefix ) => {
|
|
312
|
+
if ( isStringLiteral( argNode ) ) {
|
|
313
|
+
return argNode.value;
|
|
314
|
+
}
|
|
315
|
+
if ( isIdentifier( argNode ) && consts.has( argNode.name ) ) {
|
|
316
|
+
return consts.get( argNode.name );
|
|
317
|
+
}
|
|
318
|
+
return resolveNameFromOptions( argNode, consts, errorMessagePrefix );
|
|
319
|
+
};
|
|
320
|
+
|
|
298
321
|
/**
|
|
299
322
|
* Build a map of exported component identifiers to declared names by scanning a module.
|
|
300
|
-
*
|
|
323
|
+
* Matches any `export const X = identifier(...)` pattern — the callee name is intentionally
|
|
324
|
+
* unchecked because:
|
|
325
|
+
* - File path scoping (steps.js, evaluators.js) already constrains which files are parsed
|
|
326
|
+
* - External packages may define custom factory wrappers (e.g., verify() wraps evaluator())
|
|
327
|
+
* - Runtime metadata validation is the authoritative check for component type
|
|
328
|
+
* - Name extraction (resolveNameFromArg) rejects calls without a static name argument
|
|
301
329
|
*
|
|
302
330
|
* @param {object} params
|
|
303
331
|
* @param {string} params.path - Absolute path to the module file.
|
|
304
332
|
* @param {Map<string, Map<string,string>>} params.cache - Cache for memoizing results by file path.
|
|
305
|
-
* @param {('step'|'evaluator')} params.calleeName - Factory function identifier to match.
|
|
306
333
|
* @param {string} params.invalidMessagePrefix - Prefix used in thrown errors when name is invalid.
|
|
307
334
|
* @returns {Map<string,string>} Map of `exportedIdentifier` -> `declaredName`.
|
|
308
335
|
* @throws {Error} When names are missing, dynamic, or otherwise non-static.
|
|
309
336
|
*/
|
|
310
|
-
const buildComponentNameMap = ( { path, cache,
|
|
337
|
+
const buildComponentNameMap = ( { path, cache, invalidMessagePrefix } ) => {
|
|
311
338
|
if ( cache.has( path ) ) {
|
|
312
339
|
return cache.get( path );
|
|
313
340
|
}
|
|
@@ -319,10 +346,10 @@ const buildComponentNameMap = ( { path, cache, calleeName, invalidMessagePrefix
|
|
|
319
346
|
.filter( node => isExportNamedDeclaration( node ) && isVariableDeclaration( node.declaration ) )
|
|
320
347
|
.reduce( ( map, node ) => {
|
|
321
348
|
node.declaration.declarations
|
|
322
|
-
.filter( dec => isIdentifier( dec.id ) && isCallExpression( dec.init ) && isIdentifier( dec.init.callee
|
|
349
|
+
.filter( dec => isIdentifier( dec.id ) && isCallExpression( dec.init ) && isIdentifier( dec.init.callee ) )
|
|
323
350
|
.map( dec => [
|
|
324
351
|
dec,
|
|
325
|
-
|
|
352
|
+
resolveNameFromArg( dec.init.arguments[0], consts, `${invalidMessagePrefix} ${path} for "${dec.id.name}"` )
|
|
326
353
|
] )
|
|
327
354
|
.forEach( ( [ dec, name ] ) => map.set( dec.id.name, name ) );
|
|
328
355
|
return map;
|
|
@@ -335,7 +362,6 @@ const buildComponentNameMap = ( { path, cache, calleeName, invalidMessagePrefix
|
|
|
335
362
|
export const buildStepsNameMap = ( path, cache ) => buildComponentNameMap( {
|
|
336
363
|
path,
|
|
337
364
|
cache,
|
|
338
|
-
calleeName: 'step',
|
|
339
365
|
invalidMessagePrefix: 'Invalid step name in'
|
|
340
366
|
} );
|
|
341
367
|
|
|
@@ -351,13 +377,13 @@ export const buildStepsNameMap = ( path, cache ) => buildComponentNameMap( {
|
|
|
351
377
|
export const buildSharedStepsNameMap = ( path, cache ) => buildComponentNameMap( {
|
|
352
378
|
path,
|
|
353
379
|
cache,
|
|
354
|
-
calleeName: 'step',
|
|
355
380
|
invalidMessagePrefix: 'Invalid shared step name in'
|
|
356
381
|
} );
|
|
357
382
|
|
|
358
383
|
/**
|
|
359
384
|
* Build a map from exported evaluator identifier to declared evaluator name.
|
|
360
|
-
*
|
|
385
|
+
* Matches `export const X = evaluator({ name: '...' })` and wrapper patterns
|
|
386
|
+
* like `export const X = verify('name', fn)`.
|
|
361
387
|
*
|
|
362
388
|
* @param {string} path - Absolute path to the evaluators module file.
|
|
363
389
|
* @param {Map<string, Map<string,string>>} cache - Cache of computed evaluator name maps.
|
|
@@ -367,7 +393,6 @@ export const buildSharedStepsNameMap = ( path, cache ) => buildComponentNameMap(
|
|
|
367
393
|
export const buildEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap( {
|
|
368
394
|
path,
|
|
369
395
|
cache,
|
|
370
|
-
calleeName: 'evaluator',
|
|
371
396
|
invalidMessagePrefix: 'Invalid evaluator name in'
|
|
372
397
|
} );
|
|
373
398
|
|
|
@@ -383,7 +408,6 @@ export const buildEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap(
|
|
|
383
408
|
export const buildSharedEvaluatorsNameMap = ( path, cache ) => buildComponentNameMap( {
|
|
384
409
|
path,
|
|
385
410
|
cache,
|
|
386
|
-
calleeName: 'evaluator',
|
|
387
411
|
invalidMessagePrefix: 'Invalid shared evaluator name in'
|
|
388
412
|
} );
|
|
389
413
|
|
|
@@ -411,8 +435,8 @@ export const buildWorkflowNameMap = ( path, cache ) => {
|
|
|
411
435
|
if ( isExportNamedDeclaration( node ) && isVariableDeclaration( node.declaration ) ) {
|
|
412
436
|
|
|
413
437
|
for ( const d of node.declaration.declarations ) {
|
|
414
|
-
if ( isIdentifier( d.id ) && isCallExpression( d.init ) && isIdentifier( d.init.callee
|
|
415
|
-
const name =
|
|
438
|
+
if ( isIdentifier( d.id ) && isCallExpression( d.init ) && isIdentifier( d.init.callee ) ) {
|
|
439
|
+
const name = resolveNameFromArg( d.init.arguments[0], consts, `Invalid workflow name in ${path} for '${d.id.name}` );
|
|
416
440
|
if ( name ) {
|
|
417
441
|
result.named.set( d.id.name, name );
|
|
418
442
|
}
|
|
@@ -423,9 +447,9 @@ export const buildWorkflowNameMap = ( path, cache ) => {
|
|
|
423
447
|
} else if (
|
|
424
448
|
isExportDefaultDeclaration( node ) &&
|
|
425
449
|
isCallExpression( node.declaration ) &&
|
|
426
|
-
isIdentifier( node.declaration.callee
|
|
450
|
+
isIdentifier( node.declaration.callee )
|
|
427
451
|
) {
|
|
428
|
-
result.default =
|
|
452
|
+
result.default = resolveNameFromArg( node.declaration.arguments[0], consts, `Invalid default workflow name in ${path}` );
|
|
429
453
|
}
|
|
430
454
|
}
|
|
431
455
|
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
isSharedEvaluatorsPath,
|
|
18
18
|
isWorkflowPath,
|
|
19
19
|
createThisMethodCall,
|
|
20
|
+
resolveNameFromArg,
|
|
20
21
|
resolveNameFromOptions,
|
|
21
22
|
buildStepsNameMap,
|
|
22
23
|
buildSharedStepsNameMap,
|
|
@@ -258,4 +259,72 @@ describe( 'workflow_rewriter tools', () => {
|
|
|
258
259
|
expect( getFileKind( '/p/utils.js' ) ).toBe( null );
|
|
259
260
|
expect( getFileKind( '/p/clients/api.js' ) ).toBe( null );
|
|
260
261
|
} );
|
|
262
|
+
|
|
263
|
+
it( 'resolveNameFromArg: resolves string literal directly', () => {
|
|
264
|
+
expect( resolveNameFromArg( t.stringLiteral( 'my_name' ), new Map(), 'X' ) ).toBe( 'my_name' );
|
|
265
|
+
} );
|
|
266
|
+
|
|
267
|
+
it( 'resolveNameFromArg: resolves identifier from consts', () => {
|
|
268
|
+
const consts = new Map( [ [ 'MY_NAME', 'resolved_name' ] ] );
|
|
269
|
+
expect( resolveNameFromArg( t.identifier( 'MY_NAME' ), consts, 'X' ) ).toBe( 'resolved_name' );
|
|
270
|
+
} );
|
|
271
|
+
|
|
272
|
+
it( 'resolveNameFromArg: falls back to resolveNameFromOptions for objects', () => {
|
|
273
|
+
const opts = t.objectExpression( [ t.objectProperty( t.identifier( 'name' ), t.stringLiteral( 'obj_name' ) ) ] );
|
|
274
|
+
expect( resolveNameFromArg( opts, new Map(), 'X' ) ).toBe( 'obj_name' );
|
|
275
|
+
} );
|
|
276
|
+
|
|
277
|
+
it( 'buildEvaluatorsNameMap: reads names from string-arg factory pattern', () => {
|
|
278
|
+
const dir = mkdtempSync( join( tmpdir(), 'tools-verify-evals-' ) );
|
|
279
|
+
const evalsPath = join( dir, 'evaluators.js' );
|
|
280
|
+
writeFileSync( evalsPath, 'export const EvalA = verify( \'eval_a\', async () => {} )' );
|
|
281
|
+
const cache = new Map();
|
|
282
|
+
const map = buildEvaluatorsNameMap( evalsPath, cache );
|
|
283
|
+
expect( map.get( 'EvalA' ) ).toBe( 'eval_a' );
|
|
284
|
+
rmSync( dir, { recursive: true, force: true } );
|
|
285
|
+
} );
|
|
286
|
+
|
|
287
|
+
it( 'buildEvaluatorsNameMap: reads names from object-arg verify pattern', () => {
|
|
288
|
+
const dir = mkdtempSync( join( tmpdir(), 'tools-verify-obj-evals-' ) );
|
|
289
|
+
const evalsPath = join( dir, 'evaluators.js' );
|
|
290
|
+
writeFileSync( evalsPath, 'export const EvalA = verify( { name: \'eval_a\' }, async () => {} )' );
|
|
291
|
+
const cache = new Map();
|
|
292
|
+
const map = buildEvaluatorsNameMap( evalsPath, cache );
|
|
293
|
+
expect( map.get( 'EvalA' ) ).toBe( 'eval_a' );
|
|
294
|
+
rmSync( dir, { recursive: true, force: true } );
|
|
295
|
+
} );
|
|
296
|
+
|
|
297
|
+
it( 'buildEvaluatorsNameMap: reads names from mixed factory patterns', () => {
|
|
298
|
+
const dir = mkdtempSync( join( tmpdir(), 'tools-mixed-evals-' ) );
|
|
299
|
+
const evalsPath = join( dir, 'evaluators.js' );
|
|
300
|
+
writeFileSync( evalsPath, [
|
|
301
|
+
'export const EvalA = verify( { name: \'eval_a\' }, async () => {} )',
|
|
302
|
+
'export const EvalB = evaluator( { name: \'eval_b\' } )'
|
|
303
|
+
].join( '\n' ) );
|
|
304
|
+
const cache = new Map();
|
|
305
|
+
const map = buildEvaluatorsNameMap( evalsPath, cache );
|
|
306
|
+
expect( map.get( 'EvalA' ) ).toBe( 'eval_a' );
|
|
307
|
+
expect( map.get( 'EvalB' ) ).toBe( 'eval_b' );
|
|
308
|
+
rmSync( dir, { recursive: true, force: true } );
|
|
309
|
+
} );
|
|
310
|
+
|
|
311
|
+
it( 'buildStepsNameMap: reads names from string-arg factory pattern', () => {
|
|
312
|
+
const dir = mkdtempSync( join( tmpdir(), 'tools-verify-steps-' ) );
|
|
313
|
+
const stepsPath = join( dir, 'steps.js' );
|
|
314
|
+
writeFileSync( stepsPath, 'export const StepA = myStepHelper( \'step_a\', async () => {} )' );
|
|
315
|
+
const cache = new Map();
|
|
316
|
+
const map = buildStepsNameMap( stepsPath, cache );
|
|
317
|
+
expect( map.get( 'StepA' ) ).toBe( 'step_a' );
|
|
318
|
+
rmSync( dir, { recursive: true, force: true } );
|
|
319
|
+
} );
|
|
320
|
+
|
|
321
|
+
it( 'buildWorkflowNameMap: reads names from string-arg factory pattern', () => {
|
|
322
|
+
const dir = mkdtempSync( join( tmpdir(), 'tools-verify-workflow-' ) );
|
|
323
|
+
const wfPath = join( dir, 'workflow.js' );
|
|
324
|
+
writeFileSync( wfPath, 'export default myWorkflowHelper( { name: \'my_flow\' } )' );
|
|
325
|
+
const cache = new Map();
|
|
326
|
+
const res = buildWorkflowNameMap( wfPath, cache );
|
|
327
|
+
expect( res.default ).toBe( 'my_flow' );
|
|
328
|
+
rmSync( dir, { recursive: true, force: true } );
|
|
329
|
+
} );
|
|
261
330
|
} );
|
|
@@ -76,66 +76,70 @@ const obj = {};`;
|
|
|
76
76
|
rmSync( dir, { recursive: true, force: true } );
|
|
77
77
|
} );
|
|
78
78
|
|
|
79
|
-
it( '
|
|
79
|
+
it( 'resolves ESM import from evaluators.js regardless of callee name', () => {
|
|
80
80
|
const dir = mkdtempSync( join( tmpdir(), 'collect-esm-mismatch-eval-' ) );
|
|
81
|
-
writeFileSync( join( dir, 'evaluators.js' ), 'export const
|
|
81
|
+
writeFileSync( join( dir, 'evaluators.js' ), 'export const MyExport = step({ name: \'bad\' });' );
|
|
82
82
|
|
|
83
|
-
const source = 'import {
|
|
83
|
+
const source = 'import { MyExport } from \'./evaluators.js\';';
|
|
84
84
|
const ast = makeAst( source, join( dir, 'file.js' ) );
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
const { evaluatorImports } = collectTargetImports(
|
|
87
87
|
ast,
|
|
88
88
|
dir,
|
|
89
89
|
{ stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
|
|
90
|
-
)
|
|
90
|
+
);
|
|
91
|
+
expect( evaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
|
|
91
92
|
|
|
92
93
|
rmSync( dir, { recursive: true, force: true } );
|
|
93
94
|
} );
|
|
94
95
|
|
|
95
|
-
it( '
|
|
96
|
+
it( 'resolves ESM import from steps.js regardless of callee name', () => {
|
|
96
97
|
const dir = mkdtempSync( join( tmpdir(), 'collect-esm-mismatch-step-' ) );
|
|
97
|
-
writeFileSync( join( dir, 'steps.js' ), 'export const
|
|
98
|
+
writeFileSync( join( dir, 'steps.js' ), 'export const MyExport = evaluator({ name: \'bad\' });' );
|
|
98
99
|
|
|
99
|
-
const source = 'import {
|
|
100
|
+
const source = 'import { MyExport } from \'./steps.js\';';
|
|
100
101
|
const ast = makeAst( source, join( dir, 'file.js' ) );
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
const { stepImports } = collectTargetImports(
|
|
103
104
|
ast,
|
|
104
105
|
dir,
|
|
105
106
|
{ stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
|
|
106
|
-
)
|
|
107
|
+
);
|
|
108
|
+
expect( stepImports ).toEqual( [ { localName: 'MyExport', stepName: 'bad' } ] );
|
|
107
109
|
|
|
108
110
|
rmSync( dir, { recursive: true, force: true } );
|
|
109
111
|
} );
|
|
110
112
|
|
|
111
|
-
it( '
|
|
113
|
+
it( 'resolves CJS require from evaluators.js regardless of callee name', () => {
|
|
112
114
|
const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-mismatch-eval-' ) );
|
|
113
|
-
writeFileSync( join( dir, 'evaluators.js' ), 'export const
|
|
115
|
+
writeFileSync( join( dir, 'evaluators.js' ), 'export const MyExport = step({ name: \'bad\' });' );
|
|
114
116
|
|
|
115
|
-
const source = 'const {
|
|
117
|
+
const source = 'const { MyExport } = require( \'./evaluators.js\' );';
|
|
116
118
|
const ast = makeAst( source, join( dir, 'file.js' ) );
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
const { evaluatorImports } = collectTargetImports(
|
|
119
121
|
ast,
|
|
120
122
|
dir,
|
|
121
123
|
{ stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
|
|
122
|
-
)
|
|
124
|
+
);
|
|
125
|
+
expect( evaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
|
|
123
126
|
|
|
124
127
|
rmSync( dir, { recursive: true, force: true } );
|
|
125
128
|
} );
|
|
126
129
|
|
|
127
|
-
it( '
|
|
130
|
+
it( 'resolves CJS require from steps.js regardless of callee name', () => {
|
|
128
131
|
const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-mismatch-step-' ) );
|
|
129
|
-
writeFileSync( join( dir, 'steps.js' ), 'export const
|
|
132
|
+
writeFileSync( join( dir, 'steps.js' ), 'export const MyExport = evaluator({ name: \'bad\' });' );
|
|
130
133
|
|
|
131
|
-
const source = 'const {
|
|
134
|
+
const source = 'const { MyExport } = require( \'./steps.js\' );';
|
|
132
135
|
const ast = makeAst( source, join( dir, 'file.js' ) );
|
|
133
136
|
|
|
134
|
-
|
|
137
|
+
const { stepImports } = collectTargetImports(
|
|
135
138
|
ast,
|
|
136
139
|
dir,
|
|
137
140
|
{ stepsNameCache: new Map(), evaluatorsNameCache: new Map(), workflowNameCache: new Map() }
|
|
138
|
-
)
|
|
141
|
+
);
|
|
142
|
+
expect( stepImports ).toEqual( [ { localName: 'MyExport', stepName: 'bad' } ] );
|
|
139
143
|
|
|
140
144
|
rmSync( dir, { recursive: true, force: true } );
|
|
141
145
|
} );
|
|
@@ -259,19 +263,19 @@ const obj = {};`;
|
|
|
259
263
|
rmSync( dir, { recursive: true, force: true } );
|
|
260
264
|
} );
|
|
261
265
|
|
|
262
|
-
it( '
|
|
266
|
+
it( 'resolves CJS shared steps require regardless of callee name', () => {
|
|
263
267
|
const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-shared-step-mismatch-' ) );
|
|
264
268
|
mkdirSync( join( dir, 'shared', 'steps' ), { recursive: true } );
|
|
265
269
|
mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
|
|
266
270
|
writeFileSync(
|
|
267
271
|
join( dir, 'shared', 'steps', 'common.js' ),
|
|
268
|
-
'export const
|
|
272
|
+
'export const MyExport = evaluator({ name: \'bad\' });'
|
|
269
273
|
);
|
|
270
274
|
|
|
271
|
-
const source = 'const {
|
|
275
|
+
const source = 'const { MyExport } = require( \'../../shared/steps/common.js\' );';
|
|
272
276
|
const ast = makeAst( source, join( dir, 'workflows', 'my_workflow', 'workflow.js' ) );
|
|
273
277
|
|
|
274
|
-
|
|
278
|
+
const { sharedStepImports } = collectTargetImports(
|
|
275
279
|
ast,
|
|
276
280
|
join( dir, 'workflows', 'my_workflow' ),
|
|
277
281
|
{
|
|
@@ -279,49 +283,52 @@ const obj = {};`;
|
|
|
279
283
|
evaluatorsNameCache: new Map(), sharedEvaluatorsNameCache: new Map(),
|
|
280
284
|
workflowNameCache: new Map()
|
|
281
285
|
}
|
|
282
|
-
)
|
|
286
|
+
);
|
|
287
|
+
expect( sharedStepImports ).toEqual( [ { localName: 'MyExport', stepName: 'bad' } ] );
|
|
283
288
|
|
|
284
289
|
rmSync( dir, { recursive: true, force: true } );
|
|
285
290
|
} );
|
|
286
291
|
|
|
287
|
-
it( '
|
|
292
|
+
it( 'resolves CJS shared evaluator require regardless of callee name', () => {
|
|
288
293
|
const dir = mkdtempSync( join( tmpdir(), 'collect-cjs-shared-eval-mismatch-' ) );
|
|
289
294
|
mkdirSync( join( dir, 'shared', 'evaluators' ), { recursive: true } );
|
|
290
295
|
mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
|
|
291
296
|
writeFileSync(
|
|
292
297
|
join( dir, 'shared', 'evaluators', 'common.js' ),
|
|
293
|
-
'export const
|
|
298
|
+
'export const MyExport = step({ name: \'bad\' });'
|
|
294
299
|
);
|
|
295
300
|
|
|
296
|
-
const source = 'const {
|
|
301
|
+
const source = 'const { MyExport } = require( \'../../shared/evaluators/common.js\' );';
|
|
297
302
|
const ast = makeAst( source, join( dir, 'workflows', 'my_workflow', 'workflow.js' ) );
|
|
298
303
|
|
|
299
|
-
|
|
304
|
+
const { sharedEvaluatorImports } = collectTargetImports(
|
|
300
305
|
ast,
|
|
301
306
|
join( dir, 'workflows', 'my_workflow' ),
|
|
302
307
|
{ stepsNameCache: new Map(), evaluatorsNameCache: new Map(), sharedEvaluatorsNameCache: new Map(), workflowNameCache: new Map() }
|
|
303
|
-
)
|
|
308
|
+
);
|
|
309
|
+
expect( sharedEvaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
|
|
304
310
|
|
|
305
311
|
rmSync( dir, { recursive: true, force: true } );
|
|
306
312
|
} );
|
|
307
313
|
|
|
308
|
-
it( '
|
|
314
|
+
it( 'resolves ESM shared evaluator import regardless of callee name', () => {
|
|
309
315
|
const dir = mkdtempSync( join( tmpdir(), 'collect-esm-shared-eval-mismatch-' ) );
|
|
310
316
|
mkdirSync( join( dir, 'shared', 'evaluators' ), { recursive: true } );
|
|
311
317
|
mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
|
|
312
318
|
writeFileSync(
|
|
313
319
|
join( dir, 'shared', 'evaluators', 'common.js' ),
|
|
314
|
-
'export const
|
|
320
|
+
'export const MyExport = step({ name: \'bad\' });'
|
|
315
321
|
);
|
|
316
322
|
|
|
317
|
-
const source = 'import {
|
|
323
|
+
const source = 'import { MyExport } from \'../../shared/evaluators/common.js\';';
|
|
318
324
|
const ast = makeAst( source, join( dir, 'workflows', 'my_workflow', 'workflow.js' ) );
|
|
319
325
|
|
|
320
|
-
|
|
326
|
+
const { sharedEvaluatorImports } = collectTargetImports(
|
|
321
327
|
ast,
|
|
322
328
|
join( dir, 'workflows', 'my_workflow' ),
|
|
323
329
|
{ stepsNameCache: new Map(), evaluatorsNameCache: new Map(), sharedEvaluatorsNameCache: new Map(), workflowNameCache: new Map() }
|
|
324
|
-
)
|
|
330
|
+
);
|
|
331
|
+
expect( sharedEvaluatorImports ).toEqual( [ { localName: 'MyExport', evaluatorName: 'bad' } ] );
|
|
325
332
|
|
|
326
333
|
rmSync( dir, { recursive: true, force: true } );
|
|
327
334
|
} );
|
|
@@ -285,12 +285,12 @@ describe( 'workflow_validator loader', () => {
|
|
|
285
285
|
rmSync( dir, { recursive: true, force: true } );
|
|
286
286
|
} );
|
|
287
287
|
|
|
288
|
-
it( 'workflow.js: allows imports from ../../
|
|
289
|
-
const dir = mkdtempSync( join( tmpdir(), 'wf-
|
|
288
|
+
it( 'workflow.js: allows imports from ../../clients/pokeapi.js', async () => {
|
|
289
|
+
const dir = mkdtempSync( join( tmpdir(), 'wf-clients-' ) );
|
|
290
290
|
mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
|
|
291
|
-
mkdirSync( join( dir, '
|
|
292
|
-
writeFileSync( join( dir, '
|
|
293
|
-
const src = 'import { getPokemon } from "../../
|
|
291
|
+
mkdirSync( join( dir, 'clients' ), { recursive: true } );
|
|
292
|
+
writeFileSync( join( dir, 'clients', 'pokeapi.js' ), 'export const getPokemon = () => {};\n' );
|
|
293
|
+
const src = 'import { getPokemon } from "../../clients/pokeapi.js";';
|
|
294
294
|
await expect( runLoader( join( dir, 'workflows', 'my_workflow', 'workflow.js' ), src ) ).resolves.toBeTruthy();
|
|
295
295
|
rmSync( dir, { recursive: true, force: true } );
|
|
296
296
|
} );
|
|
@@ -305,12 +305,12 @@ describe( 'workflow_validator loader', () => {
|
|
|
305
305
|
rmSync( dir, { recursive: true, force: true } );
|
|
306
306
|
} );
|
|
307
307
|
|
|
308
|
-
it( 'steps.ts: allows imports from ../../
|
|
309
|
-
const dir = mkdtempSync( join( tmpdir(), 'steps-
|
|
308
|
+
it( 'steps.ts: allows imports from ../../clients/redis.js', async () => {
|
|
309
|
+
const dir = mkdtempSync( join( tmpdir(), 'steps-clients-' ) );
|
|
310
310
|
mkdirSync( join( dir, 'workflows', 'my_workflow' ), { recursive: true } );
|
|
311
|
-
mkdirSync( join( dir, '
|
|
312
|
-
writeFileSync( join( dir, '
|
|
313
|
-
const src = 'import { client } from "../../
|
|
311
|
+
mkdirSync( join( dir, 'clients' ), { recursive: true } );
|
|
312
|
+
writeFileSync( join( dir, 'clients', 'redis.js' ), 'export const client = {};\n' );
|
|
313
|
+
const src = 'import { client } from "../../clients/redis.js";';
|
|
314
314
|
await expect( runLoader( join( dir, 'workflows', 'my_workflow', 'steps.js' ), src ) ).resolves.toBeTruthy();
|
|
315
315
|
rmSync( dir, { recursive: true, force: true } );
|
|
316
316
|
} );
|