branchproof 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5027104f6aeb6181f75ccc463ef93d6cf78489ba28e8c6824308d13546a5586
4
- data.tar.gz: 442f07bf0dc87e1f3ed5bcc371d130da1612afd91f69837f8869b81fdf7c95f6
3
+ metadata.gz: 54d2cbd08336e8e70fa291f82e821043d06572485a57c0aa500656b29500688f
4
+ data.tar.gz: 805857b4b676e3d3cef1627890a2ab62fb7e7cda404b43907e9b2b1db2bbedca
5
5
  SHA512:
6
- metadata.gz: 707ca0fff8681d36f7a0e635513c3914ed403ddaf0e96c1ddec646574abee54daf50e60f05c16a79d2b522a7f568a09ee99da3807161dd471646291442f80323
7
- data.tar.gz: 3c446a3c71dd5a89cc0f12fa77ef61ef96a339a81bffd744dad86db4d2d7044f28c34a294342b29868b2ed848be1892892d8e28eff29f4e55f9b72a4ee57be62
6
+ metadata.gz: 44aed1ac067e6d1f0d2a5858b1b3ba14f102805f0b16c3b63cfdb9a605fb2df26bc113a1d70c53236ce1023aa991b05ae1c600439b89cb35297134883a0b5b86
7
+ data.tar.gz: d003e7b90e2413d20b788f9717f6df5512611bfbd4e3b1e8a0695b55bc9d62fbbbb3c10097905653f03119c2eb30a47d098051e5e0579a58ef51c0ce5b9dbcba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2026-09-10
4
+
5
+ - Add `--missing-only` to focus terminal reports on unproven conditions.
6
+ - Explain missing observations with required truth values and comparison tests.
7
+ - Fix incorrect `INFEASIBLE_IN_MODEL` results caused by missing source identifiers.
8
+
3
9
  ## [0.2.0] - 2026-09-09
4
10
 
5
11
  - Prepared the initial public-release candidate.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -97,7 +97,7 @@ For example, running the contents of the small `decision.rb` /
97
97
  with the terminal format produces a summary like this:
98
98
 
99
99
  ```text
100
- Branchproof 0.2.0
100
+ Branchproof 0.3.0
101
101
  Tests: PASSED (3 tests, 0 failed, 0 skipped)
102
102
  MC/DC: 100.0% (2/2 conditions proven)
103
103
  Analysis: COMPLETE
@@ -126,6 +126,53 @@ Additional tests outside this MC/DC evidence set may improve coverage.
126
126
  The test execution still runs once for the selected level. Use `--format
127
127
  json` when a consumer needs the complete identifiers and versioned schema.
128
128
 
129
+ ### Find missing cases
130
+
131
+ Use `--missing-only` to focus the terminal report on conditions that still
132
+ lack independence evidence:
133
+
134
+ ```sh
135
+ bundle exec mcdc analyze 'lib/**/*.rb' --missing-only
136
+ ```
137
+
138
+ This keeps the overall summary and diagnostics, hides proven conditions and
139
+ supporting-set lists, and shows missing scenarios using the source expressions.
140
+ It works with levels 2 and 3 (the default). JSON remains the complete report;
141
+ `--missing-only` cannot be combined with `--format json` or `--level 1`.
142
+
143
+ For example, given this decision:
144
+
145
+ ```ruby
146
+ content && Instruction.installed?(content)
147
+ ```
148
+
149
+ Observing `[TT]` and `[F-]` proves the effect of `content`, but does not prove
150
+ the effect of `Instruction.installed?(content)`. The missing case is `[TF]`:
151
+ `content` must be truthy and `Instruction.installed?(content)` must be falsey,
152
+ making the decision false. The missing condition is presented as:
153
+
154
+ ```text
155
+ Condition 1: Instruction.installed?(content)
156
+ NOT_PROVEN — missing observation
157
+ Need an observation where:
158
+ content is truthy
159
+ Instruction.installed?(content) is falsey
160
+ Expected decision: false [TF]
161
+ ```
162
+
163
+ An existing file without the instruction block
164
+ may produce this case; the test must reach the reported line. The report
165
+ describes required truth values, not application inputs or guaranteed
166
+ reachable paths. In Ruby, only `false` and `nil` are falsey; an empty string
167
+ is truthy.
168
+
169
+ `NOT_PROVEN` means analysis ran but did not find the required pair of
170
+ observations. `NOT CALCULATED` means analysis was not available or was not
171
+ requested; check the test status and diagnostics before adding tests.
172
+ `Analysis: COMPLETE` means the analysis finished, not that every condition
173
+ was proven. Missing conditions may require new tests or changes to existing
174
+ test inputs; they do not by themselves prove a bug in the application.
175
+
129
176
  The levels select how much of the one-run result is displayed:
130
177
 
131
178
  * Level 1 reports observed vectors grouped by their raw decision outcomes.
@@ -18,7 +18,7 @@ Not documented.
18
18
  ### `exit_code()` <a id="method-i-exit_code"></a> <a id="exit_code-instance_method"></a>
19
19
  Not documented.
20
20
 
21
- ### `initialize(inventory:, evidence:, analysis:, minima:, baseline:, diagnostics:, level: = 3)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
21
+ ### `initialize(inventory:, evidence:, analysis:, minima:, baseline:, diagnostics:, level: = 3, missing_only: = false)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
22
22
  - **@raise** [ArgumentError]
