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",
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Package lock/sync/add/remove commands.
|
||||
|
||||
use super::*;
|
||||
use crate::extension_selection;
|
||||
|
||||
/// `marqdo lock`.
|
||||
pub fn lock(json: bool) -> i32 {
|
||||
@@ -18,19 +19,40 @@ pub fn lock(json: bool) -> i32 {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
let graph =
|
||||
match marqdo_package::PackageResolver::new(root.clone(), Some(manifest.clone()), None)
|
||||
.with_fetch(true)
|
||||
.with_unlocked(true)
|
||||
.resolve_lock_graph()
|
||||
{
|
||||
Ok(graph) => graph,
|
||||
Err(error) => {
|
||||
eprintln!("error: {error}");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let lockfile = graph.lock;
|
||||
let resolver = marqdo_package::PackageResolver::new(root.clone(), Some(manifest.clone()), None)
|
||||
.with_fetch(true)
|
||||
.with_unlocked(true);
|
||||
let graph = match resolver.resolve_lock_graph() {
|
||||
Ok(graph) => graph,
|
||||
Err(error) => {
|
||||
eprintln!("error: {error}");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let mut lockfile = graph.lock;
|
||||
// Lock v4: record the exact extension identity declared by the project.
|
||||
// Reading manifests/declared digests is static; no binary is loaded and no
|
||||
// grant is implied.
|
||||
let extension_sources = match resolver.resolve_extension_sources() {
|
||||
Ok(sources) => sources,
|
||||
Err(error) => {
|
||||
eprintln!("error: extension selection: {error}");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let identities = match extension_selection::extension_identities(&extension_sources) {
|
||||
Ok(identities) => identities,
|
||||
Err(error) => {
|
||||
eprintln!("error[{}]: {}", error.code, error.message);
|
||||
return error.exit_code;
|
||||
}
|
||||
};
|
||||
for identity in identities {
|
||||
if let Err(error) = lockfile.merge_extension(identity) {
|
||||
eprintln!("error[ext.extension_lock_mismatch]: {error}");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
let path = root.join(marqdo_package::LOCK_FILE);
|
||||
if let Err(error) = write_atomic(&path, lockfile.to_yaml().as_bytes()) {
|
||||
eprintln!("error: cannot write {}: {error}", path.display());
|
||||
@@ -41,6 +63,7 @@ pub fn lock(json: bool) -> i32 {
|
||||
"command": "lock",
|
||||
"success": true,
|
||||
"packages": lockfile.packages,
|
||||
"extensions": lockfile.extensions,
|
||||
}));
|
||||
} else {
|
||||
println!(
|
||||
@@ -90,6 +113,30 @@ pub fn sync(locked: bool, json: bool) -> i32 {
|
||||
let resolver =
|
||||
marqdo_package::PackageResolver::new(root, Some(manifest.clone()), Some(lockfile.clone()))
|
||||
.with_fetch(!locked);
|
||||
// Verify the declared extension selection against the lock before using
|
||||
// any materialized content. A missing/changed identity fails closed.
|
||||
let extension_sources = match resolver.resolve_extension_sources() {
|
||||
Ok(sources) => sources,
|
||||
Err(error) => {
|
||||
eprintln!("error: extension selection: {error}");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let identities = match extension_selection::extension_identities(&extension_sources) {
|
||||
Ok(identities) => identities,
|
||||
Err(error) => {
|
||||
eprintln!("error[{}]: {}", error.code, error.message);
|
||||
return error.exit_code;
|
||||
}
|
||||
};
|
||||
if let Err(error) = lockfile.validate_extension_declarations(&manifest) {
|
||||
eprintln!("error[ext.extension_lock_mismatch]: {error}");
|
||||
return 1;
|
||||
}
|
||||
if let Err(error) = extension_selection::validate_against_lock(&lockfile, &identities) {
|
||||
eprintln!("error[{}]: {}", error.code, error.message);
|
||||
return error.exit_code;
|
||||
}
|
||||
if let Err(error) = resolver.materialize_env(&lockfile) {
|
||||
eprintln!("error: cannot materialize project environment: {error}");
|
||||
return 1;
|
||||
|
||||
@@ -20,6 +20,7 @@ pub fn execute(
|
||||
Ok(prepared) => prepared,
|
||||
Err(code) => return code,
|
||||
};
|
||||
let extension_sources = prepared.loaded.extension_sources.clone();
|
||||
let project = prepared.loaded;
|
||||
let static_plugins = prepared.plugins;
|
||||
if project.has_errors() {
|
||||
@@ -51,6 +52,43 @@ pub fn execute(
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
// A project-declared extension is activation, not authorization, but it is
|
||||
// still third-party executable code. `pure`/`strict` never activate it.
|
||||
if !extension_sources.is_empty() && mode != SandboxMode::Project {
|
||||
let code = if mode == SandboxMode::Strict {
|
||||
"strict.unsupported_grant"
|
||||
} else {
|
||||
"cli.invalid_grants"
|
||||
};
|
||||
let message = format!(
|
||||
"this project declares {} extension activation source(s) in {}; \
|
||||
--mode {} cannot activate third-party extensions. Use --mode project \
|
||||
with explicit grants, or remove the extensions block",
|
||||
extension_sources.len(),
|
||||
marqdo_package::MANIFEST_FILE,
|
||||
settings.mode
|
||||
);
|
||||
emit_error(json, command_name, code, &message);
|
||||
return 2;
|
||||
}
|
||||
let mut kernel_paths = settings.kernels.clone();
|
||||
kernel_paths.extend(
|
||||
extension_sources
|
||||
.iter()
|
||||
.filter(|extension| extension.kind == marqdo_package::ExtensionKind::Kernel)
|
||||
.map(|extension| extension.path.clone()),
|
||||
);
|
||||
kernel_paths.sort();
|
||||
kernel_paths.dedup();
|
||||
let mut provider_paths = settings.providers.clone();
|
||||
provider_paths.extend(
|
||||
extension_sources
|
||||
.iter()
|
||||
.filter(|extension| extension.kind == marqdo_package::ExtensionKind::Provider)
|
||||
.map(|extension| extension.path.clone()),
|
||||
);
|
||||
provider_paths.sort();
|
||||
provider_paths.dedup();
|
||||
if mode == SandboxMode::Strict {
|
||||
if let Err(error) = settings.strict_preflight() {
|
||||
emit_error(json, command_name, "strict.unsupported_grant", &error);
|
||||
@@ -121,7 +159,7 @@ pub fn execute(
|
||||
if let Some(timeout) = settings.timeout {
|
||||
host.budget.deadline = Some(Instant::now() + Duration::from_secs(timeout));
|
||||
}
|
||||
for kernel_path in &settings.kernels {
|
||||
for kernel_path in &kernel_paths {
|
||||
if let Err(error) = load_kernel_descriptor(&mut host, kernel_path) {
|
||||
if json {
|
||||
output::print_json(&json!({"success": false, "error": error}));
|
||||
@@ -139,7 +177,7 @@ pub fn execute(
|
||||
// current target artifact, check the exact grant and reject duplicate
|
||||
// names/kinds *before* any provider or plugin worker process is spawned
|
||||
// (RFC-EXT-0001 §5.4.6/§18.2 T6–T7).
|
||||
let providers = match provider_manifest::read_provider_manifests(&settings.providers) {
|
||||
let providers = match provider_manifest::read_provider_manifests(&provider_paths) {
|
||||
Ok(providers) => providers,
|
||||
Err(error) => {
|
||||
emit_prepare_error(json, command_name, &error);
|
||||
|
||||
Reference in new issue
Block a user