mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
test(setup): share Cursor conflict fixtures (#17032)
This commit is contained in:
@@ -70,6 +70,14 @@ import { configureClientConfiguration } from "../../src/application/SetupClientC
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { supportedClientRegistrationProfile } from "../fixtures/clientRegistrationProfile.js";
|
||||
|
||||
const cursorClient = (path: string) =>
|
||||
({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}) as const;
|
||||
|
||||
afterEach(() => {
|
||||
writers.before = undefined;
|
||||
writers.after = undefined;
|
||||
@@ -85,14 +93,10 @@ it("reports a conflict when a file changes while the freshness snapshot is being
|
||||
writers.duringRead = () => writeFile(target, changed);
|
||||
};
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await configureClientConfiguration(cursorClient(path))).toMatchObject({
|
||||
status: "failed",
|
||||
reason: "conflict",
|
||||
});
|
||||
expect(await readFile(path, "utf8")).toBe(changed);
|
||||
});
|
||||
|
||||
@@ -109,12 +113,7 @@ it.each(["before", "after"] as const)(
|
||||
writers[phase] = (target) => writeFile(target, changed);
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
await configureClientConfiguration(cursorClient(path)),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(Buffer.compare(await readFile(path), changed)).toBe(0);
|
||||
expect(await readFile(`${path}.rea.backup`, "utf8")).toBe(original);
|
||||
@@ -135,12 +134,7 @@ it("preserves an unrelated concurrent edit when a matching recovery backup alrea
|
||||
await writeFile(`${path}.rea.backup`, original);
|
||||
writers.before = (target) => writeFile(target, changed);
|
||||
|
||||
const result = await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
});
|
||||
const result = await configureClientConfiguration(cursorClient(path));
|
||||
|
||||
expect(result).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await readFile(path, "utf8")).toBe(changed);
|
||||
@@ -150,12 +144,7 @@ it("preserves an unrelated concurrent edit when a matching recovery backup alrea
|
||||
"config.json.rea.backup",
|
||||
]);
|
||||
writers.before = undefined;
|
||||
const retry = await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
});
|
||||
const retry = await configureClientConfiguration(cursorClient(path));
|
||||
expect(retry.status).toBe("configured");
|
||||
if (retry.status !== "configured" || retry.backupPath === undefined)
|
||||
throw new Error("Retry did not preserve its current recovery snapshot");
|
||||
@@ -164,14 +153,9 @@ it("preserves an unrelated concurrent edit when a matching recovery backup alrea
|
||||
theme: "light",
|
||||
mcpServers: { other: { command: "other" } },
|
||||
});
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
).toEqual({ status: "unchanged" });
|
||||
expect(await configureClientConfiguration(cursorClient(path))).toEqual({
|
||||
status: "unchanged",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not recreate a configuration deleted during setup", async () => {
|
||||
@@ -180,14 +164,10 @@ it("does not recreate a configuration deleted during setup", async () => {
|
||||
await writeFile(path, "{}\n");
|
||||
writers.before = (target) => rm(target);
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await configureClientConfiguration(cursorClient(path))).toMatchObject({
|
||||
status: "failed",
|
||||
reason: "conflict",
|
||||
});
|
||||
await expect(lstat(path)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
@@ -198,14 +178,10 @@ it("preserves an external edit made after the atomic write without rolling it ba
|
||||
await writeFile(path, "{}\n");
|
||||
writers.after = (target) => writeFile(target, changed);
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await configureClientConfiguration(cursorClient(path))).toMatchObject({
|
||||
status: "failed",
|
||||
reason: "conflict",
|
||||
});
|
||||
expect(await readFile(path, "utf8")).toBe(changed);
|
||||
});
|
||||
|
||||
@@ -220,14 +196,10 @@ it("does not adopt another writer's replacement merely because its bytes match",
|
||||
await rename(replacement, target);
|
||||
};
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await configureClientConfiguration(cursorClient(path))).toMatchObject({
|
||||
status: "failed",
|
||||
reason: "conflict",
|
||||
});
|
||||
expect((await lstat(path)).ino).toBe(replacementInode);
|
||||
});
|
||||
|
||||
@@ -242,14 +214,10 @@ it("detects a replacement of the original file even when its contents are identi
|
||||
replacementInode = (await lstat(replacement)).ino;
|
||||
await rename(replacement, target);
|
||||
};
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await configureClientConfiguration(cursorClient(path))).toMatchObject({
|
||||
status: "failed",
|
||||
reason: "conflict",
|
||||
});
|
||||
expect((await lstat(path)).ino).toBe(replacementInode);
|
||||
expect(await readFile(path, "utf8")).toBe("{}\n");
|
||||
});
|
||||
@@ -270,12 +238,7 @@ it.skipIf(process.platform === "win32")(
|
||||
};
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
await configureClientConfiguration(cursorClient(path)),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await readFile(first, "utf8")).toBe("{}\n");
|
||||
expect(await readFile(second, "utf8")).toBe('{"external":true}\n');
|
||||
@@ -285,12 +248,7 @@ it.skipIf(process.platform === "win32")(
|
||||
it("merges queued setup requests through absolute and relative paths to the same file", async () => {
|
||||
const root = await createTestTempDirectory("rea-config-queued-");
|
||||
const path = join(root, "config.json");
|
||||
const client = {
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
} as const;
|
||||
const client = cursorClient(path);
|
||||
const callerDirectory = process.cwd();
|
||||
process.chdir(root);
|
||||
try {
|
||||
@@ -348,27 +306,15 @@ it.skipIf(process.platform === "win32")(
|
||||
},
|
||||
);
|
||||
|
||||
const first = configureClientConfiguration(
|
||||
{
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: realPath,
|
||||
format: "json",
|
||||
},
|
||||
{ FIRST: "1" },
|
||||
);
|
||||
const first = configureClientConfiguration(cursorClient(realPath), {
|
||||
FIRST: "1",
|
||||
});
|
||||
let second: ReturnType<typeof configureClientConfiguration> | undefined;
|
||||
try {
|
||||
await writer.reached(first, "setup configuration writer");
|
||||
second = configureClientConfiguration(
|
||||
{
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: aliasPath,
|
||||
format: "json",
|
||||
},
|
||||
{ SECOND: "2" },
|
||||
);
|
||||
second = configureClientConfiguration(cursorClient(aliasPath), {
|
||||
SECOND: "2",
|
||||
});
|
||||
await expect(
|
||||
queued.reached(second, "second configuration transaction"),
|
||||
).resolves.toBe(realPath);
|
||||
@@ -405,12 +351,7 @@ it.skipIf(process.platform === "win32")(
|
||||
writers.before = (target) => chmod(target, 0o640);
|
||||
|
||||
expect(
|
||||
await configureClientConfiguration({
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
}),
|
||||
await configureClientConfiguration(cursorClient(path)),
|
||||
).toMatchObject({ status: "failed", reason: "conflict" });
|
||||
expect(await readFile(path, "utf8")).toBe(original);
|
||||
expect((await lstat(path)).mode & 0o777).toBe(0o640);
|
||||
@@ -421,12 +362,7 @@ it.skipIf(process.platform === "win32")(
|
||||
it("releases a failed setup transaction so a queued request can configure the file", async () => {
|
||||
const root = await createTestTempDirectory("rea-config-queued-failure-");
|
||||
const path = join(root, "config.json");
|
||||
const client = {
|
||||
name: "cursor",
|
||||
registrationProfile: supportedClientRegistrationProfile("cursor"),
|
||||
configPath: path,
|
||||
format: "json",
|
||||
} as const;
|
||||
const client = cursorClient(path);
|
||||
const writer = phaseGate();
|
||||
writers.before = async () => {
|
||||
writers.before = undefined;
|
||||
|
||||
Reference in New Issue
Block a user