feat(web): clone repositories in the background instead of holding the palette open (#11762)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
112a7088da
commit
8d7c700c17
28 files changed
+2206
-25
No files matched your search
@@ -178,7 +178,7 @@ it.effect("clones a looked-up repository into the requested destination", () =>
|
||||
assert.deepStrictEqual(cloneCalls, [
|
||||
{
|
||||
cwd: parent,
|
||||
args: ["clone", CLONE_URLS.url, "t3code"],
|
||||
args: ["clone", "--progress", CLONE_URLS.url, "t3code"],
|
||||
},
|
||||
]);
|
||||
}).pipe(
|
||||
@@ -197,6 +197,154 @@ it.effect("clones a looked-up repository into the requested destination", () =>
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("reports clone progress from git's stderr and keeps its error text on failure", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const parent = yield* fs.makeTempDirectoryScoped({
|
||||
prefix: "t3-source-control-clone-progress-",
|
||||
});
|
||||
const destinationPath = path.join(parent, "t3code");
|
||||
const progress: Array<{ stage: string; percent: number | null; detail: string | null }> = [];
|
||||
|
||||
const stderrLines = [
|
||||
"Cloning into 't3code'...",
|
||||
"remote: Enumerating objects: 10, done.",
|
||||
"Receiving objects: 40% (4/10), 1.00 MiB | 2.00 MiB/s",
|
||||
"Receiving objects: 100% (10/10), 2.50 MiB | 2.00 MiB/s, done.",
|
||||
"fatal: early EOF",
|
||||
"fatal: unable to access 'https://user:s3c@[email protected]/octocat/t3code.git/': could not resolve host",
|
||||
];
|
||||
const error = yield* Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
return yield* Effect.flip(
|
||||
service.cloneRepository(
|
||||
{ remoteUrl: CLONE_URLS.sshUrl, destinationPath },
|
||||
{ onProgress: (line) => Effect.sync(() => void progress.push(line)) },
|
||||
),
|
||||
);
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
makeLayer({
|
||||
git: {
|
||||
execute: (input) =>
|
||||
Effect.gen(function* () {
|
||||
for (const line of stderrLines) {
|
||||
yield* input.progress?.onStderrLine?.(line) ?? Effect.void;
|
||||
}
|
||||
return yield* new GitCommandError({
|
||||
operation: input.operation,
|
||||
command: "git",
|
||||
cwd: input.cwd,
|
||||
detail: "Git command exited with a non-zero status.",
|
||||
exitCode: 128,
|
||||
});
|
||||
}),
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(progress, [
|
||||
{ stage: "counting", percent: null, detail: null },
|
||||
{ stage: "receiving", percent: 40, detail: "1.00 MiB | 2.00 MiB/s" },
|
||||
{ stage: "receiving", percent: 100, detail: "2.50 MiB | 2.00 MiB/s" },
|
||||
]);
|
||||
// Git echoes the remote in some failures; the credentials must not follow.
|
||||
assert.strictEqual(
|
||||
error.detail,
|
||||
"fatal: early EOF fatal: unable to access 'https://github.com/octocat/t3code.git/': could not resolve host",
|
||||
);
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("strips embedded credentials from the remote URL it reports", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-redact-" });
|
||||
const destinationPath = path.join(parent, "t3code");
|
||||
const cloneArgs: Array<ReadonlyArray<string>> = [];
|
||||
const result = yield* Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
return yield* service.prepareClone({
|
||||
remoteUrl: "https://user:[email protected]/octocat/t3code.git",
|
||||
destinationPath,
|
||||
});
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
makeLayer({
|
||||
git: {
|
||||
execute: (input) =>
|
||||
Effect.sync(() => {
|
||||
cloneArgs.push(input.args);
|
||||
return processOutput();
|
||||
}),
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
assert.equal(result.remoteUrl, "https://github.com/octocat/t3code.git");
|
||||
// Git itself still receives the credentials.
|
||||
assert.equal(result.cloneUrl, "https://user:[email protected]/octocat/t3code.git");
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("discards only a directory git wrote to", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-discard-" });
|
||||
const partial = path.join(parent, "partial");
|
||||
yield* fs.makeDirectory(path.join(partial, ".git"), { recursive: true });
|
||||
yield* fs.writeFileString(path.join(partial, "README.md"), "half");
|
||||
const foreign = path.join(parent, "foreign");
|
||||
yield* fs.makeDirectory(foreign);
|
||||
yield* fs.writeFileString(path.join(foreign, "notes.txt"), "mine");
|
||||
|
||||
// A file where the directory should be must not be removed either.
|
||||
const replaced = path.join(parent, "replaced");
|
||||
yield* fs.writeFileString(replaced, "not a directory");
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
yield* service.discardClone(partial);
|
||||
const error = yield* Effect.flip(service.discardClone(foreign));
|
||||
assert.include(error.detail, "not from the clone");
|
||||
const replacedError = yield* Effect.flip(service.discardClone(replaced));
|
||||
assert.include(replacedError.detail, "could not be inspected");
|
||||
// A destination that never got created is nothing to discard.
|
||||
yield* service.discardClone(path.join(parent, "missing"));
|
||||
}).pipe(Effect.provide(makeLayer({})));
|
||||
|
||||
// The partial clone is emptied but its directory (the workspace root) stays.
|
||||
assert.deepStrictEqual(yield* fs.readDirectory(partial), []);
|
||||
assert.deepStrictEqual(yield* fs.readDirectory(foreign), ["notes.txt"]);
|
||||
assert.strictEqual(yield* fs.readFileString(replaced), "not a directory");
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("redacts query tokens and userinfo containing '@' from reported URLs", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-source-control-redact2-" });
|
||||
yield* Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
const query = yield* service.prepareClone({
|
||||
remoteUrl: "https://github.com/octocat/t3code.git?access_token=s3cret",
|
||||
destinationPath: path.join(parent, "a"),
|
||||
});
|
||||
assert.equal(query.remoteUrl, "https://github.com/octocat/t3code.git");
|
||||
const nested = yield* service.prepareClone({
|
||||
remoteUrl: "https://user:pa@[email protected]/octocat/t3code.git",
|
||||
destinationPath: path.join(parent, "b"),
|
||||
});
|
||||
assert.equal(nested.remoteUrl, "https://github.com/octocat/t3code.git");
|
||||
}).pipe(Effect.provide(makeLayer({})));
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
|
||||
it.effect("preserves destination probe failures instead of treating them as missing paths", () => {
|
||||
const fileSystemCause = PlatformError.systemError({
|
||||
_tag: "PermissionDenied",
|
||||
|
||||
Reference in new issue
Block a user