chopratejas commited on
Commit
9da4ddc
·
1 Parent(s): 6d9a566

Update test for lowered TOIN confidence threshold default

Browse files
tests/test_critical_gaps.py CHANGED
@@ -1209,9 +1209,9 @@ class TestLowPriorityFixes:
1209
  """LOW FIX #21: TOIN confidence threshold should be configurable."""
1210
  from headroom.config import SmartCrusherConfig
1211
 
1212
- # Default value
1213
  config = SmartCrusherConfig()
1214
- assert config.toin_confidence_threshold == 0.5
1215
 
1216
  # Custom value
1217
  config2 = SmartCrusherConfig(toin_confidence_threshold=0.8)
 
1209
  """LOW FIX #21: TOIN confidence threshold should be configurable."""
1210
  from headroom.config import SmartCrusherConfig
1211
 
1212
+ # Default value (lowered from 0.5 to 0.3 for faster TOIN learning)
1213
  config = SmartCrusherConfig()
1214
+ assert config.toin_confidence_threshold == 0.3
1215
 
1216
  # Custom value
1217
  config2 = SmartCrusherConfig(toin_confidence_threshold=0.8)
tests/test_toin_full_integration.py CHANGED
@@ -13,17 +13,17 @@ from pathlib import Path
13
 
14
  import pytest
15
 
 
 
16
  from headroom.telemetry.toin import (
 
17
  TOINConfig,
18
  ToolIntelligenceNetwork,
 
19
  get_toin,
20
  reset_toin,
21
- get_default_toin_storage_path,
22
- TOIN_PATH_ENV_VAR,
23
  )
24
- from headroom.telemetry.models import ToolSignature
25
  from headroom.transforms.smart_crusher import SmartCrusher, SmartCrusherConfig
26
- from headroom.config import CCRConfig
27
 
28
 
29
  @pytest.fixture(autouse=True)
@@ -76,7 +76,7 @@ class TestTOINDefaultStoragePath:
76
  config = TOINConfig()
77
 
78
  print(f"\nDefault storage_path: {config.storage_path}")
79
- print(f"Expected location: ~/.headroom/toin.json")
80
 
81
  # Verify it's not None/empty
82
  assert config.storage_path, "TOINConfig should have a default storage_path"
@@ -238,7 +238,7 @@ class TestTOINPersistenceAcrossInstances:
238
  # Verify specific pattern exists
239
  pattern = toin2.get_pattern(sample_tool_signature.structure_hash)
240
  assert pattern is not None, "Pattern for our tool signature should exist"
241
- print(f"\nReloaded pattern details:")
242
  print(f" - total_compressions: {pattern.total_compressions}")
243
  print(f" - total_retrievals: {pattern.total_retrievals}")
244
  print(f" - sample_size: {pattern.sample_size}")
@@ -290,7 +290,7 @@ class TestTOINFullFeedbackLoop:
290
 
291
  # Get pattern stats
292
  pattern = toin.get_pattern(sample_tool_signature.structure_hash)
293
- print(f"\n--- Pattern Stats ---")
294
  print(f" total_compressions: {pattern.total_compressions}")
295
  print(f" total_retrievals: {pattern.total_retrievals}")
296
  print(f" retrieval_rate: {pattern.retrieval_rate:.1%}")
@@ -312,11 +312,16 @@ class TestTOINFullFeedbackLoop:
312
  # With 60% retrieval rate (3/5) and full_retrieval_rate of 100% (3/3),
313
  # TOIN should recommend skipping compression
314
  retrieval_rate = pattern.retrieval_rate
315
- assert retrieval_rate >= 0.5, f"Expected retrieval rate >= 50%, got {retrieval_rate:.1%}"
 
 
316
 
317
  # With high retrieval rate and high full retrieval rate, should skip
318
  if pattern.full_retrieval_rate > 0.8:
319
- assert hint.skip_compression or hint.compression_level in ("none", "conservative"), (
 
 
 
320
  f"High full retrieval rate should trigger skip or conservative, "
321
  f"got compression_level={hint.compression_level}"
322
  )
