rsmp-validator 0.3.2 → 0.4.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/config/secrets_example.yaml +2 -2
  3. data/config/simulator/supervisor.yaml +1 -1
  4. data/config/simulator/tlc.yaml +2 -1
  5. data/config/{cross_rs4s.yaml → sites/cross_rs4s.yaml} +5 -5
  6. data/config/sites/cross_rs5.yaml +62 -0
  7. data/config/{lightmotion_satellite.yaml → sites/lightmotion_satellite.yaml} +1 -1
  8. data/config/{swarco_itc3.yaml → sites/swarco_itc3.yaml} +3 -4
  9. data/config/validator.rb +1 -0
  10. data/config/validator_example.yaml +2 -2
  11. data/lib/rsmp/validator/buffer_replay_queue.rb +37 -0
  12. data/lib/rsmp/validator/cli/config_cli.rb +34 -9
  13. data/lib/rsmp/validator/config_check.rb +21 -2
  14. data/lib/rsmp/validator/config_normalizer.rb +3 -2
  15. data/lib/rsmp/validator/configuration/loader.rb +7 -13
  16. data/lib/rsmp/validator/configuration/secrets.rb +7 -3
  17. data/lib/rsmp/validator/configuration/sxls_override.rb +19 -4
  18. data/lib/rsmp/validator/configuration/test_requirements.rb +63 -0
  19. data/lib/rsmp/validator/configuration/version_normalization.rb +10 -5
  20. data/lib/rsmp/validator/configuration.rb +2 -9
  21. data/lib/rsmp/validator/helpers/alarms.rb +3 -3
  22. data/lib/rsmp/validator/helpers/connection.rb +14 -14
  23. data/lib/rsmp/validator/helpers/expectations.rb +35 -0
  24. data/lib/rsmp/validator/helpers/input.rb +3 -3
  25. data/lib/rsmp/validator/helpers/signal_plans.rb +11 -16
  26. data/lib/rsmp/validator/helpers/signal_priority.rb +23 -22
  27. data/lib/rsmp/validator/lifecycle.rb +2 -0
  28. data/lib/rsmp/validator/missing_configuration.rb +10 -0
  29. data/lib/rsmp/validator/options/site_test_options.rb +1 -1
  30. data/lib/rsmp/validator/options/supervisor_test_options.rb +1 -1
  31. data/lib/rsmp/validator/site_tester.rb +4 -19
  32. data/lib/rsmp/validator/version.rb +1 -1
  33. data/lib/rsmp/validator.rb +1 -0
  34. data/schemas/site_test.json +0 -4
  35. data/schemas/supervisor_test.json +0 -2
  36. data/schemas/test_config/common.json +21 -0
  37. data/schemas/test_config/core/3.1.4.json +14 -0
  38. data/schemas/test_config/core/3.1.5.json +14 -0
  39. data/schemas/test_config/core.json +33 -0
  40. data/schemas/test_config/tlc/1.0.15.json +13 -0
  41. data/schemas/test_config/tlc/1.0.7.json +67 -0
  42. data/schemas/test_config/tlc/1.0.8.json +13 -0
  43. data/schemas/test_config/tlc/1.1.0.json +13 -0
  44. data/schemas/test_config/versions.json +28 -0
  45. data/test/site/core/aggregated_status_spec.rb +28 -6
  46. data/test/site/core/message_buffer_spec.rb +90 -75
  47. data/test/site/tlc/alarm_spec.rb +9 -5
  48. data/test/site/tlc/clock_spec.rb +9 -9
  49. data/test/site/tlc/detector_logics_spec.rb +11 -9
  50. data/test/site/tlc/emergency_routes_spec.rb +4 -4
  51. data/test/site/tlc/invalid_command_spec.rb +9 -8
  52. data/test/site/tlc/invalid_status_spec.rb +8 -7
  53. data/test/site/tlc/modes_spec.rb +21 -21
  54. data/test/site/tlc/signal_groups_spec.rb +10 -10
  55. data/test/site/tlc/signal_plans_spec.rb +21 -21
  56. data/test/site/tlc/signal_priority_spec.rb +5 -5
  57. data/test/site/tlc/subscribe_spec.rb +31 -26
  58. data/test/site/tlc/system_spec.rb +11 -11
  59. data/test/site/tlc/traffic_data_spec.rb +12 -10
  60. data/test/site/tlc/traffic_situations_spec.rb +3 -3
  61. data/test/supervisor/aggregated_status_spec.rb +4 -0
  62. metadata +25 -11
  63. /data/config/{gem_tlc.yaml → sites/gem_tlc.yaml} +0 -0
  64. /data/config/{gem_tlc_secrets.yaml → sites/gem_tlc_secrets.yaml} +0 -0
  65. /data/config/{kapsch_etx.yaml → sites/kapsch_etx.yaml} +0 -0
  66. /data/config/{semaforica_cartesio.yaml → sites/semaforica_cartesio.yaml} +0 -0
  67. /data/config/{gem_supervisor.yaml → supervisors/gem_supervisor.yaml} +0 -0
  68. /data/config/{tecsen_tmacs_supervisor.yaml → supervisors/tecsen_tmacs_supervisor.yaml} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf28fcdaff9ccf8df4f107cbe2f045e55316f81285c21520da2ef63a19f9f94f
