feat: rebuild desktop sync as linked server accounts, fix packaged plugin bundles and UI scaling

This commit is contained in:
LukeGus committed 2026-09-26 00:41:25 -05:00
1 parent 7c02daccf4
commit 6cd9a2846d
242 files changed
+39127 -8558

No files matched your search

+17 -3
View File
@@ -19,8 +19,22 @@ describe("Electron security boundary", () => {
);
});
it("allows the renderer to hand the local session to Remote Sync", () => {
expect(main).toContain('ipcMain.handle("notify-local-login"');
expect(preload).toContain('"notify-local-login"');
it("never hands the linked server's session to the renderer over IPC", () => {
// The embedded backend owns the link; the renderer asks it, with its
// own local session, rather than main.
for (const channel of [
"get-remote-sync-jwt",
"save-remote-sync-jwt",
"notify-local-login",
]) {
expect(main).not.toContain(`"${channel}"`);
expect(preload).not.toContain(`"${channel}"`);
}
});
it("scopes proxy headers and basic auth to the linked origin", () => {
expect(main).toContain('"sync-proxy-config"');
expect(main).toContain("linkedServer.applyLinkHeaders(");
expect(main).toContain("linkedServer.answerLogin(");
});
});
+44
View File
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { build } from "../packages/plugin-sdk/cli/commands/build.mjs";
const cleanups: Array<() => void> = [];
@@ -39,4 +40,47 @@ describe("termix-plugin build", () => {
expect(pkg).toEqual({ type: "module" });
expect(fs.existsSync(path.join(dir, "dist", "backend.js"))).toBe(true);
});
it("loads a bundled CommonJS package that requires a host-provided one, with Vite's build constants", async () => {
vi.spyOn(console, "log").mockImplementation(() => {});
const dir = fixturePlugin();
const dep = path.join(dir, "node_modules", "cjs-dep");
fs.mkdirSync(dep, { recursive: true });
fs.writeFileSync(
path.join(dep, "package.json"),
JSON.stringify({ name: "cjs-dep", main: "index.js" }),
);
// What react-xtermjs does: a CommonJS require of React's JSX runtime.
fs.writeFileSync(
path.join(dep, "index.js"),
'const runtime = require("react/jsx-runtime");\nexports.render = () => runtime.jsx("div", {});\n',
);
fs.mkdirSync(path.join(dir, "src", "frontend"), { recursive: true });
fs.writeFileSync(
path.join(dir, "src", "frontend", "index.ts"),
'import { render } from "cjs-dep";\nexport const rendered = render();\nexport const dev = import.meta.env.DEV;\nexport const mode = process.env.NODE_ENV;\n',
);
await build({ cwd: dir });
// Stand in for the import map: point the external at a stub module.
const stub = path.join(dir, "jsx-runtime.mjs");
fs.writeFileSync(
stub,
"export const jsx = (type) => ({ type });\nexport const jsxs = jsx;\n",
);
const bundle = fs
.readFileSync(path.join(dir, "dist", "frontend.js"), "utf8")
.replaceAll(
'"react/jsx-runtime"',
JSON.stringify(pathToFileURL(stub).href),
);
const runnable = path.join(dir, "dist", "runnable.mjs");
fs.writeFileSync(runnable, bundle);
const mod = await import(pathToFileURL(runnable).href);
expect(mod.rendered).toEqual({ type: "div" });
expect(mod.dev).toBe(false);
expect(mod.mode).toBe("production");
});
});
+43
View File
@@ -0,0 +1,43 @@
import { createRequire } from "node:module";
import postcss from "postcss";
import { describe, expect, it } from "vitest";
const require = createRequire(import.meta.url);
const config = require("../postcss.config.cjs") as {
plugins: Record<string, unknown>;
};
const pxtorem = require("postcss-pxtorem");
async function convert(css: string, from = "src/ui/index.css") {
const result = await postcss([
pxtorem(config.plugins["postcss-pxtorem"]),
]).process(css, { from });
return result.css;
}
describe("interface size conversion", () => {
it("turns px into rem against the 14px Normal root", async () => {
expect(await convert(".a{font-size:10px;width:280px}")).toBe(
".a{font-size:0.71429rem;width:20rem}",
);
});
it("keeps hairlines, breakpoints and the root size rules in px", async () => {
expect(await convert(".b{border-width:1px}")).toBe(".b{border-width:1px}");
expect(await convert("@media (min-width:768px){.c{gap:7px}}")).toBe(
"@media (min-width:768px){.c{gap:0.5rem}}",
);
expect(await convert("html.fs-lg{font-size:17px}")).toBe(
"html.fs-lg{font-size:17px}",
);
});
it("leaves third-party CSS alone", async () => {
expect(
await convert(
".xterm{padding:4px}",
"node_modules/@xterm/xterm/css/xterm.css",
),
).toBe(".xterm{padding:4px}");
});
});