|
1 | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | | -import { join } from "node:path"; |
| 4 | +import { join, resolve } from "node:path"; |
5 | 5 |
|
6 | 6 | type OpenAiTemplate = { |
7 | 7 | provider: { |
@@ -42,6 +42,26 @@ describe("install-oc-codex-multi-auth script", () => { |
42 | 42 | expect(errorSpy).not.toHaveBeenCalled(); |
43 | 43 | }); |
44 | 44 |
|
| 45 | + it("detects direct CLI execution after path normalization", async () => { |
| 46 | + vi.resetModules(); |
| 47 | + const { isDirectRunPath } = await import("../scripts/install-oc-codex-multi-auth.js"); |
| 48 | + const scriptPath = resolve("scripts", "install-oc-codex-multi-auth.js"); |
| 49 | + const symlinkedScriptPath = join( |
| 50 | + process.cwd(), |
| 51 | + "global", |
| 52 | + "node_modules", |
| 53 | + "oc-codex-multi-auth", |
| 54 | + "install-oc-codex-multi-auth.js", |
| 55 | + ); |
| 56 | + const resolveRealPath = (path: string) => path === symlinkedScriptPath ? scriptPath : path; |
| 57 | + |
| 58 | + expect(isDirectRunPath(symlinkedScriptPath, scriptPath, resolveRealPath)).toBe(true); |
| 59 | + expect( |
| 60 | + isDirectRunPath(resolve("scripts", "install-oc-codex-multi-auth-core.js"), scriptPath), |
| 61 | + ).toBe(false); |
| 62 | + expect(isDirectRunPath(undefined, scriptPath)).toBe(false); |
| 63 | + }); |
| 64 | + |
45 | 65 | it("writes compact UI catalog by default, preserves user model entries, and normalizes plugin entries", async () => { |
46 | 66 | vi.resetModules(); |
47 | 67 | tempHome = await createTempHome(); |
|
0 commit comments