4
- data.tar.gz: 5c7614286acbcb9dce4abb36b66fb48a94493b072a7f88432b598e3249d0b6df
3
+ metadata.gz: c5d29638c39c7a9bf729e6f6483f470474581b5d2428155523d5f5c5036ba738
4
+ data.tar.gz: 966c2e1f373676a55852f64aadea6c3db580b00d342d1eaa223b5500b65f2625
5
5
  SHA512:
6
- metadata.gz: 3e31a7dd63d4143b7804f04026d090a1936e3918a6bd2f060c6e6dd8ae81ad74600ac76cac553a17a89daad2bf769efeaf293f0c6f73d5ca049dbcc756f99e06
7
- data.tar.gz: 4abbb6813ee551793997e18e680f131f15680f2a2a16361d524607baf9068807e4f7a663e5d136e2941b9dad8c9601a3ba995dcf80dcc778fef365702e34aa01
6
+ metadata.gz: 6b0b0a801b1447486098018eff54198b9f4d76b05a32689832c6355b365bd6d96382171a2ee6d04a436a12b1a51527a308b4a97b48807ba0386aee9f9f5c9db1
7
+ data.tar.gz: 895130c52fd6724a2a44f5fbb7f0e13763f9254700aa5ab52d43e580df16339363010d4ca321c96dede440850ed56f80c9593a56d148d322e0c2bc12513d94e4
@@ -1,5 +1,5 @@
1
- # copy this to config/secrets.yaml and add your real
2
- # security codes
1
+ # Copy this beside your device config as <name>_secrets.yaml
2
+ # (for example, config/sites/my_site_secrets.yaml) and add your security codes.
3
3
 
4
4
  security_codes:
5
5
  1: '1111'
@@ -2,7 +2,7 @@ port: 13111
2
2
  sites:
3
3
  default:
4
4
  sxls:
5
- tlc: '1.2.1'
5
+ tlc: ['1.2.1', '1.2.0', '1.1.0', '1.0.15', '1.0.14', '1.0.13', '1.0.10', '1.0.9', '1.0.8', '1.0.7']
6
6
  intervals:
7
7
  timer: 0.1
8
8
  watchdog: 0.1
@@ -4,7 +4,8 @@ supervisors:
4
4
  - ip: 127.0.0.1
5
5
  port: 13111
6
6
  sxls:
7
- tlc: '1.2.1'
7
+ # Start on the newest version; accept testing hints for the other supported versions.
8
+ tlc: ['1.3.0', '1.2.1', '1.2.0', '1.1.0', '1.0.15', '1.0.14', '1.0.13', '1.0.10', '1.0.9', '1.0.8', '1.0.7']
8
9
  components:
9
10
  main:
10
11
  TC:
@@ -4,7 +4,7 @@
4
4
  compliance:
5
5
  id: cross-rs4s
6
6
  kind: site
7
- name: Cross RS4S/RS4T/RS5
7
+ name: Cross RS4S/RS4T
8
8
  product_url: https://www.cross-traffic.com/en/traffic-light-controllers/
9
9
 
