fix(view): make static examples self-contained

Foreign cell examples read stdin with a deterministic fallback, so static exports show real output without tracebacks. Low-level session bindings named 会话 are no longer mistaken for a view plan; static export runs all cells again.
This commit is contained in:
cflmy committed 2026-10-18 13:19:41 +08:00
1 parent 518f8e386b
commit e4387259ba
5 files changed
+33 -38

No files matched your search

-31
View File
@@ -50,13 +50,6 @@ fn record_field(record: &Value, key: &str) -> Option<Value> {
/// Run the document's cells at export time and keep their real outputs. This
/// is what makes a static page show foreign results instead of just source.
fn cell_needs_stdin(source: &str) -> bool {
source.contains("sys.stdin")
|| source.contains("process.stdin")
|| source.contains("readFileSync(0")
|| source.contains("readFileSync(0,")
}
fn static_cell_outputs(
root: &ViewRoot,
abs: &std::path::Path,
@@ -66,23 +59,6 @@ fn static_cell_outputs(
let Ok(mut session) = DocumentSession::open(abs, &root.root) else {
return out;
};
if stdin.trim().is_empty() {
let mut run_order = Vec::new();
for cell in session.cells.iter() {
if cell_needs_stdin(&cell.source) {
out.insert(
cell.name.clone(),
StaticCellOutput {
ok: true,
text: "(static: this cell reads stdin; its input is supplied by foreign.call — see Execution)".to_string(),
},
);
} else {
run_order.push(cell.name.clone());
}
}
session.order = run_order;
}
let Ok(summary) = session.run_all_with_stdin(false, Some(stdin)) else {
session.close();
return out;
@@ -263,13 +239,6 @@ fn resolve_abs(root: &ViewRoot, rel: &str) -> Result<PathBuf> {
mod tests {
use super::*;
#[test]
fn detects_stdin_dependent_cells() {
assert!(cell_needs_stdin("import sys\njson.load(sys.stdin)"));
assert!(cell_needs_stdin("process.stdin.on('data', () => {})"));
assert!(!cell_needs_stdin("console.log('hello')"));
}
#[test]
fn injects_visible_static_cell_outputs() {
let html = r#"<div class="card" data-code-name="a"></div><pre class="code-out" hidden></pre>"#;