@kuafucloud/repo-kit 0.2.2-alpha.3 → 0.2.2-alpha.4
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/README.md +7 -0
- package/dist/guard/rules/external/npm-dependency-policy.d.ts +1 -9
- package/dist/guard/rules/external/npm-dependency-policy.js +1 -79
- package/dist/guard/rules/external/rules.js +1 -10
- package/dist/verify/commit-gate.js +1 -64
- package/dist/verify/full-command.js +0 -14
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @kuafucloud/repo-kit
|
|
2
|
+
|
|
3
|
+
Kuafu 仓库守卫、Git hooks 与验证任务编排工具,由项目的 `agent-tool` 调用。
|
|
4
|
+
|
|
5
|
+
项目使用精确版本的 npm 依赖;同仓包可使用 `workspace:*`。正式依赖从 npmjs 安装,仓库守卫检查依赖版本与本地路径协议,不再读取本机包目录判断版本是否已发布。
|
|
6
|
+
|
|
7
|
+
常用入口:`kuafu-guard`、`kuafu-verify`。验证配置及执行环境由 Host 和业务仓共同提供,推送门禁仍由 `agent-tool task push` 执行。
|
|
@@ -8,15 +8,7 @@ export declare function isForbiddenLocalPathSpecifier(specifier: string): boolea
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function collectNpmDependencyVersionPolicyDiagnostics(workspaceRoot: string): Promise<GuardDiagnostic[]>;
|
|
10
10
|
/**
|
|
11
|
-
* 规则 2:npm-
|
|
12
|
-
* 当存在本机正式包仓(<devRoot>/packages/index.json)时,校验仓库声明的每个 @kuafucloud/* 精确版本
|
|
13
|
-
* 均已在正式发布源存在,防止仅存在于 cache/npm-local 或未发布的版本被提交。
|
|
14
|
-
*/
|
|
15
|
-
export declare function collectNpmDependencyPublishedExistenceDiagnostics(workspaceRoot: string, options?: {
|
|
16
|
-
registryRoot?: string;
|
|
17
|
-
}): Promise<GuardDiagnostic[]>;
|
|
18
|
-
/**
|
|
19
|
-
* 规则 3:npm-no-active-local-install-state
|
|
11
|
+
* 规则 2:npm-no-active-local-install-state
|
|
20
12
|
* 检查当前仓库的本地安装回执,若仍挂载 cache/npm-local/ 临时包则阻断提交。
|
|
21
13
|
*/
|
|
22
14
|
export declare function collectNpmNoActiveLocalInstallStateDiagnostics(workspaceRoot: string): Promise<GuardDiagnostic[]>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
-
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
const STABLE_OR_ALPHA_SEMVER = /^\d+\.\d+\.\d+(?:-alpha\.[1-9]\d*)?$/u;
|
|
6
5
|
const WORKSPACE_PROTOCOL = /^workspace:(?:\*|\^|~)$/u;
|
|
@@ -154,73 +153,7 @@ export async function collectNpmDependencyVersionPolicyDiagnostics(workspaceRoot
|
|
|
154
153
|
return diagnostics;
|
|
155
154
|
}
|
|
156
155
|
/**
|
|
157
|
-
* 规则 2:npm-
|
|
158
|
-
* 当存在本机正式包仓(<devRoot>/packages/index.json)时,校验仓库声明的每个 @kuafucloud/* 精确版本
|
|
159
|
-
* 均已在正式发布源存在,防止仅存在于 cache/npm-local 或未发布的版本被提交。
|
|
160
|
-
*/
|
|
161
|
-
export async function collectNpmDependencyPublishedExistenceDiagnostics(workspaceRoot, options) {
|
|
162
|
-
const diagnostics = [];
|
|
163
|
-
const root = path.resolve(workspaceRoot);
|
|
164
|
-
const registryRoot = resolveOfficialRegistryRoot(options?.registryRoot);
|
|
165
|
-
const indexPath = path.join(registryRoot, "index.json");
|
|
166
|
-
if (!existsSync(indexPath)) {
|
|
167
|
-
return diagnostics;
|
|
168
|
-
}
|
|
169
|
-
let officialPackages = {};
|
|
170
|
-
try {
|
|
171
|
-
const parsed = JSON.parse(await readFile(indexPath, "utf8"));
|
|
172
|
-
if (parsed.schemaVersion === 2 && parsed.packages && !Array.isArray(parsed.packages)) {
|
|
173
|
-
officialPackages = parsed.packages;
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
return diagnostics;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
return diagnostics;
|
|
181
|
-
}
|
|
182
|
-
const pkgFiles = await collectManifestFiles(root);
|
|
183
|
-
const checked = new Set();
|
|
184
|
-
for (const absPath of pkgFiles) {
|
|
185
|
-
const relPath = path.relative(root, absPath).split(path.sep).join("/");
|
|
186
|
-
let pkg;
|
|
187
|
-
try {
|
|
188
|
-
pkg = JSON.parse(await readFile(absPath, "utf8"));
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
for (const section of DEP_SECTIONS) {
|
|
194
|
-
const deps = pkg[section];
|
|
195
|
-
if (!deps || typeof deps !== "object" || Array.isArray(deps))
|
|
196
|
-
continue;
|
|
197
|
-
for (const [depName, rawSpec] of Object.entries(deps)) {
|
|
198
|
-
if (typeof rawSpec !== "string" || !depName.startsWith("@kuafucloud/"))
|
|
199
|
-
continue;
|
|
200
|
-
const spec = rawSpec.trim();
|
|
201
|
-
if (WORKSPACE_PROTOCOL.test(spec) || !STABLE_OR_ALPHA_SEMVER.test(spec))
|
|
202
|
-
continue;
|
|
203
|
-
const key = `${relPath}:${depName}@${spec}`;
|
|
204
|
-
if (checked.has(key))
|
|
205
|
-
continue;
|
|
206
|
-
checked.add(key);
|
|
207
|
-
const publishedVersions = officialPackages[depName];
|
|
208
|
-
if (!publishedVersions || !Object.prototype.hasOwnProperty.call(publishedVersions, spec)) {
|
|
209
|
-
diagnostics.push({
|
|
210
|
-
ruleId: "npm-dependency-published-existence",
|
|
211
|
-
severity: "error",
|
|
212
|
-
filePath: relPath,
|
|
213
|
-
line: 1,
|
|
214
|
-
message: `依赖 ${depName}@${spec} 在正式发布源 (${indexPath}) 中不存在;请先通过 platform-tool 发布该包再提交。`,
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return diagnostics;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* 规则 3:npm-no-active-local-install-state
|
|
156
|
+
* 规则 2:npm-no-active-local-install-state
|
|
224
157
|
* 检查当前仓库的本地安装回执,若仍挂载 cache/npm-local/ 临时包则阻断提交。
|
|
225
158
|
*/
|
|
226
159
|
export async function collectNpmNoActiveLocalInstallStateDiagnostics(workspaceRoot) {
|
|
@@ -247,17 +180,6 @@ export async function collectNpmNoActiveLocalInstallStateDiagnostics(workspaceRo
|
|
|
247
180
|
}
|
|
248
181
|
return [];
|
|
249
182
|
}
|
|
250
|
-
function resolveOfficialRegistryRoot(explicit) {
|
|
251
|
-
if (explicit && explicit.trim())
|
|
252
|
-
return path.resolve(explicit.trim());
|
|
253
|
-
if (process.env.KUAFU_NPM_REGISTRY_ROOT?.trim()) {
|
|
254
|
-
return path.resolve(process.env.KUAFU_NPM_REGISTRY_ROOT.trim());
|
|
255
|
-
}
|
|
256
|
-
if (process.env.KUAFU_PROJECT_ROOT?.trim()) {
|
|
257
|
-
return path.resolve(process.env.KUAFU_PROJECT_ROOT.trim(), "..", "..", "packages");
|
|
258
|
-
}
|
|
259
|
-
return path.join(os.homedir(), "Documents", "kuafu-root", "packages");
|
|
260
|
-
}
|
|
261
183
|
async function collectManifestFiles(root) {
|
|
262
184
|
const files = [];
|
|
263
185
|
const rootPkg = path.join(root, "package.json");
|
|
@@ -14,7 +14,7 @@ import { collectAppNativeSourceBoundaryIssues } from "./app/validate-native-sour
|
|
|
14
14
|
import { collectExtensionElectronBoundaryIssues } from "./extension/validate-electron-boundary.js";
|
|
15
15
|
import { collectExternalExtensionKitServerBoundaryIssues } from "./extension/validate-extension-kit-server-boundary.js";
|
|
16
16
|
import { validateNoLegacyE2EPaths, validateStorySourceCode } from "./story-rules.js";
|
|
17
|
-
import {
|
|
17
|
+
import { collectNpmDependencyVersionPolicyDiagnostics, collectNpmNoActiveLocalInstallStateDiagnostics, } from "./npm-dependency-policy.js";
|
|
18
18
|
import { toGuardDiagnostics } from "./shared/diagnostic.js";
|
|
19
19
|
import { collectFiles, pathExists } from "./shared/records.js";
|
|
20
20
|
import { readFile } from "node:fs/promises";
|
|
@@ -194,14 +194,6 @@ const npmDependencyVersionPolicyRule = {
|
|
|
194
194
|
},
|
|
195
195
|
run: async (context) => await collectNpmDependencyVersionPolicyDiagnostics(context.workspaceRoot),
|
|
196
196
|
};
|
|
197
|
-
const npmDependencyPublishedExistenceRule = {
|
|
198
|
-
meta: {
|
|
199
|
-
id: "npm-dependency-published-existence",
|
|
200
|
-
title: "npm 依赖正式发布源存在性守卫",
|
|
201
|
-
level: "L0",
|
|
202
|
-
},
|
|
203
|
-
run: async (context) => await collectNpmDependencyPublishedExistenceDiagnostics(context.workspaceRoot),
|
|
204
|
-
};
|
|
205
197
|
const npmNoActiveLocalInstallStateRule = {
|
|
206
198
|
meta: {
|
|
207
199
|
id: "npm-no-active-local-install-state",
|
|
@@ -226,6 +218,5 @@ export const externalRuleRegistry = {
|
|
|
226
218
|
[extensionKitServerBoundaryRule.meta.id]: extensionKitServerBoundaryRule,
|
|
227
219
|
[productStoryGuardRule.meta.id]: productStoryGuardRule,
|
|
228
220
|
[npmDependencyVersionPolicyRule.meta.id]: npmDependencyVersionPolicyRule,
|
|
229
|
-
[npmDependencyPublishedExistenceRule.meta.id]: npmDependencyPublishedExistenceRule,
|
|
230
221
|
[npmNoActiveLocalInstallStateRule.meta.id]: npmNoActiveLocalInstallStateRule,
|
|
231
222
|
};
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
export { readStagedPushVerification, readPushBranch } from "./delivery-verification.js";
|
|
2
2
|
import { assertVerificationCandidateIsIsolated } from "./verification-candidate.js";
|
|
3
3
|
import { executeRepoGuard } from "../guard/repo.js";
|
|
4
|
-
import { matchesVerificationProofIdentity, matchesVerificationProofCoverage } from "./verification-proof-rules.js";
|
|
5
4
|
import { findStagedProcessIssue } from "./commit-candidate-rules.js";
|
|
6
5
|
import { execFile } from "node:child_process";
|
|
7
6
|
import { createHash } from "node:crypto";
|
|
8
|
-
import { mkdir,
|
|
7
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
8
|
import path from "node:path";
|
|
10
|
-
import { createVerificationImpactPlan } from "./impact-plan.js";
|
|
11
9
|
import { normalizeVerificationWorkspaceIdentity } from "./verification-identity.js";
|
|
12
10
|
export { normalizeVerificationWorkspaceIdentity } from "./verification-identity.js";
|
|
13
|
-
import { readCheckoutVerificationRuntime } from "./checkout-environment.js";
|
|
14
11
|
export function resolveVerificationStateRoot(workspaceRoot, input) {
|
|
15
12
|
const identity = normalizeVerificationWorkspaceIdentity(input);
|
|
16
13
|
return identity.workspaceId
|
|
@@ -85,50 +82,6 @@ export async function runTaskCommitGate(input) {
|
|
|
85
82
|
}
|
|
86
83
|
return buildResult({ ...identity, stagedFiles, proofPath: null, errors });
|
|
87
84
|
}
|
|
88
|
-
async function validateVerifyProof(input) {
|
|
89
|
-
const proof = await readVerifyProof(input.expectedProofPath);
|
|
90
|
-
if (!proof) {
|
|
91
|
-
input.errors.push({
|
|
92
|
-
code: await hasAnyVerifyProof(input.proofRoot) ? "verify.proof.stale" : "verify.proof.missing",
|
|
93
|
-
message: await hasAnyVerifyProof(input.proofRoot)
|
|
94
|
-
? "Verification proof exists but is not valid for the current commit gate."
|
|
95
|
-
: "Current workspace has no commit verification proof.",
|
|
96
|
-
details: { expectedProofPath: input.expectedProofPath },
|
|
97
|
-
});
|
|
98
|
-
return buildResult({ ...input, proofPath: null });
|
|
99
|
-
}
|
|
100
|
-
const headSha = (await git(input.workspaceRoot, ["rev-parse", "HEAD"])).trim();
|
|
101
|
-
const runtime = await readCheckoutVerificationRuntime(input.workspaceRoot);
|
|
102
|
-
// 保原短路顺序:身份本身无效时不能额外写Git tree。
|
|
103
|
-
const candidateTree = input.workspaceId && proof.schemaVersion === 3 && proof.workspaceId === input.workspaceId && !Object.hasOwn(proof, "devKey")
|
|
104
|
-
? (await git(input.workspaceRoot, ["write-tree"])).trim() : null;
|
|
105
|
-
if (!matchesVerificationProofIdentity(proof, { ...input, headSha, runtime, candidateTree })) {
|
|
106
|
-
input.errors.push({
|
|
107
|
-
code: "verify.proof.stale",
|
|
108
|
-
message: "Verification proof is invalid or does not match HEAD, the current staged source and execution tools.",
|
|
109
|
-
details: { expectedProofPath: input.expectedProofPath },
|
|
110
|
-
});
|
|
111
|
-
return buildResult({ ...input, proofPath: input.expectedProofPath });
|
|
112
|
-
}
|
|
113
|
-
const requestedScope = proof.requestedScope === "full" ? "full" : proof.requestedScope === "auto" ? "auto" : null;
|
|
114
|
-
if (!requestedScope) {
|
|
115
|
-
input.errors.push({ code: "verify.proof.stale", message: "Verification proof has an unsupported requested scope." });
|
|
116
|
-
return buildResult({ ...input, proofPath: input.expectedProofPath });
|
|
117
|
-
}
|
|
118
|
-
const [autoPlan, proofPlan] = await Promise.all([
|
|
119
|
-
createVerificationImpactPlan({ workspaceRoot: input.workspaceRoot, requestedScope: "auto" }),
|
|
120
|
-
createVerificationImpactPlan({ workspaceRoot: input.workspaceRoot, requestedScope }),
|
|
121
|
-
]);
|
|
122
|
-
if (!matchesVerificationProofCoverage(proof, proofPlan, autoPlan)) {
|
|
123
|
-
input.errors.push({
|
|
124
|
-
code: "verify.proof.insufficient",
|
|
125
|
-
message: "Verification proof does not cover the canonical plan required by the current staged source.",
|
|
126
|
-
details: { expectedMode: autoPlan.resolvedMode, actualMode: proof.resolvedMode },
|
|
127
|
-
});
|
|
128
|
-
return buildResult({ ...input, proofPath: input.expectedProofPath });
|
|
129
|
-
}
|
|
130
|
-
return buildResult({ ...input, proofPath: input.expectedProofPath });
|
|
131
|
-
}
|
|
132
85
|
/**
|
|
133
86
|
* 只读取已暂存 diff 的 raw 记录,确保待提交源码变化后必须重跑 verify full。
|
|
134
87
|
* 不能使用 `git write-tree`:它可能刷新 index 并创建 index.lock,反而让校验影响工作区。
|
|
@@ -147,22 +100,6 @@ function buildResult(input) {
|
|
|
147
100
|
ok: input.errors.length === 0,
|
|
148
101
|
};
|
|
149
102
|
}
|
|
150
|
-
async function readVerifyProof(proofPath) {
|
|
151
|
-
const content = await readFile(proofPath, "utf-8").catch(() => "");
|
|
152
|
-
if (!content)
|
|
153
|
-
return null;
|
|
154
|
-
try {
|
|
155
|
-
const parsed = JSON.parse(content);
|
|
156
|
-
return parsed && typeof parsed === "object" ? parsed : null;
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async function hasAnyVerifyProof(proofRoot) {
|
|
163
|
-
const entries = await readdir(proofRoot).catch(() => []);
|
|
164
|
-
return entries.some((entry) => entry.endsWith(".json"));
|
|
165
|
-
}
|
|
166
103
|
async function git(cwd, args) {
|
|
167
104
|
return await new Promise((resolve, reject) => {
|
|
168
105
|
execFile("git", ["-c", "core.quotePath=false", ...args], {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const E2E_DATABASE_BACKEND_ENV = "PLATFORM_E2E_DATABASE_BACKEND";
|
|
2
1
|
const PLATFORM_ARCHITECTURE_GATE = "if [ -f packages/platform-tool/package.json ]; then node packages/host-tooling/scripts/verify-architecture.mjs; else echo '{\"command\":\"release.verify-architecture\",\"ok\":true,\"notApplicable\":true}'; fi";
|
|
3
2
|
// 先核对真实任务图的写入依赖排他,再让只读检查使用有界并行;保留全部依赖边。
|
|
4
3
|
const REPOSITORY_TYPECHECK = "node --import tsx packages/host-tooling/scripts/verify-static-checks.mjs check-types";
|
|
@@ -6,7 +5,6 @@ const REPOSITORY_LINT = "node --import tsx packages/host-tooling/scripts/verify-
|
|
|
6
5
|
// test目标自身禁止结果缓存,依赖build继续按源码身份复用;不能用全图skip禁用构建缓存。
|
|
7
6
|
const PARALLEL_REPOSITORY_UNITS = "pnpm exec nx run-many --target=test:unit --all --parallel=3 --nx-bail=true";
|
|
8
7
|
export const WORKSPACE_CORE_BROWSER_COMMAND = "pnpm --dir products/host run test:workspace-core";
|
|
9
|
-
const PRODUCT_TEST_TECHNICAL_E2E_COMMAND = "pnpm --dir packages/product-test run test:technical-e2e";
|
|
10
8
|
const PLATFORM_WORKSPACE_MARKER = "packages/platform-tool/package.json";
|
|
11
9
|
const REPOSITORY_VERIFY_SCRIPT_CHECK = "node -e \"const scripts=require('./package.json').scripts||{}; process.exit(typeof scripts.verify === 'string' && scripts.verify.trim() ? 0 : 1)\"";
|
|
12
10
|
// Browser E2E 使用隔离的 Test Host Renderer;它不是安装态 Host 的运行模式。
|
|
@@ -14,7 +12,6 @@ export const BROWSER_TEST_COMMAND = "node --import tsx products/host/scripts/tes
|
|
|
14
12
|
// Host 本地宿主集成测试必须消费当前源码新打出的正常安装态候选,不能复用上次的 unpacked App,
|
|
15
13
|
// 也不能把 Browser Test Host 的标记打进候选包。
|
|
16
14
|
const CONSOLE_INSTALLED_HOST_CANDIDATE = "pnpm --dir products/host run package:candidate";
|
|
17
|
-
const E2E_COLLECTION_CHECK = "node packages/host-tooling/scripts/verify-e2e-collection.mjs";
|
|
18
15
|
const HOST_INTEGRATION_TESTS = "PLATFORM_E2E_PREBUILT=1 pnpm --dir products/host run test:integration";
|
|
19
16
|
export function createDefaultPushVerifyPlan(input) {
|
|
20
17
|
const beforePrepareCommands = [
|
|
@@ -125,14 +122,3 @@ function normalizeDatabaseBackend(value) {
|
|
|
125
122
|
}
|
|
126
123
|
throw new Error(`Unsupported database backend: ${value}. Use "do" or "postgres".`);
|
|
127
124
|
}
|
|
128
|
-
function createPlaywrightCommand(input) {
|
|
129
|
-
// Browser入口从同轮父输入生成独立Renderer,不覆盖canonical Host;
|
|
130
|
-
// Playwright global setup不再重复构建。Playwright配置会将真实
|
|
131
|
-
// 空目录 clone / npm 安装 / 全 Product 构建的 Local Initialization 专项场景
|
|
132
|
-
// 留给 `agent-tool verify e2e --local-initialization`,避免公网波动阻塞提交。
|
|
133
|
-
const command = BROWSER_TEST_COMMAND;
|
|
134
|
-
if (input.databaseBackend === "do") {
|
|
135
|
-
return command;
|
|
136
|
-
}
|
|
137
|
-
return `${E2E_DATABASE_BACKEND_ENV}=${input.databaseBackend} ${command}`;
|
|
138
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kuafucloud/repo-kit",
|
|
3
|
-
"version": "0.2.2-alpha.
|
|
3
|
+
"version": "0.2.2-alpha.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"type": "module",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"test:unit": "node --import tsx ../testing-infrastructure/test-source-unit.mjs"
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"@kuafucloud/product-build": "0.2.2-alpha.
|
|
96
|
+
"@kuafucloud/product-build": "0.2.2-alpha.5",
|
|
97
97
|
"typescript": "5.9.3",
|
|
98
98
|
"yaml": "2.9.0",
|
|
99
99
|
"zod": "^3.25.76",
|