Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/github/codeql-acti…
Browse files Browse the repository at this point in the history
…on-3.26.11
  • Loading branch information
TimothyJones authored Oct 7, 2024
2 parents e65150a + b38565c commit f5018e3
Show file tree
Hide file tree
Showing 126 changed files with 3,156 additions and 1,853 deletions.
18 changes: 15 additions & 3 deletions docs/maintainers/MaintainerLogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ At this level, logs can be super verbose.
## Connector maintainer debug

If you need to debug the connector layer, you can set the environment variable
`CASE_CONNECTOR_DEBUG` to anything other than `0` or `false`. This is a separate log stream to the `logLevel` - it can be set independently. At this log level,
all communication between the core connector and the host
language client is logged. It's extremely verbose.
`CASE_CONNECTOR_DEBUG` to `true`. This is a separate log stream to the
usual config `logLevel` - it can be set independently. This will log the communication
and a few other things that have been useful during previous debug sessions. It
will be sent to the connector process' standard error stream.

At this log level, most of the communication between the core connector and the host
language client is logged.

### Deep connector maintainer debug

With `CASE_CONNECTOR_DEBUG=true`, the majority of communication that is to do
with logging and printing test output is still not printed. If you really need
to log everything, set `CASE_CONNECTOR_DEBUG` to `deep` or `deepMaintainerDebug`.
This is extremely verbose, and mostly useful when first implementing a new
language's connector.
12 changes: 11 additions & 1 deletion docs/maintainers/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Java:

Next:

- [ ] Configuration Errors in triggers are incorrectly mapped to verification failures
- [ ] Don't throw exceptions in the DSL - it won't be handled correctly by JSii.
- [ ] Perhaps separate the DSL's needs in the definition package and the pretty-format, bit too.
- [ ] Rename handle -> functonName in the registerFunction() calls
- [ ] Fix variables so that you can have different defaults for different states
- [ ] State handlers in the grpc connector aren't given the configuration
- [ ] Connect CASE_CONNECTOR_CLIENT to a maintainer log somewhere
- [ ] Connect CASE_CONNECTOR_CLIENT in Jest DSL - probably include it in an
Expand Down Expand Up @@ -100,6 +103,13 @@ Next:
- [ ] There should be a never-throws boundary in the domain layer, in case the mappers throw
- [ ] DRY out the unexpected error handler

## Mindless tasks

Good for when I don't want to think

- [ ] Replace all `maintainerLog` lines with appropriate `connectorDebugLog` lines
- [ ] Kill

## Documentation todos

- [ ] case-context ? Maybe move this out
Expand Down
5 changes: 1 addition & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/case-connector-proto/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Case-Connector-Proto

