codex-multi-auth 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { readFile, writeFile, rm, mkdir } from "node:fs/promises";
3
- import { spawnSync } from "node:child_process";
4
- import { dirname, join, resolve } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import process from "node:process";
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { readFile, writeFile, rm, mkdir } from "node:fs/promises";
3
+ import { spawnSync } from "node:child_process";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import process from "node:process";
7
7
 
8
8
  const scriptDir = dirname(fileURLToPath(import.meta.url));
9
9
  const repoRoot = resolve(scriptDir, "..");
@@ -13,50 +13,50 @@ const scenarioTemplates = {
13
13
  modern: join(repoRoot, "config", "codex-modern.json"),
14
14
  };
15
15
 
16
- const pluginPackageName = "codex-multi-auth";
17
- const DEFAULT_MATRIX_TIMEOUT_MS = 120000;
18
-
19
- function resolveCmdScriptEntry(commandPath) {
20
- if (!/\.cmd$/i.test(commandPath)) {
21
- return null;
22
- }
23
- try {
24
- const raw = readFileSync(commandPath, "utf8");
25
- const match = raw.match(/"%dp0%\\([^"\r\n]+\.js)"/i);
26
- if (!match || typeof match[1] !== "string") {
27
- return null;
28
- }
29
- const relScriptPath = match[1].replace(/[\\/]+/g, "/");
30
- const scriptPath = resolve(dirname(commandPath), relScriptPath);
31
- return existsSync(scriptPath) ? scriptPath : null;
32
- } catch {
33
- return null;
34
- }
35
- }
36
-
37
- function buildExecutable(command) {
38
- const scriptEntry = resolveCmdScriptEntry(command);
39
- if (scriptEntry) {
40
- return {
41
- command: process.execPath,
42
- shell: false,
43
- prefixArgs: [scriptEntry],
44
- displayCommand: command,
45
- };
46
- }
47
- return { command, shell: /\.cmd$/i.test(command) };
48
- }
49
-
50
- export function resolveCodexExecutable() {
51
- const envOverride = process.env.CODEX_BIN;
52
- if (envOverride && envOverride.trim().length > 0) {
53
- const command = envOverride.trim();
54
- return buildExecutable(command);
55
- }
56
-
57
- if (process.platform !== "win32") {
58
- return { command: "codex", shell: false };
59
- }
16
+ const pluginPackageName = "codex-multi-auth";
17
+ const DEFAULT_MATRIX_TIMEOUT_MS = 120000;
18
+
19
+ function resolveCmdScriptEntry(commandPath) {
20
+ if (!/\.cmd$/i.test(commandPath)) {
21
+ return null;
22
+ }
23
+ try {
24
+ const raw = readFileSync(commandPath, "utf8");
25
+ const match = raw.match(/"%dp0%\\([^"\r\n]+\.js)"/i);
26
+ if (!match || typeof match[1] !== "string") {
27
+ return null;
28
+ }
29
+ const relScriptPath = match[1].replace(/[\\/]+/g, "/");
30
+ const scriptPath = resolve(dirname(commandPath), relScriptPath);
31
+ return existsSync(scriptPath) ? scriptPath : null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ function buildExecutable(command) {
38
+ const scriptEntry = resolveCmdScriptEntry(command);
39
+ if (scriptEntry) {
40
+ return {
41
+ command: process.execPath,
42
+ shell: false,
43
+ prefixArgs: [scriptEntry],
44
+ displayCommand: command,
45
+ };
46
+ }
47
+ return { command, shell: /\.cmd$/i.test(command) };
48
+ }
49
+
50
+ export function resolveCodexExecutable() {
51
+ const envOverride = process.env.CODEX_BIN;
52
+ if (envOverride && envOverride.trim().length > 0) {
53
+ const command = envOverride.trim();
54
+ return buildExecutable(command);
55
+ }
56
+
57
+ if (process.platform !== "win32") {
58
+ return { command: "codex", shell: false };
59
+ }
60
60
 
61
61
  const whereResult = spawnSync("where", ["Codex"], {
62
62
  encoding: "utf8",
@@ -71,27 +71,27 @@ export function resolveCodexExecutable() {
71
71
  return { command: "codex", shell: false };
72
72
  }
73
73
 
74
- const exactExe = candidates.find((candidate) =>
75
- /npm\\Codex\.exe$/i.test(candidate),
76
- );
77
- if (exactExe) {
78
- return { command: exactExe, shell: false };
79
- }
80
-
81
- const exactCmd = candidates.find((candidate) =>
82
- /npm\\Codex\.cmd$/i.test(candidate),
83
- );
84
- if (exactCmd) {
85
- return buildExecutable(exactCmd);
86
- }
87
-
88
- const anyCmd = candidates.find((candidate) => /\.cmd$/i.test(candidate));
89
- if (anyCmd) {
90
- return buildExecutable(anyCmd);
91
- }
92
-
93
- return { command: candidates[0], shell: false };
94
- }
74
+ const exactExe = candidates.find((candidate) =>
75
+ /npm\\Codex\.exe$/i.test(candidate),
76
+ );
77
+ if (exactExe) {
78
+ return { command: exactExe, shell: false };
79
+ }
80
+
81
+ const exactCmd = candidates.find((candidate) =>
82
+ /npm\\Codex\.cmd$/i.test(candidate),
83
+ );
84
+ if (exactCmd) {
85
+ return buildExecutable(exactCmd);
86
+ }
87
+
88
+ const anyCmd = candidates.find((candidate) => /\.cmd$/i.test(candidate));
89
+ if (anyCmd) {
90
+ return buildExecutable(anyCmd);
91
+ }
92
+
93
+ return { command: candidates[0], shell: false };
94
+ }
95
95
 
96
96
  const CodexExecutable = resolveCodexExecutable();
97
97
 
@@ -130,6 +130,9 @@ function toFileUri(pathValue) {
130
130
  return `file:///${normalized}`;
131
131
  }
132
132
 
133
+ let stopCodexServersQueue = Promise.resolve();
134
+ const spawnedCodexPids = new Set();
135
+
133
136
  function runQuiet(command, commandArgs) {
134
137
  try {
135
138
  spawnSync(command, commandArgs, {
@@ -141,9 +144,6 @@ function runQuiet(command, commandArgs) {
141
144
  }
142
145
  }
143
146
 
144
- let stopCodexServersQueue = Promise.resolve();
145
- const spawnedCodexPids = new Set();
146
-
147
147
  export function registerSpawnedCodex(pid) {
148
148
  if (!Number.isInteger(pid) || pid <= 0) return;
149
149
  spawnedCodexPids.add(pid);
@@ -244,28 +244,36 @@ function enumerateCases(models, smoke, maxCases) {
244
244
  return selected;
245
245
  }
246
246
 
247
- function executeModelCase(caseInfo, index) {
248
- const token = `MODEL_MATRIX_OK_${index}`;
249
- const message = token;
250
- const args = [
251
- "exec",
252
- message,
253
- "--model",
254
- caseInfo.model,
255
- "--json",
256
- "--skip-git-repo-check",
257
- ];
258
- if (caseInfo.variant) {
259
- args.push("-c", `model_reasoning_effort="${caseInfo.variant}"`);
260
- }
261
-
262
- const timeoutMs = resolveMatrixTimeoutMs();
263
- const commandArgs = [...(CodexExecutable.prefixArgs ?? []), ...args];
264
- const finalized = spawnSync(CodexExecutable.command, commandArgs, {
265
- cwd: repoRoot,
266
- encoding: "utf8",
267
- windowsHide: true,
268
- shell: CodexExecutable.shell,
247
+ function buildModelCaseArgs(caseInfo, index) {
248
+ const token = `MODEL_MATRIX_OK_${index}`;
249
+ const args = [
250
+ "exec",
251
+ token,
252
+ "--model",
253
+ caseInfo.model,
254
+ "--json",
255
+ "--skip-git-repo-check",
256
+ ];
257
+ if (caseInfo.variant) {
258
+ args.push("-c", `model_reasoning_effort="${caseInfo.variant}"`);
259
+ }
260
+ return { token, args };
261
+ }
262
+
263
+ export function __buildModelCaseArgsForTests(caseInfo, index) {
264
+ return buildModelCaseArgs(caseInfo, index);
265
+ }
266
+
267
+ function executeModelCase(caseInfo, index) {
268
+ const { token, args } = buildModelCaseArgs(caseInfo, index);
269
+
270
+ const timeoutMs = resolveMatrixTimeoutMs();
271
+ const commandArgs = [...(CodexExecutable.prefixArgs ?? []), ...args];
272
+ const finalized = spawnSync(CodexExecutable.command, commandArgs, {
273
+ cwd: repoRoot,
274
+ encoding: "utf8",
275
+ windowsHide: true,
276
+ shell: CodexExecutable.shell,
269
277
  timeout: timeoutMs,
270
278
  killSignal: "SIGKILL",
271
279
  env: {
@@ -286,10 +294,10 @@ function executeModelCase(caseInfo, index) {
286
294
  };
287
295
  }
288
296
 
289
- const combinedOutput = `${finalized.stdout ?? ""}\n${finalized.stderr ?? ""}`.trim();
290
- const hasToken = combinedOutput.includes(token);
291
- const exitCode = finalized.status ?? 1;
292
- const ok = exitCode === 0 && hasToken;
297
+ const combinedOutput = `${finalized.stdout ?? ""}\n${finalized.stderr ?? ""}`.trim();
298
+ const hasToken = combinedOutput.includes(token);
299
+ const exitCode = finalized.status ?? 1;
300
+ const ok = exitCode === 0 && hasToken;
293
301
 
294
302
  return {
295
303
  ...caseInfo,
@@ -371,11 +379,11 @@ async function runScenario(scenario, options) {
371
379
 
372
380
  const results = [];
373
381
  for (let i = 0; i < cases.length; i += 1) {
374
- const caseInfo = cases[i];
375
- const result = executeModelCase(
376
- caseInfo,
377
- i + 1,
378
- );
382
+ const caseInfo = cases[i];
383
+ const result = executeModelCase(
384
+ caseInfo,
385
+ i + 1,
386
+ );
379
387
  results.push(result);
380
388
  const variantLabel = result.variant ? ` [variant=${result.variant}]` : "";
381
389
  if (result.ok) {
@@ -426,10 +434,10 @@ async function main() {
426
434
 
427
435
  console.log("Codex Model Matrix Audit");
428
436
  console.log(`Repo: ${repoRoot}`);
429
- console.log(`Scenarios: ${scenarios.join(", ")}`);
430
- console.log(`Mode: ${smoke ? "smoke" : "full"}`);
431
- console.log(`Plugin: ${pluginRef}`);
432
- console.log(`Codex command: ${CodexExecutable.displayCommand ?? CodexExecutable.command}`);
437
+ console.log(`Scenarios: ${scenarios.join(", ")}`);
438
+ console.log(`Mode: ${smoke ? "smoke" : "full"}`);
439
+ console.log(`Plugin: ${pluginRef}`);
440
+ console.log(`Codex command: ${CodexExecutable.displayCommand ?? CodexExecutable.command}`);
433
441
 
434
442
  const backups = await backupLocalConfigs();
435
443
  const allResults = [];
@@ -441,7 +449,6 @@ async function main() {
441
449
  smoke,
442
450
  maxCases,
443
451
  pluginRef,
444
- portStart: 47000 + i * 500,
445
452
  });
446
453
  allResults.push(...scenarioResults.map((item) => ({ ...item, scenario })));
447
454
  }
@@ -463,10 +470,10 @@ async function main() {
463
470
  generatedAt: new Date().toISOString(),
464
471
  repoRoot,
465
472
  scenarios,
466
- mode: smoke ? "smoke" : "full",
467
- plugin: pluginRef,
468
- CodexCommand: CodexExecutable.displayCommand ?? CodexExecutable.command,
469
- totals: {
473
+ mode: smoke ? "smoke" : "full",
474
+ plugin: pluginRef,
475
+ CodexCommand: CodexExecutable.displayCommand ?? CodexExecutable.command,
476
+ totals: {
470
477
  total: allResults.length,
471
478
  passed,
472
479
  failed: failed.length,
@@ -1,2 +1,2 @@
1
- export type PluginInput = any;
1
+ export type PluginInput = any;
2
2
  export type Plugin = any;
@@ -1,42 +1,42 @@
1
- export interface ToolContext {
2
- [key: string]: any;
3
- directory: string;
4
- worktree: string;
5
- ask: (request: any) => Promise<any> | any;
6
- }
7
-
8
- export interface ToolDefinition<TArgs = any, TResult = any> {
9
- description?: string;
10
- args?: Record<string, any>;
11
- parameters?: unknown;
12
- execute: (args: TArgs, context: ToolContext) => Promise<TResult> | TResult;
13
- [key: string]: any;
14
- }
15
-
16
- export interface SchemaNode {
17
- optional: () => SchemaNode;
18
- describe: (_text: string) => SchemaNode;
19
- min: (_value: number) => SchemaNode;
20
- max: (_value: number) => SchemaNode;
21
- default: (_value: unknown) => SchemaNode;
22
- int: () => SchemaNode;
23
- array: (_node?: unknown) => SchemaNode;
24
- [key: string]: any;
25
- }
26
-
27
- export interface ToolFactory {
28
- <TArgs = any, TResult = any>(definition: ToolDefinition<TArgs, TResult>): ToolDefinition<TArgs, TResult>;
29
- schema: {
30
- string: () => SchemaNode;
31
- number: () => SchemaNode;
32
- boolean: () => SchemaNode;
33
- object: (shape: Record<string, unknown>) => SchemaNode;
34
- enum: (values: readonly unknown[]) => SchemaNode;
35
- literal: (value: unknown) => SchemaNode;
36
- array: (node: unknown) => SchemaNode;
37
- any: () => SchemaNode;
38
- unknown: () => SchemaNode;
39
- };
40
- }
41
-
1
+ export interface ToolContext {
2
+ [key: string]: any;
3
+ directory: string;
4
+ worktree: string;
5
+ ask: (request: any) => Promise<any> | any;
6
+ }
7
+
8
+ export interface ToolDefinition<TArgs = any, TResult = any> {
9
+ description?: string;
10
+ args?: Record<string, any>;
11
+ parameters?: unknown;
12
+ execute: (args: TArgs, context: ToolContext) => Promise<TResult> | TResult;
13
+ [key: string]: any;
14
+ }
15
+
16
+ export interface SchemaNode {
17
+ optional: () => SchemaNode;
18
+ describe: (_text: string) => SchemaNode;
19
+ min: (_value: number) => SchemaNode;
20
+ max: (_value: number) => SchemaNode;
21
+ default: (_value: unknown) => SchemaNode;
22
+ int: () => SchemaNode;
23
+ array: (_node?: unknown) => SchemaNode;
24
+ [key: string]: any;
25
+ }
26
+
27
+ export interface ToolFactory {
28
+ <TArgs = any, TResult = any>(definition: ToolDefinition<TArgs, TResult>): ToolDefinition<TArgs, TResult>;
29
+ schema: {
30
+ string: () => SchemaNode;
31
+ number: () => SchemaNode;
32
+ boolean: () => SchemaNode;
33
+ object: (shape: Record<string, unknown>) => SchemaNode;
34
+ enum: (values: readonly unknown[]) => SchemaNode;
35
+ literal: (value: unknown) => SchemaNode;
36
+ array: (node: unknown) => SchemaNode;
37
+ any: () => SchemaNode;
38
+ unknown: () => SchemaNode;
39
+ };
40
+ }
41
+
42
42
  export declare const tool: ToolFactory;
@@ -1,29 +1,29 @@
1
- const chain = {
2
- optional() { return this; },
3
- describe() { return this; },
4
- min() { return this; },
5
- max() { return this; },
6
- default() { return this; },
7
- int() { return this; },
8
- array() { return this; },
9
- };
10
-
11
- function node() {
12
- return Object.create(chain);
13
- }
14
-
15
- export function tool(definition) {
16
- return definition;
17
- }
18
-
19
- tool.schema = {
20
- string: () => node(),
21
- number: () => node(),
22
- boolean: () => node(),
23
- object: () => node(),
24
- enum: () => node(),
25
- literal: () => node(),
26
- array: () => node(),
27
- any: () => node(),
28
- unknown: () => node(),
1
+ const chain = {
2
+ optional() { return this; },
3
+ describe() { return this; },
4
+ min() { return this; },
5
+ max() { return this; },
6
+ default() { return this; },
7
+ int() { return this; },
8
+ array() { return this; },
9
+ };
10
+
11
+ function node() {
12
+ return Object.create(chain);
13
+ }
14
+
15
+ export function tool(definition) {
16
+ return definition;
17
+ }
18
+
19
+ tool.schema = {
20
+ string: () => node(),
21
+ number: () => node(),
22
+ boolean: () => node(),
23
+ object: () => node(),
24
+ enum: () => node(),
25
+ literal: () => node(),
26
+ array: () => node(),
27
+ any: () => node(),
28
+ unknown: () => node(),
29
29
  };
@@ -1,4 +1,4 @@
1
- export type Auth = any;
2
- export type Provider = any;
3
- export type Model = any;
1
+ export type Auth = any;
2
+ export type Provider = any;
3
+ export type Model = any;
4
4
  export type CodexClient = any;