| ... | ... | @@ -57,6 +57,49 @@ it.layer(NodeServices.layer)("telemetry identity", (it) => { |
| 57 | 57 | ), |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | it.effect("falls back quietly when Codex authenticates with an API key", () => { |
| 61 | const logs: CapturedLog[] = []; |
| 62 | const logger = makeCaptureLogger(logs); |
| 63 | |
| 64 | return Effect.gen(function* () { |
| 65 | const config = yield* ServerConfig.ServerConfig; |
| 66 | const fileSystem = yield* FileSystem.FileSystem; |
| 67 | const path = yield* Path.Path; |
| 68 | const homeDirectory = path.join(config.baseDir, "home"); |
| 69 | const codexAuthPath = path.join(homeDirectory, ".codex", "auth.json"); |
| 70 | const anonymousId = "api-key-fallback-anonymous-id"; |
| 71 | const privateApiKey = "sk-private-openai-api-key"; |
| 72 | |
| 73 | yield* fileSystem.makeDirectory(path.dirname(codexAuthPath), { recursive: true }); |
| 74 | yield* fileSystem.writeFileString( |
| 75 | codexAuthPath, |
| 76 | `{"auth_mode":"apikey","OPENAI_API_KEY":"${privateApiKey}"}`, |
| 77 | ); |
| 78 | yield* fileSystem.writeFileString(config.anonymousIdPath, anonymousId); |
| 79 | |
| 80 | const identifier = yield* Identify.getTelemetryIdentifierForHome(homeDirectory); |
| 81 | |
| 82 | assert.equal(identifier, sha256(anonymousId)); |
| 83 | assert.isUndefined(findIdentityLog(logs, "codex", "TelemetryIdentityDecodeError")); |
| 84 | assert.isUndefined(findIdentityLog(logs, "codex", "TelemetryIdentityReadError")); |
| 85 | const allLogs = logs |
| 86 | .map((log) => |
| 87 | [String(log.message), ...Object.values(log.annotations).map(String)].join("\n"), |
| 88 | ) |
| 89 | .join("\n"); |
| 90 | assert.notInclude(allLogs, privateApiKey); |
| 91 | }).pipe( |
| 92 | Effect.provide( |
| 93 | Layer.merge( |
| 94 | ServerConfig.layerTest(process.cwd(), { |
| 95 | prefix: "t3-telemetry-identify-apikey-", |
| 96 | }), |
| 97 | Logger.layer([logger], { mergeWithExisting: false }), |
| 98 | ), |
| 99 | ), |
| 100 | ); |
| 101 | }); |
| 102 | |
| 60 | 103 | it.effect("logs structured decode context and falls back from malformed Codex auth", () => { |
| 61 | 104 | const logs: CapturedLog[] = []; |
| 62 | 105 | const logger = makeCaptureLogger(logs); |