[![Build and test](https://github.com/case-contract-testing/case/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/case-contract-testing/case/actions/workflows/build-and-test.yml)
[![Known Vulnerabilities](https://snyk.io/test/github/case-contract-testing/case/badge.svg?targetFile=packages/case-connector-proto/package.json)](https://snyk.io/test/github/case-contract-testing/case?targetFile=packages/case-connector-proto/package.json)
[![Build and test](https://github.com/case-contract-testing/contract-case/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/case-contract-testing/contract-case/actions/workflows/build-and-test.yml)
[![Known Vulnerabilities](https://snyk.io/test/github/case-contract-testing/contract-case/badge.svg?targetFile=packages/case-connector-proto/package.json)](https://snyk.io/test/github/case-contract-testing/?targetFile=packages/case-connector-proto/package.json)

This is the proto module for CaseConnector. It contains only the generated code.

Expand Down
35 changes: 26 additions & 9 deletions packages/case-connector-proto/proto/contract_case_stream.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ message ContractCaseConfig {
}

// Indicates a successful response with no payload
message ResultSuccess {}
message ResultSuccessHasMapPayload { google.protobuf.Struct map = 1; }
message ResultSuccessHasAnyPayload { google.protobuf.Value payload = 1; }
message ResultSuccess {
}
message ResultSuccessHasMapPayload {
// Always a map of Strings -> Strings
google.protobuf.Struct map = 1;
}
message ResultSuccessHasAnyPayload {
// Always a JSON serialised object
google.protobuf.StringValue payload = 1;
}
message ResultFailure {
google.protobuf.StringValue kind = 1;
google.protobuf.StringValue message = 2;
Expand All @@ -67,7 +74,9 @@ message StateHandlerHandle {
Stage stage = 2;
}

message TriggerFunctionHandle { google.protobuf.StringValue handle = 1; }
message TriggerFunctionHandle {
google.protobuf.StringValue handle = 1;
}

// Requests from client / host

Expand All @@ -93,11 +102,14 @@ message RunRejectingExampleRequest {

// From host to core, instructs the core to strip the matchers from a given
// matcher / data object
message StripMatchersRequest { google.protobuf.Struct matcher_or_data = 2; }
message StripMatchersRequest {
google.protobuf.Struct matcher_or_data = 2;
}

// From host to core, instructs the core to finish the current contract
// definition
message EndDefinitionRequest {}
message EndDefinitionRequest {
}

// From host to core, instructs the core to load a plugin
message LoadPluginRequest {
Expand All @@ -109,7 +121,9 @@ message LoadPluginRequest {
// Responses from server

// From Core to Host, instructs the host to run a given state handler
message RunStateHandlerRequest { StateHandlerHandle state_handler_handle = 1; }
message RunStateHandlerRequest {
StateHandlerHandle state_handler_handle = 1;
}

// From Core to Host, requests the host invoke one of the user-provided
// triggers.
Expand Down Expand Up @@ -255,7 +269,9 @@ message PrintTestTitleRequest {
//
// Most messages must be acknowledged with a response - this indicates the
// return of the previous message.
message ResultResponse { BoundaryResult result = 1; }
message ResultResponse {
BoundaryResult result = 1;
}

// From the Host to the Core, requests that a verification session begins
message BeginVerificationRequest {
Expand All @@ -266,7 +282,8 @@ message BeginVerificationRequest {
}

// From the Host to the Core, requests a list of the available contracts
message AvailableContractDefinitions {}
message AvailableContractDefinitions {
}

// From the Host to the Core, instructs the core that the current verification
// session is now configured, and asks it to execute the verification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ export namespace ResultSuccessHasMapPayload {
export class ResultSuccessHasAnyPayload extends jspb.Message {
hasPayload(): boolean;
clearPayload(): void;
getPayload(): google_protobuf_struct_pb.Value | undefined;
getPayload(): google_protobuf_wrappers_pb.StringValue | undefined;
setPayload(
value?: google_protobuf_struct_pb.Value,
value?: google_protobuf_wrappers_pb.StringValue,
): ResultSuccessHasAnyPayload;

serializeBinary(): Uint8Array;
Expand All @@ -288,7 +288,7 @@ export class ResultSuccessHasAnyPayload extends jspb.Message {

export namespace ResultSuccessHasAnyPayload {
export type AsObject = {
payload?: google_protobuf_struct_pb.Value.AsObject;
payload?: google_protobuf_wrappers_pb.StringValue.AsObject;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload.prototype
*/
proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload.toObject = function(includeInstance, msg) {
var f, obj = {
payload: (f = msg.getPayload()) && google_protobuf_struct_pb.Value.toObject(includeInstance, f)
payload: (f = msg.getPayload()) && google_protobuf_wrappers_pb.StringValue.toObject(includeInstance, f)
};

if (includeInstance) {
Expand Down Expand Up @@ -2147,8 +2147,8 @@ proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload.deseriali
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = new google_protobuf_struct_pb.Value;
reader.readMessage(value,google_protobuf_struct_pb.Value.deserializeBinaryFromReader);
var value = new google_protobuf_wrappers_pb.StringValue;
reader.readMessage(value,google_protobuf_wrappers_pb.StringValue.deserializeBinaryFromReader);
msg.setPayload(value);
break;
default:
Expand Down Expand Up @@ -2185,24 +2185,24 @@ proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload.serialize
writer.writeMessage(
1,
f,
google_protobuf_struct_pb.Value.serializeBinaryToWriter
google_protobuf_wrappers_pb.StringValue.serializeBinaryToWriter
);
}
};


/**
* optional google.protobuf.Value payload = 1;
* @return {?proto.google.protobuf.Value}
* optional google.protobuf.StringValue payload = 1;
* @return {?proto.google.protobuf.StringValue}
*/
proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload.prototype.getPayload = function() {
return /** @type{?proto.google.protobuf.Value} */ (
jspb.Message.getWrapperField(this, google_protobuf_struct_pb.Value, 1));
return /** @type{?proto.google.protobuf.StringValue} */ (
jspb.Message.getWrapperField(this, google_protobuf_wrappers_pb.StringValue, 1));
};


/**
* @param {?proto.google.protobuf.Value|undefined} value
* @param {?proto.google.protobuf.StringValue|undefined} value
* @return {!proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload} returns this
*/
proto.io.contract_testing.contractcase.grpc.ResultSuccessHasAnyPayload.prototype.setPayload = function(value) {
Expand Down
8 changes: 4 additions & 4 deletions packages/case-connector/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Case-Connector

[![Build and test](https://github.com/case-contract-testing/case/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/case-contract-testing/case/actions/workflows/build-and-test.yml)
[![Known Vulnerabilities](https://snyk.io/test/github/case-contract-testing/case/badge.svg?targetFile=packages/case-boundary/package.json)](https://snyk.io/test/github/case-contract-testing/case?targetFile=packages/case-boundary/package.json)
[![Build and test](https://github.com/case-contract-testing/contract-case/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/case-contract-testing/contract-case/actions/workflows/build-and-test.yml)
[![Known Vulnerabilities](https://snyk.io/test/github/case-contract-testing/contract-case/badge.svg?targetFile=packages/case-connector/package.json)](https://snyk.io/test/github/case-contract-testing/case?targetFile=packages/case-boundary/package.json)

This is the server connector (alternative to the case-boundary) to allow ContractCase to be run as a server.
This is the server connector (formerly case-boundary) to allow ContractCase to be run as a server.

If you're wanting to learn about ContractCase, [start here instead](https://case.contract-testing.io/docs/intro)

Expand All @@ -12,4 +12,4 @@ Don't depend on this directly unless you are writing a custom wrapper for Contra
This package exists to work around [this JSii](https://github.com/aws/jsii/issues/4133)
bug, by exposing the communication layer as a gRPC service.

See the proto file [here in the proto directory](./proto/contract_case_stream.proto).
For details of the protocol schema, see the case-connector-proto package.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,9 @@ export const handleVoidResult = (
export const handleSuccessAnyResult = (
result: BoundaryResult,
defaultError: ErrorType,
): unknown => {
): string => {
if (result.resultType === RESULT_SUCCESS_HAS_ANY_PAYLOAD) {
try {
return JSON.parse((result as BoundarySuccessWithAny).payload);
} catch (e) {
maintainerLog('Error parsing successAny: ', e, 'result was', result);
throw new CaseCoreError(
'Was unable to parse the payload returned by a success any result. This is probably a bug in the language-specific wrapper.',
);
}
return (result as BoundarySuccessWithAny).payload;
}
if (result.resultType === RESULT_FAILURE) {
throw failureToJsError(result, defaultError);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import { CaseCoreError } from '@contract-case/case-core';
import { BoundaryInvokableFunction } from '../types.js';
import { handleSuccessAnyResult } from './Result/index.js';
import { maintainerLog } from '../../../../domain/maintainerLog.js';

type Fn = (...args: unknown[]) => Promise<unknown>;
type Fn = (...args: unknown[]) => Promise<string>;

export const mapInvokableFunction =
(invokeableFn: BoundaryInvokableFunction): Fn =>
(...args: unknown[]): Promise<unknown> =>
(...args: unknown[]): Promise<string> =>
Promise.resolve()
.then(() => invokeableFn(...args.map((arg) => JSON.stringify(arg))))
.then((result) =>
handleSuccessAnyResult(result, 'CaseConfigurationError'),
);
)
.then((resultString) => {
try {
return JSON.parse(resultString);
} catch (e) {
maintainerLog(
'Error parsing response from invokeableFunction: ',
e,
'result was',
resultString,
);
throw new CaseCoreError(
`Unable to parse the payload returned by the invokeableFunction. This is probably a bug in your invokeable function, or the language-specific wrapper (${(e as Error | undefined)?.message}).`,
);
}
});

export const mapInvokableFunctions = (
invokeableFns: Record<string, BoundaryInvokableFunction>,
Expand Down
Loading

0 comments on commit f5018e3

Please sign in to comment.