Module: Igniter::Extensions::Contracts::DebugPack
- Defined in:
- lib/igniter/extensions/contracts/debug_pack.rb
Constant Summary collapse
- REPORT_CONTRIBUTOR =
Module.new do module_function def augment(report:, result:, profile:) snapshot = DebugPack.profile_snapshot(profile) report.add_section(:debug, { profile_fingerprint: profile.fingerprint, pack_names: snapshot.pack_names, registry_keys: snapshot.registry_keys, output_names: result.outputs.keys.sort, state_keys: result.state.keys.sort, operation_count: result.compiled_graph.operations.length }) end end
Class Method Summary collapse
- .audit(pack, profile: nil) ⇒ Object
- .install_into(kernel) ⇒ Object
- .manifest ⇒ Object
- .pack_snapshot(pack_or_name, profile:) ⇒ Object
- .profile_snapshot(profile) ⇒ Object
- .provenance_summary(result) ⇒ Object
- .report(environment, inputs: nil, compiled_graph: nil, &block) ⇒ Object
- .snapshot(result, profile:) ⇒ Object
Class Method Details
.audit(pack, profile: nil) ⇒ Object
60 61 62 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 60 def audit(pack, profile: nil) Debug::PackAudit.build(pack, profile: profile) end |
.install_into(kernel) ⇒ Object
38 39 40 41 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 38 def install_into(kernel) kernel.diagnostics_contributors.register(:debug, REPORT_CONTRIBUTOR) kernel end |
.manifest ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 29 def manifest Igniter::Contracts::PackManifest.new( name: :extensions_debug, requires_packs: [ExecutionReportPack, ProvenancePack], registry_contracts: [Igniter::Contracts::PackManifest.diagnostic(:debug)], metadata: { category: :developer } ) end |
.pack_snapshot(pack_or_name, profile:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 47 def pack_snapshot(pack_or_name, profile:) manifest = case pack_or_name when Symbol, String profile.pack_manifest(pack_or_name) else pack_or_name.respond_to?(:manifest) ? pack_or_name.manifest : profile.pack_manifest(pack_or_name) end raise ArgumentError, "unknown pack #{pack_or_name}" unless manifest Debug::PackSnapshot.new(manifest) end |
.profile_snapshot(profile) ⇒ Object
43 44 45 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 43 def profile_snapshot(profile) Debug::ProfileSnapshot.new(profile: profile) end |
.provenance_summary(result) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 102 def provenance_summary(result) result.outputs.keys.sort.each_with_object({}) do |output_name, memo| lineage = ProvenancePack.lineage(result, output_name) memo[output_name] = { value: lineage.value, contributing_inputs: lineage.contributing_inputs, trace: lineage.to_h } end end |
.report(environment, inputs: nil, compiled_graph: nil, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 74 def report(environment, inputs: nil, compiled_graph: nil, &block) compilation = if block environment.compilation_report(&block) elsif compiled_graph nil else raise ArgumentError, "debug_report requires a block or compiled_graph" end graph = compiled_graph || compilation&.compiled_graph if inputs.nil? || compilation&.invalid? return Debug::Report.new(profile_snapshot: profile_snapshot(environment.profile), compilation_report: compilation) end result = environment.execute(graph, inputs: inputs) diagnostics = environment.diagnose(result) Debug::Report.new( profile_snapshot: profile_snapshot(environment.profile), compilation_report: compilation, execution_result: result, diagnostics_report: diagnostics, provenance_summary: provenance_summary(result) ) end |
.snapshot(result, profile:) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/igniter/extensions/contracts/debug_pack.rb', line 64 def snapshot(result, profile:) diagnostics = Igniter::Contracts.diagnose(result, profile: profile) Debug::Report.new( profile_snapshot: profile_snapshot(profile), execution_result: result, diagnostics_report: diagnostics, provenance_summary: provenance_summary(result) ) end |