@orchagent/cli 0.3.28 → 0.3.31
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.
- package/dist/commands/agents.js +87 -10
- package/dist/commands/billing.js +122 -0
- package/dist/commands/call.js +85 -1
- package/dist/commands/index.js +8 -0
- package/dist/commands/info.js +56 -3
- package/dist/commands/install.js +64 -5
- package/dist/commands/pricing.js +72 -0
- package/dist/commands/publish.js +71 -0
- package/dist/commands/run.js +50 -0
- package/dist/commands/search.js +15 -0
- package/dist/commands/security.js +344 -0
- package/dist/commands/seller.js +142 -0
- package/dist/commands/skill.js +83 -8
- package/dist/commands/whoami.js +8 -0
- package/dist/index.js +4 -0
- package/dist/lib/api.js +41 -0
- package/dist/lib/errors.js +2 -0
- package/dist/lib/output.js +5 -1
- package/dist/lib/pricing.js +22 -0
- package/package.json +4 -3
- package/dist/commands/llm-config.js +0 -40
- package/dist/commands/publish.test.js +0 -475
- package/dist/commands/run.test.js +0 -330
- package/dist/lib/api.test.js +0 -230
- package/dist/lib/config.test.js +0 -144
package/dist/lib/config.test.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Tests for config loading and saving.
|
|
4
|
-
*
|
|
5
|
-
* These tests cover the security-critical config management:
|
|
6
|
-
* - Loading config from file
|
|
7
|
-
* - Saving config with proper permissions
|
|
8
|
-
* - Config resolution priority (overrides > env > file)
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
const vitest_1 = require("vitest");
|
|
15
|
-
const path_1 = __importDefault(require("path"));
|
|
16
|
-
const os_1 = __importDefault(require("os"));
|
|
17
|
-
// Mock fs/promises
|
|
18
|
-
vitest_1.vi.mock('fs/promises', () => ({
|
|
19
|
-
default: {
|
|
20
|
-
readFile: vitest_1.vi.fn(),
|
|
21
|
-
writeFile: vitest_1.vi.fn(),
|
|
22
|
-
mkdir: vitest_1.vi.fn(),
|
|
23
|
-
chmod: vitest_1.vi.fn(),
|
|
24
|
-
},
|
|
25
|
-
}));
|
|
26
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
27
|
-
const config_1 = require("./config");
|
|
28
|
-
(0, vitest_1.describe)('loadConfig', () => {
|
|
29
|
-
(0, vitest_1.beforeEach)(() => {
|
|
30
|
-
vitest_1.vi.resetAllMocks();
|
|
31
|
-
});
|
|
32
|
-
(0, vitest_1.it)('returns empty object when config file missing', async () => {
|
|
33
|
-
const error = new Error('ENOENT');
|
|
34
|
-
error.code = 'ENOENT';
|
|
35
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockRejectedValueOnce(error);
|
|
36
|
-
const config = await (0, config_1.loadConfig)();
|
|
37
|
-
(0, vitest_1.expect)(config).toEqual({});
|
|
38
|
-
});
|
|
39
|
-
(0, vitest_1.it)('parses JSON config file', async () => {
|
|
40
|
-
const configData = {
|
|
41
|
-
api_key: 'sk_test_123',
|
|
42
|
-
api_url: 'https://custom.api.com',
|
|
43
|
-
default_org: 'my-org',
|
|
44
|
-
};
|
|
45
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockResolvedValueOnce(JSON.stringify(configData));
|
|
46
|
-
const config = await (0, config_1.loadConfig)();
|
|
47
|
-
(0, vitest_1.expect)(config).toEqual(configData);
|
|
48
|
-
});
|
|
49
|
-
(0, vitest_1.it)('throws on non-ENOENT errors', async () => {
|
|
50
|
-
const error = new Error('Permission denied');
|
|
51
|
-
error.code = 'EACCES';
|
|
52
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockRejectedValueOnce(error);
|
|
53
|
-
await (0, vitest_1.expect)((0, config_1.loadConfig)()).rejects.toThrow('Permission denied');
|
|
54
|
-
});
|
|
55
|
-
(0, vitest_1.it)('reads from ~/.orchagent/config.json', async () => {
|
|
56
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockResolvedValueOnce('{}');
|
|
57
|
-
await (0, config_1.loadConfig)();
|
|
58
|
-
(0, vitest_1.expect)(promises_1.default.readFile).toHaveBeenCalledWith(path_1.default.join(os_1.default.homedir(), '.orchagent', 'config.json'), 'utf-8');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
(0, vitest_1.describe)('saveConfig', () => {
|
|
62
|
-
(0, vitest_1.beforeEach)(() => {
|
|
63
|
-
vitest_1.vi.resetAllMocks();
|
|
64
|
-
vitest_1.vi.mocked(promises_1.default.mkdir).mockResolvedValue(undefined);
|
|
65
|
-
vitest_1.vi.mocked(promises_1.default.writeFile).mockResolvedValue(undefined);
|
|
66
|
-
vitest_1.vi.mocked(promises_1.default.chmod).mockResolvedValue(undefined);
|
|
67
|
-
});
|
|
68
|
-
(0, vitest_1.it)('creates config directory if missing', async () => {
|
|
69
|
-
await (0, config_1.saveConfig)({ api_key: 'sk_test' });
|
|
70
|
-
(0, vitest_1.expect)(promises_1.default.mkdir).toHaveBeenCalledWith(path_1.default.join(os_1.default.homedir(), '.orchagent'), { recursive: true });
|
|
71
|
-
});
|
|
72
|
-
(0, vitest_1.it)('writes JSON with pretty formatting', async () => {
|
|
73
|
-
const config = { api_key: 'sk_test_123' };
|
|
74
|
-
await (0, config_1.saveConfig)(config);
|
|
75
|
-
(0, vitest_1.expect)(promises_1.default.writeFile).toHaveBeenCalledWith(path_1.default.join(os_1.default.homedir(), '.orchagent', 'config.json'), vitest_1.expect.stringContaining('"api_key": "sk_test_123"'), { mode: 0o600 });
|
|
76
|
-
});
|
|
77
|
-
(0, vitest_1.it)('sets restrictive file permissions (0600)', async () => {
|
|
78
|
-
await (0, config_1.saveConfig)({ api_key: 'sk_test' });
|
|
79
|
-
// First via writeFile options
|
|
80
|
-
(0, vitest_1.expect)(promises_1.default.writeFile).toHaveBeenCalledWith(vitest_1.expect.any(String), vitest_1.expect.any(String), { mode: 0o600 });
|
|
81
|
-
// Then explicitly with chmod
|
|
82
|
-
(0, vitest_1.expect)(promises_1.default.chmod).toHaveBeenCalledWith(path_1.default.join(os_1.default.homedir(), '.orchagent', 'config.json'), 0o600);
|
|
83
|
-
});
|
|
84
|
-
(0, vitest_1.it)('adds trailing newline to file', async () => {
|
|
85
|
-
await (0, config_1.saveConfig)({ api_key: 'test' });
|
|
86
|
-
const writeCall = vitest_1.vi.mocked(promises_1.default.writeFile).mock.calls[0];
|
|
87
|
-
const content = writeCall[1];
|
|
88
|
-
(0, vitest_1.expect)(content.endsWith('\n')).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
(0, vitest_1.describe)('getResolvedConfig', () => {
|
|
92
|
-
const originalEnv = process.env;
|
|
93
|
-
(0, vitest_1.beforeEach)(() => {
|
|
94
|
-
vitest_1.vi.resetAllMocks();
|
|
95
|
-
process.env = { ...originalEnv };
|
|
96
|
-
// Default: no config file
|
|
97
|
-
const error = new Error('ENOENT');
|
|
98
|
-
error.code = 'ENOENT';
|
|
99
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockRejectedValue(error);
|
|
100
|
-
});
|
|
101
|
-
(0, vitest_1.afterEach)(() => {
|
|
102
|
-
process.env = originalEnv;
|
|
103
|
-
});
|
|
104
|
-
(0, vitest_1.it)('uses default API URL when not configured', async () => {
|
|
105
|
-
const config = await (0, config_1.getResolvedConfig)();
|
|
106
|
-
(0, vitest_1.expect)(config.apiUrl).toBe('https://api.orchagent.com');
|
|
107
|
-
});
|
|
108
|
-
(0, vitest_1.it)('reads API key from file config', async () => {
|
|
109
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockResolvedValueOnce(JSON.stringify({ api_key: 'sk_from_file' }));
|
|
110
|
-
const config = await (0, config_1.getResolvedConfig)();
|
|
111
|
-
(0, vitest_1.expect)(config.apiKey).toBe('sk_from_file');
|
|
112
|
-
});
|
|
113
|
-
(0, vitest_1.it)('prioritizes env vars over file config', async () => {
|
|
114
|
-
process.env.ORCHAGENT_API_KEY = 'sk_from_env';
|
|
115
|
-
vitest_1.vi.mocked(promises_1.default.readFile).mockResolvedValueOnce(JSON.stringify({ api_key: 'sk_from_file' }));
|
|
116
|
-
const config = await (0, config_1.getResolvedConfig)();
|
|
117
|
-
(0, vitest_1.expect)(config.apiKey).toBe('sk_from_env');
|
|
118
|
-
});
|
|
119
|
-
(0, vitest_1.it)('prioritizes overrides over env vars', async () => {
|
|
120
|
-
process.env.ORCHAGENT_API_KEY = 'sk_from_env';
|
|
121
|
-
const config = await (0, config_1.getResolvedConfig)({ api_key: 'sk_override' });
|
|
122
|
-
(0, vitest_1.expect)(config.apiKey).toBe('sk_override');
|
|
123
|
-
});
|
|
124
|
-
(0, vitest_1.it)('resolves API URL from env var', async () => {
|
|
125
|
-
process.env.ORCHAGENT_API_URL = 'https://custom.api.com';
|
|
126
|
-
const config = await (0, config_1.getResolvedConfig)();
|
|
127
|
-
(0, vitest_1.expect)(config.apiUrl).toBe('https://custom.api.com');
|
|
128
|
-
});
|
|
129
|
-
(0, vitest_1.it)('resolves default org from env var', async () => {
|
|
130
|
-
process.env.ORCHAGENT_DEFAULT_ORG = 'my-org';
|
|
131
|
-
const config = await (0, config_1.getResolvedConfig)();
|
|
132
|
-
(0, vitest_1.expect)(config.defaultOrg).toBe('my-org');
|
|
133
|
-
});
|
|
134
|
-
(0, vitest_1.it)('returns undefined apiKey when not set anywhere', async () => {
|
|
135
|
-
const config = await (0, config_1.getResolvedConfig)();
|
|
136
|
-
(0, vitest_1.expect)(config.apiKey).toBeUndefined();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
(0, vitest_1.describe)('getConfigPath', () => {
|
|
140
|
-
(0, vitest_1.it)('returns path to config file', () => {
|
|
141
|
-
const configPath = (0, config_1.getConfigPath)();
|
|
142
|
-
(0, vitest_1.expect)(configPath).toBe(path_1.default.join(os_1.default.homedir(), '.orchagent', 'config.json'));
|
|
143
|
-
});
|
|
144
|
-
});
|