chore: initialize standalone UPM package
Publish UPM package / publish (push) Failing after 1s

This commit is contained in:
2026-08-26 02:49:49 +08:00
commit f9b05b4178
33 changed files with 812 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
name: Publish UPM package
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
NODE_AUTH_TOKEN: ${{ secrets.SHRINKSDK_PACKAGE_TOKEN }}
steps:
- name: Fetch tagged revision
shell: bash
run: |
set -eu
ref="${{ gitea.sha }}"
test -n "$ref"
git init .
git remote add origin "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.Network.git"
git fetch --depth=1 origin "$ref"
git checkout --detach FETCH_HEAD
- name: Validate immutable release version
shell: bash
run: |
set -eu
tag="$(git describe --exact-match --tags HEAD)"
version="$(node -p "require('./package.json').version")"
test "$tag" = "v$version"
npm pack --dry-run
- name: Publish to ShrinkSDK registry
shell: bash
run: |
set -eu
: "${NODE_AUTH_TOKEN:?SHRINKSDK_PACKAGE_TOKEN is required}"
npmrc="$HOME/.npmrc"
cleanup() { rm -f "$npmrc"; }
trap cleanup EXIT
printf '%s\n' \
'registry=https://git.crash.work/api/packages/ShrinkSDK/npm/' \
'//git.crash.work/api/packages/ShrinkSDK/npm/:_authToken=${NODE_AUTH_TOKEN}' > "$npmrc"
npm publish --registry=https://git.crash.work/api/packages/ShrinkSDK/npm/
+39
View File
@@ -0,0 +1,39 @@
name: Verify standalone Unity package
on:
workflow_dispatch:
jobs:
editmode:
runs-on: unity-2022.3.62f3
container:
image: docker.1panel.live/unityci/editor:ubuntu-2022.3.62f3-windows-mono-3
volumes:
- /www/dk_project/bt-recovery/gitea/runner/seedskey-unity-license:/root/.local/share/unity3d/Unity
- /www/dk_project/bt-recovery/gitea/runner/seedskey-unity-entitlements:/root/.config/unity3d/Unity/licenses
steps:
- name: Fetch selected revision
shell: bash
run: |
set -eu
ref="${{ gitea.sha }}"
git init .
git remote add origin "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.Network.git"
git fetch --depth=1 origin "$ref"
git checkout --detach FETCH_HEAD
- name: Run package EditMode tests
shell: bash
run: |
set -eu
unity_bin="$(command -v unity-editor || command -v unity || command -v Unity || true)"
test -n "$unity_bin"
"$unity_bin" \
-batchmode \
-nographics \
-quit \
-projectPath "$PWD/Development~/UnityProject" \
-runTests \
-testPlatform EditMode \
-testResults "$PWD/TestResults/editmode.xml" \
-logFile "$PWD/TestResults/unity.log"
+10
View File
@@ -0,0 +1,10 @@
/Development~/UnityProject/[Ll]ibrary/
/Development~/UnityProject/[Tt]emp/
/Development~/UnityProject/[Oo]bj/
/Development~/UnityProject/[Ll]ogs/
/Development~/UnityProject/[Uu]ser[Ss]ettings/
/Development~/UnityProject/TestResults/
/Tools~/**/[Bb]in/
/Tools~/**/[Oo]bj/
*.user
*.DotSettings.user
+8
View File
@@ -0,0 +1,8 @@
.git/
.gitea/
Development~/
Tools~/
*.csproj
*.sln
*.user
*.DotSettings.user
+16
View File
@@ -0,0 +1,16 @@
# Changelog
本文件记录 `ShrinkCommand.Integration.Network` 在当前工作区中的包内变更。
## [0.1.0] - 2026-04-07
### Added
- 增加 `command/execute` RPC 桥接。
- 远程会话可自动映射为 `IShrinkCommandSource`,统一走命令运行时。
- 命令执行结果可直接通过 `ShrinkNetwork` 返回给远端调用方。
### Changed
- 桥接层公共类型补齐 `#nullable enable`,对齐当前运行时与宿主侧的可空语义。
- 保持桥接层职责边界,命令核心仍不直接依赖网络实现。
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: cc0d137c46b092f49a54bc3afcd7c161
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+6
View File
@@ -0,0 +1,6 @@
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Ll]ogs/
[Uu]ser[Ss]ettings/
TestResults/
@@ -0,0 +1,15 @@
{
"scopedRegistries": [
{
"name": "ShrinkSDK",
"url": "https://git.crash.work/api/packages/ShrinkSDK/npm/",
"scopes": [
"com.cneicy"
]
}
],
"dependencies": {
"com.unity.test-framework": "1.1.33",
"com.cneicy.shrink-command-integration-network": "file:../../.."
}
}
@@ -0,0 +1,2 @@
m_EditorVersion: 2022.3.62f3
m_EditorVersionWithRevision: 2022.3.62f3 (96770f904ca7)
+24
View File
@@ -0,0 +1,24 @@
# ShrinkCommand.Integration.Network
`ShrinkCommand``ShrinkNetwork` 的桥接层。
## 能力
- 通过网络 RPC 执行命令
- 远程命令来源自动映射为 `IShrinkCommandSource`
- 继续复用命令系统自己的权限与来源限制
## 接入
```csharp
commandService = new ShrinkCommandService();
commandService.AutoRegisterAll();
networkService.UseCommandBridge(commandService);
```
客户端调用:
```csharp
var response = await session.ExecuteCommandAsync("help");
```
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c85d4974b8207cf45848e1379ad7baa3
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+19
View File
@@ -0,0 +1,19 @@
{
"name": "ShrinkCommand.Integration.Network",
"rootNamespace": "ShrinkCommand.Integration",
"references": [
"ShrinkCommand.Runtime",
"ShrinkNetwork.Runtime",
"ShrinkContext.Core.Runtime",
"UniTask"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d9c305f415a0515409b2795a809e7240
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,49 @@
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using ShrinkCommand;
using ShrinkContext;
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
/// <summary>
/// 命令-网络集成组件(论文 6.5 集成组件模式):
/// 核心(command / network)互不依赖,本组件注入双方服务键,全部就绪才激活,
/// 任一提供者退役即自动停用——依赖接线由响应式余效应结构性完成,替代手工桥接编排。
///
/// 已知边界:ShrinkNetworkService 当前无 handler 注销 API,停用不撤销已注册的
/// command/execute 处理器(传输解绑后不可达;网络服务实例重建时自然消失)。
/// </summary>
public sealed class ShrinkCommandNetworkIntegrationComponent : IShrinkComponent
{
/// <summary>与 ShrinkNetworkAppComponent.ServiceKey 保持一致(避免跨包硬引用)。</summary>
public const string NetworkServiceKey = "shrink.service.network";
public const string CommandServiceKey = "shrink.service.command";
public const string ProvideKey = "shrink.integration.command-network";
private static readonly string[] InjectKeys = { CommandServiceKey, NetworkServiceKey };
private static readonly string[] ProvideKeys = { ProvideKey };
public string Name => "shrink.integration.command-network";
public IReadOnlyList<string> Inject => InjectKeys;
public IReadOnlyList<string> Provide => ProvideKeys;
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
{
var commandService = ctx.Get<ShrinkCommandService>(CommandServiceKey);
var networkService = ctx.Get<ShrinkNetworkService>(NetworkServiceKey);
var options = config as ShrinkNetworkCommandBridgeOptions;
ShrinkNetworkCommandBridge.RegisterService(networkService, commandService, options);
ctx.Set(ProvideKey, ShrinkNetworkCommandBridge.ExecuteRoute);
// 桥注册按网络服务实例幂等去重;可逆面为集成键的发布/撤回
return UniTask.CompletedTask;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5710d88a762cde489282366255f755c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+86
View File
@@ -0,0 +1,86 @@
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
public static class ShrinkNetworkCommandBridge
{
public const string ExecuteRoute = "command/execute";
private static readonly object SyncRoot = new();
private static readonly HashSet<ShrinkNetworkService> RegisteredServices = new();
public static void RegisterService(
ShrinkNetworkService networkService,
ShrinkCommandService commandService,
ShrinkNetworkCommandBridgeOptions? options = null)
{
if (networkService == null)
throw new ArgumentNullException(nameof(networkService));
if (commandService == null)
throw new ArgumentNullException(nameof(commandService));
lock (SyncRoot)
{
if (RegisteredServices.Contains(networkService))
return;
RegisteredServices.Add(networkService);
}
options ??= new ShrinkNetworkCommandBridgeOptions();
EnsureMessagesRegistered(networkService);
var requirement = new ShrinkNetworkPermissionRequirement(options.Authority, options.Permission);
networkService.RegisterRequestHandler<ShrinkNetworkCommandRequest, ShrinkNetworkCommandResponse>(
(context, request) => HandleExecuteAsync(commandService, options, context, request),
requirement);
}
public static void EnsureMessagesRegistered(ShrinkNetworkService service)
{
if (!service.MessageRegistry.TryGetMeta(typeof(ShrinkNetworkCommandRequest), out _))
{
var requestAttribute = (ShrinkNetworkMessageAttribute)Attribute.GetCustomAttribute(
typeof(ShrinkNetworkCommandRequest),
typeof(ShrinkNetworkMessageAttribute),
false)!;
service.RegisterMessage(typeof(ShrinkNetworkCommandRequest), requestAttribute.Opcode, requestAttribute.Route);
}
if (!service.MessageRegistry.TryGetMeta(typeof(ShrinkNetworkCommandResponse), out _))
{
var responseAttribute = (ShrinkNetworkMessageAttribute)Attribute.GetCustomAttribute(
typeof(ShrinkNetworkCommandResponse),
typeof(ShrinkNetworkMessageAttribute),
false)!;
service.RegisterMessage(typeof(ShrinkNetworkCommandResponse), responseAttribute.Opcode, responseAttribute.Route);
}
}
private static async UniTask<ShrinkNetworkCommandResponse> HandleExecuteAsync(
ShrinkCommandService commandService,
ShrinkNetworkCommandBridgeOptions options,
ShrinkNetworkContext context,
ShrinkNetworkCommandRequest request)
{
var source = options.SourceFactory?.Invoke(context, request) ?? new ShrinkNetworkCommandSource(context, request);
var result = await commandService.ExecuteAsync(source, request.CommandLine);
var output = source is ShrinkNetworkCommandSource networkSource
? networkSource.BuildOutputMessage(result.Message)
: result.Message;
return new ShrinkNetworkCommandResponse
{
ServiceName = string.IsNullOrWhiteSpace(request.ServiceName) ? options.ServiceName : request.ServiceName.Trim(),
CommandLine = request.CommandLine ?? string.Empty,
OutputMessage = output,
ErrorCode = result.IsSuccess ? 0 : ShrinkRpcErrorCode.HandlerException,
ErrorMessage = result.IsSuccess ? string.Empty : output
};
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f22899cbeb3779d4eb1338217fa4d38f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+52
View File
@@ -0,0 +1,52 @@
#nullable enable
using System;
using Cysharp.Threading.Tasks;
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
public static class ShrinkNetworkCommandBridgeExtensions
{
public static ShrinkNetworkService UseCommandBridge(
this ShrinkNetworkService networkService,
ShrinkCommandService commandService,
ShrinkNetworkCommandBridgeOptions? options = null)
{
if (networkService == null)
throw new ArgumentNullException(nameof(networkService));
if (commandService == null)
throw new ArgumentNullException(nameof(commandService));
ShrinkNetworkCommandBridge.RegisterService(networkService, commandService, options);
return networkService;
}
public static async UniTask<ShrinkNetworkCommandResponse> ExecuteCommandAsync(
this ShrinkNetworkSession session,
string commandLine,
string? serviceName = null,
string? clientLabel = null,
ShrinkRpcCallOptions? options = null)
{
if (session == null)
throw new ArgumentNullException(nameof(session));
ShrinkNetworkCommandBridge.EnsureMessagesRegistered(session.Service);
return await session.RpcAsync<ShrinkNetworkCommandRequest, ShrinkNetworkCommandResponse>(
new ShrinkNetworkCommandRequest
{
ServiceName = string.IsNullOrWhiteSpace(serviceName)
? ShrinkCommandConstants.DefaultServiceName
: serviceName.Trim(),
CommandLine = commandLine ?? string.Empty,
ClientLabel = clientLabel ?? string.Empty
},
options ?? new ShrinkRpcCallOptions
{
TimeoutMs = 5000,
DebugLabel = "RemoteCommand"
});
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11bf32dbf7be0e14cbddf1f03ded5cbb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+15
View File
@@ -0,0 +1,15 @@
#nullable enable
using System;
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
public sealed class ShrinkNetworkCommandBridgeOptions
{
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
public ShrinkNetworkAuthority Authority { get; set; } = ShrinkNetworkAuthority.ClientOnly;
public string Permission { get; set; } = string.Empty;
public Func<ShrinkNetworkContext, ShrinkNetworkCommandRequest, IShrinkCommandSource>? SourceFactory { get; set; }
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 174745a3cab12534c8d4b09788063fe9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+20
View File
@@ -0,0 +1,20 @@
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
[ShrinkNetworkMessage(1501, ShrinkNetworkCommandBridge.ExecuteRoute)]
public sealed class ShrinkNetworkCommandRequest : IShrinkNetworkRequest
{
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
public string CommandLine { get; set; } = string.Empty;
public string ClientLabel { get; set; } = string.Empty;
}
[ShrinkNetworkMessage(1502, "command/execute_response")]
public sealed class ShrinkNetworkCommandResponse : ShrinkRpcResponseBase
{
public string ServiceName { get; set; } = ShrinkCommandConstants.DefaultServiceName;
public string CommandLine { get; set; } = string.Empty;
public string OutputMessage { get; set; } = string.Empty;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8b44977ad838cce438d99ea565848485
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+79
View File
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Cysharp.Threading.Tasks;
using ShrinkNetwork;
namespace ShrinkCommand.Integration
{
public sealed class ShrinkNetworkCommandSource : IShrinkCommandSource
{
private readonly List<string> _lines = new();
private readonly ShrinkNetworkContext _context;
private readonly ShrinkNetworkCommandRequest _request;
public ShrinkNetworkCommandSource(ShrinkNetworkContext context, ShrinkNetworkCommandRequest request)
{
_context = context;
_request = request;
SourceId = $"network:{context.Session.SessionId}";
DisplayName = ResolveDisplayName(context, request);
}
public string SourceId { get; }
public string DisplayName { get; }
public bool IsConsole => false;
public ShrinkNetworkSession Session => _context.Session;
public bool HasPermission(string permission)
{
return string.IsNullOrWhiteSpace(permission) || Session.HasPermission(permission);
}
public UniTask WriteLineAsync(string message, CancellationToken cancellationToken = default)
{
if (!string.IsNullOrWhiteSpace(message))
_lines.Add(message);
return UniTask.CompletedTask;
}
public string BuildOutputMessage(string resultMessage)
{
if (_lines.Count == 0)
return resultMessage ?? string.Empty;
var builder = new StringBuilder();
for (var index = 0; index < _lines.Count; index++)
{
if (index > 0)
builder.AppendLine();
builder.Append(_lines[index]);
}
if (!string.IsNullOrWhiteSpace(resultMessage))
{
if (builder.Length > 0 && !string.Equals(_lines[_lines.Count - 1], resultMessage, StringComparison.Ordinal))
builder.AppendLine();
if (!string.Equals(_lines[_lines.Count - 1], resultMessage, StringComparison.Ordinal))
builder.Append(resultMessage);
}
return builder.ToString();
}
private static string ResolveDisplayName(ShrinkNetworkContext context, ShrinkNetworkCommandRequest request)
{
if (context.Session.Items.TryGetValue("auth.name", out var authName) && authName is string authNameText &&
!string.IsNullOrWhiteSpace(authNameText))
{
return authNameText.Trim();
}
if (!string.IsNullOrWhiteSpace(request.ClientLabel))
return request.ClientLabel.Trim();
return context.Session.RemoteAddress;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf31a6f53f1bb0c4ca0af60b92dce81f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a9777f2e6be37f64e8ec2df9b9afef87
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+151
View File
@@ -0,0 +1,151 @@
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using NUnit.Framework;
using ShrinkCommand.Integration;
using ShrinkCommand.Integration.App;
using ShrinkContext;
using ShrinkDataSaver.Integration.App;
using ShrinkNetwork;
using ShrinkNetwork.Integration.App;
namespace ShrinkCommand.Integration.Network.Tests
{
/// <summary>
/// 阶段 3 集成组件模式(论文 6.5):
/// 核心(command/network/datasaver)互不依赖,集成组件注入双方服务键;
/// 全部提供者就绪才激活,任一退役即停用——依赖接线由响应式余效应完成。
/// </summary>
public class IntegrationComponentsTests
{
private ShrinkContextRuntime _runtime = null!;
[SetUp]
public void SetUp()
{
_runtime = new ShrinkContextRuntime();
}
[TearDown]
public void TearDown()
{
_runtime.ShutdownAsync().GetAwaiter().GetResult();
}
private static void Run(UniTask task) => task.GetAwaiter().GetResult();
[Test]
public void Integration_ActivatesOnlyWhenBothProvidersActive()
{
var integration = _runtime.Use(new ShrinkCommandNetworkIntegrationComponent());
Assert.AreEqual(ShrinkFiberState.Inactive, integration.State, "两个服务键都缺失时等待");
var command = _runtime.Use(new ShrinkCommandAppComponent());
Assert.AreEqual(ShrinkFiberState.Active, command.State);
Assert.AreEqual(ShrinkFiberState.Inactive, integration.State, "仅命令服务就绪仍等待网络服务");
var network = _runtime.Use(new ShrinkNetworkAppComponent());
Assert.AreEqual(ShrinkFiberState.Active, network.State);
Assert.AreEqual(ShrinkFiberState.Active, integration.State,
"双键齐备后集成组件激活并完成桥注册");
}
[Test]
public void EitherProviderRetire_DeactivatesIntegration_AndReactivatesOnReturn()
{
var command = _runtime.Use(new ShrinkCommandAppComponent());
var network = _runtime.Use(new ShrinkNetworkAppComponent());
var integration = _runtime.Use(new ShrinkCommandNetworkIntegrationComponent());
Assert.AreEqual(ShrinkFiberState.Active, integration.State);
Run(_runtime.RetireAsync(network));
Assert.AreEqual(ShrinkFiberState.Inactive, integration.State,
"网络提供者退役,集成组件自动停用(服务键撤回触发)");
Assert.AreEqual(ShrinkFiberState.Active, command.State, "命令核心不受影响");
var networkAgain = _runtime.Use(new ShrinkNetworkAppComponent());
Assert.AreEqual(ShrinkFiberState.Active, integration.State,
"提供者回归后集成组件自动重新激活");
}
[Test]
public void CommandComponent_ProvidesDefaultServiceKey()
{
var fiber = _runtime.Use(new ShrinkCommandAppComponent());
Assert.AreEqual(ShrinkFiberState.Active, fiber.State);
Assert.IsTrue(_runtime.TryGetRaw<ShrinkCommandService>(_runtime.RootContext,
ShrinkCommandAppComponent.ServiceKey, out var service));
Assert.AreSame(ShrinkCommandRuntime.Default, service);
Run(_runtime.RetireAsync(fiber));
Assert.IsFalse(_runtime.TryGetRaw<ShrinkCommandService>(_runtime.RootContext,
ShrinkCommandAppComponent.ServiceKey, out _), "退役撤回服务键");
}
[Test]
public void DataSaverComponent_Activates_FlushesOnDeactivate_WithdrawsKey()
{
var fiber = _runtime.Use(new ShrinkDataSaverAppComponent());
Assert.AreEqual(ShrinkFiberState.Active, fiber.State);
Assert.IsTrue(_runtime.TryGetRaw<object>(_runtime.RootContext,
ShrinkDataSaverAppComponent.ServiceKey, out _));
Assert.DoesNotThrow(() => Run(_runtime.RetireAsync(fiber)),
"停用执行补偿式收尾(设置最终落盘;未初始化环境安全跳过)");
Assert.IsFalse(_runtime.TryGetRaw<object>(_runtime.RootContext,
ShrinkDataSaverAppComponent.ServiceKey, out _));
}
[Test]
public void DataSaverIntercept_ReadOnlyViewAllowsReadsAndDeniesWriterCapability()
{
var provider = _runtime.Use(new ShrinkDataSaverAppComponent());
Assert.AreEqual(ShrinkFiberState.Active, provider.State);
var intercept = new Dictionary<string, IReadOnlyDictionary<string, object?>>
{
[ShrinkDataSaverAppComponent.ServiceKey] = new Dictionary<string, object?>
{
[ShrinkDataSaverAccess.MetadataKey] = ShrinkDataSaverAccess.ReadOnly
}
};
var consumerComponent = new DataSaverAccessConsumer();
var consumer = _runtime.Use(consumerComponent, intercept: intercept);
Assert.AreEqual(ShrinkFiberState.Active, consumer.State);
var reader = consumerComponent.GetReader();
Assert.IsNotNull(reader);
Assert.IsFalse(reader is IShrinkDataSaverWriter,
"只读上下文取得的对象不应再暴露写接口");
Assert.Throws<ShrinkCoeffectAccessDeniedException>(() => consumerComponent.GetWriter());
Assert.IsTrue(_runtime.TryGetRaw<ShrinkDataSaverService>(_runtime.RootContext,
ShrinkDataSaverAppComponent.ServiceKey, out _),
"编排层 raw read 保留原始服务;intercept 只介导组件访问");
}
private sealed class DataSaverAccessConsumer : IShrinkComponent
{
private ShrinkCtx? _ctx;
public string Name => "test.datasaver.read-only-consumer";
public IReadOnlyList<string> Inject { get; } = new[] { ShrinkDataSaverAppComponent.ServiceKey };
public IReadOnlyList<string> Provide => Array.Empty<string>();
public UniTask ApplyAsync(ShrinkCtx ctx, object? config)
{
_ctx = ctx;
return UniTask.CompletedTask;
}
public IShrinkDataSaverReader GetReader() => Context.Get<IShrinkDataSaverReader>(
ShrinkDataSaverAppComponent.ServiceKey);
public IShrinkDataSaverWriter GetWriter() => Context.Get<IShrinkDataSaverWriter>(
ShrinkDataSaverAppComponent.ServiceKey);
private ShrinkCtx Context => _ctx ?? throw new InvalidOperationException("Consumer is not active.");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5c9445def3a931642955715272969a72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
{
"name": "ShrinkCommand.Integration.Network.Tests",
"rootNamespace": "ShrinkCommand.Integration.Network.Tests",
"references": [
"ShrinkCommand.Integration.Network",
"ShrinkCommand.Integration.App",
"ShrinkDataSaver.Integration.App",
"ShrinkNetwork.Integration.App",
"ShrinkCommand.Runtime",
"ShrinkNetwork.Runtime",
"ShrinkContext.Core.Runtime",
"UniTask",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: dd3e105f80569534b9ba2d6fa913a2cc
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+24
View File
@@ -0,0 +1,24 @@
{
"name": "com.cneicy.shrink-command-integration-network",
"version": "0.1.0",
"displayName": "ShrinkCommand - Network Integration",
"description": "ShrinkCommand 与 ShrinkNetwork 的桥接层,允许远程会话通过 RPC 执行命令。",
"unity": "2022.3",
"dependencies": {
"com.cneicy.shrink-command": "0.2.0",
"com.cneicy.shrink-network": "0.2.0",
"com.cneicy.shrink-context-core": "0.1.0"
},
"keywords": [
"command",
"network",
"integration",
"rpc"
],
"author": {
"name": "cneicy",
"url": "https://git.crash.work/ShrinkSDK"
},
"documentationUrl": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.Network",
"changelogUrl": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.Network/src/branch/main/CHANGELOG.md"
}
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 73eb22917e75fcf4b8f1c7df5490014e
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: