public static String replaceInternalStorage(
        RunContext runContext,
        @Nullable String command,
        boolean replaceWithRelativePath
    ) throws IOException {
        if (command == null) {
            return "";
        }

        return INTERNAL_STORAGE_PATTERN
            .matcher(command)
            .replaceAll(throwFunction(matchResult -> {
                String localFile = saveOnLocalStorage(runContext, matchResult.group()).replace("\\", "/");

                if (!replaceWithRelativePath) {
                    return localFile;
                }

                return runContext.workingDir().path().relativize(Path.of(localFile)).toString();
            }));
    }
@Test
    void replaceInternalStorage() throws IOException {
        var runContext = runContextFactory.of();
        var command  = ScriptService.replaceInternalStorage(runContext, null, false);
        assertThat(command, is(""));

        command = ScriptService.replaceInternalStorage(runContext, "my command", false);
        assertThat(command, is("my command"));

        Path path = Path.of("/tmp/unittest/file.txt");
        if (!path.toFile().exists()) {
            Files.createFile(path);
        }

        String internalStorageUri = "kestra://some/file.txt";
        File localFile = null;
        try {
            command = ScriptService.replaceInternalStorage(runContext, "my command with an internal storage file: " + internalStorageUri, false);

            Matcher matcher = COMMAND_PATTERN_CAPTURE_LOCAL_PATH.matcher(command);
            assertThat(matcher.matches(), is(true));
            Path absoluteLocalFilePath = Path.of(matcher.group(1));
            localFile = absoluteLocalFilePath.toFile();
            assertThat(localFile.exists(), is(true));

            command = ScriptService.replaceInternalStorage(runContext, "my command with an internal storage file: " + internalStorageUri, true);
            matcher = COMMAND_PATTERN_CAPTURE_LOCAL_PATH.matcher(command);
            assertThat(matcher.matches(), is(true));
            String relativePath = matcher.group(1);
            assertThat(relativePath, not(startsWith("/")));
            assertThat(runContext.workingDir().resolve(Path.of(relativePath)).toFile().exists(), is(true));
        } finally {
            localFile.delete();
            path.toFile().delete();
        }
    }