-
Notifications
You must be signed in to change notification settings - Fork 616
test(usage),docs(codex-app-models): isolate fixtures and document the Desktop allowlist #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import { afterEach, describe, expect, test } from "bun:test"; | ||
| import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | ||
| import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { handleManagementAPI } from "../src/server/management-api"; | ||
| import { usageLogPath } from "../src/usage/log"; | ||
| import { | ||
| addRequestLog, | ||
| clearRequestLogsForTests, | ||
|
|
@@ -10,7 +14,24 @@ import type { OcxConfig } from "../src/types"; | |
|
|
||
| const config = { providers: [] } as unknown as OcxConfig; | ||
|
|
||
| afterEach(() => clearRequestLogsForTests()); | ||
| let testDir = ""; | ||
| let previousHome: string | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| // addRequestLog persists to usage.jsonl; without a scratch OPENCODEX_HOME a bare | ||
| // `bun test <file>` run from outside the repo (no bunfig preload) writes these | ||
| // fixture rows into the real ~/.opencodex log and poisons the GUI Usage page. | ||
| previousHome = process.env.OPENCODEX_HOME; | ||
| testDir = mkdtempSync(join(tmpdir(), "ocx-logs-metrics-")); | ||
| process.env.OPENCODEX_HOME = testDir; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| clearRequestLogsForTests(); | ||
| if (previousHome === undefined) delete process.env.OPENCODEX_HOME; | ||
| else process.env.OPENCODEX_HOME = previousHome; | ||
| if (testDir) rmSync(testDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| async function readLogs(): Promise<Array<Record<string, any>>> { | ||
| const url = new URL("http://localhost/api/logs"); | ||
|
|
@@ -154,5 +175,33 @@ describe("GET /api/logs display metrics", () => { | |
| const [dto] = await readLogs(); | ||
| expect(dto!.displayMetrics.cost).toEqual({ kind: "unavailable", reason: "invalid_cache_breakdown" }); | ||
| }); | ||
|
|
||
| test("fixture usage rows land in the scratch home, never the default location", () => { | ||
| // Pins the safety property this file's isolation exists for: addRequestLog | ||
| // persists to usage.jsonl, so if the scratch-home hook is ever dropped (or a | ||
| // future test logs before it runs), a bare `bun test <file>` from outside the | ||
| // repo writes fixture rows into the developer's real ~/.opencodex log. | ||
| const requestId = "safety-pin-usage-log-target"; | ||
| addRequestLog(baseEntry({ requestId })); | ||
|
|
||
| const resolvedTarget = usageLogPath(); | ||
| expect(resolvedTarget).toBe(join(testDir, "usage.jsonl")); | ||
| expect(readFileSync(resolvedTarget, "utf-8")).toContain(requestId); | ||
|
|
||
| // The default location (what the resolver returns with no OPENCODEX_HOME | ||
| // override) must never be the write target for this suite. | ||
| const previousHome = process.env.OPENCODEX_HOME; | ||
| delete process.env.OPENCODEX_HOME; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this file is run from outside the repository as described above, the Bun preload is absent and Useful? React with 👍 / 👎. |
||
| try { | ||
| const defaultTarget = usageLogPath(); | ||
| expect(defaultTarget).not.toBe(resolvedTarget); | ||
| if (existsSync(defaultTarget)) { | ||
| expect(readFileSync(defaultTarget, "utf-8")).not.toContain(requestId); | ||
| } | ||
| } finally { | ||
| if (previousHome === undefined) delete process.env.OPENCODEX_HOME; | ||
| else process.env.OPENCODEX_HOME = previousHome; | ||
| } | ||
| }); | ||
| }); | ||
| import { ManagementRequest as Request } from "./helpers/management-auth"; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user copies this workaround without having created a custom provider literally named
input, the configured model is unroutable because the shipped registry defines this Grok route underxai(src/providers/registry.ts:879-902) and contains noinputprovider. Usexai/grok-4.5or an explicit<configured-provider>/<model>placeholder here and in the translations so the documented workaround does not fail with an unknown provider.AGENTS.md reference: docs-site/AGENTS.md:L10-L10
Useful? React with 👍 / 👎.