lex-apollo 0.4.44 → 0.4.49
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 +54 -0
- data/README.md +76 -14
- data/lib/legion/extensions/apollo/actors/contradiction_scanner.rb +2 -41
- data/lib/legion/extensions/apollo/actors/corroboration_checker.rb +1 -1
- data/lib/legion/extensions/apollo/actors/decay.rb +1 -1
- data/lib/legion/extensions/apollo/actors/entity_watchdog.rb +2 -135
- data/lib/legion/extensions/apollo/actors/expertise_aggregator.rb +1 -1
- data/lib/legion/extensions/apollo/actors/gas_subscriber.rb +16 -16
- data/lib/legion/extensions/apollo/actors/ingest.rb +7 -7
- data/lib/legion/extensions/apollo/actors/query_responder.rb +25 -6
- data/lib/legion/extensions/apollo/actors/writeback_store.rb +10 -4
- data/lib/legion/extensions/apollo/actors/writeback_vectorize.rb +9 -35
- data/lib/legion/extensions/apollo/api.rb +96 -41
- data/lib/legion/extensions/apollo/client.rb +20 -9
- data/lib/legion/extensions/apollo/gaia_integration.rb +14 -12
- data/lib/legion/extensions/apollo/helpers/capability.rb +10 -51
- data/lib/legion/extensions/apollo/helpers/confidence.rb +8 -52
- data/lib/legion/extensions/apollo/helpers/data_models.rb +22 -38
- data/lib/legion/extensions/apollo/helpers/embedding.rb +118 -0
- data/lib/legion/extensions/apollo/helpers/graph_query.rb +99 -43
- data/lib/legion/extensions/apollo/helpers/similarity.rb +35 -26
- data/lib/legion/extensions/apollo/helpers/storage.rb +75 -0
- data/lib/legion/extensions/apollo/helpers/tag_normalizer.rb +4 -4
- data/lib/legion/extensions/apollo/helpers/writeback.rb +64 -102
- data/lib/legion/extensions/apollo/runners/contradictions.rb +126 -0
- data/lib/legion/extensions/apollo/runners/embedding.rb +60 -0
- data/lib/legion/extensions/apollo/runners/entity_extractor.rb +18 -10
- data/lib/legion/extensions/apollo/runners/entity_watchdog.rb +146 -0
- data/lib/legion/extensions/apollo/runners/expertise.rb +58 -29
- data/lib/legion/extensions/apollo/runners/gas.rb +120 -142
- data/lib/legion/extensions/apollo/runners/knowledge.rb +276 -346
- data/lib/legion/extensions/apollo/runners/maintenance.rb +154 -65
- data/lib/legion/extensions/apollo/runners/query_response.rb +108 -0
- data/lib/legion/extensions/apollo/runners/request.rb +51 -46
- data/lib/legion/extensions/apollo/runners/search.rb +88 -0
- data/lib/legion/extensions/apollo/runners/writeback.rb +57 -0
- data/lib/legion/extensions/apollo/transport/messages/ingest.rb +13 -9
- data/lib/legion/extensions/apollo/transport/messages/query.rb +4 -14
- data/lib/legion/extensions/apollo/transport/messages/writeback.rb +36 -14
- data/lib/legion/extensions/apollo/transport/subscription_delivery.rb +40 -0
- data/lib/legion/extensions/apollo/transport.rb +8 -5
- data/lib/legion/extensions/apollo/version.rb +1 -1
- data/lib/legion/extensions/apollo.rb +28 -24
- data/spec/legion/extensions/apollo/actors/gas_subscriber_spec.rb +9 -24
- data/spec/legion/extensions/apollo/actors/ingest_spec.rb +18 -21
- data/spec/legion/extensions/apollo/actors/query_responder_spec.rb +59 -0
- data/spec/legion/extensions/apollo/api_spec.rb +240 -8
- data/spec/legion/extensions/apollo/contradiction_spec.rb +28 -50
- data/spec/legion/extensions/apollo/gaia_integration_spec.rb +16 -21
- data/spec/legion/extensions/apollo/helpers/capability_spec.rb +24 -27
- data/spec/legion/extensions/apollo/helpers/confidence_spec.rb +16 -101
- data/spec/legion/extensions/apollo/helpers/embedding_spec.rb +33 -0
- data/spec/legion/extensions/apollo/helpers/graph_query_spec.rb +108 -0
- data/spec/legion/extensions/apollo/helpers/similarity_spec.rb +29 -12
- data/spec/legion/extensions/apollo/helpers/storage_spec.rb +59 -0
- data/spec/legion/extensions/apollo/helpers/tag_normalizer_spec.rb +20 -18
- data/spec/legion/extensions/apollo/helpers/writeback_spec.rb +73 -74
- data/spec/legion/extensions/apollo/runners/corroboration_integration_spec.rb +35 -6
- data/spec/legion/extensions/apollo/runners/decay_cycle_spec.rb +17 -10
- data/spec/legion/extensions/apollo/runners/embedding_spec.rb +99 -0
- data/spec/legion/extensions/apollo/runners/entity_extractor_spec.rb +32 -99
- data/spec/legion/extensions/apollo/runners/entity_watchdog_spec.rb +205 -0
- data/spec/legion/extensions/apollo/runners/expertise_spec.rb +75 -79
- data/spec/legion/extensions/apollo/runners/gas_anticipate_spec.rb +14 -91
- data/spec/legion/extensions/apollo/runners/gas_deposit_integration_spec.rb +28 -11
- data/spec/legion/extensions/apollo/runners/gas_relate_spec.rb +45 -87
- data/spec/legion/extensions/apollo/runners/gas_spec.rb +87 -77
- data/spec/legion/extensions/apollo/runners/gas_synthesize_spec.rb +14 -89
- data/spec/legion/extensions/apollo/runners/ingest_transaction_integration_spec.rb +141 -9
- data/spec/legion/extensions/apollo/runners/knowledge_scope_integration_spec.rb +130 -0
- data/spec/legion/extensions/apollo/runners/knowledge_spec.rb +314 -655
- data/spec/legion/extensions/apollo/runners/lifecycle_integration_spec.rb +14 -5
- data/spec/legion/extensions/apollo/runners/maintenance_spec.rb +48 -64
- data/spec/legion/extensions/apollo/runners/query_response_spec.rb +161 -0
- data/spec/legion/extensions/apollo/runners/reembedding_integration_spec.rb +227 -0
- data/spec/legion/extensions/apollo/runners/request_spec.rb +120 -98
- data/spec/legion/extensions/apollo/runners/search_spec.rb +155 -0
- data/spec/legion/extensions/apollo/runners/writeback_spec.rb +93 -0
- data/spec/legion/extensions/apollo/transport/messages/ingest_spec.rb +26 -51
- data/spec/legion/extensions/apollo/transport/messages/query_spec.rb +20 -61
- data/spec/legion/extensions/apollo/transport/messages/writeback_spec.rb +126 -47
- data/spec/legion/extensions/apollo/transport/subscription_delivery_spec.rb +41 -0
- data/spec/legion/extensions/apollo/transport_spec.rb +33 -0
- data/spec/spec_helper.rb +42 -13
- metadata +41 -13
- data/lib/legion/extensions/apollo/helpers/entity_watchdog.rb +0 -91
- data/spec/legion/extensions/apollo/actors/contradiction_scanner_spec.rb +0 -38
- data/spec/legion/extensions/apollo/actors/decay_spec.rb +0 -45
- data/spec/legion/extensions/apollo/actors/entity_watchdog_spec.rb +0 -134
- data/spec/legion/extensions/apollo/actors/expertise_aggregator_spec.rb +0 -41
- data/spec/legion/extensions/apollo/actors/writeback_store_spec.rb +0 -42
- data/spec/legion/extensions/apollo/actors/writeback_vectorize_spec.rb +0 -102
- data/spec/legion/extensions/apollo/helpers/entity_watchdog_spec.rb +0 -64
|
@@ -3,109 +3,67 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require 'legion/extensions/apollo/runners/gas'
|
|
5
5
|
|
|
6
|
-
RSpec.describe Legion::Extensions::Apollo::Runners::Gas, '
|
|
6
|
+
RSpec.describe Legion::Extensions::Apollo::Runners::Gas, 'relation classification' do
|
|
7
7
|
let(:facts) do
|
|
8
|
-
[
|
|
9
|
-
|
|
10
|
-
{ content: 'cosine distance measures similarity', content_type: :concept }
|
|
11
|
-
]
|
|
8
|
+
[{ content: 'pgvector uses HNSW indexes', content_type: :fact },
|
|
9
|
+
{ content: 'cosine distance measures similarity', content_type: :concept }]
|
|
12
10
|
end
|
|
13
|
-
let(:
|
|
14
|
-
|
|
11
|
+
let(:similar_entries) do
|
|
12
|
+
{ success: true,
|
|
13
|
+
entries: [{ id: 'e1', content: 'HNSW is an approximate nearest neighbor algorithm', content_type: 'concept', confidence: 0.85 }],
|
|
14
|
+
count: 1 }
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
before do
|
|
18
|
+
allow(Legion::LLM).to receive(:started?).and_return(false)
|
|
19
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:retrieve_relevant).and_return(similar_entries)
|
|
20
|
+
end
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
it 'uses mechanical similar-to relations when the LLM is not started' do
|
|
23
|
+
result = described_class.send(:gas_phase_relate, facts: facts)
|
|
24
|
+
|
|
25
|
+
expect(result.map { |relation| [relation[:from_content], relation[:to_id], relation[:relation_type]] }).to eq(
|
|
26
|
+
facts.map { |fact| [fact[:content], 'e1', 'similar_to'] }
|
|
27
|
+
)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
context '
|
|
29
|
-
|
|
30
|
-
let(:similar_entries) do
|
|
31
|
-
{
|
|
32
|
-
success: true,
|
|
33
|
-
entries: [
|
|
34
|
-
{ id: 'e1', content: 'HNSW is an approximate nearest neighbor algorithm', content_type: 'concept', confidence: 0.85 }
|
|
35
|
-
],
|
|
36
|
-
count: 1
|
|
37
|
-
}
|
|
38
|
-
end
|
|
30
|
+
context 'with LLM classification available' do
|
|
31
|
+
before { allow(Legion::LLM).to receive(:started?).and_return(true) }
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
end
|
|
33
|
+
it 'uses a supported high-confidence classification' do
|
|
34
|
+
allow(Legion::LLM::Inference::GaiaCaller).to receive(:structured)
|
|
35
|
+
.and_return(data: { relations: [{ relation_type: 'depends_on', confidence: 0.85 }] })
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
it 'falls back to similar_to relations' do
|
|
47
|
-
result = described_class.phase_relate(facts, entities)
|
|
48
|
-
expect(result).to all(include(relation_type: 'similar_to'))
|
|
49
|
-
end
|
|
37
|
+
result = described_class.send(:gas_phase_relate, facts: facts)
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
expect(result).to contain_exactly(
|
|
40
|
+
include(from_content: facts[0][:content], to_id: 'e1', relation_type: 'depends_on', confidence: 0.85),
|
|
41
|
+
include(from_content: facts[1][:content], to_id: 'e1', relation_type: 'depends_on', confidence: 0.85)
|
|
42
|
+
)
|
|
55
43
|
end
|
|
56
44
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
before do
|
|
69
|
-
stub_const('Legion::LLM::Pipeline::GaiaCaller', gaia_caller)
|
|
70
|
-
allow(gaia_caller).to receive(:structured).and_return(mock_response)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it 'classifies relations via LLM' do
|
|
74
|
-
result = described_class.phase_relate(facts, entities)
|
|
75
|
-
expect(result).not_to be_empty
|
|
76
|
-
expect(result.first[:relation_type]).to eq('depends_on')
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it 'gates on confidence > 0.7' do
|
|
80
|
-
low_conf_response = double(
|
|
81
|
-
'Response',
|
|
82
|
-
message: {
|
|
83
|
-
content: '{"relations":[{"relation_type":"contradicts","confidence":0.3}]}'
|
|
84
|
-
}
|
|
85
|
-
)
|
|
86
|
-
allow(gaia_caller).to receive(:structured).and_return(low_conf_response)
|
|
87
|
-
|
|
88
|
-
result = described_class.phase_relate(facts, entities)
|
|
89
|
-
# Low confidence relations should fall back to similar_to
|
|
90
|
-
classified = result.select { |r| r[:relation_type] == 'contradicts' }
|
|
91
|
-
expect(classified).to be_empty
|
|
92
|
-
end
|
|
45
|
+
it 'does not turn a weak contradiction classification into a contradiction edge' do
|
|
46
|
+
allow(Legion::LLM::Inference::GaiaCaller).to receive(:structured)
|
|
47
|
+
.and_return(data: { relations: [{ relation_type: 'contradicts', confidence: 0.3 }] })
|
|
48
|
+
|
|
49
|
+
result = described_class.send(:gas_phase_relate, facts: facts)
|
|
50
|
+
|
|
51
|
+
expect(result.map { |relation| relation[:relation_type] }).to eq(%w[similar_to similar_to])
|
|
93
52
|
end
|
|
94
53
|
end
|
|
95
54
|
|
|
96
|
-
|
|
97
|
-
|
|
55
|
+
it 'returns no relations when retrieval succeeds without similar entries' do
|
|
56
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:retrieve_relevant)
|
|
57
|
+
.and_return(success: true, entries: [], count: 0)
|
|
98
58
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
allow(knowledge_runner).to receive(:retrieve_relevant).and_return(
|
|
102
|
-
{ success: true, entries: [], count: 0 }
|
|
103
|
-
)
|
|
104
|
-
end
|
|
59
|
+
expect(described_class.send(:gas_phase_relate, facts: facts)).to eq([])
|
|
60
|
+
end
|
|
105
61
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
62
|
+
it 'propagates failed retrieval rather than treating it as an empty knowledge store' do
|
|
63
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:retrieve_relevant)
|
|
64
|
+
.and_return(success: false, error: 'database unavailable')
|
|
65
|
+
|
|
66
|
+
expect { described_class.send(:gas_phase_relate, facts: facts) }
|
|
67
|
+
.to raise_error(IOError, /database unavailable/)
|
|
110
68
|
end
|
|
111
69
|
end
|
|
@@ -4,99 +4,109 @@ require 'spec_helper'
|
|
|
4
4
|
require 'legion/extensions/apollo/runners/gas'
|
|
5
5
|
|
|
6
6
|
RSpec.describe Legion::Extensions::Apollo::Runners::Gas do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
7
|
+
let(:audit_event) do
|
|
8
|
+
{
|
|
9
|
+
request_id: 'req-1',
|
|
10
|
+
messages: [{ role: :user, content: 'What is pgvector?' }],
|
|
11
|
+
response_content: 'pgvector uses HNSW indexes.',
|
|
12
|
+
routing: { provider: :test },
|
|
13
|
+
access_scope: 'private',
|
|
14
|
+
identity_principal_id: 42,
|
|
15
|
+
content_sanitized: true
|
|
16
|
+
}
|
|
17
|
+
end
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
before do
|
|
20
|
+
allow(described_class).to receive(:settings).and_return(
|
|
21
|
+
Legion::Extensions::Apollo.default_settings.merge(gas: Legion::Extensions::Apollo.default_settings[:gas].merge(enabled: true))
|
|
22
|
+
)
|
|
23
|
+
allow(Legion::Extensions::Apollo::Runners::EntityExtractor).to receive(:extract_entities)
|
|
24
|
+
.and_return(success: true, entities: [{ name: 'pgvector', type: 'repository' }])
|
|
25
|
+
end
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(result[:phases_completed]).to eq(0)
|
|
28
|
-
end
|
|
27
|
+
it 'skips events without an exchange response' do
|
|
28
|
+
result = described_class.process(request_id: 'req-1', messages: [])
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
expect(result).to include(success: true, phases_completed: 0, reason: 'no content')
|
|
31
|
+
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
it 'does not process audit events by default' do
|
|
34
|
+
allow(described_class).to receive(:settings).and_return(Legion::Extensions::Apollo.default_settings)
|
|
35
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).not_to receive(:handle_ingest)
|
|
36
|
+
|
|
37
|
+
expect(described_class.process(**audit_event)).to include(success: true, phases_completed: 0, reason: 'disabled')
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
event = { messages: [{ role: :user, content: 'hi' }], response_content: 'hello' }
|
|
42
|
-
expect(described_class.processable?(event)).to be true
|
|
43
|
-
end
|
|
40
|
+
it 'rejects audit events without explicit private ownership and sanitized content' do
|
|
41
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).not_to receive(:handle_ingest)
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
[audit_event.except(:identity_principal_id), audit_event.merge(access_scope: 'global'),
|
|
44
|
+
audit_event.except(:content_sanitized), audit_event.merge(response_content: 'Contact alice@example.com')].each do |event|
|
|
45
|
+
expect(described_class.process(**event)).to include(success: true, phases_completed: 0, reason: 'unsafe_audit_event')
|
|
47
46
|
end
|
|
47
|
+
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
it 'does not deposit the raw response when the LLM is unavailable' do
|
|
50
|
+
allow(Legion::LLM).to receive(:started?).and_return(false)
|
|
51
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).not_to receive(:handle_ingest)
|
|
52
|
+
|
|
53
|
+
expect(described_class.process(**audit_event)).to include(success: true, phases_completed: 0, reason: 'llm_unavailable')
|
|
52
54
|
end
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
it 'stores clean derived facts privately and scopes semantic lookup to the caller' do
|
|
57
|
+
allow(Legion::LLM).to receive(:started?).and_return(true)
|
|
58
|
+
allow(described_class).to receive(:gas_llm_comprehend)
|
|
59
|
+
.and_return([{ content: 'HNSW is an approximate search index', content_type: :fact }])
|
|
60
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:retrieve_relevant)
|
|
61
|
+
.and_return(success: true, entries: [], count: 0)
|
|
62
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:handle_ingest)
|
|
63
|
+
.and_return(success: true, entry_id: 7)
|
|
64
|
+
|
|
65
|
+
result = described_class.process(**audit_event)
|
|
66
|
+
|
|
67
|
+
expect(result).to include(success: true, phases_completed: 6, facts: 1, anticipations: 0)
|
|
68
|
+
expect(result[:deposited]).to include(deposited: 1, failed: 0, facts: 1)
|
|
69
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).to have_received(:retrieve_relevant)
|
|
70
|
+
.with(hash_including(requesting_principal_id: 42))
|
|
71
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).to have_received(:handle_ingest)
|
|
72
|
+
.with(hash_including(access_scope: 'private', identity_principal_id: 42,
|
|
73
|
+
content: 'HNSW is an approximate search index'))
|
|
60
74
|
end
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
it 'skips sensitive generated facts before lookup or deposit' do
|
|
77
|
+
allow(Legion::LLM).to receive(:started?).and_return(true)
|
|
78
|
+
allow(described_class).to receive(:gas_llm_comprehend)
|
|
79
|
+
.and_return([{ content: 'alice@example.com', content_type: :fact }])
|
|
80
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).not_to receive(:retrieve_relevant)
|
|
81
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).not_to receive(:handle_ingest)
|
|
82
|
+
|
|
83
|
+
expect(described_class.process(**audit_event)).to include(success: true, facts: 0)
|
|
68
84
|
end
|
|
69
85
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
it 'reports partial deposit failure without claiming success' do
|
|
87
|
+
allow(Legion::LLM).to receive(:started?).and_return(true)
|
|
88
|
+
allow(described_class).to receive(:gas_llm_comprehend)
|
|
89
|
+
.and_return([{ content: 'HNSW is an approximate search index', content_type: :fact }])
|
|
90
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:retrieve_relevant)
|
|
91
|
+
.and_return(success: true, entries: [], count: 0)
|
|
92
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:handle_ingest)
|
|
93
|
+
.and_return(success: false, error: 'write rejected')
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
end
|
|
95
|
+
result = described_class.process(**audit_event)
|
|
78
96
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
{ content: 'failed synthesis', content_type: :implication, source_indices: [0] },
|
|
94
|
-
{ content: 'missing ID', content_type: :connection, source_indices: [0] }
|
|
95
|
-
]
|
|
96
|
-
|
|
97
|
-
result = described_class.phase_deposit(facts, [], [], synthesis, { request_id: 'req_1' })
|
|
98
|
-
|
|
99
|
-
expect(result).to include(deposited: 2, failed: 3, facts: 1, synthesis: 1, relations: 0)
|
|
100
|
-
end
|
|
97
|
+
expect(result).to include(success: false, phases_completed: 6)
|
|
98
|
+
expect(result[:deposited]).to include(deposited: 0, failed: 1)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'returns a structured failure when a dependency raises' do
|
|
102
|
+
allow(Legion::Extensions::Apollo::Runners::Knowledge).to receive(:retrieve_relevant)
|
|
103
|
+
.and_raise(IOError, 'retrieval unavailable')
|
|
104
|
+
allow(Legion::LLM).to receive(:started?).and_return(true)
|
|
105
|
+
allow(described_class).to receive(:gas_llm_comprehend)
|
|
106
|
+
.and_return([{ content: 'HNSW is an approximate search index', content_type: :fact }])
|
|
107
|
+
|
|
108
|
+
result = described_class.process(**audit_event)
|
|
109
|
+
|
|
110
|
+
expect(result).to include(success: false, phases_completed: 0, error: 'retrieval unavailable')
|
|
101
111
|
end
|
|
102
112
|
end
|
|
@@ -3,94 +3,19 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require 'legion/extensions/apollo/runners/gas'
|
|
5
5
|
|
|
6
|
-
RSpec.describe Legion::Extensions::Apollo::Runners::Gas, '
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
context 'when GaiaCaller is unavailable' do
|
|
21
|
-
it 'returns empty array' do
|
|
22
|
-
result = described_class.phase_synthesize(facts, relations)
|
|
23
|
-
expect(result).to eq([])
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'when GaiaCaller is available' do
|
|
28
|
-
let(:gaia_caller) { double('GaiaCaller') }
|
|
29
|
-
let(:mock_response) do
|
|
30
|
-
double(
|
|
31
|
-
'Response',
|
|
32
|
-
message: {
|
|
33
|
-
content: '{"synthesis":[{"content":"pgvector achieves fast search via HNSW",' \
|
|
34
|
-
'"content_type":"inference","source_indices":[0,1]}]}'
|
|
35
|
-
}
|
|
36
|
-
)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
stub_const('Legion::LLM::Pipeline::GaiaCaller', gaia_caller)
|
|
41
|
-
allow(gaia_caller).to receive(:structured).and_return(mock_response)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'generates derivative knowledge entries' do
|
|
45
|
-
result = described_class.phase_synthesize(facts, relations)
|
|
46
|
-
expect(result).not_to be_empty
|
|
47
|
-
expect(result.first[:content]).to include('pgvector')
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'marks entries as candidate status' do
|
|
51
|
-
result = described_class.phase_synthesize(facts, relations)
|
|
52
|
-
expect(result.first[:status]).to eq(:candidate)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'caps confidence at 0.7' do
|
|
56
|
-
result = described_class.phase_synthesize(facts, relations)
|
|
57
|
-
result.each do |entry|
|
|
58
|
-
expect(entry[:confidence]).to be <= 0.7
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'includes depends_on source indices' do
|
|
63
|
-
result = described_class.phase_synthesize(facts, relations)
|
|
64
|
-
expect(result.first[:source_indices]).to eq([0, 1])
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
context 'when LLM call fails' do
|
|
69
|
-
let(:gaia_caller) { double('GaiaCaller') }
|
|
70
|
-
|
|
71
|
-
before do
|
|
72
|
-
stub_const('Legion::LLM::Pipeline::GaiaCaller', gaia_caller)
|
|
73
|
-
allow(gaia_caller).to receive(:structured).and_raise(StandardError, 'LLM timeout')
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'returns empty array on error' do
|
|
77
|
-
result = described_class.phase_synthesize(facts, relations)
|
|
78
|
-
expect(result).to eq([])
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context 'with empty inputs' do
|
|
83
|
-
it 'returns empty array when no facts' do
|
|
84
|
-
result = described_class.phase_synthesize([], [])
|
|
85
|
-
expect(result).to eq([])
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it 'returns empty array when single fact (nothing to synthesize)' do
|
|
89
|
-
result = described_class.phase_synthesize(
|
|
90
|
-
[{ content: 'one fact', content_type: :fact, confidence: 0.9 }],
|
|
91
|
-
[]
|
|
92
|
-
)
|
|
93
|
-
expect(result).to eq([])
|
|
94
|
-
end
|
|
6
|
+
RSpec.describe Legion::Extensions::Apollo::Runners::Gas, 'synthesis phase' do
|
|
7
|
+
it 'does not synthesize or deposit a mechanical observation' do
|
|
8
|
+
allow(Legion::LLM).to receive(:started?).and_return(false)
|
|
9
|
+
allow(described_class).to receive(:settings).and_return(
|
|
10
|
+
Legion::Extensions::Apollo.default_settings.merge(gas: Legion::Extensions::Apollo.default_settings[:gas].merge(enabled: true))
|
|
11
|
+
)
|
|
12
|
+
expect(Legion::Extensions::Apollo::Runners::Knowledge).not_to receive(:handle_ingest)
|
|
13
|
+
|
|
14
|
+
result = described_class.process(
|
|
15
|
+
request_id: 'req-synthesize', messages: [{ content: 'question' }], response_content: 'observation',
|
|
16
|
+
access_scope: 'private', identity_principal_id: 42, content_sanitized: true
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
expect(result).to include(success: true, phases_completed: 0, reason: 'llm_unavailable')
|
|
95
20
|
end
|
|
96
21
|
end
|