Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions atomic-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ syn = "2"

[features]
default = []
prototype-context-completion = []
# Enable additional debug assertions
debug-checks = []
4 changes: 4 additions & 0 deletions atomic-core/src/change/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ impl Change {
collect_edge_update_hashes(inode, table)?;
}
GraphOp::SetAttr { inode, .. } => collect_position_hash(inode, table)?,
// Experimental context endpoints are encoded as full hashes,
// not repository IDs or compact graph-position indices.
#[cfg(feature = "prototype-context-completion")]
GraphOp::PrototypeContext { .. } => {}
}
}

Expand Down
8 changes: 8 additions & 0 deletions atomic-core/src/change/format_v3/compact/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl<'t> Compactor<'t> {
reason,
})?;
match op {
#[cfg(feature = "prototype-context-completion")]
GraphOp::PrototypeContext { effect } => Ok(CompactGraphOp::PrototypeContext {
effect: effect.clone(),
}),
GraphOp::FileAdd {
add_name,
add_inode,
Expand Down Expand Up @@ -235,6 +239,10 @@ impl<'t> Compactor<'t> {
reason,
})?;
let expanded: FormatResult<GraphOp<Option<Hash>>> = match op {
#[cfg(feature = "prototype-context-completion")]
CompactGraphOp::PrototypeContext { effect } => Ok(GraphOp::PrototypeContext {
effect: effect.clone(),
}),
CompactGraphOp::FileAdd {
add_name,
add_inode,
Expand Down
9 changes: 9 additions & 0 deletions atomic-core/src/change/format_v3/compact/graph_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ pub enum CompactGraphOp {
/// Canonical attribute value.
value: InodeAttr,
},
/// Private experimental sandbox operation; not a production discriminant.
#[cfg(feature = "prototype-context-completion")]
PrototypeContext {
effect: crate::change::prototype_context::PrototypeContextEffect,
},
}

impl CompactGraphOp {
Expand Down Expand Up @@ -273,6 +278,8 @@ impl CompactGraphOp {
| CompactGraphOp::ResurrectZombies { local, .. } => Some(&local.path),
CompactGraphOp::SetAttr { path, .. } => Some(path),
CompactGraphOp::AddRoot { .. } | CompactGraphOp::DelRoot { .. } => None,
#[cfg(feature = "prototype-context-completion")]
CompactGraphOp::PrototypeContext { .. } => None,
}
}

Expand All @@ -296,6 +303,8 @@ impl CompactGraphOp {
CompactGraphOp::AddRoot { .. } => "AddRoot",
CompactGraphOp::DelRoot { .. } => "DelRoot",
CompactGraphOp::SetAttr { .. } => "SetAttr",
#[cfg(feature = "prototype-context-completion")]
CompactGraphOp::PrototypeContext { .. } => "PrototypeContext",
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions atomic-core/src/change/format_v3/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@
//! modify the repository DAG (vertex insertions, edge updates). This is the
//! minimum required to apply a change. A "thin pull" downloads only these.
//!
//! - **SEMANTIC section**: The display/analysis layer. Contains [`FileOps`] with
//! - **SEMANTIC section**: The human-readable semantic layer. Contains [`FileOps`] with
//! Trunk/Branch/Leaf operations for line-level and token-level diffs, blame,
//! and code review. This is optional — it can be regenerated from graph + content.
//! A "thin review" downloads only these + content chunks.
//! and code review. Span projections retain original authored fragments;
//! graph bytes alone cannot recover authenticated semantic names.
//! Historical graph-only objects remain readable, but must not be presented as
//! a complete semantic interpretation. Selective readers must retain context.
//!
//! Both sections for the same file share the same `content_range`, which indexes
//! into the change's content chunks. This enables the reader to correlate
Expand Down
15 changes: 15 additions & 0 deletions atomic-core/src/change/graph_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ pub enum GraphOp<H> {
/// Canonical attribute value.
value: InodeAttr,
},
/// Private experimental context relation; requires the sandbox capability.
#[cfg(feature = "prototype-context-completion")]
PrototypeContext {
effect: super::prototype_context::PrototypeContextEffect,
},
}

impl<H: PartialEq> GraphOp<H> {
Expand Down Expand Up @@ -551,6 +556,8 @@ impl<H> GraphOp<H> {
| GraphOp::ResurrectZombies { local, .. } => Some(&local.path),

GraphOp::AddRoot { .. } | GraphOp::DelRoot { .. } => None,
#[cfg(feature = "prototype-context-completion")]
GraphOp::PrototypeContext { .. } => None,
}
}

Expand Down Expand Up @@ -659,6 +666,8 @@ impl<H> GraphOp<H> {
GraphOp::AddRoot { .. } => "AddRoot",
GraphOp::DelRoot { .. } => "DelRoot",
GraphOp::SetAttr { .. } => "SetAttr",
#[cfg(feature = "prototype-context-completion")]
GraphOp::PrototypeContext { .. } => "PrototypeContext",
}
}
}
Expand Down Expand Up @@ -691,6 +700,8 @@ impl<H: fmt::Debug> fmt::Display for GraphOp<H> {
GraphOp::AddRoot { .. } => write!(f, "AddRoot"),
GraphOp::DelRoot { .. } => write!(f, "DelRoot"),
GraphOp::SetAttr { path, value, .. } => write!(f, "SetAttr: {path} {value:?}"),
#[cfg(feature = "prototype-context-completion")]
GraphOp::PrototypeContext { effect } => write!(f, "PrototypeContext: {effect:?}"),
}
}
}
Expand Down Expand Up @@ -799,6 +810,8 @@ impl<'a, H> Iterator for HunkAtomIter<'a, H> {

// Attribute events are applied outside the edge graph.
(GraphOp::SetAttr { .. }, _) => None,
#[cfg(feature = "prototype-context-completion")]
(GraphOp::PrototypeContext { .. }, _) => None,
};

