Class: Eco::API::UseCases::GraphQL::Samples::Pages::Template::Deploy::DriftReport
- Inherits:
-
Object
- Object
- Eco::API::UseCases::GraphQL::Samples::Pages::Template::Deploy::DriftReport
- Defined in:
- lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb
Overview
Post-deploy verification: did the applied delta == the intended delta?
After a deploy, re-read the target template and run a self-version diff (gem
Diff::VersionDiff) between the PRE-deploy snapshot and the POST-deploy snapshot. That "applied
delta" is then compared, op/kind/attribute-wise, against the "intended delta" (the changelog of
the diff that produced the deploy batch).
We compare on a normalised signature per change (op + kind + attribute + before/after) rather than on Mongo ids, because a cross-object deploy re-homes ids on the target — the SHAPE of the change is what must match. Any change present in one side but not the other is reported honestly as drift; nothing is hand-waved as "close enough".
report = DriftReport.new( intended: source_diff, # the VersionDiff the deploy batch came from applied: Diff::VersionDiff.new(pre, post) # pre/post self-diff of the target ) report.match? # => true when applied delta == intended delta (shape-wise) report.missing # => intended changes NOT observed on the target (under-applied) report.unexpected # => changes observed on the target that were NOT intended (over/side-effect) report.report # => human summary for a ticket / log
Instance Attribute Summary collapse
-
#applied ⇒ Object
readonly
Returns the value of attribute applied.
-
#intended ⇒ Object
readonly
Returns the value of attribute intended.
Instance Method Summary collapse
-
#initialize(intended:, applied:) ⇒ DriftReport
constructor
A new instance of DriftReport.
-
#match? ⇒ Boolean
True when the applied delta exactly matches the intended delta (no drift either way).
-
#missing ⇒ Object
Signatures present in the intended delta but missing from the applied delta.
- #report ⇒ Object
- #to_h ⇒ Object
-
#unexpected ⇒ Object
Signatures present in the applied delta but not intended (side effects / over-apply).
Constructor Details
#initialize(intended:, applied:) ⇒ DriftReport
Returns a new instance of DriftReport.
28 29 30 31 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 28 def initialize(intended:, applied:) @intended = intended @applied = applied end |
Instance Attribute Details
#applied ⇒ Object (readonly)
Returns the value of attribute applied.
24 25 26 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 24 def applied @applied end |
#intended ⇒ Object (readonly)
Returns the value of attribute intended.
24 25 26 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 24 def intended @intended end |
Instance Method Details
#match? ⇒ Boolean
True when the applied delta exactly matches the intended delta (no drift either way).
44 45 46 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 44 def match? missing.empty? && unexpected.empty? end |
#missing ⇒ Object
Signatures present in the intended delta but missing from the applied delta.
34 35 36 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 34 def missing @missing ||= (intended_signatures.keys - applied_signatures.keys).map { |sig| intended_signatures[sig] } end |
#report ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 58 def report return 'DEPLOY VERIFY OK — applied delta matches intended delta.' if match? lines = ['DEPLOY DRIFT detected:'] lines << " Missing (intended but not applied): #{missing.size}" missing.each { |c| lines << " - #{describe(c)}" } lines << " Unexpected (applied but not intended): #{unexpected.size}" unexpected.each { |c| lines << " + #{describe(c)}" } lines.join("\n") end |
#to_h ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 48 def to_h { match: match?, intended: intended_signatures.size, applied: applied_signatures.size, missing: missing.map { |c| describe(c) }, unexpected: unexpected.map { |c| describe(c) } } end |
#unexpected ⇒ Object
Signatures present in the applied delta but not intended (side effects / over-apply).
39 40 41 |
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/drift_report.rb', line 39 def unexpected @unexpected ||= (applied_signatures.keys - intended_signatures.keys).map { |sig| applied_signatures[sig] } end |