feat: update Godot integration and coordinated package dependencies

This commit is contained in:
cneicy committed 2026-11-06 19:13:14 +08:00
1 parent 7a5071217d
commit 80cd594ac5
3 files changed
+95 -90

No files matched your search

+88 -83
View File
@@ -1,6 +1,8 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using NUnit.Framework;
using ShrinkApp.Starter.Basic;
using ShrinkCommand.Integration.App;
@@ -10,6 +12,7 @@ using ShrinkNetwork;
using ShrinkNetwork.Integration.App;
using ShrinkApp;
using UnityEngine;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
namespace ShrinkContext.AppAdapter.Tests
@@ -21,92 +24,94 @@ namespace ShrinkContext.AppAdapter.Tests
/// </summary>
public class NativeWiringTests
{
[Test]
public void BasicComposition_UsesNativeComponents_AndRetiresDependentsReversibly()
private ShrinkAppSettings? _settings;
private ShrinkAppLoaderHost? _host;
[UnityTearDown]
public IEnumerator TearDown()
{
var settings = ScriptableObject.CreateInstance<ShrinkAppSettings>();
ShrinkAppLoaderHost? host = null;
try
if (_host?.IsRunning == true)
yield return _host.ShutdownAsync().ToCoroutine();
if (_settings != null)
Object.DestroyImmediate(_settings);
}
[UnityTest]
public IEnumerator BasicComposition_UsesNativeComponents_AndRetiresDependentsReversibly()
{
_settings = ScriptableObject.CreateInstance<ShrinkAppSettings>();
var coreInstallers = new List<IShrinkAppModuleInstaller>();
foreach (var installerType in ShrinkAppInstallers.GetDiscoveredInstallerTypes())
{
var coreInstallers = new List<IShrinkAppModuleInstaller>();
foreach (var installerType in ShrinkAppInstallers.GetDiscoveredInstallerTypes())
{
if (Activator.CreateInstance(installerType) is not IShrinkAppModuleInstaller installer)
continue;
if (installer.ModuleId is "shrink.network" or "shrink.command" or "shrink.datasaver")
coreInstallers.Add(installer);
}
host = new ShrinkAppLoaderHost(settings, coreInstallers);
ShrinkAppBasicContextComposition.Configure(host);
host.ApplyComposition(ShrinkAppBasicContextComposition.CreateDefaultDocument());
TestAwait.Run(host.StartAsync());
Assert.AreEqual(7, host.ModuleIds.Count);
Assert.AreEqual(7, host.ActiveModuleIds.Count);
Assert.IsTrue(host.IsModuleActive("shrink.network"));
Assert.IsTrue(host.IsModuleActive("shrink.command"));
Assert.IsTrue(host.IsModuleActive("shrink.datasaver"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.command-network"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.command-eventbus"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.datasaver-eventbus"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.network-eventbus"));
var root = host.Context.RootContext;
Assert.IsTrue(host.Context.TryGetRaw<ShrinkNetworkService>(root,
ShrinkNetworkAppComponent.ServiceKey, out _), "网络服务键由原生组件提供");
Assert.IsTrue(host.Context.TryGetRaw<ShrinkCommand.ShrinkCommandService>(root,
ShrinkCommandAppComponent.ServiceKey, out _), "命令服务键由原生组件提供");
Assert.IsTrue(host.Context.TryGetRaw<object>(root,
ShrinkDataSaverAppComponent.ServiceKey, out _), "存档服务键由原生组件提供");
Assert.IsTrue(host.Context.TryGetRaw<object>(root,
"shrink.integration.command-network", out _));
Assert.IsTrue(host.Context.TryGetRaw<object>(root,
"shrink.integration.command-eventbus", out _));
Assert.IsTrue(host.Context.TryGetRaw<object>(root,
"shrink.integration.datasaver-eventbus", out _));
Assert.IsTrue(host.Context.TryGetRaw<object>(root,
"shrink.integration.network-eventbus", out _));
Assert.IsTrue(host.Services.TryGet<ShrinkNetworkAppService>(out _));
Assert.IsTrue(host.Services.TryGet<ShrinkCommandAppService>(out _));
Assert.IsTrue(host.Services.TryGet<ShrinkDataSaverService>(out _));
TestAwait.Run(host.SetModuleDisabledAsync("shrink.command", true));
Assert.IsFalse(host.IsModuleActive("shrink.command"));
Assert.IsFalse(host.IsModuleActive("shrink.integration.command-network"));
Assert.IsFalse(host.IsModuleActive("shrink.integration.command-eventbus"));
Assert.IsTrue(host.IsModuleActive("shrink.network"), "无关提供者不得重载");
Assert.IsTrue(host.IsModuleActive("shrink.datasaver"), "无关提供者不得重载");
Assert.IsTrue(host.IsModuleActive("shrink.integration.network-eventbus"));
Assert.IsTrue(host.IsModuleActive("shrink.integration.datasaver-eventbus"));
Assert.IsFalse(host.Context.TryGetRaw<object>(root,
ShrinkCommandAppComponent.ServiceKey, out _));
Assert.IsFalse(host.Context.TryGetRaw<object>(root,
"shrink.integration.command-network", out _));
Assert.IsFalse(host.Context.TryGetRaw<object>(root,
"shrink.integration.command-eventbus", out _));
Assert.IsFalse(host.Services.TryGet<ShrinkCommandAppService>(out _),
"兼容门面应随组件退役注销");
TestAwait.Run(host.SetModuleDisabledAsync("shrink.command", false));
Assert.AreEqual(7, host.ActiveModuleIds.Count);
Assert.IsTrue(host.Services.TryGet<ShrinkCommandAppService>(out _));
TestAwait.Run(host.ShutdownAsync());
Assert.AreEqual(0, host.ActiveModuleIds.Count);
Assert.IsFalse(host.Services.TryGet<ShrinkNetworkAppService>(out _));
Assert.IsFalse(host.Services.TryGet<ShrinkCommandAppService>(out _));
Assert.IsFalse(host.Services.TryGet<ShrinkDataSaverService>(out _));
}
finally
{
if (host?.IsRunning == true)
TestAwait.Run(host.ShutdownAsync());
Object.DestroyImmediate(settings);
if (Activator.CreateInstance(installerType) is not IShrinkAppModuleInstaller installer)
continue;
if (installer.ModuleId is "shrink.network" or "shrink.command" or "shrink.datasaver")
coreInstallers.Add(installer);
}
_host = new ShrinkAppLoaderHost(_settings, coreInstallers);
ShrinkAppBasicContextComposition.Configure(_host);
_host.ApplyComposition(ShrinkAppBasicContextComposition.CreateDefaultDocument());
yield return _host.StartAsync().ToCoroutine();
Assert.AreEqual(7, _host.ModuleIds.Count);
Assert.AreEqual(7, _host.ActiveModuleIds.Count);
Assert.IsTrue(_host.IsModuleActive("shrink.network"));
Assert.IsTrue(_host.IsModuleActive("shrink.command"));
Assert.IsTrue(_host.IsModuleActive("shrink.datasaver"));
Assert.IsTrue(_host.IsModuleActive("shrink.integration.command-network"));
Assert.IsTrue(_host.IsModuleActive("shrink.integration.command-eventbus"));
Assert.IsTrue(_host.IsModuleActive("shrink.integration.datasaver-eventbus"));
Assert.IsTrue(_host.IsModuleActive("shrink.integration.network-eventbus"));
var root = _host.Context.RootContext;
Assert.IsTrue(_host.Context.TryGetRaw<ShrinkNetworkService>(root,
ShrinkNetworkAppComponent.ServiceKey, out _), "网络服务键由原生组件提供");
Assert.IsTrue(_host.Context.TryGetRaw<ShrinkCommand.ShrinkCommandService>(root,
ShrinkCommandAppComponent.ServiceKey, out _), "命令服务键由原生组件提供");
Assert.IsTrue(_host.Context.TryGetRaw<object>(root,
ShrinkDataSaverAppComponent.ServiceKey, out _), "存档服务键由原生组件提供");
Assert.IsTrue(_host.Context.TryGetRaw<object>(root,
"shrink.integration.command-network", out _));
Assert.IsTrue(_host.Context.TryGetRaw<object>(root,
"shrink.integration.command-eventbus", out _));
Assert.IsTrue(_host.Context.TryGetRaw<object>(root,
"shrink.integration.datasaver-eventbus", out _));
Assert.IsTrue(_host.Context.TryGetRaw<object>(root,
"shrink.integration.network-eventbus", out _));
Assert.IsTrue(_host.Services.TryGet<ShrinkNetworkAppService>(out _));
Assert.IsTrue(_host.Services.TryGet<ShrinkCommandAppService>(out _));
Assert.IsTrue(_host.Services.TryGet<ShrinkDataSaverService>(out _));
yield return _host.SetModuleDisabledAsync("shrink.command", true).ToCoroutine();
Assert.IsFalse(_host.IsModuleActive("shrink.command"));
Assert.IsFalse(_host.IsModuleActive("shrink.integration.command-network"));
Assert.IsFalse(_host.IsModuleActive("shrink.integration.command-eventbus"));
Assert.IsTrue(_host.IsModuleActive("shrink.network"), "无关提供者不得重载");
Assert.IsTrue(_host.IsModuleActive("shrink.datasaver"), "无关提供者不得重载");
Assert.IsTrue(_host.IsModuleActive("shrink.integration.network-eventbus"));
Assert.IsTrue(_host.IsModuleActive("shrink.integration.datasaver-eventbus"));
Assert.IsFalse(_host.Context.TryGetRaw<object>(root,
ShrinkCommandAppComponent.ServiceKey, out _));
Assert.IsFalse(_host.Context.TryGetRaw<object>(root,
"shrink.integration.command-network", out _));
Assert.IsFalse(_host.Context.TryGetRaw<object>(root,
"shrink.integration.command-eventbus", out _));
Assert.IsFalse(_host.Services.TryGet<ShrinkCommandAppService>(out _),
"兼容门面应随组件退役注销");
yield return _host.SetModuleDisabledAsync("shrink.command", false).ToCoroutine();
Assert.AreEqual(7, _host.ActiveModuleIds.Count);
Assert.IsTrue(_host.Services.TryGet<ShrinkCommandAppService>(out _));
yield return _host.ShutdownAsync().ToCoroutine();
Assert.AreEqual(0, _host.ActiveModuleIds.Count);
Assert.IsFalse(_host.Services.TryGet<ShrinkNetworkAppService>(out _));
Assert.IsFalse(_host.Services.TryGet<ShrinkCommandAppService>(out _));
Assert.IsFalse(_host.Services.TryGet<ShrinkDataSaverService>(out _));
}
}
}