Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions apps/vs-code-designer/src/__test__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import * as vscode from 'vscode';
import * as binaries from '../app/utils/binaries';
import { ensureProjectFiles } from '../app/projectConsistency/projectFilesConsistency';
import { ensureVSCodeFiles } from '../app/projectConsistency/vscodeConsistency';
import { isDevContainerWorkspace } from '../app/utils/devContainerUtils';
import { getWorkspaceSetting, shouldValidateAndInstallRuntimeDependencies, updateGlobalSetting } from '../app/utils/vsCodeConfig/settings';
import {
getWorkspaceSetting,
isProjectConsistencyCheckEnabled,
shouldValidateAndInstallRuntimeDependencies,
updateGlobalSetting,
} from '../app/utils/vsCodeConfig/settings';
import { autoStartDesignTimeSetting, extensionCommand } from '../constants';
import { ext } from '../extensionVariables';
import { activate } from '../main';
Expand All @@ -17,6 +24,8 @@ const mocks = vi.hoisted(() => ({
getWorkspaceLogicAppRoots: vi.fn(),
isAutoStartDesignTimeNotificationSuppressed: vi.fn(),
isManagedIdentityAuthNotificationSuppressed: vi.fn(),
ensureProjectFiles: vi.fn(),
ensureVSCodeFiles: vi.fn(),
scheduleStartAllDesignTimeApis: vi.fn(),
startDesignTimeApi: vi.fn(),
}));
Expand Down Expand Up @@ -61,6 +70,7 @@ vi.mock('../app/utils/vsCodeConfig/settings', () => ({
getWorkspaceSetting: vi.fn(),
isManagedIdentityAuthEnabled: vi.fn(() => true),
shouldParameterizeConnections: vi.fn(() => false),
isProjectConsistencyCheckEnabled: vi.fn(() => true),
updateGlobalSetting: vi.fn(),
shouldValidateAndInstallRuntimeDependencies: vi.fn(),
}));
Expand Down Expand Up @@ -94,11 +104,11 @@ vi.mock('../app/languageServer/languageClient', () => ({
}));

vi.mock('../app/projectConsistency/projectFilesConsistency', () => ({
ensureProjectFiles: vi.fn(),
ensureProjectFiles: mocks.ensureProjectFiles,
}));

vi.mock('../app/projectConsistency/vscodeConsistency', () => ({
ensureVSCodeFiles: vi.fn(),
ensureVSCodeFiles: mocks.ensureVSCodeFiles,
}));

