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
51 changes: 51 additions & 0 deletions Assets/Tests/Editor/SkillInstallLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,44 @@ public void GetToolDescriptionsByToolName_WhenSkillHasDescription_MapsDescriptio
Assert.That(descriptions[UnityCliLoopConstants.COMMAND_NAME_WAIT_FOR_PAUSE_POINT], Does.StartWith("Pauses Unity's playback"));
}

// Tests that duplicate skill names use the earlier source root across each precedence boundary.
[Test]
public void GetSkillSourceInfos_WhenNamesOverlap_PrefersEarlierSourceRoot()
{
string temporaryRoot = CreateTemporaryProjectRoot();
string manifestPackageRoot = CreateTemporaryProjectRoot();
string assetsRoot = Path.Combine(temporaryRoot, "Assets");
string directPackageRoot = Path.Combine(temporaryRoot, "Packages", "com.example.direct");
string cachePackageRoot = Path.Combine(
temporaryRoot,
"Library",
"PackageCache",
"com.example.cached@1.0.0");

WriteSourceSkill(assetsRoot, "uloop-assets-priority", "assets-winner", "AssetsWinner");
WriteSourceSkill(directPackageRoot, "uloop-assets-priority", "direct-loser", "DirectLoser");
WriteSourceSkill(directPackageRoot, "uloop-package-priority", "direct-winner", "DirectWinner");
WriteSourceSkill(manifestPackageRoot, "uloop-package-priority", "manifest-loser", "ManifestLoser");
WriteSourceSkill(manifestPackageRoot, "uloop-manifest-priority", "manifest-winner", "ManifestWinner");
WriteSourceSkill(cachePackageRoot, "uloop-manifest-priority", "cache-loser", "CacheLoser");

string manifestPath = Path.Combine(temporaryRoot, "Packages", "manifest.json");
Directory.CreateDirectory(Path.GetDirectoryName(manifestPath));
string portableManifestPackageRoot = manifestPackageRoot.Replace(Path.DirectorySeparatorChar, '/');
File.WriteAllText(
manifestPath,
$"{{\"dependencies\":{{\"com.example.manifest\":\"file:{portableManifestPackageRoot}\"," +
"\"com.example.cached\":\"1.0.0\"}}}");

Dictionary<string, SkillInstallLayout.SkillSourceInfo> skillSources = SkillInstallLayout
.GetSkillSourceInfos(temporaryRoot)
.ToDictionary(skill => skill.Name, StringComparer.Ordinal);

Assert.That(skillSources["uloop-assets-priority"].ToolName, Is.EqualTo("assets-winner"));
Assert.That(skillSources["uloop-package-priority"].ToolName, Is.EqualTo("direct-winner"));
Assert.That(skillSources["uloop-manifest-priority"].ToolName, Is.EqualTo("manifest-winner"));
}

// Tests that skill discovery follows bundled tools after they move into the first-party plugin assembly.
[Test]
public void GetSkillSourceInfos_WhenFirstPartyToolIsUnderFirstPartyTools_IncludesToolSkill()
Expand Down Expand Up @@ -347,6 +385,19 @@ private static void CreateFakeSourceSkill(
File.WriteAllText(Path.Combine(skillDir, additionalFileRelativePath), additionalFileContent);
}

private static void WriteSourceSkill(
string sourceRoot,
string skillName,
string toolName,
string toolDirectoryName)
{
string skillDirectory = Path.Combine(sourceRoot, "Editor", toolDirectoryName, "Skill");
Directory.CreateDirectory(skillDirectory);
File.WriteAllText(
Path.Combine(skillDirectory, SkillInstallLayout.SkillFileName),
$"---\nname: {skillName}\ntoolName: {toolName}\n---\n");
}

/// <summary>
/// Test support type used by editor fixtures.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,39 +167,49 @@ private static IEnumerable<string> EnumerateSourceSkillFiles(string searchRoot)

private static IEnumerable<string> EnumerateSkillSourceRoots(string projectRoot)
{
List<string> orderedRoots = new();
HashSet<string> seenRoots = new(StringComparer.Ordinal);

AddSkillSourceRoot(seenRoots, GetCliOnlySkillSourceRoot(projectRoot));
AddSkillSourceRoot(seenRoots, Path.Combine(projectRoot, "Assets"));
AddSkillSourceRoot(orderedRoots, seenRoots, GetCliOnlySkillSourceRoot(projectRoot));
AddSkillSourceRoot(orderedRoots, seenRoots, Path.Combine(projectRoot, "Assets"));
foreach (string packageRoot in EnumerateDirectProjectPackageRoots(projectRoot))
{
AddSkillSourceRoot(seenRoots, packageRoot);
AddSkillSourceRoot(orderedRoots, seenRoots, packageRoot);
}

foreach (string packageRoot in EnumerateManifestLocalPackageRoots(projectRoot))
{
AddSkillSourceRoot(seenRoots, packageRoot);
AddSkillSourceRoot(orderedRoots, seenRoots, packageRoot);
}

foreach (string packageRoot in EnumerateDependencyPackageCacheRoots(projectRoot))
{
AddSkillSourceRoot(seenRoots, packageRoot);
AddSkillSourceRoot(orderedRoots, seenRoots, packageRoot);
}

foreach (string root in seenRoots)
foreach (string root in orderedRoots)
{
yield return root;
}
}

private static void AddSkillSourceRoot(HashSet<string> roots, string root)
private static void AddSkillSourceRoot(
List<string> orderedRoots,
HashSet<string> seenRoots,
string root)
{
if (string.IsNullOrEmpty(root))
{
return;
}

roots.Add(Path.GetFullPath(root));
string normalizedRoot = Path.GetFullPath(root);
if (!seenRoots.Add(normalizedRoot))
{
return;
}

orderedRoots.Add(normalizedRoot);
}

private static string GetCliOnlySkillSourceRoot(string projectRoot)
Expand Down
Loading