10
10
  local_supervisor:
@@ -23,7 +23,7 @@ timeouts:
23
23
  connect: 30
24
24
  ready: 1
25
25
  status_response: 3
26
- status_update: 5
26
+ status_update: 1
27
27
  subscribe: 1
28
28
  command: 300
29
29
  command_response: 30
@@ -32,7 +32,7 @@ timeouts:
32
32
  startup_sequence: 45
33
33
  functional_position: 60
34
34
  priority_completion: 15
35
- yellow_flash: 2
35
+ yellow_flash: 1
36
36
  components:
37
37
  main:
38
38
  CZ+76000=101TC001:
@@ -45,9 +45,9 @@ components:
45
45
  CZ+76000=101DL002:
46
46
  CZ+76000=101DL003:
47
47
  items:
48
- plans: [1,2] #switching to each plan takes a lot of time
48
+ plans: [6,1]
49
49
  traffic_situations: [1,2,3]
50
- emergency_routes: [1] # only one emergency route
50
+ emergency_routes: [1]
51
51
  inputs: [1,3,8]
52
52
  outputs: [1,3,8]
53
53
  startup_sequence: 'efg'
@@ -0,0 +1,62 @@
1
+ # Config for testing Cross RS4S traffic light controller.
2
+ # The settings are used for starting a local supervisor listening for the site tested
3
+ # See https://rsmp-nordic.github.io/rsmp_validator/config/
4
+ compliance:
5
+ id: cross-rs5
6
+ kind: site
7
+ name: Cross RS5
8
+ product_url: https://www.cross-traffic.com/en/traffic-light-controllers/
9
+
10
+ local_supervisor:
11
+ port: 12112
12
+ ips: all
13
+ max_sites: 1
14
+ sites:
15
+ default:
16
+ intervals:
17
+ timer: 1
18
+ watchdog: 60
19
+ sxls:
20
+ tlc: '1.2.1'
21
+ timeouts:
22
+ watchdog: 30
23
+ acknowledgement: 5
24
+ connect: 30
25
+ ready: 1
26
+ status_response: 3
27
+ status_update: 2 # Without this subscription don't work: "It is not valid to set updateRate=0 and sendOnChange=false since it means that no subscription updates will be sent."
28
+ subscribe: 30
29
+ command: 300
30
+ command_response: 30
31
+ alarm: 3
32
+ disconnect: 20
33
+ startup_sequence: 100
34
+ functional_position: 60
35
+ priority_completion: 15
36
+ yellow_flash: 30
37
+ components:
38
+ main:
39
+ CZ+77000=101TC001:
40
+ signal_group:
41
+ CZ+77000=101SG001:
42
+ CZ+77000=101SG002:
43
+ CZ+77000=101SG003:
44
+ detector_logic:
45
+ CZ+77000=101DL001:
46
+ CZ+77000=101DL002:
47
+ CZ+77000=101DL003:
48
+ items:
49
+ plans: [1,2] #switching to each plan takes a lot of time
50
+ traffic_situations: [1,2,3]
51
+ emergency_routes: [1] # only one emergency route
52
+ inputs: [1,3,8]
53
+ outputs: [1,3,8]
54
+ startup_sequence: 'efg'
55
+ alarm_triggers:
56
+ A0302:
57
+ input: 1
58
+ component: CZ+77000=101DL001
59
+ secrets:
60
+ security_codes:
61
+ 1: '1111'
62
+ 2: 'r;PwL7%U?SN2E.5'
@@ -16,7 +16,7 @@ local_supervisor:
16
16
  timer: 1 # main validator timer resolution in seconds
17
17
  watchdog: 20 # send watchdog every x seconds
18
18
  sxls:
19
- tlc: '1.2.0'
19
+ tlc: '1.2.1'
20
20
  timeouts: # Timeouts used when waiting for messages from site.
21
21
  watchdog: 60
22
22
  acknowledgement: 55
@@ -5,8 +5,7 @@ compliance:
5
5
  id: swarco-itc3
6
6
  kind: site
7
7
  name: Swarco ITC-3
