Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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 @@ -1501,12 +1501,13 @@ private ParameterProvider BuildClientEndpointParameter()

private IReadOnlyList<ClientProvider> GetSubClients()
{
var seen = new HashSet<ClientProvider>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot instead of having this change in the generator, can we de-dup the children in the emitter so the generated code model has no duplicate entries?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the deduplication from the C# generator to the emitter in 4cd0636. The client-converter.ts now deduplicates children when populating the code model, and the ClientProvider.cs/ClientProviderTests.cs changes have been reverted.

var subClients = new List<ClientProvider>(_inputClient.Children.Count);

foreach (var client in _inputClient.Children)
{
var subClient = ScmCodeModelGenerator.Instance.TypeFactory.CreateClient(client);
if (subClient != null)
if (subClient != null && seen.Add(subClient))
{
subClients.Add(subClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,38 @@ public void TestBuildFields_ForParent_InitializedByParentOnly_WithSubClientParam
Assert.IsNull(cachingField, "Parent should not have caching field for subclient that has subclient-specific parameters in its accessor");
}

[Test]
public void TestBuildMethods_ForParent_DuplicateChildrenDoesNotCrash()
{
var parentClient = InputFactory.Client("ParentClient");
var subClient = InputFactory.Client(
"SubClient",
parent: parentClient,
initializedBy: InputClientInitializedBy.Parent);

// Simulate duplicate children (same InputClient appearing multiple times in children list)
parentClient.Update(children: [subClient, subClient]);

MockHelpers.LoadMockGenerator(
clients: () => [parentClient]);

var parentProvider = new ClientProvider(parentClient);

Assert.IsNotNull(parentProvider);

// Accessing Methods should not throw due to duplicate children
Assert.DoesNotThrow(() => { var _ = parentProvider.Methods; });

// The parent should have only one factory method for the subclient (not duplicated)
var factoryMethods = parentProvider.Methods.Where(
m => m.Signature?.Name == "GetSubClient" || m.Signature?.Name == "GetSubClientClient").ToList();
Assert.AreEqual(1, factoryMethods.Count, "Parent should have exactly one factory method for the subclient despite duplicate children");

// The parent should have only one caching field (not duplicated)
var cachingFields = parentProvider.Fields.Where(f => f.Name == "_cachedSubClient").ToList();
Assert.AreEqual(1, cachingFields.Count, "Parent should have exactly one caching field despite duplicate children");
}

private void ValidatePrimaryConstructor(
ConstructorProvider primaryPublicConstructor,
List<InputParameter> inputParameters,
Expand Down