Skip to content

Commit

Permalink
Merge pull request #719 from rage/fix-cli-permissions
Browse files Browse the repository at this point in the history
Fix cli permissions
  • Loading branch information
Heliozoa authored Aug 20, 2024
2 parents 5e89caa + 93c0385 commit 4a6fb3c
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 260 deletions.
11 changes: 10 additions & 1 deletion bin/runTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ async function main() {
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "testLoader");

const extensionTestsEnv = {
TMC_VSCODE_TESTMODE: "1",
};

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath, platform });
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
extensionTestsEnv,
platform,
});
} catch (err) {
console.error("Failed to run tests");
exitCode = 1;
Expand Down
179 changes: 91 additions & 88 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"eslint-check": "eslint . --ext .js,.ts",
"postinstall": "babel node_modules/ts-results --out-dir node_modules/ts-results --plugins=@babel/plugin-transform-modules-commonjs",
"lint-check": "npm run eslint-check && npm run prettier-check",
"prepare": "husky install",
"prepare": "ts-patch install && typia patch && husky install",
"prettier": "prettier --write --ignore-path \"./src/shared/*\" --ignore-path \"./webview-ui/src/shared/*\" --ignore-path \"./.eslintignore\" \"./**/*.{html,js,json,jsx,ts,yml}\"",
"prettier-check": "prettier --check --ignore-path \"./src/shared/*\" --ignore-path \"./webview-ui/src/shared/*\" --ignore-path \"./.eslintignore\" \"./**/*.{html,js,json,jsx,ts,yml}\"",
"release": "./bin/publishRelease.sh",
Expand Down Expand Up @@ -466,16 +466,16 @@
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/preset-env": "^7.23.6",
"@playwright/test": "^1.40.1",
"@playwright/test": "1.46.1",
"@types/chai": "^4.3.11",
"@types/chai-as-promised": "^7.1.8",
"@types/du": "^1.0.3",
"@types/fs-extra": "^11.0.4",
"@types/glob": "^8.1.0",
"@types/lodash": "^4.14.202",
"@types/mocha": "^10.0.6",
"@types/mock-fs": "^4.13.4",
"@types/node": "^20.10.5",
"@types/tmp": "0.2.6",
"@types/unzipper": "^0.10.9",
"@types/vscode": "^1.75.0",
"@typescript-eslint/eslint-plugin": "^6.15.0",
Expand All @@ -495,15 +495,15 @@
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"mocha": "^10.2.0",
"mock-fs": "^5.2.0",
"prettier": "^3.1.1",
"raw-loader": "^4.0.2",
"terser-webpack-plugin": "^5.3.9",
"tmp": "0.2.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"ts-patch": "^3.1.1",
"ts-patch": "^3.2.1",
"typemoq": "^2.1.0",
"typescript": "^5.3.3",
"typescript": "^5.3.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
Expand Down
32 changes: 8 additions & 24 deletions playwright/pages/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Page } from "@playwright/test";

