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
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class ApplicableToJsonConverter : JsonConverter<ApplicableTo>
Self = deploymentProps.TryGetValue("self", out var self) ? new AppliesCollection(self.ToArray()) : null,
Ece = deploymentProps.TryGetValue("ece", out var ece) ? new AppliesCollection(ece.ToArray()) : null,
Eck = deploymentProps.TryGetValue("eck", out var eck) ? new AppliesCollection(eck.ToArray()) : null,
Ess = deploymentProps.TryGetValue("ess", out var ess) ? new AppliesCollection(ess.ToArray()) : null
Ess = deploymentProps.TryGetValue("ech", out var ess) || deploymentProps.TryGetValue("ess", out ess) ? new AppliesCollection(ess.ToArray()) : null
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ApplicableToYamlConverter(IReadOnlyCollection<string> productKeys)
private readonly string[] _knownKeys =
[
"stack", "deployment", "serverless", "product", // Applicability categories
"ece", "eck", "ess", "self", // Deployment options
"ece", "eck", "ess", "ech", "self", // Deployment options ("ech" aliasing to "ess")
"elasticsearch", "observability", "security", // Serverless flavors
.. productKeys
];
Expand Down Expand Up @@ -146,11 +146,17 @@ private static bool TryGetDeployment(Dictionary<object, object?> dictionary, Lis
var d = new DeploymentApplicability();
var assigned = false;

var hasEss = dictionary.ContainsKey("ess");
var hasEch = dictionary.ContainsKey("ech");
if (hasEss && hasEch)
diagnostics.Add((Severity.Warning, "Both 'ess' and 'ech' are defined. Move 'ess' content into 'ech' to avoid information loss."));

var mapping = new Dictionary<string, Action<AppliesCollection?>>
{
{ "ece", a => d.Ece = a },
{ "eck", a => d.Eck = a },
{ "ess", a => d.Ess = a },
{ "ech", a => d.Ess = a },
{ "self", a => d.Self = a }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,43 @@ public void RoundTripComplexAllFieldsPopulated()
deserialized.ProductApplicability.ApmAgentDotnet.Should().BeEquivalentTo(original.ProductApplicability.ApmAgentDotnet);
}

[Fact]
public void RoundTripDeploymentEssRoundTripsCorrectly()
{
var original = new ApplicableTo
{
Deployment = new DeploymentApplicability
{
Ess = new AppliesCollection([new Applicability { Lifecycle = ProductLifecycle.GenerallyAvailable, Version = (VersionSpec)"9.0.0" }])
}
};

var json = JsonSerializer.Serialize(original, _options);
var deserialized = JsonSerializer.Deserialize<ApplicableTo>(json, _options);
Copy link
Member

@reakaleek reakaleek Feb 23, 2026

Choose a reason for hiding this comment

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

I don't think we need to test the JSON deserializer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, changed it to the pattern elsewhere in the tests now.

Copy link
Member

Choose a reason for hiding this comment

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

Ah nevermind. I just realized the alias logic is within the serializer?


deserialized.Should().NotBeNull();
deserialized!.Deployment.Should().NotBeNull();
deserialized.Deployment!.Ess.Should().BeEquivalentTo(original.Deployment!.Ess);
}

[Fact]
public void BothEssAndEchSubTypes_EchWins()
{
var json = """
[
{ "type": "deployment", "sub_type": "ess", "lifecycle": "ga", "version": "9.0.0" },
{ "type": "deployment", "sub_type": "ech", "lifecycle": "beta", "version": "9.1.0" }
]
""";

var deserialized = JsonSerializer.Deserialize<ApplicableTo>(json, _options);

deserialized.Should().NotBeNull();
deserialized!.Deployment.Should().NotBeNull();
deserialized.Deployment!.Ess.Should().NotBeNull();
deserialized.Deployment.Ess!.First().Lifecycle.Should().Be(ProductLifecycle.Beta);
}

[Fact]
public void RoundTripAllLifecycles()
{
Expand Down
68 changes: 68 additions & 0 deletions tests/authoring/Applicability/AppliesToFrontMatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,74 @@ applies_to:
)
))

type ``parses ech as alias for ess`` () =
static let markdown = frontMatter """
applies_to:
deployment:
ech: ga 9.0
"""
[<Fact>]
let ``apply matches expected`` () =
markdown |> appliesTo (ApplicableTo(
Deployment=DeploymentApplicability(
Ess=AppliesCollection.op_Explicit "ga 9.0"
)
))

type ``parses ech with version alongside other deployment types`` () =
static let markdown = frontMatter """
applies_to:
deployment:
ech: beta 9.1
eck: ga 9.0
ece: removed 9.2.0
self: unavailable 9.3.0
"""
[<Fact>]
let ``apply matches expected`` () =
markdown |> appliesTo (ApplicableTo(
Deployment=DeploymentApplicability(
Ess=AppliesCollection.op_Explicit "beta 9.1",
Eck=AppliesCollection.op_Explicit "ga 9.0",
Ece=AppliesCollection.op_Explicit "removed 9.2.0",
Self=AppliesCollection.op_Explicit "unavailable 9.3.0"
)
))

type ``both ess and ech defined uses ech value and warns`` () =
static let markdown = frontMatter """
applies_to:
deployment:
ess: ga 9.0
ech: beta 9.1
"""
[<Fact>]
let ``ech value wins`` () =
markdown |> appliesTo (ApplicableTo(
Deployment=DeploymentApplicability(
Ess=AppliesCollection.op_Explicit "beta 9.1"
)
))

[<Fact>]
let ``emits warning about both being defined`` () =
markdown |> hasWarning "Both 'ess' and 'ech' are defined"

type ``parses ech at top level`` () =
static let markdown = frontMatter """
applies_to:
ech: preview 9.1
stack: ga 9.1
"""
[<Fact>]
let ``apply matches expected`` () =
markdown |> appliesTo (ApplicableTo(
Deployment=DeploymentApplicability(
Ess=AppliesCollection.op_Explicit "preview 9.1"
),
Stack=AppliesCollection.op_Explicit "ga 9.1.0"
))

type ``parses product coming DEPRECATED`` () =
static let markdown = frontMatter """
applies_to:
Expand Down
16 changes: 16 additions & 0 deletions tests/authoring/Inline/AppliesToRole.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ This is an inline {applies_to}`ess: preview 9.1` element.
)
))

type ``parses nested ech moniker as ess`` () =
static let markdown = Setup.Markdown """

This is an inline {applies_to}`ech: preview 9.1` element.
"""

[<Fact>]
let ``parses to AppliesDirective`` () =
let directives = markdown |> converts "index.md" |> parses<AppliesToRole>
test <@ directives.Length = 1 @>
directives |> appliesToDirective (ApplicableTo(
Deployment=DeploymentApplicability(
Ess=AppliesCollection.op_Explicit "preview 9.1.0"
)
))

type ``parses {preview} shortcut`` () =
static let markdown = Setup.Markdown """

Expand Down
Loading