@@ -486,7 +491,7 @@ class TestTOINWithSmartCrusher:
486
 
487
  # Get TOIN stats after compression
488
  stats_after = toin.get_stats()
489
- print(f"\n--- TOIN Stats After Compression ---")
490
  print(f" patterns_tracked: {stats_after['patterns_tracked']}")
491
  print(f" total_compressions: {stats_after['total_compressions']}")
492
  print(f" total_retrievals: {stats_after['total_retrievals']}")
@@ -494,11 +499,13 @@ class TestTOINWithSmartCrusher:
494
  # Verify TOIN recorded the compression
495
  # Note: SmartCrusher uses internal telemetry which may or may not go through TOIN
496
  # depending on the integration. Let's check if patterns were recorded.
497
- if stats_after['patterns_tracked'] > 0:
498
  print("\n[PASS] SmartCrusher integration with TOIN works")
499
  else:
500
  # If no patterns recorded via global TOIN, manually record to verify TOIN works
501
- print("\n[INFO] SmartCrusher may use internal telemetry, testing manual recording...")
 
 
502
  sig = ToolSignature.from_items(sample_items)
503
  toin.record_compression(
504
  tool_signature=sig,
@@ -510,7 +517,7 @@ class TestTOINWithSmartCrusher:
510
  )
511
  stats_manual = toin.get_stats()
512
  print(f" patterns_tracked after manual: {stats_manual['patterns_tracked']}")
513
- assert stats_manual['patterns_tracked'] > 0, "Manual recording should work"
514
  print("\n[PASS] TOIN recording works (manual verification)")
515
 
516
 
@@ -542,7 +549,7 @@ class TestTOINStatsOutput:
542
  strategy="smart_sample" if i % 2 == 0 else "top_n",
543
  query_context=f"query with field:value_{i}",
544
  )
545
- print(f" Recorded 10 compressions")
546
 
547
  # Record retrievals
548
  for i in range(3):
@@ -553,7 +560,7 @@ class TestTOINStatsOutput:
553
  query_fields=["status", "error"],
554
  strategy="smart_sample",
555
  )
556
- print(f" Recorded 3 retrievals")
557
 
558
  # Get stats
559
  stats = toin.get_stats()
@@ -657,7 +664,7 @@ class TestTOINFieldLearning:
657
  print("=" * 60)
658
 
659
  # Record compressions first
