From 960d6e23a0c85aef6fceef2afbe789e285c5d940 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Wed, 15 Jul 2026 10:22:09 -0400 Subject: [PATCH] test(codex-auth): cover profile cache repair entry points --- tests/unit/bin/codex-runtime-router.test.ts | 36 +++++++++++++++++++ .../commands/create-command.test.ts | 33 +++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/tests/unit/bin/codex-runtime-router.test.ts b/tests/unit/bin/codex-runtime-router.test.ts index e9380831..7a639429 100644 --- a/tests/unit/bin/codex-runtime-router.test.ts +++ b/tests/unit/bin/codex-runtime-router.test.ts @@ -176,9 +176,45 @@ describe('codex-runtime router — non-auth profile resolution', () => { expect(process.env.CCS_CODEX_PROFILE).toBe('ck'); expect(process.env.CODEX_HOME).toBe(profileDir); expect(fs.existsSync(path.join(profileDir, 'agents', 'brainstormer.toml'))).toBe(true); + expect(fs.lstatSync(path.join(profileDir, 'plugins', 'cache')).isSymbolicLink()).toBe(true); expect(argv).toEqual(['node', 'codex-runtime', 'default', 'fix failing tests']); }); + it('repairs a positional ccsx profile before delegating to CCS', async () => { + const profileDir = makeProfileDir('ck'); + writeRegistry({ + version: '1.0', + default: null, + profiles: { ck: { type: 'codex', created: '2026-01-01T00:00:00.000Z', last_used: null } }, + }); + const events: string[] = []; + + flushRouterCache(); + require.cache[resourcePath] = { + exports: { + ensureCodexProfileResources: (dir: string) => { + expect(dir).toBe(profileDir); + events.push('repair'); + }, + }, + } as NodeJS.Module; + require.cache[ccsPath] = Object.defineProperty({} as NodeJS.Module, 'exports', { + configurable: true, + get: () => { + events.push('ccs'); + return {}; + }, + }); + + const argv = ['node', 'codex-runtime', 'ck']; + const { main } = require(routerPath) as { main: (args: string[]) => Promise }; + const code = await main(argv); + + expect(code).toBe(-1); + expect(events).toEqual(['repair', 'ccs']); + expect(argv).toEqual(['node', 'codex-runtime', 'default']); + }); + it('self-heals missing Codex profile resources during launch', async () => { const profileDir = makeProfileDir('ck'); writeRegistry({ diff --git a/tests/unit/codex-auth/commands/create-command.test.ts b/tests/unit/codex-auth/commands/create-command.test.ts index 39d90e83..042878c7 100644 --- a/tests/unit/codex-auth/commands/create-command.test.ts +++ b/tests/unit/codex-auth/commands/create-command.test.ts @@ -21,6 +21,24 @@ beforeEach(() => { fs.writeFileSync(path.join(homeDir, '.codex', 'agents', 'brainstormer.toml'), 'name = "b"\n'); fs.mkdirSync(path.join(homeDir, '.codex', 'skills'), { recursive: true }); fs.writeFileSync(path.join(homeDir, '.codex', 'skills', 'review.md'), '# Review\n'); + fs.mkdirSync( + path.join(homeDir, '.codex', 'plugins', 'cache', 'claudekit', '1.0.0', 'skills', 'test'), + { recursive: true } + ); + fs.writeFileSync( + path.join( + homeDir, + '.codex', + 'plugins', + 'cache', + 'claudekit', + '1.0.0', + 'skills', + 'test', + 'SKILL.md' + ), + '# Test skill\n' + ); fs.mkdirSync(path.join(ccsHome, '.ccs'), { recursive: true }); process.env.CCS_HOME = ccsHome; spyOn(os, 'homedir').mockReturnValue(homeDir); @@ -96,6 +114,21 @@ describe('handleCreateCodex — happy path', () => { expect(fs.existsSync(instancesDir)).toBe(true); expect(fs.lstatSync(path.join(instancesDir, 'agents')).isSymbolicLink()).toBe(true); expect(fs.lstatSync(path.join(instancesDir, 'skills')).isSymbolicLink()).toBe(true); + expect( + fs.readFileSync( + path.join( + instancesDir, + 'plugins', + 'cache', + 'claudekit', + '1.0.0', + 'skills', + 'test', + 'SKILL.md' + ), + 'utf8' + ) + ).toBe('# Test skill\n'); }); });