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
9 changes: 6 additions & 3 deletions extensions/mssql/src/publishProject/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ export async function readProjectProperties(
// Calculate DACPAC output path
const projectDir = path.dirname(projectFilePath);
const projectName = path.basename(projectFilePath, path.extname(projectFilePath));
const outputPath = path.isAbsolute(result.outputPath)
? result.outputPath
: path.join(projectDir, result.outputPath);
// Normalize path separators for cross-platform compatibility
// path.normalize doesn't convert backslashes, so using a regex replace here
const normalizedOutputPath = result.outputPath.replace(/\\/g, "/");
const outputPath = path.isAbsolute(normalizedOutputPath)
? normalizedOutputPath
: path.join(projectDir, normalizedOutputPath);
const dacpacOutputPath = path.join(
outputPath,
`${projectName}${constants.DacpacExtension}`,
Expand Down
106 changes: 106 additions & 0 deletions extensions/mssql/test/unit/projectUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { expect } from "chai";
import * as sinon from "sinon";
import * as path from "path";
import { readProjectProperties } from "../../src/publishProject/projectUtils";
import { SqlProjectsService } from "../../src/services/sqlProjectsService";

suite("projectUtils Tests", () => {
Copy link
Contributor

@ssreerama ssreerama Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot We already have a publish‑project test file (PublishProjectWebViewController.test.ts). Instead of creating a new test file, could you add your tests to the existing one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think we should create a new file here. We try to keep the unit tests in identically-named files so that they're easy to locate.

Copy link
Contributor

@ssreerama ssreerama Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we publish this PR and test it with any MacOS, @Benjin IIRC you have the Mac right, can you test the fix, please!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested on macOS. It's looking good.

let sandbox: sinon.SinonSandbox;
let mockSqlProjectsService: sinon.SinonStubbedInstance<SqlProjectsService>;

setup(() => {
sandbox = sinon.createSandbox();
mockSqlProjectsService = sandbox.createStubInstance(SqlProjectsService);
});

teardown(() => {
sandbox.restore();
});

test("readProjectProperties normalizes Windows backslashes in outputPath on Unix", async () => {
const projectPath = "/home/user/project/TestProject.sqlproj";

// Mock getProjectProperties to return Windows-style path with backslashes
mockSqlProjectsService.getProjectProperties.resolves({
success: true,
outputPath: "bin\\Debug", // Windows-style path with backslashes
databaseSchemaProvider: "Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider",
} as any);

const result = await readProjectProperties(mockSqlProjectsService, projectPath);

expect(result).to.exist;
expect(result?.dacpacOutputPath).to.exist;

// The dacpac path should use forward slashes, not backslashes
expect(result?.dacpacOutputPath).to.not.include("\\");
expect(result?.dacpacOutputPath).to.include("/");

// Verify the path is constructed correctly with forward slashes
const expectedPath = path.join("/home/user/project", "bin/Debug", "TestProject.dacpac");
expect(result?.dacpacOutputPath).to.equal(expectedPath);
});

test("readProjectProperties handles absolute paths", async () => {
const projectPath = "/home/user/project/TestProject.sqlproj";
const absoluteOutputPath = "/absolute/output/path";

mockSqlProjectsService.getProjectProperties.resolves({
success: true,
outputPath: absoluteOutputPath,
databaseSchemaProvider: "Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider",
} as any);

const result = await readProjectProperties(mockSqlProjectsService, projectPath);

expect(result).to.exist;
expect(result?.dacpacOutputPath).to.exist;

// For absolute paths, should use the absolute path directly
const expectedPath = path.join(absoluteOutputPath, "TestProject.dacpac");
expect(result?.dacpacOutputPath).to.equal(expectedPath);
});

test("readProjectProperties normalizes Windows backslashes in absolute paths", async () => {
const projectPath = "/home/user/project/TestProject.sqlproj";
// Absolute path with Windows-style backslashes (edge case but should be handled)
const absoluteOutputPath = "C:\\absolute\\output\\path";

mockSqlProjectsService.getProjectProperties.resolves({
success: true,
outputPath: absoluteOutputPath,
databaseSchemaProvider: "Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider",
} as any);

const result = await readProjectProperties(mockSqlProjectsService, projectPath);

expect(result).to.exist;
expect(result?.dacpacOutputPath).to.exist;

// Even for absolute paths, backslashes should be normalized
expect(result?.dacpacOutputPath).to.not.include("\\");
});

test("readProjectProperties handles relative paths with forward slashes", async () => {
const projectPath = "/home/user/project/TestProject.sqlproj";

mockSqlProjectsService.getProjectProperties.resolves({
success: true,
outputPath: "bin/Debug", // Unix-style path
databaseSchemaProvider: "Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider",
} as any);

const result = await readProjectProperties(mockSqlProjectsService, projectPath);

expect(result).to.exist;
expect(result?.dacpacOutputPath).to.exist;

const expectedPath = path.join("/home/user/project", "bin/Debug", "TestProject.dacpac");
expect(result?.dacpacOutputPath).to.equal(expectedPath);
});
});
Loading