@chainlink/cre-sdk 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +36 -9
  2. package/dist/generated/capabilities/blockchain/evm/v1alpha/client_pb.js +1 -1
  3. package/dist/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb.d.ts +135 -0
  4. package/dist/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb.js +43 -0
  5. package/dist/generated/capabilities/internal/basicaction/v1/basic_action_pb.d.ts +77 -0
  6. package/dist/generated/capabilities/internal/basicaction/v1/basic_action_pb.js +33 -0
  7. package/dist/generated/capabilities/internal/nodeaction/v1/node_action_pb.d.ts +69 -0
  8. package/dist/generated/capabilities/internal/nodeaction/v1/node_action_pb.js +29 -0
  9. package/dist/generated/capabilities/networking/confidentialhttp/v1alpha/client_pb.d.ts +199 -100
  10. package/dist/generated/capabilities/networking/confidentialhttp/v1alpha/client_pb.js +18 -18
  11. package/dist/generated/capabilities/networking/http/v1alpha/client_pb.d.ts +69 -4
  12. package/dist/generated/capabilities/networking/http/v1alpha/client_pb.js +10 -3
  13. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +1 -0
  14. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +1 -0
  15. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +4 -18
  16. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +7 -34
  17. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +0 -3
  18. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +0 -3
  19. package/dist/sdk/cre/index.d.ts +1 -1
  20. package/dist/sdk/cre/index.js +1 -1
  21. package/dist/sdk/errors.d.ts +2 -2
  22. package/dist/sdk/errors.js +3 -1
  23. package/dist/sdk/impl/runtime-impl.js +5 -5
  24. package/dist/sdk/test/generated/capabilities/blockchain/evm/v1alpha/evm_mock_gen.d.ts +31 -0
  25. package/dist/sdk/test/generated/capabilities/blockchain/evm/v1alpha/evm_mock_gen.js +158 -0
  26. package/dist/sdk/test/generated/capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen.d.ts +17 -0
  27. package/dist/sdk/test/generated/capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen.js +53 -0
  28. package/dist/sdk/test/generated/capabilities/internal/basicaction/v1/basic_test_action_mock_gen.d.ts +17 -0
  29. package/dist/sdk/test/generated/capabilities/internal/basicaction/v1/basic_test_action_mock_gen.js +53 -0
  30. package/dist/sdk/test/generated/capabilities/internal/consensus/v1alpha/consensus_mock_gen.d.ts +20 -0
  31. package/dist/sdk/test/generated/capabilities/internal/consensus/v1alpha/consensus_mock_gen.js +67 -0
  32. package/dist/sdk/test/generated/capabilities/internal/nodeaction/v1/basic_test_node_action_mock_gen.d.ts +17 -0
  33. package/dist/sdk/test/generated/capabilities/internal/nodeaction/v1/basic_test_node_action_mock_gen.js +53 -0
  34. package/dist/sdk/test/generated/capabilities/networking/confidentialhttp/v1alpha/confidential_http_mock_gen.d.ts +17 -0
  35. package/dist/sdk/test/generated/capabilities/networking/confidentialhttp/v1alpha/confidential_http_mock_gen.js +53 -0
  36. package/dist/sdk/test/generated/capabilities/networking/http/v1alpha/http_actions_mock_gen.d.ts +17 -0
  37. package/dist/sdk/test/generated/capabilities/networking/http/v1alpha/http_actions_mock_gen.js +53 -0
  38. package/dist/sdk/test/generated/index.d.ts +8 -0
  39. package/dist/sdk/test/generated/index.js +8 -0
  40. package/dist/sdk/test/index.d.ts +7 -0
  41. package/dist/sdk/test/index.js +7 -0
  42. package/dist/sdk/testutils/index.d.ts +6 -0
  43. package/dist/sdk/testutils/index.js +6 -0
  44. package/dist/sdk/testutils/test-runtime.d.ts +84 -0
  45. package/dist/sdk/testutils/test-runtime.js +309 -0
  46. package/dist/sdk/testutils/test-writer.d.ts +13 -0
  47. package/dist/sdk/testutils/test-writer.js +19 -0
  48. package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.d.ts +1 -1
  49. package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.js +5 -0
  50. package/dist/sdk/utils/capabilities/http/http-helpers.d.ts +7 -7
  51. package/dist/sdk/utils/chain-selectors/network-lookup.js +1 -1
  52. package/dist/sdk/utils/hex-utils.js +12 -0
  53. package/dist/sdk/utils/values/value.js +10 -6
  54. package/dist/sdk/wasm/host-bindings.js +3 -1
  55. package/dist/sdk/wasm/runner.js +22 -8
  56. package/dist/sdk/wasm/runtime.js +10 -9
  57. package/dist/sdk/wasm/send-error-response.js +6 -0
  58. package/dist/workflows/standard_tests/host_wasm_write_errors_are_respected/test.ts +1 -1
  59. package/dist/workflows/standard_tests/mode_switch/don_runtime_in_node_mode/test.ts +1 -1
  60. package/dist/workflows/standard_tests/time_interpretation/test.ts +32 -0
  61. package/package.json +11 -6
  62. package/scripts/src/cre-setup.ts +1 -1
  63. package/scripts/src/generate-sdks.ts +52 -0