8
- product_url: https://www.swarco.com/products/traffic-light-controllers/itc-3-traffic-controller
9
-
8
+ product_url: https://www.swarco-its.com/products/roadside-systems/itc-controllers/itc-3-traffic-controller
10
9
  local_supervisor:
11
10
  ips: all
12
11
  max_sites: 1
@@ -16,7 +15,7 @@ local_supervisor:
16
15
  timer: 1 # main validator timer resolution in seconds
17
16
  watchdog: 20 # send watchdog every x seconds
18
17
  sxls:
19
- tlc: '1.0.15'
18
+ tlc: '1.2.1'
20
19
  timeouts: # Timeouts used when waiting for messages from site.
21
20
  watchdog: 60
22
21
  acknowledgement: 60
@@ -29,9 +28,9 @@ timeouts: # Timeouts used when waiting for messages from site.
29
28
  command_response: 60
30
29
  alarm: 60
31
30
  disconnect: 60
32
- shutdown: 60
33
31
  startup_sequence: 60
34
32
  functional_position: 60
33
+ priority_completion: 60
35
34
  yellow_flash: 60
36
35
  components:
37
36
  main:
data/config/validator.rb CHANGED
@@ -9,6 +9,7 @@ Sus::Base.include(RSMP::Validator::Log)
9
9
 
10
10
  # Include Connection helpers so with_site/with_supervisor are available in all tests
11
11
  Sus::Base.include(RSMP::Validator::Helpers::Connection)
12
+ Sus::Base.include(RSMP::Validator::Helpers::Expectations)
12
13
 
13
14
  # Include AsyncContext so all tests run inside the shared reactor
14
15
  Sus::Base.prepend(RSMP::Validator::AsyncContext)
@@ -6,10 +6,10 @@
6
6
  # But you can leave both, the unused key will just be ignored.
7
7
 
8
8
  # when testing a site, the config describes the local supervisor
9
- site: config/gem_tlc.yaml
9
+ site: config/sites/gem_tlc.yaml
10
10
 
11
11
  # when testing a supervisor, the config describes the local site
12
- supervisor: config/gem_supervisor.yaml
12
+ supervisor: config/supervisors/gem_supervisor.yaml
13
13
 
14
14
  # Optional: Auto Node Feature
15
15
  # Automatically start a local site/supervisor to test instead of an external one.
@@ -0,0 +1,37 @@
1
+ require 'rsmp'
2
+
3
+ module RSMP
4
+ module Validator
5
+ # Collect replayed updates and use the reconnect handshake to locate them on the site's clock.
6
+ class BufferReplayQueue < RSMP::Queue
7
+ def initialize(proxy, component:)
8
+ super(proxy, filter: RSMP::Filter.new(type: %w[Watchdog StatusUpdate], outgoing: false, component: component))
9
+ # The proxy installs this queue before sending Version. Receivers see the outbound
10
+ # Version only after the write, which is too late for a guaranteed lower bound.
11
+ @before_version_response = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+ end
13
+
14
+ def handle_message(message)
15
+ if message.is_a?(RSMP::Watchdog)
16
+ return if @watchdog_received_at
17
+
18
+ @watchdog_received_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
+ @watchdog_site_time = Time.iso8601(message.attribute('wTs'))
20
+ elsif message.is_a?(RSMP::StatusUpdate)
21
+ super
22
+ end
23
+ end
24
+
25
+ def site_time_window(offline, margin)
26
+ raise 'Missing site Watchdog from reconnect handshake' unless @watchdog_site_time
27
+
28
+ # The site sampled wTs after our Version response and before we received the Watchdog.
29
+ first = @watchdog_site_time - (@before_version_response - offline.begin) + margin
30
+ last = @watchdog_site_time - (@watchdog_received_at - offline.end) - margin
31
+ raise 'Reconnect handshake took too long to establish an offline timestamp window' unless first < last
32
+
33
+ first...last
34
+ end
35
+ end
36
+ end
37
+ end
@@ -6,26 +6,51 @@ module RSMP
6
6
  # CLI subcommands for validator configuration.
7
7
  class ConfigCLI < Thor
8
8
  namespace :config
9
- desc 'check PATH...', 'Validate rsmp-validator config files'
9
+ desc 'check PATH...', 'Validate config files or directories (recursively)'
10
10
  method_option :mode, type: :string, aliases: '-m', default: 'auto',
