Skip to main content

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!("{version} (git: {git_hash}, built: {build_date})")
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn test_get_version_returns_valid_semver() {
29        let version = get_version();
30        assert!(!version.is_empty());
31        // Basic semver format check
32        let parts: Vec<&str> = version.split('.').collect();
33        assert!(parts.len() >= 2, "Version should have at least major.minor");
34    }
35
36    #[test]
37    fn test_get_version_long_contains_version() {
38        let long = get_version_long();
39        let short = get_version();
40        assert!(
41            long.contains(&short),
42            "Long version should contain short version"
43        );
44    }
45}