vi.mock('../app/resourcesExtension/getExtensionApi', () => ({
Expand Down Expand Up @@ -270,6 +280,7 @@ describe('activate design-time startup', () => {
mocks.startDesignTimeApi.mockResolvedValue(undefined);
vi.mocked(isDevContainerWorkspace).mockResolvedValue(false);
vi.mocked(shouldValidateAndInstallRuntimeDependencies).mockReturnValue(false);
vi.mocked(isProjectConsistencyCheckEnabled).mockReturnValue(true);
vi.mocked(getWorkspaceSetting).mockReturnValue(false);
vi.mocked(updateGlobalSetting).mockResolvedValue(undefined);

Expand Down Expand Up @@ -299,6 +310,20 @@ describe('activate design-time startup', () => {
await Promise.all(backgroundOperations);
});

it('skips startup project consistency checks when the setting is disabled', async () => {
(vscode.workspace as any).workspaceFolders = [{ uri: { fsPath: 'D:\\workspace' }, name: 'workspace', index: 0 }];
mocks.getWorkspaceLogicAppRoots.mockResolvedValue(['D:\\workspace\\app-one']);
vi.mocked(isProjectConsistencyCheckEnabled).mockReturnValue(false);
mocks.isAutoStartDesignTimeNotificationSuppressed.mockReturnValue(true);

await activate(createExtensionContext());
await flushPromises();
await Promise.all(backgroundOperations);

expect(ensureProjectFiles).not.toHaveBeenCalled();
expect(ensureVSCodeFiles).not.toHaveBeenCalled();
});

it('starts all workspace projects before waiting for any startup to finish', async () => {
let resolveFirstStartup!: () => void;
let resolveSecondStartup!: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ describe('pickFuncProcessInternal', () => {
);
});

it('starts generateDebugSymbols for codeless NuGet launch configurations', async () => {
it('does not start a stale bundle-based generateDebugSymbols task for codeless NuGet launch configurations', async () => {
(vscode.tasks.fetchTasks as any).mockResolvedValue([funcTask, debugTask]);
(vscode.tasks.executeTask as any).mockResolvedValue(undefined);
(vscode.tasks.onDidEndTaskProcess as any).mockImplementation((callback: (event: any) => void) => {
Expand All @@ -906,7 +906,7 @@ describe('pickFuncProcessInternal', () => {
);

expect(result).toBe('1234');
expect(vscode.tasks.executeTask).toHaveBeenCalledWith(debugTask);
expect(vscode.tasks.executeTask).not.toHaveBeenCalledWith(debugTask);
expect(executeIfNotActive).toHaveBeenCalledWith(funcTask);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { workspace } from 'vscode';
import { ensureProjectFiles } from '../../projectConsistency/projectFilesConsistency';
import { ensureVSCodeFiles } from '../../projectConsistency/vscodeConsistency';
import { getWorkspaceLogicAppRoots } from '../../utils/workspace';
import { isProjectConsistencyCheckEnabled } from '../../utils/vsCodeConfig/settings';
import { runProjectConsistencyCheck } from '../runProjectConsistencyCheck';

vi.mock('../../projectConsistency/projectFilesConsistency', () => ({
ensureProjectFiles: vi.fn(),
}));

vi.mock('../../projectConsistency/vscodeConsistency', () => ({
ensureVSCodeFiles: vi.fn(),
}));

vi.mock('../../utils/workspace', () => ({
getWorkspaceLogicAppRoots: vi.fn(),
}));

vi.mock('../../utils/vsCodeConfig/settings', () => ({
isProjectConsistencyCheckEnabled: vi.fn(),
}));

describe('runProjectConsistencyCheck', () => {
const context = {} as any;

beforeEach(() => {
vi.clearAllMocks();
(workspace as any).workspaceFolders = [{ uri: { fsPath: 'D:\\workspace' }, name: 'workspace', index: 0 }];
vi.mocked(getWorkspaceLogicAppRoots).mockResolvedValue(['D:\\workspace\\app-one']);
vi.mocked(isProjectConsistencyCheckEnabled).mockReturnValue(true);
});

it('skips project and VS Code consistency checks when disabled', async () => {
vi.mocked(isProjectConsistencyCheckEnabled).mockReturnValue(false);

await runProjectConsistencyCheck(context);

expect(getWorkspaceLogicAppRoots).not.toHaveBeenCalled();
expect(ensureProjectFiles).not.toHaveBeenCalled();
expect(ensureVSCodeFiles).not.toHaveBeenCalled();
});

it('checks all discovered projects when enabled', async () => {
await runProjectConsistencyCheck(context);

expect(ensureProjectFiles).toHaveBeenCalledWith(context, 'D:\\workspace\\app-one');
expect(ensureVSCodeFiles).toHaveBeenCalledWith(context, ['D:\\workspace\\app-one']);
});
});
3 changes: 1 addition & 2 deletions apps/vs-code-designer/src/app/commands/pickFuncProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ export async function pickFuncProcessInternal(

getPickProcessTimeout(context);

const isCodelessNugetProject = !isBundleProject && debugConfig.isCodeless === true && !debugConfig.customCodeRuntime;
if (symbolTask && !debugConfig['noDebug'] && (isBundleProject || !debugConfig.isCodeless || isCodelessNugetProject)) {
if (symbolTask && !debugConfig['noDebug'] && (isBundleProject || !debugConfig.isCodeless)) {
await startDebugTask(symbolTask, workspaceFolder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { ensureProjectFiles } from '../projectConsistency/projectFilesConsistenc
import { ensureVSCodeFiles } from '../projectConsistency/vscodeConsistency';
import * as vscode from 'vscode';
import { getWorkspaceLogicAppRoots } from '../utils/workspace';
import { isProjectConsistencyCheckEnabled } from '../utils/vsCodeConfig/settings';

export async function runProjectConsistencyCheck(context: IActionContext): Promise<void> {
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0 || !isProjectConsistencyCheckEnabled()) {
return;
}
const projectPaths = await getWorkspaceLogicAppRoots();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ vi.mock('../../../../extensionVariables', () => ({
ext: { showError: vi.fn(), outputChannel: { appendLog: vi.fn() } },
}));

vi.mock('fs-extra', () => ({
pathExists: vi.fn(),
readdir: vi.fn(),
stat: vi.fn(),
statSync: vi.fn(() => ({ isDirectory: () => false })),
unlink: vi.fn(),
rename: vi.fn(),
writeFileSync: vi.fn(),
}));

vi.mock('path', async () => {
const actual = await vi.importActual<typeof import('path')>('path');
return {
Expand Down Expand Up @@ -187,7 +197,7 @@ describe('switchToDotnetProject', () => {
vi.mocked(getTemplateKeyFromProjFile).mockResolvedValue('testKey');
vi.mocked(getContainingWorkspaceFolder).mockReturnValue(undefined);
vscode.workspace.workspaceFolders = [{ uri: { fsPath: '/workspace' } } as vscode.WorkspaceFolder];
(fse.pathExists as unknown as Mock).mockResolvedValue(false);
(fse.pathExists as unknown as Mock).mockImplementation(async (filePath: string) => filePath.endsWith('/host.json'));
(fse.readdir as unknown as Mock).mockResolvedValue([]);
(fse.stat as unknown as Mock).mockResolvedValue({ isDirectory: () => false });
// writeFileSync is used by createGlobalJsonFile but not in the global test-setup mock
Expand Down Expand Up @@ -367,6 +377,49 @@ describe('switchToDotnetProject', () => {
expect(stopFuncTaskForWorkspace).toHaveBeenCalledWith(workspaceFolder);
expect(events).toEqual(['stop-func', 'init-vscode']);
});

it('should retain the generated host.json and restore local.settings.json', async () => {
const existingPaths = new Set([
'/test/project/host.json',
'/test/project/host.json-copy',
'/test/project/local.settings.json',
'/test/project/local.settings.json-copy',
]);
(fse.pathExists as unknown as Mock).mockImplementation(async (filePath: string) => existingPaths.has(filePath));

await switchToDotnetProject(mockContext, mockTarget);

expect(fse.unlink).toHaveBeenCalledWith('/test/project/host.json-copy');
expect(fse.unlink).not.toHaveBeenCalledWith('/test/project/host.json');
expect(fse.unlink).toHaveBeenCalledWith('/test/project/local.settings.json');
expect(fse.rename).toHaveBeenCalledWith('/test/project/local.settings.json-copy', '/test/project/local.settings.json');
expect(fse.rename).not.toHaveBeenCalledWith('/test/project/host.json-copy', '/test/project/host.json');
});

it('should restore the original host.json and fail when the template does not generate one', async () => {
let templateExecuted = false;
vi.mocked(executeDotnetTemplateCommand).mockImplementation(async () => {
templateExecuted = true;
return undefined;
});
(fse.pathExists as unknown as Mock).mockImplementation(async (filePath: string) => {
if (filePath === '/test/project/host.json') {
return !templateExecuted;
}
return (
filePath === '/test/project/host.json-copy' ||
filePath === '/test/project/local.settings.json' ||
filePath === '/test/project/local.settings.json-copy'
);
});

await expect(switchToDotnetProject(mockContext, mockTarget)).rejects.toThrow('NuGet project template did not generate host.json.');

expect(fse.rename).toHaveBeenCalledWith('/test/project/host.json-copy', '/test/project/host.json');
expect(fse.unlink).toHaveBeenCalledWith('/test/project/local.settings.json');
expect(fse.rename).toHaveBeenCalledWith('/test/project/local.settings.json-copy', '/test/project/local.settings.json');
expect(initDotnetExecute).not.toHaveBeenCalled();
});
});

describe('binaries handling', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ vi.mock('../../../../../utils/appSettings/localSettings', () => ({
}));

vi.mock('../../../../../utils/bundleFeed', () => ({
getBundleVersionNumber: vi.fn().mockResolvedValue('1.0.0'),
getDesignTimeBundleVersion: vi.fn().mockResolvedValue('1.0.0'),
}));

vi.mock('../../../designer/panels/designerPanel', () => {
Expand All @@ -61,6 +61,12 @@ vi.mock('../../../designer/panels/designerPanel', () => {
// ── Import the module under test (after all mocks are configured) ──────────
const mod = await import('../connectionPanel');
const OpenConnectionView = mod.default;
const { ext } = await import('../../../../../../extensionVariables');
const { startDesignTimeApi } = await import('../../../../../utils/codeless/startDesignTimeApi');
const { getDesignTimeBundleVersion } = await import('../../../../../utils/bundleFeed');
const { getLocalSettingsJson } = await import('../../../../../utils/appSettings/localSettings');
const { getArtifactsInLocalProject } = await import('../../../../../utils/codeless/artifacts');
const { getAzureConnectorDetailsForLocalProject } = await import('../../../../azureConnectors/azureConnectorDetails');

// ── Helpers ────────────────────────────────────────────────────────────────

Expand Down Expand Up @@ -212,6 +218,55 @@ describe('ConnectionView – insert_connection handles local and managed connect
});
});

describe('ConnectionPanel – design-time startup ordering', () => {
beforeEach(() => {
vi.clearAllMocks();
mockGetLogicAppProjectRoot.mockResolvedValue('/test/project');
mockGetConnectionsFromFile.mockResolvedValue('{}');
mockGetParametersFromFile.mockResolvedValue({});
vi.mocked(getDesignTimeBundleVersion).mockResolvedValue('1.0.0');
vi.mocked(getLocalSettingsJson).mockResolvedValue({ Values: {} } as any);
vi.mocked(getArtifactsInLocalProject).mockResolvedValue({ maps: {}, schemas: [] } as any);
vi.mocked(getAzureConnectorDetailsForLocalProject).mockResolvedValue({ accessToken: '', enabled: false } as any);
(ext as any).context = { extensionPath: '/extension', subscriptions: [] };
ext.designTimeInstances.clear();
});

it('waits for design-time startup before resolving bundle-dependent metadata', async () => {
let resolveDesignTime!: () => void;
vi.mocked(startDesignTimeApi).mockImplementation(
() =>
new Promise<void>((resolve) => {
resolveDesignTime = resolve;
})
);

const instance = Object.create(OpenConnectionView.prototype) as any;
instance.workflowFilePath = '/test/workflow.cs';
instance.panelGroupKey = 'connection';
instance.panelName = 'connection-panel';
instance.workflowName = 'workflow';
instance.context = { telemetry: { properties: {} } };
instance.schemaArtifacts = [];
instance.mapArtifacts = {};
instance.getExistingPanel = vi.fn().mockReturnValue(undefined);
instance.getPanelOptions = vi.fn().mockReturnValue({});
instance.getLoadingHtml = vi.fn().mockReturnValue('<html>loading</html>');
instance.getWebviewContent = vi.fn().mockResolvedValue('<html>ready</html>');

const createPromise = instance.create();
await vi.waitFor(() => expect(startDesignTimeApi).toHaveBeenCalled());
expect(mockGetConnectionsFromFile).toHaveBeenCalled();
expect(getDesignTimeBundleVersion).not.toHaveBeenCalled();

ext.designTimeInstances.set('/test/project', { port: 8000 });
resolveDesignTime();
await createPromise;

expect(getDesignTimeBundleVersion).toHaveBeenCalledWith('/test/project');
});
});

describe('ConnectionPanel – getConnectionPanelMetadata reads localSettings after azureConnectorDetails', () => {
beforeEach(() => {
vi.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getLocalSettingsJson } from '../../../../utils/appSettings/localSetting
import { getArtifactsInLocalProject } from '../../../../utils/codeless/artifacts';
import * as vscode from 'vscode';
import type { Connection } from '@microsoft/logic-apps-shared';
import { getBundleVersionNumber } from '../../../../utils/bundleFeed';
import { getDesignTimeBundleVersion } from '../../../../utils/bundleFeed';
import { saveWorkflowParameter } from '../../../../utils/codeless/parameter';
import { enableAzureConnectors } from '../../../azureConnectors/enableAzureConnectors';

Expand Down Expand Up @@ -94,14 +94,13 @@ export default class ConnectionPanel extends DesignerPanel {
// Show loading state in webview
this.panel.webview.html = this.getLoadingHtml();

// Start design time API and load metadata in parallel
const startDesignTimePromise = callWithTelemetryAndErrorHandling(
'ConnectionPanel.create.startDesignTimeApi',
async (actionContext: IActionContext) => {
await startDesignTimeApi(actionContext, this.projectPath!);
}
);
const [_, panelMetadata] = await Promise.all([startDesignTimePromise, this.getConnectionPanelMetadata()]);
const [_, panelMetadata] = await Promise.all([startDesignTimePromise, this.getConnectionPanelMetadata(startDesignTimePromise)]);

if (!ext.designTimeInstances.has(this.projectPath)) {
throw new Error(localize('designTimeNotRunning', `Design time is not running for project ${this.projectPath}.`));
Expand Down Expand Up @@ -347,7 +346,7 @@ export default class ConnectionPanel extends DesignerPanel {
});
}

private async getConnectionPanelMetadata(): Promise<ConnectionPanelMetadata> {
private async getConnectionPanelMetadata(designTimeReady: Promise<unknown> = Promise.resolve()): Promise<ConnectionPanelMetadata> {
const projectPath: string | undefined = await getLogicAppProjectRoot(this.context, this.workflowFilePath);

if (!projectPath) {
Expand All @@ -358,7 +357,7 @@ export default class ConnectionPanel extends DesignerPanel {
getConnectionsFromFile(this.context, this.workflowFilePath),
getParametersFromFile(this.context, this.workflowFilePath),
getArtifactsInLocalProject(projectPath),
getBundleVersionNumber(),
designTimeReady.then(() => getDesignTimeBundleVersion(projectPath)),
getAzureConnectorDetailsForLocalProject(this.context, projectPath),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ vi.mock('../../../../../utils/codeless/artifacts', () => ({
}));

vi.mock('../../../../../utils/bundleFeed', () => ({
getBundleVersionNumber: vi.fn().mockResolvedValue('1.0.0'),
getDesignTimeBundleVersion: vi.fn().mockResolvedValue('1.0.0'),
}));

vi.mock('../../../../../utils/appSettings/localSettings', () => ({
Expand Down Expand Up @@ -108,7 +108,7 @@ import { sendRequest } from '../../../../../utils/requestUtils';
import { startDesignTimeApi } from '../../../../../utils/codeless/startDesignTimeApi';
import { getLogicAppProjectRoot } from '../../../../../utils/codeless/connection';
import { getWebViewHTML } from '../../../../../utils/codeless/getWebViewHTML';
import { getBundleVersionNumber } from '../../../../../utils/bundleFeed';
import { getDesignTimeBundleVersion } from '../../../../../utils/bundleFeed';
import { getLocalSettingsJson } from '../../../../../utils/appSettings/localSettings';
import { getArtifactsInLocalProject } from '../../../../../utils/codeless/artifacts';
import { getAzureConnectorDetailsForLocalProject } from '../../../../azureConnectors/azureConnectorDetails';
Expand All @@ -134,7 +134,7 @@ describe('LocalDesignerV2Panel', () => {
vi.mocked(getAzureConnectorDetailsForLocalProject).mockResolvedValue({ accessToken: 'token', enabled: false } as any);
vi.mocked(getManualWorkflowsInLocalProject).mockResolvedValue({} as any);
vi.mocked(getArtifactsInLocalProject).mockResolvedValue({ maps: {}, schemas: [] } as any);
vi.mocked(getBundleVersionNumber).mockResolvedValue('1.0.0');
vi.mocked(getDesignTimeBundleVersion).mockResolvedValue('1.0.0');
vi.mocked(getWebViewHTML).mockResolvedValue('<html></html>');
vi.mocked(startDesignTimeApi).mockResolvedValue(undefined);
vi.mocked(axios.get).mockResolvedValue({ data: { properties: { manifest: {} } } });
Expand Down
Loading
Loading