11
11
  enum: %w[auto site supervisor],
12
12
  banner: 'Validator config mode: auto, site or supervisor'
13
+ method_option :core, type: :string, desc: 'Override RSMP Core version for this check'
14
+ method_option :sxls, type: :string, desc: 'Override SXL versions as name:version,...'
13
15
  def check(*paths)
14
16
  if paths.empty?
15
17
  puts 'Error: config check requires at least one path'
16
18
  exit 1
17
19
  end
18
20
 
19
- valid = true
20
- paths.each do |path|
21
- RSMP::Validator::ConfigCheck.check_file(path, mode: options[:mode])
22
- puts 'OK'
23
- rescue RSMP::ConfigurationError => e
24
- valid = false
25
- puts "Error: #{e.message}"
21
+ results = paths.map { |path| check_path(path) }
22
+ exit 1 unless results.all?
23
+ end
24
+
25
+ private
26
+
27
+ def check_path(path)
28
+ results = config_files(path).map { |file| check_file(file) }
29
+ results.all?
30
+ rescue RSMP::ConfigurationError => e
31
+ puts "Error: #{path}: #{e.message}"
32
+ false
33
+ end
34
+
35
+ def config_files(path)
36
+ return [path] unless File.directory?(path)
37
+
38
+ files = Dir.glob(File.join(path, '**', '*')).select do |file|
39
+ File.file?(file) && %w[.yaml .yml].include?(File.extname(file).downcase) &&
40
+ !file.downcase.end_with?('_secrets.yaml', '_secrets.yml')
26
41
  end
42
+ raise RSMP::ConfigurationError, 'No test config files found' if files.empty?
43
+
44
+ files
45
+ end
27
46
 
28
- exit 1 unless valid
47
+ def check_file(path)
48
+ ConfigCheck.check_file(path, mode: options[:mode], core: options[:core], sxls: options[:sxls])
49
+ puts "OK: #{path}"
50
+ true
51
+ rescue RSMP::ConfigurationError => e
52
+ puts "Error: #{path}: #{e.message}"
53
+ false
29
54
  end
30
55
  end
31
56
  end
@@ -1,4 +1,8 @@
1
1
  require 'yaml'
2
+ require_relative 'options/site_test_options'
3
+ require_relative 'options/supervisor_test_options'
4
+ require_relative 'configuration/sxls_override'
5
+ require_relative 'configuration/test_requirements'
2
6
 
3
7
  module RSMP
4
8
  module Validator
@@ -7,16 +11,31 @@ module RSMP
7
11
  Result = Struct.new(:path, :mode, :options, keyword_init: true)
8
12
 
9
13
  class << self
10
- def check_file(path, mode: 'auto')
14
+ include Configuration::SxlsOverride
15
+
16
+ def check_file(path, mode: 'auto', core: nil, sxls: nil)
11
17
  raw = load_file(path)
12
18
  resolved_mode = resolve_mode(mode, raw)
13
- options = options_class_for(resolved_mode).new(config_settings(raw), log_settings: raw['log'])
19
+ options = build_options(raw, mode: resolved_mode, path: path, core: core, sxls: sxls)
14
20
 
15
21
  Result.new(path: path, mode: resolved_mode, options: options)
16
22
  end
17
23
 
24
+ def build_options(raw, mode:, path:, core: nil, sxls: nil)
25
+ settings = config_settings(raw)
26
+ settings['core_version'] = core if core
27
+ settings['sxls'] = parse_sxls(sxls) if sxls
28
+ options = options_class_for(mode.to_s).new(settings, source: path, log_settings: raw['log'])
29
+ Configuration::TestRequirements.new(options).validate!
30
+ options
31
+ end
32
+
18
33
  private
19
34
 
35
+ def abort_with_error(message)
36
+ raise RSMP::ConfigurationError, message
37
+ end
38
+
20
39
  def load_file(path)
21
40
  ensure_config_file!(path)
22
41
 
@@ -27,7 +27,7 @@ module RSMP
27
27
  return unless codes.is_a?(Hash)
28
28
 
29
29
  settings['security_codes'] = codes.each_with_object({}) do |(key, value), memo|