23
23
  - **@return** [Report] a new instance of Report
24
24
 
data/doc/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2026-09-10
4
+
5
+ - Add `--missing-only` to focus terminal reports on unproven conditions.
6
+ - Explain missing observations with required truth values and comparison tests.
7
+ - Fix incorrect `INFEASIBLE_IN_MODEL` results caused by missing source identifiers.
8
+
3
9
  ## [0.2.0] - 2026-09-09
4
10
 
5
11
  - Prepared the initial public-release candidate.
data/doc/README.md CHANGED
@@ -97,7 +97,7 @@ For example, running the contents of the small `decision.rb` /
97
97
  with the terminal format produces a summary like this:
98
98
 
99
99
  ```text
100
- Branchproof 0.2.0
100
+ Branchproof 0.3.0
101
101
  Tests: PASSED (3 tests, 0 failed, 0 skipped)
102
102
  MC/DC: 100.0% (2/2 conditions proven)
103
103
  Analysis: COMPLETE
@@ -126,6 +126,53 @@ Additional tests outside this MC/DC evidence set may improve coverage.
126
126
  The test execution still runs once for the selected level. Use `--format
127
127
  json` when a consumer needs the complete identifiers and versioned schema.
128
128
 
129
+ ### Find missing cases
130
+
131
+ Use `--missing-only` to focus the terminal report on conditions that still
132
+ lack independence evidence:
133
+
134
+ ```sh
135
+ bundle exec mcdc analyze 'lib/**/*.rb' --missing-only
136
+ ```
137
+
138
+ This keeps the overall summary and diagnostics, hides proven conditions and
139
+ supporting-set lists, and shows missing scenarios using the source expressions.
140
+ It works with levels 2 and 3 (the default). JSON remains the complete report;
141
+ `--missing-only` cannot be combined with `--format json` or `--level 1`.
142
+
143
+ For example, given this decision:
144
+
145
+ ```ruby
146
+ content && Instruction.installed?(content)
147
+ ```
148
+
149
+ Observing `[TT]` and `[F-]` proves the effect of `content`, but does not prove
150
+ the effect of `Instruction.installed?(content)`. The missing case is `[TF]`:
151
+ `content` must be truthy and `Instruction.installed?(content)` must be falsey,
152
+ making the decision false. The missing condition is presented as:
153
+
154
+ ```text
155
+ Condition 1: Instruction.installed?(content)
156
+ NOT_PROVEN — missing observation
157
+ Need an observation where:
158
+ content is truthy
159
+ Instruction.installed?(content) is falsey
160
+ Expected decision: false [TF]
161
+ ```
162
+
163
+ An existing file without the instruction block
164
+ may produce this case; the test must reach the reported line. The report
165
+ describes required truth values, not application inputs or guaranteed
166
+ reachable paths. In Ruby, only `false` and `nil` are falsey; an empty string
167
+ is truthy.
168
+
169
+ `NOT_PROVEN` means analysis ran but did not find the required pair of
170
+ observations. `NOT CALCULATED` means analysis was not available or was not
171
+ requested; check the test status and diagnostics before adding tests.
172
+ `Analysis: COMPLETE` means the analysis finished, not that every condition
173
+ was proven. Missing conditions may require new tests or changes to existing
174
+ test inputs; they do not by themselves prove a bug in the application.
175
+
129
176
  The levels select how much of the one-run result is displayed:
130
177
 
131
178
  * Level 1 reports observed vectors grouped by their raw decision outcomes.
@@ -181,7 +181,7 @@ module Branchproof
181
181
  end
182
182
 
183
183
  effective_mask(vector, id(decision, :id), decision[:tree])
184
- vector
184
+ decision_source.nil? ? vector : vector.merge(source_id: decision_source)
185
185
  rescue ArgumentError
186
186
  @analysis_invalid = true
187
187
  add_diagnostic("invalid_vector", "error", id(vector, :id))
@@ -69,7 +69,7 @@ module Branchproof
69
69
  minima = options[:level] == 1 ? [] : Array(value(baseline, :minima))
70
70
  report = Report.new(inventory: inventory, evidence: value(baseline, :evidence) || evidence.snapshot,
71
71
  analysis: analysis, minima: minima, baseline: baseline, diagnostics: diagnostics,
72
- level: options[:level])
72
+ level: options[:level], missing_only: options[:missing_only])
73
73
  output_report(report, options)
74
74
  report.exit_code
75
75
  rescue ArgumentError => e
@@ -88,10 +88,12 @@ module Branchproof
88
88
  runner_args = delimiter ? args[(delimiter + 1)..] : []
89
89
  args = args[0...delimiter] if delimiter
90
90
  options = { level: 3, format: :terminal, output: nil, tests: [], source_paths: [], limits: Limits.default,
91
- runner_args: runner_args, project: nil }
91
+ runner_args: runner_args, project: nil, missing_only: false }
92
92
  until args.empty?
93
93
  token = args.shift
94
94
  case token
95
+ when "--missing-only"
96
+ options[:missing_only] = true
95
97
  when "--level"
96
98
  level = Integer(args.shift.to_s, 10)
97
99
  raise ArgumentError, "level must be 1, 2, or 3" unless (1..3).cover?(level)
@@ -126,6 +128,10 @@ module Branchproof
126
128
  options[:source_paths] << token
127
129
  end
128
130
  end
131
+ if options[:missing_only] && (options[:format] != :terminal || options[:level] == 1)
132
+ raise ArgumentError, "--missing-only requires terminal format and level 2 or 3"
133
+ end
134
+
129
135
  options[:project] ||= Project.new(root: Dir.pwd, mode: "auto").to_h
130
136
  options[:source_paths] = default_sources if options[:source_paths].empty?
131
137
  options[:tests] = default_tests if options[:tests].empty?
@@ -8,7 +8,7 @@ module Branchproof
8
8
  SCHEMA_VERSION = "1.0"
9
9
  CRITERION_VERSION = "masking_occurrence_v1"
10
10
 
11
- def initialize(inventory:, evidence:, analysis:, minima:, baseline:, diagnostics:, level: 3)
11
+ def initialize(inventory:, evidence:, analysis:, minima:, baseline:, diagnostics:, level: 3, missing_only: false)
12
12
  raise ArgumentError, "level must be 1, 2, or 3" unless [1, 2, 3].include?(level.to_i)
13
13
 
14
14
  @inventory = inventory || {}
@@ -18,6 +18,7 @@ module Branchproof
18
18
  @baseline = baseline || {}
19
19
  @diagnostics = Array(diagnostics)
20
20
  @level = level.to_i
21
+ @missing_only = !!missing_only
21
22
  end
22
23
 
23
24
  def write(io:, format:)
@@ -64,10 +65,11 @@ module Branchproof
64
65
  "Observations: #{metrics[:completed]} completed, #{metrics[:aborted]} aborted, " \
65
66
  "#{metrics[:unattributed]} unattributed",
66
67
  "Values: T=true, F=false, -=short-circuited"]
68
+ lines << missing_summary_line if @missing_only
67
69
  lines << "Scope: supported decisions and conditions"
68
70
  lines << ""
69
- inventory_decisions.each { |decision| render_decision(lines, decision) }
70
- render_minima(lines)
71
+ decisions_to_render.each { |decision| render_decision(lines, decision) }
72
+ render_minima(lines) unless @missing_only
71
73
  unless @diagnostics.empty?
72
74
  lines << "Diagnostics:"
73
75
  @diagnostics.each { |diagnostic| lines << " - #{value(diagnostic, :message) || value(diagnostic, :code)}" }
@@ -82,9 +84,9 @@ module Branchproof
82
84
  lines << decision_label
83
85
  lines << " Decision: #{value(decision, :expression)}"
84
86
  lines << " Status: #{value(decision, :support_status) || "SUPPORTED"}"
85
- Array(value(decision, :conditions)).each do |condition|
87
+ conditions_to_render(decision).each do |condition|
86
88
  result = condition_result(decision, condition)
87
- detail = condition_detail(result)
89
+ detail = condition_detail(decision, condition, result)
88
90
  status = if @analysis.nil? || @level == 1
89
91
  "NOT CALCULATED"
90
92
  else
@@ -93,7 +95,7 @@ module Branchproof
93
95
  lines << " Condition #{value(condition, :index)}: #{value(condition, :expression)}"
94
96
  lines << " #{status}#{detail}"
95
97
  end
96
- vectors_for(decision).each do |vector|
98
+ vectors_to_render(decision).each do |vector|
97
99
  values = Array(value(vector, :values)).map do |item|
98
100
  if item.nil?
99
101
  "-"
@@ -169,6 +171,11 @@ module Branchproof
169
171
  [value(result, :condition_id), *Array(value(result, :canonical_pair))]
170
172
  end
171
173
  end)
174
+ ids.concat(Array(value(@analysis, :decisions)).flat_map do |decision|
175
+ Array(value(decision, :condition_results)).flat_map do |result|
176
+ Array(value(value(result, :constraint_result), :candidate_vectors)).map { |vector| value(vector, :id) }
177
+ end
178
+ end)
172
179
  ids = ids.compact.map(&:to_s).reject(&:empty?).uniq
173
180
  by_prefix = ids.group_by { |id| id[0, 8] }
174
181
  ids.to_h do |id|
@@ -264,24 +271,104 @@ module Branchproof
264
271
  end
265
272
  end
266
273
 
267
- def condition_detail(result)
268
- return "" unless result && @level == 3
274
+ def condition_detail(decision, _condition, result)
275
+ return "" unless result && (@level == 3 || @missing_only)
269
276
 
270
277
  pair = value(result, :canonical_pair)
271
278
  return " (witness #{Array(pair).map { |id| short_id(id) }.join(" + ")})" if pair
272
279
 
273
280
  constraint = value(result, :constraint_result)
274
281
  if constraint
275
- constraints = Array(value(constraint, :constraints)).map { |item| item.is_a?(Hash) ? item.inspect : item.to_s }
282
+ constraints = readable_constraints(decision, constraint)
276
283
  detail = constraints.empty? ? value(constraint, :status) : constraints.join(", ")
277
284
  statement = value(constraint, :feasibility_statement)
278
285
  detail = [detail, statement].compact.reject(&:empty?).join("; ")
286
+ candidates = Array(value(constraint, :candidate_vectors))
287
+ existing = existing_vector_for(constraint)
288
+ unless candidates.empty?
289
+ detail_lines = [" — missing observation"]
290
+ candidates.each do |candidate|
291
+ detail_lines << " Need an observation where:"
292
+ detail_lines.concat(candidate_requirements(decision, candidate).map { |item| " #{item}" })
293
+ outcome = value(candidate, :outcome) ? "true" : "false"
294
+ detail_lines << " Expected decision: #{outcome} [#{vector_values(candidate)}]"
295
+ end
296
+ detail_lines << " #{statement}" unless statement.to_s.empty?
297
+ detail_lines << " Compare with: #{existing_vector_context(existing)}"
298
+ return detail_lines.join("\n")
299
+ end
300
+ unless existing.nil?
301
+ owner_ids = Array(value(existing, :test_ids))
302
+ owners = owner_ids.first(2).map { |id| test_label(id) }
303
+ owners << "#{owner_ids.length - 2} more" if owner_ids.length > 2
304
+ owner_detail = owners.empty? ? nil : " (#{owners.join(", ")})"
305
+ detail = [detail, "existing observation: #{short_id(value(existing, :id))}#{owner_detail}"].compact.join("; ")
306
+ end
279
307
  return " (missing counterpart: #{detail})" unless detail.empty?
280
308
  end
281
309
 
282
310
  ""
283
311
  end
284
312
 
313
+ def readable_constraints(decision, constraint)
314
+ Array(value(constraint, :constraints)).filter_map do |item|
315
+ if item.respond_to?(:key?)
316
+ index = value(item, :condition_index)
317
+ expression = condition_expression(decision, index) || "condition #{index}"
318
+ required = value(item, :required)
319
+ required = value(item, :value) if required.nil?
320
+ "requires #{expression}=#{required ? "true" : "false"}"
321
+ else
322
+ item.to_s
323
+ end
324
+ end
325
+ end
326
+
327
+ def condition_expression(decision, index)
328
+ condition = Array(value(decision, :conditions)).find { |item| value(item, :index).to_i == index.to_i }
329
+ value(condition, :expression)
330
+ end
331
+
332
+ def candidate_requirements(decision, candidate)
333
+ Array(value(candidate, :values)).each_with_index.map do |required, index|
334
+ expression = condition_expression(decision, index) || "condition #{index}"
335
+ if required.nil?
336
+ "#{expression} is not evaluated (short-circuited)"
337
+ else
338
+ "#{expression} is #{required ? "truthy" : "falsey"}"
339
+ end
340
+ end
341
+ end
342
+
343
+ def vector_values(vector)
344
+ Array(value(vector, :values)).map do |item|
345
+ if item.nil?
346
+ "-"
347
+ elsif item
348
+ "T"
349
+ else
350
+ "F"
351
+ end
352
+ end.join
353
+ end
354
+
355
+ def existing_vector_context(existing)
356
+ return "no existing effective observation" unless existing
357
+
358
+ owner_ids = Array(value(existing, :test_ids))
359
+ owners = owner_ids.first(2).map { |id| test_label(id) }
360
+ owners << "#{owner_ids.length - 2} more" if owner_ids.length > 2
361
+ context = "[#{vector_values(existing)}] => #{value(existing, :outcome) ? "true" : "false"}"
362
+ owners.empty? ? context : "#{context} (#{owners.join(", ")})"
363
+ end
364
+
365
+ def existing_vector_for(constraint)
366
+ id = value(constraint, :existing_vector_id).to_s
367
+ return if id.empty?
368
+
369
+ vectors.find { |vector| value(vector, :id).to_s == id }
370
+ end
371
+
285
372
  def metrics
286
373
  decisions = inventory_decisions
287
374
  unsupported, supported = decisions.partition { |decision| unsupported?(decision) }
@@ -349,6 +436,50 @@ module Branchproof
349
436
  end
350
437
  end
351
438
 
439
+ def decisions_to_render
440
+ return inventory_decisions unless @missing_only
441
+ return [] unless analysis_available?
442
+
443
+ inventory_decisions
444
+ .reject { |decision| unsupported?(decision) }
445
+ .select { |decision| conditions_to_render(decision).any? }
446
+ end
447
+
448
+ def conditions_to_render(decision)
449
+ conditions = Array(value(decision, :conditions))
450
+ return conditions unless @missing_only && analysis_available?
451
+
452
+ conditions.reject { |condition| value(condition_result(decision, condition), :status).to_s.upcase == "PROVEN" }
453
+ end
454
+
455
+ def vectors_to_render(decision)
456
+ return vectors_for(decision) unless @missing_only
457
+
458
+ []
459
+ end
460
+
461
+ def analysis_available?
462
+ !@analysis.nil? && @level > 1
463
+ end
464
+
465
+ def analysis_complete?
466
+ analysis_available? && baseline_status == "PASSED" && completeness.values.all?
467
+ end
468
+
469
+ def missing_condition_count
470
+ decisions_to_render.sum { |decision| conditions_to_render(decision).length }
471
+ end
472
+
473
+ def missing_summary_line
474
+ return "Missing conditions: Cannot identify missing conditions (analysis unavailable)" unless analysis_available?
475
+ return "Missing conditions: Cannot identify missing conditions (analysis incomplete)" unless analysis_complete?
476
+ return "No eligible conditions" if metrics[:eligible_conditions].zero?
477
+ return "No missing conditions" if analysis_complete? && missing_condition_count.zero?
478
+
479
+ count = decisions_to_render.length
480
+ "Missing conditions: #{missing_condition_count} across #{count} #{count == 1 ? "decision" : "decisions"}"
481
+ end
482
+
352
483
  def analysis_for(decision)
353
484
  Array(value(@analysis, :decisions)).find do |item|
354
485
  value(item, :decision_id).to_s == value(decision, :id).to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Branchproof
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/sig/branchproof.rbs CHANGED
@@ -102,7 +102,7 @@ module Branchproof
102
102
  class Report
103
103
  SCHEMA_VERSION: String
104
104
  CRITERION_VERSION: String
105
- def initialize: (inventory: record, evidence: record, analysis: record?, minima: Array[record], baseline: record, diagnostics: Array[record]) -> void
105
+ def initialize: (inventory: record, evidence: record, analysis: record?, minima: Array[record], baseline: record, diagnostics: Array[record], ?level: Integer, ?missing_only: bool) -> void
106
106
  def write: (io: _WriteIO, format: Symbol | String) -> nil
107
107
  def exit_code: () -> Integer
108
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branchproof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucian Ghinda
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - CHANGELOG.md
62
62
  - CODE_OF_CONDUCT.md
63
+ - LICENSE
63
64
  - LICENSE.txt
64
65
  - NOTICE
65
66
  - README.md