@boyingliu01/xp-gate 0.39.2 → 0.39.3
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/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/reinstall-xp-gate/.architecture-skip +8 -0
- package/plugins/dsh/skills/reinstall-xp-gate/.github/workflows/test.yml +106 -0
- package/plugins/dsh/skills/reinstall-xp-gate/CHANGELOG.md +379 -0
- package/plugins/dsh/skills/reinstall-xp-gate/LICENSE +21 -0
- package/plugins/dsh/skills/reinstall-xp-gate/QUALITY-OVERVIEW.md +173 -0
- package/plugins/dsh/skills/reinstall-xp-gate/README.md +167 -0
- package/plugins/dsh/skills/reinstall-xp-gate/SKILL.md +271 -0
- package/plugins/dsh/skills/reinstall-xp-gate/TODO.md +253 -0
- package/plugins/dsh/skills/reinstall-xp-gate/VERSION +1 -0
- package/plugins/dsh/skills/reinstall-xp-gate/package.json +28 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/audit.mjs +193 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/coverage.mjs +140 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/hp-gate.mjs +175 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/install.mjs +64 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/agent-paths.mjs +67 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/agents.mjs +247 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/backups.mjs +96 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/baseline.mjs +101 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/ccn.mjs +124 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/delphi.mjs +61 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/fs-tree.mjs +108 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/gatecheck.mjs +290 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/json-file.mjs +37 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/mutations.mjs +154 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/platform.mjs +92 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/probes.mjs +128 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/proc.mjs +33 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/report.mjs +29 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/residue.mjs +188 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/selfsync.mjs +75 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/skills.mjs +121 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/spawn.mjs +181 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/testreport.mjs +26 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/tools.mjs +238 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/util.mjs +33 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/verdict.mjs +45 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/version.mjs +29 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/lib/xp-cli.mjs +66 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/mutation.mjs +132 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/preflight.mjs +75 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/reinstall.mjs +305 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/setup-wsl.sh +633 -0
- package/plugins/dsh/skills/reinstall-xp-gate/scripts/verify.mjs +239 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/agents.test.mjs +168 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/baseline.test.mjs +104 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/ccn.test.mjs +87 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/cleanup.test.mjs +128 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/coverage.test.mjs +69 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/delphi.test.mjs +78 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/fixtures.mjs +61 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/gatecheck-audit.test.mjs +157 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/gatecheck.test.mjs +57 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/mutation-anchors.test.mjs +49 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/proc-contract.test.mjs +58 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/proc.test.mjs +255 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/report.test.mjs +66 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/residue.test.mjs +278 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/selfsync.test.mjs +70 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/skills.test.mjs +171 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/testreport.test.mjs +40 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/timeout-budgets.test.mjs +38 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/tools-leaf.test.mjs +323 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/tools-probe.test.mjs +350 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/tools.test.mjs +131 -0
- package/plugins/dsh/skills/reinstall-xp-gate/tests/util.test.mjs +154 -0
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
HOME, packageDir, runNpm, xpJson, gitConfig, XP_GATE_SLOW_OP_TIMEOUT_MS,
|
|
6
|
+
} from './lib/proc.mjs';
|
|
7
|
+
import { discoverSkillRoots, nativeDelphiAgents, agentInstalled } from './lib/agents.mjs';
|
|
8
|
+
import { planSkillCopies, summarizeRows } from './lib/skills.mjs';
|
|
9
|
+
import { toolReport, cmpVersion } from './lib/tools.mjs';
|
|
10
|
+
import { npmLatestOfficial } from './lib/probes.mjs';
|
|
11
|
+
import { readJson, isDir, isFile } from './lib/util.mjs';
|
|
12
|
+
import { delphiSeats, seatModel, distinctModels } from './lib/delphi.mjs';
|
|
13
|
+
import { section, table, note } from './lib/report.mjs';
|
|
14
|
+
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const quick = args.includes('--quick');
|
|
17
|
+
const asJson = args.includes('--json');
|
|
18
|
+
const checks = [];
|
|
19
|
+
|
|
20
|
+
function add(name, status, detail) {
|
|
21
|
+
checks.push({ name, status, detail });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const pkg = packageDir();
|
|
25
|
+
const version = pkg ? readJson(path.join(pkg, 'package.json'))?.version || '' : '';
|
|
26
|
+
if (!pkg || !version) {
|
|
27
|
+
add('npm package', 'FAIL', '未找到全局安装的 @boyingliu01/xp-gate');
|
|
28
|
+
} else {
|
|
29
|
+
add('npm package', 'PASS', `${version} @ ${pkg}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!quick && version) {
|
|
33
|
+
const latest = String(runNpm(['view', '@boyingliu01/xp-gate', 'version', '--prefer-online'], { timeout: 60000 }).stdout || '').trim();
|
|
34
|
+
// Ask the official registry too: the configured registry may be a mirror that
|
|
35
|
+
// has not synced the newest release yet, and "mirror latest" is not "latest".
|
|
36
|
+
const official = npmLatestOfficial('@boyingliu01/xp-gate');
|
|
37
|
+
if (official && cmpVersion(version, official) < 0) {
|
|
38
|
+
const mirrorNote = latest && cmpVersion(latest, official) < 0
|
|
39
|
+
? `;配置的镜像/源只到 ${latest}(已滞后,改用官方源或 npm view --registry 复核)`
|
|
40
|
+
: '';
|
|
41
|
+
add('registry latest', 'FAIL', `已安装 ${version},官方源 latest ${official}${mirrorNote}`);
|
|
42
|
+
} else if (!latest) {
|
|
43
|
+
add('registry latest', 'WARN', '无法查询 npm registry(离线?)');
|
|
44
|
+
} else if (cmpVersion(version, latest) < 0) {
|
|
45
|
+
add('registry latest', 'FAIL', `已安装 ${version},latest ${latest}`);
|
|
46
|
+
} else if (official && cmpVersion(latest, official) < 0) {
|
|
47
|
+
// The configured source answers PASS but is behind the real release.
|
|
48
|
+
add('registry latest', 'WARN',
|
|
49
|
+
`已安装 ${version} = 配置源 latest ${latest},但官方源已到 ${official};此 PASS 未覆盖官方源`);
|
|
50
|
+
} else {
|
|
51
|
+
add('registry latest', 'PASS', `已安装 ${version} = latest ${latest}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const cfgDir = path.join(HOME, '.config', 'xp-gate');
|
|
56
|
+
const cfg = readJson(path.join(cfgDir, 'xp-gate.json'));
|
|
57
|
+
if (!cfg) {
|
|
58
|
+
add('config', 'FAIL', `${path.join(cfgDir, 'xp-gate.json')} 不存在`);
|
|
59
|
+
} else if (cfg.mode !== 'global') {
|
|
60
|
+
add('config', 'FAIL', `mode=${cfg.mode || '(空)'},全局安装后应为 global(hint: xp-gate install --global)`);
|
|
61
|
+
} else {
|
|
62
|
+
add('config', 'PASS', `mode=global templateDir=${cfg.templateDir || 'n/a'}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const hooksPath = gitConfig('core.hooksPath');
|
|
66
|
+
if (!hooksPath) {
|
|
67
|
+
add('core.hooksPath', 'FAIL', '未设置;init 未生效');
|
|
68
|
+
} else if (!isDir(hooksPath)) {
|
|
69
|
+
add('core.hooksPath', 'FAIL', `${hooksPath} 不存在`);
|
|
70
|
+
} else {
|
|
71
|
+
const required = ['pre-commit', 'pre-push', 'post-merge'];
|
|
72
|
+
const missing = required.filter((n) => !isFile(path.join(hooksPath, n)));
|
|
73
|
+
if (missing.length) add('hooks', 'FAIL', `${hooksPath} 缺少 ${missing.join(', ')}`);
|
|
74
|
+
else add('hooks', 'PASS', `${hooksPath} 含 ${required.join('/')}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A doctor check that can only ever fail because an agent is not installed.
|
|
79
|
+
*
|
|
80
|
+
* `doctor-tui.js` requires `~/.config/opencode/tui.json` unconditionally and
|
|
81
|
+
* reports "TUI registration: FAIL / Not registered" when it is absent, without
|
|
82
|
+
* checking whether OpenCode exists. After OpenCode is removed that check is
|
|
83
|
+
* unsatisfiable by design: the only way to pass it is to reinstall the editor
|
|
84
|
+
* the user deleted. Reporting it as a failure would make this audit
|
|
85
|
+
* permanently red for a correct configuration, and quietly PASSing it would
|
|
86
|
+
* hide a real misconfiguration on a machine that DOES use OpenCode -- which is
|
|
87
|
+
* why the branch is gated on the CLI actually being absent.
|
|
88
|
+
*/
|
|
89
|
+
function isVacuousForMissingAgent(check) {
|
|
90
|
+
return /TUI registration/i.test(String(check.name)) && !agentInstalled('OpenCode');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const doctor = xpJson(['doctor', '--json'], { timeout: XP_GATE_SLOW_OP_TIMEOUT_MS });
|
|
94
|
+
if (!doctor.json?.checks) {
|
|
95
|
+
add('doctor', 'FAIL', `doctor --json 无输出: ${String(doctor.stderr || '').slice(0, 200)}`);
|
|
96
|
+
} else {
|
|
97
|
+
const fails = doctor.json.checks
|
|
98
|
+
.filter((c) => String(c.status).toUpperCase() === 'FAIL')
|
|
99
|
+
.filter((c) => !isVacuousForMissingAgent(c));
|
|
100
|
+
const warns = doctor.json.checks.filter((c) => String(c.status).toUpperCase() === 'WARN');
|
|
101
|
+
const dropped = doctor.json.checks
|
|
102
|
+
.filter((c) => String(c.status).toUpperCase() === 'FAIL')
|
|
103
|
+
.filter((c) => isVacuousForMissingAgent(c));
|
|
104
|
+
if (dropped.length) {
|
|
105
|
+
// Named out loud rather than silently dropped: "we ignored a FAIL" must be
|
|
106
|
+
// visible, or the next reader cannot tell a tolerated gap from a clean run.
|
|
107
|
+
add('doctor (not applicable)', 'SKIP', dropped.map((c) => `${c.name}: ${c.detail} — OpenCode 未安装`).join(' | '));
|
|
108
|
+
}
|
|
109
|
+
if (fails.length) add('doctor', 'FAIL', fails.map((c) => `${c.name}: ${c.detail}`).join(' | '));
|
|
110
|
+
else add('doctor', warns.length ? 'WARN' : 'PASS', warns.length ? warns.map((c) => `${c.name}: ${c.detail}`).join(' | ') : `ok=${doctor.json.ok}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const delphi = readJson(path.join(cfgDir, '.delphi-config.json'));
|
|
114
|
+
if (!delphi) {
|
|
115
|
+
add('delphi config', 'FAIL', `${path.join(cfgDir, '.delphi-config.json')} 不存在(purge 后未恢复?)`);
|
|
116
|
+
} else {
|
|
117
|
+
const channels = delphi.channels || [];
|
|
118
|
+
// Seats come from profiles[active_profile].experts, which is the shipped
|
|
119
|
+
// shape; a legacy top-level `pinned_models` is still accepted. See
|
|
120
|
+
// lib/delphi.mjs for why reading only `pinned_models` reported "0 席" for a
|
|
121
|
+
// valid config and left every verify run permanently red.
|
|
122
|
+
const seats = delphiSeats(delphi);
|
|
123
|
+
const distinct = distinctModels(seats);
|
|
124
|
+
const where = delphi.active_profile
|
|
125
|
+
? `profiles.${delphi.active_profile}.experts`
|
|
126
|
+
: 'pinned_models';
|
|
127
|
+
if (!channels.includes('external')) add('delphi channels', 'FAIL', `channels=${JSON.stringify(channels)},缺少 external`);
|
|
128
|
+
else add('delphi channels', 'PASS', JSON.stringify(channels));
|
|
129
|
+
if (seats.length < 3) add('delphi pinned seats', 'FAIL', `只有 ${seats.length} 席(期望 3 席,取自 ${where})`);
|
|
130
|
+
else if (distinct.size < 3) add('delphi pinned seats', 'FAIL', `${seats.length} 席但只有 ${distinct.size} 个不同模型`);
|
|
131
|
+
else add('delphi pinned seats', 'PASS', seats.map(([k, v]) => `${k}=${seatModel(v)}`).join(', '));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const natives = nativeDelphiAgents();
|
|
135
|
+
if (natives.length) add('native delphi agents', 'FAIL', `${natives.length} 个原生 agent 仍在: ${natives.join(', ')}(external-only 下应为 0)`);
|
|
136
|
+
else add('native delphi agents', 'PASS', '0');
|
|
137
|
+
|
|
138
|
+
const allRoots = discoverSkillRoots();
|
|
139
|
+
const roots = allRoots.filter((r) => r.live);
|
|
140
|
+
const deadRoots = allRoots.filter((r) => !r.live);
|
|
141
|
+
if (!pkg) {
|
|
142
|
+
add('skills parity', 'FAIL', '无发布包,无法比对');
|
|
143
|
+
} else if (roots.length === 0) {
|
|
144
|
+
add('skills parity', 'FAIL', '没有判定为活的 agent skills 根');
|
|
145
|
+
} else {
|
|
146
|
+
const { names, rows } = planSkillCopies(pkg, roots);
|
|
147
|
+
const summary = summarizeRows(rows);
|
|
148
|
+
const bad = [...summary.entries()].filter(([, s]) => s.drift || s.missing);
|
|
149
|
+
// `extra` is not damage: every shipped file matched, the copy simply carries
|
|
150
|
+
// files the package does not ship. ~/xp-gate/skills is a source checkout that
|
|
151
|
+
// legitimately keeps its own __tests__/, and calling that FAIL left verify
|
|
152
|
+
// permanently red on a correct install. Reported so it stays visible.
|
|
153
|
+
const extraneous = rows.filter((r) => r.state === 'extra');
|
|
154
|
+
if (bad.length) {
|
|
155
|
+
add('skills parity', 'FAIL', `${bad.map(([a, s]) => `${a}(drift=${s.drift},missing=${s.missing})`).join('; ')}`);
|
|
156
|
+
} else if (extraneous.length) {
|
|
157
|
+
const detail = extraneous.map((r) => `${r.agent}/${r.name}: ${r.extra.join(', ')}`).join('; ');
|
|
158
|
+
add('skills parity', 'WARN', `${names.length} skills × ${roots.length} agents 内容一致,但副本多了包内没有的文件: ${detail}`);
|
|
159
|
+
} else {
|
|
160
|
+
add('skills parity', 'PASS', `${names.length} skills × ${roots.length} agents 全部一致`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const selfMissing = roots.filter((r) => !isFile(path.join(r.dir, 'reinstall-xp-gate', 'SKILL.md')));
|
|
164
|
+
if (selfMissing.length) add('reinstall-xp-gate copy', 'WARN', `以下 agent 未分发: ${selfMissing.map((r) => r.agent).join(', ')}`);
|
|
165
|
+
else add('reinstall-xp-gate copy', 'PASS', `${roots.length} 个 agent 根均已分发`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (deadRoots.length) {
|
|
169
|
+
add('inactive agent roots', 'WARN', `${deadRoots.length} 个配置目录已判残留(未计入验收): ${deadRoots.map((r) => `${r.agent}(${r.reason})`).join(', ')}`);
|
|
170
|
+
} else {
|
|
171
|
+
add('inactive agent roots', 'PASS', '无残留配置目录');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const opencodeRoot = roots.find((r) => r.dir === path.join(HOME, '.config', 'opencode', 'skills'));
|
|
175
|
+
const opencodePkg = path.join(HOME, '.config', 'opencode', 'node_modules', '@boyingliu01', 'opencode-plugin', 'package.json');
|
|
176
|
+
if (isFile(opencodePkg)) {
|
|
177
|
+
const v = readJson(opencodePkg)?.version || '';
|
|
178
|
+
add('opencode plugin', v === version ? 'PASS' : 'FAIL', `plugin ${v || '?'} vs cli ${version}`);
|
|
179
|
+
} else if (opencodeRoot) {
|
|
180
|
+
add('opencode plugin', 'WARN', `未安装 ${opencodePkg}(该 agent 的插件能力不可用)`);
|
|
181
|
+
} else {
|
|
182
|
+
add('opencode plugin', 'SKIP', '未检测到 OpenCode');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const dshBase = path.join(HOME, '.dsh', 'profiles');
|
|
186
|
+
const dshHits = [];
|
|
187
|
+
if (isDir(dshBase)) {
|
|
188
|
+
for (const entry of fs.readdirSync(dshBase, { withFileTypes: true })) {
|
|
189
|
+
if (!entry.isDirectory()) continue;
|
|
190
|
+
const file = path.join(dshBase, entry.name, 'node_modules', '@boyingliu01', 'dsh-plugin-xp-gate', 'package.json');
|
|
191
|
+
if (isFile(file)) dshHits.push({ profile: entry.name, version: readJson(file)?.version || '' });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!dshHits.length) add('dsh plugin', 'SKIP', '未检测到 DSH profile 插件');
|
|
195
|
+
else {
|
|
196
|
+
const bad = dshHits.filter((h) => h.version !== version);
|
|
197
|
+
add('dsh plugin', bad.length ? 'FAIL' : 'PASS', dshHits.map((h) => `${h.profile}=${h.version}`).join(', ') + ` vs cli ${version}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (quick) {
|
|
201
|
+
add('gate tools', 'SKIP', '--quick 跳过');
|
|
202
|
+
} else {
|
|
203
|
+
const rows = await toolReport();
|
|
204
|
+
const missing = rows.filter((r) => r.status === 'missing');
|
|
205
|
+
const outdated = rows.filter((r) => r.status === 'outdated');
|
|
206
|
+
const unverified = rows.filter((r) => r.status === 'unverified');
|
|
207
|
+
if (missing.length) add('gate tools', 'FAIL', `缺失: ${missing.map((r) => r.name).join(', ')}`);
|
|
208
|
+
else if (outdated.length) add('gate tools', 'WARN', `落后: ${outdated.map((r) => `${r.name} ${r.version}->${r.latest}`).join(', ')}`);
|
|
209
|
+
else add('gate tools', 'PASS', rows.map((r) => `${r.name} ${r.version || '?'}`).join(', '));
|
|
210
|
+
if (unverified.length && !missing.length && !outdated.length) note(`无法判定最新版: ${unverified.map((r) => r.name).join(', ')}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const uninstallBackup = path.join(cfgDir, '.uninstall-backup');
|
|
214
|
+
if (isDir(uninstallBackup)) {
|
|
215
|
+
const count = fs.readdirSync(uninstallBackup).length;
|
|
216
|
+
add('uninstall residue', 'FAIL', `${uninstallBackup} 仍有 ${count} 份历史快照`);
|
|
217
|
+
} else {
|
|
218
|
+
add('uninstall residue', 'PASS', '无 .uninstall-backup');
|
|
219
|
+
}
|
|
220
|
+
const skillBackup = path.join(cfgDir, 'backup');
|
|
221
|
+
if (isDir(skillBackup)) {
|
|
222
|
+
add('skill backup dir', 'WARN', `${skillBackup} 存在(install-skill 覆盖备份,可人工清理)`);
|
|
223
|
+
} else {
|
|
224
|
+
add('skill backup dir', 'PASS', '无覆盖备份残留');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (asJson) {
|
|
228
|
+
console.log(JSON.stringify({ ok: !checks.some((c) => c.status === 'FAIL'), checks }, null, 2));
|
|
229
|
+
} else {
|
|
230
|
+
section('验收结果');
|
|
231
|
+
table(['status', 'check', 'detail'], checks.map((c) => [c.status, c.name, c.detail]));
|
|
232
|
+
const fails = checks.filter((c) => c.status === 'FAIL').length;
|
|
233
|
+
const warns = checks.filter((c) => c.status === 'WARN').length;
|
|
234
|
+
console.log(`\n FAIL=${fails} WARN=${warns} PASS=${checks.filter((c) => c.status === 'PASS').length} SKIP=${checks.filter((c) => c.status === 'SKIP').length}`);
|
|
235
|
+
if (fails === 0) console.log(' 结论:静态验收通过;真实提交与 delphi-review 冒烟仍需人工各跑一次。');
|
|
236
|
+
else console.log(' 结论:存在 FAIL,按上面 detail 修复后重跑 verify。');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
process.exit(checks.some((c) => c.status === 'FAIL') ? 1 : 0);
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
import { labelFor, isOfficialSkillRoot, probeLiveness, agentInstalled, discoverSkillRoots, selfWrittenHome } from '../scripts/lib/agents.mjs';
|
|
8
|
+
import { HOME } from '../scripts/lib/proc.mjs';
|
|
9
|
+
|
|
10
|
+
// discoverSkillRoots() scans the real HOME, so its OUTPUT is not asserted here:
|
|
11
|
+
// that would encode this machine's agent layout into the suite. What IS pinned
|
|
12
|
+
// is that it runs at all. MEASURED: the split that moved looksLikeSkillRoot to
|
|
13
|
+
// agent-paths.mjs left the call in agents.mjs unresolved, and `install.mjs`
|
|
14
|
+
// crashed on every machine with "looksLikeSkillRoot is not defined" -- a
|
|
15
|
+
// function that exists only to decide whether a candidate path is a directory.
|
|
16
|
+
test('discoverSkillRoots runs without throwing', () => {
|
|
17
|
+
const roots = discoverSkillRoots();
|
|
18
|
+
assert.ok(Array.isArray(roots), 'it returns the list of skill roots');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const under = (...parts) => `${HOME}/${parts.join('/')}`;
|
|
22
|
+
|
|
23
|
+
test('labelFor maps known config dirs to their product names', () => {
|
|
24
|
+
assert.equal(labelFor(under('.dsh', 'skills')), 'DSH');
|
|
25
|
+
assert.equal(labelFor(under('.qoder', 'skills')), 'Qoder');
|
|
26
|
+
assert.equal(labelFor(under('.qoder-cn', 'skills')), 'Qoder CN');
|
|
27
|
+
assert.equal(labelFor(under('.config', 'opencode', 'skills')), 'OpenCode');
|
|
28
|
+
assert.equal(labelFor(under('.workbuddy', 'skills')), 'WorkBuddy');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('labelFor derives a readable name for unknown agents', () => {
|
|
32
|
+
// New agents must not need a code change to be labelled sanely.
|
|
33
|
+
assert.equal(labelFor(under('.some-new-agent', 'skills')), 'some new agent');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('isOfficialSkillRoot only accepts the four roots xp-gate itself installs to', () => {
|
|
37
|
+
assert.equal(isOfficialSkillRoot(under('.dsh', 'skills')), true);
|
|
38
|
+
assert.equal(isOfficialSkillRoot(under('.qoder', 'skills')), true);
|
|
39
|
+
assert.equal(isOfficialSkillRoot(under('.trae-cn', 'skills')), false);
|
|
40
|
+
assert.equal(isOfficialSkillRoot(under('.agents', 'skills')), false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('probeLiveness treats the shared skill store as always live', () => {
|
|
44
|
+
// ~/.agents/skills is a shared repo, not one agent's config; it must never be
|
|
45
|
+
// demoted to "residue" or every symlinked agent loses its skills.
|
|
46
|
+
const r = probeLiveness({ agent: 'Generic agents', dir: under('.agents', 'skills') });
|
|
47
|
+
assert.equal(r.live, true);
|
|
48
|
+
assert.equal(r.reason, 'shared skill store');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('probeLiveness reports not-live with a reason for a nonexistent agent dir', () => {
|
|
52
|
+
const r = probeLiveness({ agent: 'No Such Agent', dir: under('.no-such-agent-xyz', 'skills') });
|
|
53
|
+
assert.equal(r.live, false);
|
|
54
|
+
assert.match(r.reason, /no app\/cli|idle/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('probeLiveness always returns both fields, whatever the verdict', () => {
|
|
58
|
+
// Callers destructure live/reason unconditionally; a missing key would print
|
|
59
|
+
// "undefined" into the report table.
|
|
60
|
+
for (const entry of [
|
|
61
|
+
{ agent: 'Generic agents', dir: under('.agents', 'skills') },
|
|
62
|
+
{ agent: 'No Such Agent', dir: under('.nope-xyz', 'skills') },
|
|
63
|
+
]) {
|
|
64
|
+
const r = probeLiveness(entry);
|
|
65
|
+
assert.equal(typeof r.live, 'boolean');
|
|
66
|
+
assert.equal(typeof r.reason, 'string');
|
|
67
|
+
assert.ok(r.reason.length > 0);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('probeLiveness honours the liveDays window argument', () => {
|
|
72
|
+
// A dir that is neither app- nor CLI-backed falls through to the mtime rule.
|
|
73
|
+
const entry = { agent: 'No Such Agent', dir: under('.nope-xyz', 'skills') };
|
|
74
|
+
assert.equal(probeLiveness(entry, 0).live, false);
|
|
75
|
+
// Missing dir -> Infinity days, past any finite window.
|
|
76
|
+
assert.equal(probeLiveness(entry, 100000).live, false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Issue #4: an uninstalled OpenCode stays "live" because xp-gate writes
|
|
81
|
+
* tui.json and skills/ into its config dir, which refreshes the mtime that
|
|
82
|
+
* recency treats as "the user is still here".
|
|
83
|
+
*
|
|
84
|
+
* A home that contains NOTHING but what this toolchain writes is residue.
|
|
85
|
+
* A home that also holds something the agent itself created is not.
|
|
86
|
+
*/
|
|
87
|
+
function home(layout) {
|
|
88
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'xgr-home-'));
|
|
89
|
+
for (const [name, kind] of Object.entries(layout)) {
|
|
90
|
+
const target = path.join(dir, name);
|
|
91
|
+
if (kind === 'dir') fs.mkdirSync(target);
|
|
92
|
+
else fs.writeFileSync(target, kind);
|
|
93
|
+
}
|
|
94
|
+
return dir;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
test('selfWrittenHome is true when the dir holds only xp-gate products', () => {
|
|
98
|
+
const dir = home({ 'tui.json': '{}\n', skills: 'dir' });
|
|
99
|
+
try {
|
|
100
|
+
assert.equal(selfWrittenHome(dir), true);
|
|
101
|
+
} finally {
|
|
102
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('selfWrittenHome is false when the agent left something of its own', () => {
|
|
107
|
+
const dir = home({ 'tui.json': '{}\n', skills: 'dir', 'opencode.json': '{}\n' });
|
|
108
|
+
try {
|
|
109
|
+
assert.equal(selfWrittenHome(dir), false);
|
|
110
|
+
} finally {
|
|
111
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('selfWrittenHome is false for an empty dir, which is a fresh install', () => {
|
|
116
|
+
// An agent that just created its config dir has no skills yet. Calling that
|
|
117
|
+
// residue would skip the machine that most needs them.
|
|
118
|
+
const dir = home({});
|
|
119
|
+
try {
|
|
120
|
+
assert.equal(selfWrittenHome(dir), false);
|
|
121
|
+
} finally {
|
|
122
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('probeLiveness does not call a self-written home active', () => {
|
|
127
|
+
// The measured failure: no app, no CLI, and the only reason the agent looked
|
|
128
|
+
// live was that xp-gate had just written tui.json. Recency must not count
|
|
129
|
+
// that as the user coming back.
|
|
130
|
+
const dir = home({ 'tui.json': '{}\n', skills: 'dir' });
|
|
131
|
+
try {
|
|
132
|
+
const r = probeLiveness(
|
|
133
|
+
{ agent: 'No Such Agent', dir: path.join(dir, 'skills') },
|
|
134
|
+
30,
|
|
135
|
+
() => dir,
|
|
136
|
+
);
|
|
137
|
+
assert.equal(r.live, false);
|
|
138
|
+
assert.match(r.reason, /no app\/cli/);
|
|
139
|
+
} finally {
|
|
140
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('probeLiveness still trusts a recent write the agent made itself', () => {
|
|
145
|
+
const dir = home({ 'tui.json': '{}\n', skills: 'dir', 'opencode.json': '{}\n' });
|
|
146
|
+
try {
|
|
147
|
+
const r = probeLiveness(
|
|
148
|
+
{ agent: 'No Such Agent', dir: path.join(dir, 'skills') },
|
|
149
|
+
30,
|
|
150
|
+
() => dir,
|
|
151
|
+
);
|
|
152
|
+
assert.equal(r.live, true);
|
|
153
|
+
assert.match(r.reason, /active 0d ago/);
|
|
154
|
+
} finally {
|
|
155
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('agentInstalled reports a CLI that is not on PATH as absent', () => {
|
|
160
|
+
// The one consumer is verify.mjs, deciding whether xp-gate's unconditional
|
|
161
|
+
// "TUI registration" check is worth reporting. A CLI that cannot be resolved
|
|
162
|
+
// is the signal that the agent is gone; a config directory alone is not
|
|
163
|
+
// evidence, because leftovers survive an uninstall.
|
|
164
|
+
assert.equal(typeof agentInstalled('OpenCode'), 'boolean');
|
|
165
|
+
// A name with no CLI probe can never be "installed" by this measure.
|
|
166
|
+
assert.equal(agentInstalled('Generic agents'), false);
|
|
167
|
+
assert.equal(agentInstalled('No Such Agent'), false);
|
|
168
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
runsRoot, makeRunDir, snapshotConfig, writeBaseline,
|
|
9
|
+
xpGateInfo, configInfo, delphiInfo, doctorInfo,
|
|
10
|
+
} from '../scripts/lib/baseline.mjs';
|
|
11
|
+
import { HOME } from '../scripts/lib/proc.mjs';
|
|
12
|
+
import { readJson, rmrf } from '../scripts/lib/util.mjs';
|
|
13
|
+
|
|
14
|
+
test('runsRoot lives outside the xp-gate config dir so purge cannot delete it', () => {
|
|
15
|
+
const root = runsRoot();
|
|
16
|
+
// The entire point of the run directory: it must survive
|
|
17
|
+
// `uninstall --purge`, which removes ~/.config/xp-gate wholesale.
|
|
18
|
+
assert.ok(!root.includes(`${path.sep}.config${path.sep}`), `runsRoot must not be under .config: ${root}`);
|
|
19
|
+
assert.ok(root.startsWith(HOME));
|
|
20
|
+
assert.ok(root.includes('reinstall-runs'));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('makeRunDir creates a timestamped directory under runsRoot', (t) => {
|
|
24
|
+
const dir = makeRunDir();
|
|
25
|
+
t.after(() => rmrf(dir));
|
|
26
|
+
|
|
27
|
+
assert.ok(fs.existsSync(dir));
|
|
28
|
+
assert.equal(fs.statSync(dir).isDirectory(), true);
|
|
29
|
+
assert.equal(path.dirname(dir), runsRoot());
|
|
30
|
+
assert.match(path.basename(dir), /^\d{8}-\d{6}$/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('snapshotConfig returns an array of the config filenames it copied', () => {
|
|
34
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'xgr-snap-'));
|
|
35
|
+
try {
|
|
36
|
+
const copied = snapshotConfig(dir);
|
|
37
|
+
assert.ok(Array.isArray(copied));
|
|
38
|
+
// Only these two are user configuration; everything else is regenerable.
|
|
39
|
+
for (const name of copied) {
|
|
40
|
+
assert.ok(['.delphi-config.json', 'xp-gate.json'].includes(name), `unexpected snapshot: ${name}`);
|
|
41
|
+
assert.equal(fs.existsSync(path.join(dir, name)), true, `copied file missing: ${name}`);
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
rmrf(dir);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('writeBaseline writes a readable baseline.json into the run dir', (t) => {
|
|
49
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'xgr-base-'));
|
|
50
|
+
try {
|
|
51
|
+
writeBaseline(dir, { createdAt: 'x', platform: 'test' });
|
|
52
|
+
assert.equal(readJson(path.join(dir, 'baseline.json')).platform, 'test');
|
|
53
|
+
} finally {
|
|
54
|
+
rmrf(dir);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('xpGateInfo reports an empty version when no package is installed', () => {
|
|
59
|
+
const info = xpGateInfo('');
|
|
60
|
+
assert.equal(info.packageDir, '');
|
|
61
|
+
assert.equal(info.version, '');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('xpGateInfo reads the version out of package.json', (t) => {
|
|
65
|
+
const pkg = fs.mkdtempSync(path.join(os.tmpdir(), 'xgr-pkgver-'));
|
|
66
|
+
t.after(() => rmrf(pkg));
|
|
67
|
+
fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify({ version: '9.9.9' }));
|
|
68
|
+
|
|
69
|
+
const info = xpGateInfo(pkg);
|
|
70
|
+
assert.equal(info.packageDir, pkg);
|
|
71
|
+
assert.equal(info.version, '9.9.9');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('configInfo defaults every field instead of emitting undefined', () => {
|
|
75
|
+
const info = configInfo(null);
|
|
76
|
+
assert.equal(typeof info.mode, 'string');
|
|
77
|
+
assert.equal(typeof info.templateDir, 'string');
|
|
78
|
+
assert.equal(typeof info.hooksPath, 'string');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('delphiInfo uses ?? null so empty values survive as empty', () => {
|
|
82
|
+
// `|| null` here would turn a legitimately empty channels list into "unset",
|
|
83
|
+
// silently changing what the baseline records.
|
|
84
|
+
const info = delphiInfo({ channels: [], pinned_models: null, active_profile: '' });
|
|
85
|
+
assert.deepEqual(info.channels, []);
|
|
86
|
+
assert.equal(info.pinned_models, null);
|
|
87
|
+
assert.equal(info.active_profile, '');
|
|
88
|
+
|
|
89
|
+
const empty = delphiInfo(null);
|
|
90
|
+
assert.equal(empty.channels, null);
|
|
91
|
+
assert.equal(empty.pinned_models, null);
|
|
92
|
+
assert.equal(empty.active_profile, null);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('doctorInfo projects the JSON fields when parsing succeeded', () => {
|
|
96
|
+
const info = doctorInfo({ json: { ok: true, issues: [], checks: [1] } });
|
|
97
|
+
assert.deepEqual(info, { ok: true, issues: [], checks: [1] });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('doctorInfo falls back to a truncated stderr when JSON is unavailable', () => {
|
|
101
|
+
const info = doctorInfo({ json: null, stderr: 'x'.repeat(2000) });
|
|
102
|
+
assert.equal('error' in info, true);
|
|
103
|
+
assert.ok(info.error.length <= 500);
|
|
104
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import { parseLizardCsv, ccnViolations, splitCsvLine } from '../scripts/lib/ccn.mjs';
|
|
5
|
+
|
|
6
|
+
// These tests exist because the complexity check silently passed on a tree that
|
|
7
|
+
// contained a CCN-22 function, twice, for two different reasons: lizard was run
|
|
8
|
+
// without --csv (so stdout was empty), and the CSV column indices were wrong (so
|
|
9
|
+
// every row was dropped). Both failures looked exactly like clean code.
|
|
10
|
+
|
|
11
|
+
/** A real lizard 1.26.1 record, copied verbatim apart from the numbers. */
|
|
12
|
+
const REAL_ROW = '13,11,99,1,13,"tangled@1-13@src/a.js","src/a.js","tangled","tangled ( n )",1,13';
|
|
13
|
+
|
|
14
|
+
test('parseLizardCsv reads CCN from column 1, not column 0', () => {
|
|
15
|
+
// Column 0 is NLOC (13 here). A parser reading column 0 reports the wrong
|
|
16
|
+
// number and, worse, ranks a 13-line flat function above a branchy one.
|
|
17
|
+
const [row] = parseLizardCsv(REAL_ROW);
|
|
18
|
+
assert.equal(row.ccn, 11);
|
|
19
|
+
assert.equal(row.nloc, 13);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('parseLizardCsv does not use the token count as complexity', () => {
|
|
23
|
+
// Columns 1 and 2 are adjacent and both plausible-looking numbers. Measured
|
|
24
|
+
// contrast that makes the trap concrete: a branch-free helper is CCN 1 with 54
|
|
25
|
+
// tokens, while a two-branch function is CCN 3 with 25 tokens -- so ranking by
|
|
26
|
+
// tokens orders the code backwards. This fixture pins CCN 1 alongside a much
|
|
27
|
+
// larger token count.
|
|
28
|
+
const flat = '7,1,54,1,7,"simple@1-7@a.js","a.js","simple","simple ( n )",1,7';
|
|
29
|
+
const [row] = parseLizardCsv(flat);
|
|
30
|
+
assert.equal(row.ccn, 1, 'a branch-free function is CCN 1');
|
|
31
|
+
assert.notEqual(row.ccn, 54, 'the token count must never be read as CCN');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('parseLizardCsv keeps the file and the source line of the violation', () => {
|
|
35
|
+
// A violation detached from its file is not actionable; this is what a naive
|
|
36
|
+
// split(',') produces, because lizard's signature cell contains commas.
|
|
37
|
+
const [row] = parseLizardCsv(REAL_ROW);
|
|
38
|
+
assert.equal(row.file, 'src/a.js');
|
|
39
|
+
assert.equal(row.line, 1);
|
|
40
|
+
assert.equal(row.name, 'tangled');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('parseLizardCsv survives a signature containing commas', () => {
|
|
44
|
+
const row = '9,7,80,2,9,"f@5-9@b.js","b.js","f","f ( a , b )",5,9';
|
|
45
|
+
const [parsed] = parseLizardCsv(row);
|
|
46
|
+
assert.equal(parsed.ccn, 7);
|
|
47
|
+
assert.equal(parsed.file, 'b.js');
|
|
48
|
+
assert.equal(parsed.line, 5);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('parseLizardCsv drops non-function lines instead of counting them as CCN 0', () => {
|
|
52
|
+
assert.deepEqual(parseLizardCsv(''), []);
|
|
53
|
+
assert.deepEqual(parseLizardCsv('not,a,function,row'), []);
|
|
54
|
+
assert.deepEqual(parseLizardCsv('\n\n \n'), []);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('parseLizardCsv handles CRLF output', () => {
|
|
58
|
+
// lizard emits CRLF on Windows; a parser splitting on "\n" alone leaves the
|
|
59
|
+
// stray "\r" inside the last numeric cell and Number() becomes NaN.
|
|
60
|
+
const text = `${REAL_ROW}\r\n${REAL_ROW}\r\n`;
|
|
61
|
+
assert.equal(parseLizardCsv(text).length, 2);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('splitCsvLine honours quoted cells', () => {
|
|
65
|
+
assert.deepEqual(splitCsvLine('1,2,3'), ['1', '2', '3']);
|
|
66
|
+
assert.deepEqual(splitCsvLine('1,"a,b",c'), ['1', 'a,b', 'c']);
|
|
67
|
+
assert.deepEqual(splitCsvLine('"a",b'), ['a', 'b']);
|
|
68
|
+
assert.deepEqual(splitCsvLine('a,"b"'), ['a', 'b']);
|
|
69
|
+
assert.deepEqual(splitCsvLine('""'), ['']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('splitCsvLine treats a doubled quote as one literal quote', () => {
|
|
73
|
+
assert.deepEqual(splitCsvLine('"a""b"'), ['a"b']);
|
|
74
|
+
assert.deepEqual(splitCsvLine('"a","b"'), ['a', 'b']);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('ccnViolations blocks strictly above the threshold', () => {
|
|
78
|
+
// Gate 3 blocks above 5, so exactly 5 must pass. An off-by-one here would
|
|
79
|
+
// either block every helper at the limit or let the reference case through.
|
|
80
|
+
const rows = [{ ccn: 4 }, { ccn: 5 }, { ccn: 6 }];
|
|
81
|
+
assert.deepEqual(ccnViolations(rows, 5).map((r) => r.ccn), [6]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('ccnViolations returns everything above a zero threshold', () => {
|
|
85
|
+
const rows = [{ ccn: 1 }, { ccn: 2 }];
|
|
86
|
+
assert.equal(ccnViolations(rows, 0).length, 2);
|
|
87
|
+
});
|