| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874 |
- import { describe, expect, it } from "vitest";
- import type {
- PluginSyncCandidate,
- PluginSyncRemoteStatus,
- ZCodePluginInfo,
- ZCodePluginsOverviewResult,
- } from "@zcode/shared";
- import {
- buildMarketplaceRemotePluginStatuses,
- buildMarketplaceRemotePluginSyncCandidates,
- buildRemotePluginSyncRows,
- buildRemotePluginSyncRowsForCandidates,
- filterRemotePluginSyncRows,
- resolveDefaultRemotePluginSyncSelection,
- shouldAllowRemotePluginSyncDialogOpenChange,
- shouldFinishRemotePluginSyncRun,
- syncSelectedRemotePlugins,
- } from "../src/settings/RemotePluginSyncDialog.js";
- type RemotePluginSyncParams = Parameters<typeof syncSelectedRemotePlugins>[0];
- type RemotePluginSyncRow = RemotePluginSyncParams["rows"][number];
- type RemoteInstallResult = Awaited<
- ReturnType<NonNullable<RemotePluginSyncParams["remoteZCodeAgentService"]>["installPlugin"]>
- >;
- function makeCandidate(
- overrides: Partial<PluginSyncCandidate>,
- ): PluginSyncCandidate {
- return {
- id: "remote-tools-id",
- name: "remote-tools",
- pluginId: "remote-tools@inline",
- directoryName: "remote-tools",
- path: "/Users/me/.zcode/plugins/remote-tools",
- sizeBytes: 128,
- enabled: true,
- componentTypes: ["skills"],
- ...overrides,
- };
- }
- function makeOverview(
- installed: ZCodePluginsOverviewResult["installedPlugins"],
- source: ZCodePluginsOverviewResult["marketplaces"][number]["source"] = {
- source: "github",
- repo: "example/team-plugins",
- ref: "main",
- },
- ): ZCodePluginsOverviewResult {
- return {
- marketplaces: [
- {
- id: "team-market",
- name: "team-market",
- source,
- pluginCount: 1,
- },
- ],
- availablePlugins: [],
- installedPlugins: installed,
- restorableBuiltins: [],
- diagnostics: [],
- capability: { supported: true },
- };
- }
- function deferred<T>() {
- let resolve!: (value: T) => void;
- let reject!: (reason?: unknown) => void;
- const promise = new Promise<T>((promiseResolve, promiseReject) => {
- resolve = promiseResolve;
- reject = promiseReject;
- });
- return { promise, reject, resolve };
- }
- function makeMarketplaceRow(name: string): RemotePluginSyncRow {
- return {
- candidate: {
- id: `marketplace:${name}@team-market`,
- kind: "marketplace",
- name,
- pluginId: `${name}@team-market`,
- marketplace: "team-market",
- enabled: true,
- componentTypes: ["command"],
- marketplacePlugin: {
- marketplaceSourceInput: "example/team-plugins",
- pluginName: name,
- },
- },
- exists: false,
- remoteMarketplaceExists: true,
- };
- }
- function makePluginInfo(
- overrides: Partial<ZCodePluginInfo>,
- ): ZCodePluginInfo {
- return {
- id: "formatter@team-market",
- name: "formatter",
- enabled: true,
- source: "cache",
- marketplace: "team-market",
- skillRootCount: 0,
- commandRootCount: 0,
- mcpServerNames: [],
- rootPath: "/cache/formatter",
- ...overrides,
- };
- }
- function delay(ms: number): Promise<"timeout"> {
- return new Promise((resolve) => {
- setTimeout(() => resolve("timeout"), ms);
- });
- }
- describe("RemotePluginSyncDialog helpers", () => {
- it("only finishes the currently active remote plugin sync run", () => {
- const currentRun = new AbortController();
- const staleRun = new AbortController();
- expect(shouldFinishRemotePluginSyncRun(currentRun, currentRun)).toBe(true);
- expect(shouldFinishRemotePluginSyncRun(currentRun, staleRun)).toBe(false);
- });
- it("joins local plugin candidates with remote status by plugin id and directory", () => {
- const rows = buildRemotePluginSyncRows(
- [
- makeCandidate({ id: "missing-id", pluginId: "missing@inline", directoryName: "missing" }),
- makeCandidate({ id: "existing-id", pluginId: "existing@inline", directoryName: "existing" }),
- ],
- [
- {
- pluginId: "existing@inline",
- directoryName: "existing",
- exists: true,
- reason: "samePluginId",
- },
- ] satisfies PluginSyncRemoteStatus[],
- );
- expect(rows).toMatchObject([
- { candidate: { id: "inline:missing-id" }, exists: false },
- { candidate: { id: "inline:existing-id" }, exists: true },
- ]);
- });
- it("selects only missing remote plugins by default", () => {
- const rows = buildRemotePluginSyncRows(
- [
- makeCandidate({ id: "missing-id", pluginId: "missing@inline", directoryName: "missing" }),
- makeCandidate({ id: "existing-id", pluginId: "existing@inline", directoryName: "existing" }),
- ],
- [
- {
- pluginId: "existing@inline",
- directoryName: "existing",
- exists: true,
- },
- ],
- );
- expect(Array.from(resolveDefaultRemotePluginSyncSelection(rows))).toEqual([
- "inline:missing-id",
- ]);
- });
- it("filters existing remote plugins unless requested", () => {
- const rows = buildRemotePluginSyncRows(
- [
- makeCandidate({ id: "missing-id", pluginId: "missing@inline", directoryName: "missing" }),
- makeCandidate({ id: "existing-id", pluginId: "existing@inline", directoryName: "existing" }),
- ],
- [
- {
- pluginId: "existing@inline",
- directoryName: "existing",
- exists: true,
- },
- ],
- );
- expect(filterRemotePluginSyncRows(rows, false).map((row) => row.candidate.id)).toEqual([
- "inline:missing-id",
- ]);
- expect(filterRemotePluginSyncRows(rows, true).map((row) => row.candidate.id)).toEqual([
- "inline:missing-id",
- "inline:existing-id",
- ]);
- });
- it("blocks dialog close requests while plugin sync is running", () => {
- expect(shouldAllowRemotePluginSyncDialogOpenChange("preflighting", false)).toBe(false);
- expect(shouldAllowRemotePluginSyncDialogOpenChange("preflighting", true)).toBe(true);
- expect(shouldAllowRemotePluginSyncDialogOpenChange("syncing", false)).toBe(false);
- expect(shouldAllowRemotePluginSyncDialogOpenChange("syncing", true)).toBe(true);
- expect(shouldAllowRemotePluginSyncDialogOpenChange("selection", false)).toBe(true);
- expect(shouldAllowRemotePluginSyncDialogOpenChange("complete", false)).toBe(true);
- });
- it("does not carry legacy install scope into marketplace candidates", () => {
- const candidates = buildMarketplaceRemotePluginSyncCandidates(
- makeOverview([
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: false,
- scope: "workspace",
- version: "2.0.0",
- installPath: "/Users/me/.zcode/cli/plugins/cache/team-market/formatter/2.0.0",
- componentTypes: ["command", "skill"],
- },
- ]),
- [],
- );
- expect(candidates).toMatchObject([
- {
- id: "marketplace:formatter@team-market",
- kind: "marketplace",
- name: "formatter",
- pluginId: "formatter@team-market",
- marketplace: "team-market",
- enabled: false,
- componentTypes: ["command", "skill"],
- marketplacePlugin: {
- marketplaceSourceInput: "example/team-plugins#main",
- pluginName: "formatter",
- },
- },
- ]);
- });
- it("keeps local configured plugin options on marketplace sync candidates", () => {
- const candidates = buildMarketplaceRemotePluginSyncCandidates(
- makeOverview([
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- },
- ]),
- [
- makePluginInfo({
- userConfig: {
- region: { type: "string" },
- token: { type: "string", sensitive: true },
- },
- configuredOptions: {
- region: "cn",
- token: "local-secret",
- },
- }),
- ],
- );
- expect(candidates[0]?.pluginOptions).toEqual({
- configuredOptions: {
- region: "cn",
- token: "local-secret",
- },
- userConfig: {
- region: { type: "string" },
- token: { type: "string", sensitive: true },
- },
- });
- });
- it("builds marketplace candidates with source archive metadata for local directory sources", () => {
- const candidates = buildMarketplaceRemotePluginSyncCandidates(
- makeOverview(
- [
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- },
- ],
- { source: "directory", path: "/Users/me/plugins/team-market" },
- ),
- [],
- );
- expect(candidates).toMatchObject([
- {
- id: "marketplace:formatter@team-market",
- marketplacePlugin: {
- pluginName: "formatter",
- marketplaceSourceArchive: {
- marketplaceId: "team-market",
- source: { source: "directory", path: "/Users/me/plugins/team-market" },
- },
- },
- },
- ]);
- expect(candidates[0]?.marketplacePlugin).not.toHaveProperty("marketplaceSourceInput");
- });
- it("selects missing marketplace plugins and filters existing ones", () => {
- const candidates = buildMarketplaceRemotePluginSyncCandidates(
- makeOverview([
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- },
- {
- id: "runner@team-market",
- name: "runner",
- marketplace: "team-market",
- enabled: true,
- scope: "workspace",
- },
- ]),
- [],
- );
- const statuses = buildMarketplaceRemotePluginStatuses(
- candidates,
- makeOverview([
- {
- id: "runner@team-market",
- name: "runner",
- marketplace: "team-market",
- enabled: true,
- scope: "workspace",
- installPath: "/remote/cache/runner",
- },
- ]),
- );
- const rows = buildRemotePluginSyncRowsForCandidates(candidates, statuses);
- expect(Array.from(resolveDefaultRemotePluginSyncSelection(rows))).toEqual([
- "marketplace:formatter@team-market",
- ]);
- expect(filterRemotePluginSyncRows(rows, false).map((row) => row.candidate.id)).toEqual([
- "marketplace:formatter@team-market",
- ]);
- });
- it("mirrors a local marketplace source before adding and installing on the remote", async () => {
- const calls: string[] = [];
- const archive = new Uint8Array([1, 2, 3]);
- const result = await syncSelectedRemotePlugins({
- localPluginSyncService: {
- exportMarketplaceSourceArchive: async (params) => {
- calls.push(`export:${params.marketplaceId}:${params.pluginNames.join(",")}`);
- expect(params.source).toEqual({
- source: "directory",
- path: "/Users/me/plugins/team-market",
- });
- return {
- archive,
- archiveBytes: archive.byteLength,
- marketplaceId: "team-market",
- pluginNames: params.pluginNames,
- };
- },
- } as never,
- remotePluginSyncService: {
- importMarketplaceSourceArchive: async (params) => {
- calls.push("import");
- expect(params.archive).toBe(archive);
- return {
- marketplaceId: "team-market",
- path: "/remote/.zcode/plugins/marketplace-sources/team-market-hash",
- status: "synced",
- };
- },
- } as never,
- remoteWorkspacePath: "/remote/workspace",
- remoteZCodeAgentService: {
- addPluginMarketplace: async (params) => {
- calls.push(`add:${params.source}`);
- return { diagnostics: [] };
- },
- installPlugin: async (params) => {
- calls.push(`install:${params.pluginName}@${params.marketplace}`);
- return {
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- installPath: "/remote/cache/formatter",
- },
- ],
- };
- },
- setPluginEnabled: async (params) => {
- calls.push(`enabled:${params.pluginId}:${params.enabled}`);
- return {
- enabled: params.enabled,
- plugin: {
- id: params.pluginId,
- name: "formatter",
- enabled: params.enabled,
- source: "cache",
- marketplace: "team-market",
- skillRootCount: 0,
- commandRootCount: 0,
- mcpServerNames: [],
- rootPath: "/remote/cache/formatter",
- },
- };
- },
- } as never,
- rows: [
- {
- candidate: {
- id: "marketplace:formatter@team-market",
- kind: "marketplace",
- name: "formatter",
- pluginId: "formatter@team-market",
- marketplace: "team-market",
- enabled: true,
- componentTypes: ["skill"],
- marketplacePlugin: {
- marketplaceSourceArchive: {
- marketplaceId: "team-market",
- source: { source: "directory", path: "/Users/me/plugins/team-market" },
- },
- pluginName: "formatter",
- },
- },
- exists: false,
- remoteMarketplaceExists: false,
- },
- ],
- });
- expect(result.results).toMatchObject([
- {
- pluginId: "formatter@team-market",
- status: "synced",
- },
- ]);
- expect(calls).toEqual([
- "export:team-market:formatter",
- "import",
- "add:/remote/.zcode/plugins/marketplace-sources/team-market-hash",
- "install:formatter@team-market",
- "enabled:formatter@team-market:true",
- ]);
- });
- it("syncs only portable configured plugin options and preserves remote options", async () => {
- const configureCalls: Array<Record<string, unknown>> = [];
- const progress: string[] = [];
- const result = await syncSelectedRemotePlugins({
- localPluginSyncService: {} as never,
- remotePluginSyncService: {} as never,
- remoteWorkspacePath: "/remote/workspace",
- remoteZCodeAgentService: {
- installPlugin: async () => ({
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- installPath: "/remote/cache/formatter",
- },
- ],
- }),
- setPluginEnabled: async (params) => ({
- enabled: params.enabled,
- plugin: makePluginInfo({
- id: params.pluginId,
- rootPath: "/remote/cache/formatter",
- }),
- }),
- listPlugins: async () => ({
- diagnostics: [],
- plugins: [
- makePluginInfo({
- id: "formatter@team-market",
- rootPath: "/remote/cache/formatter",
- userConfig: {
- region: { type: "string" },
- retries: { type: "number" },
- token: { type: "string", sensitive: true },
- workspaceDir: { type: "directory" },
- },
- configuredOptions: {
- remoteOnly: true,
- },
- }),
- ],
- }),
- configurePlugin: async (params) => {
- configureCalls.push(params.options);
- return { diagnostics: [], pluginId: params.pluginId };
- },
- } as never,
- rows: [
- {
- candidate: {
- id: "marketplace:formatter@team-market",
- kind: "marketplace",
- name: "formatter",
- pluginId: "formatter@team-market",
- marketplace: "team-market",
- enabled: true,
- componentTypes: ["command"],
- pluginOptions: {
- userConfig: {
- region: { type: "string" },
- retries: { type: "number" },
- token: { type: "string", sensitive: true },
- workspaceDir: { type: "directory" },
- stale: { type: "string" },
- },
- configuredOptions: {
- region: "cn",
- retries: 2,
- token: "local-secret",
- workspaceDir: "/Users/me/project",
- stale: "old",
- },
- },
- marketplacePlugin: {
- marketplaceSourceInput: "example/team-plugins",
- pluginName: "formatter",
- },
- },
- exists: false,
- remoteMarketplaceExists: true,
- },
- ],
- onItemProgress: (event) => {
- progress.push(event.log);
- },
- });
- expect(result.results).toMatchObject([
- {
- pluginId: "formatter@team-market",
- status: "synced",
- },
- ]);
- expect(configureCalls).toEqual([
- {
- remoteOnly: true,
- region: "cn",
- retries: 2,
- },
- ]);
- expect(progress.join("\n")).toContain("RPC plugins/configure 2 portable option(s)");
- expect(progress.join("\n")).toContain("skipped 3 non-portable plugin option(s)");
- });
- it("uses User config scope for all marketplace sync operations", async () => {
- const calls: Array<{ operation: string; scope: string | undefined }> = [];
- const result = await syncSelectedRemotePlugins({
- localPluginSyncService: {} as never,
- remotePluginSyncService: {} as never,
- remoteWorkspacePath: "/remote/workspace",
- remoteZCodeAgentService: {
- installPlugin: async (params) => {
- calls.push({ operation: "install", scope: params.scope });
- return {
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [
- {
- id: "formatter@team-market",
- name: "formatter",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- installPath: "/remote/cache/formatter",
- },
- ],
- };
- },
- setPluginEnabled: async (params) => {
- calls.push({ operation: "setEnabled", scope: params.scope });
- return {
- enabled: params.enabled,
- plugin: makePluginInfo({ id: params.pluginId, rootPath: "/remote/cache/formatter" }),
- };
- },
- listPlugins: async () => ({
- diagnostics: [],
- plugins: [
- makePluginInfo({
- configuredOptions: {},
- id: "formatter@team-market",
- userConfig: { region: { type: "string" } },
- }),
- ],
- }),
- configurePlugin: async (params) => {
- calls.push({ operation: "configure", scope: params.scope });
- return { diagnostics: [], pluginId: params.pluginId };
- },
- } as never,
- rows: [
- {
- candidate: {
- id: "marketplace:formatter@team-market",
- kind: "marketplace",
- name: "formatter",
- pluginId: "formatter@team-market",
- marketplace: "team-market",
- enabled: true,
- componentTypes: ["skill"],
- pluginOptions: {
- userConfig: { region: { type: "string" } },
- configuredOptions: { region: "cn" },
- },
- marketplacePlugin: {
- marketplaceSourceInput: "example/team-plugins",
- pluginName: "formatter",
- },
- },
- exists: false,
- remoteMarketplaceExists: true,
- },
- ],
- });
- expect(result.results).toMatchObject([
- { pluginId: "formatter@team-market", status: "synced" },
- ]);
- expect(calls).toEqual([
- { operation: "install", scope: "user" },
- { operation: "setEnabled", scope: "user" },
- { operation: "configure", scope: "user" },
- ]);
- });
- it("stops waiting for one marketplace plugin and continues syncing the next plugin", async () => {
- const slowInstall = deferred<RemoteInstallResult>();
- const slowStarted = deferred<void>();
- const fastStarted = deferred<void>();
- const stoppedIds = new Set<string>();
- const stopWaiters = new Map<string, () => void>();
- const progress: Array<{ candidateId: string; log: string; status: string }> = [];
- const cancelCalls: string[] = [];
- const installOperationIds: string[] = [];
- const stopPlugin = (candidateId: string) => {
- stoppedIds.add(candidateId);
- stopWaiters.get(candidateId)?.();
- };
- const resultPromise = syncSelectedRemotePlugins({
- localPluginSyncService: {} as never,
- remotePluginSyncService: {} as never,
- remoteWorkspacePath: "/remote/workspace",
- remoteZCodeAgentService: {
- installPlugin: async (params) => {
- installOperationIds.push(params.operationId ?? "");
- if (params.pluginName === "slow") {
- slowStarted.resolve();
- return await slowInstall.promise;
- }
- fastStarted.resolve();
- return {
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [
- {
- id: "fast@team-market",
- name: "fast",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- installPath: "/remote/cache/fast",
- },
- ],
- };
- },
- setPluginEnabled: async (params) => ({
- enabled: params.enabled,
- plugin: {
- id: params.pluginId,
- name: params.pluginId.split("@")[0] ?? params.pluginId,
- enabled: params.enabled,
- source: "cache",
- marketplace: "team-market",
- skillRootCount: 0,
- commandRootCount: 0,
- mcpServerNames: [],
- rootPath: `/remote/cache/${params.pluginId}`,
- },
- }),
- cancelPluginOperation: async (params) => {
- cancelCalls.push(params.operationId);
- return { cancelled: true, operationId: params.operationId };
- },
- } as never,
- rows: [makeMarketplaceRow("slow"), makeMarketplaceRow("fast")],
- onItemProgress: (event) => {
- progress.push({
- candidateId: event.candidateId,
- log: event.log,
- status: event.status,
- });
- },
- stopControl: {
- isStopped: (candidateId) => stoppedIds.has(candidateId),
- waitForStop: (candidateId) =>
- new Promise<void>((resolve) => {
- stopWaiters.set(candidateId, resolve);
- }),
- cancelOperation: async (operationId) => {
- await (
- {
- cancelPluginOperation: async (params: { operationId: string }) => {
- cancelCalls.push(params.operationId);
- return { cancelled: true, operationId: params.operationId };
- },
- }
- ).cancelPluginOperation({ operationId });
- },
- },
- });
- await slowStarted.promise;
- stopPlugin("marketplace:slow@team-market");
- await expect(
- Promise.race([fastStarted.promise.then(() => "fast-started" as const), delay(25)]),
- ).resolves.toBe("fast-started");
- expect(installOperationIds[0]).toMatch(/^remote-plugin-sync-/);
- expect(cancelCalls).toEqual([installOperationIds[0]]);
- slowInstall.resolve({
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [
- {
- id: "slow@team-market",
- name: "slow",
- marketplace: "team-market",
- enabled: true,
- scope: "user",
- installPath: "/remote/cache/slow",
- },
- ],
- });
- await expect(resultPromise).resolves.toMatchObject({
- results: [
- {
- pluginId: "slow@team-market",
- status: "stopped",
- },
- {
- pluginId: "fast@team-market",
- status: "synced",
- },
- ],
- });
- expect(progress).toEqual(
- expect.arrayContaining([
- expect.objectContaining({
- candidateId: "marketplace:slow@team-market",
- status: "syncing",
- log: expect.stringContaining("install"),
- }),
- expect.objectContaining({
- candidateId: "marketplace:slow@team-market",
- status: "stopped",
- log: expect.stringContaining("stop"),
- }),
- expect.objectContaining({
- candidateId: "marketplace:fast@team-market",
- status: "synced",
- }),
- ]),
- );
- });
- it("aborts an active remote plugin operation when its target becomes invalid", async () => {
- const controller = new AbortController();
- const slowInstall = deferred<RemoteInstallResult>();
- const slowStarted = deferred<void>();
- const cancelCalls: string[] = [];
- const installOperationIds: string[] = [];
- const resultPromise = syncSelectedRemotePlugins({
- localPluginSyncService: {} as never,
- remotePluginSyncService: {} as never,
- remoteWorkspacePath: "/remote/workspace",
- remoteZCodeAgentService: {
- installPlugin: async (params) => {
- installOperationIds.push(params.operationId ?? "");
- slowStarted.resolve();
- return await slowInstall.promise;
- },
- } as never,
- rows: [makeMarketplaceRow("slow")],
- signal: controller.signal,
- stopControl: {
- isStopped: () => false,
- cancelOperation: async (operationId) => {
- cancelCalls.push(operationId);
- },
- },
- });
- await slowStarted.promise;
- controller.abort();
- const outcome = await Promise.race([resultPromise, delay(25)]);
- expect(outcome).not.toBe("timeout");
- expect(outcome).toMatchObject({
- results: [
- {
- pluginId: "slow@team-market",
- status: "stopped",
- },
- ],
- });
- expect(cancelCalls).toEqual([installOperationIds[0]]);
- slowInstall.resolve({
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [],
- });
- });
- it("does not start a remote install when a plugin was already stopped", async () => {
- const installCalls: string[] = [];
- const result = await syncSelectedRemotePlugins({
- localPluginSyncService: {} as never,
- remotePluginSyncService: {} as never,
- remoteWorkspacePath: "/remote/workspace",
- remoteZCodeAgentService: {
- installPlugin: async (params) => {
- installCalls.push(params.pluginName);
- return {
- dependencyClosure: [],
- diagnostics: [],
- installedPlugins: [],
- };
- },
- } as never,
- rows: [makeMarketplaceRow("stopped")],
- stopControl: {
- isStopped: (candidateId) => candidateId === "marketplace:stopped@team-market",
- },
- });
- expect(installCalls).toEqual([]);
- expect(result.results).toMatchObject([
- {
- pluginId: "stopped@team-market",
- status: "stopped",
- },
- ]);
- });
- });
|