Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions apps/server/src/vcs/VcsDriverRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ChildProcessSpawner } from "effect/process";
import * as VcsProcess from "./VcsProcess.ts";
import * as VcsProjectConfig from "./VcsProjectConfig.ts";
import * as VcsDriverRegistry from "./VcsDriverRegistry.ts";
import * as JjVcsDriver from "./JjVcsDriver.ts";
import { commitId, describeJj, runJj, seedJjRepo } from "./testing/JjTestSupport.ts";

const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({
exitCode: ChildProcessSpawner.ExitCode(0),
Expand All @@ -21,9 +23,52 @@ const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({
const normalizeGitArgs = (args: ReadonlyArray<string>): ReadonlyArray<string> =>
args[0] === "-C" && args.length >= 2 ? args.slice(2) : args;

describeJj("VcsDriverRegistry JJ cache invalidation", () => {
it.effect("refreshes registered review diffs after the JJ service invalidates repo caches", () =>
Effect.gen(function* () {
const { root } = yield* seedJjRepo({ prefix: "t3-jj-registry-cache-", withRemote: true });
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const registry = yield* VcsDriverRegistry.VcsDriverRegistry;
const jj = yield* JjVcsDriver.JjVcsDriver;
const { driver } = yield* registry.resolve({ cwd: root });
const getDiffPreview = driver.getDiffPreview;
if (!getDiffPreview || !jj.getDiffPreview) {
assert.fail("The Jujutsu driver exposes no review diff preview.");
}
yield* fileSystem.writeFileString(path.join(root, "seed.txt"), "updated\n");

const expectedFiles = [{ path: "seed.txt", previousPath: null, additions: 1, deletions: 1 }];
const before = yield* getDiffPreview({ cwd: root, baseRef: "origin/main" });
assert.deepEqual(before.sources[1]?.files, expectedFiles);

yield* runJj(root, ["git", "remote", "rename", "origin", "upstream"]);
yield* jj.invalidateRepoCaches(root);

const refreshed = yield* jj.getDiffPreview({ cwd: root, baseRef: "upstream/main" });
assert.deepEqual(refreshed.sources[1]?.files, expectedFiles);
assert.equal(refreshed.sources[1]?.baseRef, yield* commitId(root, "main@upstream"));

const after = yield* getDiffPreview({ cwd: root, baseRef: "upstream/main" });
assert.deepEqual(after.sources[1]?.files, expectedFiles);
assert.equal(after.sources[1]?.baseRef, refreshed.sources[1]?.baseRef);
assert.include(after.sources[1]?.diff ?? "", "-seed\n+updated\n");
}).pipe(
Effect.provide(
VcsDriverRegistry.layer.pipe(
Layer.provideMerge(JjVcsDriver.layer),
Layer.provide(VcsProcess.layer),
Layer.provideMerge(NodeServices.layer),
),
),
),
);
});

describe("VcsDriverRegistry", () => {
it.effect("routes directly by VCS driver kind for non-repository workflows", () => {
const layer = Layer.effect(VcsDriverRegistry.VcsDriverRegistry, VcsDriverRegistry.make).pipe(
Layer.provide(JjVcsDriver.layer),
Layer.provide(NodeServices.layer),
Layer.provide(
Layer.mock(VcsProjectConfig.VcsProjectConfig)({
Expand All @@ -48,6 +93,7 @@ describe("VcsDriverRegistry", () => {
it.effect("auto-detects a colocated workspace as jj, ahead of git, without a subprocess", () => {
let processCalls = 0;
const layer = Layer.effect(VcsDriverRegistry.VcsDriverRegistry, VcsDriverRegistry.make).pipe(
Layer.provide(JjVcsDriver.layer),
Layer.provideMerge(NodeServices.layer),
Layer.provide(
Layer.mock(VcsProjectConfig.VcsProjectConfig)({
Expand Down Expand Up @@ -87,6 +133,7 @@ describe("VcsDriverRegistry", () => {
// `rootDir`, that holds `.git` is the repository.
const makeDiskBackedLayer = (rootDir: string, calls: string[]) =>
Layer.effect(VcsDriverRegistry.VcsDriverRegistry, VcsDriverRegistry.make).pipe(
Layer.provide(JjVcsDriver.layer),
Layer.provide(NodeServices.layer),
Layer.provide(
Layer.mock(VcsProjectConfig.VcsProjectConfig)({
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/vcs/VcsDriverRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const make = Effect.gen(function* () {
const path = yield* Path.Path;
const projectConfig = yield* VcsProjectConfig.VcsProjectConfig;
const git = yield* GitVcsDriver.makeVcsDriver;
const jj = yield* JjVcsDriver.makeVcsDriver;
const jj = yield* JjVcsDriver.JjVcsDriver;
const drivers: Partial<Record<VcsDriverKind, VcsDriver.VcsDriver["Service"]>> = {
git,
jj,
Expand Down Expand Up @@ -228,5 +228,6 @@ export const make = Effect.gen(function* () {
});

export const layer = Layer.effect(VcsDriverRegistry, make).pipe(
Layer.provide(JjVcsDriver.layer),
Layer.provide(VcsProjectConfig.layer),
);
Loading