-
Notifications
You must be signed in to change notification settings - Fork 27
feat: publish RBS and RBI types with Gem #410
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
Open
chris-olszewski
wants to merge
25
commits into
main
Choose a base branch
from
olszewski/feat_publish_types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9ccb91b
chore: fix RPCError::Code mispelling
chris-olszewski aa71656
Add sig/ to gemspec to ship RBS types with the gem
chris-olszewski 25d30dd
Add tapioca baseline for RBI drift detection
chris-olszewski c040ac3
Add enriched RBI types for Sorbet users
chris-olszewski eb4559d
Fix RBI issues found during Sorbet validation
chris-olszewski 1ca1584
Fix Workflow::Mutex/Queue/SizedQueue missing parent classes in RBI
chris-olszewski 8c65984
Add Api::Common::V1::Payload/Payloads stubs to RBI
chris-olszewski 4fb7d81
Add CI Sorbet type check for enriched RBI
chris-olszewski e98bd98
Document RBI maintenance workflow for SDK developers
chris-olszewski 7f4b103
fixup rbi
chris-olszewski 237ea7b
strip comments
chris-olszewski 7c40bc8
feat: add sorbet runtime check to tests
chris-olszewski 5405fc8
fixup type errors
chris-olszewski aa2da00
test: run sorbet runtime typecheck in ci
chris-olszewski 6d15ca9
chore: fix interceptor type errors
chris-olszewski c91948d
fix(test): fix activity info test to avoid type error
chris-olszewski 13a022a
attempt to remove non-determism in type checking
chris-olszewski d8b78ad
self review
chris-olszewski 03329d9
include sig globally, support anon blocks
chris-olszewski f5d98ba
chore: add test to limit amount of untyped uses
chris-olszewski 33e7e8a
first pass at removing untyped
chris-olszewski 7c94020
type envconfig
chris-olszewski ea6ae84
split out grpc service rbi
chris-olszewski 3f29a2d
fail on uninstrumented methods
chris-olszewski 76e1c77
increase coverage
chris-olszewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| source 'https://rubygems.org' | ||
|
|
||
| gem 'temporalio', path: '../..' | ||
|
|
||
| gem 'sorbet', group: :development | ||
| gem 'sorbet-runtime' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| # typed: true | ||
| # frozen_string_literal: true | ||
|
|
||
| # This file validates the enriched RBI types by exercising key SDK API patterns. | ||
| # It is checked by `srb tc` in CI — it is never executed at runtime. | ||
|
|
||
| require 'sorbet-runtime' | ||
| require 'temporalio/activity' | ||
| require 'temporalio/client' | ||
| require 'temporalio/converters' | ||
| require 'temporalio/converters/payload_codec' | ||
| require 'temporalio/worker' | ||
| require 'temporalio/workflow' | ||
|
|
||
| extend T::Sig | ||
|
|
||
| # --- Activity definitions --- | ||
|
|
||
| class MyActivity < Temporalio::Activity::Definition | ||
| extend T::Sig | ||
|
|
||
| sig { params(name: String).returns(String) } | ||
| def execute(name) | ||
| ctx = Temporalio::Activity::Context.current | ||
| ctx.logger.info("Running activity for #{name}") | ||
| ctx.heartbeat('progress') | ||
| "Hello, #{name}!" | ||
| end | ||
| end | ||
|
|
||
| # --- Workflow definitions --- | ||
|
|
||
| class MyWorkflow < Temporalio::Workflow::Definition | ||
| extend T::Sig | ||
|
|
||
| T::Sig::WithoutRuntime.sig { returns(Temporalio::Workflow::Definition::Query) } | ||
| def self.my_query = T.unsafe(nil) | ||
|
|
||
| T::Sig::WithoutRuntime.sig { returns(Temporalio::Workflow::Definition::Signal) } | ||
| def self.my_signal = T.unsafe(nil) | ||
|
|
||
| T::Sig::WithoutRuntime.sig { returns(Temporalio::Workflow::Definition::Update) } | ||
| def self.my_update = T.unsafe(nil) | ||
|
|
||
| sig { void } | ||
| def initialize | ||
| @value = T.let(nil, T.nilable(String)) | ||
| @done = T.let(false, T::Boolean) | ||
| end | ||
|
|
||
| sig { params(name: String).returns(String) } | ||
| def execute(name) | ||
| # Execute activity | ||
| result = T.cast( | ||
| Temporalio::Workflow.execute_activity(MyActivity, name, start_to_close_timeout: 300), | ||
| String | ||
| ) | ||
|
|
||
| # Workflow primitives | ||
| Temporalio::Workflow.logger.info("Activity result: #{result}") | ||
| _info = Temporalio::Workflow.info | ||
| _now = Temporalio::Workflow.now | ||
|
|
||
| # Wait with timeout | ||
| begin | ||
| Temporalio::Workflow.timeout(10) do | ||
| Temporalio::Workflow.wait_condition { @done } | ||
| end | ||
| rescue Timeout::Error | ||
| # expected | ||
| end | ||
|
|
||
| result | ||
| end | ||
|
|
||
| workflow_query | ||
| sig { returns(T.nilable(String)) } | ||
| def my_query | ||
| @value | ||
| end | ||
|
|
||
| workflow_signal | ||
| sig { params(value: String).void } | ||
| def my_signal(value) | ||
| @value = value | ||
| end | ||
|
|
||
| workflow_update | ||
| sig { params(value: String).returns(String) } | ||
| def my_update(value) | ||
| old = @value | ||
| @value = value | ||
| old || '' | ||
| end | ||
|
|
||
| workflow_update_validator(:my_update) | ||
| sig { params(value: String).void } | ||
| def validate_my_update(value) | ||
| raise 'empty' if value.empty? | ||
| end | ||
| end | ||
|
|
||
| # --- Client usage --- | ||
|
|
||
| sig { void } | ||
| def check_client_types | ||
| client = Temporalio::Client.connect('localhost:7233', 'default') | ||
|
|
||
| # Start workflow | ||
| handle = client.start_workflow( | ||
| MyWorkflow, 'world', | ||
| id: 'test-id', task_queue: 'test-queue' | ||
| ) | ||
|
|
||
| # Query, signal, update | ||
| handle.query(MyWorkflow.my_query) | ||
| handle.signal(MyWorkflow.my_signal, 'value') | ||
| handle.execute_update(MyWorkflow.my_update, 'value') | ||
|
|
||
| # Result | ||
| _result = handle.result | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some expressions like this (and in various other places in this file), could we add The runtime typechecking that assertion performs wouldn't run, but the static typechecking would |
||
| end | ||
|
|
||
| # --- Worker usage --- | ||
|
|
||
| sig { void } | ||
| def check_worker_types | ||
| client = Temporalio::Client.connect('localhost:7233', 'default') | ||
|
|
||
| worker = Temporalio::Worker.new( | ||
| client: client, | ||
| task_queue: 'test-queue', | ||
| activities: [MyActivity], | ||
| workflows: [MyWorkflow] | ||
| ) | ||
|
|
||
| worker.run(shutdown_signals: ['SIGINT']) | ||
| end | ||
|
|
||
| # --- Converter/codec usage --- | ||
|
|
||
| class MyCodec < Temporalio::Converters::PayloadCodec | ||
| extend T::Sig | ||
|
|
||
| sig { params(payloads: T::Enumerable[T.untyped]).returns(T::Array[T.untyped]) } | ||
| def encode(payloads) | ||
| payloads.map { |p| p } | ||
| end | ||
|
|
||
| sig { params(payloads: T::Enumerable[T.untyped]).returns(T::Array[T.untyped]) } | ||
| def decode(payloads) | ||
| payloads.map { |p| p } | ||
| end | ||
| end | ||
|
|
||
| sig { void } | ||
| def check_converter_types | ||
| codec = MyCodec.new | ||
| converter = Temporalio::Converters::DataConverter.new(payload_codec: codec) | ||
| Temporalio::Client.connect('localhost:7233', 'default', data_converter: converter) | ||
| end | ||
|
|
||
| # --- Error types --- | ||
|
|
||
| sig { void } | ||
| def check_error_types | ||
| raise Temporalio::Error::ApplicationError.new('test', non_retryable: true) | ||
| rescue Temporalio::Error::ApplicationError => e | ||
| _msg = e.message | ||
| _non_retryable = e.non_retryable | ||
| end | ||
|
|
||
| # --- Cancellation --- | ||
|
|
||
| sig { void } | ||
| def check_cancellation_types | ||
| cancellation = Temporalio::Cancellation.new | ||
| _canceled = cancellation.canceled? | ||
| _reason = cancellation.canceled_reason | ||
| cancellation.check! | ||
| end | ||
|
|
||
| # --- Search attributes --- | ||
|
|
||
| sig { void } | ||
| def check_search_attributes_types | ||
| key = Temporalio::SearchAttributes::Key.new('my-key', Temporalio::SearchAttributes::IndexedValueType::TEXT) | ||
| update = Temporalio::SearchAttributes::Update.new(key, 'value') | ||
| _k = update.key | ||
| _v = update.value | ||
| end | ||
|
|
||
| # --- Workflow mutex --- | ||
|
|
||
| sig { void } | ||
| def check_workflow_mutex_types | ||
| mutex = Temporalio::Workflow::Mutex.new | ||
| mutex.synchronize { 'value' } | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --dir | ||
| . |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to include the RBI types for these as well? At Stripe we maintain https://github.com/sorbet/protoc-gen-rbi, which I'd recommend. Tapioca looks like it also has its own support: https://github.com/Shopify/tapioca/blob/main/manual/compiler_protobuf.md, though I'm not sure how it compares.
To give some motivation, this is the most common source of needing to do
T.unsafe(...)in our integration with sdk-ruby at Stripe today (which is still in its early stages). We have code that looks like this:The existing types being added in this PR would let us remove the
T.let(...)cast on the first statement [0], but we'd need to keep theT.unsafe(cls).new(...)on the second statement unless there were RBI stubs for the Protobuf types.It's understandable if the
SigApplicatorsystem wouldn't work for these (since I think the methods might not actually exist on the classes?[0]: (we could remove that today, but we'd be calling a method on a
T.untyped)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If sdk-ruby weren't able to publish the RBI types for the protobufs, I think we'd strongly consider setting up our own additional RBI generation to cover the protobuf classes, at Stripe.
I think it's still globally preferable if this is provided by the upstream, though (since all users will get them).