ctx_runner 0.1.0 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/ctx_runner/document.rb +47 -0
- data/lib/ctx_runner/evidence.rb +41 -0
- data/lib/ctx_runner/report.rb +21 -11
- data/lib/ctx_runner/version.rb +1 -1
- data/lib/ctx_runner.rb +2 -0
- metadata +19 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb856e1dde339c23607f185f8ac5ac0ab9bca29d94dc115661b145d1f2dfef5a
|
|
4
|
+
data.tar.gz: a255c77dafecab0b028974ebf2173efa5c412771621454a7e5c7cf2f6f0ee1cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2bfdd9ed85c4c2f48dfcaa568575a39f38cd6d7ebb952f198ed0d251b62b8749fe519de9886162bdaffa907733b4d12259bcf85d6b79a1aec7fa10868b1d8d7
|
|
7
|
+
data.tar.gz: 1e0fd95eddbe30863f53c3ac854d0c4a6452b17ad5b42e91c60b9dd4789ff162d7625ffb8a96c9b92e09bb1aae1d5b812600206c922fcf683f146796f9920c46
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.1 (2026-10-23)
|
|
6
|
+
|
|
7
|
+
- Add shared offline evidence validation with mandatory target identity.
|
|
8
|
+
- Normalize owned JSON documents without freezing caller keys; support consumers without encode/decode roundtrips.
|
|
9
|
+
|
|
3
10
|
## 0.1.0 (2026-10-22)
|
|
4
11
|
|
|
5
12
|
- Centralize batch completion, cancellation priority and presentation failures; close result registration before finalization and preserve immutable summaries.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "time"
|
|
4
|
+
|
|
5
|
+
module CtxRunner
|
|
6
|
+
# 显式证据边界:生成独立 JSON 值,不通过文本往返转换业务事实。
|
|
7
|
+
module Document
|
|
8
|
+
def self.call(value)
|
|
9
|
+
convert(value, {}.compare_by_identity, 0)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.convert(value, active, depth)
|
|
13
|
+
raise ArgumentError, "Document nesting exceeds the evidence budget" if depth > 128
|
|
14
|
+
case value
|
|
15
|
+
when Hash, Array, Data
|
|
16
|
+
raise ArgumentError, "Document must not contain cyclic data" if active[value]
|
|
17
|
+
active[value] = true
|
|
18
|
+
begin
|
|
19
|
+
case value
|
|
20
|
+
when Data then convert(value.to_h, active, depth + 1)
|
|
21
|
+
when Array then value.map { |item| convert(item, active, depth + 1) }.freeze
|
|
22
|
+
when Hash
|
|
23
|
+
value.each_with_object({}) do |(key, item), result|
|
|
24
|
+
unless [ String, Symbol, Integer, Float, Rational, Complex, NilClass, TrueClass, FalseClass ].any? { |type| key.is_a?(type) }
|
|
25
|
+
raise ArgumentError, "Document keys must be plain values"
|
|
26
|
+
end
|
|
27
|
+
name = String.new(key.to_s)
|
|
28
|
+
raise ArgumentError, "Document keys collide after normalization" if result.key?(name)
|
|
29
|
+
result[name.freeze] = convert(item, active, depth + 1)
|
|
30
|
+
end.freeze
|
|
31
|
+
end
|
|
32
|
+
ensure
|
|
33
|
+
active.delete(value)
|
|
34
|
+
end
|
|
35
|
+
when Time then value.iso8601(6).freeze
|
|
36
|
+
when String then value.dup.freeze
|
|
37
|
+
when Symbol, Rational, Complex then value.to_s.freeze
|
|
38
|
+
when Float
|
|
39
|
+
raise ArgumentError, "Document numbers must be finite" unless value.finite?
|
|
40
|
+
value
|
|
41
|
+
when Integer, NilClass, TrueClass, FalseClass then value
|
|
42
|
+
else raise ArgumentError, "Document must contain plain values"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
private_class_method :convert
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ipaddr"
|
|
4
|
+
|
|
5
|
+
module CtxRunner
|
|
6
|
+
# 离线证据的公共外壳;记录字段和领域语义交给消费模块校验。
|
|
7
|
+
module Evidence
|
|
8
|
+
def self.validate(document)
|
|
9
|
+
unless document.is_a?(Hash) && document["device"].is_a?(Hash) &&
|
|
10
|
+
%w[name host].all? { |key| document["device"][key].is_a?(String) && !document["device"][key].empty? }
|
|
11
|
+
raise ArgumentError, "无设备身份"
|
|
12
|
+
end
|
|
13
|
+
host = document["device"]["host"]
|
|
14
|
+
raise ArgumentError, "目标地址须为规范主机地址" unless !host.include?("/") && IPAddr.new(host).to_s == host
|
|
15
|
+
snapshot = document.fetch("snapshot")
|
|
16
|
+
return if snapshot.nil?
|
|
17
|
+
raise ArgumentError, "快照结构错误" unless snapshot.is_a?(Hash) && snapshot["dimensions"].is_a?(Hash)
|
|
18
|
+
if !snapshot["target"].is_a?(Hash) || snapshot["target"]["host"] != host
|
|
19
|
+
raise ArgumentError, "设备身份与采集目标不一致"
|
|
20
|
+
end
|
|
21
|
+
snapshot["dimensions"].each do |dimension, observation|
|
|
22
|
+
unless observation.is_a?(Hash) && %w[complete partial failed unsupported not_requested].include?(observation["status"])
|
|
23
|
+
raise ArgumentError, "观测结构错误"
|
|
24
|
+
end
|
|
25
|
+
records = array(observation.fetch("records"))
|
|
26
|
+
array(observation.fetch("issues", []))
|
|
27
|
+
records.each { |record| yield(record, dimension) }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.array(value)
|
|
32
|
+
raise ArgumentError, "列表结构错误" unless value.is_a?(Array) && value.all? { |entry| entry.is_a?(Hash) }
|
|
33
|
+
value
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.map(value)
|
|
37
|
+
raise ArgumentError, "映射结构错误" unless value.is_a?(Hash) && value.values.all? { |entry| entry.is_a?(Hash) }
|
|
38
|
+
value
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/ctx_runner/report.rb
CHANGED
|
@@ -66,31 +66,40 @@ module CtxRunner
|
|
|
66
66
|
# 先保存未完成检查点;文本发布或最终提交失败都不能留下成功摘要。
|
|
67
67
|
checkpoint = summary.merge(status: interrupted ? :interrupted : :incomplete,
|
|
68
68
|
report_error: report_error || :report_finalization_unconfirmed)
|
|
69
|
-
checkpoint
|
|
69
|
+
checkpoint_body = JSON.pretty_generate(checkpoint) + "\n"
|
|
70
|
+
publish_checkpoint("summary.json", checkpoint_body)
|
|
70
71
|
publish("summary.txt", yield(summary))
|
|
71
|
-
|
|
72
|
+
commit_summary("summary.json", summary, checkpoint: checkpoint, checkpoint_body: checkpoint_body)
|
|
72
73
|
end
|
|
73
74
|
|
|
74
75
|
# 新一轮发布必须先撤销旧完成结论;非局部退出也不能绕过这条边界。
|
|
75
76
|
def checkpoint(relative, value)
|
|
77
|
+
publish_checkpoint(relative, JSON.pretty_generate(serializable(value)) + "\n")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# 领域报告正文完成后提交最终状态;取消和提交后失败共用恢复协议。
|
|
81
|
+
def finalize(relative, summary, checkpoint:)
|
|
82
|
+
relative = checked_relative(relative)
|
|
83
|
+
summary = CtxParser::Immutable.copy(serializable(summary))
|
|
84
|
+
checkpoint = CtxParser::Immutable.copy(serializable(checkpoint))
|
|
85
|
+
commit_summary(relative, summary, checkpoint: checkpoint, checkpoint_body: JSON.pretty_generate(checkpoint) + "\n")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def publish_checkpoint(relative, body)
|
|
76
89
|
relative = checked_relative(relative)
|
|
77
90
|
validated = true
|
|
78
91
|
published = false
|
|
79
|
-
publish(relative,
|
|
92
|
+
publish(relative, body)
|
|
80
93
|
published = true
|
|
81
94
|
ensure
|
|
82
95
|
invalidate_completed_summary(relative: relative) if validated && !published
|
|
83
96
|
end
|
|
97
|
+
private :publish_checkpoint
|
|
84
98
|
|
|
85
|
-
|
|
86
|
-
def finalize(relative, summary, checkpoint:)
|
|
87
|
-
relative = checked_relative(relative)
|
|
88
|
-
summary = CtxParser::Immutable.copy(serializable(summary))
|
|
89
|
-
checkpoint = CtxParser::Immutable.copy(serializable(checkpoint))
|
|
90
|
-
checkpoint_body = JSON.pretty_generate(checkpoint) + "\n"
|
|
99
|
+
def commit_summary(relative, summary, checkpoint:, checkpoint_body:)
|
|
91
100
|
finalized = false
|
|
92
101
|
begin
|
|
93
|
-
publish(relative, JSON.pretty_generate(
|
|
102
|
+
publish(relative, JSON.pretty_generate(summary) + "\n")
|
|
94
103
|
finalized = true
|
|
95
104
|
rescue Error => error
|
|
96
105
|
# 未替换时原检查点仍安全,不做可能破坏它的多余恢复写入。
|
|
@@ -98,7 +107,7 @@ module CtxRunner
|
|
|
98
107
|
finalized = true
|
|
99
108
|
raise
|
|
100
109
|
rescue Interrupt
|
|
101
|
-
restore_checkpoint(JSON.pretty_generate(
|
|
110
|
+
restore_checkpoint(JSON.pretty_generate(checkpoint.merge(status: :interrupted)) + "\n", relative: relative)
|
|
102
111
|
finalized = true
|
|
103
112
|
raise
|
|
104
113
|
ensure
|
|
@@ -107,6 +116,7 @@ module CtxRunner
|
|
|
107
116
|
end
|
|
108
117
|
summary
|
|
109
118
|
end
|
|
119
|
+
private :commit_summary
|
|
110
120
|
|
|
111
121
|
# 每次发送配置前后发布检查点;失败由执行器停止后续写入。
|
|
112
122
|
def write_execution(state)
|
data/lib/ctx_runner/version.rb
CHANGED
data/lib/ctx_runner.rb
CHANGED
|
@@ -7,4 +7,6 @@ require_relative "ctx_runner/query"
|
|
|
7
7
|
require_relative "ctx_runner/batch"
|
|
8
8
|
require_relative "ctx_runner/report"
|
|
9
9
|
require_relative "ctx_runner/fingerprint"
|
|
10
|
+
require_relative "ctx_runner/document"
|
|
11
|
+
require_relative "ctx_runner/evidence"
|
|
10
12
|
require_relative "ctx_runner/execution"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ctx_runner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gatework contributors
|
|
@@ -38,7 +38,7 @@ dependencies:
|
|
|
38
38
|
version: '0.2'
|
|
39
39
|
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: 0.2.
|
|
41
|
+
version: 0.2.6
|
|
42
42
|
type: :runtime
|
|
43
43
|
prerelease: false
|
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -48,7 +48,7 @@ dependencies:
|
|
|
48
48
|
version: '0.2'
|
|
49
49
|
- - ">="
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
|
-
version: 0.2.
|
|
51
|
+
version: 0.2.6
|
|
52
52
|
- !ruby/object:Gem::Dependency
|
|
53
53
|
name: digest
|
|
54
54
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -63,6 +63,20 @@ dependencies:
|
|
|
63
63
|
- - ">="
|
|
64
64
|
- !ruby/object:Gem::Version
|
|
65
65
|
version: '0'
|
|
66
|
+
- !ruby/object:Gem::Dependency
|
|
67
|
+
name: ipaddr
|
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
type: :runtime
|
|
74
|
+
prerelease: false
|
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
66
80
|
- !ruby/object:Gem::Dependency
|
|
67
81
|
name: json
|
|
68
82
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -135,6 +149,8 @@ files:
|
|
|
135
149
|
- lib/ctx_runner.rb
|
|
136
150
|
- lib/ctx_runner/batch.rb
|
|
137
151
|
- lib/ctx_runner/collection.rb
|
|
152
|
+
- lib/ctx_runner/document.rb
|
|
153
|
+
- lib/ctx_runner/evidence.rb
|
|
138
154
|
- lib/ctx_runner/execution.rb
|
|
139
155
|
- lib/ctx_runner/fingerprint.rb
|
|
140
156
|
- lib/ctx_runner/observation.rb
|