Skip to content

Commit 2acc1fe

Browse files
committed
[ fix ] Add path of downloaded ALS after the user chooce to download it
1 parent b2b3b1c commit 2acc1fe

File tree

7 files changed

+167
-83
lines changed

7 files changed

+167
-83
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
77

8-
## v0.6.5 - 2025-??-??
8+
## v0.6.5 - 2025-08-21
99

1010
### Fixed
1111
- #250: Misplaced hole when a line contains some special characters

lib/js/src/Main/Mock.bs.js

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

lib/js/src/State/State__SwitchVersion.bs.js

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

lib/js/test/tests/Connection/Test__Connection__Config.bs.js

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

src/Main/Mock.res

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,47 @@ module Platform = {
8686
let downloadLatestALS = (_logChannel, _memento, _globalStorageUri) => _platform =>
8787
Promise.resolve(Ok(downloadedPath))
8888

89-
let getFetchSpec = (_memento, _globalStorageUri, _platform) =>
90-
Promise.resolve(Error(Connection__Download.Error.CannotFindCompatibleALSRelease))
89+
let getFetchSpec = (_memento, _globalStorageUri, _platform) => {
90+
// Create a mock fetch spec that will make Download.getAvailableDownload work
91+
let mockAsset = {
92+
Connection__Download__GitHub.Asset.url: "https://mock.url/download.zip",
93+
id: 123456,
94+
node_id: "mock_node_id",
95+
name: "als-Agda-2.6.3-macOS-arm64.zip",
96+
label: "",
97+
content_type: "application/zip",
98+
state: "uploaded",
99+
size: 1000000,
100+
created_at: "2023-01-01T00:00:00Z",
101+
updated_at: "2023-01-01T00:00:00Z",
102+
browser_download_url: "https://mock.url/download.zip",
103+
}
104+
let mockRelease = {
105+
Connection__Download__GitHub.Release.url: "https://mock.url/release",
106+
assets_url: "https://mock.url/assets",
107+
upload_url: "https://mock.url/upload",
108+
html_url: "https://mock.url/html",
109+
id: 789012,
110+
node_id: "mock_release_node_id",
111+
tag_name: "v0.2.10",
112+
target_commitish: "main",
113+
name: "v0.2.10",
114+
draft: false,
115+
prerelease: false,
116+
created_at: "2023-01-01T00:00:00Z",
117+
published_at: "2023-01-01T00:00:00Z",
118+
assets: [mockAsset],
119+
tarball_url: "https://mock.url/tarball",
120+
zipball_url: "https://mock.url/zipball",
121+
body: Some("Mock release"),
122+
}
123+
let mockFetchSpec = {
124+
Connection__Download__GitHub.FetchSpec.asset: mockAsset,
125+
release: mockRelease,
126+
saveAsFileName: "als-Agda-2.6.3-macOS-arm64",
127+
}
128+
Promise.resolve(Ok(mockFetchSpec))
129+
}
91130
let findCommand = (_command, ~timeout as _timeout=1000) =>
92131
Promise.resolve(Error(Connection__Command.Error.NotFound))
93132
let openFolder = _uri => Promise.resolve()

src/State/State__SwitchVersion.res

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,24 @@ module Handler = {
592592
)
593593

594594
if alreadyDownloaded {
595+
// Add the already downloaded path to config
596+
// We need to get the downloaded path - use the same logic as the download case
597+
switch await Download.getAvailableDownload(state, platformDeps) {
598+
| Some((_, _)) =>
599+
// Get the path from the fetchSpec
600+
module PlatformOps = unpack(platformDeps)
601+
switch await PlatformOps.determinePlatform() {
602+
| Ok(platform) =>
603+
switch await PlatformOps.getFetchSpec(state.memento, state.globalStorageUri, platform) {
604+
| Ok(fetchSpec) =>
605+
let downloadedPath = VSCode.Uri.joinPath(state.globalStorageUri, [fetchSpec.saveAsFileName, "als"])->VSCode.Uri.fsPath
606+
await Config.Connection.addAgdaPath(state.channels.log, downloadedPath)
607+
| Error(_) => ()
608+
}
609+
| Error(_) => ()
610+
}
611+
| None => ()
612+
}
595613
// Show "already downloaded" message
596614
VSCode.Window.showInformationMessage(
597615
versionString ++ " is already downloaded",
@@ -619,7 +637,9 @@ module Handler = {
619637
[],
620638
)->Promise.done
621639
state.channels.log->Chan.emit(Log.SwitchVersionUI(SelectionCompleted))
622-
| Ok(_) =>
640+
| Ok(downloadedPath) =>
641+
// Add the downloaded path to config
642+
await Config.Connection.addAgdaPath(state.channels.log, downloadedPath)
623643
// Refresh the UI to show new status
624644
let newDownloadInfo = await Download.getAvailableDownload(state, platformDeps)
625645
let _ = SwitchVersionManager.refreshFromMemento(manager)

test/tests/Connection/Test__Connection__Config.res

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,6 @@ describe("Config.Connection paths", () => {
7070
): Platform.t
7171
)
7272

73-
// Mock platform with download capability for testing download actions
74-
let platformWithMockDownload = (
75-
module(
76-
{
77-
include Desktop.Desktop
78-
let findCommand = (_command, ~timeout as _timeout=1000) => {
79-
Promise.resolve(Ok(systemAgda.contents))
80-
}
81-
let determinePlatform = async () => Ok(Connection__Download__Platform.MacOS_Arm)
82-
let alreadyDownloaded = _globalStorageUri => async () => None
83-
84-
let downloadLatestALS = (_logChannel, _memento, _globalStorageUri) => _platform => {
85-
Promise.resolve(Ok(downloadedALS.contents))
86-
}
87-
}
88-
): Platform.t
89-
)
90-
9173
// Helper function to create a connection with given config paths
9274
// also returns a Log listener to capture config changes
9375
let makeConnection = async (configPaths: array<string>, platform: Platform.t) => {
@@ -350,7 +332,11 @@ describe("Config.Connection paths", () => {
350332
detail: "ALS v0.2.10, Agda v2.7.0.1",
351333
}
352334

353-
await executeUITest(mockState, platformWithMockDownload, mockSelectedItem)
335+
await executeUITest(
336+
mockState,
337+
Mock.Platform.makeWithSuccessfulDownload(downloadedALS.contents),
338+
mockSelectedItem,
339+
)
354340
let logs = listener(~filter=Log.isConfig)
355341
let finalConfig = Config.Connection.getAgdaPaths()
356342
(logs, finalConfig)
@@ -408,7 +394,6 @@ describe("Config.Connection paths", () => {
408394
}
409395
}
410396

411-
412397
describe(
413398
"Switch version UI selection",
414399
() => {
@@ -418,7 +403,11 @@ describe("Config.Connection paths", () => {
418403
let initialConfig = [userAgda.contents]
419404
let selectedPath = alternativeAgda.contents // not in initial config
420405

421-
let (logs, finalConfig) = await UITestBuilders.simulatePathSelection(initialConfig, selectedPath, ~description="")
406+
let (logs, finalConfig) = await UITestBuilders.simulatePathSelection(
407+
initialConfig,
408+
selectedPath,
409+
~description="",
410+
)
422411

423412
// Should add the selected path to config
424413
let expectedConfig = Array.concat(initialConfig, [selectedPath])
@@ -451,7 +440,11 @@ describe("Config.Connection paths", () => {
451440
let initialConfig = [userAgda.contents]
452441
let selectedPath = alternativeAgda.contents
453442

454-
let (logs, finalConfig) = await UITestBuilders.simulatePathSelection(initialConfig, selectedPath, ~description="")
443+
let (logs, finalConfig) = await UITestBuilders.simulatePathSelection(
444+
initialConfig,
445+
selectedPath,
446+
~description="",
447+
)
455448

456449
// Should add the new path to existing config
457450
let expectedConfig = Array.concat(initialConfig, [selectedPath])
@@ -475,15 +468,15 @@ describe("Config.Connection paths", () => {
475468
~isAlreadyDownloaded=false,
476469
)
477470

478-
// Download action should not modify config in test environment
479-
// (real downloads would modify config, but test environment doesn't have download capability)
480-
Assert.deepStrictEqual(logs, [])
481-
Assert.deepStrictEqual(finalConfig, initialConfig)
471+
// Should add the downloaded ALS path to config
472+
let expectedConfig = Array.concat(initialConfig, [downloadedALS.contents])
473+
Assert.deepStrictEqual(logs, [Log.Config(Changed(initialConfig, expectedConfig))])
474+
Assert.deepStrictEqual(finalConfig, expectedConfig)
482475
},
483476
)
484477

485478
Async.it(
486-
"should show already downloaded message when user selects already downloaded ALS",
479+
"should add already downloaded path to config when user selects already downloaded ALS",
487480
async () => {
488481
let initialConfig = [userAgda.contents]
489482

@@ -492,10 +485,10 @@ describe("Config.Connection paths", () => {
492485
~isAlreadyDownloaded=true,
493486
)
494487

495-
// Download action should not modify config in test environment
496-
// (shows message but doesn't download or modify config)
497-
Assert.deepStrictEqual(logs, [])
498-
Assert.deepStrictEqual(finalConfig, initialConfig)
488+
// Should add the already downloaded ALS path to config
489+
let expectedConfig = Array.concat(initialConfig, [downloadedALS.contents])
490+
Assert.deepStrictEqual(logs, [Log.Config(Changed(initialConfig, expectedConfig))])
491+
Assert.deepStrictEqual(finalConfig, expectedConfig)
499492
},
500493
)
501494
},

0 commit comments

Comments
 (0)