Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2307e5379c |
@@ -1406,226 +1406,3 @@ async fn query_temporal_graph(
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_to_rbac_claims_with_roles() {
|
||||
let jwt = JwtClaims {
|
||||
sub: "alice".to_string(),
|
||||
iss: "authentik".to_string(),
|
||||
aud: "memory".to_string(),
|
||||
exp: i64::MAX,
|
||||
iat: 0,
|
||||
nbf: None,
|
||||
permissions: Some(vec!["memory:read".to_string()]),
|
||||
groups: Some(vec!["engineering".to_string()]),
|
||||
roles: Some(vec!["authenticated-user".to_string(), "homelab-team".to_string()]),
|
||||
};
|
||||
|
||||
let rbac = to_rbac_claims(&jwt);
|
||||
|
||||
assert_eq!(rbac.sub, "alice");
|
||||
assert!(rbac.has_role("authenticated-user"));
|
||||
assert!(rbac.has_role("homelab-team"));
|
||||
assert!(!rbac.has_role("admin"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_rbac_claims_basic() {
|
||||
let jwt = JwtClaims {
|
||||
sub: "alice".to_string(),
|
||||
iss: "test".to_string(),
|
||||
aud: "memory".to_string(),
|
||||
exp: i64::MAX,
|
||||
iat: 0,
|
||||
nbf: None,
|
||||
permissions: Some(vec!["memory:read".to_string(), "memory:write".to_string()]),
|
||||
groups: Some(vec!["engineering".to_string(), "ml-team".to_string()]),
|
||||
roles: Some(vec!["authenticated-user".to_string()]),
|
||||
};
|
||||
|
||||
let rbac = to_rbac_claims(&jwt);
|
||||
|
||||
assert_eq!(rbac.sub, "alice");
|
||||
assert!(rbac.in_group("engineering"));
|
||||
assert!(rbac.in_group("ml-team"));
|
||||
assert!(rbac.has_permission("memory:read"));
|
||||
assert!(rbac.has_permission("memory:write"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_rbac_claims_empty() {
|
||||
let jwt = JwtClaims {
|
||||
sub: "anonymous".to_string(),
|
||||
iss: "test".to_string(),
|
||||
aud: "memory".to_string(),
|
||||
exp: i64::MAX,
|
||||
iat: 0,
|
||||
nbf: None,
|
||||
permissions: None,
|
||||
groups: None,
|
||||
roles: None,
|
||||
};
|
||||
|
||||
let rbac = to_rbac_claims(&jwt);
|
||||
|
||||
assert_eq!(rbac.sub, "anonymous");
|
||||
assert!(!rbac.in_group("any"));
|
||||
assert!(!rbac.has_permission("any"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_result_to_resource_meta_wiki() {
|
||||
let result = crate::query_worker::QueryResult {
|
||||
level: "corpus".to_string(),
|
||||
score: 0.9,
|
||||
text: "Some wiki content".to_string(),
|
||||
source: Some("docs/kubernetes.md".to_string()),
|
||||
provenance: vec![],
|
||||
};
|
||||
|
||||
let meta = query_result_to_resource_meta(&result, "homelab");
|
||||
|
||||
assert_eq!(meta.resource_type, ResourceType::Wiki);
|
||||
assert_eq!(meta.project, "homelab");
|
||||
assert_eq!(meta.visibility, Visibility::Public);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_result_to_resource_meta_skill() {
|
||||
let result = crate::query_worker::QueryResult {
|
||||
level: "L1".to_string(),
|
||||
score: 0.8,
|
||||
text: "Skill content".to_string(),
|
||||
source: Some("shared/skills/SKILL-debug/SKILL.md".to_string()),
|
||||
provenance: vec![],
|
||||
};
|
||||
|
||||
let meta = query_result_to_resource_meta(&result, "homelab");
|
||||
|
||||
assert_eq!(meta.resource_type, ResourceType::Skill);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_result_to_resource_meta_private() {
|
||||
let result = crate::query_worker::QueryResult {
|
||||
level: "L2".to_string(),
|
||||
score: 0.7,
|
||||
text: "Private content".to_string(),
|
||||
source: Some("docs/private/secrets.md".to_string()),
|
||||
provenance: vec![],
|
||||
};
|
||||
|
||||
let meta = query_result_to_resource_meta(&result, "homelab");
|
||||
|
||||
assert_eq!(meta.visibility, Visibility::Private);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_result_to_resource_meta_embedding() {
|
||||
let result = crate::query_worker::QueryResult {
|
||||
level: "L1".to_string(),
|
||||
score: 0.85,
|
||||
text: "Learned fact".to_string(),
|
||||
source: Some("memory-123".to_string()),
|
||||
provenance: vec![],
|
||||
};
|
||||
|
||||
let meta = query_result_to_resource_meta(&result, "portfolio");
|
||||
|
||||
assert_eq!(meta.resource_type, ResourceType::Embedding);
|
||||
assert_eq!(meta.project, "portfolio");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_rbac_integration_admin_access() {
|
||||
use std::sync::Arc;
|
||||
use crate::rbac::{builtin_role_provider, AccessGuard};
|
||||
|
||||
let guard = AccessGuard::new(Arc::new(builtin_role_provider()));
|
||||
|
||||
// Admin JWT with roles from Authentik
|
||||
let jwt = JwtClaims {
|
||||
sub: "admin-user".to_string(),
|
||||
iss: "test".to_string(),
|
||||
aud: "memory".to_string(),
|
||||
exp: i64::MAX,
|
||||
iat: 0,
|
||||
nbf: None,
|
||||
permissions: Some(vec!["*".to_string()]),
|
||||
groups: None,
|
||||
roles: Some(vec!["admin".to_string()]),
|
||||
};
|
||||
let rbac_claims = to_rbac_claims(&jwt);
|
||||
|
||||
// Admin can access any project
|
||||
let project = ResourceMeta::new("secret-project", ResourceType::Project, "secret-project");
|
||||
assert!(guard.can_read(&rbac_claims, &project).await);
|
||||
assert!(guard.can_write(&rbac_claims, &project).await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_rbac_integration_portfolio_agent() {
|
||||
use std::sync::Arc;
|
||||
use crate::rbac::{builtin_role_provider, AccessGuard};
|
||||
|
||||
let guard = AccessGuard::new(Arc::new(builtin_role_provider()));
|
||||
|
||||
// Portfolio agent JWT with roles from Authentik
|
||||
let jwt = JwtClaims {
|
||||
sub: "visitor-123".to_string(),
|
||||
iss: "test".to_string(),
|
||||
aud: "memory".to_string(),
|
||||
exp: i64::MAX,
|
||||
iat: 0,
|
||||
nbf: None,
|
||||
permissions: Some(vec!["memory:read".to_string()]),
|
||||
groups: None,
|
||||
roles: Some(vec!["portfolio-agent".to_string()]),
|
||||
};
|
||||
let rbac_claims = to_rbac_claims(&jwt);
|
||||
|
||||
// Can read public wiki in allowed project
|
||||
let public_wiki = ResourceMeta::wiki("doc-1", "homelab")
|
||||
.with_visibility(Visibility::Public);
|
||||
assert!(guard.can_read(&rbac_claims, &public_wiki).await);
|
||||
|
||||
// Cannot read private wiki
|
||||
let private_wiki = ResourceMeta::wiki("secret", "homelab")
|
||||
.with_visibility(Visibility::Private);
|
||||
assert!(!guard.can_read(&rbac_claims, &private_wiki).await);
|
||||
|
||||
// Cannot write to any project
|
||||
let project = ResourceMeta::new("homelab", ResourceType::Project, "homelab");
|
||||
assert!(!guard.can_write(&rbac_claims, &project).await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_rbac_integration_no_role() {
|
||||
use std::sync::Arc;
|
||||
use crate::rbac::{builtin_role_provider, AccessGuard};
|
||||
|
||||
let guard = AccessGuard::new(Arc::new(builtin_role_provider()));
|
||||
|
||||
// JWT with no roles (anonymous user)
|
||||
let jwt = JwtClaims {
|
||||
sub: "anonymous".to_string(),
|
||||
iss: "test".to_string(),
|
||||
aud: "memory".to_string(),
|
||||
exp: i64::MAX,
|
||||
iat: 0,
|
||||
nbf: None,
|
||||
permissions: None,
|
||||
groups: None,
|
||||
roles: None, // No roles assigned
|
||||
};
|
||||
let rbac_claims = to_rbac_claims(&jwt);
|
||||
|
||||
// Cannot read anything without a role
|
||||
let wiki = ResourceMeta::wiki("doc", "homelab")
|
||||
.with_visibility(Visibility::Public);
|
||||
assert!(!guard.can_read(&rbac_claims, &wiki).await);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ fn gate_metadata_preservation() {
|
||||
|
||||
// Verify we get a valid OptimizedChunk with proper fields
|
||||
assert!(optimized.original_tokens > 0, "should track original tokens");
|
||||
assert!(optimized.compressed_tokens >= 0, "should track compressed tokens");
|
||||
assert!(optimized.compressed_tokens <= optimized.original_tokens, "compressed should not exceed original");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -122,7 +122,7 @@ fn gate_error_handling_graceful() {
|
||||
match optimizer.optimize(case.as_str()) {
|
||||
Ok(result) => {
|
||||
// Valid compression
|
||||
assert!(result.original_tokens >= 0);
|
||||
assert!(result.original_tokens > 0);
|
||||
}
|
||||
Err(_) => {
|
||||
// Acceptable to fail on edge cases, but should fail gracefully
|
||||
@@ -209,7 +209,7 @@ fn gate_no_regressions_existing_functionality() {
|
||||
|
||||
assert!(!result.compressed.is_empty(), "basic optimization should work");
|
||||
assert!(result.original_tokens > 0, "should track tokens");
|
||||
assert!(result.compressed_tokens >= 0, "should have compressed tokens");
|
||||
assert!(result.compressed_tokens <= result.original_tokens, "compressed should not exceed original");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -136,13 +136,13 @@ mod tests {
|
||||
access_token: "test".to_string(),
|
||||
token_type: "Bearer".to_string(),
|
||||
expires_in: 3600,
|
||||
obtained_at: SystemTime::now(),
|
||||
obtained_at: Some(SystemTime::now()),
|
||||
};
|
||||
|
||||
assert!(!token.is_expired());
|
||||
|
||||
// Simulate aged token
|
||||
token.obtained_at = SystemTime::now() - Duration::from_secs(3600);
|
||||
token.obtained_at = Some(SystemTime::now() - Duration::from_secs(3600));
|
||||
assert!(token.is_expired());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "chunk-abc123",
|
||||
"level": "L1",
|
||||
"score": 0.95,
|
||||
"text": "Kubernetes uses port 8080 for API server",
|
||||
"source": "transcript://session-001"
|
||||
},
|
||||
{
|
||||
"id": "chunk-def456",
|
||||
"level": "L2",
|
||||
"score": 0.87,
|
||||
"text": "Common debugging pattern for CrashLoopBackOff pods",
|
||||
"source": "transcript://session-002"
|
||||
},
|
||||
{
|
||||
"id": "chunk-ghi789",
|
||||
"level": "R",
|
||||
"score": 0.72,
|
||||
"text": "See kubectl troubleshooting guide section 3.2",
|
||||
"source": "obsidian://poimen-vault/kubectl.md"
|
||||
}
|
||||
],
|
||||
"total_hits": 127,
|
||||
"search_time_ms": 145,
|
||||
"query": "fix kubernetes port conflict"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# Kubernetes Troubleshooting Guide
|
||||
|
||||
## Port Conflicts
|
||||
|
||||
When a port conflict occurs on port 8080, check for existing services:
|
||||
|
||||
```bash
|
||||
kubectl get svc --all-namespaces | grep 8080
|
||||
```
|
||||
|
||||
### Common Causes
|
||||
|
||||
1. Multiple services binding to same NodePort
|
||||
2. Host network pods conflicting with node services
|
||||
3. Ingress controller port overlap
|
||||
|
||||
## CrashLoopBackOff
|
||||
|
||||
Pods enter CrashLoopBackOff when the container exits repeatedly.
|
||||
|
||||
### Diagnosis Steps
|
||||
|
||||
1. Check pod logs: `kubectl logs <pod> --previous`
|
||||
2. Check events: `kubectl describe pod <pod>`
|
||||
3. Check resource limits: memory/CPU constraints
|
||||
4. Check liveness probes: incorrect health check paths
|
||||
|
||||
### Resolution
|
||||
|
||||
- Increase memory limits if OOMKilled
|
||||
- Fix application startup errors
|
||||
- Adjust probe timing (initialDelaySeconds)
|
||||
- Check environment variable configuration
|
||||
@@ -0,0 +1,16 @@
|
||||
2025-01-15T10:00:00Z INFO Starting service on port 8080
|
||||
2025-01-15T10:00:01Z DEBUG Database connection pool initialized (max=20)
|
||||
2025-01-15T10:00:02Z INFO Health check endpoint ready at /health
|
||||
2025-01-15T10:00:05Z WARN High memory usage detected: 85% of 512Mi limit
|
||||
2025-01-15T10:00:10Z ERROR Connection refused: temporal-frontend:7233
|
||||
2025-01-15T10:00:15Z INFO Retry attempt 1/3 for temporal connection
|
||||
2025-01-15T10:00:20Z INFO Connected to temporal-frontend.temporal.svc.cluster.local:7233
|
||||
2025-01-15T10:00:25Z DEBUG Worker registered on task queue: poimen-taskqueue
|
||||
2025-01-15T10:00:30Z INFO Processing ingest request: project=poimen source=transcript://session-001
|
||||
2025-01-15T10:00:31Z DEBUG Entity extraction complete: 5 entities found
|
||||
2025-01-15T10:00:32Z DEBUG Fact extraction complete: 3 facts found
|
||||
2025-01-15T10:00:33Z INFO Contradiction check: 0 contradictions detected
|
||||
2025-01-15T10:00:34Z INFO Ingest complete: chunk-abc123 (145ms)
|
||||
2025-01-15T10:00:40Z WARN Slow query detected: 850ms for hybrid search
|
||||
2025-01-15T10:00:45Z ERROR Pod OOMKilled: poimen-worker-abc123 (memory limit exceeded)
|
||||
2025-01-15T10:00:50Z INFO Pod restarted: poimen-worker-abc123 (restart count: 1)
|
||||
Reference in New Issue
Block a user