Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/sorbet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Sorbet

on: [push, pull_request]

permissions:
contents: read

jobs:
sorbet:
name: Sorbet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Ruby
uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
with:
bundler-cache: true
ruby-version: "3.4"
- name: Type check
run: bundle exec srb tc
10 changes: 3 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inherit_from: .rubocop_todo.yml

inherit_mode:
merge:
- Exclude
Expand All @@ -13,15 +15,9 @@ plugins:
- rubocop-rspec
- rubocop-performance
- rubocop-rake
- rubocop-sorbet

AllCops:
TargetRubyVersion: 3.3
Exclude:
- 'vendor/**/*'

# singed does not use Sorbet: there is no sorbet/ config, no sorbet runtime dependency, and no
# typecheck step. The Sorbet cops would only add `# typed:` sigils that nothing reads, and
# `# typed: strict` would claim a level of typing this gem does not have. rubocop-gusto's own
# .rubocop.yml disables the department for the same reason.
Sorbet:
Enabled: false
16 changes: 16 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-exclude-limit --no-auto-gen-timestamp`
# using RuboCop version 1.88.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SuggestedStrictness.
Sorbet/StrictSigil:
Exclude:
- 'sorbet/tapioca/require.rb'
- 'spec/spec_helper.rb'
- 'spec/support/sidekiq.rb'
13 changes: 13 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ bundle exec rspec spec/path/to/spec.rb
# Lint
bundle exec rubocop
bundle exec rubocop -a # auto-correct

# Type check (Sorbet)
bundle exec srb tc

# Regenerate gem RBIs after Gemfile.lock changes
bin/tapioca gems
```

## Architecture

- `lib/singed.rb` — main entry point; provides `Singed.flamegraph` block helper
- `lib/singed/` — core classes: flamegraph output handling, stackprof/rbspy integrations, speedscope launcher
- `spec/` — RSpec tests

## Types

