Skip to content

Commit d0d57bd

Browse files
authored
Merge pull request #751 from rage/sha
langs shasum
2 parents b5c1daa + 73383fe commit d0d57bd

File tree

14 files changed

+267
-50
lines changed

14 files changed

+267
-50
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [3.5.0] - 2025-06-16
4+
5+
- Added shasum check for langs CLI executable.
6+
37
## [3.4.0] - 2025-06-16
48

59
- Improved error handling during initialization.

bin/updateLangs.bash

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
if [ -z ${1+x} ]; then
5+
echo -e "Missing version argument"
6+
exit 1
7+
fi
8+
9+
VERSION="$1"
10+
BINDINGS_DOWNLOAD_URL="https://raw.githubusercontent.com/rage/tmc-langs-rust/${VERSION}/crates/tmc-langs-cli/bindings.d.ts"
11+
BINDINGS_DOWNLOAD_TARGET="./shared/langsSchema.ts"
12+
13+
echo "Removing old schema"
14+
rm "$BINDINGS_DOWNLOAD_TARGET"
15+
16+
echo "Downloading generated type definitions"
17+
GENERATED=$(curl "$BINDINGS_DOWNLOAD_URL")
18+
19+
# write version to the file
20+
printf "// VERSION=%s\n" "$VERSION" > "$BINDINGS_DOWNLOAD_TARGET"
21+
# write URL to the file to make it easy to keep track of the version
22+
printf "// %s\n\n" "$BINDINGS_DOWNLOAD_URL" >> "$BINDINGS_DOWNLOAD_TARGET"
23+
echo "$GENERATED" | npx prettier --parser typescript >> "$BINDINGS_DOWNLOAD_TARGET"
24+
25+
# update version number
26+
sed -i s/"TMC_LANGS_RUST_VERSION = .*"/"TMC_LANGS_RUST_VERSION = \"${VERSION}\";/" ./config.js

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const path = require("path");
55

6-
const TMC_LANGS_RUST_VERSION = "0.37.1";
6+
const TMC_LANGS_RUST_VERSION = "0.38.0";
77

