config-source: bind import cache keys to content

This commit is contained in:
2026-08-14 12:06:10 +09:00
parent 6446eb1302
commit 46ffde19a6
2 changed files with 20 additions and 2 deletions
+20 -2
View File
@@ -998,6 +998,7 @@ impl ImportLoader for SnapshotImportLoader {
format!("virtual config import is missing: {path}"), format!("virtual config import is missing: {path}"),
) )
})?; })?;
let cache_key = snapshot_import_cache_key(entry);
if path.as_str().ends_with(".md") { if path.as_str().ends_with(".md") {
let projection = project_markdown_document(&entry.content).map_err(|message| { let projection = project_markdown_document(&entry.content).map_err(|message| {
Diagnostic::new( Diagnostic::new(
@@ -1013,10 +1014,10 @@ impl ImportLoader for SnapshotImportLoader {
format!("failed to import Markdown `{path}`: {message}"), format!("failed to import Markdown `{path}`: {message}"),
) )
})?; })?;
return Ok(LoadedImport::value(path.as_str(), value)); return Ok(LoadedImport::value(cache_key, value));
} }
Ok(LoadedImport::source( Ok(LoadedImport::source(
path.as_str(), cache_key,
path.as_str(), path.as_str(),
entry.content.clone(), entry.content.clone(),
)) ))
@@ -1038,6 +1039,13 @@ impl ImportLoader for SnapshotImportLoader {
} }
} }
fn snapshot_import_cache_key(entry: &ConfigEntry) -> String {
// The source id remains the virtual path for diagnostics and relative-import
// resolution. The cache identity also includes immutable source content so
// equal paths from different revisions cannot alias in an Engine cache.
format!("{}@{}", entry.path, entry.content_digest)
}
pub fn resolve_import( pub fn resolve_import(
current: &VirtualPath, current: &VirtualPath,
specifier: &str, specifier: &str,
@@ -1688,6 +1696,16 @@ mod tests {
assert_ne!(empty.fingerprint, configured.fingerprint); assert_ne!(empty.fingerprint, configured.fingerprint);
} }
#[test]
fn snapshot_import_cache_key_binds_virtual_path_and_content_digest() {
let first = text_entry("skills/debug-rust/SKILL.md", "first");
let second = text_entry("skills/debug-rust/SKILL.md", "second");
let first_key = snapshot_import_cache_key(&first);
assert!(first_key.starts_with("skills/debug-rust/SKILL.md@sha256:"));
assert!(first_key.ends_with(&first.content_digest));
assert_ne!(first_key, snapshot_import_cache_key(&second));
}
#[test] #[test]
fn markdown_import_projects_frontmatter_and_content_as_a_value() { fn markdown_import_projects_frontmatter_and_content_as_a_value() {
let markdown = concat!( let markdown = concat!(