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 (2 of 71 files). Show all

Unified · Split

2 files
  1. apps/server/src/textGeneration/CursorTextGeneration.test.ts +25 −21
  2. apps/server/src/textGeneration/GrokTextGeneration.test.ts +18 −16
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 });
apps/server/src/textGeneration/GrokTextGeneration.test.ts+18−16
@@ -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";
@@ -18,8 +18,8 @@ import * as TextGeneration from "./TextGeneration.ts"; · 9 unmodified lines
18import { makeGrokTextGeneration } from "./GrokTextGeneration.ts";18import { makeGrokTextGeneration } from "./GrokTextGeneration.ts";
19const decodeGrokSettings = Schema.decodeSync(GrokSettings);19const decodeGrokSettings = Schema.decodeSync(GrokSettings);
20 20
21const __dirname = path.dirname(fileURLToPath(import.meta.url));21const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
22const mockAgentPath = path.join(__dirname, "../../scripts/acp-mock-agent.ts");22const mockAgentPath = NodePath.join(__dirname, "../../scripts/acp-mock-agent.ts");
23 23
24function shellSingleQuote(value: string): string {24function shellSingleQuote(value: string): string {
25 return `'${value.replaceAll("'", `'"'"'`)}'`;25 return `'${value.replaceAll("'", `'"'"'`)}'`;
@@ -30,10 +30,10 @@ const GrokTextGenerationTestLayer = ServerConfig.ServerConfig.layerTest(process. · 4 unmodified lines
30}).pipe(Layer.provideMerge(NodeServices.layer));30}).pipe(Layer.provideMerge(NodeServices.layer));
31 31
32function makeAcpGrokWrapper(dir: string, env: Record<string, string>): string {32function makeAcpGrokWrapper(dir: string, env: Record<string, string>): string {
33 const binDir = path.join(dir, "bin");33 const binDir = NodePath.join(dir, "bin");
34 const grokPath = path.join(binDir, "grok");34 const grokPath = NodePath.join(binDir, "grok");
35 mkdirSync(binDir, { recursive: true });35 NodeFS.mkdirSync(binDir, { recursive: true });
36 writeFileSync(36 NodeFS.writeFileSync(
37 grokPath,37 grokPath,
38 [38 [
39 "#!/bin/sh",39 "#!/bin/sh",
@@ -47,7 +47,7 @@ function makeAcpGrokWrapper(dir: string, env: Record<string, string>): string { · 7 unmodified lines
47 ].join("\n"),47 ].join("\n"),
48 "utf8",48 "utf8",
49 );49 );
50 chmodSync(grokPath, 0o755);50 NodeFS.chmodSync(grokPath, 0o755);
51 return grokPath;51 return grokPath;
52}52}
53 53
@@ -56,10 +56,10 @@ function withFakeAcpGrok<A, E, R>( · 2 unmodified lines
56 effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,56 effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,
57) {57) {
58 return Effect.gen(function* () {58 return Effect.gen(function* () {
59 const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3code-grok-text-acp-"));59 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3code-grok-text-acp-"));
60 yield* Effect.addFinalizer(() =>60 yield* Effect.addFinalizer(() =>
61 Effect.sync(() => {61 Effect.sync(() => {
62 rmSync(tempDir, { recursive: true, force: true });62 NodeFS.rmSync(tempDir, { recursive: true, force: true });
63 }),63 }),
64 );64 );
65 const binaryPath = makeAcpGrokWrapper(tempDir, env);65 const binaryPath = makeAcpGrokWrapper(tempDir, env);
@@ -72,7 +72,7 @@ function withFakeAcpGrok<A, E, R>( · 6 unmodified lines
72function readJsonRpcRequests(72function readJsonRpcRequests(
73 filePath: string,73 filePath: string,
74): ReadonlyArray<{ readonly method?: string; readonly params?: Record<string, unknown> }> {74): ReadonlyArray<{ readonly method?: string; readonly params?: Record<string, unknown> }> {
75 return readFileSync(filePath, "utf8")75 return NodeFS.readFileSync(filePath, "utf8")
76 .trim()76 .trim()
77 .split("\n")77 .split("\n")
78 .filter((line) => line.length > 0)78 .filter((line) => line.length > 0)
@@ -81,8 +81,10 @@ function readJsonRpcRequests( · 2 unmodified lines
81 81
82it.layer(GrokTextGenerationTestLayer)("GrokTextGeneration", (it) => {82it.layer(GrokTextGenerationTestLayer)("GrokTextGeneration", (it) => {
83 it.effect("uses ACP with disabled tool capabilities and forwards the requested model id", () => {83 it.effect("uses ACP with disabled tool capabilities and forwards the requested model id", () => {
84 const requestLogDir = mkdtempSync(path.join(os.tmpdir(), "t3code-grok-text-log-"));84 const requestLogDir = NodeFS.mkdtempSync(
85 const requestLogPath = path.join(requestLogDir, "requests.ndjson");85 NodePath.join(NodeOS.tmpdir(), "t3code-grok-text-log-"),
86 );
87 const requestLogPath = NodePath.join(requestLogDir, "requests.ndjson");
86 88
87 return withFakeAcpGrok(89 return withFakeAcpGrok(
88 {90 {