30
- int_key = key.is_a?(String) && key.match?(/^\d+$/) ? key.to_i : key
30
+ int_key = key.is_a?(String) && key.match?(/\A\d+\z/) ? key.to_i : key
31
31
  memo[int_key] = value
32
32
  end
33
33
  end
@@ -45,7 +45,7 @@ module RSMP
45
45
 
46
46
  def self.normalize_programming_keys(programming)
47
47
  programming.each_with_object({}) do |(key, value), memo|
48
- int_key = key.is_a?(String) && key.match?(/^\d+$/) ? key.to_i : key
48
+ int_key = key.is_a?(String) && key.match?(/\A\d+\z/) ? key.to_i : key
49
49
  memo[int_key] = value
50
50
  end
51
51
  end
@@ -83,6 +83,7 @@ module RSMP
83
83
  sxl = item.dup
84
84
  sxl.delete('name')
85
85
  version = sxl.delete('version')
86
+ version = sxl.delete('versions') || version
86
87
  sxl.delete('prefix')
87
88
  memo[name] = sxl.empty? ? version : sxl.merge('version' => version)
88
89
  end
@@ -6,8 +6,13 @@ module RSMP
6
6
  private
7
7
 
8
8
  def build_tester_options(raw_config, config_path)
9
- options_class = tester_options_class_for(raw_config)
10
- build_options_from_raw(raw_config, config_path, options_class)
9
+ ConfigCheck.build_options(
10
+ raw_config,
11
+ mode: mode, path: config_path,
12
+ core: core_version_override, sxls: sxls_override
13
+ )
14
+ rescue RSMP::ConfigurationError => e
15
+ abort_with_error e.message
11
16
  end
12
17
 
13
18
  def apply_loaded_config(options)
@@ -51,17 +56,6 @@ module RSMP
51
56
  abort_with_error e.message
52
57
  end
53
58
 
54
- def tester_options_class_for(_raw)
55
- case mode
56
- when :site
57
- RSMP::Validator::SiteTest::Options
58
- when :supervisor
59
- RSMP::Validator::SupervisorTest::Options
60
- else
61
- abort_with_error "Unknown test mode: #{mode}"
62
- end
63
- end
64
-
65
59
  def auto_node_options_class_for(raw)
66
60
  case mode
67
61
  when :site
@@ -12,7 +12,7 @@ module RSMP
12
12
  end
13
13
 
14
14
  def load_secrets_file(config_path)
15
- basename = File.basename(config_path, '.yaml')
15
+ basename = File.basename(config_path, File.extname(config_path))
16
16
  folder = File.dirname(config_path)
17
17
  secrets_path = File.join(folder, "#{basename}_secrets.yaml")
18
18
  return unless File.exist?(secrets_path)
@@ -23,11 +23,13 @@ module RSMP
23
23
  end
24
24
 
25
25
  def normalize_security_codes!
26
+ return unless config['secrets'].is_a?(Hash)
27
+
26
28
  codes = config.dig('secrets', 'security_codes')
27
29
  return unless codes.is_a?(Hash)
28
30
 
29
31
  normalized = codes.each_with_object({}) do |(key, value), memo|
30
- int_key = key.is_a?(String) && key.match?(/^\d+$/) ? key.to_i : key
32
+ int_key = key.is_a?(String) && key.match?(/\A\d+\z/) ? key.to_i : key
31
33
  memo[int_key] = value
32
34
  end
33
35
 
@@ -35,7 +37,9 @@ module RSMP
35
37
  end
36
38
 
37
39
  def warn_missing_security_codes
38
- return warn_no_security_code unless config.dig('secrets', 'security_codes')
40
+ return unless config['secrets'].nil? || config['secrets'].is_a?(Hash)
41
+
42
+ return warn_no_security_code unless config.dig('secrets', 'security_codes').is_a?(Hash)
39
43
 
40
44
  warn_security_code_not_configured(1) unless config.dig('secrets', 'security_codes', 1)
41
45
  warn_security_code_not_configured(2) unless config.dig('secrets', 'security_codes', 2)
@@ -4,6 +4,7 @@ module RSMP
4
4
  # Parses CLI SXL overrides.
