Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the way we use CDDL #50

Merged
merged 7 commits into from
Sep 18, 2020
Merged

Refactor the way we use CDDL #50

merged 7 commits into from
Sep 18, 2020

Conversation

jgraham
Copy link
Member

@jgraham jgraham commented Aug 26, 2020

Previously the spec only provided fragments of CDDL to validate
specific kinds of messages. But it makes sense from an implementation
point of view to have full schema that can be used directly.

In practice we require two seperate schema, one for validation of
messages going from the local end (i.e. client) to the remote
end (i.e. browser) and one for messages going in the opposite
direction. This change adds those schema to the spec.

The modelling adopted here is likely not the only approach, but the
basic idea is that each kind of message is modelled as a choice
between several variants, representing each possible message in the
protocol. Because the messages have unique names (e.g. in the method
field) we know that zero or one will match. However the names are not
represented directly.

In terms of organistaion, this currently defines a schema prelude with
each message type specified by a set of choices, one per module. Then
each module defines a choice per command (or other message) and
finally the messages themselves define the actual schema. I expect
this organisation to change somewhat over time. In particular using
the //= oeprator in CDDL seems like it might avoid the need to
define so many terms upfront, but it also seemed to be poorly
supported in the CDDL library I tried.


Preview | Diff

index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
Copy link
Member

@foolip foolip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slowpoke is sorry, review is here.

index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
"invalid argument"
),
message: text,
stacktrace: text,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to introduce stacktrace here? https://www.jsonrpc.org/specification#error_object doesn't have it, and maybe we should, but it'd be good to introduce in a separate PR for visibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was basing it on what we provide in WebDriver 1.0 rather than on JSON-RPC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we won't be using JSON-RPC error objects, but this is doing more than refactoring. If you mention the addition in the eventual commit message, that's OK I think.

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
jgraham and others added 5 commits September 11, 2020 16:12
Previously the spec only provided fragments of CDDL to validate
specific kinds of messages. But it makes sense from an implementation
point of view to have full schema that can be used directly.

In practice we require two seperate schema, one for validation of
messages going from the local end (i.e. client) to the remote
end (i.e. browser) and one for messages going in the opposite
direction. This change adds those schema to the spec.

The modelling adopted here is likely not the only approach, but the
basic idea is that each kind of message is modelled as a choice
between several variants, representing each possible message in the
protocol. Because the messages have unique names (e.g. in the `method`
field) we know that zero or one will match. However the names are not
represented directly.

In terms of organistaion, this currently defines a schema prelude with
each message type specified by a set of choices, one per module. Then
each module defines a choice per command (or other message) and
finally the messages themselves define the actual schema. I expect
this organisation to change somewhat over time. In particular using
the `//=` oeprator in CDDL seems like it might avoid the need to
define so many terms upfront, but it also seemed to be poorly
supported in the CDDL library I tried.
Co-authored-by: Philip Jägenstedt <philip@foolip.org>
index.bs Show resolved Hide resolved
index.bs Outdated
- A <dfn export for=command>return type</dfn>, which may be null.
Each [=command=] is defined by:
- A <dfn export for=command>command id</dfn>. This is an integer id
provided by the [=local end=] for each command. The value of the id is not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section should at least briefly explain what the command ID is for. The remote end does in fact use it when sending a command response back to the local end. So I think it's fair to say the ID can be treated as opaque, but it is not entirely accurate to say the remote end doesn't use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking some more about this, I'm not sure the command ID should be mentioned here at all. It's a transport-layer concept that has no bearing on the definition of the command itself. Maybe the definition and requirements for the command ID should go in the transport section instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirements are already there. I've changed things so that this section is only stating facts about the command id; I couldn't see anywhere in the transport section that would make it clearer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The new description is more clear.

index.bs Outdated Show resolved Hide resolved
Also use remote-cddl for remote end definitions, and local-cddl for local end definitions
Copy link
Contributor

@bwalderman bwalderman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jgraham jgraham merged commit db6776c into master Sep 18, 2020
@jgraham jgraham deleted the cddl_refactor branch September 18, 2020 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants