## Problem CLI-created community corpus items (tier 3) were stored correctly but invisible via API queries. Two issues blocked discoverability: 1. **Prefix mismatch**: API hardcoded 'community://pattern/' for aggregated patterns, but CLI creates 'community://rust/http/...' URIs 2. **Query parameter parsing**: Axum's default parser doesn't support bracket notation (?sources[]=value) used by the dashboard Result: 0/22 CLI-created items were queryable. ## Solution ### Fix 1: Broaden Community Prefix - Changed: 'community://pattern/' → 'community://' in corpus handler - Impact: Now matches both aggregated patterns AND CLI-created items - Backward compatible: Broader prefix includes narrower results ### Fix 2: Add QsQuery Extractor - Added: serde_qs dependency + custom QsQuery extractor - Supports: Bracket notation for array parameters (?sources[]=a&sources[]=b) - Compatible: Works with JavaScript URLSearchParams standard - Tested: 3 new unit tests for extractor behavior ## Verification - ✅ All 22 CLI-created community items now queryable (was 0) - ✅ Source filtering works: community (22), RFC (2), vendor (5) - ✅ Multi-source queries work: ?sources[]=community&sources[]=rfc → 24 - ✅ All 89 API tests pass + 3 new extractor tests - ✅ Clippy clean (0 warnings) - ✅ No regressions in existing functionality ## Files Changed - crates/stemedb-api/Cargo.toml: Add serde_qs dependency - crates/stemedb-api/src/extractors.rs: New QsQuery extractor (117 lines) - crates/stemedb-api/src/handlers/aphoria/corpus.rs: Use QsQuery, broaden prefix - crates/stemedb-api/src/lib.rs: Export extractors module Also includes: Scale-adaptive thresholds, wiki corpus extraction, documentation updates, and dashboard UI improvements from prior work. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
141 lines
4.7 KiB
Rust
141 lines
4.7 KiB
Rust
//! Integration tests for scale-adaptive promotion thresholds.
|
|
//!
|
|
//! Verifies that promotion criteria automatically adjust based on organization size,
|
|
//! enabling small teams to see value immediately while maintaining quality gates
|
|
//! for larger organizations.
|
|
|
|
use aphoria::corpus::thresholds::{PromotionDecision, ScaleAdaptiveThresholds, ScaleTier};
|
|
use stemedb_core::types::SourceClass;
|
|
|
|
#[test]
|
|
fn test_micro_team_sees_patterns() {
|
|
let thresholds = ScaleAdaptiveThresholds::default();
|
|
|
|
// Micro team with 3 projects, pattern appears in 2
|
|
let decision = thresholds.evaluate(
|
|
2, // project_count
|
|
3, // total_projects
|
|
false, // no authority
|
|
None,
|
|
);
|
|
|
|
// With adaptive thresholds:
|
|
// - Scale tier: Micro (1-5 projects)
|
|
// - Emerging min_projects: max(2, 0.50*3) = max(2, 1.5) = 2
|
|
// - Adoption rate: 2/3 = 67% >= 50%
|
|
// Should require review (emerging tier)
|
|
assert_eq!(decision, PromotionDecision::RequireReview);
|
|
}
|
|
|
|
#[test]
|
|
fn test_micro_team_regulatory_disabled() {
|
|
let thresholds = ScaleAdaptiveThresholds::default();
|
|
|
|
// Micro team with 5 projects, pattern appears in all 5 with RFC match
|
|
let decision = thresholds.evaluate(
|
|
5, // project_count
|
|
5, // total_projects
|
|
true, // has authority
|
|
Some("rfc://1234"), // RFC scheme
|
|
);
|
|
|
|
// Regulatory tier is disabled for micro teams
|
|
// Should fall through to emerging tier
|
|
assert_eq!(decision, PromotionDecision::RequireReview);
|
|
}
|
|
|
|
#[test]
|
|
fn test_small_team_enables_all_tiers() {
|
|
let thresholds = ScaleAdaptiveThresholds::default();
|
|
|
|
// Small team with 10 projects, pattern in 9 with RFC match
|
|
let decision = thresholds.evaluate(
|
|
9, // project_count
|
|
10, // total_projects
|
|
true, // has authority
|
|
Some("rfc://5246"), // RFC scheme
|
|
);
|
|
|
|
// Small tier regulatory: max(5, 0.90*10) = max(5, 9) = 9
|
|
// Adoption rate: 9/10 = 90% >= 90%
|
|
// Should auto-promote to regulatory
|
|
assert_eq!(
|
|
decision,
|
|
PromotionDecision::AutoPromote(SourceClass::Regulatory)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_enterprise_maintains_strict_thresholds() {
|
|
let thresholds = ScaleAdaptiveThresholds::default();
|
|
|
|
// Enterprise with 1000 projects, pattern in 950 with RFC match
|
|
let decision = thresholds.evaluate(
|
|
950, // project_count
|
|
1000, // total_projects
|
|
true, // has authority
|
|
Some("rfc://9110"), // RFC scheme
|
|
);
|
|
|
|
// Enterprise tier: max(100, 0.95*1000) = max(100, 950) = 950
|
|
// Adoption rate: 950/1000 = 95% >= 95%
|
|
// Should auto-promote to regulatory (backward compatible behavior)
|
|
assert_eq!(
|
|
decision,
|
|
PromotionDecision::AutoPromote(SourceClass::Regulatory)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_scale_tier_progression() {
|
|
// Verify scale tier boundaries
|
|
assert_eq!(ScaleTier::from_total_projects(1), ScaleTier::Micro);
|
|
assert_eq!(ScaleTier::from_total_projects(5), ScaleTier::Micro);
|
|
assert_eq!(ScaleTier::from_total_projects(6), ScaleTier::Small);
|
|
assert_eq!(ScaleTier::from_total_projects(25), ScaleTier::Small);
|
|
assert_eq!(ScaleTier::from_total_projects(26), ScaleTier::Medium);
|
|
assert_eq!(ScaleTier::from_total_projects(100), ScaleTier::Medium);
|
|
assert_eq!(ScaleTier::from_total_projects(101), ScaleTier::Large);
|
|
assert_eq!(ScaleTier::from_total_projects(500), ScaleTier::Large);
|
|
assert_eq!(ScaleTier::from_total_projects(501), ScaleTier::Enterprise);
|
|
}
|
|
|
|
#[test]
|
|
fn test_adaptive_floor_prevents_noise() {
|
|
let thresholds = ScaleAdaptiveThresholds::default();
|
|
|
|
// Micro team with 3 projects, pattern appears in only 1
|
|
let decision = thresholds.evaluate(
|
|
1, // project_count
|
|
3, // total_projects
|
|
false, // no authority
|
|
None,
|
|
);
|
|
|
|
// Even though 1/3 = 33% meets percentage (50% of 3 = 1.5),
|
|
// the floor of 2 prevents single-project noise
|
|
// Adoption rate: 1/3 = 33% < 50%
|
|
assert_eq!(decision, PromotionDecision::Skip);
|
|
}
|
|
|
|
#[test]
|
|
fn test_medium_team_clinical_tier() {
|
|
let thresholds = ScaleAdaptiveThresholds::default();
|
|
|
|
// Medium team with 50 projects, pattern in 38 with OWASP match
|
|
let decision = thresholds.evaluate(
|
|
38, // project_count
|
|
50, // total_projects
|
|
true, // has authority
|
|
Some("owasp://top-10/a01"), // OWASP scheme
|
|
);
|
|
|
|
// Medium tier clinical: max(10, 0.75*50) = max(10, 37.5) = 38
|
|
// Adoption rate: 38/50 = 76% >= 75%
|
|
// Should auto-promote to clinical
|
|
assert_eq!(
|
|
decision,
|
|
PromotionDecision::AutoPromote(SourceClass::Clinical)
|
|
);
|
|
}
|