-
-
Notifications
You must be signed in to change notification settings - Fork 60
refactor!: move base extension contracts to abstractions #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Beutl.Extensibility.Abstractions/Beutl.Extensibility.Abstractions.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Beutl.Configuration\Beutl.Configuration.csproj" /> | ||
| <ProjectReference Include="..\Beutl.Core\Beutl.Core.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/Beutl.Extensibility.Abstractions.Tests/Beutl.Extensibility.Abstractions.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <IsPackable>false</IsPackable> | ||
| <IsTestProject>true</IsTestProject> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
| <PackageReference Include="NUnit" /> | ||
| <PackageReference Include="NUnit3TestAdapter" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="NUnit.Framework" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Beutl.Extensibility.Abstractions\Beutl.Extensibility.Abstractions.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
102 changes: 102 additions & 0 deletions
102
tests/Beutl.Extensibility.Abstractions.Tests/ExtensibilityAbstractionsAssemblyTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| using System.Reflection; | ||
|
|
||
| using Beutl.Extensibility; | ||
|
|
||
| namespace Beutl.Extensibility.Abstractions.Tests; | ||
|
|
||
| [TestFixture] | ||
| public class ExtensibilityAbstractionsAssemblyTests | ||
| { | ||
| [Test] | ||
| public void BaseExtensionContracts_LiveInAbstractionsAssembly() | ||
| { | ||
| Assert.That(typeof(Extension).Assembly.GetName().Name, Is.EqualTo("Beutl.Extensibility.Abstractions")); | ||
| Assert.That(typeof(ExtensionSettings).Assembly, Is.SameAs(typeof(Extension).Assembly)); | ||
| Assert.That(typeof(ExportAttribute).Assembly, Is.SameAs(typeof(Extension).Assembly)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void MinimalExtension_CanUseOnlyAbstractionsProject() | ||
| { | ||
| var extension = new MinimalExtension(); | ||
|
|
||
| Assert.That(extension.Name, Is.EqualTo(nameof(MinimalExtension))); | ||
| Assert.That(extension.Settings, Is.TypeOf<MinimalSettings>()); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AbstractionsAssembly_DoesNotPullInHeavyImplementationDependencies() | ||
| { | ||
| // Walk the full closure, not just direct references: GetReferencedAssemblies() is pruned of | ||
| // unused references, so a heavy but not-type-referenced dependency would slip a direct-only check. | ||
| HashSet<string> closure = CollectReferencedAssemblyClosure(typeof(Extension).Assembly); | ||
|
|
||
| // The thin layer must never reach the heavy UI/media layer, directly or transitively. | ||
| string[] heavyAssemblies = | ||
| [ | ||
| "Beutl.Extensibility", | ||
| "Beutl.Engine", | ||
| "Avalonia", | ||
| "FluentAvaloniaUI", | ||
| "Microsoft.CodeAnalysis.CSharp.Scripting", | ||
| "SkiaSharp", | ||
| "SkiaSharp.HarfBuzz", | ||
| "Vortice.XAudio2", | ||
| ]; | ||
| foreach (string heavy in heavyAssemblies) | ||
| { | ||
| Assert.That(closure, Does.Not.Contain(heavy), $"Abstractions must not depend on {heavy}."); | ||
| } | ||
|
|
||
| // Closed allowlist so any new Beutl.* assembly entering the closure fails even when the | ||
| // blocklist above doesn't name it. | ||
| string[] allowedBeutlAssemblies = | ||
| [ | ||
| "Beutl.Extensibility.Abstractions", | ||
| "Beutl.Core", | ||
| "Beutl.Configuration", | ||
| "Beutl.Utilities", | ||
| "Beutl.Language", | ||
| ]; | ||
| string[] beutlInClosure = [.. closure.Where(x => x.StartsWith("Beutl.", StringComparison.Ordinal))]; | ||
| Assert.That(beutlInClosure, Is.SubsetOf(allowedBeutlAssemblies)); | ||
| } | ||
|
|
||
| private static HashSet<string> CollectReferencedAssemblyClosure(Assembly root) | ||
| { | ||
| var seen = new HashSet<string>(StringComparer.Ordinal) { root.GetName().Name! }; | ||
| var queue = new Queue<Assembly>(); | ||
| queue.Enqueue(root); | ||
|
|
||
| while (queue.Count > 0) | ||
| { | ||
| foreach (AssemblyName reference in queue.Dequeue().GetReferencedAssemblies()) | ||
| { | ||
| if (!seen.Add(reference.Name!)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| queue.Enqueue(Assembly.Load(reference)); | ||
| } | ||
| catch | ||
| { | ||
| // Name is already recorded; an assembly absent from the test output just can't be walked further. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return seen; | ||
| } | ||
|
|
||
| private sealed class MinimalExtension : Extension | ||
| { | ||
| public override ExtensionSettings Settings { get; } = new MinimalSettings(); | ||
| } | ||
|
|
||
| private sealed class MinimalSettings : ExtensionSettings | ||
| { | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.