@@ -0,0 +1,67 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { ReportRequestSchema, ReportResponseSchema, SimpleConsensusInputsSchema, } from '../../../../../../../generated/sdk/v1alpha/sdk_pb';
4
+ import { ValueSchema } from '../../../../../../../generated/values/v1/values_pb';
5
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
6
+ /**
7
+ * Mock for ConsensusCapability. Use testInstance() to obtain an instance; do not construct directly.
8
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
9
+ */
10
+ export class ConsensusMock {
11
+ static CAPABILITY_ID = 'consensus@1.0.0-alpha';
12
+ /** Set to define the return value for Simple. May return a plain object (ValueJson) or the message type. */
13
+ simple;
14
+ /** Set to define the return value for Report. May return a plain object (ReportResponseJson) or the message type. */
15
+ report;
16
+ constructor() {
17
+ const self = this;
18
+ const qualifiedId = ConsensusMock.CAPABILITY_ID;
19
+ try {
20
+ registerTestCapability(qualifiedId, (req) => {
21
+ switch (req.method) {
22
+ case 'Simple': {
23
+ const input = anyUnpack(req.payload, SimpleConsensusInputsSchema);
24
+ const handler = self.simple;
25
+ if (typeof handler !== 'function')
26
+ throw new Error("Simple: no implementation provided; set the mock's simple property to define the return value.");
27
+ const raw = handler(input);
28
+ const output = raw && typeof raw.$typeName === 'string'
29
+ ? raw
30
+ : fromJson(ValueSchema, raw);
31
+ return { response: { case: 'payload', value: anyPack(ValueSchema, output) } };
32
+ }
33
+ case 'Report': {
34
+ const input = anyUnpack(req.payload, ReportRequestSchema);
35
+ const handler = self.report;
36
+ if (typeof handler !== 'function')
37
+ throw new Error("Report: no implementation provided; set the mock's report property to define the return value.");
38
+ const raw = handler(input);
39
+ const output = raw && typeof raw.$typeName === 'string'
40
+ ? raw
41
+ : fromJson(ReportResponseSchema, raw);
42
+ return { response: { case: 'payload', value: anyPack(ReportResponseSchema, output) } };
43
+ }
44
+ default:
45
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
46
+ }
47
+ });
48
+ }
49
+ catch {
50
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
51
+ }
52
+ }
53
+ /**
54
+ * Returns the mock instance for this capability.
55
+ * Multiple calls with the same arguments return the same instance.
56
+ * Must be called within the test framework's test() method.
57
+ */
58
+ static testInstance() {
59
+ const qualifiedId = ConsensusMock.CAPABILITY_ID;
60
+ let instance = __getTestMockInstance(qualifiedId);
61
+ if (!instance) {
62
+ instance = new ConsensusMock();
63
+ __setTestMockInstance(qualifiedId, instance);
64
+ }
65
+ return instance;
66
+ }
67
+ }
@@ -0,0 +1,17 @@
1
+ import { type NodeInputs, type NodeOutputs, type NodeOutputsJson } from '../../../../../../../generated/capabilities/internal/nodeaction/v1/node_action_pb';
2
+ /**
3
+ * Mock for BasicActionCapability. Use testInstance() to obtain an instance; do not construct directly.
4
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
5
+ */
6
+ export declare class BasicTestNodeActionMock {
7
+ static readonly CAPABILITY_ID = "basic-test-node-action@1.0.0";
8
+ /** Set to define the return value for PerformAction. May return a plain object (NodeOutputsJson) or the message type. */
9
+ performAction?: (input: NodeInputs) => NodeOutputs | NodeOutputsJson;
10
+ private constructor();
11
+ /**
12
+ * Returns the mock instance for this capability.
13
+ * Multiple calls with the same arguments return the same instance.
14
+ * Must be called within the test framework's test() method.
15
+ */
16
+ static testInstance(): BasicTestNodeActionMock;
17
+ }
@@ -0,0 +1,53 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { NodeInputsSchema, NodeOutputsSchema, } from '../../../../../../../generated/capabilities/internal/nodeaction/v1/node_action_pb';
4
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
+ /**
6
+ * Mock for BasicActionCapability. Use testInstance() to obtain an instance; do not construct directly.
7
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
8
+ */
9
+ export class BasicTestNodeActionMock {
10
+ static CAPABILITY_ID = 'basic-test-node-action@1.0.0';
11
+ /** Set to define the return value for PerformAction. May return a plain object (NodeOutputsJson) or the message type. */
12
+ performAction;
13
+ constructor() {
14
+ const self = this;
15
+ const qualifiedId = BasicTestNodeActionMock.CAPABILITY_ID;
16
+ try {
17
+ registerTestCapability(qualifiedId, (req) => {
18
+ switch (req.method) {
19
+ case 'PerformAction': {
20
+ const input = anyUnpack(req.payload, NodeInputsSchema);
21
+ const handler = self.performAction;
22
+ if (typeof handler !== 'function')
23
+ throw new Error("PerformAction: no implementation provided; set the mock's performAction property to define the return value.");
24
+ const raw = handler(input);
25
+ const output = raw && typeof raw.$typeName === 'string'
26
+ ? raw
27
+ : fromJson(NodeOutputsSchema, raw);
28
+ return { response: { case: 'payload', value: anyPack(NodeOutputsSchema, output) } };
29
+ }
30
+ default:
31
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
32
+ }
33
+ });
34
+ }
35
+ catch {
36
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
37
+ }
38
+ }
39
+ /**
40
+ * Returns the mock instance for this capability.
41
+ * Multiple calls with the same arguments return the same instance.
42
+ * Must be called within the test framework's test() method.
43
+ */
44
+ static testInstance() {
45
+ const qualifiedId = BasicTestNodeActionMock.CAPABILITY_ID;
46
+ let instance = __getTestMockInstance(qualifiedId);
47
+ if (!instance) {
48
+ instance = new BasicTestNodeActionMock();
49
+ __setTestMockInstance(qualifiedId, instance);
50
+ }
51
+ return instance;
52
+ }
53
+ }
@@ -0,0 +1,17 @@
1
+ import { type ConfidentialHTTPRequest, type HTTPResponse, type HTTPResponseJson } from '../../../../../../../generated/capabilities/networking/confidentialhttp/v1alpha/client_pb';
2
+ /**
3
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
4
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
5
+ */
6
+ export declare class ConfidentialHttpMock {
7
+ static readonly CAPABILITY_ID = "confidential-http@1.0.0-alpha";
8
+ /** Set to define the return value for SendRequest. May return a plain object (HTTPResponseJson) or the message type. */
9
+ sendRequest?: (input: ConfidentialHTTPRequest) => HTTPResponse | HTTPResponseJson;
10
+ private constructor();
11
+ /**
12
+ * Returns the mock instance for this capability.
13
+ * Multiple calls with the same arguments return the same instance.
14
+ * Must be called within the test framework's test() method.
15
+ */
16
+ static testInstance(): ConfidentialHttpMock;
17
+ }
@@ -0,0 +1,53 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { ConfidentialHTTPRequestSchema, HTTPResponseSchema, } from '../../../../../../../generated/capabilities/networking/confidentialhttp/v1alpha/client_pb';
4
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
+ /**
6
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
7
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
8
+ */
9
+ export class ConfidentialHttpMock {
10
+ static CAPABILITY_ID = 'confidential-http@1.0.0-alpha';
11
+ /** Set to define the return value for SendRequest. May return a plain object (HTTPResponseJson) or the message type. */
12
+ sendRequest;
13
+ constructor() {
14
+ const self = this;
15
+ const qualifiedId = ConfidentialHttpMock.CAPABILITY_ID;
16
+ try {
17
+ registerTestCapability(qualifiedId, (req) => {
18
+ switch (req.method) {
19
+ case 'SendRequest': {
20
+ const input = anyUnpack(req.payload, ConfidentialHTTPRequestSchema);
21
+ const handler = self.sendRequest;
22
+ if (typeof handler !== 'function')
23
+ throw new Error("SendRequest: no implementation provided; set the mock's sendRequest property to define the return value.");
24
+ const raw = handler(input);
25
+ const output = raw && typeof raw.$typeName === 'string'
26
+ ? raw
27
+ : fromJson(HTTPResponseSchema, raw);
28
+ return { response: { case: 'payload', value: anyPack(HTTPResponseSchema, output) } };
29
+ }
30
+ default:
31
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
32
+ }
33
+ });
34
+ }
35
+ catch {
36
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
37
+ }
38
+ }
39
+ /**
40
+ * Returns the mock instance for this capability.
41
+ * Multiple calls with the same arguments return the same instance.
42
+ * Must be called within the test framework's test() method.
43
+ */
44
+ static testInstance() {
45
+ const qualifiedId = ConfidentialHttpMock.CAPABILITY_ID;
46
+ let instance = __getTestMockInstance(qualifiedId);
47
+ if (!instance) {
48
+ instance = new ConfidentialHttpMock();
49
+ __setTestMockInstance(qualifiedId, instance);
50
+ }
51
+ return instance;
52
+ }
53
+ }
@@ -0,0 +1,17 @@
1
+ import { type Request, type Response, type ResponseJson } from '../../../../../../../generated/capabilities/networking/http/v1alpha/client_pb';
2
+ /**
3
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
4
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
5
+ */
6
+ export declare class HttpActionsMock {
7
+ static readonly CAPABILITY_ID = "http-actions@1.0.0-alpha";
8
+ /** Set to define the return value for SendRequest. May return a plain object (ResponseJson) or the message type. */
9
+ sendRequest?: (input: Request) => Response | ResponseJson;
10
+ private constructor();
11
+ /**
12
+ * Returns the mock instance for this capability.
13
+ * Multiple calls with the same arguments return the same instance.
14
+ * Must be called within the test framework's test() method.
15
+ */
16
+ static testInstance(): HttpActionsMock;
17
+ }
@@ -0,0 +1,53 @@
1
+ import { fromJson } from '@bufbuild/protobuf';
2
+ import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
3
+ import { RequestSchema, ResponseSchema, } from '../../../../../../../generated/capabilities/networking/http/v1alpha/client_pb';
4
+ import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
5
+ /**
6
+ * Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
7
+ * Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
8
+ */
9
+ export class HttpActionsMock {
10
+ static CAPABILITY_ID = 'http-actions@1.0.0-alpha';
11
+ /** Set to define the return value for SendRequest. May return a plain object (ResponseJson) or the message type. */
12
+ sendRequest;
13
+ constructor() {
14
+ const self = this;
15
+ const qualifiedId = HttpActionsMock.CAPABILITY_ID;
16
+ try {
17
+ registerTestCapability(qualifiedId, (req) => {
18
+ switch (req.method) {
19
+ case 'SendRequest': {
20
+ const input = anyUnpack(req.payload, RequestSchema);
21
+ const handler = self.sendRequest;
22
+ if (typeof handler !== 'function')
23
+ throw new Error("SendRequest: no implementation provided; set the mock's sendRequest property to define the return value.");
24
+ const raw = handler(input);
25
+ const output = raw && typeof raw.$typeName === 'string'
26
+ ? raw
27
+ : fromJson(ResponseSchema, raw);
28
+ return { response: { case: 'payload', value: anyPack(ResponseSchema, output) } };
29
+ }
30
+ default:
31
+ return { response: { case: 'error', value: `unknown method ${req.method}` } };
32
+ }
33
+ });
34
+ }
35
+ catch {
36
+ throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
37
+ }
38
+ }
39
+ /**
40
+ * Returns the mock instance for this capability.
41
+ * Multiple calls with the same arguments return the same instance.
42
+ * Must be called within the test framework's test() method.
43
+ */
44
+ static testInstance() {
45
+ const qualifiedId = HttpActionsMock.CAPABILITY_ID;
46
+ let instance = __getTestMockInstance(qualifiedId);
47
+ if (!instance) {
48
+ instance = new HttpActionsMock();
49
+ __setTestMockInstance(qualifiedId, instance);
50
+ }
51
+ return instance;
52
+ }
53
+ }
@@ -0,0 +1,8 @@
1
+ /** Auto-generated barrel of capability mocks. Do not edit. */
2
+ export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
3
+ export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
4
+ export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
5
+ export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
6
+ export { BasicTestNodeActionMock } from './capabilities/internal/nodeaction/v1/basic_test_node_action_mock_gen';
7
+ export { ConfidentialHttpMock } from './capabilities/networking/confidentialhttp/v1alpha/confidential_http_mock_gen';
8
+ export { HttpActionsMock } from './capabilities/networking/http/v1alpha/http_actions_mock_gen';
@@ -0,0 +1,8 @@
1
+ /** Auto-generated barrel of capability mocks. Do not edit. */
2
+ export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
3
+ export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
4
+ export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
5
+ export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
6
+ export { BasicTestNodeActionMock } from './capabilities/internal/nodeaction/v1/basic_test_node_action_mock_gen';
7
+ export { ConfidentialHttpMock } from './capabilities/networking/confidentialhttp/v1alpha/confidential_http_mock_gen';
8
+ export { HttpActionsMock } from './capabilities/networking/http/v1alpha/http_actions_mock_gen';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test-only surface for the CRE SDK: test framework and (when generated) capability mocks.
3
+ * Use for unit testing runtime logic without the WASM execution environment.
4
+ */
5
+ export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState, test, } from '../testutils/test-runtime';
6
+ export { TestWriter } from '../testutils/test-writer';
7
+ export * from './generated';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test-only surface for the CRE SDK: test framework and (when generated) capability mocks.
3
+ * Use for unit testing runtime logic without the WASM execution environment.
4
+ */
5
+ export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime, test, } from '../testutils/test-runtime';
6
+ export { TestWriter } from '../testutils/test-writer';
7
+ export * from './generated';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Test-only utilities for the CRE SDK runtime. Not part of the public API.
3
+ * Use for unit testing runtime logic without the WASM execution environment.
4
+ */
5
+ export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState, test, } from './test-runtime';
6
+ export { TestWriter } from './test-writer';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Test-only utilities for the CRE SDK runtime. Not part of the public API.
3
+ * Use for unit testing runtime logic without the WASM execution environment.
4
+ */
5
+ export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime, test, } from './test-runtime';
6
+ export { TestWriter } from './test-writer';
@@ -0,0 +1,84 @@
1
+ /**
2
+ * TestRuntime and harness for testing the CRE SDK runtime without WASM.
3
+ * Registry is scoped per test via AsyncLocalStorage; use testWithRuntime to run tests with a registry.
4
+ */
5
+ import type { Any } from '@bufbuild/protobuf/wkt';
6
+ import type { RuntimeHelpers } from '../impl/runtime-impl';
7
+ import { RuntimeImpl } from '../impl/runtime-impl';
8
+ import { TestWriter } from './test-writer';
9
+ /** Error message when response exceeds max size. Used by the harness when its await implements the size check. */
10
+ export declare const RESPONSE_BUFFER_TOO_SMALL = "response buffer too small";
11
+ export declare const DEFAULT_MAX_RESPONSE_SIZE_BYTES: number;
12
+ export declare const REPORT_METADATA_HEADER_LENGTH = 109;
13
+ export type Secrets = Map<string, Map<string, string>>;
14
+ export type CapabilityHandler = (request: {
15
+ id: string;
16
+ method: string;
17
+ payload: Any;
18
+ }) => {
19
+ response: {
20
+ case: 'payload';
21
+ value: Any;
22
+ };
23
+ } | {
24
+ response: {
25
+ case: 'error';
26
+ value: string;
27
+ };
28
+ };
29
+ /**
30
+ * Returns the capability handler for the given id from the current test's registry, if any.
31
+ * Only defined when called inside a testWithRuntime scope (after the handler is registered).
32
+ */
33
+ export declare function getTestCapabilityHandler(id: string): CapabilityHandler | undefined;
34
+ /**
35
+ * Registers a capability handler for the current test's registry.
36
+ * Must be called inside a testWithRuntime scope; throws if no registry is active.
37
+ */
38
+ export declare function registerTestCapability(id: string, handler: CapabilityHandler): void;
39
+ /**
40
+ * Gets a mock instance from the current test's registry, or undefined if not found or no registry active.
41
+ * @internal Used by generated mocks for singleton pattern.
42
+ */
43
+ export declare function __getTestMockInstance<T>(id: string): T | undefined;
44
+ /**
45
+ * Stores a mock instance in the current test's registry.
46
+ * @internal Used by generated mocks for singleton pattern.
47
+ */
48
+ export declare function __setTestMockInstance<T>(id: string, instance: T): void;
49
+ /**
50
+ * Test-only: returns the current registry store (for cleanup/isolation assertions).
51
+ * Do not use in production code.
52
+ */
53
+ export declare function __testOnlyRegistryStore(): object | undefined;
54
+ /**
55
+ * Test-only: runs a callback with a fresh registry and cleans up (for cleanup/failure tests).
56
+ * Do not use in production code.
57
+ */
58
+ export declare function __testOnlyRunWithRegistry(fn: () => void | Promise<void>): Promise<void>;
59
+ export interface TestRuntimeState {
60
+ timeProvider?: () => number;
61
+ }
62
+ export interface NewTestRuntimeOptions {
63
+ timeProvider?: () => number;
64
+ maxResponseSize?: number;
65
+ }
66
+ /**
67
+ * Runs a test using the CRE runtime.
68
+ */
69
+ export declare function test(title: string, fn: () => void | Promise<void>): void;
70
+ /**
71
+ * Creates a test runtime. This must be called from within a test in this package.
72
+ */
73
+ export declare function newTestRuntime(secrets?: Secrets | null, options?: NewTestRuntimeOptions): TestRuntime;
74
+ /**
75
+ * TestRuntime is a Runtime implementation for unit tests. Extends RuntimeImpl; construct via newTestRuntime.
76
+ * Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
77
+ */
78
+ export declare class TestRuntime extends RuntimeImpl<unknown> {
79
+ private readonly testWriter;
80
+ private readonly state;
81
+ constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState);
82
+ getLogs(): string[];
83
+ setTimeProvider(timeProvider: () => number): void;
84
+ }