Limit Run target platforms to plugin declarations

This commit is contained in:
npc0-hue
2026-08-26 16:45:43 +08:00
parent 35f1eb0844
commit 861ee752ed
2 changed files with 16 additions and 6 deletions
+9 -2
View File
@@ -6,7 +6,7 @@ import { MaintenancePage } from "./MaintenancePage";
import { PluginsPage } from "./PluginsPage";
import { ProfileSettingsPage } from "./ProfileSettingsPage";
import { ServerDetailPage } from "./ServerDetailPage";
import { ServersPage } from "./ServersPage";
import { runPlatformOptions, ServersPage } from "./ServersPage";
import { UsersPage } from "./UsersPage";
import runtimeTaskProgressSource from "../components/RuntimeTaskProgress.tsx?raw";
import serverDeploymentWorkflowSource from "../components/ServerDeploymentWorkflow.tsx?raw";
@@ -17,7 +17,7 @@ import serverDetailPageSource from "./ServerDetailPage.tsx?raw";
import type { PageComponentProps } from "../contracts/page";
import { capabilitiesForRoles, type CurrentUserView } from "../contracts/workspace";
import type { OperationTracker } from "../stores/operations";
import type { UserResponse } from "../api/types";
import type { GamePluginResponse, UserResponse } from "../api/types";
const adminUser: CurrentUserView = {
id: "user-admin",
@@ -62,6 +62,13 @@ function pageProps(params: PageComponentProps["params"] = {}): PageComponentProp
}
describe("first-party console pages", () => {
it("only offers plugin-declared run platforms", () => {
const plugin = { supportedOs: ["windows", "linux"] } as GamePluginResponse;
expect(runPlatformOptions(plugin, "darwin")).toEqual(["windows", "linux"]);
expect(runPlatformOptions(undefined, "windows")).toEqual(["windows"]);
});
it("renders the platform overview with first-screen health modules", () => {
const html = renderToStaticMarkup(<HomePage {...pageProps()} />);
+7 -4
View File
@@ -981,7 +981,7 @@ function quickRuntimeDefaultsForPlugin(pluginId: string) {
};
}
function runPlatformOptions(plugin: GamePluginResponse | undefined, fallback: string): string[] {
export function runPlatformOptions(plugin: GamePluginResponse | undefined, fallback: string): string[] {
const options = new Set<string>();
const add = (value: string | undefined) => {
const normalized = value?.trim().toLowerCase();
@@ -989,10 +989,13 @@ function runPlatformOptions(plugin: GamePluginResponse | undefined, fallback: st
options.add(normalized);
}
};
add(fallback);
plugin?.supportedOs?.forEach(add);
plugin?.runtimeProfiles?.lifecycleProfiles?.forEach((profile) => profile.platforms?.forEach(add));
["linux", "windows", "darwin"].forEach(add);
if (options.size === 0) {
plugin?.runtimeProfiles?.lifecycleProfiles?.forEach((profile) => profile.platforms?.forEach(add));
}
if (options.size === 0) {
add(fallback);
}
return [...options];
}