mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 20:15:40 +00:00
test(codex-auth): cover profile cache repair entry points
This commit is contained in:
1 parent
e5d4d860b3
commit
960d6e23a0
2 files changed
+69
No files matched your search
@@ -176,9 +176,45 @@ describe('codex-runtime router — non-auth profile resolution', () => {
|
|||||||
expect(process.env.CCS_CODEX_PROFILE).toBe('ck');
|
expect(process.env.CCS_CODEX_PROFILE).toBe('ck');
|
||||||
expect(process.env.CODEX_HOME).toBe(profileDir);
|
expect(process.env.CODEX_HOME).toBe(profileDir);
|
||||||
expect(fs.existsSync(path.join(profileDir, 'agents', 'brainstormer.toml'))).toBe(true);
|
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']);
|
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<number> };
|
||||||
|
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 () => {
|
it('self-heals missing Codex profile resources during launch', async () => {
|
||||||
const profileDir = makeProfileDir('ck');
|
const profileDir = makeProfileDir('ck');
|
||||||
writeRegistry({
|
writeRegistry({
|
||||||
|
|||||||
@@ -21,6 +21,24 @@ beforeEach(() => {
|
|||||||
fs.writeFileSync(path.join(homeDir, '.codex', 'agents', 'brainstormer.toml'), 'name = "b"\n');
|
fs.writeFileSync(path.join(homeDir, '.codex', 'agents', 'brainstormer.toml'), 'name = "b"\n');
|
||||||
fs.mkdirSync(path.join(homeDir, '.codex', 'skills'), { recursive: true });
|
fs.mkdirSync(path.join(homeDir, '.codex', 'skills'), { recursive: true });
|
||||||
fs.writeFileSync(path.join(homeDir, '.codex', 'skills', 'review.md'), '# Review\n');
|
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 });
|
fs.mkdirSync(path.join(ccsHome, '.ccs'), { recursive: true });
|
||||||
process.env.CCS_HOME = ccsHome;
|
process.env.CCS_HOME = ccsHome;
|
||||||
spyOn(os, 'homedir').mockReturnValue(homeDir);
|
spyOn(os, 'homedir').mockReturnValue(homeDir);
|
||||||
@@ -96,6 +114,21 @@ describe('handleCreateCodex — happy path', () => {
|
|||||||
expect(fs.existsSync(instancesDir)).toBe(true);
|
expect(fs.existsSync(instancesDir)).toBe(true);
|
||||||
expect(fs.lstatSync(path.join(instancesDir, 'agents')).isSymbolicLink()).toBe(true);
|
expect(fs.lstatSync(path.join(instancesDir, 'agents')).isSymbolicLink()).toBe(true);
|
||||||
expect(fs.lstatSync(path.join(instancesDir, 'skills')).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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user