Files
NetMesh/electron/plugins/electronRuntime.live.test.cjs
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

115 lines
4.4 KiB
JavaScript

"use strict";
if (!process.versions.electron) {
const test = require("node:test");
test("live Electron plugin runtimes", { skip: "run with npm run test:plugin-runtime:electron" }, () => {});
} else {
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const electron = require("electron");
const { PLUGIN_PROTOCOL_SCHEME } = require("./constants.cjs");
const { inspectContributionIconSource } = require("./contributionIconService.cjs");
const { createIsolatedContributionIconRasterizer } = require("./contributionIconRasterizer.cjs");
const { createPluginHostService } = require("./hostService.cjs");
const appRoot = path.resolve(__dirname, "..", "..");
const userData = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-plugin-electron-smoke-"));
electron.app.setPath("userData", userData);
electron.app.commandLine.appendSwitch("disable-gpu");
electron.app.on("window-all-closed", () => {});
electron.protocol.registerSchemesAsPrivileged([{
scheme: PLUGIN_PROTOCOL_SCHEME,
privileges: {
standard: true,
secure: true,
supportFetchAPI: true,
corsEnabled: false,
codeCache: true,
},
}]);
void electron.app.whenReady().then(async () => {
const rasterizeContributionIcon = createIsolatedContributionIconRasterizer({
BrowserWindow: electron.BrowserWindow,
});
const rasterizedIcon = await rasterizeContributionIcon({
body: Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 64"><rect width="128" height="64" fill="red"/></svg>'),
mimeType: "image/svg+xml",
width: 128,
height: 64,
maxEdge: 64,
});
assert.deepEqual(inspectContributionIconSource(rasterizedIcon, ".png", 64), {
mimeType: "image/png",
width: 64,
height: 32,
});
const { buildPluginPackage } = await import("@netcatty/plugin-cli");
const fixtures = [
{ id: "com.netcatty.runtime-smoke-browser", kind: "browser" },
{ id: "com.netcatty.runtime-smoke-utility", kind: "utility" },
];
const runtimeAppRoot = path.join(userData, "runtime-app");
const runtimeDirectory = path.join(runtimeAppRoot, "electron", "plugins", "runtime");
for (const packageName of ["plugin-contract", "plugin-sdk"]) {
fs.cpSync(
path.join(appRoot, "node_modules", "@netcatty", packageName, "dist"),
path.join(runtimeAppRoot, "node_modules", "@netcatty", packageName, "dist"),
{ recursive: true },
);
}
fs.cpSync(path.join(__dirname, "runtime"), runtimeDirectory, { recursive: true });
const service = createPluginHostService({
app: electron.app,
electron,
appRoot: runtimeAppRoot,
runtimeDirectory,
requestPermissionDecision: async (request) => ({
requestId: request.requestId,
decision: "allow",
scope: "application",
}),
});
await service.manager.initialize();
for (const fixture of fixtures) {
const archivePath = path.join(userData, `${fixture.id}.ncpkg`);
await buildPluginPackage(
path.join(__dirname, "fixtures", `${fixture.kind}-runtime-plugin`),
archivePath,
);
const installed = await service.manager.install(archivePath, { enable: true });
assert.equal(installed.id, fixture.id);
const active = service.database.getActivePlugin(fixture.id);
assert.equal(active.runtime.status, "running");
assert.equal(active.runtime.kind, fixture.kind);
assert.deepEqual(service.database.getValue(fixture.id, "smoke.activation"), {
kind: fixture.kind,
ready: true,
});
}
await service.manager.shutdown();
fs.rmSync(userData, { recursive: true, force: true });
process.stdout.write("PLUGIN_RUNTIME_SMOKE_OK\n");
electron.app.exit(0);
}).catch(async (error) => {
console.error(error);
await new Promise((resolve) => setTimeout(resolve, 250));
for (const pluginId of [
"com.netcatty.runtime-smoke-browser",
"com.netcatty.runtime-smoke-utility",
]) {
try {
const logPath = path.join(userData, "plugins", "logs", pluginId, "runtime.log");
console.error(fs.readFileSync(logPath, "utf8"));
} catch {}
}
if (process.env.NETCATTY_PLUGIN_SMOKE_KEEP) console.error(`Smoke data retained at ${userData}`);
else fs.rmSync(userData, { recursive: true, force: true });
electron.app.exit(1);
});
}