Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 131 additions & 142 deletions crates/vite_task/src/session/reporter/labeled.rs

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions crates/vite_task/src/session/reporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,49 @@ impl LeafExecutionPath {
}
unreachable!("LeafExecutionPath: empty path")
}

/// Return true when this leaf is contained in a chain of execution graphs where
/// every graph (root + all nested `Expanded` ancestors) has exactly one node.
///
/// This is used by the labeled reporter to determine whether inherited stdio can
/// be suggested for spawned processes.
///
/// # Panics
///
/// - If the path is empty (indicates a bug in path construction).
/// - If an intermediate path element points to a `Leaf` item instead of
/// `Expanded`.
fn all_containing_graphs_single_node(&self, root_graph: &ExecutionGraph) -> bool {
let Some((last_path_item, parent_path_items)) = self.0.split_last() else {
unreachable!("LeafExecutionPath: empty path")
};

let mut current_graph = root_graph;
if current_graph.node_count() != 1 {
return false;
}

for (depth, path_item) in parent_path_items.iter().enumerate() {
let item = path_item.resolve(current_graph);
match &item.kind {
ExecutionItemKind::Expanded(nested_graph) => {
current_graph = nested_graph;
if current_graph.node_count() != 1 {
return false;
}
}
ExecutionItemKind::Leaf(_) => {
unreachable!(
"LeafExecutionPath: intermediate element at depth {depth} is a Leaf, expected Expanded"
)
}
}
}

// Validate that the final path item resolves in the containing graph.
let _ = last_path_item.resolve(current_graph);
true
}
}

impl std::ops::Index<&LeafExecutionPath> for ExecutionGraph {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Tests stdin inheritance behavior for spawned tasks.
#
# Stdin is inherited from the parent process only when BOTH conditions are met:
# 1. The reporter suggests inherited stdin (single spawn leaf in the graph, or synthetic execution)
# 1. The reporter suggests inherited stdin (the leaf is in a single-node graph chain,
# or the execution uses PlainReporter for synthetic execution)
# 2. Caching is disabled for the task (cache_metadata is None)
#
# Otherwise, stdin is set to /dev/null.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "stdio-graph-criteria-test",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "other"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"tasks": {
"check-tty": {
"command": "check-tty",
"cache": false
},
"bar": {
"command": "check-tty",
"cache": false
},
"foo-nested": {
"command": "vp run bar",
"cache": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- packages/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tests stdio suggestion criteria based on graph shape along each leaf path.
#
# Rules under test:
# - Suggest piped when the leaf's containing graph has more than one node, or
# any ancestor graph on its path has more than one node.
# - Suggest inherited only when every graph on the path (root + nested Expanded
# graphs) has exactly one node.

[[e2e]]
name = "single-node chains inherit even with multi-node sibling graph"
steps = [
"vp run foo",
]

[[e2e]]
name = "multi-node ancestor forces piped for nested single-node graph"
steps = [
"vp run -r foo-nested",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
expression: e2e_outputs
---
> vp run -r foo-nested
~/packages/other$ check-tty ⊘ cache disabled: no cache config
stdin:not-tty
stdout:not-tty
stderr:not-tty

$ check-tty ⊘ cache disabled: no cache config
stdin:not-tty
stdout:not-tty
stderr:not-tty


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Vite+ Task Runner • Execution Summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Statistics: 2 tasks • 0 cache hits • 0 cache misses • 2 cache disabled
Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] other#bar: ~/packages/other$ check-tty ✓
→ Cache disabled in task configuration
·······················································
[2] stdio-graph-criteria-test#bar: $ check-tty ✓
→ Cache disabled in task configuration
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
expression: e2e_outputs
---
> vp run foo
$ check-tty ⊘ cache disabled: no cache config
stdin:tty
stdout:tty
stderr:tty

$ check-tty ⊘ cache disabled: no cache config
stdin:tty
stdout:tty
stderr:tty

~/packages/other$ check-tty ⊘ cache disabled: no cache config
stdin:not-tty
stdout:not-tty
stderr:not-tty

$ check-tty ⊘ cache disabled: no cache config
stdin:not-tty
stdout:not-tty
stderr:not-tty


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Vite+ Task Runner • Execution Summary
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Statistics: 4 tasks • 0 cache hits • 0 cache misses • 4 cache disabled
Performance: 0% cache hit rate

Task Details:
────────────────────────────────────────────────
[1] stdio-graph-criteria-test#foo: $ check-tty ✓
→ Cache disabled in task configuration
·······················································
[2] stdio-graph-criteria-test#bar: $ check-tty ✓
→ Cache disabled in task configuration
·······················································
[3] other#check-tty: ~/packages/other$ check-tty ✓
→ Cache disabled in task configuration
·······················································
[4] stdio-graph-criteria-test#check-tty: $ check-tty ✓
→ Cache disabled in task configuration
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"cacheScripts": true,
"tasks": {
"check-tty": {
"command": "check-tty",
"cache": false
},
"bar": {
"command": "check-tty",
"cache": false
},
"foo": {
"command": "check-tty && vp run bar && vp run -r check-tty",
"cache": false
},
"foo-nested": {
"command": "vp run bar",
"cache": false
}
}
}