lex-agentic-self 0.1.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 +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-self.gemspec +31 -0
- data/lib/legion/extensions/agentic/self/agency/client.rb +21 -0
- data/lib/legion/extensions/agentic/self/agency/helpers/constants.rb +77 -0
- data/lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb +136 -0
- data/lib/legion/extensions/agentic/self/agency/helpers/outcome_event.rb +52 -0
- data/lib/legion/extensions/agentic/self/agency/runners/agency.rb +117 -0
- data/lib/legion/extensions/agentic/self/agency/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/agency.rb +19 -0
- data/lib/legion/extensions/agentic/self/anchor/client.rb +15 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb +92 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/anchor_engine.rb +123 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/chain.rb +93 -0
- data/lib/legion/extensions/agentic/self/anchor/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/self/anchor/runners/cognitive_anchor.rb +70 -0
- data/lib/legion/extensions/agentic/self/anchor/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/anchor.rb +22 -0
- data/lib/legion/extensions/agentic/self/anosognosia/client.rb +28 -0
- data/lib/legion/extensions/agentic/self/anosognosia/helpers/anosognosia_engine.rb +153 -0
- data/lib/legion/extensions/agentic/self/anosognosia/helpers/cognitive_deficit.rb +71 -0
- data/lib/legion/extensions/agentic/self/anosognosia/helpers/constants.rb +29 -0
- data/lib/legion/extensions/agentic/self/anosognosia/runners/anosognosia.rb +98 -0
- data/lib/legion/extensions/agentic/self/anosognosia/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/anosognosia.rb +19 -0
- data/lib/legion/extensions/agentic/self/architecture/client.rb +19 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/architecture_engine.rb +167 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/connection.rb +57 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb +80 -0
- data/lib/legion/extensions/agentic/self/architecture/runners/cognitive_architecture.rb +125 -0
- data/lib/legion/extensions/agentic/self/architecture/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/architecture.rb +20 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/actors/idle.rb +45 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/client.rb +28 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/helpers/constants.rb +53 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/helpers/dmn_engine.rb +221 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/helpers/wandering_thought.rb +60 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network.rb +122 -0
- data/lib/legion/extensions/agentic/self/default_mode_network/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/default_mode_network.rb +20 -0
- data/lib/legion/extensions/agentic/self/fingerprint/client.rb +28 -0
- data/lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb +73 -0
- data/lib/legion/extensions/agentic/self/fingerprint/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/self/fingerprint/helpers/fingerprint_engine.rb +169 -0
- data/lib/legion/extensions/agentic/self/fingerprint/runners/cognitive_fingerprint.rb +86 -0
- data/lib/legion/extensions/agentic/self/fingerprint/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/fingerprint.rb +19 -0
- data/lib/legion/extensions/agentic/self/identity/actors/credential_refresh.rb +49 -0
- data/lib/legion/extensions/agentic/self/identity/actors/orphan_check.rb +52 -0
- data/lib/legion/extensions/agentic/self/identity/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/dimensions.rb +75 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/fingerprint.rb +170 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/graph_client.rb +29 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/graph_token.rb +36 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/token_cache.rb +59 -0
- data/lib/legion/extensions/agentic/self/identity/helpers/vault_secrets.rb +80 -0
- data/lib/legion/extensions/agentic/self/identity/local_migrations/20260316000030_create_fingerprint.rb +20 -0
- data/lib/legion/extensions/agentic/self/identity/runners/entra.rb +402 -0
- data/lib/legion/extensions/agentic/self/identity/runners/identity.rb +90 -0
- data/lib/legion/extensions/agentic/self/identity/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/identity.rb +28 -0
- data/lib/legion/extensions/agentic/self/metacognition/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/constants.rb +377 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/narrator_bridge.rb +85 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/registry_store.rb +70 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/self_model.rb +160 -0
- data/lib/legion/extensions/agentic/self/metacognition/helpers/snapshot_store.rb +82 -0
- data/lib/legion/extensions/agentic/self/metacognition/runners/metacognition.rb +116 -0
- data/lib/legion/extensions/agentic/self/metacognition/runners/registry.rb +180 -0
- data/lib/legion/extensions/agentic/self/metacognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/metacognition.rb +22 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/client.rb +25 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/calibration_tracker.rb +96 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_engine.rb +141 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_judgment.rb +79 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/runners/metacognitive_monitoring.rb +151 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/metacognitive_monitoring.rb +20 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/client.rb +29 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/arc.rb +137 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/arc_engine.rb +119 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/beat_event.rb +59 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/helpers/constants.rb +66 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/runners/narrative.rb +101 -0
- data/lib/legion/extensions/agentic/self/narrative_arc/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/narrative_arc.rb +20 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/actors/narrative_decay.rb +45 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/client.rb +22 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/chapter.rb +48 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/constants.rb +62 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/episode.rb +67 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/narrative_engine.rb +187 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/helpers/theme.rb +50 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity.rb +158 -0
- data/lib/legion/extensions/agentic/self/narrative_identity/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/narrative_identity.rb +21 -0
- data/lib/legion/extensions/agentic/self/narrative_self/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/autobiography.rb +187 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/episode.rb +81 -0
- data/lib/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread.rb +65 -0
- data/lib/legion/extensions/agentic/self/narrative_self/runners/narrative_self.rb +86 -0
- data/lib/legion/extensions/agentic/self/narrative_self/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/narrative_self.rb +20 -0
- data/lib/legion/extensions/agentic/self/personality/client.rb +21 -0
- data/lib/legion/extensions/agentic/self/personality/helpers/constants.rb +84 -0
- data/lib/legion/extensions/agentic/self/personality/helpers/personality_store.rb +126 -0
- data/lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb +147 -0
- data/lib/legion/extensions/agentic/self/personality/runners/personality.rb +102 -0
- data/lib/legion/extensions/agentic/self/personality/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/personality.rb +19 -0
- data/lib/legion/extensions/agentic/self/reflection/client.rb +27 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/constants.rb +66 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/llm_enhancer.rb +166 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/monitors.rb +186 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/reflection.rb +54 -0
- data/lib/legion/extensions/agentic/self/reflection/helpers/reflection_store.rb +99 -0
- data/lib/legion/extensions/agentic/self/reflection/runners/reflection.rb +199 -0
- data/lib/legion/extensions/agentic/self/reflection/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/reflection.rb +21 -0
- data/lib/legion/extensions/agentic/self/self_model/client.rb +19 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/capability.rb +93 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/knowledge_domain.rb +82 -0
- data/lib/legion/extensions/agentic/self/self_model/helpers/self_model.rb +150 -0
- data/lib/legion/extensions/agentic/self/self_model/runners/self_model.rb +82 -0
- data/lib/legion/extensions/agentic/self/self_model/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/self_model.rb +21 -0
- data/lib/legion/extensions/agentic/self/self_talk/actors/volume_decay.rb +45 -0
- data/lib/legion/extensions/agentic/self/self_talk/client.rb +30 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/constants.rb +63 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb +114 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/dialogue_turn.rb +43 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/inner_voice.rb +77 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/llm_enhancer.rb +135 -0
- data/lib/legion/extensions/agentic/self/self_talk/helpers/self_talk_engine.rb +160 -0
- data/lib/legion/extensions/agentic/self/self_talk/runners/self_talk.rb +172 -0
- data/lib/legion/extensions/agentic/self/self_talk/version.rb +13 -0
- data/lib/legion/extensions/agentic/self/self_talk.rb +22 -0
- data/lib/legion/extensions/agentic/self/version.rb +11 -0
- data/lib/legion/extensions/agentic/self.rb +33 -0
- data/spec/legion/extensions/agentic/self/agency/client_spec.rb +67 -0
- data/spec/legion/extensions/agentic/self/agency/helpers/constants_spec.rb +73 -0
- data/spec/legion/extensions/agentic/self/agency/helpers/efficacy_model_spec.rb +190 -0
- data/spec/legion/extensions/agentic/self/agency/helpers/outcome_event_spec.rb +85 -0
- data/spec/legion/extensions/agentic/self/agency/runners/agency_spec.rb +132 -0
- data/spec/legion/extensions/agentic/self/anchor/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/anchor_engine_spec.rb +109 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/anchor_spec.rb +124 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/chain_spec.rb +106 -0
- data/spec/legion/extensions/agentic/self/anchor/helpers/constants_spec.rb +53 -0
- data/spec/legion/extensions/agentic/self/anchor/runners/cognitive_anchor_spec.rb +70 -0
- data/spec/legion/extensions/agentic/self/anosognosia/anosognosia_spec.rb +15 -0
- data/spec/legion/extensions/agentic/self/anosognosia/client_spec.rb +50 -0
- data/spec/legion/extensions/agentic/self/anosognosia/helpers/anosognosia_engine_spec.rb +266 -0
- data/spec/legion/extensions/agentic/self/anosognosia/helpers/cognitive_deficit_spec.rb +150 -0
- data/spec/legion/extensions/agentic/self/anosognosia/helpers/constants_spec.rb +58 -0
- data/spec/legion/extensions/agentic/self/anosognosia/runners/anosognosia_spec.rb +225 -0
- data/spec/legion/extensions/agentic/self/architecture/client_spec.rb +51 -0
- data/spec/legion/extensions/agentic/self/architecture/helpers/architecture_engine_spec.rb +321 -0
- data/spec/legion/extensions/agentic/self/architecture/helpers/connection_spec.rb +118 -0
- data/spec/legion/extensions/agentic/self/architecture/helpers/subsystem_spec.rb +189 -0
- data/spec/legion/extensions/agentic/self/architecture/runners/cognitive_architecture_spec.rb +181 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/client_spec.rb +69 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/helpers/constants_spec.rb +76 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/helpers/dmn_engine_spec.rb +321 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/helpers/wandering_thought_spec.rb +145 -0
- data/spec/legion/extensions/agentic/self/default_mode_network/runners/default_mode_network_spec.rb +269 -0
- data/spec/legion/extensions/agentic/self/fingerprint/client_spec.rb +54 -0
- data/spec/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait_spec.rb +180 -0
- data/spec/legion/extensions/agentic/self/fingerprint/helpers/constants_spec.rb +108 -0
- data/spec/legion/extensions/agentic/self/fingerprint/helpers/fingerprint_engine_spec.rb +318 -0
- data/spec/legion/extensions/agentic/self/fingerprint/runners/cognitive_fingerprint_spec.rb +232 -0
- data/spec/legion/extensions/agentic/self/identity/actors/orphan_check_spec.rb +104 -0
- data/spec/legion/extensions/agentic/self/identity/client_spec.rb +32 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/dimensions_spec.rb +51 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/fingerprint_spec.rb +66 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/graph_client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/graph_token_spec.rb +31 -0
- data/spec/legion/extensions/agentic/self/identity/helpers/token_cache_spec.rb +50 -0
- data/spec/legion/extensions/agentic/self/identity/local_persistence_spec.rb +329 -0
- data/spec/legion/extensions/agentic/self/identity/runners/entra_spec.rb +655 -0
- data/spec/legion/extensions/agentic/self/identity/runners/identity_spec.rb +61 -0
- data/spec/legion/extensions/agentic/self/metacognition/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/constants_spec.rb +31 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/narrator_bridge_spec.rb +102 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/registry_store_spec.rb +227 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/self_model_spec.rb +117 -0
- data/spec/legion/extensions/agentic/self/metacognition/helpers/snapshot_store_spec.rb +128 -0
- data/spec/legion/extensions/agentic/self/metacognition/runners/metacognition_spec.rb +110 -0
- data/spec/legion/extensions/agentic/self/metacognition/runners/registry_spec.rb +281 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/client_spec.rb +59 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/calibration_tracker_spec.rb +143 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/constants_spec.rb +91 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_engine_spec.rb +198 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/helpers/monitoring_judgment_spec.rb +172 -0
- data/spec/legion/extensions/agentic/self/metacognitive_monitoring/runners/metacognitive_monitoring_spec.rb +244 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/client_spec.rb +22 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/arc_engine_spec.rb +183 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/arc_spec.rb +177 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/beat_event_spec.rb +96 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/helpers/constants_spec.rb +75 -0
- data/spec/legion/extensions/agentic/self/narrative_arc/runners/narrative_spec.rb +142 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/client_spec.rb +69 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/chapter_spec.rb +85 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/constants_spec.rb +83 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/episode_spec.rb +180 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/narrative_engine_spec.rb +307 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/helpers/theme_spec.rb +107 -0
- data/spec/legion/extensions/agentic/self/narrative_identity/runners/narrative_identity_spec.rb +240 -0
- data/spec/legion/extensions/agentic/self/narrative_self/client_spec.rb +67 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/autobiography_spec.rb +155 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/constants_spec.rb +28 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/episode_spec.rb +144 -0
- data/spec/legion/extensions/agentic/self/narrative_self/helpers/narrative_thread_spec.rb +87 -0
- data/spec/legion/extensions/agentic/self/narrative_self/runners/narrative_self_spec.rb +118 -0
- data/spec/legion/extensions/agentic/self/personality/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/self/personality/helpers/constants_spec.rb +41 -0
- data/spec/legion/extensions/agentic/self/personality/helpers/personality_store_spec.rb +66 -0
- data/spec/legion/extensions/agentic/self/personality/helpers/trait_model_spec.rb +148 -0
- data/spec/legion/extensions/agentic/self/personality/runners/personality_spec.rb +67 -0
- data/spec/legion/extensions/agentic/self/reflection/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/llm_enhancer_spec.rb +191 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/monitors_spec.rb +120 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/reflection_spec.rb +49 -0
- data/spec/legion/extensions/agentic/self/reflection/helpers/reflection_store_spec.rb +93 -0
- data/spec/legion/extensions/agentic/self/reflection/runners/reflection_spec.rb +204 -0
- data/spec/legion/extensions/agentic/self/self_model/client_spec.rb +55 -0
- data/spec/legion/extensions/agentic/self/self_model/helpers/capability_spec.rb +160 -0
- data/spec/legion/extensions/agentic/self/self_model/helpers/knowledge_domain_spec.rb +128 -0
- data/spec/legion/extensions/agentic/self/self_model/helpers/self_model_spec.rb +238 -0
- data/spec/legion/extensions/agentic/self/self_model/runners/self_model_spec.rb +143 -0
- data/spec/legion/extensions/agentic/self/self_talk/actors/volume_decay_spec.rb +46 -0
- data/spec/legion/extensions/agentic/self/self_talk/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/constants_spec.rb +110 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/dialogue_spec.rb +191 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/dialogue_turn_spec.rb +78 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/inner_voice_spec.rb +172 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/llm_enhancer_spec.rb +206 -0
- data/spec/legion/extensions/agentic/self/self_talk/helpers/self_talk_engine_spec.rb +239 -0
- data/spec/legion/extensions/agentic/self/self_talk/runners/self_talk_llm_spec.rb +169 -0
- data/spec/legion/extensions/agentic/self/self_talk/runners/self_talk_spec.rb +196 -0
- data/spec/spec_helper.rb +46 -0
- metadata +347 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Self::Architecture::Helpers::ArchitectureEngine do
|
|
4
|
+
subject(:engine) { described_class.new }
|
|
5
|
+
|
|
6
|
+
let(:constants) { Legion::Extensions::Agentic::Self::Architecture::Helpers::Constants }
|
|
7
|
+
|
|
8
|
+
def register_pair
|
|
9
|
+
engine.register_subsystem(name: :source, subsystem_type: :cognition)
|
|
10
|
+
engine.register_subsystem(name: :target, subsystem_type: :memory)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#register_subsystem' do
|
|
14
|
+
it 'returns a Subsystem instance' do
|
|
15
|
+
result = engine.register_subsystem(name: :cognition_hub, subsystem_type: :cognition)
|
|
16
|
+
expect(result).to be_a(Legion::Extensions::Agentic::Self::Architecture::Helpers::Subsystem)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'stores the subsystem by name' do
|
|
20
|
+
engine.register_subsystem(name: :my_sub, subsystem_type: :memory)
|
|
21
|
+
expect(engine.active_subsystems.map(&:name)).to include(:my_sub)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'raises on duplicate name' do
|
|
25
|
+
engine.register_subsystem(name: :dup, subsystem_type: :cognition)
|
|
26
|
+
expect { engine.register_subsystem(name: :dup, subsystem_type: :memory) }
|
|
27
|
+
.to raise_error(ArgumentError, /already registered/)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'accepts custom health' do
|
|
31
|
+
sub = engine.register_subsystem(name: :custom, subsystem_type: :safety, health: 0.5)
|
|
32
|
+
expect(sub.health).to eq(0.5)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#create_connection' do
|
|
37
|
+
before { register_pair }
|
|
38
|
+
|
|
39
|
+
it 'returns a Connection instance' do
|
|
40
|
+
conn = engine.create_connection(source_name: :source, target_name: :target)
|
|
41
|
+
expect(conn).to be_a(Legion::Extensions::Agentic::Self::Architecture::Helpers::Connection)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'links source and target by id' do
|
|
45
|
+
source_id = engine.subsystem_status(name: :source)[:id]
|
|
46
|
+
target_id = engine.subsystem_status(name: :target)[:id]
|
|
47
|
+
conn = engine.create_connection(source_name: :source, target_name: :target)
|
|
48
|
+
expect(conn.source_id).to eq(source_id)
|
|
49
|
+
expect(conn.target_id).to eq(target_id)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'raises when source does not exist' do
|
|
53
|
+
expect { engine.create_connection(source_name: :ghost, target_name: :target) }
|
|
54
|
+
.to raise_error(ArgumentError, /not found/)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'accepts custom connection_type and weight' do
|
|
58
|
+
conn = engine.create_connection(
|
|
59
|
+
source_name: :source, target_name: :target, connection_type: :excitatory, weight: 0.9
|
|
60
|
+
)
|
|
61
|
+
expect(conn.connection_type).to eq(:excitatory)
|
|
62
|
+
expect(conn.weight).to eq(0.9)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe '#activate_subsystem' do
|
|
67
|
+
before { register_pair }
|
|
68
|
+
|
|
69
|
+
it 'returns a result hash' do
|
|
70
|
+
result = engine.activate_subsystem(name: :source)
|
|
71
|
+
expect(result).to include(:name, :status, :health)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'increments activation_count on the subsystem' do
|
|
75
|
+
engine.activate_subsystem(name: :source)
|
|
76
|
+
status = engine.subsystem_status(name: :source)
|
|
77
|
+
expect(status[:activation_count]).to eq(1)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'propagates activation to excitatory neighbors' do
|
|
81
|
+
engine.create_connection(source_name: :source, target_name: :target, connection_type: :excitatory)
|
|
82
|
+
engine.activate_subsystem(name: :source)
|
|
83
|
+
target_status = engine.subsystem_status(name: :target)
|
|
84
|
+
expect(target_status[:activation_count]).to eq(1)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'does not propagate for non-excitatory connections' do
|
|
88
|
+
engine.create_connection(source_name: :source, target_name: :target, connection_type: :inhibitory)
|
|
89
|
+
engine.activate_subsystem(name: :source)
|
|
90
|
+
target_status = engine.subsystem_status(name: :target)
|
|
91
|
+
expect(target_status[:activation_count]).to eq(0)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'does not propagate via inactive connections' do
|
|
95
|
+
conn = engine.create_connection(source_name: :source, target_name: :target, connection_type: :excitatory)
|
|
96
|
+
conn.toggle!
|
|
97
|
+
engine.activate_subsystem(name: :source)
|
|
98
|
+
target_status = engine.subsystem_status(name: :target)
|
|
99
|
+
expect(target_status[:activation_count]).to eq(0)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'raises for unknown subsystem' do
|
|
103
|
+
expect { engine.activate_subsystem(name: :unknown) }.to raise_error(ArgumentError)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe '#degrade_subsystem' do
|
|
108
|
+
before { engine.register_subsystem(name: :deg_sub, subsystem_type: :cognition) }
|
|
109
|
+
|
|
110
|
+
it 'reduces health' do
|
|
111
|
+
original = engine.subsystem_status(name: :deg_sub)[:health]
|
|
112
|
+
engine.degrade_subsystem(name: :deg_sub)
|
|
113
|
+
expect(engine.subsystem_status(name: :deg_sub)[:health]).to be < original
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'returns a hash with name and health' do
|
|
117
|
+
result = engine.degrade_subsystem(name: :deg_sub)
|
|
118
|
+
expect(result).to include(:name, :health, :status)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe '#recover_subsystem' do
|
|
123
|
+
before do
|
|
124
|
+
engine.register_subsystem(name: :rec_sub, subsystem_type: :cognition)
|
|
125
|
+
engine.degrade_subsystem(name: :rec_sub)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'increases health' do
|
|
129
|
+
before_health = engine.subsystem_status(name: :rec_sub)[:health]
|
|
130
|
+
engine.recover_subsystem(name: :rec_sub)
|
|
131
|
+
expect(engine.subsystem_status(name: :rec_sub)[:health]).to be > before_health
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
describe '#subsystem_status' do
|
|
136
|
+
before { engine.register_subsystem(name: :status_sub, subsystem_type: :introspection) }
|
|
137
|
+
|
|
138
|
+
it 'returns a full status hash' do
|
|
139
|
+
h = engine.subsystem_status(name: :status_sub)
|
|
140
|
+
expect(h[:name]).to eq(:status_sub)
|
|
141
|
+
expect(h[:subsystem_type]).to eq(:introspection)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'raises for unknown subsystem' do
|
|
145
|
+
expect { engine.subsystem_status(name: :nope) }.to raise_error(ArgumentError)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe '#active_subsystems' do
|
|
150
|
+
it 'returns only active subsystems' do
|
|
151
|
+
engine.register_subsystem(name: :active_one, subsystem_type: :cognition)
|
|
152
|
+
engine.register_subsystem(name: :inactive_one, subsystem_type: :memory)
|
|
153
|
+
engine.degrade_subsystem(name: :inactive_one)
|
|
154
|
+
engine.degrade_subsystem(name: :inactive_one)
|
|
155
|
+
engine.degrade_subsystem(name: :inactive_one)
|
|
156
|
+
engine.degrade_subsystem(name: :inactive_one)
|
|
157
|
+
engine.degrade_subsystem(name: :inactive_one)
|
|
158
|
+
|
|
159
|
+
names = engine.active_subsystems.map(&:name)
|
|
160
|
+
expect(names).to include(:active_one)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'returns empty array when no subsystems' do
|
|
164
|
+
expect(engine.active_subsystems).to be_empty
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
describe '#bottlenecked_subsystems' do
|
|
169
|
+
it 'returns subsystems that are bottlenecked' do
|
|
170
|
+
engine.register_subsystem(name: :bottleneck, subsystem_type: :communication)
|
|
171
|
+
sub = engine.active_subsystems.find { |s| s.name == :bottleneck }
|
|
172
|
+
sub.load = 0.5
|
|
173
|
+
sub.health = 0.3
|
|
174
|
+
|
|
175
|
+
result = engine.bottlenecked_subsystems
|
|
176
|
+
expect(result.map(&:name)).to include(:bottleneck)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'excludes healthy subsystems' do
|
|
180
|
+
engine.register_subsystem(name: :healthy, subsystem_type: :cognition)
|
|
181
|
+
expect(engine.bottlenecked_subsystems).to be_empty
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe '#connections_for' do
|
|
186
|
+
before { register_pair }
|
|
187
|
+
|
|
188
|
+
it 'returns connections involving the subsystem' do
|
|
189
|
+
engine.create_connection(source_name: :source, target_name: :target)
|
|
190
|
+
conns = engine.connections_for(name: :source)
|
|
191
|
+
expect(conns).not_to be_empty
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it 'includes connections where subsystem is the target' do
|
|
195
|
+
engine.create_connection(source_name: :source, target_name: :target)
|
|
196
|
+
conns = engine.connections_for(name: :target)
|
|
197
|
+
expect(conns).not_to be_empty
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it 'returns empty when no connections' do
|
|
201
|
+
engine.register_subsystem(name: :isolated, subsystem_type: :safety)
|
|
202
|
+
expect(engine.connections_for(name: :isolated)).to be_empty
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
describe '#downstream' do
|
|
207
|
+
before do
|
|
208
|
+
engine.register_subsystem(name: :a, subsystem_type: :cognition)
|
|
209
|
+
engine.register_subsystem(name: :b, subsystem_type: :memory)
|
|
210
|
+
engine.register_subsystem(name: :c, subsystem_type: :motivation)
|
|
211
|
+
engine.register_subsystem(name: :d, subsystem_type: :safety)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'returns direct downstream neighbors' do
|
|
215
|
+
engine.create_connection(source_name: :a, target_name: :b)
|
|
216
|
+
result = engine.downstream(name: :a)
|
|
217
|
+
expect(result.map(&:name)).to include(:b)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it 'traverses multi-hop paths' do
|
|
221
|
+
engine.create_connection(source_name: :a, target_name: :b)
|
|
222
|
+
engine.create_connection(source_name: :b, target_name: :c)
|
|
223
|
+
result = engine.downstream(name: :a)
|
|
224
|
+
names = result.map(&:name)
|
|
225
|
+
expect(names).to include(:b, :c)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it 'does not include the source subsystem itself' do
|
|
229
|
+
engine.create_connection(source_name: :a, target_name: :b)
|
|
230
|
+
result = engine.downstream(name: :a)
|
|
231
|
+
expect(result.map(&:name)).not_to include(:a)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it 'respects max_depth limit' do
|
|
235
|
+
engine.create_connection(source_name: :a, target_name: :b)
|
|
236
|
+
engine.create_connection(source_name: :b, target_name: :c)
|
|
237
|
+
engine.create_connection(source_name: :c, target_name: :d)
|
|
238
|
+
result = engine.downstream(name: :a, max_depth: 1)
|
|
239
|
+
expect(result.map(&:name)).to include(:b)
|
|
240
|
+
expect(result.map(&:name)).not_to include(:c)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'handles cycles without infinite loop' do
|
|
244
|
+
engine.create_connection(source_name: :a, target_name: :b)
|
|
245
|
+
engine.create_connection(source_name: :b, target_name: :a)
|
|
246
|
+
expect { engine.downstream(name: :a) }.not_to raise_error
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it 'skips inactive connections' do
|
|
250
|
+
conn = engine.create_connection(source_name: :a, target_name: :b)
|
|
251
|
+
conn.toggle!
|
|
252
|
+
result = engine.downstream(name: :a)
|
|
253
|
+
expect(result.map(&:name)).not_to include(:b)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe '#architecture_health' do
|
|
258
|
+
it 'returns 0.0 when no subsystems' do
|
|
259
|
+
expect(engine.architecture_health).to eq(0.0)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
it 'returns average health across all subsystems' do
|
|
263
|
+
engine.register_subsystem(name: :s1, subsystem_type: :cognition, health: 1.0)
|
|
264
|
+
engine.register_subsystem(name: :s2, subsystem_type: :memory, health: 0.5)
|
|
265
|
+
expect(engine.architecture_health).to be_within(0.001).of(0.75)
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
describe '#architecture_graph' do
|
|
270
|
+
before { register_pair }
|
|
271
|
+
|
|
272
|
+
it 'returns hash with nodes and edges keys' do
|
|
273
|
+
engine.create_connection(source_name: :source, target_name: :target)
|
|
274
|
+
graph = engine.architecture_graph
|
|
275
|
+
expect(graph).to include(:nodes, :edges)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
it 'nodes contains subsystem hashes' do
|
|
279
|
+
graph = engine.architecture_graph
|
|
280
|
+
names = graph[:nodes].map { |n| n[:name] }
|
|
281
|
+
expect(names).to include(:source, :target)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
it 'edges contains connection hashes' do
|
|
285
|
+
engine.create_connection(source_name: :source, target_name: :target)
|
|
286
|
+
graph = engine.architecture_graph
|
|
287
|
+
expect(graph[:edges]).not_to be_empty
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
describe '#decay_all' do
|
|
292
|
+
it 'degrades all subsystems' do
|
|
293
|
+
engine.register_subsystem(name: :d1, subsystem_type: :cognition)
|
|
294
|
+
engine.register_subsystem(name: :d2, subsystem_type: :memory)
|
|
295
|
+
health_before = engine.architecture_health
|
|
296
|
+
engine.decay_all
|
|
297
|
+
expect(engine.architecture_health).to be < health_before
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it 'returns decayed count' do
|
|
301
|
+
engine.register_subsystem(name: :dec, subsystem_type: :cognition)
|
|
302
|
+
result = engine.decay_all
|
|
303
|
+
expect(result[:decayed]).to eq(1)
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
describe '#to_h' do
|
|
308
|
+
it 'returns summary stats hash' do
|
|
309
|
+
engine.register_subsystem(name: :stat_sub, subsystem_type: :coordination)
|
|
310
|
+
h = engine.to_h
|
|
311
|
+
expect(h).to include(:subsystem_count, :connection_count, :active_count,
|
|
312
|
+
:bottlenecked_count, :architecture_health)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
it 'reports correct subsystem_count' do
|
|
316
|
+
engine.register_subsystem(name: :s1, subsystem_type: :cognition)
|
|
317
|
+
engine.register_subsystem(name: :s2, subsystem_type: :memory)
|
|
318
|
+
expect(engine.to_h[:subsystem_count]).to eq(2)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Self::Architecture::Helpers::Connection do
|
|
4
|
+
subject(:connection) do
|
|
5
|
+
described_class.new(source_id: 'src-uuid', target_id: 'tgt-uuid')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'assigns a uuid id' do
|
|
10
|
+
expect(connection.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'stores source_id' do
|
|
14
|
+
expect(connection.source_id).to eq('src-uuid')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'stores target_id' do
|
|
18
|
+
expect(connection.target_id).to eq('tgt-uuid')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'defaults connection_type to :informational' do
|
|
22
|
+
expect(connection.connection_type).to eq(:informational)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'defaults weight to 0.5' do
|
|
26
|
+
expect(connection.weight).to eq(0.5)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'defaults active to true' do
|
|
30
|
+
expect(connection.active).to be(true)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'sets created_at to now' do
|
|
34
|
+
expect(connection.created_at).to be_a(Time)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'accepts custom connection_type' do
|
|
38
|
+
c = described_class.new(source_id: 's', target_id: 't', connection_type: :excitatory)
|
|
39
|
+
expect(c.connection_type).to eq(:excitatory)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'clamps weight above 1.0' do
|
|
43
|
+
c = described_class.new(source_id: 's', target_id: 't', weight: 1.5)
|
|
44
|
+
expect(c.weight).to eq(1.0)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'clamps weight below 0.0' do
|
|
48
|
+
c = described_class.new(source_id: 's', target_id: 't', weight: -0.5)
|
|
49
|
+
expect(c.weight).to eq(0.0)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#strengthen!' do
|
|
54
|
+
it 'increases weight by 0.05 by default' do
|
|
55
|
+
before_weight = connection.weight
|
|
56
|
+
connection.strengthen!
|
|
57
|
+
expect(connection.weight).to be_within(0.001).of(before_weight + 0.05)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'does not exceed 1.0' do
|
|
61
|
+
connection.weight = 0.98
|
|
62
|
+
connection.strengthen!
|
|
63
|
+
expect(connection.weight).to eq(1.0)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'returns self' do
|
|
67
|
+
expect(connection.strengthen!).to be(connection)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#weaken!' do
|
|
72
|
+
it 'decreases weight by 0.05 by default' do
|
|
73
|
+
before_weight = connection.weight
|
|
74
|
+
connection.weaken!
|
|
75
|
+
expect(connection.weight).to be_within(0.001).of(before_weight - 0.05)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'does not go below 0.0' do
|
|
79
|
+
connection.weight = 0.02
|
|
80
|
+
connection.weaken!
|
|
81
|
+
expect(connection.weight).to eq(0.0)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'returns self' do
|
|
85
|
+
expect(connection.weaken!).to be(connection)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#toggle!' do
|
|
90
|
+
it 'flips active from true to false' do
|
|
91
|
+
expect { connection.toggle! }.to change(connection, :active).from(true).to(false)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'flips active from false to true' do
|
|
95
|
+
connection.active = false
|
|
96
|
+
expect { connection.toggle! }.to change(connection, :active).from(false).to(true)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'returns self' do
|
|
100
|
+
expect(connection.toggle!).to be(connection)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe '#to_h' do
|
|
105
|
+
it 'returns a hash with all expected keys' do
|
|
106
|
+
h = connection.to_h
|
|
107
|
+
expect(h.keys).to include(:id, :source_id, :target_id, :connection_type, :weight, :active, :created_at)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'reflects current state' do
|
|
111
|
+
connection.weight = 0.8
|
|
112
|
+
connection.active = false
|
|
113
|
+
h = connection.to_h
|
|
114
|
+
expect(h[:weight]).to eq(0.8)
|
|
115
|
+
expect(h[:active]).to be(false)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Self::Architecture::Helpers::Subsystem do
|
|
4
|
+
subject(:subsystem) { described_class.new(name: :test_sub, subsystem_type: :cognition) }
|
|
5
|
+
|
|
6
|
+
describe '#initialize' do
|
|
7
|
+
it 'assigns a uuid id' do
|
|
8
|
+
expect(subsystem.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'stores name as symbol' do
|
|
12
|
+
expect(subsystem.name).to eq(:test_sub)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'stores subsystem_type as symbol' do
|
|
16
|
+
expect(subsystem.subsystem_type).to eq(:cognition)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'defaults health to DEFAULT_HEALTH' do
|
|
20
|
+
expect(subsystem.health).to eq(Legion::Extensions::Agentic::Self::Architecture::Helpers::Constants::DEFAULT_HEALTH)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'defaults status to active' do
|
|
24
|
+
expect(subsystem.status).to eq(:active)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'defaults load to 0.0' do
|
|
28
|
+
expect(subsystem.load).to eq(0.0)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'defaults activation_count to 0' do
|
|
32
|
+
expect(subsystem.activation_count).to eq(0)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'defaults last_activated_at to nil' do
|
|
36
|
+
expect(subsystem.last_activated_at).to be_nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'sets created_at to now' do
|
|
40
|
+
expect(subsystem.created_at).to be_a(Time)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'accepts custom health' do
|
|
44
|
+
s = described_class.new(name: :s, subsystem_type: :memory, health: 0.5)
|
|
45
|
+
expect(s.health).to eq(0.5)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'clamps health above 1.0' do
|
|
49
|
+
s = described_class.new(name: :s, subsystem_type: :memory, health: 1.5)
|
|
50
|
+
expect(s.health).to eq(1.0)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'clamps health below 0.0' do
|
|
54
|
+
s = described_class.new(name: :s, subsystem_type: :memory, health: -0.5)
|
|
55
|
+
expect(s.health).to eq(0.0)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#activate!' do
|
|
60
|
+
it 'increments activation_count' do
|
|
61
|
+
expect { subsystem.activate! }.to change(subsystem, :activation_count).by(1)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'sets last_activated_at' do
|
|
65
|
+
subsystem.activate!
|
|
66
|
+
expect(subsystem.last_activated_at).to be_a(Time)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'boosts health' do
|
|
70
|
+
original = subsystem.health
|
|
71
|
+
subsystem.activate!
|
|
72
|
+
expect(subsystem.health).to be > original
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'returns self for chaining' do
|
|
76
|
+
expect(subsystem.activate!).to be(subsystem)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#degrade!' do
|
|
81
|
+
it 'reduces health by HEALTH_DECAY by default' do
|
|
82
|
+
original = subsystem.health
|
|
83
|
+
subsystem.degrade!
|
|
84
|
+
expect(subsystem.health).to be < original
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'accepts custom amount' do
|
|
88
|
+
subsystem.degrade!(0.3)
|
|
89
|
+
expect(subsystem.health).to be_within(0.001).of(0.5)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'does not go below 0.0' do
|
|
93
|
+
10.times { subsystem.degrade!(0.2) }
|
|
94
|
+
expect(subsystem.health).to eq(0.0)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'sets status to degraded when health below 0.4' do
|
|
98
|
+
subsystem.degrade!(0.5)
|
|
99
|
+
expect(subsystem.status).to eq(:degraded)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'returns self' do
|
|
103
|
+
expect(subsystem.degrade!).to be(subsystem)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe '#recover!' do
|
|
108
|
+
before { subsystem.degrade!(0.5) }
|
|
109
|
+
|
|
110
|
+
it 'boosts health' do
|
|
111
|
+
original = subsystem.health
|
|
112
|
+
subsystem.recover!
|
|
113
|
+
expect(subsystem.health).to be > original
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'does not exceed 1.0' do
|
|
117
|
+
10.times { subsystem.recover!(0.2) }
|
|
118
|
+
expect(subsystem.health).to eq(1.0)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'restores status to active when health reaches 0.4+' do
|
|
122
|
+
subsystem.recover!(0.2)
|
|
123
|
+
subsystem.recover!(0.2)
|
|
124
|
+
expect(subsystem.status).to eq(:active)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'returns self' do
|
|
128
|
+
expect(subsystem.recover!).to be(subsystem)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe '#bottlenecked?' do
|
|
133
|
+
it 'returns false when load is low' do
|
|
134
|
+
subsystem.load = 0.1
|
|
135
|
+
expect(subsystem.bottlenecked?).to be(false)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'returns false when load is high but health is high' do
|
|
139
|
+
subsystem.load = 0.8
|
|
140
|
+
expect(subsystem.bottlenecked?).to be(false)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it 'returns true when load > BOTTLENECK_THRESHOLD and health < 0.5' do
|
|
144
|
+
subsystem.load = 0.5
|
|
145
|
+
subsystem.degrade!(0.4)
|
|
146
|
+
expect(subsystem.bottlenecked?).to be(true)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe '#health_label' do
|
|
151
|
+
it 'returns :excellent for health >= 0.8' do
|
|
152
|
+
subsystem.health = 0.9
|
|
153
|
+
expect(subsystem.health_label).to eq(:excellent)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'returns :good for health in 0.6...0.8' do
|
|
157
|
+
subsystem.health = 0.7
|
|
158
|
+
expect(subsystem.health_label).to eq(:good)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'returns :fair for health in 0.4...0.6' do
|
|
162
|
+
subsystem.health = 0.5
|
|
163
|
+
expect(subsystem.health_label).to eq(:fair)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'returns :degraded for health in 0.2...0.4' do
|
|
167
|
+
subsystem.health = 0.3
|
|
168
|
+
expect(subsystem.health_label).to eq(:degraded)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'returns :critical for health <= 0.2' do
|
|
172
|
+
subsystem.health = 0.1
|
|
173
|
+
expect(subsystem.health_label).to eq(:critical)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe '#to_h' do
|
|
178
|
+
it 'returns a hash with all expected keys' do
|
|
179
|
+
h = subsystem.to_h
|
|
180
|
+
expect(h.keys).to include(:id, :name, :subsystem_type, :health, :health_label,
|
|
181
|
+
:status, :load, :activation_count, :last_activated_at,
|
|
182
|
+
:created_at, :bottlenecked)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'includes bottlenecked flag' do
|
|
186
|
+
expect(subsystem.to_h[:bottlenecked]).to be(false)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|