opencode_cloud_core/
version.rs

1//! Version information for opencode-cloud
2
3/// Get the current version string
4pub fn get_version() -> String {
5    env!("CARGO_PKG_VERSION").to_string()
6}
7
8/// Get the long version string with build information
9///
10/// Returns version plus build metadata when available (git commit, build date).
11/// Falls back gracefully if build info is not available.
12pub fn get_version_long() -> String {
13    let version = get_version();
14
15    // Build info is set via environment variables during build
16    // These may be set by CI or build scripts
17    let git_hash = option_env!("OCC_GIT_HASH").unwrap_or("unknown");
18    let build_date = option_env!("OCC_BUILD_DATE").unwrap_or("unknown");
19
20    format!(
21        "{version} (git: {git_hash}, built: {build_date})",
22        version = version,
23        git_hash = git_hash,
24        build_date = build_date
25    )
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn test_get_version_returns_valid_semver() {
34        let version = get_version();
35        assert!(!version.is_empty());
36        // Basic semver format check
37        let parts: Vec<&str> = version.split('.').collect();
38        assert!(parts.len() >= 2, "Version should have at least major.minor");
39    }
40
41    #[test]
42    fn test_get_version_long_contains_version() {
43        let long = get_version_long();
44        let short = get_version();
45        assert!(
46            long.contains(&short),
47            "Long version should contain short version"
48        );
49    }
50}