fix(host,cli): enforce console capability and label call --json output
- host: `打印` checks the console capability at the execution point (pure and project modes grant it, but the boundary is now real instead of decorative). - cli: `marqdo call --json` reports "command":"call" instead of "run".
This commit is contained in:
1 parent
2f1b10d0ee
commit
fae0cd4b18
2 files changed
+11
-3
No files matched your search
@@ -485,6 +485,7 @@ pub fn execute(
|
||||
json: bool,
|
||||
trace: bool,
|
||||
) -> i32 {
|
||||
let command_name = if function.is_some() { "call" } else { "run" };
|
||||
let project = match load_project(file, json) {
|
||||
Ok(project) => project,
|
||||
Err(code) => return code,
|
||||
@@ -492,7 +493,7 @@ pub fn execute(
|
||||
if project.has_errors() {
|
||||
if json {
|
||||
output::print_json(&json!({
|
||||
"command": "run",
|
||||
"command": command_name,
|
||||
"success": false,
|
||||
"diagnostics": output::diagnostics_json(&project.diagnostics),
|
||||
}));
|
||||
@@ -589,7 +590,7 @@ pub fn execute(
|
||||
Ok(outcome) => {
|
||||
if json {
|
||||
output::print_json(&json!({
|
||||
"command": "run",
|
||||
"command": command_name,
|
||||
"success": true,
|
||||
"value": marqdo_value::to_wire(&outcome.value),
|
||||
"stdout": stdout_text,
|
||||
@@ -616,7 +617,7 @@ pub fn execute(
|
||||
Err(error) => {
|
||||
if json {
|
||||
output::print_json(&json!({
|
||||
"command": "run",
|
||||
"command": command_name,
|
||||
"success": false,
|
||||
"stdout": stdout_text,
|
||||
"error": runtime_error_json(&error, &project),
|
||||
|
||||
@@ -254,6 +254,13 @@ impl StdHost {
|
||||
args: Vec<Value>,
|
||||
ctx: &ExecutionContext,
|
||||
) -> Result<Value, RuntimeError> {
|
||||
if !self.capabilities.console {
|
||||
return Err(RuntimeError::new(
|
||||
ErrorCategory::PermissionDenied,
|
||||
ctx.span,
|
||||
"program output (console) capability was not granted",
|
||||
));
|
||||
}
|
||||
if args.len() != 1 {
|
||||
return Err(arity(ctx.span, "打印", 1, args.len()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user