Skip to content

Commit 308b03f

Browse files
(MAINT) Address copilot review
1 parent 1a8a212 commit 308b03f

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

lib/dsc-lib/locales/schemas.definitions.yaml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,28 @@ schemas:
5858
exactly the same characters - the comparison is case-sensitive. If you're defining a
5959
resource that doesn't follow semantic versioning, consider defining the version as an
6060
[ISO 8601 date][04], like `2026-01-15`. When you do, DSC can correctly determine that a
61-
later date should be treated as a newer version. stringVariant: title: en-us: Arbitrary
62-
version string description: en-us: >- Defines the version for the type as an arbitrary
63-
string. deprecationMessage: en-us: >- Arbitrary string versions for resources are only in
64-
place for compatibility with ARM. Resource authors should define their resources with
65-
valid semantic versions, like `1.2.3`. markdownDescription: en-us: |- Defines the version
66-
for the type as an arbitrary string. When the version for the type isn't a valid semantic
67-
version, DSC treats the version as a string. This enables DSC to support
68-
non-semantically-versioned types, such as using a release date as the version.
61+
later date should be treated as a newer version.
6962
7063
[01]: https://learn.microsoft.com/powershell/dsc/reference/schemas/definitions/semver
7164
[02]: https://learn.microsoft.com/powershell/dsc/reference/schemas/definitions/semverReq
7265
[03]: https://doc.rust-lang.org/std/cmp/trait.Ord.html#lexicographical-comparison
7366
[04]: https://www.iso.org/iso-8601-date-and-time-format.html
67+
stringVariant:
68+
title:
69+
en-us: Arbitrary version string
70+
description:
71+
en-us: >-
72+
Defines the version for the type as an arbitrary string.
73+
deprecationMessage:
74+
en-us: >-
75+
Arbitrary string versions for resources are only in place for compatibility with ARM.
76+
Resource authors should define their resources with valid semantic versions, like
77+
`1.2.3`.
78+
markdownDescription:
79+
en-us: |-
80+
Defines the version for the type as an arbitrary string. When the version for the type
81+
isn't a valid semantic version, DSC treats the version as a string. This enables DSC to
82+
support non-semantically-versioned types, such as using a release date as the version.
7483
semanticVariant:
7584
title:
7685
en-us: Semantic resource version
@@ -196,12 +205,14 @@ schemas:
196205
version and this version requirement are exactly the same. The comparison is
197206
case-sensitive.
198207
208+
[01]: https://learn.microsoft.com/powershell/dsc/reference/schemas/definitions/resourceVersion
209+
199210
semver:
200211
title:
201212
en-us: Semantic version
202213
description:
203214
en-us: |-
204-
Defines a valid semantic version (semver)as a string.
215+
Defines a valid semantic version (semver) as a string.
205216
206217
For reference, see https://semver.org/
207218
markdownDescription:

