runtime_analysis 1.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +115 -0
- data/LICENSE.txt +96 -0
- data/README.md +164 -0
- data/editor/nvim/README.md +278 -0
- data/editor/nvim/lua/runtime_analysis/connected.lua +565 -0
- data/editor/nvim/lua/runtime_analysis/go_to_class.lua +63 -0
- data/editor/nvim/lua/runtime_analysis/inline.lua +138 -0
- data/editor/nvim/lua/runtime_analysis/lens.lua +50 -0
- data/editor/nvim/lua/runtime_analysis/lsp.lua +92 -0
- data/editor/nvim/lua/runtime_analysis/menu.lua +98 -0
- data/editor/nvim/lua/runtime_analysis/preview.lua +70 -0
- data/editor/nvim/lua/runtime_analysis/project.lua +28 -0
- data/editor/nvim/lua/runtime_analysis/rerun.lua +39 -0
- data/editor/nvim/lua/runtime_analysis/text.lua +23 -0
- data/editor/nvim/lua/runtime_analysis/value_popup.lua +45 -0
- data/editor/nvim/plugin/runtime_analysis.lua +71 -0
- data/examples/trackers/PROMPT.md +86 -0
- data/examples/trackers/honeybadger.rb +19 -0
- data/examples/trackers/sentry.rb +16 -0
- data/ext/runtime_analysis/extconf.rb +68 -0
- data/ext/runtime_analysis/fast.c +775 -0
- data/ext/runtime_analysis/fast.h +59 -0
- data/ext/runtime_analysis/hold.c +560 -0
- data/ext/runtime_analysis/init.c +36 -0
- data/ext/runtime_analysis/names.c +78 -0
- data/ext/runtime_analysis/names.h +28 -0
- data/ext/runtime_analysis/novelty.c +139 -0
- data/ext/runtime_analysis/novelty.h +22 -0
- data/ext/runtime_analysis/os.c +73 -0
- data/ext/runtime_analysis/os.h +32 -0
- data/ext/runtime_analysis/ring.c +445 -0
- data/ext/runtime_analysis/rows.c +304 -0
- data/ext/runtime_analysis/sink.c +485 -0
- data/ext/runtime_analysis/sink.h +240 -0
- data/ext/runtime_analysis/state.c +254 -0
- data/ext/runtime_analysis/state.h +57 -0
- data/ext/runtime_analysis/wrapper.c +278 -0
- data/ext/runtime_analysis/wrapper.h +24 -0
- data/lib/runtime_analysis/errors.rb +34 -0
- data/lib/runtime_analysis/failsafe.rb +123 -0
- data/lib/runtime_analysis/host/controller_entry_point.rb +18 -0
- data/lib/runtime_analysis/host/declared.rb +152 -0
- data/lib/runtime_analysis/host/inject.rb +90 -0
- data/lib/runtime_analysis/host/job_runners.rb +27 -0
- data/lib/runtime_analysis/host/middleware.rb +23 -0
- data/lib/runtime_analysis/host/minitest_integration.rb +22 -0
- data/lib/runtime_analysis/host/railtie.rb +42 -0
- data/lib/runtime_analysis/host/reports.rb +54 -0
- data/lib/runtime_analysis/host/rspec_integration.rb +17 -0
- data/lib/runtime_analysis/host/web.rb +22 -0
- data/lib/runtime_analysis/host.rb +34 -0
- data/lib/runtime_analysis/inject.rb +5 -0
- data/lib/runtime_analysis/minitest.rb +9 -0
- data/lib/runtime_analysis/native/build.rb +17 -0
- data/lib/runtime_analysis/native/byte_size.rb +27 -0
- data/lib/runtime_analysis/native/call_site_logger/definitions.rb +51 -0
- data/lib/runtime_analysis/native/call_site_logger/held.rb +35 -0
- data/lib/runtime_analysis/native/call_site_logger/rows.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger/segments.rb +100 -0
- data/lib/runtime_analysis/native/call_site_logger/streams.rb +110 -0
- data/lib/runtime_analysis/native/call_site_logger.rb +80 -0
- data/lib/runtime_analysis/native/rotation_policy.rb +28 -0
- data/lib/runtime_analysis/native/sanitizer_runtime.rb +50 -0
- data/lib/runtime_analysis/native/sink.rb +12 -0
- data/lib/runtime_analysis/native.rb +74 -0
- data/lib/runtime_analysis/platform.rb +30 -0
- data/lib/runtime_analysis/query/index/anonymise.rb +98 -0
- data/lib/runtime_analysis/query/index/graph.rb +107 -0
- data/lib/runtime_analysis/query/index/graph_cache.rb +32 -0
- data/lib/runtime_analysis/query/index/reading/declared.rb +42 -0
- data/lib/runtime_analysis/query/index/reading/dict.rb +43 -0
- data/lib/runtime_analysis/query/index/reading/frame.rb +27 -0
- data/lib/runtime_analysis/query/index/reading/node.rb +45 -0
- data/lib/runtime_analysis/query/index/reading/path.rb +21 -0
- data/lib/runtime_analysis/query/index/reading/reruns.rb +30 -0
- data/lib/runtime_analysis/query/index/reading/rows.rb +128 -0
- data/lib/runtime_analysis/query/index/reading/stream.rb +82 -0
- data/lib/runtime_analysis/query/index/reading/tree.rb +66 -0
- data/lib/runtime_analysis/query/index/reading/tree_builder.rb +135 -0
- data/lib/runtime_analysis/query/index/reading/values.rb +49 -0
- data/lib/runtime_analysis/query/index/reading.rb +80 -0
- data/lib/runtime_analysis/query/index/shapes.rb +142 -0
- data/lib/runtime_analysis/query/index/signatures/active_support.rb +31 -0
- data/lib/runtime_analysis/query/index/signatures/core.json +1 -0
- data/lib/runtime_analysis/query/index/signatures/layers.rb +29 -0
- data/lib/runtime_analysis/query/index/signatures/lineage.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/overloads.rb +32 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/entry.rb +95 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/export.rb +76 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/library.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/overload.rb +66 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/project.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/rbs/types.rb +79 -0
- data/lib/runtime_analysis/query/index/signatures/rbs.rb +57 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/sig.rb +48 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/signed.rb +69 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/table.rb +43 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet/types.rb +96 -0
- data/lib/runtime_analysis/query/index/signatures/sorbet.rb +150 -0
- data/lib/runtime_analysis/query/index/signatures/sources.rb +80 -0
- data/lib/runtime_analysis/query/index/signatures/written.rb +45 -0
- data/lib/runtime_analysis/query/index/signatures.rb +93 -0
- data/lib/runtime_analysis/query/index/source_named_graph.rb +84 -0
- data/lib/runtime_analysis/query/index/static/change_set.rb +20 -0
- data/lib/runtime_analysis/query/index/static/changes.rb +80 -0
- data/lib/runtime_analysis/query/index/static/code_visitor.rb +144 -0
- data/lib/runtime_analysis/query/index/static/klass.rb +13 -0
- data/lib/runtime_analysis/query/index/static/method.rb +19 -0
- data/lib/runtime_analysis/query/index/static/params.rb +52 -0
- data/lib/runtime_analysis/query/index/static/source.rb +69 -0
- data/lib/runtime_analysis/query/index/static/stub.rb +14 -0
- data/lib/runtime_analysis/query/index/static/stub_visitor.rb +133 -0
- data/lib/runtime_analysis/query/index/static/value.rb +17 -0
- data/lib/runtime_analysis/query/index/static/values.rb +71 -0
- data/lib/runtime_analysis/query/index/static/visibility.rb +40 -0
- data/lib/runtime_analysis/query/index/static.rb +85 -0
- data/lib/runtime_analysis/query/index.rb +32 -0
- data/lib/runtime_analysis/query/nodes.rb +60 -0
- data/lib/runtime_analysis/query/project/config.rb +108 -0
- data/lib/runtime_analysis/query/project.rb +40 -0
- data/lib/runtime_analysis/query/report/document.rb +84 -0
- data/lib/runtime_analysis/query/report/finding.rb +15 -0
- data/lib/runtime_analysis/query/report/json_renderer.rb +51 -0
- data/lib/runtime_analysis/query/report/list.rb +15 -0
- data/lib/runtime_analysis/query/report/location.rb +14 -0
- data/lib/runtime_analysis/query/report/one_row.rb +14 -0
- data/lib/runtime_analysis/query/report/outline.rb +15 -0
- data/lib/runtime_analysis/query/report/paint.rb +34 -0
- data/lib/runtime_analysis/query/report/related.rb +11 -0
- data/lib/runtime_analysis/query/report/table.rb +15 -0
- data/lib/runtime_analysis/query/report/text.rb +13 -0
- data/lib/runtime_analysis/query/report/text_renderer.rb +102 -0
- data/lib/runtime_analysis/query/report.rb +35 -0
- data/lib/runtime_analysis/query/surfaces/class_value.rb +17 -0
- data/lib/runtime_analysis/query/surfaces/cli/answer.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli/command_line.rb +77 -0
- data/lib/runtime_analysis/query/surfaces/cli/usage.rb +32 -0
- data/lib/runtime_analysis/query/surfaces/cli.rb +101 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/lexical.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/notation.rb +33 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/observed.rb +102 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/outline.rb +111 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_file.rb +100 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_member.rb +50 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/rbs_notation.rb +44 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/seen.rb +74 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sig_text.rb +49 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_edit.rb +106 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/sorbet_notation.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/crystallise/subject.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/crystallise.rb +94 -0
- data/lib/runtime_analysis/query/surfaces/mcp.rb +89 -0
- data/lib/runtime_analysis/query/surfaces/record/commands.rb +45 -0
- data/lib/runtime_analysis/query/surfaces/record/environment.rb +48 -0
- data/lib/runtime_analysis/query/surfaces/record/ignore.rb +62 -0
- data/lib/runtime_analysis/query/surfaces/record/question.rb +55 -0
- data/lib/runtime_analysis/query/surfaces/record/run.rb +30 -0
- data/lib/runtime_analysis/query/surfaces/record.rb +122 -0
- data/lib/runtime_analysis/query/surfaces/rerun.rb +87 -0
- data/lib/runtime_analysis/query/surfaces/setup/agents.rb +76 -0
- data/lib/runtime_analysis/query/surfaces/setup/changes.rb +107 -0
- data/lib/runtime_analysis/query/surfaces/setup/project.rb +80 -0
- data/lib/runtime_analysis/query/surfaces/setup/steps.md +205 -0
- data/lib/runtime_analysis/query/surfaces/setup.rb +98 -0
- data/lib/runtime_analysis/query/surfaces.rb +14 -0
- data/lib/runtime_analysis/query/tools/base.rb +86 -0
- data/lib/runtime_analysis/query/tools/method_lookup.rb +37 -0
- data/lib/runtime_analysis/query/tools/namespaces.rb +36 -0
- data/lib/runtime_analysis/query/tools/origins.rb +47 -0
- data/lib/runtime_analysis/query/tools/stubs.rb +53 -0
- data/lib/runtime_analysis/query/tools/unknown_method.rb +11 -0
- data/lib/runtime_analysis/query/tools/verify_mock.rb +145 -0
- data/lib/runtime_analysis/query/tools/what_calls.rb +67 -0
- data/lib/runtime_analysis/query/tools/what_it_receives.rb +142 -0
- data/lib/runtime_analysis/query/tools/where_nil_comes_from.rb +105 -0
- data/lib/runtime_analysis/query/tools/who_actually_answered.rb +82 -0
- data/lib/runtime_analysis/query/tools.rb +34 -0
- data/lib/runtime_analysis/query.rb +33 -0
- data/lib/runtime_analysis/recording/blob.rb +13 -0
- data/lib/runtime_analysis/recording/format.rb +32 -0
- data/lib/runtime_analysis/recording/opcodes.rb +30 -0
- data/lib/runtime_analysis/recording/raise_ids.rb +15 -0
- data/lib/runtime_analysis/recording/ruby_sink.rb +176 -0
- data/lib/runtime_analysis/recording/run_manifest.rb +110 -0
- data/lib/runtime_analysis/recording/seen/nothing.rb +15 -0
- data/lib/runtime_analysis/recording/seen/tally.rb +48 -0
- data/lib/runtime_analysis/recording/seen.rb +63 -0
- data/lib/runtime_analysis/recording/sink.rb +19 -0
- data/lib/runtime_analysis/recording/source_blob.rb +20 -0
- data/lib/runtime_analysis/recording.rb +52 -0
- data/lib/runtime_analysis/rspec.rb +8 -0
- data/lib/runtime_analysis/ruby_parsing/packages.rb +17 -0
- data/lib/runtime_analysis/ruby_parsing.rb +98 -0
- data/lib/runtime_analysis/trace/configuration/capturing.rb +32 -0
- data/lib/runtime_analysis/trace/configuration/per_run.rb +31 -0
- data/lib/runtime_analysis/trace/configuration/tier.rb +27 -0
- data/lib/runtime_analysis/trace/configuration.rb +115 -0
- data/lib/runtime_analysis/trace/entries.rb +47 -0
- data/lib/runtime_analysis/trace/hold/raises.rb +28 -0
- data/lib/runtime_analysis/trace/hold/requests.rb +47 -0
- data/lib/runtime_analysis/trace/hold/telling.rb +45 -0
- data/lib/runtime_analysis/trace/hold/unwound.rb +30 -0
- data/lib/runtime_analysis/trace/hold.rb +142 -0
- data/lib/runtime_analysis/trace/inclusion.rb +46 -0
- data/lib/runtime_analysis/trace/installer/alias_repair.rb +68 -0
- data/lib/runtime_analysis/trace/installer/answers.rb +24 -0
- data/lib/runtime_analysis/trace/installer/body_sync.rb +25 -0
- data/lib/runtime_analysis/trace/installer/built_classes.rb +43 -0
- data/lib/runtime_analysis/trace/installer/called_names.rb +33 -0
- data/lib/runtime_analysis/trace/installer/class_builders.rb +50 -0
- data/lib/runtime_analysis/trace/installer/deferral.rb +42 -0
- data/lib/runtime_analysis/trace/installer/hook.rb +170 -0
- data/lib/runtime_analysis/trace/installer/included_gems.rb +53 -0
- data/lib/runtime_analysis/trace/installer/probe.rb +28 -0
- data/lib/runtime_analysis/trace/installer/reflection.rb +50 -0
- data/lib/runtime_analysis/trace/installer/registry.rb +78 -0
- data/lib/runtime_analysis/trace/installer/sorbet.rb +29 -0
- data/lib/runtime_analysis/trace/installer/wrapping/ivar_writes.rb +62 -0
- data/lib/runtime_analysis/trace/installer/wrapping.rb +66 -0
- data/lib/runtime_analysis/trace/installer.rb +149 -0
- data/lib/runtime_analysis/trace/mechanism/block_entries.rb +29 -0
- data/lib/runtime_analysis/trace/mechanism/frame_readers.rb +61 -0
- data/lib/runtime_analysis/trace/mechanism/native_asks.rb +36 -0
- data/lib/runtime_analysis/trace/mechanism/native_sync.rb +28 -0
- data/lib/runtime_analysis/trace/mechanism/pure_wrapper.rb +41 -0
- data/lib/runtime_analysis/trace/mechanism/ruby_wrapper.rb +141 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper.rb +79 -0
- data/lib/runtime_analysis/trace/mechanism/wrapper_shape.rb +40 -0
- data/lib/runtime_analysis/trace/mechanism.rb +28 -0
- data/lib/runtime_analysis/trace/nil_origin/answers.rb +24 -0
- data/lib/runtime_analysis/trace/nil_origin/beyond.rb +182 -0
- data/lib/runtime_analysis/trace/nil_origin/index.rb +164 -0
- data/lib/runtime_analysis/trace/nil_origin/lifetime.rb +29 -0
- data/lib/runtime_analysis/trace/nil_origin/named.rb +48 -0
- data/lib/runtime_analysis/trace/nil_origin/objects.rb +78 -0
- data/lib/runtime_analysis/trace/nil_origin/provenance.rb +136 -0
- data/lib/runtime_analysis/trace/nil_origin/receiver.rb +121 -0
- data/lib/runtime_analysis/trace/nil_origin/rows.rb +43 -0
- data/lib/runtime_analysis/trace/nil_origin/source.rb +315 -0
- data/lib/runtime_analysis/trace/nil_origin/stored.rb +159 -0
- data/lib/runtime_analysis/trace/nil_origin/told.rb +152 -0
- data/lib/runtime_analysis/trace/nil_origin/values.rb +47 -0
- data/lib/runtime_analysis/trace/nil_origin/weighed.rb +70 -0
- data/lib/runtime_analysis/trace/nil_origin/writers.rb +79 -0
- data/lib/runtime_analysis/trace/nil_origin.rb +278 -0
- data/lib/runtime_analysis/trace/novelty.rb +17 -0
- data/lib/runtime_analysis/trace/pure/novelty.rb +43 -0
- data/lib/runtime_analysis/trace/pure/state.rb +94 -0
- data/lib/runtime_analysis/trace/pure.rb +15 -0
- data/lib/runtime_analysis/trace/recorder/class_name.rb +63 -0
- data/lib/runtime_analysis/trace/recorder/fingerprint.rb +39 -0
- data/lib/runtime_analysis/trace/recorder/frame_key.rb +27 -0
- data/lib/runtime_analysis/trace/recorder/paths.rb +89 -0
- data/lib/runtime_analysis/trace/recorder/raise_site.rb +36 -0
- data/lib/runtime_analysis/trace/recorder/reachability.rb +46 -0
- data/lib/runtime_analysis/trace/recorder/row_emission.rb +137 -0
- data/lib/runtime_analysis/trace/recorder/safe_steps.rb +84 -0
- data/lib/runtime_analysis/trace/recorder/tree_steps.rb +42 -0
- data/lib/runtime_analysis/trace/recorder/unwinding.rb +23 -0
- data/lib/runtime_analysis/trace/recorder.rb +149 -0
- data/lib/runtime_analysis/trace/state.rb +16 -0
- data/lib/runtime_analysis/trace.rb +142 -0
- data/lib/runtime_analysis/version.rb +6 -0
- data/lib/runtime_analysis/web.rb +6 -0
- data/lib/runtime_analysis.rb +125 -0
- metadata +330 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/query/surfaces/class_value"
|
|
4
|
+
|
|
5
|
+
module RuntimeAnalysis
|
|
6
|
+
module Query
|
|
7
|
+
module Surfaces
|
|
8
|
+
class Crystallise
|
|
9
|
+
module Seen
|
|
10
|
+
NAMED = /\A[A-Z]\w*(::[A-Z]\w*)*\z/
|
|
11
|
+
DOUBLE = /\ARSpec::Mocks::/
|
|
12
|
+
WRITTEN = { "TrueClass" => "bool", "FalseClass" => "bool", "NilClass" => "nil" }.freeze
|
|
13
|
+
PRIVATE_IN_RAILS = { /::ActiveRecord_Relation\z/ => "ActiveRecord::Relation",
|
|
14
|
+
/::ActiveRecord_AssociationRelation\z/ => "ActiveRecord::AssociationRelation",
|
|
15
|
+
/::ActiveRecord_Associations_CollectionProxy\z/ =>
|
|
16
|
+
"ActiveRecord::Associations::CollectionProxy" }.freeze
|
|
17
|
+
HELD = { "Array" => %i[elements], "Hash" => %i[keys elements] }.freeze
|
|
18
|
+
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
def enforced = Enforced
|
|
22
|
+
|
|
23
|
+
def type(shape, enforced: false)
|
|
24
|
+
real = real_classes(shape, enforced)
|
|
25
|
+
ordered(real).map { |name| holding(name, shape, enforced) } if nameable?(real)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def real_classes(shape, enforced)
|
|
29
|
+
seen = shape ? shape.classes : {}
|
|
30
|
+
real = seen.reject { |name, _| DOUBLE.match?(name) }
|
|
31
|
+
return real unless enforced
|
|
32
|
+
|
|
33
|
+
real.size < seen.size ? {} : nameable_at_runtime(real)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def nameable_at_runtime(classes)
|
|
37
|
+
pooled(classes) { |name| PRIVATE_IN_RAILS.find { |pattern, _| pattern.match?(name) }&.last || name }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def nameable?(classes)
|
|
41
|
+
!classes.empty? && classes.keys.all? { |name| NAMED.match?(ClassValue.of(name) || name) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def ordered(classes)
|
|
45
|
+
names = counted(classes).sort_by { |name, count| [-count, name] }.map(&:first)
|
|
46
|
+
(names - ["nil"]) + (names & ["nil"])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def counted(classes)
|
|
50
|
+
pooled(classes) { |name| WRITTEN.fetch(name, name) }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def pooled(classes)
|
|
54
|
+
classes.group_by { |name, _| yield name }.transform_values { |seen| seen.sum(&:last) }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def holding(name, shape, enforced)
|
|
58
|
+
itself = ClassValue.of(name)
|
|
59
|
+
return ["Class", [itself]] if itself
|
|
60
|
+
|
|
61
|
+
held = HELD.fetch(name, []).map { |part| type(shape[part], enforced: enforced) }
|
|
62
|
+
held.any? ? [name, *held] : name
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
module Enforced
|
|
66
|
+
def self.type(shape)
|
|
67
|
+
Seen.type(shape, enforced: true)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through observed_spec.rb, which reads the sig written for each method.
|
|
4
|
+
|
|
5
|
+
require_relative "sorbet_notation"
|
|
6
|
+
require_relative "lexical"
|
|
7
|
+
|
|
8
|
+
module RuntimeAnalysis
|
|
9
|
+
module Query
|
|
10
|
+
module Surfaces
|
|
11
|
+
class Crystallise
|
|
12
|
+
class SigText
|
|
13
|
+
ROOM = 100
|
|
14
|
+
|
|
15
|
+
def initialize(observed, lexical)
|
|
16
|
+
@observed = observed
|
|
17
|
+
@lexical = lexical
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def lines(room = ROOM)
|
|
21
|
+
one = "sig { #{[("params(#{typed.join(", ")})" unless typed.empty?), tail].compact.join(".")} }"
|
|
22
|
+
one.size <= room ? [one] : spread
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def typed
|
|
28
|
+
@observed.parameters.map { |each| "#{each.name}: #{written(each.type)}" }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def tail
|
|
32
|
+
@observed.initializer? ? "void" : "returns(#{written(@observed.result)})"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def written(type)
|
|
36
|
+
SorbetNotation.of(@lexical.type(type))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def spread
|
|
40
|
+
return ["sig do", " #{tail}", "end"] if typed.empty?
|
|
41
|
+
|
|
42
|
+
["sig do", " params(", *typed.map { |each| " #{each}," }.tap { |all| all.last.chomp!(",") },
|
|
43
|
+
" ).#{tail}", "end"]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../crystallise_spec.rb, which inserts and replaces sigs.
|
|
4
|
+
|
|
5
|
+
require_relative "sig_text"
|
|
6
|
+
require "runtime_analysis/query/nodes"
|
|
7
|
+
|
|
8
|
+
module RuntimeAnalysis
|
|
9
|
+
module Query
|
|
10
|
+
module Surfaces
|
|
11
|
+
class Crystallise
|
|
12
|
+
class SorbetEdit
|
|
13
|
+
ROOM = 100
|
|
14
|
+
NOUN = "sig"
|
|
15
|
+
Insertion = Struct.new(:index, :text)
|
|
16
|
+
|
|
17
|
+
class Insertion
|
|
18
|
+
def outdented
|
|
19
|
+
text.lines.map { |line| line.delete_prefix(text.delete_suffix(text.lstrip)) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def initialize(subject)
|
|
24
|
+
@subject = subject
|
|
25
|
+
@lines = subject.text.lines
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def noun = NOUN
|
|
29
|
+
|
|
30
|
+
def count
|
|
31
|
+
sigs.size
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def target
|
|
35
|
+
@subject.file
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def preview
|
|
39
|
+
sigs.map { |sig| shown(sig) }.join
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def save(root)
|
|
43
|
+
File.write(File.join(root, target), text)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def text
|
|
47
|
+
before = (extends + sigs).group_by(&:index)
|
|
48
|
+
@lines.each_with_index.map { |line, index| "#{before.fetch(index, []).map(&:text).join}#{line}" }.join
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def shown(sig)
|
|
54
|
+
above = sig.outdented.map { |line| " #{line}" }.join
|
|
55
|
+
"#{target}:#{sig.index + 1}\n#{above} #{@lines.fetch(sig.index).strip}\n"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def indent(index)
|
|
59
|
+
line = @lines.fetch(index)
|
|
60
|
+
line.delete_suffix(line.lstrip)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def sigs
|
|
64
|
+
@sigs ||= bodies.flat_map { |scope| signable(scope).map { |method| sig(method, scope) } }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def bodies
|
|
68
|
+
[].tap { |all| @subject.outline.each { |scope| all << scope if scope.node } }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def signable(scope)
|
|
72
|
+
@subject.seen_in(scope).select { |method| line_above?(method, scope) && signable?(method) }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def line_above?(method, scope)
|
|
76
|
+
method.line > scope.node.start_line
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def signable?(method)
|
|
80
|
+
definition = @subject.source.definition(method)
|
|
81
|
+
definition && !@subject.source.signed?(definition) && @subject.observed(method).named?
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def sig(method, scope)
|
|
85
|
+
index = method.line - 1
|
|
86
|
+
Insertion.new(index, sig_lines(method, scope, indent(index)))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def sig_lines(method, scope, indent)
|
|
90
|
+
text = SigText.new(@subject.observed(method), @subject.lexical(scope))
|
|
91
|
+
text.lines(ROOM - indent.size).map { |line| "#{indent}#{line}\n" }.join
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def extends
|
|
95
|
+
bodies.reject(&:extended).reject { |scope| signable(scope).empty? }.map { |scope| extend_in(scope) }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def extend_in(scope)
|
|
99
|
+
index = scope.node.start_line
|
|
100
|
+
Insertion.new(index, "#{indent(index - 1)} extend T::Sig\n#{"\n" if @lines.fetch(index).match?(/\S/)}")
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through notation_spec.rb, which writes each type both ways.
|
|
4
|
+
|
|
5
|
+
require_relative "notation"
|
|
6
|
+
|
|
7
|
+
module RuntimeAnalysis
|
|
8
|
+
module Query
|
|
9
|
+
module Surfaces
|
|
10
|
+
class Crystallise
|
|
11
|
+
module SorbetNotation
|
|
12
|
+
extend Notation
|
|
13
|
+
|
|
14
|
+
HOLDERS = { "Array" => ["T::Array", 1], "Hash" => ["T::Hash", 2], "Set" => ["T::Set", 1],
|
|
15
|
+
"Range" => ["T::Range", 1] }.freeze
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
def untyped = "T.untyped"
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def only_nil = "NilClass"
|
|
23
|
+
|
|
24
|
+
def union(present)
|
|
25
|
+
present.size > 1 ? "T.any(#{present.join(", ")})" : present.first
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def optional(present)
|
|
29
|
+
"T.nilable(#{union(present)})"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def a_class(itself)
|
|
33
|
+
itself ? "T.class_of(#{itself})" : "T::Class[T.anything]"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def one(name, *held)
|
|
37
|
+
return "T::Boolean" if name == "bool"
|
|
38
|
+
return a_class(itself_of(held)) if name == "Class"
|
|
39
|
+
|
|
40
|
+
holder, takes = HOLDERS[name]
|
|
41
|
+
holder ? holding(holder, held, takes) : name
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# no-unit-test: asserted through ../crystallise_spec.rb, which crystallises whole files.
|
|
4
|
+
|
|
5
|
+
require "runtime_analysis/ruby_parsing"
|
|
6
|
+
require "runtime_analysis/query/index"
|
|
7
|
+
require_relative "observed"
|
|
8
|
+
require_relative "lexical"
|
|
9
|
+
require_relative "outline"
|
|
10
|
+
|
|
11
|
+
module RuntimeAnalysis
|
|
12
|
+
module Query
|
|
13
|
+
module Surfaces
|
|
14
|
+
class Crystallise
|
|
15
|
+
class Subject
|
|
16
|
+
attr_reader :file, :text, :source
|
|
17
|
+
|
|
18
|
+
def initialize(file, text, recording, seen)
|
|
19
|
+
@file = file
|
|
20
|
+
@text = text
|
|
21
|
+
@source = Index.source(text)
|
|
22
|
+
@graph, @shapes = recording
|
|
23
|
+
@seen = seen
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def outline
|
|
27
|
+
@outline ||= Outline.of(RubyParsing.tree_of(@text))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def observed(method)
|
|
31
|
+
@observed ||= {}
|
|
32
|
+
@observed[method] ||= observe(method)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def observe(method)
|
|
36
|
+
Observed.new(method, @source.definition(method), @graph, @shapes, @seen)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def seen_in(scope)
|
|
40
|
+
@source.methods.select { |method| scope.lines.include?(method.line) && observed(method).seen? }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def lexical(scope)
|
|
44
|
+
@known ||= @graph.static.classes.to_set(&:name)
|
|
45
|
+
Lexical.new(scope.nesting, @known)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def seen?
|
|
49
|
+
@source.methods.any? { |method| observed(method).seen? }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/query/index"
|
|
4
|
+
require_relative "crystallise/seen"
|
|
5
|
+
require_relative "crystallise/subject"
|
|
6
|
+
require_relative "crystallise/rbs_file"
|
|
7
|
+
require_relative "crystallise/sorbet_edit"
|
|
8
|
+
|
|
9
|
+
module RuntimeAnalysis
|
|
10
|
+
module Query
|
|
11
|
+
module Surfaces
|
|
12
|
+
class Crystallise
|
|
13
|
+
WRITERS = { sorbet: SorbetEdit, rbs: RbsFile }.freeze
|
|
14
|
+
SEEN = { sorbet: Seen.enforced, rbs: Seen }.freeze
|
|
15
|
+
FLAGS = %w[--sorbet --rbs --write].freeze
|
|
16
|
+
NOTATION_DIRECTORY = { sorbet: "sorbet", rbs: "sig" }.freeze
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
def command(argv, line, graphs, out)
|
|
20
|
+
flags = argv & FLAGS
|
|
21
|
+
files = argv - flags
|
|
22
|
+
line.parse!(files)
|
|
23
|
+
raise ArgumentError, "crystallise needs a file" if files.empty?
|
|
24
|
+
|
|
25
|
+
on(line, graphs, out).call(files, notation: notation(flags, line.root), write: flags.include?("--write"))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def on(line, graphs, out)
|
|
29
|
+
new(graphs.load(line.recording), Project.new(line.root), out: out)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def notation(flags, root)
|
|
33
|
+
asked = WRITERS.keys.select { |name| flags.include?("--#{name}") }
|
|
34
|
+
chosen = asked.empty? ? kept(root) : asked
|
|
35
|
+
chosen.size == 1 ? chosen.first : raise(ArgumentError, "crystallise needs --sorbet or --rbs")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def kept(root)
|
|
39
|
+
NOTATION_DIRECTORY.select { |_, directory| File.directory?(File.join(root, directory)) }.keys
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def initialize(graph, project, out:)
|
|
44
|
+
@graph = Index.as_named(graph, project)
|
|
45
|
+
@shapes = Index.shapes(@graph, classes_only: true)
|
|
46
|
+
@project = project
|
|
47
|
+
@out = out
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def call(files, notation:, write: false)
|
|
51
|
+
files.map { |file| one(@project.relative(File.expand_path(file, @project.root)), notation, write) }.max
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def one(file, notation, write)
|
|
57
|
+
subject = subject(file, notation)
|
|
58
|
+
return say("no run called a method of #{file}", 1) unless subject.seen?
|
|
59
|
+
|
|
60
|
+
writer = WRITERS.fetch(notation).new(subject)
|
|
61
|
+
writer.count.zero? ? say("no #{writer.noun} to add to #{file}", 1) : finish(writer, write)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def subject(file, notation)
|
|
65
|
+
Subject.new(file, File.read(File.join(@project.root, file)), [@graph, @shapes], SEEN.fetch(notation))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def finish(writer, write)
|
|
69
|
+
write ? save(writer) : show(writer)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def show(writer)
|
|
73
|
+
@out.print writer.preview
|
|
74
|
+
0
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def save(writer)
|
|
78
|
+
return say("wrote #{counted(writer)} to #{writer.target}", 0) if writer.save(@project.root)
|
|
79
|
+
|
|
80
|
+
say("#{writer.target} was not written by ra crystallise and is left as it is", 1)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def counted(writer)
|
|
84
|
+
"#{writer.count} #{writer.noun}#{"s" unless writer.count == 1}"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def say(message, status)
|
|
88
|
+
@out.puts "ra: #{message}"
|
|
89
|
+
status
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/query"
|
|
4
|
+
require "runtime_analysis/query/index"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Surfaces
|
|
9
|
+
class Mcp
|
|
10
|
+
ROWS = "How many rows to show (default #{Report.top}, or all)".freeze
|
|
11
|
+
|
|
12
|
+
def self.serve(recording:, root:)
|
|
13
|
+
server = build(recording: recording, root: root)
|
|
14
|
+
MCP::Server::Transports::StdioTransport.new(server).open
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Recorded = Struct.new(:graphs, :recording, :project)
|
|
18
|
+
|
|
19
|
+
class Recorded
|
|
20
|
+
def graph = graphs.load(recording)
|
|
21
|
+
def must_be_readable = graph
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.build(recording:, root:)
|
|
25
|
+
load_sdk
|
|
26
|
+
recorded = Recorded.new(Index.cache, recording, Project.new(root))
|
|
27
|
+
recorded.must_be_readable
|
|
28
|
+
MCP::Server.new(name: "runtime_analysis", version: VERSION, tools: tools(recorded))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.tools(recorded)
|
|
32
|
+
Tools.all.map { |tool| new(tool, recorded).define }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.load_sdk
|
|
36
|
+
require "mcp"
|
|
37
|
+
rescue LoadError
|
|
38
|
+
raise LoadError, "the MCP server needs the mcp gem: gem install mcp"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def initialize(tool, recorded)
|
|
42
|
+
@tool = tool
|
|
43
|
+
@recorded = recorded
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def define
|
|
47
|
+
answer = public_method(:answer)
|
|
48
|
+
MCP::Tool.define(name: @tool.tool_name, description: @tool.description, input_schema: schema) do |**args|
|
|
49
|
+
answer.call(args.except(:server_context))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def answer(args)
|
|
54
|
+
asked = declared.key?(:top) ? args : args.except(:top)
|
|
55
|
+
instance = @tool.new(@recorded.graph, project: @recorded.project)
|
|
56
|
+
Mcp.run(instance, asked, args.fetch(:top, Report.top))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def schema
|
|
60
|
+
{ properties: declared.merge(top: top),
|
|
61
|
+
required: @tool.arguments.select(&:required).map(&:name) }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def top
|
|
65
|
+
{ type: %w[integer string], description: declared.dig(:top, :description) || ROWS }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def declared
|
|
69
|
+
@tool.arguments.to_h { |arg| [arg.name, property(arg)] }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def property(argument)
|
|
73
|
+
{ type: argument.type, description: argument.description }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.run(instance, args, top)
|
|
77
|
+
response(instance.call(**args).top(top))
|
|
78
|
+
rescue ArgumentError => e
|
|
79
|
+
MCP::Tool::Response.new([{ type: "text", text: e.message }], error: true)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def self.response(document)
|
|
83
|
+
text = Report.text(document)
|
|
84
|
+
MCP::Tool::Response.new([{ type: "text", text: text }], structured_content: Report.to_h(document))
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "runtime_analysis/errors"
|
|
6
|
+
|
|
7
|
+
module RuntimeAnalysis
|
|
8
|
+
module Query
|
|
9
|
+
module Surfaces
|
|
10
|
+
class Record
|
|
11
|
+
class Commands
|
|
12
|
+
NAME = "commands.json"
|
|
13
|
+
|
|
14
|
+
def self.file(env)
|
|
15
|
+
File.join(env["XDG_CONFIG_HOME"] || File.join(Dir.home, ".config"), "runtime_analysis", NAME)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
attr_reader :file
|
|
19
|
+
|
|
20
|
+
def initialize(file, root)
|
|
21
|
+
@file = file
|
|
22
|
+
@root = root
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def [](name)
|
|
26
|
+
all.dig(@root, name)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def []=(name, command)
|
|
30
|
+
FileUtils.mkdir_p(File.dirname(@file))
|
|
31
|
+
File.write(@file, JSON.pretty_generate(all.merge(@root => all.fetch(@root, {}).merge(name => command))))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def all
|
|
37
|
+
File.exist?(@file) ? JSON.parse(File.read(@file)) : {}
|
|
38
|
+
rescue Errors.unreadable_json
|
|
39
|
+
{}
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "runtime_analysis/query/surfaces/setup"
|
|
4
|
+
require "runtime_analysis/platform"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Surfaces
|
|
9
|
+
class Record
|
|
10
|
+
class Environment
|
|
11
|
+
LIB = Platform.lib
|
|
12
|
+
INJECT = "-rruntime_analysis/inject"
|
|
13
|
+
|
|
14
|
+
def initialize(root, recording, env: ENV)
|
|
15
|
+
@root = root
|
|
16
|
+
@recording = recording
|
|
17
|
+
@env = env
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_h(label = nil)
|
|
21
|
+
kept("OUTPUT" => @recording, "TIER" => "4", "LABEL" => label)
|
|
22
|
+
.merge("DISABLE_SPRING" => "1", **(set_up? ? kept("ENABLED" => "1") : injected))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def set_up?
|
|
26
|
+
Setup.project(@root).bundled?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def kept(values)
|
|
32
|
+
values.to_h { |name, value| ["RUNTIME_ANALYSIS_#{name}", @env.fetch("RUNTIME_ANALYSIS_#{name}", value)] }
|
|
33
|
+
.compact
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def injected
|
|
37
|
+
{ "RUBYLIB" => after("RUBYLIB", LIB, Platform.search_path_separator),
|
|
38
|
+
"RUBYOPT" => after("RUBYOPT", INJECT, " "), "RUNTIME_ANALYSIS_ROOT" => @root }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def after(name, value, separator)
|
|
42
|
+
[@env[name], value].compact.join(separator)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module RuntimeAnalysis
|
|
7
|
+
module Query
|
|
8
|
+
module Surfaces
|
|
9
|
+
class Record
|
|
10
|
+
class Ignore
|
|
11
|
+
NOT_IGNORED = 1
|
|
12
|
+
|
|
13
|
+
def initialize(root, recording, capture: Open3.public_method(:capture2e))
|
|
14
|
+
@root = root
|
|
15
|
+
@recording = recording
|
|
16
|
+
@capture = capture
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def call
|
|
20
|
+
add(exclude) if inside? && shown?
|
|
21
|
+
rescue SystemCallError
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def inside?
|
|
28
|
+
@recording.start_with?("#{@root}/")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def pattern
|
|
32
|
+
"/#{@recording.delete_prefix("#{@root}/")}/"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def shown?
|
|
36
|
+
git("check-ignore", File.join(@recording, "run.json")).last.exitstatus == NOT_IGNORED
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def exclude
|
|
40
|
+
git("rev-parse", "--git-path", "info/exclude").first.rstrip
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def add(file)
|
|
44
|
+
path = File.expand_path(file, @root)
|
|
45
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
46
|
+
File.write(path, "#{ended(path)}#{pattern}\n")
|
|
47
|
+
file
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def ended(path)
|
|
51
|
+
text = File.exist?(path) ? File.read(path) : ""
|
|
52
|
+
text.empty? || text.end_with?("\n") ? text : "#{text}\n"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def git(*command)
|
|
56
|
+
@capture.call("git", "-C", @root, *command)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|