History

[codex] Enforce canonical Node namespace imports (#3238)

Julius Marminge committed 4 months ago

Commit 2fa37ec1 parent db2750271 files · +1205 −952Browse files

Showing the changes to apps/server/src/textGeneration/CursorTextGeneration.test.ts (1 of 71 files). Show all

Unified · Split

apps/server/src/textGeneration/CursorTextGeneration.test.ts+25−21
@@ -1,8 +1,8 @@
11 // @effect-diagnostics nodeBuiltinImport:off
2−import * as path from "node:path";
3−import * as os from "node:os";
4−import { fileURLToPath } from "node:url";
5−import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2+import * as NodePath from "node:path";
3+import * as NodeOS from "node:os";
4+import * as NodeURL from "node:url";
5+import * as NodeFS from "node:fs";
66
77 import * as NodeServices from "@effect/platform-node/NodeServices";
88 import { it } from "@effect/vitest";
@@ -21,8 +21,8 @@ import * as TextGeneration from "./TextGeneration.ts"; · 12 unmodified lines
2121 import { makeCursorTextGeneration } from "./CursorTextGeneration.ts";
2222 const decodeCursorSettings = Schema.decodeSync(CursorSettings);
2323
24−const __dirname = path.dirname(fileURLToPath(import.meta.url));
25−const mockAgentPath = path.join(__dirname, "../../scripts/acp-mock-agent.ts");
24+const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
25+const mockAgentPath = NodePath.join(__dirname, "../../scripts/acp-mock-agent.ts");
2626
2727 function shellSingleQuote(value: string): string {
2828 return `'${value.replaceAll("'", `'"'"'`)}'`;
@@ -33,10 +33,10 @@ const CursorTextGenerationTestLayer = ServerConfig.ServerConfig.layerTest(proces · 4 unmodified lines
3333 }).pipe(Layer.provideMerge(NodeServices.layer));
3434
3535 function makeAcpAgentWrapper(dir: string, env: Record<string, string>): string {
36− const binDir = path.join(dir, "bin");
37− const agentPath = path.join(binDir, "agent");
38− mkdirSync(binDir, { recursive: true });
39− writeFileSync(
36+ const binDir = NodePath.join(dir, "bin");
37+ const agentPath = NodePath.join(binDir, "agent");
38+ NodeFS.mkdirSync(binDir, { recursive: true });
39+ NodeFS.writeFileSync(
4040 agentPath,
4141 [
4242 "#!/bin/sh",
@@ -50,7 +50,7 @@ function makeAcpAgentWrapper(dir: string, env: Record<string, string>): string { · 7 unmodified lines
5050 ].join("\n"),
5151 "utf8",
5252 );
53− chmodSync(agentPath, 0o755);
53+ NodeFS.chmodSync(agentPath, 0o755);
5454 return agentPath;
5555 }
5656
@@ -59,10 +59,10 @@ function withFakeAcpAgent<A, E, R>( · 2 unmodified lines
5959 effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,
6060 ) {
6161 return Effect.gen(function* () {
62− const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3code-cursor-text-acp-"));
62+ const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3code-cursor-text-acp-"));
6363 yield* Effect.addFinalizer(() =>
6464 Effect.sync(() => {
65− rmSync(tempDir, { recursive: true, force: true });
65+ NodeFS.rmSync(tempDir, { recursive: true, force: true });
6666 }),
6767 );
6868 const agentPath = makeAcpAgentWrapper(tempDir, env);
@@ -76,7 +76,7 @@ function waitForFileContent(path: string): Effect.Effect<string> { · 7 unmodified lines
7676 return Effect.gen(function* () {
7777 const deadline = (yield* Clock.currentTimeMillis) + 5_000;
7878 for (;;) {
79− const result = yield* Effect.exit(Effect.sync(() => readFileSync(path, "utf8")));
79+ const result = yield* Effect.exit(Effect.sync(() => NodeFS.readFileSync(path, "utf8")));
8080 if (Exit.isSuccess(result)) {
8181 return result.value;
8282 }
@@ -92,8 +92,10 @@ function waitForFileContent(path: string): Effect.Effect<string> { · 9 unmodified lines
9292
9393 it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => {
9494 it.effect("uses ACP model config options instead of raw CLI model ids", () => {
95− const requestLogDir = mkdtempSync(path.join(os.tmpdir(), "t3code-cursor-text-log-"));
96− const requestLogPath = path.join(requestLogDir, "requests.ndjson");
95+ const requestLogDir = NodeFS.mkdtempSync(
96+ NodePath.join(NodeOS.tmpdir(), "t3code-cursor-text-log-"),
97+ );
98+ const requestLogPath = NodePath.join(requestLogDir, "requests.ndjson");
9799
98100 return withFakeAcpAgent(
99101 {
@@ -123,7 +125,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 23 unmodified lines
123125 expect(generated.subject).toBe("Add generated commit message");
124126 expect(generated.body).toBe("- verify cursor acp model config path");
125127
126− const requests = readFileSync(requestLogPath, "utf8")
128+ const requests = NodeFS.readFileSync(requestLogPath, "utf8")
127129 .trim()
128130 .split("\n")
129131 .filter((line) => line.length > 0)
@@ -181,7 +183,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 51 unmodified lines
181183 ]),
182184 );
183185
184− rmSync(requestLogDir, { recursive: true, force: true });
186+ NodeFS.rmSync(requestLogDir, { recursive: true, force: true });
185187 }),
186188 );
187189 });
@@ -235,8 +237,10 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 47 unmodified lines
235237 );
236238
237239 it.effect("closes the ACP child process after text generation completes", () => {
238− const exitLogDir = mkdtempSync(path.join(os.tmpdir(), "t3code-cursor-text-exit-log-"));
239− const exitLogPath = path.join(exitLogDir, "exit.log");
240+ const exitLogDir = NodeFS.mkdtempSync(
241+ NodePath.join(NodeOS.tmpdir(), "t3code-cursor-text-exit-log-"),
242+ );
243+ const exitLogPath = NodePath.join(exitLogDir, "exit.log");
240244
241245 return withFakeAcpAgent(
242246 {
@@ -265,7 +269,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 22 unmodified lines
265269 const exitLog = yield* waitForFileContent(exitLogPath);
266270 expect(exitLog).toContain("exit:0");
267271
268− rmSync(exitLogDir, { recursive: true, force: true });
272+ NodeFS.rmSync(exitLogDir, { recursive: true, force: true });
269273 }),
270274 );
271275 });