lib/dsc-lib/src/types/semantic_version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ use serde::{Deserialize, Serialize};
190190
/// let v2_0_0: SemanticVersion = "2.0.0".parse().unwrap();
191191
/// let v1_2_3: SemanticVersion = "1.2.3".parse().unwrap();
192192
/// let v1_2_3_pre: SemanticVersion = "1.2.3-rc.1".parse().unwrap();
193-
/// let v1_2_3_build: SemanticVersion = "1.2.3+rci.1".parse().unwrap();
193+
/// let v1_2_3_build: SemanticVersion = "1.2.3+ci.1".parse().unwrap();
194194
/// let v1_2_3_pre_build: SemanticVersion = "1.2.3-rc.1+ci.1".parse().unwrap();
195195
///
196196
/// // Comparisons of stable versions work as expected
@@ -573,7 +573,7 @@ impl PartialEq<str> for SemanticVersion {
573573

574574
impl PartialEq<SemanticVersion> for str {
575575
fn eq(&self, other: &SemanticVersion) -> bool {
576-
match SemanticVersion::parse(&self) {
576+
match SemanticVersion::parse(self) {
577577
Ok(version) => version.eq(other),
578578
Err(_) => false,
579579
}

lib/dsc-lib/src/types/semantic_version_req.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ use crate::{dscerror::DscError, schemas::dsc_repo::DscRepoSchema, types::Semanti
118118
///
119119
/// You can specify the minor and patch version segments as a wildcard with the asterisk (`*`)
120120
/// character, indicating that it should match any version for that segment. If the minor version
121-
/// segment is a wildcard,the patch version segment must either be a wildcard or omitted.
121+
/// segment is a wildcard, the patch version segment must either be a wildcard or omitted.
122122
///
123123
/// When specifying an explicit operator, specifying the version for a comparator with wildcards is
124124
/// equivalent to omitting those version segments. When you define a comparator without an explicit
@@ -144,7 +144,7 @@ use crate::{dscerror::DscError, schemas::dsc_repo::DscRepoSchema, types::Semanti
144144
/// | `^1.2` | `>=1.2.0, <2.0.0` | `1.2`, `^1.2.*` |
145145
/// | `^1.2.*` | `>=1.2.0, <2.0.0` | `1.2` |
146146
/// | `=1` | `>=1.0.0, <2.0.0` | `1`, `1.*`, `1.*.*`, `^1`, `^1.*`, `^1.*.*`, `=1.*`, `=1.*.*` |
147-
/// | `=1.*` | `>=1,0.0, <2.0.0` | `1`, `1.*`, `1.*.*`, `^1`, `^1.*`, `^1.*.*`, `=1`, `=1.*.*` |
147+
/// | `=1.*` | `>=1.0.0, <2.0.0` | `1`, `1.*`, `1.*.*`, `^1`, `^1.*`, `^1.*.*`, `=1`, `=1.*.*` |
148148
/// | `=1.*.*` | `>=1.0.0, <2.0.0` | `1`, `1.*`, `1.*.*`, `^1`, `^1.*`, `^1.*.*`, `=1`, `=1.*` |
149149
/// | `=1.2` | `>=1.2.0, <1.3.0` | `1.2.*`, `=1.2.*` |
150150
/// | `=1.2.*` | `>=1.2.0, <1.3.0` | `1.2.*`, `=1.2` |
@@ -263,15 +263,15 @@ use crate::{dscerror::DscError, schemas::dsc_repo::DscRepoSchema, types::Semanti
263263
/// be less than the version for this comparator. Versions equal to or greater than the
264264
/// comparator version don't match the comparator.
265265
///
266-
/// | Literal comparator | Effective requirement | Valid versions | Invalid versions |
267-
/// |:------------------:|:---------------------:|:---------------------------------------|:------------------------------------------------|
268-
/// | `<1` | `<1.0.0` |`0.1.0` | `1.0.0`, `1.2.0`, `1.2.3`, `0.1.0-rc.1` |
269-
/// | `<1.*` | `<1.0.0` |`0.1.0` | `1.0.0`, `1.2.0`, `1.2.3`, `0.1.0-rc.1` |
270-
/// | `<1.*.*` | `<1.0.0` |`0.1.0` | `1.0.0`, `1.2.0`, `1.2.3`, `0.1.0-rc.1` |
271-
/// | `<1.2` | `<1.2.0` | 0.1.0`, `1.0.0`, `1.1.1` | `1.2.0`, `1.2.3`, `1.3.0`, `1.2.0-rc.1`, |
272-
/// | `<1.2.*` | `<1.2.0` | 0.1.0`, `1.0.0`, `1.1.1` | `1.2.0`, `1.2.3`, `1.3.0`, `1.2.0-rc.1`, |
273-
/// | `<1.2.3` | `<1.2.3` | 0.1.0`, `1.0.0`, `1.2.0` | `1.2.3`, `1.3.0`, `1.2.3-rc.1` |
274-
/// | `<1.2.3-rc.2` | `<1.2.3-rc.2` | 0.1.0`, `1.0.0`, `1.2.0`, `1.2.3-rc.1` | `1.2.3`, `1.3.0`, `1.0.0-rc.1`, ``1.2.3-rc.2 |
266+
/// | Literal comparator | Effective requirement | Valid versions | Invalid versions |
267+
/// |:------------------:|:----------------------:|:----------------------------------------|:---------------------------------------------|
268+
/// | `<1` | `<1.0.0` | `0.1.0` | `1.0.0`, `1.2.0`, `1.2.3`, `0.1.0-rc.1` |
269+
/// | `<1.*` | `<1.0.0` | `0.1.0` | `1.0.0`, `1.2.0`, `1.2.3`, `0.1.0-rc.1` |
270+
/// | `<1.*.*` | `<1.0.0` | `0.1.0` | `1.0.0`, `1.2.0`, `1.2.3`, `0.1.0-rc.1` |
271+
/// | `<1.2` | `<1.2.0` | `0.1.0`, `1.0.0`, `1.1.1` | `1.2.0`, `1.2.3`, `1.3.0`, `1.2.0-rc.1`, |
272+
/// | `<1.2.*` | `<1.2.0` | `0.1.0`, `1.0.0`, `1.1.1` | `1.2.0`, `1.2.3`, `1.3.0`, `1.2.0-rc.1`, |
273+
/// | `<1.2.3` | `<1.2.3` | `0.1.0`, `1.0.0`, `1.2.0` | `1.2.3`, `1.3.0`, `1.2.3-rc.1` |
274+
/// | `<1.2.3-rc.2` | `<1.2.3-rc.2` | `0.1.0`, `1.0.0`, `1.2.0`, `1.2.3-rc.1` | `1.2.3`, `1.3.0`, `1.0.0-rc.1`, `1.2.3-rc.2` |
275275
///
276276
/// - <a id="operator-less-than-or-equal-to"></a>Less than or equal to (`<=`) - Indicates that the
277277
/// [`SemanticVersion`] must be any version up to the version for this comparator. Versions
@@ -355,7 +355,7 @@ use crate::{dscerror::DscError, schemas::dsc_repo::DscRepoSchema, types::Semanti
355355
/// 1. If the version doesn't define any wildcards, the implicit operator for the comparator is
356356
/// the caret operator. The following sets of comparators are parsed identically:
357357
///
358-
/// - `1` and `^ `
358+
/// - `1` and `^1`
359359
/// - `1.2` and `^1.2`
360360
/// - `1.2.3` and `^1.2.3`
361361
/// - `1.2.3-rc.1` and `^1.2.3-rc.1`
@@ -657,7 +657,7 @@ impl SemanticVersionReq {
657657
/// |:----------------:|:-----:|:------------------------------------------------------------------------------------|
658658
/// | `1.*` | Yes | Defines a literal major version segment followed by a wildcard minor version. |
659659
/// | `1.2.*` | Yes | Defines literal major and minor segments followed by a wildcard patch version. |
660-
/// | `1.*.*` | No | Defines more than one wildcard, which is forbidden. |
660+
/// | `1.*.*` | Yes | Equivalent to `1.*` - both wildcards match any minor and patch version. |
661661
/// | `1.*.3` | No | If the version includes any wildcards, it must be the last defined version segment. |
662662
/// | `1.2.3-*` | No | Defines the prerelease segment as a wildcard, which is forbidden. |
663663
pub const WILDCARD_VERSION_PATTERN: &str = const_str::concat!(
@@ -771,10 +771,7 @@ impl FromStr for SemanticVersionReq {
771771
impl TryFrom<String> for SemanticVersionReq {
772772
type Error = DscError;
773773
fn try_from(value: String) -> Result<Self, Self::Error> {
774-
match semver::VersionReq::parse(value.as_str()) {
775-
Ok(r) => Ok(Self(r)),
776-
Err(e) => Err(DscError::SemVer(e)),
777-
}
774+
Self::parse(value.as_str())
778775
}
779776
}
780777

lib/dsc-lib/tests/integration/types/resource_version_req.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ mod schema {
177177
LazyLock::new(|| Validator::new((&*ROOT_SCHEMA).as_value()).unwrap());
178178

179179
static KEYWORD_PATTERN: LazyLock<Regex> =
180-
LazyLock::new(|| Regex::new(r"^\w+(\.\w+)+$").expect("pattern is semantic"));
180+
LazyLock::new(|| Regex::new(r"^\w+(\.\w+)+$").expect("pattern is valid"));
181181

182182
#[test_case("title", &*ROOT_SCHEMA; "title")]
183183
#[test_case("description", &*ROOT_SCHEMA; "description")]
@@ -207,18 +207,18 @@ mod schema {
207207
)
208208
}
209209

210-
#[test_case(&json!("^1.2.3") => true ; "single comparator semantic version req string value is semantic")]
211-
#[test_case(&json!("^1.2.3, <1.5") => true ; "multi comparator semantic version req string value is semantic")]
212-
#[test_case(&json!("=1.2.3a") => true ; "invalid semantic version req string value is semantic")]
213-
#[test_case(&json!("2026-01-15") => true ; "iso8601 date full string value is semantic")]
214-
#[test_case(&json!("2026-01") => true ; "iso8601 date year month string value is semantic")]
215-
#[test_case(&json!("arbitrary_string") => true ; "arbitrary string value is semantic")]
216-
#[test_case(&json!(true) => false; "boolean value is arbitrary")]
217-
#[test_case(&json!(1) => false; "integer value is arbitrary")]
218-
#[test_case(&json!(1.2) => false; "float value is arbitrary")]
219-
#[test_case(&json!({"version": "1.2.3"}) => false; "object value is arbitrary")]
220-
#[test_case(&json!(["1.2.3"]) => false; "array value is arbitrary")]
221-
#[test_case(&serde_json::Value::Null => false; "null value is arbitrary")]
210+
#[test_case(&json!("^1.2.3") => true ; "single comparator semantic version req string value is valid")]
211+
#[test_case(&json!("^1.2.3, <1.5") => true ; "multi comparator semantic version req string value is valid")]
212+
#[test_case(&json!("=1.2.3a") => true ; "invalid semantic version req string value is valid")]
213+
#[test_case(&json!("2026-01-15") => true ; "iso8601 date full string value is valid")]
214+
#[test_case(&json!("2026-01") => true ; "iso8601 date year month string value is valid")]
215+
#[test_case(&json!("arbitrary_string") => true ; "arbitrary string value is valid")]
216+
#[test_case(&json!(true) => false; "boolean value is invalid")]
217+
#[test_case(&json!(1) => false; "integer value is invalid")]
218+
#[test_case(&json!(1.2) => false; "float value is invalid")]
219+
#[test_case(&json!({"version": "1.2.3"}) => false; "object value is invalid")]
220+
#[test_case(&json!(["1.2.3"]) => false; "array value is invalid")]
221+
#[test_case(&serde_json::Value::Null => false; "null value is invalid")]
222222
fn validation(input_json: &Value) -> bool {
223223
(&*VALIDATOR).validate(input_json).is_ok()
224224
}

0 commit comments

Comments
 (0)