feat(ext): extension selection + lock v4, inspect --extensions (RFC-EXT-0001 PR-04)
- marqdo.yaml.extensions accepts only ./path or @alias/path, resolves to a regular file inside its owning package, never grants - lock_version 4 records plugin/kernel/provider manifest+artifact identity; v3 requires explicit 'marqdo lock' migration; sync/check/run compare identity - check stays static; run re-verifies artifact bytes; pure/strict refuse - inspect --extensions reports declared/locked identity, plugin descriptors and stdlib aliases with authorization 'not_granted' - black-box extension_selection suite (13) + package-layer tests; specs/ADR-0056 - workspace gate: fmt/clippy clean, 599 passed across 67 targets
This commit is contained in:
1 parent
1f6fd644a0
commit
89555382e0
19 files changed
+2240
-63
No files matched your search
@@ -17,24 +17,31 @@ pub struct InspectFlags {
|
||||
pub refs: bool,
|
||||
/// Show platform capability report.
|
||||
pub platform: bool,
|
||||
/// Show declared/loaded extension identities (never grants).
|
||||
pub extensions: bool,
|
||||
}
|
||||
|
||||
pub fn inspect(file: Option<&Path>, flags: &InspectFlags, json: bool) -> i32 {
|
||||
let prepared = match prepare_project(file, json, &[]) {
|
||||
pub fn inspect(file: Option<&Path>, flags: &InspectFlags, json: bool, plugins: &[PathBuf]) -> i32 {
|
||||
let prepared = match prepare_project(file, json, plugins) {
|
||||
Ok(prepared) => prepared,
|
||||
Err(code) => return code,
|
||||
};
|
||||
let project = prepared.loaded;
|
||||
let project = &prepared.loaded;
|
||||
let entry = project.entry_file();
|
||||
let module = &entry.analysis.module;
|
||||
let selected_any =
|
||||
flags.ast || flags.units || flags.signature || flags.ir || flags.refs || flags.platform;
|
||||
let selected_any = flags.ast
|
||||
|| flags.units
|
||||
|| flags.signature
|
||||
|| flags.ir
|
||||
|| flags.refs
|
||||
|| flags.platform
|
||||
|| flags.extensions;
|
||||
if json {
|
||||
let mut object = serde_json::Map::new();
|
||||
object.insert("command".into(), json!("inspect"));
|
||||
object.insert("module".into(), json!(entry.module_id.to_string()));
|
||||
if !selected_any {
|
||||
object.insert("summary".into(), summary_json(&project));
|
||||
object.insert("summary".into(), summary_json(project));
|
||||
}
|
||||
if flags.ast {
|
||||
object.insert(
|
||||
@@ -58,7 +65,7 @@ pub fn inspect(file: Option<&Path>, flags: &InspectFlags, json: bool) -> i32 {
|
||||
);
|
||||
}
|
||||
if flags.refs {
|
||||
object.insert("refs".into(), json!(refs_json(&project)));
|
||||
object.insert("refs".into(), json!(refs_json(project)));
|
||||
}
|
||||
if flags.platform {
|
||||
object.insert(
|
||||
@@ -66,6 +73,9 @@ pub fn inspect(file: Option<&Path>, flags: &InspectFlags, json: bool) -> i32 {
|
||||
serde_json::to_value(PlatformCapabilities::detect()).unwrap_or_default(),
|
||||
);
|
||||
}
|
||||
if flags.extensions {
|
||||
object.insert("extensions".into(), extensions_json(&prepared, project));
|
||||
}
|
||||
output::print_json(&serde_json::Value::Object(object));
|
||||
return 0;
|
||||
}
|
||||
@@ -120,7 +130,7 @@ pub fn inspect(file: Option<&Path>, flags: &InspectFlags, json: bool) -> i32 {
|
||||
if flags.refs {
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&refs_json(&project)).unwrap_or_default()
|
||||
serde_json::to_string_pretty(&refs_json(project)).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
if flags.platform {
|
||||
@@ -129,5 +139,102 @@ pub fn inspect(file: Option<&Path>, flags: &InspectFlags, json: bool) -> i32 {
|
||||
serde_json::to_string_pretty(&PlatformCapabilities::detect()).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
if flags.extensions {
|
||||
let value = extensions_json(&prepared, project);
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&value).unwrap_or_default()
|
||||
);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
/// Static extension identity projection for `inspect --extensions`.
|
||||
///
|
||||
/// Reports declared sources, lock identity, static plugin descriptors and
|
||||
/// official stdlib aliases. It deliberately never shows environment variables,
|
||||
/// secrets, binary contents or an authorization result beyond
|
||||
/// `not_granted` (inspection does not grant anything).
|
||||
fn extensions_json(
|
||||
prepared: &crate::project_prepare::PreparedProgram,
|
||||
project: &crate::loader::LoadedProject,
|
||||
) -> serde_json::Value {
|
||||
let root = project.root.as_path();
|
||||
let relative = |path: &Path| {
|
||||
path.strip_prefix(root)
|
||||
.map(|value| value.to_string_lossy().to_string())
|
||||
.unwrap_or_else(|_| path.to_string_lossy().to_string())
|
||||
};
|
||||
let declared: Vec<serde_json::Value> = project
|
||||
.extension_sources
|
||||
.iter()
|
||||
.map(|extension| {
|
||||
let identity = prepared.extension_identities.iter().find(|identity| {
|
||||
identity.kind == extension.kind
|
||||
&& identity.source == extension.from
|
||||
&& identity.logical_owner == extension.logical_owner
|
||||
});
|
||||
let locked = project.lock.as_ref().is_some_and(|lock| {
|
||||
identity.is_some_and(|identity| {
|
||||
lock.extension(identity.kind, &identity.name, &identity.logical_owner)
|
||||
.is_some()
|
||||
})
|
||||
});
|
||||
json!({
|
||||
"kind": extension.kind.as_str(),
|
||||
"source": extension.from,
|
||||
"path": relative(&extension.path),
|
||||
"logical_owner": extension.logical_owner,
|
||||
"name": identity.map(|identity| identity.name.clone()),
|
||||
"version": identity.map(|identity| identity.version.clone()),
|
||||
"manifest_digest": identity.map(|identity| identity.manifest_digest.clone()),
|
||||
"artifact_digest": identity.map(|identity| identity.artifact_digest.clone()),
|
||||
"selected_target": identity.map(|identity| identity.selected_target.clone()),
|
||||
"status": if locked { "locked" } else { "unlocked" },
|
||||
"authorization": "not_granted",
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let plugins: Vec<serde_json::Value> = prepared
|
||||
.plugins
|
||||
.plugins
|
||||
.iter()
|
||||
.map(|plugin| {
|
||||
json!({
|
||||
"package": plugin.package,
|
||||
"version": plugin.version,
|
||||
"kind": plugin.kind.as_str(),
|
||||
"manifest_path": relative(&plugin.manifest_path),
|
||||
"manifest_digest": plugin.manifest_sha256,
|
||||
"selected_target": plugin.artifact_target,
|
||||
"artifact_digest": plugin.artifact_sha256,
|
||||
"artifact_path": relative(&plugin.artifact_path()),
|
||||
"exports": plugin.exports.iter().map(|export| json!({
|
||||
"name": export.name,
|
||||
"signature": export.signature,
|
||||
})).collect::<Vec<_>>(),
|
||||
"validation": "static_manifest_ok",
|
||||
"authorization": "not_granted",
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let aliases: Vec<serde_json::Value> = project
|
||||
.official_aliases
|
||||
.iter()
|
||||
.map(|alias| {
|
||||
json!({
|
||||
"public_names": alias.public_names,
|
||||
"target": alias.function.to_string(),
|
||||
"owner_package": alias.owner_package,
|
||||
"source": "verified stdlib bundle",
|
||||
"authorization": "official_bundle",
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
json!({
|
||||
"declared": declared,
|
||||
"plugins": plugins,
|
||||
"stdlib_aliases": aliases,
|
||||
"note": "inspect never loads or executes an extension and never grants a permission",
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user