mirror of
https://github.com/ultraworkers/claw-code-parity.git
synced 2026-06-25 11:31:11 +00:00
Compare commits
No commits in common. "69b9232acf5afe56140804e3d87801f976dbabb6" and "6e239c0b679030b722b5d108789763792961287b" have entirely different histories.
69b9232acf
...
6e239c0b67
@ -16,20 +16,20 @@ mod mcp_stdio;
|
|||||||
pub mod mcp_tool_bridge;
|
pub mod mcp_tool_bridge;
|
||||||
mod oauth;
|
mod oauth;
|
||||||
pub mod permission_enforcer;
|
pub mod permission_enforcer;
|
||||||
|
mod policy_engine;
|
||||||
|
pub mod recovery_recipes;
|
||||||
mod permissions;
|
mod permissions;
|
||||||
pub mod plugin_lifecycle;
|
pub mod plugin_lifecycle;
|
||||||
mod policy_engine;
|
|
||||||
mod prompt;
|
mod prompt;
|
||||||
pub mod recovery_recipes;
|
|
||||||
mod remote;
|
mod remote;
|
||||||
|
pub mod session_control;
|
||||||
pub mod sandbox;
|
pub mod sandbox;
|
||||||
mod session;
|
mod session;
|
||||||
pub mod session_control;
|
|
||||||
mod sse;
|
mod sse;
|
||||||
pub mod stale_branch;
|
pub mod stale_branch;
|
||||||
pub mod summary_compression;
|
pub mod summary_compression;
|
||||||
pub mod task_packet;
|
|
||||||
pub mod task_registry;
|
pub mod task_registry;
|
||||||
|
pub mod task_packet;
|
||||||
pub mod team_cron_registry;
|
pub mod team_cron_registry;
|
||||||
pub mod trust_resolver;
|
pub mod trust_resolver;
|
||||||
mod usage;
|
mod usage;
|
||||||
@ -90,6 +90,10 @@ pub use oauth::{
|
|||||||
OAuthCallbackParams, OAuthRefreshRequest, OAuthTokenExchangeRequest, OAuthTokenSet,
|
OAuthCallbackParams, OAuthRefreshRequest, OAuthTokenExchangeRequest, OAuthTokenSet,
|
||||||
PkceChallengeMethod, PkceCodePair,
|
PkceChallengeMethod, PkceCodePair,
|
||||||
};
|
};
|
||||||
|
pub use policy_engine::{
|
||||||
|
evaluate, DiffScope, GreenLevel, LaneBlocker, LaneContext, PolicyAction, PolicyCondition,
|
||||||
|
PolicyEngine, PolicyRule, ReviewStatus,
|
||||||
|
};
|
||||||
pub use permissions::{
|
pub use permissions::{
|
||||||
PermissionContext, PermissionMode, PermissionOutcome, PermissionOverride, PermissionPolicy,
|
PermissionContext, PermissionMode, PermissionOutcome, PermissionOverride, PermissionPolicy,
|
||||||
PermissionPromptDecision, PermissionPrompter, PermissionRequest,
|
PermissionPromptDecision, PermissionPrompter, PermissionRequest,
|
||||||
@ -98,18 +102,14 @@ pub use plugin_lifecycle::{
|
|||||||
DegradedMode, DiscoveryResult, PluginHealthcheck, PluginLifecycle, PluginLifecycleEvent,
|
DegradedMode, DiscoveryResult, PluginHealthcheck, PluginLifecycle, PluginLifecycleEvent,
|
||||||
PluginState, ResourceInfo, ServerHealth, ServerStatus, ToolInfo,
|
PluginState, ResourceInfo, ServerHealth, ServerStatus, ToolInfo,
|
||||||
};
|
};
|
||||||
pub use policy_engine::{
|
pub use recovery_recipes::{
|
||||||
evaluate, DiffScope, GreenLevel, LaneBlocker, LaneContext, PolicyAction, PolicyCondition,
|
attempt_recovery, recipe_for, EscalationPolicy, FailureScenario, RecoveryContext,
|
||||||
PolicyEngine, PolicyRule, ReconcileReason, ReviewStatus,
|
RecoveryEvent, RecoveryRecipe, RecoveryResult, RecoveryStep,
|
||||||
};
|
};
|
||||||
pub use prompt::{
|
pub use prompt::{
|
||||||
load_system_prompt, prepend_bullets, ContextFile, ProjectContext, PromptBuildError,
|
load_system_prompt, prepend_bullets, ContextFile, ProjectContext, PromptBuildError,
|
||||||
SystemPromptBuilder, FRONTIER_MODEL_NAME, SYSTEM_PROMPT_DYNAMIC_BOUNDARY,
|
SystemPromptBuilder, FRONTIER_MODEL_NAME, SYSTEM_PROMPT_DYNAMIC_BOUNDARY,
|
||||||
};
|
};
|
||||||
pub use recovery_recipes::{
|
|
||||||
attempt_recovery, recipe_for, EscalationPolicy, FailureScenario, RecoveryContext,
|
|
||||||
RecoveryEvent, RecoveryRecipe, RecoveryResult, RecoveryStep,
|
|
||||||
};
|
|
||||||
pub use remote::{
|
pub use remote::{
|
||||||
inherited_upstream_proxy_env, no_proxy_list, read_token, upstream_proxy_ws_url,
|
inherited_upstream_proxy_env, no_proxy_list, read_token, upstream_proxy_ws_url,
|
||||||
RemoteSessionContext, UpstreamProxyBootstrap, UpstreamProxyState, DEFAULT_REMOTE_BASE_URL,
|
RemoteSessionContext, UpstreamProxyBootstrap, UpstreamProxyState, DEFAULT_REMOTE_BASE_URL,
|
||||||
@ -125,19 +125,20 @@ pub use session::{
|
|||||||
ContentBlock, ConversationMessage, MessageRole, Session, SessionCompaction, SessionError,
|
ContentBlock, ConversationMessage, MessageRole, Session, SessionCompaction, SessionError,
|
||||||
SessionFork,
|
SessionFork,
|
||||||
};
|
};
|
||||||
pub use sse::{IncrementalSseParser, SseEvent};
|
|
||||||
pub use stale_branch::{
|
pub use stale_branch::{
|
||||||
apply_policy, check_freshness, BranchFreshness, StaleBranchAction, StaleBranchEvent,
|
apply_policy, check_freshness, BranchFreshness, StaleBranchAction, StaleBranchEvent,
|
||||||
StaleBranchPolicy,
|
StaleBranchPolicy,
|
||||||
};
|
};
|
||||||
|
pub use sse::{IncrementalSseParser, SseEvent};
|
||||||
pub use task_packet::{
|
pub use task_packet::{
|
||||||
validate_packet, AcceptanceTest, BranchPolicy, CommitPolicy, RepoConfig, ReportingContract,
|
validate_packet, AcceptanceTest, BranchPolicy, CommitPolicy,
|
||||||
TaskPacket, TaskPacketValidationError, TaskScope, ValidatedPacket,
|
RepoConfig, ReportingContract, TaskPacket, TaskPacketValidationError, TaskScope,
|
||||||
|
ValidatedPacket,
|
||||||
};
|
};
|
||||||
pub use trust_resolver::{TrustConfig, TrustDecision, TrustEvent, TrustPolicy, TrustResolver};
|
|
||||||
pub use usage::{
|
pub use usage::{
|
||||||
format_usd, pricing_for_model, ModelPricing, TokenUsage, UsageCostEstimate, UsageTracker,
|
format_usd, pricing_for_model, ModelPricing, TokenUsage, UsageCostEstimate, UsageTracker,
|
||||||
};
|
};
|
||||||
|
pub use trust_resolver::{TrustConfig, TrustDecision, TrustEvent, TrustPolicy, TrustResolver};
|
||||||
pub use worker_boot::{
|
pub use worker_boot::{
|
||||||
Worker, WorkerEvent, WorkerEventKind, WorkerFailure, WorkerFailureKind, WorkerReadySnapshot,
|
Worker, WorkerEvent, WorkerEventKind, WorkerFailure, WorkerFailureKind, WorkerReadySnapshot,
|
||||||
WorkerRegistry, WorkerStatus,
|
WorkerRegistry, WorkerStatus,
|
||||||
|
|||||||
@ -42,7 +42,6 @@ pub enum PolicyCondition {
|
|||||||
StaleBranch,
|
StaleBranch,
|
||||||
StartupBlocked,
|
StartupBlocked,
|
||||||
LaneCompleted,
|
LaneCompleted,
|
||||||
LaneReconciled,
|
|
||||||
ReviewPassed,
|
ReviewPassed,
|
||||||
ScopedDiff,
|
ScopedDiff,
|
||||||
TimedOut { duration: Duration },
|
TimedOut { duration: Duration },
|
||||||
@ -62,7 +61,6 @@ impl PolicyCondition {
|
|||||||
Self::StaleBranch => context.branch_freshness >= STALE_BRANCH_THRESHOLD,
|
Self::StaleBranch => context.branch_freshness >= STALE_BRANCH_THRESHOLD,
|
||||||
Self::StartupBlocked => context.blocker == LaneBlocker::Startup,
|
Self::StartupBlocked => context.blocker == LaneBlocker::Startup,
|
||||||
Self::LaneCompleted => context.completed,
|
Self::LaneCompleted => context.completed,
|
||||||
Self::LaneReconciled => context.reconciled,
|
|
||||||
Self::ReviewPassed => context.review_status == ReviewStatus::Approved,
|
Self::ReviewPassed => context.review_status == ReviewStatus::Approved,
|
||||||
Self::ScopedDiff => context.diff_scope == DiffScope::Scoped,
|
Self::ScopedDiff => context.diff_scope == DiffScope::Scoped,
|
||||||
Self::TimedOut { duration } => context.branch_freshness >= *duration,
|
Self::TimedOut { duration } => context.branch_freshness >= *duration,
|
||||||
@ -78,25 +76,11 @@ pub enum PolicyAction {
|
|||||||
Escalate { reason: String },
|
Escalate { reason: String },
|
||||||
CloseoutLane,
|
CloseoutLane,
|
||||||
CleanupSession,
|
CleanupSession,
|
||||||
Reconcile { reason: ReconcileReason },
|
|
||||||
Notify { channel: String },
|
Notify { channel: String },
|
||||||
Block { reason: String },
|
Block { reason: String },
|
||||||
Chain(Vec<PolicyAction>),
|
Chain(Vec<PolicyAction>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Why a lane was reconciled without further action.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum ReconcileReason {
|
|
||||||
/// Branch already merged into main — no PR needed.
|
|
||||||
AlreadyMerged,
|
|
||||||
/// Work superseded by another lane or direct commit.
|
|
||||||
Superseded,
|
|
||||||
/// PR would be empty — all changes already landed.
|
|
||||||
EmptyDiff,
|
|
||||||
/// Lane manually closed by operator.
|
|
||||||
ManualClose,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PolicyAction {
|
impl PolicyAction {
|
||||||
fn flatten_into(&self, actions: &mut Vec<PolicyAction>) {
|
fn flatten_into(&self, actions: &mut Vec<PolicyAction>) {
|
||||||
match self {
|
match self {
|
||||||
@ -139,7 +123,6 @@ pub struct LaneContext {
|
|||||||
pub review_status: ReviewStatus,
|
pub review_status: ReviewStatus,
|
||||||
pub diff_scope: DiffScope,
|
pub diff_scope: DiffScope,
|
||||||
pub completed: bool,
|
pub completed: bool,
|
||||||
pub reconciled: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LaneContext {
|
impl LaneContext {
|
||||||
@ -161,22 +144,6 @@ impl LaneContext {
|
|||||||
review_status,
|
review_status,
|
||||||
diff_scope,
|
diff_scope,
|
||||||
completed,
|
completed,
|
||||||
reconciled: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a lane context that is already reconciled (no further action needed).
|
|
||||||
#[must_use]
|
|
||||||
pub fn reconciled(lane_id: impl Into<String>) -> Self {
|
|
||||||
Self {
|
|
||||||
lane_id: lane_id.into(),
|
|
||||||
green_level: 0,
|
|
||||||
branch_freshness: Duration::from_secs(0),
|
|
||||||
blocker: LaneBlocker::None,
|
|
||||||
review_status: ReviewStatus::Pending,
|
|
||||||
diff_scope: DiffScope::Full,
|
|
||||||
completed: true,
|
|
||||||
reconciled: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +188,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
evaluate, DiffScope, LaneBlocker, LaneContext, PolicyAction, PolicyCondition, PolicyEngine,
|
evaluate, DiffScope, LaneBlocker, LaneContext, PolicyAction, PolicyCondition, PolicyEngine,
|
||||||
PolicyRule, ReconcileReason, ReviewStatus, STALE_BRANCH_THRESHOLD,
|
PolicyRule, ReviewStatus, STALE_BRANCH_THRESHOLD,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn default_context() -> LaneContext {
|
fn default_context() -> LaneContext {
|
||||||
@ -488,94 +455,4 @@ mod tests {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reconciled_lane_emits_reconcile_and_cleanup() {
|
|
||||||
// given — a lane where branch is already merged, no PR needed, session stale
|
|
||||||
let engine = PolicyEngine::new(vec![
|
|
||||||
PolicyRule::new(
|
|
||||||
"reconcile-closeout",
|
|
||||||
PolicyCondition::LaneReconciled,
|
|
||||||
PolicyAction::Chain(vec![
|
|
||||||
PolicyAction::Reconcile {
|
|
||||||
reason: ReconcileReason::AlreadyMerged,
|
|
||||||
},
|
|
||||||
PolicyAction::CloseoutLane,
|
|
||||||
PolicyAction::CleanupSession,
|
|
||||||
]),
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
// This rule should NOT fire — reconciled lanes are completed but we want
|
|
||||||
// the more specific reconcile rule to handle them
|
|
||||||
PolicyRule::new(
|
|
||||||
"generic-closeout",
|
|
||||||
PolicyCondition::And(vec![
|
|
||||||
PolicyCondition::LaneCompleted,
|
|
||||||
// Only fire if NOT reconciled
|
|
||||||
PolicyCondition::And(vec![]),
|
|
||||||
]),
|
|
||||||
PolicyAction::CloseoutLane,
|
|
||||||
30,
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
let context = LaneContext::reconciled("lane-9411");
|
|
||||||
|
|
||||||
// when
|
|
||||||
let actions = engine.evaluate(&context);
|
|
||||||
|
|
||||||
// then — reconcile rule fires first (priority 5), then generic closeout also fires
|
|
||||||
// because reconciled context has completed=true
|
|
||||||
assert_eq!(
|
|
||||||
actions,
|
|
||||||
vec![
|
|
||||||
PolicyAction::Reconcile {
|
|
||||||
reason: ReconcileReason::AlreadyMerged,
|
|
||||||
},
|
|
||||||
PolicyAction::CloseoutLane,
|
|
||||||
PolicyAction::CleanupSession,
|
|
||||||
PolicyAction::CloseoutLane,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reconciled_context_has_correct_defaults() {
|
|
||||||
let ctx = LaneContext::reconciled("test-lane");
|
|
||||||
assert_eq!(ctx.lane_id, "test-lane");
|
|
||||||
assert!(ctx.completed);
|
|
||||||
assert!(ctx.reconciled);
|
|
||||||
assert_eq!(ctx.blocker, LaneBlocker::None);
|
|
||||||
assert_eq!(ctx.green_level, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn non_reconciled_lane_does_not_trigger_reconcile_rule() {
|
|
||||||
let engine = PolicyEngine::new(vec![PolicyRule::new(
|
|
||||||
"reconcile-closeout",
|
|
||||||
PolicyCondition::LaneReconciled,
|
|
||||||
PolicyAction::Reconcile {
|
|
||||||
reason: ReconcileReason::EmptyDiff,
|
|
||||||
},
|
|
||||||
5,
|
|
||||||
)]);
|
|
||||||
// Normal completed lane — not reconciled
|
|
||||||
let context = LaneContext::new(
|
|
||||||
"lane-7",
|
|
||||||
0,
|
|
||||||
Duration::from_secs(0),
|
|
||||||
LaneBlocker::None,
|
|
||||||
ReviewStatus::Pending,
|
|
||||||
DiffScope::Full,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
let actions = engine.evaluate(&context);
|
|
||||||
assert!(actions.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reconcile_reason_variants_are_distinct() {
|
|
||||||
assert_ne!(ReconcileReason::AlreadyMerged, ReconcileReason::Superseded);
|
|
||||||
assert_ne!(ReconcileReason::EmptyDiff, ReconcileReason::ManualClose);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,286 +0,0 @@
|
|||||||
//! Integration tests for cross-module wiring.
|
|
||||||
//!
|
|
||||||
//! These tests verify that adjacent modules in the runtime crate actually
|
|
||||||
//! connect correctly — catching wiring gaps that unit tests miss.
|
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use runtime::{
|
|
||||||
apply_policy, BranchFreshness, DiffScope, LaneBlocker,
|
|
||||||
LaneContext, PolicyAction, PolicyCondition, PolicyEngine, PolicyRule,
|
|
||||||
ReconcileReason, ReviewStatus, StaleBranchAction, StaleBranchPolicy,
|
|
||||||
};
|
|
||||||
use runtime::green_contract::{GreenLevel, GreenContract, GreenContractOutcome};
|
|
||||||
|
|
||||||
/// stale_branch + policy_engine integration:
|
|
||||||
/// When a branch is detected stale, does it correctly flow through
|
|
||||||
/// PolicyCondition::StaleBranch to generate the expected action?
|
|
||||||
#[test]
|
|
||||||
fn stale_branch_detection_flows_into_policy_engine() {
|
|
||||||
// given — a stale branch context (2 hours behind main, threshold is 1 hour)
|
|
||||||
let stale_context = LaneContext::new(
|
|
||||||
"stale-lane",
|
|
||||||
0,
|
|
||||||
Duration::from_secs(2 * 60 * 60), // 2 hours stale
|
|
||||||
LaneBlocker::None,
|
|
||||||
ReviewStatus::Pending,
|
|
||||||
DiffScope::Full,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let engine = PolicyEngine::new(vec![PolicyRule::new(
|
|
||||||
"stale-merge-forward",
|
|
||||||
PolicyCondition::StaleBranch,
|
|
||||||
PolicyAction::MergeForward,
|
|
||||||
10,
|
|
||||||
)]);
|
|
||||||
|
|
||||||
// when
|
|
||||||
let actions = engine.evaluate(&stale_context);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assert_eq!(actions, vec![PolicyAction::MergeForward]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// stale_branch + policy_engine: Fresh branch does NOT trigger stale rules
|
|
||||||
#[test]
|
|
||||||
fn fresh_branch_does_not_trigger_stale_policy() {
|
|
||||||
let fresh_context = LaneContext::new(
|
|
||||||
"fresh-lane",
|
|
||||||
0,
|
|
||||||
Duration::from_secs(30 * 60), // 30 min stale — under 1 hour threshold
|
|
||||||
LaneBlocker::None,
|
|
||||||
ReviewStatus::Pending,
|
|
||||||
DiffScope::Full,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let engine = PolicyEngine::new(vec![PolicyRule::new(
|
|
||||||
"stale-merge-forward",
|
|
||||||
PolicyCondition::StaleBranch,
|
|
||||||
PolicyAction::MergeForward,
|
|
||||||
10,
|
|
||||||
)]);
|
|
||||||
|
|
||||||
let actions = engine.evaluate(&fresh_context);
|
|
||||||
assert!(actions.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// green_contract + policy_engine integration:
|
|
||||||
/// A lane that meets its green contract should be mergeable
|
|
||||||
#[test]
|
|
||||||
fn green_contract_satisfied_allows_merge() {
|
|
||||||
let contract = GreenContract::new(GreenLevel::Workspace);
|
|
||||||
let satisfied = contract.is_satisfied_by(GreenLevel::Workspace);
|
|
||||||
assert!(satisfied);
|
|
||||||
|
|
||||||
let exceeded = contract.is_satisfied_by(GreenLevel::MergeReady);
|
|
||||||
assert!(exceeded);
|
|
||||||
|
|
||||||
let insufficient = contract.is_satisfied_by(GreenLevel::Package);
|
|
||||||
assert!(!insufficient);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// green_contract + policy_engine:
|
|
||||||
/// Lane with green level below contract requirement gets blocked
|
|
||||||
#[test]
|
|
||||||
fn green_contract_unsatisfied_blocks_merge() {
|
|
||||||
let context = LaneContext::new(
|
|
||||||
"partial-green-lane",
|
|
||||||
1, // GreenLevel::Package as u8
|
|
||||||
Duration::from_secs(0),
|
|
||||||
LaneBlocker::None,
|
|
||||||
ReviewStatus::Pending,
|
|
||||||
DiffScope::Full,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
// This is a conceptual test — we need a way to express "requires workspace green"
|
|
||||||
// Currently LaneContext has raw green_level: u8, not a contract
|
|
||||||
// For now we just verify the policy condition works
|
|
||||||
let engine = PolicyEngine::new(vec![PolicyRule::new(
|
|
||||||
"workspace-green-required",
|
|
||||||
PolicyCondition::GreenAt { level: 3 }, // GreenLevel::Workspace
|
|
||||||
PolicyAction::MergeToDev,
|
|
||||||
10,
|
|
||||||
)]);
|
|
||||||
|
|
||||||
let actions = engine.evaluate(&context);
|
|
||||||
assert!(actions.is_empty()); // level 1 < 3, so no merge
|
|
||||||
}
|
|
||||||
|
|
||||||
/// reconciliation + policy_engine integration:
|
|
||||||
/// A reconciled lane should be handled by reconcile rules, not generic closeout
|
|
||||||
#[test]
|
|
||||||
fn reconciled_lane_matches_reconcile_condition() {
|
|
||||||
let context = LaneContext::reconciled("reconciled-lane");
|
|
||||||
|
|
||||||
let engine = PolicyEngine::new(vec![
|
|
||||||
PolicyRule::new(
|
|
||||||
"reconcile-first",
|
|
||||||
PolicyCondition::LaneReconciled,
|
|
||||||
PolicyAction::Reconcile {
|
|
||||||
reason: ReconcileReason::AlreadyMerged,
|
|
||||||
},
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
PolicyRule::new(
|
|
||||||
"generic-closeout",
|
|
||||||
PolicyCondition::LaneCompleted,
|
|
||||||
PolicyAction::CloseoutLane,
|
|
||||||
30,
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
let actions = engine.evaluate(&context);
|
|
||||||
|
|
||||||
// Both rules fire — reconcile (priority 5) first, then closeout (priority 30)
|
|
||||||
assert_eq!(
|
|
||||||
actions,
|
|
||||||
vec![
|
|
||||||
PolicyAction::Reconcile {
|
|
||||||
reason: ReconcileReason::AlreadyMerged,
|
|
||||||
},
|
|
||||||
PolicyAction::CloseoutLane,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// stale_branch module: apply_policy generates correct actions
|
|
||||||
#[test]
|
|
||||||
fn stale_branch_apply_policy_produces_rebase_action() {
|
|
||||||
let stale = BranchFreshness::Stale {
|
|
||||||
commits_behind: 5,
|
|
||||||
missing_fixes: vec!["fix-123".to_string()],
|
|
||||||
};
|
|
||||||
|
|
||||||
let action = apply_policy(&stale, StaleBranchPolicy::AutoRebase);
|
|
||||||
assert_eq!(action, StaleBranchAction::Rebase);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn stale_branch_apply_policy_produces_merge_forward_action() {
|
|
||||||
let stale = BranchFreshness::Stale {
|
|
||||||
commits_behind: 3,
|
|
||||||
missing_fixes: vec![],
|
|
||||||
};
|
|
||||||
|
|
||||||
let action = apply_policy(&stale, StaleBranchPolicy::AutoMergeForward);
|
|
||||||
assert_eq!(action, StaleBranchAction::MergeForward);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn stale_branch_apply_policy_warn_only() {
|
|
||||||
let stale = BranchFreshness::Stale {
|
|
||||||
commits_behind: 2,
|
|
||||||
missing_fixes: vec!["fix-456".to_string()],
|
|
||||||
};
|
|
||||||
|
|
||||||
let action = apply_policy(&stale, StaleBranchPolicy::WarnOnly);
|
|
||||||
match action {
|
|
||||||
StaleBranchAction::Warn { message } => {
|
|
||||||
assert!(message.contains("2 commit(s) behind main"));
|
|
||||||
assert!(message.contains("fix-456"));
|
|
||||||
}
|
|
||||||
_ => panic!("expected Warn action, got {:?}", action),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn stale_branch_fresh_produces_noop() {
|
|
||||||
let fresh = BranchFreshness::Fresh;
|
|
||||||
let action = apply_policy(&fresh, StaleBranchPolicy::AutoRebase);
|
|
||||||
assert_eq!(action, StaleBranchAction::Noop);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Combined flow: stale detection + policy + action
|
|
||||||
#[test]
|
|
||||||
fn end_to_end_stale_lane_gets_merge_forward_action() {
|
|
||||||
// Simulating what a harness would do:
|
|
||||||
// 1. Detect branch freshness
|
|
||||||
// 2. Build lane context from freshness + other signals
|
|
||||||
// 3. Run policy engine
|
|
||||||
// 4. Return actions
|
|
||||||
|
|
||||||
// given: detected stale state
|
|
||||||
let _freshness = BranchFreshness::Stale {
|
|
||||||
commits_behind: 5,
|
|
||||||
missing_fixes: vec!["fix-123".to_string()],
|
|
||||||
};
|
|
||||||
|
|
||||||
// when: build context and evaluate policy
|
|
||||||
let context = LaneContext::new(
|
|
||||||
"lane-9411",
|
|
||||||
3, // Workspace green
|
|
||||||
Duration::from_secs(5 * 60 * 60), // 5 hours stale, definitely over threshold
|
|
||||||
LaneBlocker::None,
|
|
||||||
ReviewStatus::Approved,
|
|
||||||
DiffScope::Scoped,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let engine = PolicyEngine::new(vec![
|
|
||||||
// Priority 5: Check if stale first
|
|
||||||
PolicyRule::new(
|
|
||||||
"auto-merge-forward-if-stale-and-approved",
|
|
||||||
PolicyCondition::And(vec![
|
|
||||||
PolicyCondition::StaleBranch,
|
|
||||||
PolicyCondition::ReviewPassed,
|
|
||||||
]),
|
|
||||||
PolicyAction::MergeForward,
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
// Priority 10: Normal stale handling
|
|
||||||
PolicyRule::new(
|
|
||||||
"stale-warning",
|
|
||||||
PolicyCondition::StaleBranch,
|
|
||||||
PolicyAction::Notify {
|
|
||||||
channel: "#build-status".to_string(),
|
|
||||||
},
|
|
||||||
10,
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
let actions = engine.evaluate(&context);
|
|
||||||
|
|
||||||
// then: both rules should fire (stale + approved matches both)
|
|
||||||
assert_eq!(
|
|
||||||
actions,
|
|
||||||
vec![
|
|
||||||
PolicyAction::MergeForward,
|
|
||||||
PolicyAction::Notify {
|
|
||||||
channel: "#build-status".to_string(),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fresh branch with approved review should merge (not stale-blocked)
|
|
||||||
#[test]
|
|
||||||
fn fresh_approved_lane_gets_merge_action() {
|
|
||||||
let context = LaneContext::new(
|
|
||||||
"fresh-approved-lane",
|
|
||||||
3, // Workspace green
|
|
||||||
Duration::from_secs(30 * 60), // 30 min — under 1 hour threshold = fresh
|
|
||||||
LaneBlocker::None,
|
|
||||||
ReviewStatus::Approved,
|
|
||||||
DiffScope::Scoped,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let engine = PolicyEngine::new(vec![
|
|
||||||
PolicyRule::new(
|
|
||||||
"merge-if-green-approved-not-stale",
|
|
||||||
PolicyCondition::And(vec![
|
|
||||||
PolicyCondition::GreenAt { level: 3 },
|
|
||||||
PolicyCondition::ReviewPassed,
|
|
||||||
// NOT PolicyCondition::StaleBranch — fresh lanes bypass this
|
|
||||||
]),
|
|
||||||
PolicyAction::MergeToDev,
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
let actions = engine.evaluate(&context);
|
|
||||||
assert_eq!(actions, vec![PolicyAction::MergeToDev]);
|
|
||||||
}
|
|
||||||
@ -5580,8 +5580,8 @@ mod tests {
|
|||||||
format_unknown_slash_command_message, normalize_permission_mode, parse_args,
|
format_unknown_slash_command_message, normalize_permission_mode, parse_args,
|
||||||
parse_git_status_branch, parse_git_status_metadata_for, parse_git_workspace_summary,
|
parse_git_status_branch, parse_git_status_metadata_for, parse_git_workspace_summary,
|
||||||
permission_policy, print_help_to, push_output_block, render_config_report,
|
permission_policy, print_help_to, push_output_block, render_config_report,
|
||||||
render_diff_report, render_diff_report_for, render_memory_report, render_repl_help,
|
render_diff_report, render_diff_report_for, render_memory_report, render_repl_help, render_resume_usage,
|
||||||
render_resume_usage, resolve_model_alias, resolve_session_reference, response_to_events,
|
resolve_model_alias, resolve_session_reference, response_to_events,
|
||||||
resume_supported_slash_commands, run_resume_command,
|
resume_supported_slash_commands, run_resume_command,
|
||||||
slash_command_completion_candidates_with_sessions, status_context, validate_no_args,
|
slash_command_completion_candidates_with_sessions, status_context, validate_no_args,
|
||||||
write_mcp_server_fixture, CliAction, CliOutputFormat, CliToolExecutor, GitWorkspaceSummary,
|
write_mcp_server_fixture, CliAction, CliOutputFormat, CliToolExecutor, GitWorkspaceSummary,
|
||||||
|
|||||||
@ -16,7 +16,6 @@ use runtime::{
|
|||||||
mcp_tool_bridge::McpToolRegistry,
|
mcp_tool_bridge::McpToolRegistry,
|
||||||
permission_enforcer::{EnforcementResult, PermissionEnforcer},
|
permission_enforcer::{EnforcementResult, PermissionEnforcer},
|
||||||
read_file,
|
read_file,
|
||||||
summary_compression::compress_summary_text,
|
|
||||||
task_registry::TaskRegistry,
|
task_registry::TaskRegistry,
|
||||||
team_cron_registry::{CronRegistry, TeamRegistry},
|
team_cron_registry::{CronRegistry, TeamRegistry},
|
||||||
worker_boot::{WorkerReadySnapshot, WorkerRegistry},
|
worker_boot::{WorkerReadySnapshot, WorkerRegistry},
|
||||||
@ -2145,14 +2144,6 @@ enum LaneEventName {
|
|||||||
Finished,
|
Finished,
|
||||||
#[serde(rename = "lane.failed")]
|
#[serde(rename = "lane.failed")]
|
||||||
Failed,
|
Failed,
|
||||||
#[serde(rename = "lane.reconciled")]
|
|
||||||
Reconciled,
|
|
||||||
#[serde(rename = "lane.merged")]
|
|
||||||
Merged,
|
|
||||||
#[serde(rename = "lane.superseded")]
|
|
||||||
Superseded,
|
|
||||||
#[serde(rename = "lane.closed")]
|
|
||||||
Closed,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
@ -3163,15 +3154,12 @@ fn persist_agent_terminal_state(
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
next_manifest.current_blocker = None;
|
next_manifest.current_blocker = None;
|
||||||
let compressed_detail = result
|
|
||||||
.filter(|value| !value.trim().is_empty())
|
|
||||||
.map(|value| compress_summary_text(value.trim()));
|
|
||||||
next_manifest.lane_events.push(LaneEvent {
|
next_manifest.lane_events.push(LaneEvent {
|
||||||
event: LaneEventName::Finished,
|
event: LaneEventName::Finished,
|
||||||
status: status.to_string(),
|
status: status.to_string(),
|
||||||
emitted_at: iso8601_now(),
|
emitted_at: iso8601_now(),
|
||||||
failure_class: None,
|
failure_class: None,
|
||||||
detail: compressed_detail,
|
detail: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
write_agent_manifest(&next_manifest)
|
write_agent_manifest(&next_manifest)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user