if result.is_some() {
Expand Down Expand Up @@ -858,6 +871,8 @@ impl<H> GraphOp<H> {
GraphOp::DirDel { .. } => 1,
GraphOp::DirUndel { .. } => 1,
GraphOp::SetAttr { .. } => 0,
#[cfg(feature = "prototype-context-completion")]
GraphOp::PrototypeContext { .. } => 0,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions atomic-core/src/change/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ mod graph_op;
mod header;
mod local;
pub mod ops;
#[cfg(feature = "prototype-context-completion")]
pub mod prototype_context;
mod provenance;
pub mod provenance_graph;
pub mod semantic_context;
pub mod session;
pub mod signing;
pub mod span_patch;
Expand Down
220 changes: 220 additions & 0 deletions atomic-core/src/change/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,25 @@ impl FileOps {
}

/// Translate existing semantic identities while preserving ROOT placeholders.
///
/// Resolve each distinct external owner once, before changing any operation.
/// If resolution fails, `self` is unchanged. The caller supplies the owner
/// mapping; this does not infer names from paths, application order or local
/// numeric coincidences.
pub fn remap_referenced_node_ids<E>(
&mut self,
mut remap: impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
) -> Result<(), E> {
let mapping: std::collections::BTreeMap<_, _> = self
.referenced_node_ids()
.into_iter()
.map(|id| remap(id).map(|resolved| (id, resolved)))
.collect::<Result<_, E>>()?;
let mut remap = |id| -> Result<crate::types::NodeId, E> {
// referenced_node_ids enumerates the same non-ROOT fields walked
// below. All fallible resolution finished before the first write.
Ok(mapping[&id])
};
fn trunk<E>(
id: &mut TrunkId,
f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
Expand Down Expand Up @@ -1154,6 +1169,211 @@ mod tests {
BranchId::new(NodeId::new(1), idx)
}

// These are representation laws for transport of patch names, not a claim
// that arbitrary overlapping patches commute or that view removal is an
// inverse patch. ROOT is the self-name, not an external owner to transport.
fn transport_fixtures() -> Vec<FileOps> {
let trunk = TrunkId::new(NodeId::new(2), 17);
let branch = |owner, index| BranchId::new(NodeId::new(owner), index);
let leaf = |owner, index| LeafId::new(NodeId::new(owner), index);
let tokens = vec![
LeafOp::Insert {
after: Some(leaf(0, 11)),
kind: TokenKind::Word,
content: b"new".to_vec(),
},
LeafOp::Insert {
after: Some(leaf(5, 12)),
kind: TokenKind::Whitespace,
content: b" ".to_vec(),
},
LeafOp::Delete { leaf: leaf(6, 13) },
LeafOp::Replace {
leaf: leaf(7, 14),
new_content: b"replacement".to_vec(),
},
LeafOp::Restore { leaf: leaf(8, 15) },
];
let lines = vec![
LineOps::new(
branch(0, 20),
BranchOp::Insert {
after: Some(branch(3, 21)),
content: tokens.clone(),
},
)
.with_content_range(ChangePosition::new(100), ChangePosition::new(120)),
LineOps::new(
branch(3, 21),
BranchOp::Delete {
branch: branch(4, 22),
content: tokens.clone(),
},
),
LineOps::new(
branch(4, 22),
BranchOp::Modify {
branch: branch(3, 21),
old_content: tokens.clone(),
new_content: tokens,
},
),
LineOps::new(
branch(0, 23),
BranchOp::Restore {
branch: branch(4, 22),
},
),
LineOps::new(
branch(3, 24),
BranchOp::Reparent {
branch: branch(4, 25),
new_after: Some(branch(0, 26)),
},
),
];
let variants = vec![
None,
Some(TrunkOp::Create {
path: "f".into(),
encoding: Some(Encoding::Utf8),
}),
Some(TrunkOp::Delete { trunk }),
Some(TrunkOp::Move {
trunk,
new_path: "renamed".into(),
}),
Some(TrunkOp::Undelete { trunk }),
Some(TrunkOp::SetMode { trunk, mode: 0o644 }),
Some(TrunkOp::SetKind {
trunk,
kind: crate::change::InodeKind::Regular,
}),
];
let mut fixtures: Vec<_> = variants
.into_iter()
.map(|trunk_op| FileOps {
trunk_id: trunk,
path: "f".into(),
trunk_op,
line_ops: lines.clone(),
})
.collect();
fixtures.push(FileOps::projected_span_edit(
"projected".into(),
crate::change::span_patch::ExternalFile {
owner: crate::types::Hash::of(b"portable owner is not a local ID"),
ordinal: 7,
},
crate::change::span_patch::SpanProjectionId(crate::types::Hash::of(b"projection")),
));
fixtures
}

#[test]
fn semantic_transport_identity_composition_and_inverse() {
for original in transport_fixtures() {
let mut identity = original.clone();
identity.remap_referenced_node_ids::<()>(Ok).unwrap();
assert_eq!(identity, original);

let mut sequential = original.clone();
sequential
.remap_referenced_node_ids::<()>(|id| Ok(NodeId::new(id.get() + 100)))
.unwrap();
sequential
.remap_referenced_node_ids::<()>(|id| Ok(NodeId::new(id.get() * 3)))
.unwrap();
let mut composed = original.clone();
composed
.remap_referenced_node_ids::<()>(|id| Ok(NodeId::new((id.get() + 100) * 3)))
.unwrap();
assert_eq!(
sequential, composed,
"transport must compose as name substitution"
);

let mut roundtrip = original.clone();
roundtrip
.remap_referenced_node_ids::<()>(|id| Ok(NodeId::new(id.get() + 100)))
.unwrap();
roundtrip
.remap_referenced_node_ids::<()>(|id| Ok(NodeId::new(id.get() - 100)))
.unwrap();
assert_eq!(
roundtrip, original,
"inverse renaming must preserve all non-name fields and ROOT"
);
}
}

#[test]
fn semantic_transport_disjoint_renamings_commute() {
let left = |id: NodeId| -> Result<NodeId, ()> {
Ok(if id.get() == 2 { NodeId::new(102) } else { id })
};
let right = |id: NodeId| -> Result<NodeId, ()> {
Ok(if id.get() == 3 { NodeId::new(103) } else { id })
};
for original in transport_fixtures() {
let mut left_right = original.clone();
left_right.remap_referenced_node_ids(left).unwrap();
left_right.remap_referenced_node_ids(right).unwrap();
let mut right_left = original;
right_left.remap_referenced_node_ids(right).unwrap();
right_left.remap_referenced_node_ids(left).unwrap();
assert_eq!(left_right, right_left);
}
}

#[test]
fn semantic_transport_resolves_each_external_owner_once() {
for original in transport_fixtures() {
let owners = original.referenced_node_ids();
let mut observed = std::collections::BTreeSet::new();
let mut transported = original;
transported
.remap_referenced_node_ids::<()>(|id| {
assert!(!id.is_root(), "ROOT must retain its self-relative meaning");
assert!(
observed.insert(id),
"one owner must not be resolved inconsistently at different occurrences"
);
Ok(NodeId::new(id.get() + 100))
})
.unwrap();
assert_eq!(observed, owners);
assert_eq!(
transported.referenced_node_ids(),
owners
.iter()
.map(|id| NodeId::new(id.get() + 100))
.collect()
);
}
}

#[test]
fn semantic_transport_failure_leaves_the_patch_unchanged() {
for original in transport_fixtures() {
for missing in original.referenced_node_ids() {
let mut transported = original.clone();
let result = transported.remap_referenced_node_ids(|id| {
if id == missing {
Err(id)
} else {
Ok(NodeId::new(id.get() + 100))
}
});
assert_eq!(result, Err(missing));
assert_eq!(
transported, original,
"an undefined transport must not leave a partly renamed patch"
);
}
}
}

// FileOps Tests

#[test]
Expand Down
Loading
Loading