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 @@
1// @effect-diagnostics nodeBuiltinImport:off1// @effect-diagnostics nodeBuiltinImport:off
2import * as path from "node:path";2import * as NodePath from "node:path";
3import * as os from "node:os";3import * as NodeOS from "node:os";
4import { fileURLToPath } from "node:url";4import * as NodeURL from "node:url";
5import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";5import * as NodeFS from "node:fs";
6 6
7import * as NodeServices from "@effect/platform-node/NodeServices";7import * as NodeServices from "@effect/platform-node/NodeServices";
8import { it } from "@effect/vitest";8import { it } from "@effect/vitest";
@@ -21,8 +21,8 @@ import * as TextGeneration from "./TextGeneration.ts"; · 12 unmodified lines
21import { makeCursorTextGeneration } from "./CursorTextGeneration.ts";21import { makeCursorTextGeneration } from "./CursorTextGeneration.ts";
22const decodeCursorSettings = Schema.decodeSync(CursorSettings);22const decodeCursorSettings = Schema.decodeSync(CursorSettings);
23 23
24const __dirname = path.dirname(fileURLToPath(import.meta.url));24const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
25const mockAgentPath = path.join(__dirname, "../../scripts/acp-mock-agent.ts");25const mockAgentPath = NodePath.join(__dirname, "../../scripts/acp-mock-agent.ts");
26 26
27function shellSingleQuote(value: string): string {27function shellSingleQuote(value: string): string {
28 return `'${value.replaceAll("'", `'"'"'`)}'`;28 return `'${value.replaceAll("'", `'"'"'`)}'`;
@@ -33,10 +33,10 @@ const CursorTextGenerationTestLayer = ServerConfig.ServerConfig.layerTest(proces · 4 unmodified lines
33}).pipe(Layer.provideMerge(NodeServices.layer));33}).pipe(Layer.provideMerge(NodeServices.layer));
34 34
35function makeAcpAgentWrapper(dir: string, env: Record<string, string>): string {35function makeAcpAgentWrapper(dir: string, env: Record<string, string>): string {
36 const binDir = path.join(dir, "bin");36 const binDir = NodePath.join(dir, "bin");
37 const agentPath = path.join(binDir, "agent");37 const agentPath = NodePath.join(binDir, "agent");
38 mkdirSync(binDir, { recursive: true });38 NodeFS.mkdirSync(binDir, { recursive: true });
39 writeFileSync(39 NodeFS.writeFileSync(
40 agentPath,40 agentPath,
41 [41 [
42 "#!/bin/sh",42 "#!/bin/sh",
@@ -50,7 +50,7 @@ function makeAcpAgentWrapper(dir: string, env: Record<string, string>): string { · 7 unmodified lines
50 ].join("\n"),50 ].join("\n"),
51 "utf8",51 "utf8",
52 );52 );
53 chmodSync(agentPath, 0o755);53 NodeFS.chmodSync(agentPath, 0o755);
54 return agentPath;54 return agentPath;
55}55}
56 56
@@ -59,10 +59,10 @@ function withFakeAcpAgent<A, E, R>( · 2 unmodified lines
59 effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,59 effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,
60) {60) {
61 return Effect.gen(function* () {61 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-"));
63 yield* Effect.addFinalizer(() =>63 yield* Effect.addFinalizer(() =>
64 Effect.sync(() => {64 Effect.sync(() => {
65 rmSync(tempDir, { recursive: true, force: true });65 NodeFS.rmSync(tempDir, { recursive: true, force: true });
66 }),66 }),
67 );67 );
68 const agentPath = makeAcpAgentWrapper(tempDir, env);68 const agentPath = makeAcpAgentWrapper(tempDir, env);
@@ -76,7 +76,7 @@ function waitForFileContent(path: string): Effect.Effect<string> { · 7 unmodified lines
76 return Effect.gen(function* () {76 return Effect.gen(function* () {
77 const deadline = (yield* Clock.currentTimeMillis) + 5_000;77 const deadline = (yield* Clock.currentTimeMillis) + 5_000;
78 for (;;) {78 for (;;) {
79 const result = yield* Effect.exit(Effect.sync(() => readFileSync(path, "utf8")));79 const result = yield* Effect.exit(Effect.sync(() => NodeFS.readFileSync(path, "utf8")));
80 if (Exit.isSuccess(result)) {80 if (Exit.isSuccess(result)) {
81 return result.value;81 return result.value;
82 }82 }
@@ -92,8 +92,10 @@ function waitForFileContent(path: string): Effect.Effect<string> { · 9 unmodified lines
92 92
93it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => {93it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => {
94 it.effect("uses ACP model config options instead of raw CLI model ids", () => {94 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-"));95 const requestLogDir = NodeFS.mkdtempSync(
96 const requestLogPath = path.join(requestLogDir, "requests.ndjson");96 NodePath.join(NodeOS.tmpdir(), "t3code-cursor-text-log-"),
97 );
98 const requestLogPath = NodePath.join(requestLogDir, "requests.ndjson");
97 99
98 return withFakeAcpAgent(100 return withFakeAcpAgent(
99 {101 {
@@ -123,7 +125,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 23 unmodified lines
123 expect(generated.subject).toBe("Add generated commit message");125 expect(generated.subject).toBe("Add generated commit message");
124 expect(generated.body).toBe("- verify cursor acp model config path");126 expect(generated.body).toBe("- verify cursor acp model config path");
125 127
126 const requests = readFileSync(requestLogPath, "utf8")128 const requests = NodeFS.readFileSync(requestLogPath, "utf8")
127 .trim()129 .trim()
128 .split("\n")130 .split("\n")
129 .filter((line) => line.length > 0)131 .filter((line) => line.length > 0)
@@ -181,7 +183,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 51 unmodified lines
181 ]),183 ]),
182 );184 );
183 185
184 rmSync(requestLogDir, { recursive: true, force: true });186 NodeFS.rmSync(requestLogDir, { recursive: true, force: true });
185 }),187 }),
186 );188 );
187 });189 });
@@ -235,8 +237,10 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 47 unmodified lines
235 );237 );
236 238
237 it.effect("closes the ACP child process after text generation completes", () => {239 it.effect("closes the ACP child process after text generation completes", () => {
238 const exitLogDir = mkdtempSync(path.join(os.tmpdir(), "t3code-cursor-text-exit-log-"));240 const exitLogDir = NodeFS.mkdtempSync(
239 const exitLogPath = path.join(exitLogDir, "exit.log");241 NodePath.join(NodeOS.tmpdir(), "t3code-cursor-text-exit-log-"),
242 );
243 const exitLogPath = NodePath.join(exitLogDir, "exit.log");
240 244
241 return withFakeAcpAgent(245 return withFakeAcpAgent(
242 {246 {
@@ -265,7 +269,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 22 unmodified lines
265 const exitLog = yield* waitForFileContent(exitLogPath);269 const exitLog = yield* waitForFileContent(exitLogPath);
266 expect(exitLog).toContain("exit:0");270 expect(exitLog).toContain("exit:0");
267 271
268 rmSync(exitLogDir, { recursive: true, force: true });272 NodeFS.rmSync(exitLogDir, { recursive: true, force: true });
269 }),273 }),
270 );274 );
271 });275 });