agent-gear 2.8.0 → 2.9.0
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/AGENTS.md +11 -1
- package/dist/acp/detector.d.ts +2 -0
- package/dist/acp/detector.d.ts.map +1 -1
- package/dist/acp/detector.js +18 -3
- package/dist/acp/detector.js.map +1 -1
- package/dist/acp/detector.test.d.ts +2 -0
- package/dist/acp/detector.test.d.ts.map +1 -0
- package/dist/acp/detector.test.js +50 -0
- package/dist/acp/detector.test.js.map +1 -0
- package/dist/commands/harness.d.ts +5 -1
- package/dist/commands/harness.d.ts.map +1 -1
- package/dist/commands/harness.js +7 -3
- package/dist/commands/harness.js.map +1 -1
- package/dist/harness/dsh-cli.d.ts +17 -0
- package/dist/harness/dsh-cli.d.ts.map +1 -0
- package/dist/harness/dsh-cli.js +51 -0
- package/dist/harness/dsh-cli.js.map +1 -0
- package/dist/harness/dsh-cli.test.d.ts +2 -0
- package/dist/harness/dsh-cli.test.d.ts.map +1 -0
- package/dist/harness/dsh-cli.test.js +51 -0
- package/dist/harness/dsh-cli.test.js.map +1 -0
- package/dist/harness/dsh-config.atomic-failure.test.d.ts +2 -0
- package/dist/harness/dsh-config.atomic-failure.test.d.ts.map +1 -0
- package/dist/harness/dsh-config.atomic-failure.test.js +35 -0
- package/dist/harness/dsh-config.atomic-failure.test.js.map +1 -0
- package/dist/harness/dsh-config.d.ts +46 -0
- package/dist/harness/dsh-config.d.ts.map +1 -0
- package/dist/harness/dsh-config.js +228 -0
- package/dist/harness/dsh-config.js.map +1 -0
- package/dist/harness/dsh-config.test.d.ts +2 -0
- package/dist/harness/dsh-config.test.d.ts.map +1 -0
- package/dist/harness/dsh-config.test.js +229 -0
- package/dist/harness/dsh-config.test.js.map +1 -0
- package/dist/harness/env.d.ts +11 -0
- package/dist/harness/env.d.ts.map +1 -1
- package/dist/harness/env.js +23 -0
- package/dist/harness/env.js.map +1 -1
- package/dist/harness/env.test.js +23 -1
- package/dist/harness/env.test.js.map +1 -1
- package/dist/harness/opencode-cli.d.ts +5 -0
- package/dist/harness/opencode-cli.d.ts.map +1 -1
- package/dist/harness/opencode-cli.js +8 -1
- package/dist/harness/opencode-cli.js.map +1 -1
- package/dist/harness/prepare.d.ts +27 -9
- package/dist/harness/prepare.d.ts.map +1 -1
- package/dist/harness/prepare.js +67 -23
- package/dist/harness/prepare.js.map +1 -1
- package/dist/harness/prepare.test.js +110 -3
- package/dist/harness/prepare.test.js.map +1 -1
- package/dist/socketio-client.auth-gate.test.js +3 -3
- package/package.json +3 -2
- package/src/acp/detector.test.ts +64 -0
- package/src/acp/detector.ts +18 -3
- package/src/commands/harness.ts +9 -3
- package/src/harness/dsh-cli.test.ts +58 -0
- package/src/harness/dsh-cli.ts +67 -0
- package/src/harness/dsh-config.atomic-failure.test.ts +51 -0
- package/src/harness/dsh-config.test.ts +275 -0
- package/src/harness/dsh-config.ts +280 -0
- package/src/harness/env.test.ts +32 -1
- package/src/harness/env.ts +26 -0
- package/src/harness/opencode-cli.ts +9 -2
- package/src/harness/prepare.test.ts +129 -3
- package/src/harness/prepare.ts +103 -27
- package/src/socketio-client.auth-gate.test.ts +3 -3
- package/tests/acp-detector.test.ts +28 -8
- package/tests/commands/harness.test.ts +17 -7
- package/tests/socketio-client.test.ts +2 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { DshCliError, verifyDshCli } from './dsh-cli.js';
|
|
3
|
+
import type { CommandRunner } from './opencode-cli.js';
|
|
4
|
+
|
|
5
|
+
describe('verifyDshCli (T-CLI1)', () => {
|
|
6
|
+
it('runs `dsh --version` and returns the prerelease version unchanged', async () => {
|
|
7
|
+
const runner = vi.fn<CommandRunner>(async () => ({ stdout: '0.1.2-alpha.2\n', stderr: '' }));
|
|
8
|
+
|
|
9
|
+
await expect(verifyDshCli(runner)).resolves.toBe('0.1.2-alpha.2');
|
|
10
|
+
expect(runner).toHaveBeenCalledWith('dsh', ['--version']);
|
|
11
|
+
expect(runner).toHaveBeenCalledTimes(1);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('accepts the exact pinned version (v prefix / command prefix tolerated)', async () => {
|
|
15
|
+
const runner = vi.fn<CommandRunner>(async () => ({ stdout: 'v0.1.2-alpha.2\n', stderr: '' }));
|
|
16
|
+
await expect(verifyDshCli(runner, '0.1.2-alpha.2')).resolves.toBe('0.1.2-alpha.2');
|
|
17
|
+
|
|
18
|
+
const prefixed = vi.fn<CommandRunner>(async () => ({ stdout: 'dsh 0.1.2-alpha.2\n', stderr: '' }));
|
|
19
|
+
await expect(verifyDshCli(prefixed, '0.1.2-alpha.2')).resolves.toBe('dsh 0.1.2-alpha.2');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('fails on a version mismatch without leaking secrets', async () => {
|
|
23
|
+
const runner = vi.fn<CommandRunner>(async () => ({ stdout: '0.1.1\n', stderr: '' }));
|
|
24
|
+
let error: unknown;
|
|
25
|
+
try {
|
|
26
|
+
await verifyDshCli(runner, '0.1.2-alpha.2');
|
|
27
|
+
} catch (caught) {
|
|
28
|
+
error = caught;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
expect(error).toBeInstanceOf(DshCliError);
|
|
32
|
+
const message = (error as Error).message;
|
|
33
|
+
expect(message).toContain('version mismatch');
|
|
34
|
+
expect(message).toContain('0.1.2-alpha.2');
|
|
35
|
+
expect(message).toContain('0.1.1');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('fails when dsh prints no version output', async () => {
|
|
39
|
+
const runner = vi.fn<CommandRunner>(async () => ({ stdout: ' \n', stderr: '' }));
|
|
40
|
+
await expect(verifyDshCli(runner)).rejects.toBeInstanceOf(DshCliError);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('fails when the dsh command is missing', async () => {
|
|
44
|
+
const runner = vi.fn<CommandRunner>(async () => {
|
|
45
|
+
throw new Error('spawn dsh ENOENT');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
let error: unknown;
|
|
49
|
+
try {
|
|
50
|
+
await verifyDshCli(runner);
|
|
51
|
+
} catch (caught) {
|
|
52
|
+
error = caught;
|
|
53
|
+
}
|
|
54
|
+
expect(error).toBeInstanceOf(DshCliError);
|
|
55
|
+
expect((error as Error).message).toContain('dsh --version');
|
|
56
|
+
expect((error as Error).message).toContain('ENOENT');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { extractVersion, normalizeCliVersion, type CommandRunner } from './opencode-cli.js';
|
|
3
|
+
|
|
4
|
+
/** `dsh --version` 硬校验失败。 */
|
|
5
|
+
export class DshCliError extends Error {
|
|
6
|
+
constructor(message: string) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'DshCliError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
13
|
+
|
|
14
|
+
/** 生产默认执行器:`dsh --version`(预发布段原样返回)。 */
|
|
15
|
+
const defaultRunner: CommandRunner = (command, args) =>
|
|
16
|
+
new Promise((resolve, reject) => {
|
|
17
|
+
execFile(
|
|
18
|
+
command,
|
|
19
|
+
args,
|
|
20
|
+
{ timeout: DEFAULT_TIMEOUT_MS, maxBuffer: 1024 * 1024, encoding: 'utf8' },
|
|
21
|
+
(error, stdout, stderr) => {
|
|
22
|
+
if (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
resolve({ stdout: stdout ?? '', stderr: stderr ?? '' });
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `dsh --version` 硬校验(计划 §3 B2):
|
|
33
|
+
*
|
|
34
|
+
* - 版本归一化与 `verifyOpencodeCli` 完全一致(首个非空行 + 末段 + 去 `v` 前缀),
|
|
35
|
+
* `0.1.2-alpha.2` 预发布段原样比较(不引入 semver);
|
|
36
|
+
* - `expectedVersion` 非空时要求严格相等;init 脚本已固定双包版本,agent-gear 侧二次校验;
|
|
37
|
+
* - 只有 `--version`,不做 `-v` 回退(dsh 无该兼容需求)。
|
|
38
|
+
*
|
|
39
|
+
* 失败抛 {@link DshCliError},消息只包含命令与版本信息,不含任何 env/secret。
|
|
40
|
+
*/
|
|
41
|
+
export async function verifyDshCli(
|
|
42
|
+
runner: CommandRunner = defaultRunner,
|
|
43
|
+
expectedVersion?: string,
|
|
44
|
+
): Promise<string> {
|
|
45
|
+
const failures: string[] = [];
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const result = await runner('dsh', ['--version']);
|
|
49
|
+
const version = extractVersion(result.stdout, result.stderr);
|
|
50
|
+
if (version) {
|
|
51
|
+
if (expectedVersion && normalizeCliVersion(version) !== normalizeCliVersion(expectedVersion)) {
|
|
52
|
+
throw new DshCliError(
|
|
53
|
+
`DeepSeek Harness CLI version mismatch: expected ${expectedVersion}, got ${version}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return version;
|
|
57
|
+
}
|
|
58
|
+
failures.push('`dsh --version` returned no version output');
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof DshCliError) throw error;
|
|
61
|
+
failures.push(`\`dsh --version\` failed: ${(error as Error).message}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw new DshCliError(
|
|
65
|
+
`DeepSeek Harness CLI version check failed; dsh is required by the harness workload (${failures.join('; ')})`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const fs = vi.hoisted(() => ({
|
|
4
|
+
chmod: vi.fn(),
|
|
5
|
+
mkdir: vi.fn(),
|
|
6
|
+
readFile: vi.fn(),
|
|
7
|
+
rename: vi.fn(),
|
|
8
|
+
rm: vi.fn(),
|
|
9
|
+
stat: vi.fn(),
|
|
10
|
+
writeFile: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
vi.mock('node:fs/promises', () => fs);
|
|
14
|
+
|
|
15
|
+
import { DshConfigError, writeDshConfig } from './dsh-config.js';
|
|
16
|
+
|
|
17
|
+
const ENV = {
|
|
18
|
+
modelBaseUrl: 'http://admin-api:8002/v1',
|
|
19
|
+
modelApiKey: 'zag_sk_super_secret',
|
|
20
|
+
modelIds: ['model-a'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('T-DSH7 dsh config atomic write failure cleanup', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
vi.clearAllMocks();
|
|
26
|
+
fs.mkdir.mockResolvedValue(undefined);
|
|
27
|
+
fs.chmod.mockResolvedValue(undefined);
|
|
28
|
+
fs.writeFile.mockResolvedValue(undefined);
|
|
29
|
+
fs.rm.mockResolvedValue(undefined);
|
|
30
|
+
// 目标文件不存在 → 走新建分支
|
|
31
|
+
fs.stat.mockRejectedValue(new Error('ENOENT'));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('removes the temp file when rename fails and preserves the original error surface', async () => {
|
|
35
|
+
fs.rename.mockRejectedValue(new Error('rename failed'));
|
|
36
|
+
|
|
37
|
+
await expect(writeDshConfig({ env: ENV, dshHome: '/tmp/opencode-dsh-atomic' })).rejects.toBeInstanceOf(
|
|
38
|
+
DshConfigError,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
42
|
+
expect.stringMatching(/\/tmp\/opencode-dsh-atomic\/profiles\/acp\/\.cordis\.patch\..*\.tmp$/),
|
|
43
|
+
expect.any(String),
|
|
44
|
+
{ encoding: 'utf-8', mode: 0o600 },
|
|
45
|
+
);
|
|
46
|
+
expect(fs.rm).toHaveBeenCalledWith(
|
|
47
|
+
expect.stringMatching(/\/tmp\/opencode-dsh-atomic\/profiles\/acp\/\.cordis\.patch\..*\.tmp$/),
|
|
48
|
+
{ force: true },
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { parse } from 'yaml';
|
|
5
|
+
import { DshConfigError, defaultDshHome, writeDshConfig } from './dsh-config.js';
|
|
6
|
+
|
|
7
|
+
const TMP_BASE = '/tmp/opencode';
|
|
8
|
+
const API_KEY = 'zag_sk_dsh_super_secret';
|
|
9
|
+
|
|
10
|
+
const ENV = {
|
|
11
|
+
modelBaseUrl: 'http://admin-api:8002/v1',
|
|
12
|
+
modelApiKey: API_KEY,
|
|
13
|
+
modelIds: ['model-a', 'model-b'],
|
|
14
|
+
modelContextLengths: { 'model-a': 128000 },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async function makeHome(): Promise<string> {
|
|
18
|
+
await mkdir(TMP_BASE, { recursive: true });
|
|
19
|
+
return mkdtemp(join(TMP_BASE, 'dsh-'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function readYaml(path: string): Promise<unknown> {
|
|
23
|
+
return parse(await readFile(path, 'utf-8'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('writeDshConfig (T-DSH*)', () => {
|
|
27
|
+
const dirs: string[] = [];
|
|
28
|
+
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await Promise.all(dirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('defaultDshHome 优先 DSH_HOME,否则 ~/.dsh', () => {
|
|
34
|
+
expect(defaultDshHome({ DSH_HOME: ' /custom/dsh ' })).toBe('/custom/dsh');
|
|
35
|
+
expect(defaultDshHome({})).toMatch(/\/\.dsh$/);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('T-DSH1: 新建 patch 写入 4 个条目与 ZAG provider,并新建 credentials', async () => {
|
|
39
|
+
const home = await makeHome();
|
|
40
|
+
dirs.push(home);
|
|
41
|
+
|
|
42
|
+
const result = await writeDshConfig({ env: ENV, dshHome: home });
|
|
43
|
+
|
|
44
|
+
expect(result).toMatchObject({
|
|
45
|
+
patchCreated: true,
|
|
46
|
+
credentialsCreated: true,
|
|
47
|
+
modelCount: 2,
|
|
48
|
+
entryCount: 4,
|
|
49
|
+
});
|
|
50
|
+
expect(result.patchPath).toBe(join(home, 'profiles', 'acp', 'cordis.patch.yml'));
|
|
51
|
+
expect(result.credentialsPath).toBe(join(home, '.credentials.yaml'));
|
|
52
|
+
|
|
53
|
+
const patch = (await readYaml(result.patchPath)) as Array<Record<string, any>>;
|
|
54
|
+
expect(patch.map((entry) => entry.id)).toEqual([
|
|
55
|
+
'llm-deepseek',
|
|
56
|
+
'llm-pi-ai',
|
|
57
|
+
'agent-default-model',
|
|
58
|
+
'acp',
|
|
59
|
+
]);
|
|
60
|
+
expect(patch[0]).toEqual({ id: 'llm-deepseek', disabled: true });
|
|
61
|
+
expect(patch[1].config.providers.zag).toMatchObject({
|
|
62
|
+
displayName: 'ZAG',
|
|
63
|
+
apiKeyEnv: 'ZAG_MODEL_API_KEY',
|
|
64
|
+
api: 'openai-completions',
|
|
65
|
+
baseURL: 'http://admin-api:8002/v1',
|
|
66
|
+
models: [
|
|
67
|
+
{ id: 'model-a', name: 'model-a', contextWindow: 128000 },
|
|
68
|
+
{ id: 'model-b', name: 'model-b' },
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
expect(patch[2]).toEqual({
|
|
72
|
+
id: 'agent-default-model',
|
|
73
|
+
config: { provider: 'zag', model: 'model-a' },
|
|
74
|
+
});
|
|
75
|
+
expect(patch[3]).toEqual({
|
|
76
|
+
id: 'acp',
|
|
77
|
+
name: '@deepseek-ai/dsh-acp',
|
|
78
|
+
config: { provider: 'zag', model: 'model-a' },
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const credentials = (await readYaml(result.credentialsPath)) as Record<string, any>;
|
|
82
|
+
expect(credentials).toEqual({ version: 1, refs: { ZAG_MODEL_API_KEY: API_KEY } });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('T-DSH2/T-DSH3: 合并时只替换我方条目(models 整体替换),其他条目与注释保留', async () => {
|
|
86
|
+
const home = await makeHome();
|
|
87
|
+
dirs.push(home);
|
|
88
|
+
const profilesDir = join(home, 'profiles', 'acp');
|
|
89
|
+
await mkdir(profilesDir, { recursive: true });
|
|
90
|
+
const patchPath = join(profilesDir, 'cordis.patch.yml');
|
|
91
|
+
await writeFile(
|
|
92
|
+
patchPath,
|
|
93
|
+
[
|
|
94
|
+
'# top comment',
|
|
95
|
+
'- id: other',
|
|
96
|
+
' value: 1 # keep inline',
|
|
97
|
+
'- id: llm-pi-ai',
|
|
98
|
+
' config:',
|
|
99
|
+
' providers:',
|
|
100
|
+
' zag:',
|
|
101
|
+
' models:',
|
|
102
|
+
' - id: old-model',
|
|
103
|
+
'- id: agent-default-model',
|
|
104
|
+
' config: { provider: old, model: old-model }',
|
|
105
|
+
'',
|
|
106
|
+
].join('\n'),
|
|
107
|
+
'utf-8',
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
await writeDshConfig({ env: ENV, dshHome: home });
|
|
111
|
+
|
|
112
|
+
const text = await readFile(patchPath, 'utf-8');
|
|
113
|
+
expect(text).toContain('# top comment');
|
|
114
|
+
expect(text).toContain('value: 1 # keep inline');
|
|
115
|
+
const patch = parse(text) as Array<Record<string, any>>;
|
|
116
|
+
expect(patch[0]).toEqual({ id: 'other', value: 1 });
|
|
117
|
+
const zag = patch.find((entry) => entry.id === 'llm-pi-ai')!.config.providers.zag;
|
|
118
|
+
expect(zag.models.map((model: { id: string }) => model.id)).toEqual(['model-a', 'model-b']);
|
|
119
|
+
expect(patch.filter((entry) => entry.id === 'llm-pi-ai')).toHaveLength(1);
|
|
120
|
+
expect(patch.filter((entry) => entry.id === 'llm-deepseek')).toHaveLength(1);
|
|
121
|
+
expect(patch.filter((entry) => entry.id === 'acp')).toHaveLength(1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('T-DSH4: contextWindow 仅在正整数时写入', async () => {
|
|
125
|
+
const home = await makeHome();
|
|
126
|
+
dirs.push(home);
|
|
127
|
+
|
|
128
|
+
await writeDshConfig({
|
|
129
|
+
env: {
|
|
130
|
+
...ENV,
|
|
131
|
+
modelContextLengths: {
|
|
132
|
+
'model-a': 0,
|
|
133
|
+
'model-b': -1,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
dshHome: home,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const patch = (await readYaml(join(home, 'profiles', 'acp', 'cordis.patch.yml'))) as Array<
|
|
140
|
+
Record<string, any>
|
|
141
|
+
>;
|
|
142
|
+
const models = patch.find((entry) => entry.id === 'llm-pi-ai')!.config.providers.zag.models;
|
|
143
|
+
expect(models).toEqual([
|
|
144
|
+
{ id: 'model-a', name: 'model-a' },
|
|
145
|
+
{ id: 'model-b', name: 'model-b' },
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('T-DSH5: credentials 合并只替换 refs.ZAG_MODEL_API_KEY,保留其它 refs/records 与注释', async () => {
|
|
150
|
+
const home = await makeHome();
|
|
151
|
+
dirs.push(home);
|
|
152
|
+
await mkdir(home, { recursive: true });
|
|
153
|
+
const credentialsPath = join(home, '.credentials.yaml');
|
|
154
|
+
await writeFile(
|
|
155
|
+
credentialsPath,
|
|
156
|
+
[
|
|
157
|
+
'# credentials comment',
|
|
158
|
+
'version: 1',
|
|
159
|
+
'refs:',
|
|
160
|
+
' OTHER: keep-me',
|
|
161
|
+
'records:',
|
|
162
|
+
' github: token # keep record',
|
|
163
|
+
'',
|
|
164
|
+
].join('\n'),
|
|
165
|
+
'utf-8',
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const result = await writeDshConfig({ env: ENV, dshHome: home });
|
|
169
|
+
|
|
170
|
+
expect(result.credentialsCreated).toBe(false);
|
|
171
|
+
const text = await readFile(credentialsPath, 'utf-8');
|
|
172
|
+
expect(text).toContain('# credentials comment');
|
|
173
|
+
expect(text).toContain('token # keep record');
|
|
174
|
+
const credentials = parse(text) as Record<string, any>;
|
|
175
|
+
expect(credentials.version).toBe(1);
|
|
176
|
+
expect(credentials.refs).toEqual({ OTHER: 'keep-me', ZAG_MODEL_API_KEY: API_KEY });
|
|
177
|
+
expect(credentials.records).toEqual({ github: 'token' });
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('T-DSH6: 目录 0700、两文件 0600', async () => {
|
|
181
|
+
const home = await makeHome();
|
|
182
|
+
dirs.push(home);
|
|
183
|
+
|
|
184
|
+
const result = await writeDshConfig({ env: ENV, dshHome: home });
|
|
185
|
+
|
|
186
|
+
expect((await stat(join(home, 'profiles', 'acp'))).mode & 0o777).toBe(0o700);
|
|
187
|
+
expect((await stat(result.patchPath)).mode & 0o777).toBe(0o600);
|
|
188
|
+
expect((await stat(result.credentialsPath)).mode & 0o777).toBe(0o600);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('T-DSH8: 非法 YAML 抛错且不覆盖既有文件', async () => {
|
|
192
|
+
const home = await makeHome();
|
|
193
|
+
dirs.push(home);
|
|
194
|
+
const profilesDir = join(home, 'profiles', 'acp');
|
|
195
|
+
await mkdir(profilesDir, { recursive: true });
|
|
196
|
+
const patchPath = join(profilesDir, 'cordis.patch.yml');
|
|
197
|
+
const broken = '- id: broken\n config: [unclosed\n';
|
|
198
|
+
await writeFile(patchPath, broken, 'utf-8');
|
|
199
|
+
|
|
200
|
+
await expect(writeDshConfig({ env: ENV, dshHome: home })).rejects.toBeInstanceOf(DshConfigError);
|
|
201
|
+
expect(await readFile(patchPath, 'utf-8')).toBe(broken);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('T-DSH8b: credentials 结构非法时抛错且不写 patch', async () => {
|
|
205
|
+
const home = await makeHome();
|
|
206
|
+
dirs.push(home);
|
|
207
|
+
await mkdir(home, { recursive: true });
|
|
208
|
+
const credentialsPath = join(home, '.credentials.yaml');
|
|
209
|
+
const broken = 'version: 1\nrefs: not-a-map\n';
|
|
210
|
+
await writeFile(credentialsPath, broken, 'utf-8');
|
|
211
|
+
|
|
212
|
+
await expect(writeDshConfig({ env: ENV, dshHome: home })).rejects.toBeInstanceOf(DshConfigError);
|
|
213
|
+
expect(await readFile(credentialsPath, 'utf-8')).toBe(broken);
|
|
214
|
+
await expect(stat(join(home, 'profiles', 'acp', 'cordis.patch.yml'))).rejects.toThrow();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('T-DSH9: 空模型清单不写 model 字段、modelCount=0、不抛错', async () => {
|
|
218
|
+
const home = await makeHome();
|
|
219
|
+
dirs.push(home);
|
|
220
|
+
|
|
221
|
+
const result = await writeDshConfig({
|
|
222
|
+
env: { ...ENV, modelIds: [], modelContextLengths: {} },
|
|
223
|
+
dshHome: home,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(result.modelCount).toBe(0);
|
|
227
|
+
const patch = (await readYaml(result.patchPath)) as Array<Record<string, any>>;
|
|
228
|
+
expect(patch.find((entry) => entry.id === 'agent-default-model')!.config).toEqual({
|
|
229
|
+
provider: 'zag',
|
|
230
|
+
});
|
|
231
|
+
expect(patch.find((entry) => entry.id === 'acp')!.config).toEqual({ provider: 'zag' });
|
|
232
|
+
const zag = patch.find((entry) => entry.id === 'llm-pi-ai')!.config.providers.zag;
|
|
233
|
+
expect(zag.models).toEqual([]);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('T-DSH10: 二次执行结果等价(条目不重复、权限不漂移)', async () => {
|
|
237
|
+
const home = await makeHome();
|
|
238
|
+
dirs.push(home);
|
|
239
|
+
|
|
240
|
+
const first = await writeDshConfig({ env: ENV, dshHome: home });
|
|
241
|
+
const firstPatch = await readFile(first.patchPath, 'utf-8');
|
|
242
|
+
const firstCredentials = await readFile(first.credentialsPath, 'utf-8');
|
|
243
|
+
|
|
244
|
+
const second = await writeDshConfig({ env: ENV, dshHome: home });
|
|
245
|
+
|
|
246
|
+
expect(second.patchCreated).toBe(false);
|
|
247
|
+
expect(second.credentialsCreated).toBe(false);
|
|
248
|
+
expect(await readFile(second.patchPath, 'utf-8')).toBe(firstPatch);
|
|
249
|
+
expect(await readFile(second.credentialsPath, 'utf-8')).toBe(firstCredentials);
|
|
250
|
+
const patch = parse(firstPatch) as Array<Record<string, any>>;
|
|
251
|
+
expect(patch).toHaveLength(4);
|
|
252
|
+
expect((await stat(second.patchPath)).mode & 0o777).toBe(0o600);
|
|
253
|
+
expect((await stat(join(home, 'profiles', 'acp'))).mode & 0o777).toBe(0o700);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('T-DSH11: 返回值/错误信息不含 API Key', async () => {
|
|
257
|
+
const home = await makeHome();
|
|
258
|
+
dirs.push(home);
|
|
259
|
+
|
|
260
|
+
const result = await writeDshConfig({ env: ENV, dshHome: home });
|
|
261
|
+
expect(JSON.stringify(result)).not.toContain(API_KEY);
|
|
262
|
+
|
|
263
|
+
const brokenHome = await makeHome();
|
|
264
|
+
dirs.push(brokenHome);
|
|
265
|
+
const profilesDir = join(brokenHome, 'profiles', 'acp');
|
|
266
|
+
await mkdir(profilesDir, { recursive: true });
|
|
267
|
+
await writeFile(join(profilesDir, 'cordis.patch.yml'), '- broken: [\n', 'utf-8');
|
|
268
|
+
try {
|
|
269
|
+
await writeDshConfig({ env: ENV, dshHome: brokenHome });
|
|
270
|
+
expect.unreachable();
|
|
271
|
+
} catch (error) {
|
|
272
|
+
expect(JSON.stringify((error as Error).message)).not.toContain(API_KEY);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|