Skip to content

Commit ce081b8

Browse files
feat(server): detect colocated jj repositories before git
Co-authored-by: Omar Shaarawi <[email protected]>
1 parent 19d7a9e commit ce081b8

38 files changed

Lines changed: 2446 additions & 409 deletions

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import { UsageLimitRecoveryCard } from "./UsageLimitRecoveryCard";
1111
import { AppText as Text } from "../../components/ui/AppText";
1212
import { useThreadSelection } from "../../state/use-thread-selection";
1313
import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree";
14-
import { selectTerminology, selectUnsupportedReason, vcsEnvironment } from "../../state/vcs";
14+
import {
15+
selectNotice,
16+
selectTerminology,
17+
selectUnsupportedReason,
18+
vcsEnvironment,
19+
} from "../../state/vcs";
1520
import { useNavigation } from "@react-navigation/native";
1621
import type { WorktreeSetupCardProps } from "./worktree-setup-card";
1722
import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types";
@@ -435,6 +440,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
435440
});
436441
const vcsTerminology = useEnvironmentQuerySelector(vcsStatusAtom, selectTerminology);
437442
const vcsUnsupportedReason = useEnvironmentQuerySelector(vcsStatusAtom, selectUnsupportedReason);
443+
const vcsNotice = useEnvironmentQuerySelector(vcsStatusAtom, selectNotice);
438444
const isKeyboardVisible = useKeyboardState((state) => state.isVisible);
439445
const liveKeyboardHeight = useKeyboardState((state) => state.height);
440446
// Android can swallow the IME hide callbacks when the app is backgrounded mid keyboard-hide
@@ -1048,6 +1054,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
10481054
selectedThread={props.selectedThread}
10491055
showContent={showContent}
10501056
/>
1057+
{vcsNotice ? (
1058+
<Text className="border-b border-border bg-card px-4 py-3 text-sm text-muted-foreground">
1059+
{vcsNotice}
1060+
</Text>
1061+
) : null}
10511062
{vcsUnsupportedReason ? (
10521063
<Text
10531064
accessibilityRole="alert"

‎apps/mobile/src/features/threads/git/GitOverviewSheet.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
264264
) : undefined
265265
}
266266
>
267+
{gitStatus.data?.vcs?.kind === "git" ? (
268+
<Text className="text-muted-foreground">{gitStatus.data.vcs.notice}</Text>
269+
) : null}
267270
{vcsUnsupportedReason ? (
268271
<Text accessibilityRole="alert" className="text-warning-foreground">
269272
{vcsUnsupportedReason}

‎apps/mobile/src/state/vcs.render.test.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ it.each(["ThreadDetailScreen", "ReviewSheet"] as const)(
539539
expect.objectContaining({ vcsKind: null, enabled: true }),
540540
);
541541
}
542+
if (screen === "ThreadDetailScreen") {
543+
const notice = "Jujutsu could not run: Config error: invalid configuration";
544+
await publish(AsyncResult.success({ ...gitStatus, vcs: { kind: "git", notice } }), 1);
545+
expect(container.textContent).toContain(notice);
546+
await publish(AsyncResult.success(gitStatus), 1);
547+
expect(container.textContent).not.toContain(notice);
548+
}
542549
} finally {
543550
await act(() => root.unmount());
544551
registry.dispose();

‎apps/mobile/src/state/vcs.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const selectUnsupportedReason = (
2525
) => resolveVcsUnsupportedReason(Option.getOrNull(AsyncResult.value(result)));
2626
export const selectKind = (result: AsyncResult.AsyncResult<VcsStatusLocalResult, unknown>) =>
2727
Option.getOrNull(AsyncResult.value(result))?.vcs?.kind ?? null;
28+
export const selectNotice = (result: AsyncResult.AsyncResult<VcsStatusLocalResult, unknown>) => {
29+
const vcs = Option.getOrNull(AsyncResult.value(result))?.vcs;
30+
return vcs?.kind === "git" ? (vcs.notice ?? null) : null;
31+
};
2832

2933
/** Terminology readers use local status so they never keep remote polling alive. */
3034
export function useVcsTerminology(
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// @effect-diagnostics nodeBuiltinImport:off
2+
import * as NodePath from "node:path";
3+
import * as NodeServices from "@effect/platform-node/NodeServices";
4+
import { it } from "@effect/vitest";
5+
import { CheckpointRef } from "@t3tools/contracts";
6+
import * as Effect from "effect/Effect";
7+
import * as FileSystem from "effect/FileSystem";
8+
import * as Layer from "effect/Layer";
9+
import * as PlatformError from "effect/PlatformError";
10+
import * as Scope from "effect/Scope";
11+
import { expect } from "vite-plus/test";
12+
import * as CheckpointStore from "./CheckpointStore.ts";
13+
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
14+
import * as VcsProcess from "../vcs/VcsProcess.ts";
15+
import { createJjRepo, describeJj, runGit, runJj } from "../vcs/testing/JjTestSupport.ts";
16+
import * as ServerConfig from "../config.ts";
17+
18+
const layerServerConfig = ServerConfig.ServerConfig.layerTest(process.cwd(), {
19+
prefix: "t3-checkpoint-store-test-",
20+
});
21+
const layerVcsProcessTest = VcsProcess.layer.pipe(Layer.provide(NodeServices.layer));
22+
const layerVcsDriverTest = VcsDriverRegistry.layer.pipe(Layer.provide(layerVcsProcessTest));
23+
const layerCheckpointStoreTest = CheckpointStore.layer.pipe(
24+
Layer.provideMerge(layerVcsDriverTest),
25+
Layer.provideMerge(NodeServices.layer),
26+
);
27+
const layerTest = layerCheckpointStoreTest.pipe(
28+
Layer.provideMerge(layerVcsProcessTest),
29+
Layer.provideMerge(layerVcsDriverTest),
30+
Layer.provideMerge(layerServerConfig),
31+
Layer.provideMerge(NodeServices.layer),
32+
);
33+
34+
function makeTmpDir(
35+
prefix = "checkpoint-store-test-",
36+
): Effect.Effect<string, PlatformError.PlatformError, FileSystem.FileSystem | Scope.Scope> {
37+
return Effect.gen(function* () {
38+
const fileSystem = yield* FileSystem.FileSystem;
39+
return yield* fileSystem.makeTempDirectoryScoped({ prefix });
40+
});
41+
}
42+
43+
it.layer(layerTest)("CheckpointStore activation", (it) => {
44+
describeJj("with Jujutsu installed", () => {
45+
it.effect(
46+
"restores a Git-captured checkpoint after activation without a visible checkpoint commit",
47+
() =>
48+
Effect.gen(function* () {
49+
const cwd = yield* makeTmpDir();
50+
const fs = yield* FileSystem.FileSystem;
51+
yield* runGit(cwd, ["init", "--initial-branch=main"]);
52+
yield* runGit(cwd, ["config", "user.name", "Test"]);
53+
yield* runGit(cwd, ["config", "user.email", "[email protected]"]);
54+
const file = NodePath.join(cwd, "tracked.txt");
55+
yield* fs.writeFileString(file, "initial\n");
56+
yield* runGit(cwd, ["add", "."]);
57+
yield* runGit(cwd, ["commit", "-m", "initial"]);
58+
const head = (yield* runGit(cwd, ["rev-parse", "HEAD"])).trim();
59+
yield* fs.writeFileString(file, "captured\n");
60+
const store = yield* CheckpointStore.CheckpointStore;
61+
const checkpointRef = CheckpointRef.make("refs/t3/checkpoints/activation/0");
62+
yield* store.captureCheckpoint({ cwd, checkpointRef });
63+
const captured = (yield* runGit(cwd, ["rev-parse", checkpointRef])).trim();
64+
yield* createJjRepo(cwd);
65+
yield* fs.writeFileString(file, "later\n");
66+
yield* store.restoreCheckpoint({ cwd, checkpointRef });
67+
expect(yield* fs.readFileString(file)).toBe("captured\n");
68+
expect((yield* runGit(cwd, ["rev-parse", "refs/heads/main"])).trim()).toBe(head);
69+
const visible = yield* runJj(cwd, [
70+
"log",
71+
"--no-graph",
72+
"-r",
73+
"all()",
74+
"-T",
75+
'commit_id ++ "\\n"',
76+
]);
77+
expect(visible).not.toContain(captured);
78+
}),
79+
);
80+
it.effect("returns true for a colocated Jujutsu repository", () =>
81+
Effect.gen(function* () {
82+
const tmp = yield* makeTmpDir();
83+
yield* createJjRepo(tmp);
84+
const checkpointStore = yield* CheckpointStore.CheckpointStore;
85+
expect(yield* checkpointStore.supportsCheckpoints(tmp)).toBe(true);
86+
}),
87+
);
88+
it.effect("returns false for a Jujutsu repository with no colocated Git store", () =>
89+
Effect.gen(function* () {
90+
const fileSystem = yield* FileSystem.FileSystem;
91+
const base = yield* makeTmpDir();
92+
const store = NodePath.join(base, "store.git");
93+
const root = NodePath.join(base, "project");
94+
yield* fileSystem.makeDirectory(store, { recursive: true });
95+
yield* fileSystem.makeDirectory(root, { recursive: true });
96+
yield* runGit(store, ["init", "--bare", "--initial-branch=main", store]);
97+
yield* runJj(root, ["git", "init", "--git-repo", store]);
98+
const checkpointStore = yield* CheckpointStore.CheckpointStore;
99+
expect(yield* checkpointStore.supportsCheckpoints(root)).toBe(false);
100+
}),
101+
);
102+
});
103+
});

‎apps/server/src/git/GitWorkflowService.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,51 @@ describe("GitWorkflowService", () => {
590590
);
591591
}
592592

593+
it.effect(
594+
"preserves Git results and attaches an informational fallback notice to both status shapes",
595+
() => {
596+
const local = {
597+
isRepo: true,
598+
hasPrimaryRemote: true,
599+
isDefaultRef: true,
600+
refName: "main",
601+
hasWorkingTreeChanges: false,
602+
workingTree: { files: [], insertions: 0, deletions: 0 },
603+
};
604+
const full = {
605+
...local,
606+
hasUpstream: false,
607+
aheadCount: 0,
608+
behindCount: 0,
609+
aheadOfDefaultCount: 0,
610+
pr: null,
611+
};
612+
const vcs = {
613+
kind: "git" as const,
614+
notice:
615+
"Jujutsu was not found on the server’s PATH. Using Git for this colocated repository.",
616+
};
617+
const detect = vi.fn(() => Effect.succeed({ ...handleFor("git"), notice: vcs.notice }));
618+
return Effect.gen(function* () {
619+
const workflow = yield* GitWorkflowService.GitWorkflowService;
620+
assert.deepStrictEqual(yield* workflow.localStatus({ cwd: "/repo" }), { ...local, vcs });
621+
expect(detect).toHaveBeenCalledExactlyOnceWith({ cwd: "/repo" });
622+
detect.mockClear();
623+
assert.deepStrictEqual(yield* workflow.status({ cwd: "/repo" }), { ...full, vcs });
624+
expect(detect).toHaveBeenCalledExactlyOnceWith({ cwd: "/repo" });
625+
}).pipe(
626+
Effect.provide(
627+
makeLayer({
628+
detect,
629+
gitManager: {
630+
localStatus: () => Effect.succeed(local),
631+
status: () => Effect.succeed(full),
632+
},
633+
}),
634+
),
635+
);
636+
},
637+
);
593638
it.effect("returns an empty local status when no VCS repository is detected", () =>
594639
Effect.gen(function* () {
595640
const workflow = yield* GitWorkflowService.GitWorkflowService;

‎apps/server/src/git/GitWorkflowService.ts‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,30 @@ export const make = Effect.gen(function* () {
477477
.pipe(Effect.map((result) => result.stdout.trim().length > 0)),
478478
jj: jjWorkflow.hasRefNamed,
479479
})(input),
480-
status: routeOr(
481-
"GitWorkflowService.status",
482-
statusRouting,
483-
() => Effect.succeed(nonRepositoryStatus()),
484-
{ git: gitManager.status, jj: jjWorkflow.status },
485-
),
486-
localStatus: routeOr(
487-
"GitWorkflowService.localStatus",
488-
statusRouting,
489-
() => Effect.succeed(nonRepositoryLocalStatus()),
490-
{ git: gitManager.localStatus, jj: jjWorkflow.localStatus },
491-
),
480+
status: (input) =>
481+
Effect.gen(function* () {
482+
const handle = yield* registry
483+
.detect({ cwd: input.cwd })
484+
.pipe(undetectableWorkflow("GitWorkflowService.status", input.cwd, true));
485+
if (handle === null || handle.kind === "unknown") return nonRepositoryStatus();
486+
if (handle.kind === "jj") return yield* jjWorkflow.status(input);
487+
const result = yield* gitManager.status(input);
488+
return handle.notice
489+
? { ...result, vcs: { kind: "git" as const, notice: handle.notice } }
490+
: result;
491+
}),
492+
localStatus: (input) =>
493+
Effect.gen(function* () {
494+
const handle = yield* registry
495+
.detect({ cwd: input.cwd })
496+
.pipe(undetectableWorkflow("GitWorkflowService.localStatus", input.cwd, true));
497+
if (handle === null || handle.kind === "unknown") return nonRepositoryLocalStatus();
498+
if (handle.kind === "jj") return yield* jjWorkflow.localStatus(input);
499+
const result = yield* gitManager.localStatus(input);
500+
return handle.notice
501+
? { ...result, vcs: { kind: "git" as const, notice: handle.notice } }
502+
: result;
503+
}),
492504
remoteStatus: (input, options) =>
493505
routeOr("GitWorkflowService.remoteStatus", statusRouting, () => Effect.succeed(null), {
494506
git: (statusInput: VcsStatusInput) => gitManager.remoteStatus(statusInput, options),

‎apps/server/src/jj/JjStatus.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ describeJj("JjStatus.localStatus", () => {
113113
),
114114
);
115115

116-
117116
it.effect("returns orphan-history status without optional branch totals", () =>
118117
withRepo({}, ({ root, status, fileSystem, path }) =>
119118
Effect.gen(function* () {
@@ -375,7 +374,10 @@ describeJj("JjStatus.localStatus", () => {
375374
const local = yield* status.localStatus({ cwd: root });
376375

377376
assert.equal(local.vcs?.kind, "jj");
378-
assert.include(local.vcs?.unsupportedReason ?? "", "colocated Jujutsu repositories");
377+
assert.include(
378+
local.vcs?.kind === "jj" ? (local.vcs.unsupportedReason ?? "") : "",
379+
"colocated Jujutsu repositories",
380+
);
379381
assert.equal(local.refName, null);
380382
assert.equal(local.hasWorkingTreeChanges, false);
381383
}),

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,17 @@ import * as OrchestratorMcpService from "../mcp/OrchestratorMcpService.ts";
6565
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
6666
import * as JjVcsDriver from "../vcs/JjVcsDriver.ts";
6767
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
68+
import * as VcsProcess from "../vcs/VcsProcess.ts";
6869
import * as GitManager from "../git/GitManager.ts";
70+
import * as JjStatus from "../jj/JjStatus.ts";
6971
import * as JjWorkflow from "../jj/JjWorkflow.ts";
70-
import { describeJj, runGit, runJj, withJjRepo } from "../vcs/testing/JjTestSupport.ts";
72+
import {
73+
describeJj,
74+
runGit,
75+
runJj,
76+
stubSourceControlProviders,
77+
withJjRepo,
78+
} from "../vcs/testing/JjTestSupport.ts";
7179
import { threadLaunchErrorForWire } from "../ws.ts";
7280
import * as ThreadManagement from "./ThreadManagementService.ts";
7381
import * as ThreadTitleRegeneration from "./ThreadTitleRegenerationService.ts";
@@ -427,6 +435,80 @@ describeJj("unsupported Jujutsu draft launches", () => {
427435
);
428436
});
429437

438+
describeJj("broken pinned Jujutsu draft launches", () => {
439+
it.effect("preserves the real jj refusal through the client JSON codec and status", () =>
440+
withJjRepo({ prefix: "t3-jj-pinned-refusal-", seed: true }, (repo) =>
441+
Effect.gen(function* () {
442+
yield* repo.fileSystem.makeDirectory(repo.path.join(repo.root, ".t3code"));
443+
yield* repo.fileSystem.writeFileString(
444+
repo.path.join(repo.root, ".t3code", "vcs.json"),
445+
JSON.stringify({ vcs: { kind: "jj" } }),
446+
);
447+
yield* repo.fileSystem.writeFileString(
448+
repo.path.join(repo.root, ".jj", "repo", "config.toml"),
449+
"[ui\n",
450+
);
451+
const status = yield* JjStatus.makeJjStatus({
452+
driver: repo.driver,
453+
process: repo.process,
454+
gitManager: yield* GitManager.GitManager.pipe(
455+
Effect.provide(Layer.mock(GitManager.GitManager)({})),
456+
),
457+
sourceControlProviders: yield* stubSourceControlProviders,
458+
});
459+
const workflow = yield* GitWorkflow.GitWorkflowService.pipe(
460+
Effect.provide(
461+
GitWorkflow.layer.pipe(
462+
Layer.provide(VcsDriverRegistry.layer),
463+
Layer.provide(Layer.succeed(JjVcsDriver.JjVcsDriver, repo.driver)),
464+
Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
465+
Layer.provide(Layer.mock(GitManager.GitManager)({})),
466+
Layer.provide(Layer.mock(JjWorkflow.JjWorkflow)({ localStatus: status.localStatus })),
467+
Layer.provide(Layer.succeed(VcsProcess.VcsProcess, repo.process)),
468+
Layer.provide(NodeServices.layer),
469+
),
470+
),
471+
);
472+
const harness = makeHarness({
473+
workspaceRoot: repo.root,
474+
git: { providerCwd: workflow.providerCwd },
475+
});
476+
yield* Effect.gen(function* () {
477+
const launches = yield* ThreadLaunch.ThreadLaunchService;
478+
const result = yield* launches
479+
.launch(launchInput({ command: "broken-jj", thread: "broken-jj", message: "hello" }))
480+
.pipe(Effect.result);
481+
assert.isTrue(Result.isFailure(result));
482+
if (Result.isFailure(result) && result.failure._tag === "ThreadLaunchError") {
483+
const codec = Schema.toCodecJson(OrchestrationV2ThreadLaunchError);
484+
const encoded = yield* Schema.encodeEffect(codec)(
485+
threadLaunchErrorForWire(result.failure),
486+
);
487+
const decoded = yield* Schema.decodeUnknownEffect(codec)(
488+
JSON.parse(JSON.stringify(encoded)),
489+
);
490+
assert.include(decoded.message, "Jujutsu could not run: Config error:");
491+
assert.notInclude(decoded.message, "\n");
492+
} else {
493+
assert.fail("Expected a thread launch refusal");
494+
}
495+
const threads = yield* ThreadManagement.ThreadManagementService;
496+
assert.deepEqual(
497+
yield* threads.listProjectThreads({ projectId, includeSubagents: true }),
498+
[],
499+
);
500+
assert.equal(harness.createWorktree.mock.calls.length, 0);
501+
}).pipe(Effect.provide(harness.layer));
502+
const local = yield* workflow.localStatus({ cwd: repo.root });
503+
assert.equal(local.vcs?.kind, "jj");
504+
if (local.vcs?.kind === "jj") {
505+
assert.include(local.vcs.unsupportedReason, "Jujutsu could not run: Config error:");
506+
}
507+
}),
508+
),
509+
);
510+
});
511+
430512
it.effect.each(
431513
(["new", "existing"] as const).flatMap((target) =>
432514
(["user", "agent"] as const).map((createdBy) => ({ target, createdBy })),

0 commit comments

Comments
 (0)