fix(view): use the same run path for static and live cells
Run All now records per-cell failures and continues; static export uses the same foreign_doc run_all and injects those records. A cell that succeeds in view therefore succeeds in the static snapshot, and failures match.
This commit is contained in:
1 parent
0ba4d3d2d7
commit
e0d34669e0
3 files changed
+114
-54
No files matched your search
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
### Added
|
||||
|
||||
- **foreign 拥有视图会话**:新增 `foreign.session kernels= cells=`,返回 foreign 会话句柄;`view` 只消费 `会话` 绑定,不再识别 `内核表` / `会话表` 保留名。没有 `会话` 时,view cells 使用无状态一次性执行,不创建内核。清除输出已接通 `/api/session/clear`,普通 view 与 foreign cells 共用,并由 Execution 面板的 Clear 按钮清除页面输出;无 `会话` 的 view 在 Run All 时执行整个文档并回写 Execution(不再空转);静态导出与动态 view 共用同一套 View 外壳和按钮布局;静态页面执行按钮点击显示“静态页面无法真实执行”,不伪造成功;静态导出会实际执行代码单元并把 stdout/stderr 注入代码卡,失败也显示真实错误;移除 `In []` / `Out []` 与 Notebook 品牌;没有新增 CLI 或第二个交互模式。
|
||||
- **foreign 拥有视图会话**:新增 `foreign.session kernels= cells=`,返回 foreign 会话句柄;`view` 只消费 `会话` 绑定,不再识别 `内核表` / `会话表` 保留名。没有 `会话` 时,view cells 使用无状态一次性执行,不创建内核。清除输出已接通 `/api/session/clear`,普通 view 与 foreign cells 共用,并由 Execution 面板的 Clear 按钮清除页面输出;无 `会话` 的 view 在 Run All 时执行整个文档并回写 Execution(不再空转);静态导出与动态 view 共用同一套 View 外壳和按钮布局;静态页面执行按钮点击显示“静态页面无法真实执行”,不伪造成功;静态导出与 view 的 Run All 共用同一 foreign_doc `run_all` 路径,成功/失败行为一致;构建时实际执行代码单元并把 stdout/stderr 注入代码卡,失败也显示真实错误;移除 `In []` / `Out []` 与 Notebook 品牌;没有新增 CLI 或第二个交互模式。
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
+62
-1
@@ -666,7 +666,23 @@ impl DocumentSession {
|
||||
let mut records = Vec::new();
|
||||
let mut failed = 0i64;
|
||||
for name in self.order.clone() {
|
||||
let record = self.run_cell(&name, None)?;
|
||||
let record = match self.run_cell(&name, None) {
|
||||
Ok(record) => record,
|
||||
Err(error) => {
|
||||
if let Some(i) = self.cell_index(&name) {
|
||||
self.cells[i].status = CellStatus::Error;
|
||||
self.cells[i].last_error = error.clone();
|
||||
}
|
||||
Value::Map(vec![
|
||||
("ok".into(), Value::Bool(false)),
|
||||
("stdout".into(), Value::Text(String::new())),
|
||||
("stderr".into(), Value::Text(String::new())),
|
||||
("error".into(), Value::Text(error)),
|
||||
("code".into(), Value::Int(-1)),
|
||||
("ms".into(), Value::Int(0)),
|
||||
])
|
||||
}
|
||||
};
|
||||
let ok = match &record {
|
||||
Value::Map(m) => matches!(
|
||||
m.iter().find(|(k, _)| k == "ok").map(|(_, v)| v),
|
||||
@@ -1248,6 +1264,51 @@ console.log(globalThis.kept);
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_all_continues_after_a_cell_error() {
|
||||
if !node_available() {
|
||||
return;
|
||||
}
|
||||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let path = root.join(format!(
|
||||
"target/view-run-all-error-{}-{}.mq.md",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|d| d.as_nanos())
|
||||
.unwrap_or(0)
|
||||
));
|
||||
let source = r#"# main
|
||||
|
||||
`a` =
|
||||
```node
|
||||
throw new Error("boom");
|
||||
```
|
||||
|
||||
`b` =
|
||||
```node
|
||||
console.log("after error");
|
||||
```
|
||||
"#;
|
||||
std::fs::write(&path, source).unwrap();
|
||||
let mut s = DocumentSession::open(&path, &root).unwrap();
|
||||
let summary = s.run_all(false).unwrap();
|
||||
let records = match &summary {
|
||||
Value::Map(entries) => entries.iter().find(|(k, _)| k == "records").map(|(_, v)| v.clone()),
|
||||
_ => None,
|
||||
};
|
||||
let Some(Value::List(records)) = records else { panic!("no records") };
|
||||
assert_eq!(records.len(), 2);
|
||||
assert_eq!(field(&records[0], "ok"), Some(Value::Bool(false)));
|
||||
assert_eq!(field(&records[1], "ok"), Some(Value::Bool(true)));
|
||||
assert!(field(&records[1], "stdout")
|
||||
.and_then(|v| v.reveal_text().map(|s| s.to_string()))
|
||||
.unwrap_or_default()
|
||||
.contains("after error"));
|
||||
s.close();
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reload_marks_changed_cell_dirty() {
|
||||
if !node_available() {
|
||||
|
||||
+51
-52
@@ -55,69 +55,68 @@ fn static_cell_outputs(root: &ViewRoot, abs: &std::path::Path) -> HashMap<String
|
||||
let Ok(mut session) = DocumentSession::open(abs, &root.root) else {
|
||||
return out;
|
||||
};
|
||||
for cell in session.order.clone() {
|
||||
let record = match session.run_cell(&cell, None) {
|
||||
Ok(record) => record,
|
||||
Err(error) => {
|
||||
out.insert(
|
||||
cell,
|
||||
StaticCellOutput {
|
||||
ok: false,
|
||||
text: error,
|
||||
},
|
||||
);
|
||||
let Ok(summary) = session.run_all(false) else {
|
||||
session.close();
|
||||
return out;
|
||||
};
|
||||
let records = match &summary {
|
||||
Value::Map(entries) => entries
|
||||
.iter()
|
||||
.find(|(k, _)| k == "records")
|
||||
.map(|(_, v)| v.clone()),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(Value::List(records)) = records {
|
||||
for rec in records {
|
||||
let Some(cell) = record_field(&rec, "cell").and_then(|v| value_text(&v)) else {
|
||||
continue;
|
||||
};
|
||||
let ok = record_field(&rec, "ok")
|
||||
.and_then(|v| value_bool(&v))
|
||||
.unwrap_or(false);
|
||||
let mut parts = Vec::new();
|
||||
if let Some(stdout) = record_field(&rec, "stdout").and_then(|v| value_text(&v)) {
|
||||
if !stdout.is_empty() {
|
||||
parts.push(stdout);
|
||||
}
|
||||
}
|
||||
};
|
||||
let ok = record_field(&record, "ok")
|
||||
.and_then(|v| value_bool(&v))
|
||||
.unwrap_or(false);
|
||||
let mut parts = Vec::new();
|
||||
if let Some(stdout) = record_field(&record, "stdout").and_then(|v| value_text(&v)) {
|
||||
if !stdout.is_empty() {
|
||||
parts.push(stdout);
|
||||
if let Some(stderr) = record_field(&rec, "stderr").and_then(|v| value_text(&v)) {
|
||||
if !stderr.is_empty() {
|
||||
parts.push(format!("[stderr]\n{stderr}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(stderr) = record_field(&record, "stderr").and_then(|v| value_text(&v)) {
|
||||
if !stderr.is_empty() {
|
||||
parts.push(format!("[stderr]\n{stderr}"));
|
||||
if let Some(error) = record_field(&rec, "error").and_then(|v| value_text(&v)) {
|
||||
if !error.is_empty() {
|
||||
parts.push(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(error) = record_field(&record, "error").and_then(|v| value_text(&v)) {
|
||||
if !error.is_empty() {
|
||||
parts.push(error);
|
||||
}
|
||||
}
|
||||
let mut meta = Vec::new();
|
||||
if let Some(code) =
|
||||
record_field(&record, "code").and_then(|v| match v {
|
||||
let mut meta = Vec::new();
|
||||
if let Some(code) = record_field(&rec, "code").and_then(|v| match v {
|
||||
Value::Int(n) => Some(n),
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
if code != 0 {
|
||||
meta.push(format!("exit {code}"));
|
||||
}) {
|
||||
if code != 0 {
|
||||
meta.push(format!("exit {code}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(ms) =
|
||||
record_field(&record, "ms").and_then(|v| match v {
|
||||
if let Some(ms) = record_field(&rec, "ms").and_then(|v| match v {
|
||||
Value::Int(n) => Some(n),
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
if ms > 0 {
|
||||
meta.push(format!("{ms}ms"));
|
||||
}) {
|
||||
if ms > 0 {
|
||||
meta.push(format!("{ms}ms"));
|
||||
}
|
||||
}
|
||||
if !meta.is_empty() {
|
||||
parts.push(format!("— {}", meta.join(" · ")));
|
||||
}
|
||||
let text = if parts.is_empty() {
|
||||
"(no output)".to_string()
|
||||
} else {
|
||||
parts.join("\n\n")
|
||||
};
|
||||
out.insert(cell, StaticCellOutput { ok, text });
|
||||
}
|
||||
if !meta.is_empty() {
|
||||
parts.push(format!("— {}", meta.join(" · ")));
|
||||
}
|
||||
let text = if parts.is_empty() {
|
||||
"(no output)".to_string()
|
||||
} else {
|
||||
parts.join("\n\n")
|
||||
};
|
||||
out.insert(cell, StaticCellOutput { ok, text });
|
||||
}
|
||||
session.close();
|
||||
out
|
||||
|
||||
Reference in new issue
Block a user