Skip to content

Commit

Permalink
feat: support hostname is an IP
Browse files Browse the repository at this point in the history
  • Loading branch information
savoygu committed Feb 18, 2024
1 parent a0a5e18 commit 0998e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const configParsers = {
return 'api.openai.com';
}

// eslint-disable-next-line regexp/no-unused-capturing-group
parseAssert('hostname', /^([a-zA-Z\d-]+\.)*[a-zA-Z\d-]+\.[a-zA-Z]+$/.test(hostname), 'Must be an hostname');
parseAssert('hostname', /^(?:[a-zA-Z\d](?:[a-zA-Z\d-]{0,61}[a-zA-Z\d])?\.)+[a-zA-Z]{2,}$/.test(hostname)
|| /^(?:\d{1,3}\.){3}\d{1,3}$/.test(hostname), 'Must be an hostname');

return hostname;
},
Expand Down
16 changes: 11 additions & 5 deletions tests/specs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,22 @@ export default testSuite(({ describe }) => {
});

test('updates config', async () => {
const defaultConfig = await aicommits(['config', 'get', 'hostname']);
expect(defaultConfig.stdout).toBe('hostname=api.openai.com');
let hostname = 'hostname=api.chatanywhere.com.cn';
await aicommits(['config', 'set', hostname]);

let configFile = await fs.readFile(configPath, 'utf8');
expect(configFile).toMatch(hostname);

const hostname = 'hostname=api.chatanywhere.com.cn';
let get = await aicommits(['config', 'get', 'hostname']);
expect(get.stdout).toBe(hostname);

hostname = 'hostname=127.0.0.1';
await aicommits(['config', 'set', hostname]);

const configFile = await fs.readFile(configPath, 'utf8');
configFile = await fs.readFile(configPath, 'utf8');
expect(configFile).toMatch(hostname);

const get = await aicommits(['config', 'get', 'hostname']);
get = await aicommits(['config', 'get', 'hostname']);
expect(get.stdout).toBe(hostname);
});
});
Expand Down

0 comments on commit 0998e39

Please sign in to comment.