- Files under `lib/` are `# typed: strict`. Write their signatures as [RBS comments](https://sorbet.org/docs/rbs-support) (`#: (String) -> bool`), not `sig` blocks.
- `sorbet-runtime` isn't a dependency of the gem, so nothing under `lib/` may reference `T` at runtime. Use the RBS assertion comments (`#: Type`, `#: as !nil`, `#: as Type`, `#: as untyped`, `#: self as Type`) instead of `T.let`, `T.must`, `T.cast`, `T.unsafe` and `T.bind`.
- Apps that use Tapioca still run these signatures: Tapioca rewrites RBS comments into runtime-checked `sig`s while it loads the app. A signature must therefore only name constants that are loaded whenever its file is (not `ActiveSupport` in `lib/singed.rb`), and must accept every value an app can pass while booting, such as `flamegraph [:show, :index]` in a controller. Otherwise the app's `tapioca gem` or `tapioca dsl` run errors. The specs here don't load `sorbet-runtime`, so they can't catch this.
- Types the generated gem RBIs are missing go in `sorbet/rbi/shims/`.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ source "https://rubygems.org"
gemspec

gem "activejob"
gem "railties"
gem "rake", "~> 13.4"
gem "rspec"
gem "rubocop-gusto", require: false
gem "rubocop-performance", require: false
gem "rubocop-rake", require: false
gem "rubocop-rspec", require: false
gem "rubocop-sorbet", require: false
gem "rubyzip"
gem "sidekiq"
gem "sorbet", require: false
gem "tapioca", require: false
105 changes: 101 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activejob (8.1.3.1)
activesupport (= 8.1.3.1)
actionpack (8.1.4)
actionview (= 8.1.4)
activesupport (= 8.1.4)
nokogiri (>= 1.8.5)
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
useragent (~> 0.16)
actionview (8.1.4)
activesupport (= 8.1.4)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (8.1.4)
activesupport (= 8.1.4)
globalid (>= 0.3.6)
activesupport (8.1.3.1)
activesupport (8.1.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
Expand All @@ -25,32 +41,80 @@ GEM
uri (>= 0.13.1)
ast (2.4.3)
base64 (0.3.0)
benchmark (0.5.0)
bigdecimal (4.1.2)
builder (3.3.0)
code_teams (1.3.1)
sorbet-runtime
concurrent-ruby (1.3.8)
connection_pool (3.0.2)
crass (1.0.7)
diff-lcs (1.6.2)
drb (2.2.3)
erb (6.0.7)
erubi (1.13.1)
globalid (1.4.0)
activesupport (>= 6.1)
i18n (1.15.2)
concurrent-ruby (~> 1.0)
io-console (0.9.4)
irb (1.18.0)
pp (>= 0.6.0)
prism (>= 1.3.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.21.2)
language_server-protocol (3.17.0.6)
lint_roller (1.1.0)
logger (1.7.0)
loofah (2.25.2)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
minitest (6.0.6)
drb (~> 2.0)
prism (~> 1.5)
netrc (0.11.0)
nokogiri (1.19.4-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.19.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.19.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.19.4-x86_64-linux-gnu)
racc (~> 1.4)
parallel (2.1.0)
parser (3.3.12.0)
ast (~> 2.4.1)
racc
pp (0.6.4)
prettyprint
prettyprint (0.2.0)
prism (1.9.0)
racc (1.8.1)
rack (3.2.7)
rack-session (2.1.2)
base64 (>= 0.1.0)
rack (>= 3.0.0)
rack-test (2.2.0)
rack (>= 1.3)
rackup (2.3.1)
rack (>= 3)
rails-dom-testing (2.3.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.7.1)
loofah (~> 2.25, >= 2.25.2)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (8.1.4)
actionpack (= 8.1.4)
activesupport (= 8.1.4)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
tsort (>= 0.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.4.2)
rbi (0.4.3)
Expand All @@ -60,9 +124,17 @@ GEM
logger
prism (>= 1.6.0)
tsort
rdoc (8.1.0)
erb
prism (>= 1.6.0)
rbs (>= 4.0.0)
tsort
redis-client (0.30.1)
connection_pool
regexp_parser (2.12.0)
reline (0.7.0)
io-console (~> 0.5)
require-hooks (0.5.1)
rexml (3.4.4)
rspec (3.13.2)
rspec-core (~> 3.13.0)
Expand Down Expand Up @@ -118,6 +190,10 @@ GEM
rubocop (>= 1.75.2)
spoom (~> 1.8)
ruby-progressbar (1.13.0)
rubydex (0.4.1-aarch64-linux)
rubydex (0.4.1-arm64-darwin)
rubydex (0.4.1-x86_64-darwin)
rubydex (0.4.1-x86_64-linux)
rubyzip (3.5.0)
securerandom (0.4.1)
sidekiq (8.1.7)
Expand Down Expand Up @@ -146,6 +222,18 @@ GEM
sorbet-static-and-runtime (>= 0.5.10187)
thor (>= 0.19.2)
stackprof (0.2.28)
tapioca (0.20.0)
benchmark
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (>= 0.4.1)
require-hooks (>= 0.2.2)
rubydex (>= 0.1.0.beta10)
sorbet-static-and-runtime (>= 0.6.12698)
spoom (>= 1.7.16)
thor (>= 1.2.0)
tsort
thor (1.5.0)
tsort (0.2.0)
tzinfo (2.0.6)
Expand All @@ -154,6 +242,8 @@ GEM
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
uri (1.1.1)
useragent (0.16.11)
zeitwerk (2.8.3)

PLATFORMS
aarch64-linux
Expand All @@ -163,12 +253,19 @@ PLATFORMS

DEPENDENCIES
activejob
railties
rake (~> 13.4)
rspec
rubocop-gusto
rubocop-performance
rubocop-rake
rubocop-rspec
rubocop-sorbet
rubyzip
sidekiq
singed!
sorbet
tapioca

BUNDLED WITH
4.0.15
4.0.15
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ end

This won't catch the entire request though, just once it's been routed to controller and a response has been served (ie no middleware).

If Sorbet checks the controller (`# typed: true` or stricter), also include `Singed::ControllerExt` in it. The Railtie already includes it into `ActionController::Base` at runtime, but Sorbet can't see that, so it would check `flamegraph :show` against the block form of `flamegraph` instead:

```ruby
class EmployeesController < ApplicationController
include Singed::ControllerExt

flamegraph :show
end
```

### Rack/Rails requests

To capture the whole request, there is a middleware which checks for the `X-Singed` header to be 'true'. With curl, you can do this like:
Expand Down
16 changes: 16 additions & 0 deletions bin/tapioca
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'tapioca' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("tapioca", "tapioca")
Loading
Loading