5
5
  module SxlsOverride
6
6
  def apply_auto_node_overrides!(raw_config)
7
+ raw_config['core_version'] = core_version_override if mode == :site && core_version_override
7
8
  apply_auto_node_sxls_override!(raw_config) if sxls_override
8
9
  end
9
10
 
@@ -14,14 +15,28 @@ module RSMP
14
15
  raw_config['sites']['default'] ||= {}
15
16
  raw_config['sites']['default']['sxls'] = sxls
16
17
  else
17
- raw_config['sxls'] = sxls
18
+ raw_config['sxls'] = auto_site_sxls(sxls, raw_config['sxls'])
19
+ end
20
+ end
21
+
22
+ # An explicit list opts the auto site into hint testing. Keep its initial
23
+ # version and allowed alternatives while the tester requests one version.
24
+ def auto_site_sxls(overrides, configured)
25
+ return overrides unless configured.is_a?(Hash)
26
+
27
+ overrides.to_h do |name, version|
28
+ [name, configured[name].is_a?(Array) ? configured[name] : version]
18
29
  end
19
30
  end
20
31
 
21
32
  def parse_sxls(value)
22
- value.split(',').each_with_object({}) do |item, memo|
23
- parts = item.split(':')
24
- abort_with_error "Invalid --sxls item #{item.inspect}, expected name:version" unless parts.length == 2
33
+ abort_with_error 'Invalid --sxls value, expected name:version,...' if value.empty?
34
+
35
+ value.split(',', -1).each_with_object({}) do |item, memo|
36
+ parts = item.split(':', -1)
37
+ unless parts.length == 2 && parts.none?(&:empty?)
38
+ abort_with_error "Invalid --sxls item #{item.inspect}, expected name:version"
39
+ end
25
40
 
26
41
  name, version = parts
27
42
  memo[name] = version
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require_relative 'version_normalization'
3
+ require_relative 'secrets'
4
+
5
+ module RSMP
6
+ module Validator
7
+ module Configuration
8
+ # Validates the complete test configuration for each selected protocol version.
9
+ class TestRequirements
10
+ include VersionNormalization
11
+ include Secrets
12
+
13
+ SCHEMA_ROOT = File.expand_path('../../../../schemas/test_config', __dir__)
14
+
15
+ attr_reader :config
16
+
17
+ def initialize(options)
18
+ @options = options
19
+ @config = options.to_h
20
+ end
21
+
22
+ def validate!
23
+ normalize_core_version!
24
+ normalize_sxls!
25
+ load_secrets_file(@options.source) if @options.source && !config['secrets']
26
+
27
+ validate_versions!
28
+ normalize_security_codes!
29
+ end
30
+
31
+ private
32
+
33
+ def validate_versions!
34
+ versions = JSON.parse(File.read(File.join(SCHEMA_ROOT, 'versions.json')))
35
+ validate_version!(versions, 'core', config['core_version'])
36
+ config['sxls'].each do |sxl|
37
+ validate_version!(versions, sxl['name'], sxl['version'])
38
+ end
39
+ end
40
+
41
+ def validate_version!(versions, name, version)
42
+ # SXLs without a conformance suite have no additional test settings.
43
+ return unless versions.key?(name)
44
+
45
+ schema = versions.fetch(name)[version]
46
+ abort_with_error "No test configuration schema for #{name} #{version}" unless schema
47
+
48
+ path = File.join(SCHEMA_ROOT, schema)
49
+ abort_with_error "Missing test configuration schema: #{path}" unless File.file?(path)
50
+
51
+ # YAML security-code keys may be integers; JSON Schema uses string keys.
52
+ @options.validate!(JSON.parse(JSON.generate(config)), path: path)
53
+ rescue RSMP::ConfigurationError => e
54
+ raise RSMP::ConfigurationError, "#{name} #{version}: #{e.message}"
55
+ end
56
+
57
+ def abort_with_error(message)
58
+ raise RSMP::ConfigurationError, message
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -2,8 +2,8 @@ module RSMP
2
2
  module Validator
3
3
  module Configuration
4
4
  # Canonicalizes the versions used by filters and compliance metadata.
