-
Notifications
You must be signed in to change notification settings - Fork 10
feat(spider-storage): Add ValidatedJobSubmission to hold a validated task graph and its task inputs.
#320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sitaowang1998
merged 11 commits into
y-scope:main
from
sitaowang1998:validate-job-submission
May 9, 2026
Merged
feat(spider-storage): Add ValidatedJobSubmission to hold a validated task graph and its task inputs.
#320
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
20bea90
Add ValidatedJobSubmission
sitaowang1998 327d793
Rename function
sitaowang1998 e489f9e
Fix error type
sitaowang1998 7e759b3
Move ValidatedJobSubmission into storage
sitaowang1998 3b5fcf8
Fix error
sitaowang1998 bdd9d3e
Fix docstring
sitaowang1998 4dc7cd8
Task graph consume validated job submission
sitaowang1998 b53714d
Fix docstring
sitaowang1998 f9e1163
Apply suggestions from code review
sitaowang1998 1e09f8d
Rename validate to create
sitaowang1998 935d8a5
Merge branch 'validate-job-submission' of github.com:sitaowang1998/sp…
sitaowang1998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| use spider_core::{task::TaskGraph, types::io::TaskInput}; | ||
|
|
||
| use super::error::InternalError; | ||
|
|
||
| /// A validated wrapper around a task graph and its corresponding job inputs. | ||
| /// | ||
| /// This type guarantees at construction time that: | ||
| /// | ||
| /// * The task graph contains at least one task. | ||
| /// * The number of job inputs matches the number of graph inputs expected by the task graph. | ||
| /// | ||
| /// By passing this type through the call chain, downstream consumers can trust the consistency | ||
| /// invariant without re-validating. | ||
| #[derive(Debug)] | ||
| pub struct ValidatedJobSubmission { | ||
| task_graph: TaskGraph, | ||
| inputs: Vec<TaskInput>, | ||
| } | ||
|
|
||
| impl ValidatedJobSubmission { | ||
| /// Creates a new validated job submission. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// The validated job submission on success. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if: | ||
| /// | ||
| /// * [`InternalError::TaskGraphEmpty`] if the task graph contains no tasks. | ||
| /// * [`InternalError::TaskGraphInputSizeMismatch`] if the number of inputs does not match the | ||
| /// number of graph inputs. | ||
| pub fn validate(task_graph: TaskGraph, inputs: Vec<TaskInput>) -> Result<Self, InternalError> { | ||
| let num_tasks = task_graph.get_num_tasks(); | ||
| if num_tasks == 0 { | ||
| return Err(InternalError::TaskGraphEmpty); | ||
| } | ||
| let expected_inputs = task_graph.get_task_graph_input_indices().len(); | ||
| let actual_inputs = inputs.len(); | ||
| if expected_inputs != actual_inputs { | ||
| return Err(InternalError::TaskGraphInputSizeMismatch { | ||
| expected: expected_inputs, | ||
| actual: actual_inputs, | ||
| }); | ||
| } | ||
|
sitaowang1998 marked this conversation as resolved.
Outdated
|
||
| Ok(Self { task_graph, inputs }) | ||
| } | ||
|
|
||
| /// # Returns | ||
| /// | ||
| /// A reference to the validated task graph. | ||
| #[must_use] | ||
| pub const fn task_graph(&self) -> &TaskGraph { | ||
| &self.task_graph | ||
| } | ||
|
|
||
| /// # Returns | ||
| /// | ||
| /// A reference to the validated job inputs. | ||
| #[must_use] | ||
| pub fn inputs(&self) -> &[TaskInput] { | ||
| &self.inputs | ||
| } | ||
|
|
||
| /// Consumes the wrapper and returns the owned task graph and job inputs. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// A tuple of `(task_graph, inputs)`. | ||
| #[must_use] | ||
| pub fn into_parts(self) -> (TaskGraph, Vec<TaskInput>) { | ||
| (self.task_graph, self.inputs) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use spider_core::{ | ||
| task::{ | ||
| DataTypeDescriptor, | ||
| ExecutionPolicy, | ||
| TaskDescriptor, | ||
| TaskGraph as SubmittedTaskGraph, | ||
| TdlContext, | ||
| ValueTypeDescriptor, | ||
| }, | ||
| types::io::TaskInput, | ||
| }; | ||
|
|
||
| use super::{super::error::InternalError, *}; | ||
|
|
||
| fn create_single_input_task_graph() -> SubmittedTaskGraph { | ||
| let bytes_type = DataTypeDescriptor::Value(ValueTypeDescriptor::bytes()); | ||
| let mut graph = | ||
| SubmittedTaskGraph::new(None, None).expect("task graph creation should succeed"); | ||
| graph | ||
| .insert_task(TaskDescriptor { | ||
| tdl_context: TdlContext { | ||
| package: "test_pkg".to_owned(), | ||
| task_func: "test_fn".to_owned(), | ||
| }, | ||
| execution_policy: Some(ExecutionPolicy::default()), | ||
| inputs: vec![bytes_type], | ||
| outputs: vec![], | ||
| input_sources: None, | ||
| }) | ||
| .expect("task insertion should succeed"); | ||
| graph | ||
| } | ||
|
|
||
| #[test] | ||
| fn valid_job_submission_succeeds() { | ||
| let graph = create_single_input_task_graph(); | ||
| let inputs = vec![TaskInput::ValuePayload(vec![1u8; 4])]; | ||
| let result = ValidatedJobSubmission::validate(graph, inputs); | ||
| assert!(result.is_ok(), "valid submission should succeed"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn empty_task_graph_fails() { | ||
| let graph = | ||
| SubmittedTaskGraph::new(None, None).expect("task graph creation should succeed"); | ||
| let inputs = vec![]; | ||
| let result = ValidatedJobSubmission::validate(graph, inputs); | ||
| assert!( | ||
| matches!(result, Err(InternalError::TaskGraphEmpty)), | ||
| "empty task graph should return EmptyTaskGraph" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn mismatched_input_count_fails() { | ||
| let graph = create_single_input_task_graph(); | ||
| let inputs = vec![]; | ||
| let result = ValidatedJobSubmission::validate(graph, inputs); | ||
| assert!( | ||
| matches!( | ||
| result, | ||
| Err(InternalError::TaskGraphInputSizeMismatch { | ||
| expected: 1, | ||
| actual: 0 | ||
| }) | ||
| ), | ||
| "mismatched input count should return TaskGraphInputSizeMismatch" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn into_parts_returns_owned_components() { | ||
| let graph = create_single_input_task_graph(); | ||
| let inputs = vec![TaskInput::ValuePayload(vec![1u8; 4])]; | ||
| let submission = | ||
| ValidatedJobSubmission::validate(graph, inputs).expect("submission should be valid"); | ||
| let (graph, inputs) = submission.into_parts(); | ||
| assert_eq!(graph.get_num_tasks(), 1, "task graph should have 1 task"); | ||
| assert_eq!(inputs.len(), 1, "should have 1 input"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.