Fix script deletion during execution on desktop
This commit fixes an issue seen on certain Windows environments (Windows 10 22H2 and 11 23H2 Pro Azure VMs) where scripts were being deleted during execution due to temporary directory usage. To resolve this, scripts are now stored in a persistent directory, enhancing reliability for long-running scripts and improving auditability along with troubleshooting. Key changes: - Move script execution logic to the `main` process from `preloader` to utilize Electron's `app.getPath`. - Improve runtime environment detection for non-browser environments to allow its usage in Electron main process. - Introduce a secure module to expose IPC channels from the main process to the renderer via the preloader process. Supporting refactorings include: - Simplify `CodeRunner` interface by removing the `tempScriptFolderName` parameter. - Rename `NodeSystemOperations` to `NodeElectronSystemOperations` as it now wraps electron APIs too, and convert it to class for simplicity. - Rename `TemporaryFileCodeRunner` to `ScriptFileCodeRunner` to reflect its new functinoality. - Rename `SystemOperations` folder to `System` for simplicity. - Rename `HostRuntimeEnvironment` to `BrowserRuntimeEnvironment` for clarity. - Refactor main Electron process configuration to align with latest Electron documentation/recommendations. - Refactor unit tests `BrowserRuntimeEnvironment` to simplify singleton workaround. - Use alias imports like `electron/main` and `electron/common` for better clarity.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { BrowserCondition, TouchSupportExpectation } from '@/infrastructure/RuntimeEnvironment/BrowserOs/BrowserCondition';
|
||||
import { BrowserCondition, TouchSupportExpectation } from '@/infrastructure/RuntimeEnvironment/Browser/BrowserOs/BrowserCondition';
|
||||
|
||||
export class BrowserConditionStub implements BrowserCondition {
|
||||
public operatingSystem: OperatingSystem = OperatingSystem.Android;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BrowserEnvironment } from '@/infrastructure/RuntimeEnvironment/BrowserOs/BrowserOsDetector';
|
||||
import { BrowserEnvironment } from '@/infrastructure/RuntimeEnvironment/Browser/BrowserOs/BrowserOsDetector';
|
||||
|
||||
export class BrowserEnvironmentStub implements BrowserEnvironment {
|
||||
public isTouchSupported = false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { BrowserEnvironment, BrowserOsDetector } from '@/infrastructure/RuntimeEnvironment/BrowserOs/BrowserOsDetector';
|
||||
import { BrowserEnvironment, BrowserOsDetector } from '@/infrastructure/RuntimeEnvironment/Browser/BrowserOs/BrowserOsDetector';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export class BrowserOsDetectorStub
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CommandOps } from '@/infrastructure/CodeRunner/SystemOperations/SystemOperations';
|
||||
import { CommandOps } from '@/infrastructure/CodeRunner/System/SystemOperations';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export class CommandOpsStub
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FileSystemOps } from '@/infrastructure/CodeRunner/SystemOperations/SystemOperations';
|
||||
import { FileSystemOps } from '@/infrastructure/CodeRunner/System/SystemOperations';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export class FileSystemOpsStub
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FilenameGenerator } from '@/infrastructure/CodeRunner/Filename/FilenameGenerator';
|
||||
import { FilenameGenerator } from '@/infrastructure/CodeRunner/Creation/Filename/FilenameGenerator';
|
||||
|
||||
export class FilenameGeneratorStub implements FilenameGenerator {
|
||||
private filename = `[${FilenameGeneratorStub.name}]file-name-stub`;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LocationOps } from '@/infrastructure/CodeRunner/SystemOperations/SystemOperations';
|
||||
import { LocationOps } from '@/infrastructure/CodeRunner/System/SystemOperations';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export class LocationOpsStub
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { OperatingSystemOps } from '@/infrastructure/CodeRunner/SystemOperations/SystemOperations';
|
||||
import { OperatingSystemOps } from '@/infrastructure/CodeRunner/System/SystemOperations';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export class OperatingSystemOpsStub
|
||||
extends StubWithObservableMethodCalls<OperatingSystemOps>
|
||||
implements OperatingSystemOps {
|
||||
private temporaryDirectory = '/stub-temp-dir/';
|
||||
private userDataDirectory = `/${OperatingSystemOpsStub.name}-user-data-dir/`;
|
||||
|
||||
public withTemporaryDirectoryResult(directory: string): this {
|
||||
this.temporaryDirectory = directory;
|
||||
public withUserDirectoryResult(directory: string): this {
|
||||
this.userDataDirectory = directory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public getTempDirectory(): string {
|
||||
public getUserDataDirectory(): string {
|
||||
this.registerMethodCall({
|
||||
methodName: 'getTempDirectory',
|
||||
methodName: 'getUserDataDirectory',
|
||||
args: [],
|
||||
});
|
||||
return this.temporaryDirectory;
|
||||
return this.userDataDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
14
tests/unit/shared/Stubs/ScriptDirectoryProviderStub.ts
Normal file
14
tests/unit/shared/Stubs/ScriptDirectoryProviderStub.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { ScriptDirectoryProvider } from '@/infrastructure/CodeRunner/Creation/Directory/ScriptDirectoryProvider';
|
||||
|
||||
export class ScriptDirectoryProviderStub implements ScriptDirectoryProvider {
|
||||
private directoryPath = `[${ScriptDirectoryProviderStub.name}]scriptDirectory`;
|
||||
|
||||
public withDirectoryPath(directoryPath: string): this {
|
||||
this.directoryPath = directoryPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public provideScriptDirectory(): Promise<string> {
|
||||
return Promise.resolve(this.directoryPath);
|
||||
}
|
||||
}
|
||||
21
tests/unit/shared/Stubs/ScriptFileCreatorStub.ts
Normal file
21
tests/unit/shared/Stubs/ScriptFileCreatorStub.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ScriptFileCreator } from '@/infrastructure/CodeRunner/Creation/ScriptFileCreator';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export class ScriptFileCreatorStub
|
||||
extends StubWithObservableMethodCalls<ScriptFileCreator>
|
||||
implements ScriptFileCreator {
|
||||
private createdFilePath = `[${ScriptFileCreatorStub.name}]scriptFilePath`;
|
||||
|
||||
public withCreatedFilePath(path: string): this {
|
||||
this.createdFilePath = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public createScriptFile(contents: string): Promise<string> {
|
||||
this.registerMethodCall({
|
||||
methodName: 'createScriptFile',
|
||||
args: [contents],
|
||||
});
|
||||
return Promise.resolve(this.createdFilePath);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
OperatingSystemOps,
|
||||
LocationOps,
|
||||
SystemOperations,
|
||||
} from '@/infrastructure/CodeRunner/SystemOperations/SystemOperations';
|
||||
} from '@/infrastructure/CodeRunner/System/SystemOperations';
|
||||
import { CommandOpsStub } from './CommandOpsStub';
|
||||
import { FileSystemOpsStub } from './FileSystemOpsStub';
|
||||
import { LocationOpsStub } from './LocationOpsStub';
|
||||
|
||||
Reference in New Issue
Block a user