Open History to see the last commit
1import { expect } from "e2e";
2import * as Effect from "effect/Effect";
3import * as FileSystem from "effect/FileSystem";
4
5import { run } from "./shell.ts";
6import { runPromise, test, WEB } from "./t3.ts";
7
8test(
9 "An index error after recording a commit does not reuse its message",
10 WEB,
11 async ({ t3, app, screen }) => {
12 const project = await t3.project("demo");
13 const git = (...args: string[]) => runPromise(run("git", args, { cwd: project }));
14 await git("config", "user.name", "Scenario");
15 await git("config", "user.email", "scenario@example.invalid");
16 await git("config", "core.hooksPath", ".git/hooks");
17 const input = { project, title: "Partial commit", messages: ["Start"] };
18 // Replay advertises only its default until discovery publishes the named recordings.
19 const thread = await t3.thread({ ...input, model: "default" }).catch((error: unknown) => {
20 if (!String(error).includes("Model default is not advertised by provider devReplay.")) {
21 throw error;
22 }
23 return t3.thread(input);
24 });
25 await runPromise(
26 Effect.gen(function* () {
27 const fs = yield* FileSystem.FileSystem;
28 const hook = `${project}/.git/hooks/post-commit`;
29 // Hold the real index after Git has recorded the commit, before T3 syncs the selected paths.
30 yield* fs.writeFileString(
31 hook,
32 '#!/bin/sh\n: > "$(git rev-parse --absolute-git-dir)/index.lock"\n',
33 );
34 yield* fs.chmod(hook, 0o755);
35 yield* fs.writeFileString(`${project}/first.txt`, "Include now\n");
36 yield* fs.writeFileString(`${project}/later.txt`, "Include later\n");
37 }),
38 );
39
40 await t3.open(thread);
41 const openCommit = async () => {
42 await screen.getByRole("button", "Git action options").tap();
43 await screen.getByRole("menuitem", "Commit", { exact: true }).tap();
44 await screen.getByRole("button", "Open later.txt in editor").waitFor();
45 };
46 await openCommit();
47 await screen.getByRole("button", "Edit", { exact: true }).tap();
48 await screen.getByRole("checkbox", "Include later.txt").tap();
49 const message = screen.getByPlaceholder("Leave empty to auto-generate");
50 await message.fill("Commit the first file");
51 await screen.getByRole("button", "Commit", { exact: true }).tap();
52 await screen.getByText(/^Committed [0-9a-f]+$|^Action failed$/).waitFor();
53 const failure = screen.getByRole("dialog", "Action failed", { exact: true });
54 if (await failure.isVisible()) {
55 await failure.getByRole("button", "Dismiss notification", { exact: true }).tap();
56 await failure.waitFor({ state: "detached" });
57 }
58 await runPromise(
59 Effect.flatMap(FileSystem.FileSystem, (fs) =>
60 fs.remove(`${project}/.git/index.lock`, { force: true }),
61 ),
62 );
63 if ((await git("log", "-1", "--format=%s")).stdout.trim() !== "Commit the first file") {
64 throw new Error("Git did not record the first commit");
65 }
66 await openCommit();
67 await app.screenshot("message-after-commit-with-index-error");
68 expect(await message.inputValue()).toBe("");
69 },
70);