Skip to content

Commit 993531f

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 948ab3e commit 993531f

2 files changed

Lines changed: 68 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 current.workspace_dirs != desired.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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,13 @@ fn raw_preimage_accepts_valid_bytes_and_wrong_cas_preserves_declarations() {
19831983
let temp = tempfile::tempdir().unwrap();
19841984
let valid = temp.path().join("valid");
19851985
write_agent(&valid, "worker", false);
1986+
fs::create_dir_all(valid.join("resolvers")).unwrap();
1987+
fs::copy(DEMO_WASM_SRC, valid.join("resolvers/observe.wasm")).unwrap();
1988+
fs::write(
1989+
valid.join("catalog.kdl"),
1990+
profile_catalog_config(&[("dev.example.observe", "resolvers/observe.wasm")]),
1991+
)
1992+
.unwrap();
19861993
let valid_prepared = temp.path().join("valid-prepared");
19871994
snapshot(&valid, &valid_prepared);
19881995
let valid_raw_snapshot = raw_snapshot(&valid, &temp.path().join("valid-raw"));
@@ -1992,6 +1999,7 @@ fn raw_preimage_accepts_valid_bytes_and_wrong_cas_preserves_declarations() {
19921999
String::from_utf8_lossy(&valid_raw_snapshot.stderr)
19932000
);
19942001
let valid_raw_snapshot: Value = serde_json::from_slice(&valid_raw_snapshot.stdout).unwrap();
2002+
let generation_before = fs::read(valid.join(".st2/catalog-generation")).ok();
19952003
let valid_raw_apply = raw_apply(
19962004
&valid,
19972005
&valid_prepared,
@@ -2002,6 +2010,32 @@ fn raw_preimage_accepts_valid_bytes_and_wrong_cas_preserves_declarations() {
20022010
"{}",
20032011
String::from_utf8_lossy(&valid_raw_apply.stderr)
20042012
);
2013+
let valid_raw_apply: Value = serde_json::from_slice(&valid_raw_apply.stdout).unwrap();
2014+
assert_eq!(valid_raw_apply["status"], "unchanged");
2015+
assert!(!valid.join(".st2/catalog-apply-incomplete").exists());
2016+
assert_eq!(
2017+
fs::read(valid.join(".st2/catalog-generation")).ok(),
2018+
generation_before
2019+
);
2020+
2021+
fs::write(valid.join("resolvers/observe.wasm"), b"stale module").unwrap();
2022+
let stale_module_apply = raw_apply(
2023+
&valid,
2024+
&valid_prepared,
2025+
valid_raw_snapshot["rootSha256"].as_str().unwrap(),
2026+
);
2027+
assert!(
2028+
stale_module_apply.status.success(),
2029+
"{}",
2030+
String::from_utf8_lossy(&stale_module_apply.stderr)
2031+
);
2032+
let stale_module_apply: Value =
2033+
serde_json::from_slice(&stale_module_apply.stdout).unwrap();
2034+
assert_eq!(stale_module_apply["status"], "applied");
2035+
assert_eq!(
2036+
fs::read(valid.join("resolvers/observe.wasm")).unwrap(),
2037+
fs::read(DEMO_WASM_SRC).unwrap()
2038+
);
20052039

20062040
let invalid = temp.path().join("invalid");
20072041
write_invalid_agent(&invalid, "worker");

0 commit comments

Comments
 (0)