Skip to content

Commit 57eaadd

Browse files
Merge remote-tracking branch 'origin/main' into pr-25988
2 parents 48db37e + 32ecd71 commit 57eaadd

54 files changed

Lines changed: 1819 additions & 257 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/review/reviewModel.ts‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,22 @@ export function buildReviewSectionItems(input: {
534534
},
535535
);
536536

537-
const gitItems = input.gitSections.map<ReviewSectionItem>((section) => ({
538-
id: `git:${section.kind}`,
539-
kind: section.kind,
540-
title: section.title,
541-
subtitle: gitSubtitle(section),
542-
diff: section.diff,
543-
source: section,
544-
...(section.files ? { files: section.files } : {}),
545-
truncated: section.truncated,
546-
isLoading: false,
547-
}));
537+
const gitItems = input.gitSections
538+
.filter(
539+
(section): section is typeof section & { kind: ReviewSectionKind } =>
540+
section.kind !== "commit",
541+
)
542+
.map<ReviewSectionItem>((section) => ({
543+
id: `git:${section.kind}`,
544+
kind: section.kind,
545+
title: section.title,
546+
subtitle: gitSubtitle(section),
547+
diff: section.diff,
548+
source: section,
549+
...(section.files ? { files: section.files } : {}),
550+
truncated: section.truncated,
551+
isLoading: false,
552+
}));
548553
const hasChangesItem = gitItems.some((item) => item.id === CHANGES_SECTION_ID);
549554
const visibleGitItems =
550555
input.loadingGitSections && !hasChangesItem

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const RPC_REQUIRED_SCOPES = {
170170
[WS_METHODS.vcsRefreshStatus]: AuthOrchestrationReadScope,
171171
[WS_METHODS.gitResolvePullRequest]: AuthOrchestrationReadScope,
172172
[WS_METHODS.vcsListRefs]: AuthOrchestrationReadScope,
173+
[WS_METHODS.reviewGetBranchCommits]: AuthFilesystemReadScope,
173174
[WS_METHODS.reviewGetDiffPreview]: AuthFilesystemReadScope,
174175
[WS_METHODS.reviewGetDiffFileContents]: AuthFilesystemReadScope,
175176
[WS_METHODS.terminalOpen]: AuthTerminalOperateScope,

‎apps/server/src/cli/service.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ const serviceProtectCommand = Command.make("protect", {
314314
);
315315
}
316316

317+
yield* Console.log(
318+
[
319+
"Keeps T3 Code running when agents fill this machine's memory:",
320+
" - reserves memory for the T3 Code server, so the kernel takes memory from agents first",
321+
" - makes the out-of-memory killer pick agents before the server",
322+
"It adds systemd drop-in files and changes nothing else. Undo with `t3 service protect --undo`.",
323+
].join("\n"),
324+
);
317325
const names = remote.map((unit) => unit.replace(/\.service$/, "")).join(" and ");
318326
const protectRemote =
319327
remote.length > 0 &&
@@ -328,7 +336,7 @@ const serviceProtectCommand = Command.make("protect", {
328336
});
329337
yield* Console.log(
330338
[
331-
"As root, through sudo:",
339+
"Drop-ins it writes, as root through sudo:",
332340
...formatDropIns(plan.system),
333341
"As you:",
334342
...formatDropIns([plan.managerDefaults, ...plan.user]),

‎apps/server/src/cloud/serviceProtection.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Effect from "effect/Effect";
1111
import * as FileSystem from "effect/FileSystem";
1212
import * as Sink from "effect/Sink";
1313
import * as Stream from "effect/Stream";
14+
import type * as ChildProcess from "effect/process/ChildProcess";
1415
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1516

1617
import * as ProcessRunner from "../processRunner.ts";
@@ -122,13 +123,13 @@ it.each([
122123
expect(ServiceProtection.loadedRemoteAccessUnits(shown)).toEqual(expected);
123124
});
124125

125-
const fakeSudo = (exitCode: number, onRun: () => void) =>
126+
const fakeSudo = (exitCode: number, onRun: (command: ChildProcess.StandardCommand) => void) =>
126127
ChildProcessSpawner.make((command) =>
127128
Effect.gen(function* () {
128129
if (command._tag !== "StandardCommand" || command.command !== "sudo") {
129130
return yield* Effect.die("Unexpected command");
130131
}
131-
onRun();
132+
onRun(command);
132133
return ChildProcessSpawner.makeHandle({
133134
pid: ChildProcessSpawner.ProcessId(123),
134135
stdout: Stream.empty,
@@ -180,19 +181,21 @@ it.effect("lowers no score before the manager default is in place, and undoes in
180181
writesManagerDropIn = false,
181182
) => {
182183
let atSudo: ReturnType<typeof present> | undefined;
184+
let sudoOptions: ChildProcess.CommandOptions | undefined;
183185
return effect.pipe(
184186
Effect.provideService(
185187
ChildProcessSpawner.ChildProcessSpawner,
186-
fakeSudo(exitCode, () => {
188+
fakeSudo(exitCode, (command) => {
187189
atSudo = present();
190+
sudoOptions = command.options;
188191
if (writesManagerDropIn) {
189192
NodeFS.mkdirSync(NodePath.dirname(managerDropIn), { recursive: true });
190193
NodeFS.writeFileSync(managerDropIn, "[Service]\nOOMScoreAdjust=-900\n");
191194
}
192195
}),
193196
),
194197
Effect.exit,
195-
Effect.map((exit) => ({ exit, atSudo })),
198+
Effect.map((exit) => ({ exit, atSudo, sudoOptions })),
196199
);
197200
};
198201
const refused = yield* withSudo(ServiceProtection.applyProtection(plan), 1);
@@ -209,6 +212,8 @@ it.effect("lowers no score before the manager default is in place, and undoes in
209212

210213
const applied = yield* withSudo(ServiceProtection.applyProtection(plan), 0);
211214
expect(applied.atSudo).toEqual({ managerDefaults: true, user: 0 });
215+
// sudo needs the controlling terminal to ask for a password.
216+
expect(applied.sudoOptions).toMatchObject({ detached: false, stdin: "inherit" });
212217
expect(present()).toEqual({ managerDefaults: true, user: plan.user.length });
213218

214219
const removed = yield* withSudo(ServiceProtection.removeProtection(plan), 0);

‎apps/server/src/cloud/serviceProtection.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ const runPrivileged = Effect.fn("ServiceProtection.runPrivileged")(function* (sc
240240
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
241241
const exitCode = yield* spawner
242242
.exitCode(
243+
// Effect detaches children on POSIX by default; sudo then has no controlling
244+
// terminal and cannot ask for a password.
243245
ChildProcess.make("sudo", ["/bin/sh", "-c", script], {
246+
detached: false,
244247
stdin: "inherit",
245248
stdout: "inherit",
246249
stderr: "inherit",

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const RPC_AGGREGATES = {
181181
[WS_METHODS.vcsCreateRef]: "vcs",
182182
[WS_METHODS.vcsSwitchRef]: "vcs",
183183
[WS_METHODS.vcsInit]: "vcs",
184+
[WS_METHODS.reviewGetBranchCommits]: "review",
184185
[WS_METHODS.reviewGetDiffPreview]: "review",
185186
[WS_METHODS.reviewGetDiffFileContents]: "review",
186187
[WS_METHODS.terminalOpen]: "terminal",

‎apps/server/src/review/ReviewService.ts‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as Path from "effect/Path";
88
import {
99
VcsRepositoryDetectionError,
1010
VcsUnsupportedOperationError,
11+
type ReviewBranchCommitsInput,
12+
type ReviewBranchCommitsResult,
1113
type ReviewDiffFileContentsInput,
1214
type ReviewDiffFileContentsResult,
1315
type ReviewDiffPreviewError,
@@ -20,9 +22,18 @@ import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
2022
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
2123
import * as KnownWorkspaces from "../workspace/KnownWorkspaces.ts";
2224

25+
const WORKSPACE_BOUND_SUBJECTS = {
26+
"ReviewService.getBranchCommits": "commit list",
27+
"ReviewService.getDiffPreview": "diff preview",
28+
"ReviewService.getDiffFileContents": "diff file contents",
29+
} as const;
30+
2331
export class ReviewService extends Context.Service<
2432
ReviewService,
2533
{
34+
readonly getBranchCommits: (
35+
input: ReviewBranchCommitsInput,
36+
) => Effect.Effect<ReviewBranchCommitsResult, ReviewDiffPreviewError>;
2637
readonly getDiffPreview: (
2738
input: ReviewDiffPreviewInput,
2839
) => Effect.Effect<ReviewDiffPreviewResult, ReviewDiffPreviewError>;
@@ -61,7 +72,7 @@ export const make = Effect.gen(function* () {
6172
};
6273

6374
const assertWorkspaceBoundCwd = Effect.fn("ReviewService.assertWorkspaceBoundCwd")(function* (
64-
operation: "ReviewService.getDiffPreview" | "ReviewService.getDiffFileContents",
75+
operation: keyof typeof WORKSPACE_BOUND_SUBJECTS,
6576
cwd: string,
6677
) {
6778
const [candidate, workspaceRoot] = yield* Effect.all([
@@ -78,13 +89,27 @@ export const make = Effect.gen(function* () {
7889
return yield* new VcsRepositoryDetectionError({
7990
operation,
8091
cwd,
81-
detail:
82-
operation === "ReviewService.getDiffPreview"
83-
? "Review diff preview cwd must stay within the configured workspace root."
84-
: "Review diff file contents cwd must stay within the configured workspace root.",
92+
detail: `Review ${WORKSPACE_BOUND_SUBJECTS[operation]} cwd must stay within the configured workspace root.`,
8593
});
8694
});
8795

96+
const getBranchCommits: ReviewService["Service"]["getBranchCommits"] = Effect.fn(
97+
"ReviewService.getBranchCommits",
98+
)(function* (input) {
99+
yield* assertWorkspaceBoundCwd("ReviewService.getBranchCommits", input.cwd);
100+
101+
const handle = yield* vcsRegistry.detect({ cwd: input.cwd, requestedKind: "auto" });
102+
if (!handle) return { commits: [], truncated: false };
103+
if (handle.kind !== "git") {
104+
return yield* new VcsUnsupportedOperationError({
105+
operation: "ReviewService.getBranchCommits",
106+
kind: handle.kind,
107+
detail: "Review commit lists require a Git repository.",
108+
});
109+
}
110+
return yield* git.getReviewBranchCommits(input);
111+
});
112+
88113
const getDiffPreview: ReviewService["Service"]["getDiffPreview"] = Effect.fn(
89114
"ReviewService.getDiffPreview",
90115
)(function* (input) {
@@ -120,6 +145,7 @@ export const make = Effect.gen(function* () {
120145
});
121146

122147
return ReviewService.of({
148+
getBranchCommits,
123149
getDiffPreview,
124150
getDiffFileContents,
125151
});

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
type VcsCreateRefResult,
2121
type VcsCreateWorktreeInput,
2222
type VcsCreateWorktreeResult,
23+
type ReviewBranchCommitsInput,
24+
type ReviewBranchCommitsResult,
2325
type ReviewDiffPreviewInput,
2426
type ReviewDiffPreviewResult,
2527
type ReviewDiffFileContentsInput,
@@ -328,6 +330,9 @@ export class GitVcsDriver extends Context.Service<
328330
cwd: string,
329331
baseRef: string,
330332
) => Effect.Effect<GitRangeContext, GitCommandError>;
333+
readonly getReviewBranchCommits: (
334+
input: ReviewBranchCommitsInput,
335+
) => Effect.Effect<ReviewBranchCommitsResult, GitCommandError>;
331336
readonly getReviewDiffPreview: (
332337
input: ReviewDiffPreviewInput,
333338
) => Effect.Effect<ReviewDiffPreviewResult, GitCommandError>;

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @effect-diagnostics nodeBuiltinImport:off - realpathSync.native resolves Windows 8.3 short names, which the Effect realPath does not.
22
import * as NodeFS from "node:fs";
3+
import * as NodeOS from "node:os";
4+
import * as NodeURL from "node:url";
35
import * as NodeServices from "@effect/platform-node/NodeServices";
46
import * as HostProcess from "@t3tools/shared/HostProcess";
57
import { assert, it, describe } from "@effect/vitest";
@@ -1466,6 +1468,140 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
14661468
});
14671469

14681470
describe("review diff previews", () => {
1471+
it.effect("diffs a root commit against the empty tree but rejects a shallow boundary", () =>
1472+
Effect.gen(function* () {
1473+
const upstream = yield* makeTmpDir();
1474+
yield* initRepoWithCommit(upstream);
1475+
const driver = yield* GitVcsDriver.GitVcsDriver;
1476+
const emptyTree = yield* git(upstream, ["hash-object", "-t", "tree", NodeOS.devNull]);
1477+
const root = yield* git(upstream, ["rev-parse", "HEAD"]);
1478+
const rootSource = (yield* driver.getReviewDiffPreview({ cwd: upstream, commitSha: root }))
1479+
.sources[0]!;
1480+
assert.equal(rootSource.baseRef, emptyTree);
1481+
assert.include(rootSource.diff, "+# test");
1482+
1483+
yield* writeTextFile(upstream, "README.md", "# boundary\n");
1484+
yield* git(upstream, ["commit", "-am", "boundary"]);
1485+
const sha = yield* git(upstream, ["rev-parse", "HEAD"]);
1486+
const cwd = yield* makeTmpDir();
1487+
yield* git(upstream, ["clone", "--depth=1", NodeURL.pathToFileURL(upstream).href, cwd], {
1488+
GIT_CONFIG_GLOBAL: NodeOS.devNull,
1489+
GIT_CONFIG_NOSYSTEM: "1",
1490+
});
1491+
assert.equal(yield* git(cwd, ["rev-parse", "--is-shallow-repository"]), "true");
1492+
for (const request of [
1493+
driver.getReviewDiffPreview({ cwd, commitSha: sha }),
1494+
driver.getReviewDiffFileContents(
1495+
makeReviewDiffFileContentsInput(cwd, {
1496+
sourceKind: "commit",
1497+
changeType: "new",
1498+
headRef: sha,
1499+
baseRef: emptyTree,
1500+
}),
1501+
),
1502+
]) {
1503+
const error = yield* Effect.asVoid<unknown, GitCommandError, never>(request).pipe(
1504+
Effect.flip,
1505+
);
1506+
assert.include(error.detail, "parent");
1507+
}
1508+
}),
1509+
);
1510+
1511+
it.effect("lists the branch's commits newest first, at most 100, and flags the rest", () =>
1512+
Effect.gen(function* () {
1513+
const cwd = yield* makeTmpDir();
1514+
const { initialBranch } = yield* initRepoWithCommit(cwd);
1515+
const driver = yield* GitVcsDriver.GitVcsDriver;
1516+
yield* git(cwd, ["checkout", "-b", "feature/commits"]);
1517+
for (let index = 0; index < 102; index++) {
1518+
yield* git(cwd, ["commit", "--allow-empty", "-m", `feature ${index}`]);
1519+
}
1520+
1521+
const result = yield* driver.getReviewBranchCommits({ cwd, baseRef: initialBranch });
1522+
assert.strictEqual(result.truncated, true);
1523+
assert.strictEqual(result.commits.length, 100);
1524+
assert.strictEqual(result.commits[0]?.sha, yield* git(cwd, ["rev-parse", "HEAD"]));
1525+
assert.deepStrictEqual(
1526+
[result.commits[0]?.subject, result.commits[99]?.subject],
1527+
["feature 101", "feature 2"],
1528+
);
1529+
}),
1530+
);
1531+
1532+
it.effect("previews one selected commit, a merge against its first parent", () =>
1533+
Effect.gen(function* () {
1534+
const cwd = yield* makeTmpDir();
1535+
const { initialBranch } = yield* initRepoWithCommit(cwd);
1536+
const driver = yield* GitVcsDriver.GitVcsDriver;
1537+
yield* git(cwd, ["checkout", "-b", "feature/merge-preview"]);
1538+
yield* git(cwd, ["checkout", "-b", "feature/side"]);
1539+
yield* writeTextFile(cwd, "README.md", "# side commit\n");
1540+
yield* git(cwd, ["add", "README.md"]);
1541+
yield* git(cwd, ["commit", "-m", "side change"]);
1542+
yield* git(cwd, ["checkout", "feature/merge-preview"]);
1543+
yield* writeTextFile(cwd, "feature.txt", "feature commit\n");
1544+
yield* git(cwd, ["add", "feature.txt"]);
1545+
yield* git(cwd, ["commit", "-m", "feature change"]);
1546+
const firstParent = yield* git(cwd, ["rev-parse", "HEAD"]);
1547+
yield* git(cwd, ["merge", "--no-ff", "--no-edit", "feature/side"]);
1548+
const mergeSha = yield* git(cwd, ["rev-parse", "HEAD"]);
1549+
yield* git(cwd, ["checkout", "-b", "feature/elsewhere", initialBranch]);
1550+
yield* writeTextFile(cwd, "elsewhere.txt", "elsewhere\n");
1551+
yield* git(cwd, ["add", "elsewhere.txt"]);
1552+
yield* git(cwd, ["commit", "-m", "elsewhere change"]);
1553+
const elsewhereSha = yield* git(cwd, ["rev-parse", "HEAD"]);
1554+
yield* git(cwd, ["checkout", "feature/merge-preview"]);
1555+
yield* writeTextFile(cwd, "README.md", "# dirty tree\n");
1556+
1557+
const elsewhere = yield* driver.getReviewDiffPreview({ cwd, commitSha: elsewhereSha });
1558+
assert.deepStrictEqual(
1559+
elsewhere.sources
1560+
.find((candidate) => candidate.kind === "commit")
1561+
?.files?.map((file) => file.path),
1562+
["elsewhere.txt"],
1563+
);
1564+
1565+
const preview = yield* driver.getReviewDiffPreview({
1566+
cwd,
1567+
baseRef: initialBranch,
1568+
commitSha: mergeSha,
1569+
});
1570+
const source = preview.sources.find((candidate) => candidate.kind === "commit")!;
1571+
assert.strictEqual(source.baseRef, firstParent);
1572+
assert.strictEqual(source.headRef, mergeSha);
1573+
assert.deepStrictEqual(
1574+
source.files?.map((file) => file.path),
1575+
["README.md"],
1576+
);
1577+
assert.include(source.diff, "+# side commit");
1578+
assert.notInclude(source.diff, "dirty tree");
1579+
assert.notInclude(source.diff, "feature.txt");
1580+
1581+
const patch = yield* driver.getReviewDiffPreview({
1582+
cwd,
1583+
baseRef: initialBranch,
1584+
commitSha: mergeSha,
1585+
file: { path: "README.md", previousPath: null, sourceKind: "commit" },
1586+
});
1587+
assert.include(
1588+
patch.sources.find((candidate) => candidate.kind === "commit")!.diff,
1589+
"+# side commit",
1590+
);
1591+
const contents = yield* driver.getReviewDiffFileContents(
1592+
makeReviewDiffFileContentsInput(cwd, {
1593+
sourceKind: "commit",
1594+
baseRef: source.baseRef,
1595+
headRef: source.headRef,
1596+
}),
1597+
);
1598+
assert.deepStrictEqual(contents, {
1599+
oldContents: "# test\n",
1600+
newContents: "# side commit\n",
1601+
});
1602+
}),
1603+
);
1604+
14691605
it.effect("loads repository-relative files from a nested project directory", () =>
14701606
Effect.gen(function* () {
14711607
const cwd = yield* makeTmpDir();

0 commit comments

Comments
 (0)