Skip to content

Commit db76ee0

Browse files
fix(catalog): preserve raw apply no-ops
agent-identity: dev3.direct.omp.2cshu64q agent-persona: generalist agent-supervisor: unavailable agent-tool: OMP agent-tool-version: 18.0.9 agent-runtime: OMP 18.0.9 tooling-profile: dotfiles@b607597
1 parent eb7ed64 commit db76ee0

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

src/catalog_transaction.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,34 @@ impl DeclarationProjection {
280280
}
281281
}
282282

283+
fn raw_declarations_match(
284+
catalog: &Path,
285+
current: &DeclarationProjection,
286+
desired: &DeclarationProjection,
287+
) -> bool {
288+
if !desired.workspace_dirs.is_subset(&current.workspace_dirs)
289+
|| !current
290+
.files
291+
.iter()
292+
.all(|(path, file)| desired.files.get(path) == Some(file))
293+
{
294+
return false;
295+
}
296+
297+
let mut live_profile_modules = BTreeMap::new();
298+
for path in &desired.profile_modules {
299+
if current.files.contains_key(path) {
300+
continue;
301+
}
302+
if add_profile_module(catalog, Path::new(path), &mut live_profile_modules).is_err() {
303+
return false;
304+
}
305+
}
306+
desired.files.iter().all(|(path, file)| {
307+
current.files.get(path) == Some(file) || live_profile_modules.get(path) == Some(file)
308+
})
309+
}
310+
283311
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
284312
enum ProjectionSource {
285313
Current,
@@ -1628,7 +1656,12 @@ pub fn apply(request: ApplyRequest) -> Result<ApplyResult> {
16281656
&desired.workspace_dirs,
16291657
)?
16301658
};
1631-
if current.root_sha256 == desired.root_sha256 && same_pty_root {
1659+
let same_declarations = if raw_preimage {
1660+
raw_declarations_match(&catalog, &current, &desired)
1661+
} else {
1662+
current.root_sha256 == desired.root_sha256
1663+
};
1664+
if same_declarations && same_pty_root {
16321665
return Ok(ApplyResult {
16331666
schema: if raw_preimage {
16341667
RAW_APPLY_SCHEMA

tests/catalog_apply.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,15 +1994,25 @@ fn raw_preimage_accepts_valid_bytes_and_wrong_cas_preserves_declarations() {
19941994
let temp = tempfile::tempdir().unwrap();
19951995
let valid = temp.path().join("valid");
19961996
write_agent(&valid, "worker", false);
1997+
fs::create_dir_all(valid.join("resolvers")).unwrap();
1998+
fs::copy(DEMO_WASM_SRC, valid.join("resolvers/observe.wasm")).unwrap();
1999+
fs::write(
2000+
valid.join("catalog.kdl"),
2001+
profile_catalog_config(&[("dev.example.observe", "resolvers/observe.wasm")]),
2002+
)
2003+
.unwrap();
19972004
let valid_prepared = temp.path().join("valid-prepared");
19982005
snapshot(&valid, &valid_prepared);
2006+
let orphan_workspace = agent_dir(&valid, "worker").join(".workspace");
2007+
fs::create_dir(&orphan_workspace).unwrap();
19992008
let valid_raw_snapshot = raw_snapshot(&valid, &temp.path().join("valid-raw"));
20002009
assert!(
20012010
valid_raw_snapshot.status.success(),
20022011
"{}",
20032012
String::from_utf8_lossy(&valid_raw_snapshot.stderr)
20042013
);
20052014
let valid_raw_snapshot: Value = serde_json::from_slice(&valid_raw_snapshot.stdout).unwrap();
2015+
let generation_before = fs::read(valid.join(".st2/catalog-generation")).ok();
20062016
let valid_raw_apply = raw_apply(
20072017
&valid,
20082018
&valid_prepared,
@@ -2013,6 +2023,34 @@ fn raw_preimage_accepts_valid_bytes_and_wrong_cas_preserves_declarations() {
20132023
"{}",
20142024
String::from_utf8_lossy(&valid_raw_apply.stderr)
20152025
);
2026+
let valid_raw_apply: Value = serde_json::from_slice(&valid_raw_apply.stdout).unwrap();
2027+
assert_eq!(valid_raw_apply["status"], "unchanged");
2028+
assert!(!valid.join(".st2/catalog-apply-incomplete").exists());
2029+
assert_eq!(
2030+
fs::read(valid.join(".st2/catalog-generation")).ok(),
2031+
generation_before
2032+
);
2033+
assert!(orphan_workspace.is_dir());
2034+
2035+
fs::write(valid.join("resolvers/observe.wasm"), b"stale module").unwrap();
2036+
let stale_module_apply = raw_apply(
2037+
&valid,
2038+
&valid_prepared,
2039+
valid_raw_snapshot["rootSha256"].as_str().unwrap(),
2040+
);
2041+
assert!(
2042+
stale_module_apply.status.success(),
2043+
"{}",
2044+
String::from_utf8_lossy(&stale_module_apply.stderr)
2045+
);
2046+
let stale_module_apply: Value =
2047+
serde_json::from_slice(&stale_module_apply.stdout).unwrap();
2048+
assert_eq!(stale_module_apply["status"], "applied");
2049+
assert_eq!(
2050+
fs::read(valid.join("resolvers/observe.wasm")).unwrap(),
2051+
fs::read(DEMO_WASM_SRC).unwrap()
2052+
);
2053+
assert!(orphan_workspace.is_dir());
20162054

20172055
let invalid = temp.path().join("invalid");
20182056
write_invalid_agent(&invalid, "worker");

0 commit comments

Comments
 (0)