-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test(server): hold the prototype-named override case in a sibling file #5011
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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * The prototype-named model context override, held in a sibling file. | ||
| * | ||
| * Split out of management-provider-validation.test.ts for the reason recorded in | ||
| * d3ca5522db and #4908: that file sits at its file-size ratchet cap, and the cap only | ||
| * ever moves downward, so a test added to it after the cap was set fails the ratchet | ||
| * for every later pull request rather than only its own. The case is unchanged. | ||
| */ | ||
| import { describe, expect, setDefaultTimeout, spyOn, test } from "bun:test"; | ||
| import { managementFetch as fetch } from "../helpers/management-auth"; | ||
| import { existsSync, mkdirSync, mkdtempSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { loadConfig, saveConfig } from "../../src/config"; | ||
| import { startServer } from "../../src/server"; | ||
| import * as destinationPolicy from "../../src/lib/destination-policy"; | ||
| import { removeTreeWithRetry } from "../helpers/remove-tree"; | ||
| import type { OcxConfig } from "../../src/types"; | ||
|
|
||
| setDefaultTimeout(60_000); | ||
|
|
||
| const TEST_DIR = mkdtempSync(join(tmpdir(), "ocx-management-provider-proto-")); | ||
|
|
||
| const canonicalDirect = { | ||
| adapter: "openai-responses", | ||
| baseUrl: "https://chatgpt.com/backend-api/codex", | ||
| authMode: "forward", | ||
| codexAccountMode: "direct", | ||
| } as const; | ||
|
|
||
| describe("provider management validation", () => { | ||
| // A "__proto__" model id is a legitimate override key once the GUI can draft it. | ||
| // The merge target must be a null-prototype map: on an ordinary object the | ||
| // assignment windows["__proto__"] = n invokes the inherited setter, so the | ||
| // PATCH would return success while silently dropping the override. | ||
| test("PATCH modelContextWindows persists a __proto__-named model override", async () => { | ||
| if (existsSync(TEST_DIR)) removeTreeWithRetry(TEST_DIR); | ||
| mkdirSync(TEST_DIR, { recursive: true }); | ||
| process.env.OPENCODEX_HOME = TEST_DIR; | ||
|
Contributor
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. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,100p' tests/server/management-provider-proto-override.test.ts
rg -n -C 3 'OPENCODEX_HOME|management-provider-proto-override' tests/server tests package.json bunfig.toml 2>/dev/null | head -260
rg -n 'management-provider-proto-override|tests/server' package.json scripts .github 2>/dev/null | head -180Repository: lidge-jun/opencodex Length of output: 23204 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- former location and references ---'
rg -n -C 12 'PATCH modelContextWindows persists a __proto__-named model override|OPENCODEX_HOME|management-provider-proto-override' tests/server/management-provider-validation.test.ts tests/preload.ts package.json bunfig.toml scripts 2>/dev/null | head -260
printf '%s\n' '--- preload ---'
wc -l tests/preload.ts
cat -n tests/preload.ts
printf '%s\n' '--- runner configuration ---'
cat -n bunfig.toml
cat -n package.json | sed -n '1,180p'
printf '%s\n' '--- temporary-home helpers and cleanup ---'
rg -n -C 5 'function (sandbox|isolat|restore)|installIsolatedCodexHome|previous(Home|OpenCodexHome)|afterEach|OPENCODEX_HOME' tests/helpers tests/server/management-provider-validation.test.ts tests/server/server-images.test.ts tests/server/api-debug.test.ts | head -320Repository: lidge-jun/opencodex Length of output: 50375 🏁 Script executed: #!/bin/bash
set -o pipefail
printf '%s\n' '--- test wrapper and isolation flags ---'
rg -n -C 8 'bun test|--isolate|no-isolate|parallel|createIsolatedTestEnvironment' scripts/test.ts scripts package.json bunfig.toml 2>/dev/null | head -240
printf '%s\n' '--- former test location ---'
git log --oneline --all -- tests/server/management-provider-validation.test.ts tests/server/management-provider-proto-override.test.ts | head -30
printf '%s\n' '--- current and parent file references ---'
git rev-parse HEAD
git show HEAD^:tests/server/management-provider-validation.test.ts 2>/dev/null | rg -n -C 18 'PATCH modelContextWindows persists a __proto__-named model override|process.env.OPENCODEX_HOME = TEST_DIR|removeTreeWithRetry\(TEST_DIR\)' | head -180
printf '%s\n' '--- helper implementation ---'
cat -n tests/helpers/isolated-codex-home.ts | sed -n '1,180p'Repository: lidge-jun/opencodex Length of output: 25495 🌐 Web query:
💡 Result: <search_synthesis> <source_evidence> Citations:
Restore
Save the previous value before the assignment and restore it in Proposed fix test("PATCH modelContextWindows persists a __proto__-named model override", async () => {
+ const previousOpenCodexHome = process.env.OPENCODEX_HOME;
+ try {
if (existsSync(TEST_DIR)) removeTreeWithRetry(TEST_DIR);
mkdirSync(TEST_DIR, { recursive: true });
process.env.OPENCODEX_HOME = TEST_DIR;
@@
- } finally {
- resolvedError.mockRestore();
- await server.stop(true);
- removeTreeWithRetry(TEST_DIR);
+ } finally {
+ resolvedError.mockRestore();
+ await server.stop(true);
+ removeTreeWithRetry(TEST_DIR);
+ }
+ } finally {
+ if (previousOpenCodexHome === undefined) delete process.env.OPENCODEX_HOME;
+ else process.env.OPENCODEX_HOME = previousOpenCodexHome;
}
});🤖 Prompt for AI Agents |
||
| saveConfig({ | ||
| port: 0, | ||
| openaiProviderTierVersion: 2, | ||
| defaultProvider: "openai", | ||
| providers: { | ||
| openai: { ...canonicalDirect }, | ||
| }, | ||
| } as OcxConfig); | ||
| const resolvedError = spyOn(destinationPolicy, "providerDestinationResolvedError").mockResolvedValue(null); | ||
|
|
||
| const server = startServer(0); | ||
| try { | ||
| const patch = await fetch(new URL("/api/providers?name=openai", server.url), { | ||
| method: "PATCH", | ||
| headers: { "content-type": "application/json" }, | ||
| // Written as a raw body: an object literal "__proto__" key would set the | ||
| // prototype instead of creating the own property under test. | ||
| body: '{"modelContextWindows":{"__proto__":128000}}', | ||
| }); | ||
| expect(patch.status).toBe(200); | ||
| const windows = loadConfig().providers.openai?.modelContextWindows ?? {}; | ||
| expect(Object.hasOwn(windows, "__proto__")).toBe(true); | ||
| expect(Object.getOwnPropertyDescriptor(windows, "__proto__")?.value).toBe(128000); | ||
| } finally { | ||
| resolvedError.mockRestore(); | ||
| await server.stop(true); | ||
| removeTreeWithRetry(TEST_DIR); | ||
| } | ||
| }); | ||
| }); | ||
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.
This assignment was previously covered by
management-provider-validation.test.ts'safterEach, which restored the priorOPENCODEX_HOME; the new file only removesTEST_DIR, leaving the variable pointed at that deleted directory. As documented intests/ci-workflows/fixture-dir-uniqueness.test.ts:13-15, isolated test files still share a process, so the next file assigned to this worker can read or preserve the stale path and produce order-dependent config failures. Snapshot and restore the variable in anafterEach/outerfinallyso cleanup also runs if setup orstartServerthrows.Useful? React with 👍 / 👎.