export class ExplorerPage {
private _trusted: boolean = false;

constructor(public readonly page: Page) {}
constructor(public readonly page: Page) {
// continuously check for the trust dialogues which
// appears at unpredictable times
page.addLocatorHandler(
page.locator(".dialog-message-text").getByText("Do you trust"),
async () => await this.page.getByRole("button", { name: "Yes" }).click(),
);
}

async openFile(filename: string): Promise<void> {
// first, let's make sure that the target isn't a directory that's already open,
Expand All @@ -28,27 +33,6 @@ export class ExplorerPage {
// selects the actual file
.getByText(filename)
.click();

// we may get prompted for trust
// when untrusted and opening a file
if (!this._trusted) {
const isDir = await this.page
.locator(".explorer-folders-view")
.locator("div.collapsible + div")
.getByText(filename)
.isVisible();
if (!isDir) {
this.page
.getByText("Yes, I trust the authors")
.click()
.then(() => {
this._trusted = true;
})
.catch(() => {
console.warn("was not asked for trust for some reason");
});
}
}
}

async openPath(path: string[]): Promise<void> {
Expand Down
16 changes: 10 additions & 6 deletions playwright/pages/tmc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ export class TmcPage {
) {}

async openMenu(): Promise<void> {
const isTmcOpen = await this.page
.getByRole("heading", { name: "TestMyCode: Menu" })
.isVisible();
if (!isTmcOpen) {
await this.page.getByRole("tab", { name: "TestMyCode" }).locator("a").click();
// for some reason the extension button doesn't work properly for some reason,
// so we'll just keep clicking until it works...
while (!(await this.page.getByRole("heading", { name: "TestMyCode: Menu" }).isVisible())) {
// the locator is very specific to not conflict with the "Welcome to TestMyCode" tab
await this.page
.locator('[id="workbench\\.parts\\.activitybar"]')
.getByRole("tab", { name: "TestMyCode" })
.locator("a")
.click();
await this.page.waitForTimeout(200);
}
await this.page.getByRole("heading", { name: "TestMyCode: Menu" }).waitFor();
}

getSidePanel(): FrameLocator {
Expand Down
2 changes: 1 addition & 1 deletion src/init/downloadCorrectLangsVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function downloadCorrectLangsVersion(

try {
const fd = await fs.open(tempPath, "r+");
await fs.fchmod(fd, 0o111);
await fs.fchmod(fd, 0o755);
await fs.close(fd);
} catch (e) {
// not sure what the best way to handle errors here is
Expand Down
6 changes: 4 additions & 2 deletions src/migrate/migrateExerciseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ function resolveExercisePathV0(
if (candidate && fs.existsSync(candidate)) {
return Ok(candidate);
} else {
Logger.debug(candidate);
Logger.debug("Invalid candidate", candidate);
}
}

return Err(
new Error(
`Failed to resolve new exercise path for exercise ${name} with paths ${candidates}`,
`Failed to resolve new exercise path for exercise ${name} with paths ${candidates.join(
", ",
)}`,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/migrate/validateData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function validateData<T>(
}

if (!validator(data)) {
throw new Error(`Data type missmatch: ${JSON.stringify(data)}`);
throw new Error(`Data type mismatch: ${JSON.stringify(data)}`);
}

return data;
Expand Down
30 changes: 14 additions & 16 deletions src/test/actions/moveExtensionDataPath.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from "chai";
import * as mockFs from "mock-fs";
import * as path from "path";
import { Err, Ok } from "ts-results";
import { IMock, It, Times } from "typemoq";
Expand All @@ -15,6 +14,7 @@ import { createMockActionContext } from "../mocks/actionContext";
import { createTMCMock, TMCMockValues } from "../mocks/tmc";
import { createUserDataMock } from "../mocks/userdata";
import { createWorkspaceMangerMock, WorkspaceManagerMockValues } from "../mocks/workspaceManager";
import { makeTmpDirs } from "../utils";

suite("moveExtensionDataPath action", function () {
const virtualFileSystem = {
Expand All @@ -27,11 +27,13 @@ suite("moveExtensionDataPath action", function () {
};

const courseName = "test-python-course";
const emptyFolder = vscode.Uri.file("/new/path/empty");
const nonEmptyFolder = vscode.Uri.file("/new/path/nonempty");
const emptyFolder = (root: string): vscode.Uri => vscode.Uri.file(root + "/new/path/empty");
const nonEmptyFolder = (root: string): vscode.Uri =>
vscode.Uri.file(root + "/new/path/nonempty");
const openExercises = workspaceExercises.filter((x) => x.status === ExerciseStatus.Open);
const openExerciseSlugs = openExercises.map((x) => x.exerciseSlug);
const stubContext = createMockActionContext();
let root: string;

let tmcMock: IMock<TMC>;
let tmcMockValues: TMCMockValues;
Expand All @@ -47,49 +49,49 @@ suite("moveExtensionDataPath action", function () {
});

setup(function () {
mockFs(virtualFileSystem);
root = makeTmpDirs(virtualFileSystem);
[tmcMock, tmcMockValues] = createTMCMock();
[userDataMock] = createUserDataMock();
[workspaceManagerMock, workspaceManagerMockValues] = createWorkspaceMangerMock();
workspaceManagerMockValues.activeCourse = courseName;
});

test("should change extension data path", async function () {
const result = await moveExtensionDataPath(actionContext(), emptyFolder);
const result = await moveExtensionDataPath(actionContext(), emptyFolder(root));
expect(result).to.be.equal(Ok.EMPTY);
tmcMock.verify(
(x) => x.moveProjectsDirectory(It.isValue(emptyFolder.fsPath), It.isAny()),
(x) => x.moveProjectsDirectory(It.isValue(emptyFolder(root).fsPath), It.isAny()),
Times.once(),
);
});

test("should append tmcdata to path if target is not empty", async function () {
const result = await moveExtensionDataPath(actionContext(), nonEmptyFolder);
const result = await moveExtensionDataPath(actionContext(), nonEmptyFolder(root));
expect(result).to.be.equal(Ok.EMPTY);
const expected = path.join(nonEmptyFolder.fsPath, "tmcdata");
const expected = path.join(nonEmptyFolder(root).fsPath, "tmcdata");
tmcMock.verify(
(x) => x.moveProjectsDirectory(It.isValue(expected), It.isAny()),
Times.once(),
);
});

test.skip("should close current workspace's exercises", async function () {
await moveExtensionDataPath(actionContext(), emptyFolder);
await moveExtensionDataPath(actionContext(), emptyFolder(root));
workspaceManagerMock.verify(
(x) => x.closeCourseExercises(It.isValue(courseName), It.isValue(openExerciseSlugs)),
Times.once(),
);
});

test("should set exercises again after moving", async function () {
await moveExtensionDataPath(actionContext(), emptyFolder);
await moveExtensionDataPath(actionContext(), emptyFolder(root));
// Due to usage of path.sep, exact matching not consistent between platforms
workspaceManagerMock.verify((x) => x.setExercises(It.isAny()), Times.once());
});

test.skip("should not close anything if no course workspace is active", async function () {
workspaceManagerMockValues.activeCourse = undefined;
await moveExtensionDataPath(actionContext(), emptyFolder);
await moveExtensionDataPath(actionContext(), emptyFolder(root));
workspaceManagerMock.verify(
(x) => x.closeCourseExercises(It.isValue(courseName), It.isValue(openExerciseSlugs)),
Times.never(),
Expand All @@ -98,11 +100,7 @@ suite("moveExtensionDataPath action", function () {

test("should result in error if TMC operation fails", async function () {
tmcMockValues.moveProjectsDirectory = Err(new Error());
const result = await moveExtensionDataPath(actionContext(), emptyFolder);
const result = await moveExtensionDataPath(actionContext(), emptyFolder(root));
expect(result.val).to.be.instanceOf(Error);
});

teardown(function () {
mockFs.restore();
});
});
52 changes: 27 additions & 25 deletions src/test/fixtures/exerciseData.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import { ExerciseStatusV0, LocalExerciseDataV0 } from "../../migrate/migrateExerciseData";

const v0_1_0: LocalExerciseDataV0[] = [
{
id: 1,
checksum: "abc123",
course: "test-python-course",
deadline: "20201214",
name: "hello_world",
organization: "test",
path: "/tmcdata/TMC workspace/Exercises/test/test-python-course/hello_world",
isOpen: true,
},
{
id: 2,
checksum: "def456",
course: "test-python-course",
deadline: "20201214",
name: "other_world",
organization: "test",
path: "/tmcdata/TMC workspace/closed-exercises/2",
isOpen: false,
},
];
const v0_1_0 = (root: string): LocalExerciseDataV0[] => {
return [
{
id: 1,
checksum: "abc123",
course: "test-python-course",
deadline: "20201214",
name: "hello_world",
organization: "test",
path: root + "/TMC workspace/Exercises/test/test-python-course/hello_world",
isOpen: true,
},
{
id: 2,
checksum: "def456",
course: "test-python-course",
deadline: "20201214",
name: "other_world",
organization: "test",
path: root + "/TMC workspace/closed-exercises/2",
isOpen: false,
},
];
};

const v0_2_0: LocalExerciseDataV0[] = [
const v0_2_0 = (root: string): LocalExerciseDataV0[] => [
{
id: 1,
checksum: "abc123",
course: "test-python-course",
deadline: "20201214",
name: "hello_world",
organization: "test",
path: "/tmcdata/TMC workspace/Exercises/test/test-python-course/hello_world",
path: root + "/TMC workspace/Exercises/test/test-python-course/hello_world",
softDeadline: "20201212",
status: ExerciseStatusV0.OPEN,
updateAvailable: true,
Expand All @@ -43,7 +45,7 @@ const v0_2_0: LocalExerciseDataV0[] = [
deadline: "20201214",
name: "other_world",
organization: "test",
path: "/tmcdata/TMC workspace/closed-exercises/2",
path: root + "/TMC workspace/closed-exercises/2",
softDeadline: "20201212",
status: ExerciseStatusV0.CLOSED,
updateAvailable: false,
Expand Down
Loading

0 comments on commit 4a6fb3c

Please sign in to comment.