5
- # Embedded RSMP nodes retain configured legacy spellings for wire
6
- # compatibility; the rsmp gem normalizes them only for schema lookup.
5
+ # Embedded RSMP nodes retain configured legacy Core spellings for wire
6
+ # compatibility. Configured SXL versions always use MAJOR.MINOR.PATCH.
7
7
  module VersionNormalization
8
8
  private
9
9
 
@@ -20,6 +20,8 @@ module RSMP
20
20
  return normalized.to_s if normalized
21
21
 
22
22
  abort_with_error "Unknown core version #{core_version}, must be one of [#{known_versions.join(', ')}]."
23
+ rescue ArgumentError
24
+ abort_with_error "Invalid core version #{core_version.inspect}"
23
25
  end
24
26
 
25
27
  def normalized_core_version(core_version, known_versions)
@@ -44,9 +46,12 @@ module RSMP
44
46
  end
45
47
 
46
48
  def canonical_sxl_version(name, version)
47
- normalized = RSMP::Schema.sanitize_version(version.to_s)
48
- RSMP::Schema.find_schema! name, normalized
49
- normalized
49
+ version = RSMP::Schema.latest_version(name) if version == 'latest'
50
+ unless RSMP::Schema.strict_version?(version)
51
+ abort_with_error "Invalid SXL version #{name} #{version.inspect}: must use MAJOR.MINOR.PATCH"
52
+ end
53
+ RSMP::Schema.find_schema! name, version
54
+ version
50
55
  rescue RSMP::Schema::UnknownSchemaError => e
51
56
  abort_with_error "Unknown SXL #{name} #{version}: #{e}"
52
57
  end
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require_relative 'missing_configuration'
2
3
  require_relative 'configuration/loader'
3
4
  require_relative 'configuration/validation'
4
5
  require_relative 'configuration/version_normalization'
@@ -23,23 +24,15 @@ module RSMP
23
24
  missing_message: "#{mode.capitalize} config file #{config_path} is missing"
24
25
  )
25
26
 
26
- apply_cli_overrides!(raw_config)
27
27
  options = build_tester_options(raw_config, config_path)
28
28
  apply_loaded_config(options)
29
29
  validate_and_finalize_config!(config_path)
30
30
  end
31
31
 
32
- def apply_cli_overrides!(raw_config)
33
- raw_config['core_version'] = core_version_override if core_version_override
34
- raw_config['sxls'] = parse_sxls(sxls_override) if sxls_override
35
- end
36
-
37
32
  def validate_and_finalize_config!(config_path)
38
33
  validate_mode_config!(config_path)
39
34
  validate_components_config!
40
35
  validate_timeouts_config!
41
- normalize_core_version!
42
- normalize_sxls!
43
36
  load_secrets config_path
44
37
  end
45
38
 
@@ -96,7 +89,7 @@ module RSMP
96
89
  elsif assume
97
90
  assume
98
91
  else
99
- raise "Config #{path_name} is missing"
92
+ raise MissingConfiguration, path
100
93
  end
101
94
  end
102
95
 
@@ -29,7 +29,7 @@ module RSMP
29
29
  yield collect_task.wait, component_id
30
30
 
31
31
  matcher = { 'cId' => component_id, 'aCId' => alarm_code_id,
32
- 'aSp' => /Issue/i, 'aS' => alarm_inactive }
32
+ 'aSp' => /\AIssue\z/i, 'aS' => alarm_inactive }
33
33
  collect_task = start_alarm_collector(site_proxy, matcher, alarm_timeout)
34
34
  force_input_and_confirm site_proxy, input:, value: 'False', within: status_timeout
35
35
  state = false
@@ -41,9 +41,9 @@ module RSMP
41
41
 
42
42
  def build_alarm_matchers(site_proxy)
43
43
  if RSMP::Proxy.version_meets_requirement? site_proxy.core_version, '>=3.2.0'
44
- [/Issue/, /Active/, /inActive/]
44
+ [/\AIssue\z/, /\AActive\z/, /\AinActive\z/]
45
45
  else
46
- [/issue/i, /active/i, /inactive/i]
46
+ [/\Aissue\z/i, /\Aactive\z/i, /\Ainactive\z/i]
47
47
  end
48
48
  end
49
49