660
- for i in range(5):
661
  fresh_toin.record_compression(
662
  tool_signature=sample_tool_signature,
663
  original_count=100,
@@ -681,7 +688,7 @@ class TestTOINFieldLearning:
681
 
682
  # Check pattern
683
  pattern = fresh_toin.get_pattern(sample_tool_signature.structure_hash)
684
- print(f"\n--- Field Retrieval Frequency ---")
685
  for field_hash, count in pattern.field_retrieval_frequency.items():
686
  print(f" {field_hash}: {count} retrievals")
687
 
 
13
 
14
  import pytest
15
 
16
+ from headroom.config import CCRConfig
17
+ from headroom.telemetry.models import ToolSignature
18
  from headroom.telemetry.toin import (
19
+ TOIN_PATH_ENV_VAR,
20
  TOINConfig,
21
  ToolIntelligenceNetwork,
22
+ get_default_toin_storage_path,
23
  get_toin,
24
  reset_toin,
 
 
25
  )
 
26
  from headroom.transforms.smart_crusher import SmartCrusher, SmartCrusherConfig
 
27
 
28
 
29
  @pytest.fixture(autouse=True)
 
76
  config = TOINConfig()
77
 
78
  print(f"\nDefault storage_path: {config.storage_path}")
79
+ print("Expected location: ~/.headroom/toin.json")
80
 
81
  # Verify it's not None/empty
82
  assert config.storage_path, "TOINConfig should have a default storage_path"
 
238
  # Verify specific pattern exists
239
  pattern = toin2.get_pattern(sample_tool_signature.structure_hash)
240
  assert pattern is not None, "Pattern for our tool signature should exist"
241
+ print("\nReloaded pattern details:")
242
  print(f" - total_compressions: {pattern.total_compressions}")
243
  print(f" - total_retrievals: {pattern.total_retrievals}")
244
  print(f" - sample_size: {pattern.sample_size}")
 
290
 
291
  # Get pattern stats
292
  pattern = toin.get_pattern(sample_tool_signature.structure_hash)
293
+ print("\n--- Pattern Stats ---")
294
  print(f" total_compressions: {pattern.total_compressions}")
295
  print(f" total_retrievals: {pattern.total_retrievals}")
296
  print(f" retrieval_rate: {pattern.retrieval_rate:.1%}")
 
312
  # With 60% retrieval rate (3/5) and full_retrieval_rate of 100% (3/3),
313
  # TOIN should recommend skipping compression
314
  retrieval_rate = pattern.retrieval_rate
315
+ assert retrieval_rate >= 0.5, (
316
+ f"Expected retrieval rate >= 50%, got {retrieval_rate:.1%}"
317
+ )
318
 
319
  # With high retrieval rate and high full retrieval rate, should skip
320
  if pattern.full_retrieval_rate > 0.8:
321
+ assert hint.skip_compression or hint.compression_level in (
322
+ "none",
323
+ "conservative",
324
+ ), (
325
  f"High full retrieval rate should trigger skip or conservative, "
326
  f"got compression_level={hint.compression_level}"
327
  )
 
491
 
492
  # Get TOIN stats after compression
493
  stats_after = toin.get_stats()
494
+ print("\n--- TOIN Stats After Compression ---")
495
  print(f" patterns_tracked: {stats_after['patterns_tracked']}")
496
  print(f" total_compressions: {stats_after['total_compressions']}")
497
  print(f" total_retrievals: {stats_after['total_retrievals']}")
 
499
  # Verify TOIN recorded the compression
500
  # Note: SmartCrusher uses internal telemetry which may or may not go through TOIN
501
  # depending on the integration. Let's check if patterns were recorded.
502
+ if stats_after["patterns_tracked"] > 0:
503
  print("\n[PASS] SmartCrusher integration with TOIN works")
504
  else:
505
  # If no patterns recorded via global TOIN, manually record to verify TOIN works
506
+ print(
507
+ "\n[INFO] SmartCrusher may use internal telemetry, testing manual recording..."
508
+ )
509
  sig = ToolSignature.from_items(sample_items)
510
  toin.record_compression(
511
  tool_signature=sig,
 
517
  )
518
  stats_manual = toin.get_stats()
519
  print(f" patterns_tracked after manual: {stats_manual['patterns_tracked']}")
520
+ assert stats_manual["patterns_tracked"] > 0, "Manual recording should work"
521
  print("\n[PASS] TOIN recording works (manual verification)")
522
 
523
 
 
549
  strategy="smart_sample" if i % 2 == 0 else "top_n",
550
  query_context=f"query with field:value_{i}",
551
  )
552
+ print(" Recorded 10 compressions")
553
 
554
  # Record retrievals
555
  for i in range(3):
 
560
  query_fields=["status", "error"],
561
  strategy="smart_sample",
562
  )
563
+ print(" Recorded 3 retrievals")
564
 
565
  # Get stats
566
  stats = toin.get_stats()
 
664
  print("=" * 60)
665
 
666
  # Record compressions first
667
+ for _i in range(5):
668
  fresh_toin.record_compression(
669
  tool_signature=sample_tool_signature,
670
  original_count=100,
 
688
 
689
  # Check pattern
690
  pattern = fresh_toin.get_pattern(sample_tool_signature.structure_hash)
691
+ print("\n--- Field Retrieval Frequency ---")
692
  for field_hash, count in pattern.field_retrieval_frequency.items():
693
  print(f" {field_hash}: {count} retrievals")
694