Showing the changes to apps/server/src/textGeneration/CursorTextGeneration.test.ts (1 of 71 files). Show all
Unified · Split
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | // @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"; | |
| 6 | 6 | |
| 7 | 7 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 8 | 8 | import { it } from "@effect/vitest"; |
| @@ -21,8 +21,8 @@ import * as TextGeneration from "./TextGeneration.ts"; · 12 unmodified lines | ||
| 21 | 21 | import { makeCursorTextGeneration } from "./CursorTextGeneration.ts"; |
| 22 | 22 | const decodeCursorSettings = Schema.decodeSync(CursorSettings); |
| 23 | 23 | |
| 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"); | |
| 26 | 26 | |
| 27 | 27 | function shellSingleQuote(value: string): string { |
| 28 | 28 | return `'${value.replaceAll("'", `'"'"'`)}'`; |
| @@ -33,10 +33,10 @@ const CursorTextGenerationTestLayer = ServerConfig.ServerConfig.layerTest(proces · 4 unmodified lines | ||
| 33 | 33 | }).pipe(Layer.provideMerge(NodeServices.layer)); |
| 34 | 34 | |
| 35 | 35 | 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( | |
| 40 | 40 | agentPath, |
| 41 | 41 | [ |
| 42 | 42 | "#!/bin/sh", |
| @@ -50,7 +50,7 @@ function makeAcpAgentWrapper(dir: string, env: Record<string, string>): string { · 7 unmodified lines | ||
| 50 | 50 | ].join("\n"), |
| 51 | 51 | "utf8", |
| 52 | 52 | ); |
| 53 | − chmodSync(agentPath, 0o755); | |
| 53 | + NodeFS.chmodSync(agentPath, 0o755); | |
| 54 | 54 | return agentPath; |
| 55 | 55 | } |
| 56 | 56 | |
| @@ -59,10 +59,10 @@ function withFakeAcpAgent<A, E, R>( · 2 unmodified lines | ||
| 59 | 59 | effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>, |
| 60 | 60 | ) { |
| 61 | 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 | 63 | yield* Effect.addFinalizer(() => |
| 64 | 64 | Effect.sync(() => { |
| 65 | − rmSync(tempDir, { recursive: true, force: true }); | |
| 65 | + NodeFS.rmSync(tempDir, { recursive: true, force: true }); | |
| 66 | 66 | }), |
| 67 | 67 | ); |
| 68 | 68 | const agentPath = makeAcpAgentWrapper(tempDir, env); |
| @@ -76,7 +76,7 @@ function waitForFileContent(path: string): Effect.Effect<string> { · 7 unmodified lines | ||
| 76 | 76 | return Effect.gen(function* () { |
| 77 | 77 | const deadline = (yield* Clock.currentTimeMillis) + 5_000; |
| 78 | 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 | 80 | if (Exit.isSuccess(result)) { |
| 81 | 81 | return result.value; |
| 82 | 82 | } |
| @@ -92,8 +92,10 @@ function waitForFileContent(path: string): Effect.Effect<string> { · 9 unmodified lines | ||
| 92 | 92 | |
| 93 | 93 | it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { |
| 94 | 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-")); | |
| 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"); | |
| 97 | 99 | |
| 98 | 100 | return withFakeAcpAgent( |
| 99 | 101 | { |
| @@ -123,7 +125,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 23 unmodified lines | ||
| 123 | 125 | expect(generated.subject).toBe("Add generated commit message"); |
| 124 | 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 | 129 | .trim() |
| 128 | 130 | .split("\n") |
| 129 | 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 | 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-")); | |
| 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"); | |
| 240 | 244 | |
| 241 | 245 | return withFakeAcpAgent( |
| 242 | 246 | { |
| @@ -265,7 +269,7 @@ it.layer(CursorTextGenerationTestLayer)("CursorTextGeneration", (it) => { · 22 unmodified lines | ||
| 265 | 269 | const exitLog = yield* waitForFileContent(exitLogPath); |
| 266 | 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 | }); |