Prefer jj detection and add ignore classifier capability

- Detect jj before git for colocated repositories
- Add ignoreClassifier to VCS capabilities
- Fix trace2 hook exit code reporting
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-05-02 14:23:05 -07:00
1 parent 7cda30c710
commit 54a838531f
5 files changed
+40 -21

No files matched your search

+1
View File
@@ -3056,6 +3056,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
expect.objectContaining({
kind: "hook_finished",
hookName: "pre-commit",
exitCode: 0,
}),
expect.objectContaining({
kind: "action_finished",
+1 -1
View File
@@ -448,7 +448,7 @@ const createTrace2Monitor = Effect.fn("createTrace2Monitor")(function* (
if (event === "child_exit") {
hookStartByChildKey.delete(childKey);
const code = traceRecord.success.exitCode;
const code = traceRecord.success.code;
const exitCode = typeof code === "number" && Number.isInteger(code) ? code : null;
const now = yield* DateTime.now;
const durationMs = started
+28 -7
View File
@@ -1,10 +1,24 @@
import { Effect, FileSystem, Layer } from "effect";
import { Context, Effect, FileSystem, Layer } from "effect";
import { VcsOutputDecodeError, VcsProcessExitError } from "@t3tools/contracts";
import { VcsDriver, type VcsDriverShape } from "./VcsDriver.ts";
import { nowFreshness } from "./VcsFreshness.ts";
import { VcsProcess, type VcsProcessShape } from "./VcsProcess.ts";
export interface JjVcsDriverShape extends VcsDriverShape {
readonly capabilities: VcsDriverShape["capabilities"] & {
readonly kind: "jj";
readonly supportsBookmarks: true;
readonly supportsAtomicSnapshot: true;
readonly supportsWorktrees: false;
readonly ignoreClassifier: "git-compatible-fallback";
};
}
export class JjVcsDriver extends Context.Service<JjVcsDriver, JjVcsDriverShape>()(
"t3/vcs/JjVcsDriver",
) {}
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
const CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
@@ -137,10 +151,11 @@ export const makeVcsDriverShape = Effect.fn("makeJjVcsDriverShape")(function* ()
const fileSystem = yield* FileSystem.FileSystem;
const capabilities = {
kind: "jj" as const,
supportsWorktrees: true,
supportsBookmarks: true,
supportsAtomicSnapshot: true,
supportsPushDefaultRemote: false,
supportsWorktrees: false as const,
supportsBookmarks: true as const,
supportsAtomicSnapshot: true as const,
supportsPushDefaultRemote: false as const,
ignoreClassifier: "git-compatible-fallback" as const,
};
const isInsideWorkTree: VcsDriverShape["isInsideWorkTree"] = (cwd) =>
@@ -308,12 +323,18 @@ export const makeVcsDriverShape = Effect.fn("makeJjVcsDriverShape")(function* ()
isInsideWorkTree,
listWorkspaceFiles,
filterIgnoredPaths,
} satisfies VcsDriverShape;
} satisfies JjVcsDriverShape;
});
export const makeVcsDriver = Effect.fn("makeJjVcsDriver")(function* () {
export const makeJjVcsDriver = Effect.fn("makeJjVcsDriver")(function* () {
const driver = yield* makeVcsDriverShape();
return JjVcsDriver.of(driver);
});
export const makeVcsDriver = Effect.fn("makeJjGenericVcsDriver")(function* () {
const driver = yield* makeVcsDriverShape();
return VcsDriver.of(driver);
});
export const layer = Layer.effect(JjVcsDriver, makeJjVcsDriver());
export const vcsLayer = Layer.effect(VcsDriver, makeVcsDriver());
@@ -102,7 +102,7 @@ describe("VcsDriverRegistry", () => {
}).pipe(Effect.provide(layer));
});
it.effect("auto-detects jj after git misses", () => {
it.effect("prefers jj auto-detection before git for colocated repositories", () => {
const calls: VcsProcessInput[] = [];
const layer = Layer.effect(VcsDriverRegistry, makeVcsDriverRegistry()).pipe(
Layer.provide(
@@ -116,13 +116,13 @@ describe("VcsDriverRegistry", () => {
Effect.sync(() => {
calls.push(input);
const command = input.args.join(" ");
if (input.command === "git" && command === "rev-parse --is-inside-work-tree") {
return processOutput("", 1, "not a git repository");
}
if (input.command === "jj" && command === "--no-pager root") {
return processOutput("/repo\n");
}
return processOutput("");
if (input.command === "git") {
return processOutput("true\n");
}
return processOutput("", 1, "not found");
}),
}),
),
@@ -135,10 +135,7 @@ describe("VcsDriverRegistry", () => {
assert.equal(handle.kind, "jj");
assert.equal(handle.repository.rootPath, "/repo");
assert.deepStrictEqual(commandCalls(calls), [
["git", "rev-parse", "--is-inside-work-tree"],
["jj", "--no-pager", "root"],
]);
assert.deepStrictEqual(commandCalls(calls), [["jj", "--no-pager", "root"]]);
}).pipe(Effect.provide(layer));
});
});
+4 -4
View File
@@ -106,12 +106,12 @@ export const make = Effect.fn("makeVcsDriverRegistry")(function* () {
return yield* detectWithDriver(requestedKind, driver, input.cwd);
}
const gitDetected = yield* detectWithDriver("git", git, input.cwd);
if (gitDetected) {
return gitDetected;
const jjDetected = yield* detectWithDriver("jj", jj, input.cwd);
if (jjDetected) {
return jjDetected;
}
return yield* detectWithDriver("jj", jj, input.cwd);
return yield* detectWithDriver("git", git, input.cwd);
});
const detectionCache = yield* Cache.makeWith<string, VcsDriverHandle | null, VcsError>(