dsh-git-push 2.16.0 → 2.17.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/lib/app/command-registry.js +2 -0
- package/lib/app/tool-call.js +4 -0
- package/lib/git/ci.js +135 -0
- package/lib/git/push.js +31 -3
- package/lib/npm/local-registry.js +25 -1
- package/lib/npm/publish.js +9 -3
- package/lib/npm/smoke.js +51 -0
- package/lib/self/index.js +1 -1
- package/package.json +1 -1
|
@@ -42,6 +42,8 @@ export const TOOL_REGISTRY = [
|
|
|
42
42
|
{ flag: 'auditExemptPaths', type: 'array', desc: '本次提交按文件临时豁免审计(数组,相对仓库根):所列文件的 finding 不参与拦截判定(含 blocker);仅本次有效,不落盘、不改 .auditignore' },
|
|
43
43
|
{ flag: 'auditExemptReason', type: 'string', desc: '豁免理由(可选,仅回显,不作拦截条件)' },
|
|
44
44
|
{ flag: 'remote', type: 'string', desc: '推送目标 remote(多 remote / fork 场景;缺省 origin)。推送与核验使用同一 remote' },
|
|
45
|
+
{ flag: 'waitCi', type: 'boolean', desc: '推送后等 CI 结果(默认不等):按推送的 sha 查 GitHub Actions,全绿=通过、任一失败=ciFailed、超时/无 CI 如实回报' },
|
|
46
|
+
{ flag: 'ciTimeoutSec', type: 'number', desc: '等 CI 的上限秒数(默认 900)' },
|
|
45
47
|
],
|
|
46
48
|
},
|
|
47
49
|
{
|
package/lib/app/tool-call.js
CHANGED
|
@@ -71,6 +71,10 @@ async function pushWithPostSteps(args, env, cfg) {
|
|
|
71
71
|
// 推送门禁——开启时 push 需显式放行(pushConfirmed:true);未放行返回 PUSH_GATE 拦截
|
|
72
72
|
pushGate: cfg.pushGate === true,
|
|
73
73
|
pushConfirmed: args.pushConfirmed === true,
|
|
74
|
+
// 推送后等 CI 结果(默认不等):按推到远端的那个 sha 查 Actions,
|
|
75
|
+
// 全绿=通过、任一失败=ciFailed、超时/无 CI 如实回报(都不改变推送本身成功的事实)
|
|
76
|
+
waitCi: args.waitCi === true || cfg.waitCi === true,
|
|
77
|
+
ciTimeoutSec: Number(args.ciTimeoutSec) > 0 ? Number(args.ciTimeoutSec) : 900,
|
|
74
78
|
// 精确 add 路径(逗号分隔,相对 repo);空 = git add -A 全量
|
|
75
79
|
paths: String(args.paths || ''),
|
|
76
80
|
});
|
package/lib/git/ci.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CI(GitHub Actions)结果等待 —— 推送后确认真跑绿了,而不是"推上去就算完成"。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要:推送成功只代表代码到了远端,构建/测试是否通过是另一回事。
|
|
5
|
+
* 实测事故:一次提交推送成功,CI 在同一 SHA 上挂了(我加的一个测试假设了 CIFS 特性,
|
|
6
|
+
* 在 ext4 runner 上必然失败)——只看推送结果完全发现不了。
|
|
7
|
+
*
|
|
8
|
+
* 设计取舍:
|
|
9
|
+
* · **只读**(GET /actions/runs),不触发、不重跑;
|
|
10
|
+
* · 按 **head_sha** 查,而不是查"最新一次 run"——否则并发提交会拿到别人的结果;
|
|
11
|
+
* · 多 workflow 同时存在时**全绿才算通过**(任一失败即 failure);
|
|
12
|
+
* · 刚推上去时 run 可能还没创建,给一段 grace(默认 60s)再判定「没有 CI」;
|
|
13
|
+
* · 超时不算失败、也不算通过,单独给 `timeout`,让调用方自己决定怎么处理。
|
|
14
|
+
*/
|
|
15
|
+
import { runGit } from './exec.js';
|
|
16
|
+
import { githubFetch } from './api.js';
|
|
17
|
+
import { parseOwnerRepoFromRemote } from './remote.js';
|
|
18
|
+
|
|
19
|
+
const DEFAULT_TIMEOUT_MS = 15 * 60 * 1000;
|
|
20
|
+
const DEFAULT_POLL_MS = 15 * 1000;
|
|
21
|
+
const DEFAULT_GRACE_MS = 60 * 1000;
|
|
22
|
+
|
|
23
|
+
/** 视为「通过」的结论集合(neutral/skipped 不算红)。 */
|
|
24
|
+
const OK_CONCLUSIONS = new Set(['success', 'neutral', 'skipped']);
|
|
25
|
+
|
|
26
|
+
/** 从本地仓库解析 owner/repo(origin 优先,其次任意 GitHub remote)。 */
|
|
27
|
+
export function resolveRepoIdentity(repoPath) {
|
|
28
|
+
const origin = runGit(['remote', 'get-url', 'origin'], { cwd: repoPath });
|
|
29
|
+
const fromOrigin = parseOwnerRepoFromRemote(origin.stdout || origin.stderr || '');
|
|
30
|
+
if (fromOrigin.owner && fromOrigin.repo) return fromOrigin;
|
|
31
|
+
const all = runGit(['remote', '-v'], { cwd: repoPath });
|
|
32
|
+
for (const line of String(all.stdout || '').split('\n')) {
|
|
33
|
+
const url = line.split(/\s+/)[1] || '';
|
|
34
|
+
const parsed = parseOwnerRepoFromRemote(url);
|
|
35
|
+
if (parsed.owner && parsed.repo) return parsed;
|
|
36
|
+
}
|
|
37
|
+
return { owner: '', repo: '' };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 查某次提交触发的所有 workflow run。
|
|
42
|
+
* @returns {Promise<{ok:boolean, runs:Array<object>, error?:string}>}
|
|
43
|
+
*/
|
|
44
|
+
export async function fetchRunsForSha({ owner, repo, sha, token = '', fetchImpl = githubFetch, perPage = 50 } = {}) {
|
|
45
|
+
if (!owner || !repo) return { ok: false, runs: [], error: '缺 owner/repo' };
|
|
46
|
+
if (!sha) return { ok: false, runs: [], error: '缺 sha' };
|
|
47
|
+
const res = await fetchImpl(`/repos/${owner}/${repo}/actions/runs?head_sha=${encodeURIComponent(sha)}&per_page=${perPage}`, { token });
|
|
48
|
+
if (res.status !== 200) return { ok: false, runs: [], error: res.json?.message || res.error || `HTTP ${res.status}` };
|
|
49
|
+
const runs = (res.json?.workflow_runs || []).map((r) => ({
|
|
50
|
+
id: r.id,
|
|
51
|
+
name: r.name || r.display_title || `run ${r.id}`,
|
|
52
|
+
status: r.status || '',
|
|
53
|
+
conclusion: r.conclusion || '',
|
|
54
|
+
// html_url 是 GitHub 的原字段;测试注入的桩可能直接用 url —— 两者都认,避免因字段名不同丢链接
|
|
55
|
+
url: r.html_url || r.url || '',
|
|
56
|
+
event: r.event || '',
|
|
57
|
+
headSha: r.head_sha || '',
|
|
58
|
+
}));
|
|
59
|
+
return { ok: true, runs };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 汇总一组 run 的结论(纯函数,便于单测)。
|
|
64
|
+
* @returns {{total:number, pending:number, failing:number, ok:number,
|
|
65
|
+
* conclusion:'none'|'pending'|'success'|'failure', failingRuns:Array<object>}}
|
|
66
|
+
*/
|
|
67
|
+
export function summarizeRuns(runs = []) {
|
|
68
|
+
let pending = 0;
|
|
69
|
+
let failing = 0;
|
|
70
|
+
let ok = 0;
|
|
71
|
+
const failingRuns = [];
|
|
72
|
+
for (const r of runs) {
|
|
73
|
+
if (r.status && r.status !== 'completed') { pending += 1; continue; }
|
|
74
|
+
if (OK_CONCLUSIONS.has(String(r.conclusion || '').toLowerCase())) { ok += 1; continue; }
|
|
75
|
+
failing += 1;
|
|
76
|
+
failingRuns.push(r);
|
|
77
|
+
}
|
|
78
|
+
const conclusion = !runs.length ? 'none' : pending ? 'pending' : failing ? 'failure' : 'success';
|
|
79
|
+
return { total: runs.length, pending, failing, ok, conclusion, failingRuns };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 等某次提交的 CI 出结果。
|
|
84
|
+
*
|
|
85
|
+
* @param {{repoPath?:string, owner?:string, repo?:string, sha:string, token?:string,
|
|
86
|
+
* timeoutMs?:number, pollMs?:number, graceMs?:number,
|
|
87
|
+
* fetchImpl?:Function, sleep?:Function, now?:Function}} o
|
|
88
|
+
* @returns {Promise<{ok:boolean, conclusion:'success'|'failure'|'pending'|'timeout'|'none',
|
|
89
|
+
* runs:Array<object>, summary:object, failing?:Array<object>, url?:string,
|
|
90
|
+
* timedOut?:boolean, note?:string, error?:string}>}
|
|
91
|
+
*/
|
|
92
|
+
export async function waitForCi({
|
|
93
|
+
repoPath = '', owner = '', repo = '', sha = '', token = '',
|
|
94
|
+
timeoutMs = DEFAULT_TIMEOUT_MS, pollMs = DEFAULT_POLL_MS, graceMs = DEFAULT_GRACE_MS,
|
|
95
|
+
fetchImpl = githubFetch, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now = () => Date.now(),
|
|
96
|
+
} = {}) {
|
|
97
|
+
let own = { owner, repo };
|
|
98
|
+
if ((!own.owner || !own.repo) && repoPath) own = resolveRepoIdentity(repoPath);
|
|
99
|
+
if (!own.owner || !own.repo) return { ok: false, conclusion: 'none', runs: [], summary: summarizeRuns([]), error: '无法解析 owner/repo(origin 不是 GitHub 地址)' };
|
|
100
|
+
const started = now();
|
|
101
|
+
let lastSummary = summarizeRuns([]);
|
|
102
|
+
for (;;) {
|
|
103
|
+
const res = await fetchRunsForSha({ owner: own.owner, repo: own.repo, sha, token, fetchImpl });
|
|
104
|
+
if (!res.ok) return { ok: false, conclusion: 'none', runs: [], summary: lastSummary, error: res.error };
|
|
105
|
+
const summary = summarizeRuns(res.runs);
|
|
106
|
+
lastSummary = summary;
|
|
107
|
+
const elapsed = now() - started;
|
|
108
|
+
if (summary.conclusion === 'none') {
|
|
109
|
+
// run 还没创建:给一段 grace,超过就认为该提交没有 CI
|
|
110
|
+
if (elapsed >= graceMs) {
|
|
111
|
+
return { ok: true, conclusion: 'none', runs: res.runs, summary, note: `该提交未触发 CI(已等 ${Math.round(elapsed / 1000)}s)` };
|
|
112
|
+
}
|
|
113
|
+
await sleep(Math.min(pollMs, Math.max(0, graceMs - elapsed)));
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (summary.conclusion !== 'pending') {
|
|
117
|
+
return {
|
|
118
|
+
ok: summary.conclusion === 'success',
|
|
119
|
+
conclusion: summary.conclusion,
|
|
120
|
+
runs: res.runs,
|
|
121
|
+
summary,
|
|
122
|
+
...(summary.failing ? { failing: summary.failingRuns.map((r) => ({ name: r.name, url: r.url, conclusion: r.conclusion })) } : {}),
|
|
123
|
+
url: summary.failingRuns[0]?.url || res.runs[0]?.url || '',
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (elapsed >= timeoutMs) {
|
|
127
|
+
return {
|
|
128
|
+
ok: false, conclusion: 'timeout', timedOut: true, runs: res.runs, summary,
|
|
129
|
+
note: `CI 在 ${Math.round(timeoutMs / 1000)}s 内未出结果(仍在跑)`,
|
|
130
|
+
url: res.runs[0]?.url || '',
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
await sleep(Math.min(pollMs, Math.max(0, timeoutMs - elapsed)));
|
|
134
|
+
}
|
|
135
|
+
}
|
package/lib/git/push.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { describeHooks, probeHooks } from './hooks.js';
|
|
10
|
+
import { waitForCi } from './ci.js';
|
|
10
11
|
import { existsSync } from 'node:fs';
|
|
11
12
|
import { join } from 'node:path';
|
|
12
13
|
import { autoTagDSHProject, ensureAuxSshRemote, readPkgVersion, updateRemoteTrackingRef } from './post-push.js';
|
|
@@ -55,7 +56,13 @@ import { resolveRepoVisibility, cachedVisibility } from './visibility.js';
|
|
|
55
56
|
* customIgnorePatterns:逗号/换行分隔的 gitignore pattern,追加进 .gitignore(幂等)
|
|
56
57
|
* @returns {{ok, steps: string[], commitSha?, pushed?, push?, remoteHeads?, error?}}
|
|
57
58
|
*/
|
|
58
|
-
export async function commitAndPush({
|
|
59
|
+
export async function commitAndPush({
|
|
60
|
+
repoPath = '', message = '', messageItems = null, push = true, dryRun = false, token = '',
|
|
61
|
+
customIgnorePatterns = '', requirementsConfirmed = false, force = false, pushMethod = 'ssh',
|
|
62
|
+
pushGate = false, pushConfirmed = false, paths = '', remote = '',
|
|
63
|
+
// 推送后是否等 CI 结果(默认不等:多数推送不需要阻塞);ciTimeoutSec 为等待上限
|
|
64
|
+
waitCi = false, ciTimeoutSec = 900,
|
|
65
|
+
} = {}) {
|
|
59
66
|
const steps = [];
|
|
60
67
|
if (!repoPath || !existsSync(join(repoPath, '.git'))) return { ok: false, steps: ['预检'], error: `非 git 仓库: ${repoPath || '(空)'}` };
|
|
61
68
|
// message 支持三种形态(字符串 / 数组 / {subject,items}):在预检处**单点**组装成规范提交信息,
|
|
@@ -211,6 +218,18 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
211
218
|
legacyIdentity,
|
|
212
219
|
};
|
|
213
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* 推送后按需等待 CI。用 commitSha(推到远端的那个提交)而不是"最新 run",
|
|
223
|
+
* 否则并发提交时会把别人的结果当自己的。超时/无 CI 都不算失败,只如实回报。
|
|
224
|
+
*/
|
|
225
|
+
const collectCi = async () => {
|
|
226
|
+
if (!waitCi) return null;
|
|
227
|
+
try {
|
|
228
|
+
return await waitForCi({ repoPath, sha: commitSha, token, timeoutMs: Math.max(30, Number(ciTimeoutSec) || 900) * 1000 });
|
|
229
|
+
} catch (e) {
|
|
230
|
+
return { ok: false, conclusion: 'none', error: `等待 CI 出错:${String(e?.message || e).slice(0, 200)}`, runs: [], summary: { total: 0 } };
|
|
231
|
+
}
|
|
232
|
+
};
|
|
214
233
|
steps.push('push');
|
|
215
234
|
// 通道由 dispatchPush 单点决策(默认 SSH:推本地 HEAD、远端 sha 与本地一致;无密钥才回落 API)。
|
|
216
235
|
// ⚠️ dispatchPush 是 async:必须 await(旧 bug:同步调用导致 pr.ok 恒 undefined,推送从未成功)
|
|
@@ -219,7 +238,10 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
219
238
|
// D24:pr.pushed=false(内容级短路「远端已是最新」)→ 如实 pushed:false(commitPushDoPush 语义)
|
|
220
239
|
// committed 必须如实带上:cleanSkipCommit 时本次**没有产生新提交**。
|
|
221
240
|
// 此前这条路径缺 committed 字段,job 输出就兜底成「已提交,未推送」——与实际相反 ✗(实测复现)
|
|
222
|
-
if (!pr.pushed)
|
|
241
|
+
if (!pr.pushed) {
|
|
242
|
+
const ci = await collectCi();
|
|
243
|
+
return { ok: true, steps, commitSha, committed: !cleanSkipCommit, pushed: false, push: pr, identity, legacyIdentity, ...(ci ? { ci } : {}) };
|
|
244
|
+
}
|
|
223
245
|
// 推送后增强对两条通道一视同仁:remote-tracking ref + aux remote + autoTag + remote heads。
|
|
224
246
|
// 原先只有 API 分支做这些,SSH 分支只拉 heads → 走 SSH 时本地 origin/<branch> 引用不更新,
|
|
225
247
|
// 下次 ahead/behind 判断就会错位。
|
|
@@ -238,7 +260,13 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
238
260
|
};
|
|
239
261
|
}
|
|
240
262
|
// committed 如实带上:cleanSkipCommit 时推的是**此前已提交的领先内容**,本次没有新提交
|
|
241
|
-
|
|
263
|
+
const ci = await collectCi();
|
|
264
|
+
if (ci) steps.push(`ci-${ci.conclusion}`);
|
|
265
|
+
return {
|
|
266
|
+
ok: true, steps, commitSha, committed: !cleanSkipCommit, pushed: true, push: enhanced.push,
|
|
267
|
+
autoTag: enhanced.autoTag, ...(enhanced.heads ? { remoteHeads: enhanced.heads } : {}), identity, legacyIdentity,
|
|
268
|
+
...(ci ? { ci, ...(ci.conclusion === 'failure' ? { ciFailed: true } : {}) } : {}),
|
|
269
|
+
};
|
|
242
270
|
}
|
|
243
271
|
// 失败回执附结构化诊断(分类 + 置信度 + 下一步)
|
|
244
272
|
const dg = pr.diagnosis || classifyPushFailure(String(pr.reason || ''), { method: pr.method });
|
|
@@ -171,7 +171,9 @@ export async function startLocalRegistry({ storeDir, port = 0 } = {}) {
|
|
|
171
171
|
* @param {{dir:string, tag?:string, packageName?:string, entrySpecs?:string[], timeoutMs?:number}} o
|
|
172
172
|
* @returns {Promise<{ok:boolean, steps:object[], failures:string[], packument?:object}>}
|
|
173
173
|
*/
|
|
174
|
-
export async function runLocalPreview({
|
|
174
|
+
export async function runLocalPreview({
|
|
175
|
+
dir, tag = 'beta', packageName = '', entrySpecs = [], bins = [], expectedVersion = '', timeoutMs = 300000,
|
|
176
|
+
} = {}) {
|
|
175
177
|
const steps = [];
|
|
176
178
|
const failures = [];
|
|
177
179
|
const reg = await startLocalRegistry();
|
|
@@ -201,12 +203,34 @@ export async function runLocalPreview({ dir, tag = 'beta', packageName = '', ent
|
|
|
201
203
|
steps.push({ step: 'install', ok: inst.code === 0 });
|
|
202
204
|
if (inst.code !== 0) { failures.push(`npm install(本地 registry)失败:${(inst.err || inst.out).slice(-400)}`); return { ok: false, steps, failures }; }
|
|
203
205
|
|
|
206
|
+
// ① 库入口:按 exports/main 逐个 import
|
|
204
207
|
if (entrySpecs.length) {
|
|
205
208
|
const script = `for (const s of ${JSON.stringify(entrySpecs)}) { await import(s); }\nconsole.log('ok');\n`;
|
|
206
209
|
const probe = await run(process.execPath, ['--input-type=module', '-e', script], { cwd: consumer, env, timeoutMs });
|
|
207
210
|
steps.push({ step: 'import', ok: probe.code === 0, specs: entrySpecs });
|
|
208
211
|
if (probe.code !== 0) failures.push(`从本地 registry 安装后加载失败:${(probe.err || '').slice(0, 400)}`);
|
|
209
212
|
}
|
|
213
|
+
// ② bin 入口:**真跑一次**(纯 CLI 包唯一有效的验证方式)。
|
|
214
|
+
// 为什么不能只 import:纯 CLI 包没有库入口,import 必然失败;而它的真实用法是 `npx <命令>`。
|
|
215
|
+
// 真跑 bin 还能抓到 import 永远测不到的故障:bin 判据用了字面路径、而 npm 装的是符号链接,
|
|
216
|
+
// 导致执行静默 exit 0 且零输出(历史事故形态)。
|
|
217
|
+
for (const b of bins) {
|
|
218
|
+
const binPath = join(consumer, 'node_modules', name, b.path);
|
|
219
|
+
const ver = await run(process.execPath, [binPath, '--version'], { cwd: consumer, env, timeoutMs: 60000 });
|
|
220
|
+
const verOut = `${ver.out || ''}${ver.err || ''}`.trim();
|
|
221
|
+
const verOk = ver.code === 0 && (!expectedVersion || verOut.includes(expectedVersion));
|
|
222
|
+
steps.push({ step: 'bin-version', ok: verOk, bin: b.command, output: verOut.slice(0, 120) });
|
|
223
|
+
if (!verOk) {
|
|
224
|
+
failures.push(`bin「${b.command} --version」未通过(退出码 ${ver.code}${expectedVersion ? `,期望输出含 ${expectedVersion}` : ''}):${verOut.slice(0, 300) || '(无输出)'}`);
|
|
225
|
+
}
|
|
226
|
+
const help = await run(process.execPath, [binPath, '--help'], { cwd: consumer, env, timeoutMs: 60000 });
|
|
227
|
+
steps.push({ step: 'bin-help', ok: help.code === 0, bin: b.command, code: help.code });
|
|
228
|
+
if (help.code !== 0) failures.push(`bin「${b.command} --help」退出码 ${help.code}(应为 0)`);
|
|
229
|
+
}
|
|
230
|
+
// ③ 既无库入口也无 bin:如实说「无可验证入口」,而不是含糊的「加载失败」
|
|
231
|
+
if (!entrySpecs.length && !bins.length) {
|
|
232
|
+
failures.push('该包既没有库入口(main/exports)也没有 bin——没有任何可验证入口,无法判断安装后是否可用');
|
|
233
|
+
}
|
|
210
234
|
return { ok: failures.length === 0, steps, failures, packument: { name, distTags: doc['dist-tags'], versions: Object.keys(doc.versions || {}) } };
|
|
211
235
|
} catch (e) {
|
|
212
236
|
failures.push(`本地彩排异常:${String(e?.message || e).slice(0, 300)}`);
|
package/lib/npm/publish.js
CHANGED
|
@@ -13,7 +13,7 @@ import { join } from 'node:path';
|
|
|
13
13
|
import { credentialsDir, readNpmToken } from '../core/credentials.js';
|
|
14
14
|
import { DEFAULT_REGISTRY, NPM_TIMEOUT_MS, normalizeRegistry, runNpm } from './registry.js';
|
|
15
15
|
import { npmArgs, writeNpmrc } from './npmrc.js';
|
|
16
|
-
import { smokeTestPackage, entrySpecsOf, isBrowserEntry } from './smoke.js';
|
|
16
|
+
import { smokeTestPackage, entrySpecsOf, isBrowserEntry, classifyPackageForm } from './smoke.js';
|
|
17
17
|
import { runLocalPreview } from './local-registry.js';
|
|
18
18
|
|
|
19
19
|
export const PUBLISH_LOG_FILE = 'npm-publish.log';
|
|
@@ -172,11 +172,17 @@ export async function publishPackage({
|
|
|
172
172
|
let preview = null;
|
|
173
173
|
if (localPreview) {
|
|
174
174
|
const pkgForPreview = JSON.parse(readFileSync(join(info.dir, 'package.json'), 'utf8'));
|
|
175
|
-
|
|
175
|
+
// 按**包的真实形态**决定验证方式:库包验 import,纯 CLI 包验 bin(真跑 --version/--help)。
|
|
176
|
+
// 历史实现一律 import,把 bin-only 的 CLI 包误判成「安装后加载失败」。
|
|
177
|
+
const form = classifyPackageForm(pkgForPreview);
|
|
178
|
+
const specs = form.entrySpecs.filter((sp) => {
|
|
176
179
|
const key = sp === pkgForPreview.name ? '.' : `./${sp.slice(String(pkgForPreview.name).length + 1)}`;
|
|
177
180
|
return !isBrowserEntry(key);
|
|
178
181
|
});
|
|
179
|
-
preview = await runLocalPreview({
|
|
182
|
+
preview = await runLocalPreview({
|
|
183
|
+
dir: info.dir, tag: tg, packageName: info.name,
|
|
184
|
+
entrySpecs: specs, bins: form.bins, expectedVersion: info.version, timeoutMs,
|
|
185
|
+
});
|
|
180
186
|
if (!preview.ok) {
|
|
181
187
|
return {
|
|
182
188
|
ok: false, blocked: 'local-preview-failed', name: info.name, version: info.version,
|
package/lib/npm/smoke.js
CHANGED
|
@@ -36,9 +36,44 @@ export function isBrowserEntry(key) {
|
|
|
36
36
|
return /(^|\/)client(\/|\.js)?(\/|$)|browser/i.test(String(key).replace(/^\.\//, ''));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** 从 package.json 取「可执行的 bin 入口」(bin 可能是字符串或对象)。 */
|
|
40
|
+
export function binEntriesOf(pkg, packageName = '') {
|
|
41
|
+
const bin = pkg?.bin;
|
|
42
|
+
const name = String(packageName || pkg?.name || '');
|
|
43
|
+
const list = [];
|
|
44
|
+
if (typeof bin === 'string' && bin.trim()) list.push({ command: name, path: bin.trim() });
|
|
45
|
+
else if (bin && typeof bin === 'object') {
|
|
46
|
+
for (const [cmd, rel] of Object.entries(bin)) {
|
|
47
|
+
if (typeof rel === 'string' && rel.trim()) list.push({ command: cmd, path: rel.trim() });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 判断包的**真实形态**,据此选择验证方式。
|
|
55
|
+
*
|
|
56
|
+
* 为什么必须分形态:纯 CLI 服务包(只有 `bin`,没有 `main`/`exports`)设计上就没有库入口,
|
|
57
|
+
* 对它 `import('<包名>')` 必然失败——但包本身完全正常(真实用法是 `npx <命令>`)。
|
|
58
|
+
* 历史实现一律用 import 探测公开面,于是把这类包误判成「安装后加载失败」,
|
|
59
|
+
* 报错还会让调用方以为包坏了。
|
|
60
|
+
* @returns {{kind:'library'|'cli'|'both'|'none', entrySpecs:string[], bins:Array<{command:string,path:string}>}}
|
|
61
|
+
*/
|
|
62
|
+
export function classifyPackageForm(pkg) {
|
|
63
|
+
const name = String(pkg?.name || '');
|
|
64
|
+
const bins = binEntriesOf(pkg, name);
|
|
65
|
+
const hasLib = Boolean(pkg?.exports) || Boolean(pkg?.main);
|
|
66
|
+
const entrySpecs = hasLib && name ? entrySpecsOf(pkg) : [];
|
|
67
|
+
const kind = hasLib && bins.length ? 'both' : hasLib ? 'library' : bins.length ? 'cli' : 'none';
|
|
68
|
+
return { kind, entrySpecs, bins };
|
|
69
|
+
}
|
|
70
|
+
|
|
39
71
|
export function entrySpecsOf(pkg) {
|
|
40
72
|
const name = String(pkg?.name || '');
|
|
41
73
|
if (!name) return [];
|
|
74
|
+
// 没有 main/exports 的包(纯 CLI)**没有库入口**:返回空数组,让调用方走 bin 验证。
|
|
75
|
+
// 历史实现无条件返回 [name],对 bin-only 包 import 必然失败(Cannot find package .../index.js)。
|
|
76
|
+
if (!pkg.exports && !pkg.main) return [];
|
|
42
77
|
const exp = pkg.exports;
|
|
43
78
|
if (typeof exp === 'string') return [name];
|
|
44
79
|
if (exp && typeof exp === 'object') {
|
|
@@ -135,6 +170,22 @@ export async function smokeTestPackage({ dir = '', workspaceRoot = '', registry
|
|
|
135
170
|
failures.push(`加载探针执行失败:${String(e.message || e).slice(0, 300)}`);
|
|
136
171
|
return { ok: false, steps, failures, tgz: tgzName, bytes };
|
|
137
172
|
}
|
|
173
|
+
// bin 入口:装完真跑一次(纯 CLI 包没有库入口,import 测不到;见 classifyPackageForm 说明)
|
|
174
|
+
const bins = binEntriesOf(pkg, name);
|
|
175
|
+
for (const b of bins) {
|
|
176
|
+
try {
|
|
177
|
+
const { execFileSync } = await import('node:child_process');
|
|
178
|
+
const out = String(execFileSync(process.execPath, [join(consumer, 'node_modules', name, b.path), '--version'], {
|
|
179
|
+
cwd: consumer, encoding: 'utf8', timeout: 60000, stdio: ['ignore', 'pipe', 'pipe'],
|
|
180
|
+
})).trim();
|
|
181
|
+
const ok = !version || out.includes(version);
|
|
182
|
+
steps.push({ step: 'bin-version', bin: b.command, ok, output: out.slice(0, 120) });
|
|
183
|
+
if (!ok) failures.push(`bin「${b.command} --version」输出未包含版本 ${version}:${out.slice(0, 200)}`);
|
|
184
|
+
} catch (e) {
|
|
185
|
+
steps.push({ step: 'bin-version', bin: b.command, ok: false });
|
|
186
|
+
failures.push(`bin「${b.command} --version」执行失败:${String(e?.message || e).slice(0, 200)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
138
189
|
for (const it of parsed.entries || []) {
|
|
139
190
|
if (it.ok) steps.push({ step: 'import', spec: it.spec, ok: true });
|
|
140
191
|
else { steps.push({ step: 'import', spec: it.spec, ok: false }); failures.push(`公开面 import 失败:${it.spec} → ${it.error}`); }
|
package/lib/self/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const VERSION = '2.
|
|
12
|
+
export const VERSION = '2.17.0'; // 2.17.0:推送后可等 CI 结果(waitCi)。推送成功只代表代码到了远端,构建是否通过是另一回事——实测一次提交推送成功、CI 在同一 SHA 上挂了(我加的一个测试假设了 CIFS 特性、在 ext4 runner 上必然失败),只看推送结果发现不了。实现:lib/git/ci.js 按 **head_sha** 查 Actions runs(不查最新一次,避免并发提交拿错结果),多 workflow 任一失败即 failure;刚推上去 run 可能还没创建,给 grace 期再判「没有 CI」;超时单独给 timeout。commitAndPush 新增 waitCi / ciTimeoutSec,回执带 ci{conclusion,runs,failing,url} 与 ciFailed 标记。同时修掉 2.16.0 引入的 CI 红:那条测试断言了「降级路径会写 origin」,在 ext4 runner(chmod 可用)上不成立——已改为与文件系统无关。历史:2.16.1 按包形态验证。
|
|
13
13
|
// 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
|
|
14
14
|
// 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
|
|
15
15
|
// 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
|