-
Notifications
You must be signed in to change notification settings - Fork 555
Fix dacpac path resolution on macOS with Windows-style separators #20824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", () => { | ||
| 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); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.