Move acceptance mutation construction into core
This commit is contained in:
parent
06789466ba
commit
51efe1c962
5 changed files with 285 additions and 216 deletions
|
|
@ -1,47 +1,56 @@
|
|||
use epiphany_core::EpiphanyReorientAcceptanceFinding;
|
||||
use epiphany_core::EpiphanyReorientFindingInterpretation as CoreEpiphanyReorientFinding;
|
||||
use epiphany_core::EpiphanyRoleAcceptanceFinding;
|
||||
use epiphany_core::EpiphanyRoleFindingInterpretation as CoreEpiphanyRoleFinding;
|
||||
use epiphany_core::EpiphanyRoleResultRoleId;
|
||||
use epiphany_core::EpiphanyRoleStatePatchDocument;
|
||||
use epiphany_core::EpiphanyStateUpdate;
|
||||
use epiphany_core::EpiphanyStateUpdatedField;
|
||||
use epiphany_core::MindGatewayReview;
|
||||
use epiphany_core::build_reorient_acceptance_bundle;
|
||||
use epiphany_core::build_role_acceptance_bundle;
|
||||
use epiphany_core::imagination_role_state_patch_policy_errors;
|
||||
use epiphany_core::mind_review_allows_state;
|
||||
use epiphany_core::mind_review_reorient_acceptance;
|
||||
use epiphany_core::mind_review_role_acceptance;
|
||||
use epiphany_core::modeling_role_state_patch_policy_errors;
|
||||
use epiphany_state_model::EpiphanyInvestigationCheckpoint;
|
||||
|
||||
pub struct RoleAcceptanceUpdate {
|
||||
pub state_update: EpiphanyStateUpdate,
|
||||
pub applied_patch: EpiphanyRoleStatePatchDocument,
|
||||
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
|
||||
pub accepted_receipt_id: String,
|
||||
pub accepted_observation_id: String,
|
||||
pub accepted_evidence_id: String,
|
||||
pub mind_review: MindGatewayReview,
|
||||
}
|
||||
pub type RoleAcceptanceUpdate = epiphany_core::EpiphanyRoleAcceptanceUpdate;
|
||||
pub type ReorientAcceptanceUpdate = epiphany_core::EpiphanyReorientAcceptanceUpdate;
|
||||
|
||||
pub struct ReorientAcceptanceUpdate {
|
||||
pub state_update: EpiphanyStateUpdate,
|
||||
pub changed_fields: Vec<EpiphanyStateUpdatedField>,
|
||||
pub accepted_receipt_id: String,
|
||||
pub accepted_observation_id: String,
|
||||
pub accepted_evidence_id: String,
|
||||
pub mind_review: MindGatewayReview,
|
||||
}
|
||||
|
||||
pub fn parse_core_role_finding_state_patch(
|
||||
pub fn build_role_acceptance_update(
|
||||
expected_revision: Option<u64>,
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
binding_id: &str,
|
||||
finding: &CoreEpiphanyRoleFinding,
|
||||
) -> Result<EpiphanyRoleStatePatchDocument, String> {
|
||||
finding
|
||||
.state_patch
|
||||
.clone()
|
||||
.ok_or_else(|| "completed role finding did not include a reviewable statePatch".to_string())
|
||||
accepted_evidence_id: String,
|
||||
accepted_observation_id: String,
|
||||
accepted_at: String,
|
||||
) -> Result<RoleAcceptanceUpdate, String> {
|
||||
epiphany_core::build_native_role_acceptance_update(
|
||||
expected_revision,
|
||||
role_id,
|
||||
binding_id,
|
||||
finding,
|
||||
accepted_evidence_id,
|
||||
accepted_observation_id,
|
||||
accepted_at,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn build_reorient_acceptance_update(
|
||||
expected_revision: Option<u64>,
|
||||
binding_id: &str,
|
||||
finding: &CoreEpiphanyReorientFinding,
|
||||
accepted_evidence_id: String,
|
||||
accepted_observation_id: String,
|
||||
accepted_at: String,
|
||||
update_scratch: bool,
|
||||
update_investigation_checkpoint: bool,
|
||||
checkpoint: Option<EpiphanyInvestigationCheckpoint>,
|
||||
) -> Result<ReorientAcceptanceUpdate, String> {
|
||||
epiphany_core::build_native_reorient_acceptance_update(
|
||||
expected_revision,
|
||||
binding_id,
|
||||
finding,
|
||||
accepted_evidence_id,
|
||||
accepted_observation_id,
|
||||
accepted_at,
|
||||
update_scratch,
|
||||
update_investigation_checkpoint,
|
||||
checkpoint,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn state_update_from_core_patch(
|
||||
|
|
@ -70,177 +79,6 @@ pub fn state_update_from_core_patch(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn build_role_acceptance_update(
|
||||
expected_revision: Option<u64>,
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
binding_id: &str,
|
||||
finding: &CoreEpiphanyRoleFinding,
|
||||
accepted_evidence_id: String,
|
||||
accepted_observation_id: String,
|
||||
accepted_at: String,
|
||||
) -> Result<RoleAcceptanceUpdate, String> {
|
||||
let mut core_patch = match role_id {
|
||||
EpiphanyRoleResultRoleId::Imagination => {
|
||||
let patch = parse_core_role_finding_state_patch(finding)?;
|
||||
let patch_errors = imagination_role_state_patch_policy_errors(&patch);
|
||||
if !patch_errors.is_empty() {
|
||||
return Err(format!(
|
||||
"imagination role state patch is not acceptable: {}",
|
||||
patch_errors.join("; ")
|
||||
));
|
||||
}
|
||||
patch
|
||||
}
|
||||
EpiphanyRoleResultRoleId::Modeling => {
|
||||
let patch = parse_core_role_finding_state_patch(finding)?;
|
||||
let patch_errors = modeling_role_state_patch_policy_errors(&patch);
|
||||
if !patch_errors.is_empty() {
|
||||
return Err(format!(
|
||||
"modeling role state patch is not acceptable: {}",
|
||||
patch_errors.join("; ")
|
||||
));
|
||||
}
|
||||
patch
|
||||
}
|
||||
EpiphanyRoleResultRoleId::Research => {
|
||||
let patch = parse_core_role_finding_state_patch(finding)?;
|
||||
let patch_errors = epiphany_core::research_role_state_patch_policy_errors(&patch);
|
||||
if !patch_errors.is_empty() {
|
||||
return Err(format!(
|
||||
"research role state patch is not acceptable: {}",
|
||||
patch_errors.join("; ")
|
||||
));
|
||||
}
|
||||
patch
|
||||
}
|
||||
EpiphanyRoleResultRoleId::Verification => EpiphanyRoleStatePatchDocument::default(),
|
||||
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => {
|
||||
return Err(format!(
|
||||
"role {:?} cannot be accepted through roleAccept",
|
||||
role_id
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let projected_fields = epiphany_update_patch_changed_fields(&core_patch)
|
||||
.into_iter()
|
||||
.map(|field| format!("{field:?}"))
|
||||
.collect();
|
||||
let mind_review = mind_review_role_acceptance(binding_id, role_id, finding, &core_patch);
|
||||
mind_review_allows_state(&mind_review)?;
|
||||
let acceptance_bundle = build_role_acceptance_bundle(
|
||||
binding_id,
|
||||
EpiphanyRoleAcceptanceFinding {
|
||||
role_id,
|
||||
verdict: finding.verdict.clone(),
|
||||
summary: finding.summary.clone(),
|
||||
next_safe_move: finding.next_safe_move.clone(),
|
||||
files_inspected: finding.files_inspected.clone(),
|
||||
runtime_result_id: finding.runtime_result_id.clone(),
|
||||
runtime_job_id: finding.runtime_job_id.clone(),
|
||||
projected_fields,
|
||||
},
|
||||
accepted_evidence_id,
|
||||
accepted_observation_id,
|
||||
accepted_at,
|
||||
)?;
|
||||
let accepted_receipt_id = acceptance_bundle.accepted_receipt_id.clone();
|
||||
let accepted_observation_id = acceptance_bundle.accepted_observation_id.clone();
|
||||
let accepted_evidence_id = acceptance_bundle.accepted_evidence_id.clone();
|
||||
core_patch.evidence.push(acceptance_bundle.evidence);
|
||||
core_patch.observations.push(acceptance_bundle.observation);
|
||||
core_patch
|
||||
.acceptance_receipts
|
||||
.push(acceptance_bundle.receipt);
|
||||
let applied_patch = core_patch.clone();
|
||||
let changed_fields = epiphany_update_patch_changed_fields(&applied_patch);
|
||||
let state_update = state_update_from_core_patch(expected_revision, core_patch);
|
||||
|
||||
Ok(RoleAcceptanceUpdate {
|
||||
state_update,
|
||||
applied_patch,
|
||||
changed_fields,
|
||||
accepted_receipt_id,
|
||||
accepted_observation_id,
|
||||
accepted_evidence_id,
|
||||
mind_review,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_reorient_acceptance_update(
|
||||
expected_revision: Option<u64>,
|
||||
binding_id: &str,
|
||||
finding: &CoreEpiphanyReorientFinding,
|
||||
accepted_evidence_id: String,
|
||||
accepted_observation_id: String,
|
||||
accepted_at: String,
|
||||
update_scratch: bool,
|
||||
update_investigation_checkpoint: bool,
|
||||
checkpoint: Option<EpiphanyInvestigationCheckpoint>,
|
||||
) -> Result<ReorientAcceptanceUpdate, String> {
|
||||
let mind_finding = EpiphanyReorientAcceptanceFinding {
|
||||
mode: finding.mode.clone(),
|
||||
summary: finding.summary.clone(),
|
||||
next_safe_move: finding.next_safe_move.clone(),
|
||||
checkpoint_still_valid: finding.checkpoint_still_valid,
|
||||
files_inspected: finding.files_inspected.clone(),
|
||||
runtime_result_id: finding.runtime_result_id.clone(),
|
||||
runtime_job_id: finding.runtime_job_id.clone(),
|
||||
};
|
||||
let mind_review = mind_review_reorient_acceptance(
|
||||
binding_id,
|
||||
&mind_finding,
|
||||
update_scratch,
|
||||
update_investigation_checkpoint,
|
||||
);
|
||||
mind_review_allows_state(&mind_review)?;
|
||||
let acceptance_bundle = build_reorient_acceptance_bundle(
|
||||
binding_id,
|
||||
mind_finding,
|
||||
accepted_evidence_id,
|
||||
accepted_observation_id,
|
||||
accepted_at,
|
||||
update_scratch,
|
||||
update_investigation_checkpoint
|
||||
.then_some(checkpoint)
|
||||
.flatten(),
|
||||
)?;
|
||||
let accepted_receipt_id = acceptance_bundle.accepted_receipt_id.clone();
|
||||
let accepted_observation_id = acceptance_bundle.accepted_observation_id.clone();
|
||||
let accepted_evidence_id = acceptance_bundle.accepted_evidence_id.clone();
|
||||
let scratch = acceptance_bundle.scratch;
|
||||
let investigation_checkpoint = acceptance_bundle.investigation_checkpoint;
|
||||
|
||||
let mut changed_fields = vec![
|
||||
EpiphanyStateUpdatedField::AcceptanceReceipts,
|
||||
EpiphanyStateUpdatedField::Observations,
|
||||
EpiphanyStateUpdatedField::Evidence,
|
||||
];
|
||||
if scratch.is_some() {
|
||||
changed_fields.push(EpiphanyStateUpdatedField::Scratch);
|
||||
}
|
||||
if investigation_checkpoint.is_some() {
|
||||
changed_fields.push(EpiphanyStateUpdatedField::InvestigationCheckpoint);
|
||||
}
|
||||
|
||||
Ok(ReorientAcceptanceUpdate {
|
||||
state_update: EpiphanyStateUpdate {
|
||||
expected_revision,
|
||||
scratch,
|
||||
investigation_checkpoint,
|
||||
acceptance_receipts: vec![acceptance_bundle.receipt],
|
||||
observations: vec![acceptance_bundle.observation],
|
||||
evidence: vec![acceptance_bundle.evidence],
|
||||
..Default::default()
|
||||
},
|
||||
changed_fields,
|
||||
accepted_receipt_id,
|
||||
accepted_observation_id,
|
||||
accepted_evidence_id,
|
||||
mind_review,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn epiphany_job_launch_changed_fields() -> Vec<EpiphanyStateUpdatedField> {
|
||||
vec![
|
||||
EpiphanyStateUpdatedField::JobBindings,
|
||||
|
|
@ -271,56 +109,57 @@ pub fn thread_epiphany_patch_has_state_replacements(
|
|||
pub fn epiphany_update_patch_changed_fields(
|
||||
patch: &EpiphanyRoleStatePatchDocument,
|
||||
) -> Vec<EpiphanyStateUpdatedField> {
|
||||
let update = state_update_from_core_patch(None, patch.clone());
|
||||
let mut fields = Vec::new();
|
||||
if patch.objective.is_some() {
|
||||
if update.objective.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Objective);
|
||||
}
|
||||
if patch.active_subgoal_id.is_some() {
|
||||
if update.active_subgoal_id.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::ActiveSubgoalId);
|
||||
}
|
||||
if patch.subgoals.is_some() {
|
||||
if update.subgoals.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Subgoals);
|
||||
}
|
||||
if patch.invariants.is_some() {
|
||||
if update.invariants.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Invariants);
|
||||
}
|
||||
if patch.graphs.is_some() {
|
||||
if update.graphs.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Graphs);
|
||||
}
|
||||
if patch.graph_frontier.is_some() {
|
||||
if update.graph_frontier.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::GraphFrontier);
|
||||
}
|
||||
if patch.graph_checkpoint.is_some() {
|
||||
if update.graph_checkpoint.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::GraphCheckpoint);
|
||||
}
|
||||
if patch.scratch.is_some() {
|
||||
if update.scratch.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Scratch);
|
||||
}
|
||||
if patch.investigation_checkpoint.is_some() {
|
||||
if update.investigation_checkpoint.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::InvestigationCheckpoint);
|
||||
}
|
||||
if patch.job_bindings.is_some() {
|
||||
if update.job_bindings.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::JobBindings);
|
||||
}
|
||||
if !patch.acceptance_receipts.is_empty() {
|
||||
if !update.acceptance_receipts.is_empty() {
|
||||
fields.push(EpiphanyStateUpdatedField::AcceptanceReceipts);
|
||||
}
|
||||
if !patch.runtime_links.is_empty() {
|
||||
if !update.runtime_links.is_empty() {
|
||||
fields.push(EpiphanyStateUpdatedField::RuntimeLinks);
|
||||
}
|
||||
if !patch.observations.is_empty() {
|
||||
if !update.observations.is_empty() {
|
||||
fields.push(EpiphanyStateUpdatedField::Observations);
|
||||
}
|
||||
if !patch.evidence.is_empty() {
|
||||
if !update.evidence.is_empty() {
|
||||
fields.push(EpiphanyStateUpdatedField::Evidence);
|
||||
}
|
||||
if patch.churn.is_some() {
|
||||
if update.churn.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Churn);
|
||||
}
|
||||
if patch.mode.is_some() {
|
||||
if update.mode.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Mode);
|
||||
}
|
||||
if patch.planning.is_some() {
|
||||
if update.planning.is_some() {
|
||||
fields.push(EpiphanyStateUpdatedField::Planning);
|
||||
}
|
||||
fields
|
||||
|
|
|
|||
Reference in a new issue