88
const mockTmcLocalMooc = {
99
__TMC_BACKEND_URL__: JSON.stringify("http://localhost:4001"),

package-lock.json

Lines changed: 91 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "test-my-code",
33
"displayName": "TestMyCode",
4-
"version": "3.4.0",
4+
"version": "3.5.0",
55
"description": "TestMyCode extension for Visual Studio Code",
66
"categories": [
77
"Education",
@@ -465,6 +465,7 @@
465465
"trailingComma": "all"
466466
},
467467
"dependencies": {
468+
"@aws-crypto/sha256-js": "^5.2.0",
468469
"del": "^8.0.0",
469470
"fs-extra": "^11.2.0",
470471
"get-folder-size": "^5.0.0",

shared/langsSchema.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// https://raw.githubusercontent.com/rage/tmc-langs-rust/master/crates/tmc-langs-cli/bindings.d.ts
1+
// VERSION=0.38.0
2+
// https://raw.githubusercontent.com/rage/tmc-langs-rust/0.38.0/crates/tmc-langs-cli/bindings.d.ts
23

34
export type Locale = string;
45

@@ -16,14 +17,19 @@ export type DataKind =
1617
"output-data-kind": "exercise-packaging-configuration";
1718
"output-data": ExercisePackagingConfiguration;
1819
}
19-
| { "output-data-kind": "local-exercises"; "output-data": Array<LocalExercise> }
20+
| { "output-data-kind": "local-tmc-exercises"; "output-data": Array<LocalTmcExercise> }
21+
| { "output-data-kind": "local-mooc-exercises"; "output-data": Array<LocalMoocExercise> }
2022
| { "output-data-kind": "refresh-result"; "output-data": RefreshData }
2123
| { "output-data-kind": "test-result"; "output-data": RunResult }
2224
| { "output-data-kind": "exercise-desc"; "output-data": ExerciseDesc }
2325
| { "output-data-kind": "updated-exercises"; "output-data": Array<UpdatedExercise> }
2426
| {
25-
"output-data-kind": "exercise-download";
26-
"output-data": DownloadOrUpdateCourseExercisesResult;
27+
"output-data-kind": "tmc-exercise-download";
28+
"output-data": DownloadOrUpdateTmcCourseExercisesResult;
29+
}
30+
| {
31+
"output-data-kind": "mooc-exercise-download";
32+
"output-data": DownloadOrUpdateMoocCourseExercisesResult;
2733
}
2834
| { "output-data-kind": "combined-course-data"; "output-data": CombinedCourseData }
2935
| { "output-data-kind": "course-details"; "output-data": CourseDetails }
@@ -64,9 +70,9 @@ export type Kind =
6470
| "invalid-token"
6571
| {
6672
"failed-exercise-download": {
67-
completed: Array<ExerciseDownload>;
68-
skipped: Array<ExerciseDownload>;
69-
failed: Array<[ExerciseDownload, Array<string>]>;
73+
completed: Array<TmcExerciseDownload>;
74+
skipped: Array<TmcExerciseDownload>;
75+
failed: Array<[TmcExerciseDownload, Array<string>]>;
7076
};
7177
};
7278

@@ -131,7 +137,11 @@ export type ExercisePackagingConfiguration = {
131137
exercise_file_paths: Array<string>;
132138
};
133139

134-
export type LocalExercise = { "exercise-slug": string; "exercise-path": string };
140+
export type LocalExercise = { tmc: LocalTmcExercise } | { mooc: LocalMoocExercise };
141+
142+
export type LocalTmcExercise = { "exercise-slug": string; "exercise-path": string };
143+
144+
export type LocalMoocExercise = { "exercise-id": string; "exercise-path": string };
135145

136146
export type Compression = "tar" | "zip" | "zstd";
137147

@@ -247,19 +257,27 @@ export type TestDesc = {
247257

248258
export type UpdatedExercise = { id: number };
249259

250-
export type DownloadOrUpdateCourseExercisesResult = {
251-
downloaded: Array<ExerciseDownload>;
252-
skipped: Array<ExerciseDownload>;
253-
failed?: Array<[ExerciseDownload, Array<string>]>;
260+
export type DownloadOrUpdateTmcCourseExercisesResult = {
261+
downloaded: Array<TmcExerciseDownload>;
262+
skipped: Array<TmcExerciseDownload>;
263+
failed?: Array<[TmcExerciseDownload, Array<string>]>;
254264
};
255265

256-
export type ExerciseDownload = {
266+
export type DownloadOrUpdateMoocCourseExercisesResult = {
267+
downloaded: Array<MoocExerciseDownload>;
268+
skipped: Array<MoocExerciseDownload>;
269+
failed?: Array<[MoocExerciseDownload, Array<string>]>;
270+
};
271+
272+
export type TmcExerciseDownload = {
257273
id: number;
258274
"course-slug": string;
259275
"exercise-slug": string;
260276
path: string;
261277
};
262278

279+
export type MoocExerciseDownload = { id: string; path: string };
280+
263281
export type CombinedCourseData = {
264282
details: CourseDetails;
265283
exercises: Array<CourseExercise>;
@@ -615,12 +633,12 @@ export type TmcExerciseTask = {
615633
};
616634

617635
export type PublicSpec =
618-
| { type: "browser"; files: Array<ExerciseFile> }
619-
| { type: "editor"; archiveName: string; archiveDownloadUrl: string; checksum: string };
636+
| { type: "Browser"; files: Array<ExerciseFile> }
637+
| { type: "Editor"; archive_name: string; archive_download_url: string; checksum: string };
620638

621639
export type ModelSolutionSpec =
622-
| { type: "browser"; solutionFiles: Array<ExerciseFile> }
623-
| { type: "editor"; archiveDownloadUrl: string };
640+
| { type: "Browser"; solution_files: Array<ExerciseFile> }
641+
| { type: "Editor"; download_url: string };
624642

625643
export type ExerciseFile = { filepath: string; contents: string };
626644

src/api/tmc.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import {
2929
CourseDetails,
3030
CourseExercise,
3131
DataKind,
32-
DownloadOrUpdateCourseExercisesResult,
32+
DownloadOrUpdateTmcCourseExercisesResult,
3333
ExerciseDetails,
34-
LocalExercise,
34+
LocalTmcExercise,
3535
Organization,
3636
OutputData,
3737
RunResult,
@@ -229,25 +229,25 @@ export default class TMC {
229229
}
230230

231231
/**
232-
* Lists local exercises for given course. Uses TMC-langs `list-local-course-exercises` command
232+
* Lists local exercises for given course. Uses TMC-langs `list-local-tmc-course-exercises` command
233233
* internally.
234234
*
235235
* @param courseSlug Course which's exercises should be listed.
236236
*/
237237
public async listLocalCourseExercises(
238238
courseSlug: string,
239-
): Promise<Result<LocalExercise[], Error>> {
239+
): Promise<Result<LocalTmcExercise[], Error>> {
240240
const res = await this._executeLangsCommand(
241241
{
242242
args: [
243-
"list-local-course-exercises",
243+
"list-local-tmc-course-exercises",
244244
"--client-name",
245245
this.clientName,
246246
"--course-slug",
247247
courseSlug,
248248
],
249249
},
250-
"local-exercises",
250+
"local-tmc-exercises",
251251
);
252252
return res.map((x) => x.data["output-data"]);
253253
}
@@ -464,7 +464,7 @@ export default class TMC {
464464
ids: number[],
465465
downloadTemplate: boolean,
466466
onDownloaded: (value: { id: number; percent: number; message?: string }) => void,
467-
): Promise<Result<DownloadOrUpdateCourseExercisesResult, Error>> {
467+
): Promise<Result<DownloadOrUpdateTmcCourseExercisesResult, Error>> {
468468
const onStdout = (res: StatusUpdateData): void => {
469469
if (
470470
res["update-data-kind"] === "client-update-data" &&
@@ -488,7 +488,7 @@ export default class TMC {
488488
),
489489
onStdout,
490490
},
491-
"exercise-download",
491+
"tmc-exercise-download",
492492
);
493493
return res.andThen((x) => {
494494
// Invalidate exercise update cache

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function activateInner(context: vscode.ExtensionContext): Promise<void> {
6767

6868
const dialog = new Dialog();
6969
const cliFolderPath = cliFolder(context);
70-
const cliPathResult = await init.downloadCorrectLangsVersion(cliFolderPath, dialog);
70+
const cliPathResult = await init.ensureLangsUpdated(cliFolderPath, dialog);
7171

7272
// download langs if necessary
7373
let tmc: Result<TMC, Error>;

0 commit comments

Comments
 (0)