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
58 changes: 38 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ homepage = "https://code0.tech"
license = "Apache-2.0"

[dependencies]
tucana = { version = "0.0.39", features = ["aquila"] }
tucana = { version = "0.0.42", features = ["aquila"] }
async-trait = "0.1.85"
log = "0.4.24"
tonic = "0.14.1"
dotenv = "0.15.0"
code0-definition-reader = "0.0.18"
tonic-health = "0.14.1"
async-nats = "0.45.0"
futures-core = "0.3.31"
regex = "1.11.2"
serde_json = "1.0.143"
walkdir = "2.5.0"
serde = "1.0.228"

[lib]
doctest = true

[features]
default = ["all"]
flow_definition = []
flow_service = ["flow_definition"]
flow_config = []
flow_health = []
flow_validator = []
all = ["flow_definition", "flow_config", "flow_health", "flow_validator"]
all = ["flow_definition", "flow_config", "flow_health", "flow_validator", "flow_service"]
23 changes: 23 additions & 0 deletions src/flow_definition/error/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::io;
use std::path::PathBuf;

#[derive(Debug)]
pub enum ReaderError {
JsonError {
path: PathBuf,
error: serde_json::Error,
},
ReadFeatureError {
path: String,
source: Box<ReaderError>,
},
ReadDirectoryError {
path: PathBuf,
error: io::Error,
},
ReadFileError {
path: PathBuf,
error: io::Error,
},
DirectoryEntryError(io::Error),
}
Comment on lines +4 to +23
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReaderError enum lacks documentation. Error types should be documented to help users understand when each error occurs:

/// Errors that can occur while reading definition files.
#[derive(Debug)]
pub enum ReaderError {
    /// Failed to parse JSON from a definition file.
    JsonError {
        /// The path to the file that failed to parse
        path: PathBuf,
        /// The underlying JSON parsing error
        error: serde_json::Error,
    },
    /// Failed to read a feature's definitions.
    ReadFeatureError {
        /// The path to the feature directory
        path: String,
        /// The underlying error that caused this failure
        source: Box<ReaderError>,
    },
    /// Failed to read a directory.
    ReadDirectoryError {
        /// The path to the directory that failed to read
        path: PathBuf,
        /// The underlying I/O error
        error: io::Error,
    },
    /// Failed to read a file.
    ReadFileError {
        /// The path to the file that failed to read
        path: PathBuf,
        /// The underlying I/O error
        error: io::Error,
    },
    /// Failed to read a directory entry.
    DirectoryEntryError(io::Error),
}

Copilot uses AI. Check for mistakes.
12 changes: 12 additions & 0 deletions src/flow_definition/feature/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod version;

use serde::Deserialize;
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition};

#[derive(Deserialize, Debug, Clone)]
pub struct Feature {
pub name: String,
pub data_types: Vec<DefinitionDataType>,
pub flow_types: Vec<FlowType>,
Comment on lines +5 to +10
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Feature struct lacks documentation. Public structs should have doc comments explaining their purpose and fields:

/// Represents a feature containing related flow definitions.
///
/// A feature groups together data types, flow types, and runtime function
/// definitions that belong to the same logical feature or module.
#[derive(Deserialize, Debug, Clone)]
pub struct Feature {
    /// The name of the feature
    pub name: String,
    /// Data type definitions associated with this feature
    pub data_types: Vec<DefinitionDataType>,
    /// Flow type definitions associated with this feature
    pub flow_types: Vec<FlowType>,
    /// Runtime function definitions associated with this feature
    pub functions: Vec<RuntimeFunctionDefinition>,
}
Suggested change
#[derive(Deserialize, Debug, Clone)]
pub struct Feature {
pub name: String,
pub data_types: Vec<DefinitionDataType>,
pub flow_types: Vec<FlowType>,
/// Represents a feature containing related flow definitions.
///
/// A feature groups together data types, flow types, and runtime function
/// definitions that belong to the same logical feature or module.
#[derive(Deserialize, Debug, Clone)]
pub struct Feature {
/// The name of the feature.
pub name: String,
/// Data type definitions associated with this feature.
pub data_types: Vec<DefinitionDataType>,
/// Flow type definitions associated with this feature.
pub flow_types: Vec<FlowType>,
/// Runtime function definitions associated with this feature.

Copilot uses AI. Check for mistakes.
pub functions: Vec<RuntimeFunctionDefinition>,
}
50 changes: 50 additions & 0 deletions src/flow_definition/feature/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition, Version};

pub trait HasVersion {
fn version(&self) -> &Option<Version>;
fn version_mut(&mut self) -> &mut Option<Version>;

fn normalize_version(&mut self) {
self.version_mut().get_or_insert(Version {
major: 0,
minor: 0,
patch: 0,
});
}

fn is_accepted(&self, filter: &Option<Version>) -> bool {
filter
.as_ref()
.is_none_or(|v| self.version().as_ref() == Some(v))
}
}
Comment on lines +3 to +20
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HasVersion trait and its methods lack documentation. Public traits should have comprehensive doc comments:

/// A trait for types that have version information.
///
/// This trait provides version handling capabilities including normalization
/// to default versions and filtering by version.
pub trait HasVersion {
    /// Returns a reference to the version option.
    fn version(&self) -> &Option<Version>;
    
    /// Returns a mutable reference to the version option.
    fn version_mut(&mut self) -> &mut Option<Version>;

    /// Normalizes the version to 0.0.0 if not set.
    ///
    /// This ensures that all definitions have a version, defaulting to 0.0.0
    /// for definitions without an explicit version.
    fn normalize_version(&mut self) {
        // ...
    }

    /// Checks if this item is accepted by the given version filter.
    ///
    /// # Parameters
    /// * `filter` - If None, accepts all versions. If Some, only accepts exact matches.
    ///
    /// # Returns
    /// `true` if the item matches the filter criteria, `false` otherwise.
    fn is_accepted(&self, filter: &Option<Version>) -> bool {
        // ...
    }
}

Copilot uses AI. Check for mistakes.

impl HasVersion for DefinitionDataType {
fn version(&self) -> &Option<Version> {
&self.version
}

fn version_mut(&mut self) -> &mut Option<Version> {
&mut self.version
}
}

impl HasVersion for FlowType {
fn version(&self) -> &Option<Version> {
&self.version
}

fn version_mut(&mut self) -> &mut Option<Version> {
&mut self.version
}
}

impl HasVersion for RuntimeFunctionDefinition {
fn version(&self) -> &Option<Version> {
&self.version
}

fn version_mut(&mut self) -> &mut Option<Version> {
&mut self.version
}
}
Comment on lines +3 to +50
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HasVersion trait and its implementations lack test coverage. Consider adding tests to verify:

  • normalize_version correctly sets default version (0.0.0) when None
  • normalize_version doesn't overwrite existing versions
  • is_accepted correctly filters based on version
  • is_accepted returns true when filter is None
  • All three implementations work correctly for their respective types

Add tests in a #[cfg(test)] module.

Copilot uses AI. Check for mistakes.
Loading