@kuafucloud/repo-kit 0.0.0-stage → 0.2.2-alpha.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/LICENSE.md +9 -0
- package/assets/git-hooks/check-push.cjs +21 -0
- package/assets/git-hooks/pre-push +7 -0
- package/assets/git-hooks/prepare-commit-msg +5 -0
- package/assets/verification/heavy-test-admission-core.d.mts +1 -0
- package/assets/verification/heavy-test-admission-core.mjs +10 -0
- package/assets/verification/host-process-lock.d.mts +24 -0
- package/assets/verification/host-process-lock.mjs +140 -0
- package/assets/verification/test-heavy-admission.d.mts +4 -0
- package/assets/verification/test-heavy-admission.mjs +34 -0
- package/bin/kuafu-guard.mjs +3 -0
- package/bin/kuafu-verify.mjs +3 -0
- package/dist/cli/guard.d.ts +1 -0
- package/dist/cli/guard.js +59 -0
- package/dist/cli/verify.d.ts +1 -0
- package/dist/cli/verify.js +58 -0
- package/dist/guard/core/config.d.ts +7 -0
- package/dist/guard/core/config.js +159 -0
- package/dist/guard/core/engine.d.ts +2 -0
- package/dist/guard/core/engine.js +151 -0
- package/dist/guard/core/formatters/sarif-rules.d.ts +2 -0
- package/dist/guard/core/formatters/sarif-rules.js +67 -0
- package/dist/guard/core/formatters/sarif.d.ts +2 -0
- package/dist/guard/core/formatters/sarif.js +3 -0
- package/dist/guard/core/formatters/text.d.ts +2 -0
- package/dist/guard/core/formatters/text.js +22 -0
- package/dist/guard/core/index.d.ts +5 -0
- package/dist/guard/core/index.js +5 -0
- package/dist/guard/core/types.d.ts +94 -0
- package/dist/guard/core/types.js +1 -0
- package/dist/guard/hooks/install-rules.d.ts +2 -0
- package/dist/guard/hooks/install-rules.js +5 -0
- package/dist/guard/hooks/install.d.ts +36 -0
- package/dist/guard/hooks/install.js +212 -0
- package/dist/guard/hooks/push.d.ts +1 -0
- package/dist/guard/hooks/push.js +5 -0
- package/dist/guard/index.d.ts +16 -0
- package/dist/guard/index.js +16 -0
- package/dist/guard/product-roots.d.ts +12 -0
- package/dist/guard/product-roots.js +37 -0
- package/dist/guard/repo-args.d.ts +8 -0
- package/dist/guard/repo-args.js +75 -0
- package/dist/guard/repo-output-rules.d.ts +12 -0
- package/dist/guard/repo-output-rules.js +44 -0
- package/dist/guard/repo.d.ts +21 -0
- package/dist/guard/repo.js +74 -0
- package/dist/guard/rules/external/api/collect-orphan-tests.d.ts +2 -0
- package/dist/guard/rules/external/api/collect-orphan-tests.js +34 -0
- package/dist/guard/rules/external/api/collect.d.ts +2 -0
- package/dist/guard/rules/external/api/collect.js +419 -0
- package/dist/guard/rules/external/api/validate-orphan-tests.d.ts +2 -0
- package/dist/guard/rules/external/api/validate-orphan-tests.js +10 -0
- package/dist/guard/rules/external/api/validate.d.ts +2 -0
- package/dist/guard/rules/external/api/validate.js +278 -0
- package/dist/guard/rules/external/app/native-source-rules.d.ts +6 -0
- package/dist/guard/rules/external/app/native-source-rules.js +164 -0
- package/dist/guard/rules/external/app/validate-native-source-boundary.d.ts +2 -0
- package/dist/guard/rules/external/app/validate-native-source-boundary.js +187 -0
- package/dist/guard/rules/external/boundary/check.d.ts +4 -0
- package/dist/guard/rules/external/boundary/check.js +198 -0
- package/dist/guard/rules/external/extension/collect.d.ts +1 -0
- package/dist/guard/rules/external/extension/collect.js +1 -0
- package/dist/guard/rules/external/extension/electron-boundary-rules.d.ts +6 -0
- package/dist/guard/rules/external/extension/electron-boundary-rules.js +10 -0
- package/dist/guard/rules/external/extension/index.d.ts +6 -0
- package/dist/guard/rules/external/extension/index.js +29 -0
- package/dist/guard/rules/external/extension/manual-cross-call-rules.d.ts +19 -0
- package/dist/guard/rules/external/extension/manual-cross-call-rules.js +19 -0
- package/dist/guard/rules/external/extension/resolve-import.d.ts +1 -0
- package/dist/guard/rules/external/extension/resolve-import.js +43 -0
- package/dist/guard/rules/external/extension/scan-relative-dependencies.d.ts +5 -0
- package/dist/guard/rules/external/extension/scan-relative-dependencies.js +53 -0
- package/dist/guard/rules/external/extension/scan-source.d.ts +11 -0
- package/dist/guard/rules/external/extension/scan-source.js +25 -0
- package/dist/guard/rules/external/extension/source-import-boundary-rules.d.ts +26 -0
- package/dist/guard/rules/external/extension/source-import-boundary-rules.js +40 -0
- package/dist/guard/rules/external/extension/test-layer-import-rules.d.ts +1 -0
- package/dist/guard/rules/external/extension/test-layer-import-rules.js +16 -0
- package/dist/guard/rules/external/extension/types.d.ts +51 -0
- package/dist/guard/rules/external/extension/types.js +1 -0
- package/dist/guard/rules/external/extension/unused-export-rules.d.ts +23 -0
- package/dist/guard/rules/external/extension/unused-export-rules.js +119 -0
- package/dist/guard/rules/external/extension/unused-module-rules.d.ts +6 -0
- package/dist/guard/rules/external/extension/unused-module-rules.js +90 -0
- package/dist/guard/rules/external/extension/validate-admin.d.ts +8 -0
- package/dist/guard/rules/external/extension/validate-admin.js +73 -0
- package/dist/guard/rules/external/extension/validate-database.d.ts +3 -0
- package/dist/guard/rules/external/extension/validate-database.js +4 -0
- package/dist/guard/rules/external/extension/validate-electron-boundary.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-electron-boundary.js +18 -0
- package/dist/guard/rules/external/extension/validate-empty-dirs.d.ts +9 -0
- package/dist/guard/rules/external/extension/validate-empty-dirs.js +44 -0
- package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.js +116 -0
- package/dist/guard/rules/external/extension/validate-features.d.ts +7 -0
- package/dist/guard/rules/external/extension/validate-features.js +27 -0
- package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.js +131 -0
- package/dist/guard/rules/external/extension/validate-peer-extension-import.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-peer-extension-import.js +41 -0
- package/dist/guard/rules/external/extension/validate-server-cross-domain-import.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-server-cross-domain-import.js +48 -0
- package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.d.ts +1 -0
- package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.js +1 -0
- package/dist/guard/rules/external/extension/validate-shared-import-boundary.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-shared-import-boundary.js +40 -0
- package/dist/guard/rules/external/extension/validate-shared.d.ts +1 -0
- package/dist/guard/rules/external/extension/validate-shared.js +1 -0
- package/dist/guard/rules/external/extension/validate-test-layer-boundary.d.ts +8 -0
- package/dist/guard/rules/external/extension/validate-test-layer-boundary.js +59 -0
- package/dist/guard/rules/external/extension/validate-test-mirror.d.ts +4 -0
- package/dist/guard/rules/external/extension/validate-test-mirror.js +32 -0
- package/dist/guard/rules/external/extension/validate-top-level.d.ts +7 -0
- package/dist/guard/rules/external/extension/validate-top-level.js +76 -0
- package/dist/guard/rules/external/extension/validate-unused-export.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-unused-export.js +187 -0
- package/dist/guard/rules/external/extension/validate-unused-module.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-unused-module.js +38 -0
- package/dist/guard/rules/external/index.d.ts +1 -0
- package/dist/guard/rules/external/index.js +1 -0
- package/dist/guard/rules/external/npm-dependency-policy.d.ts +22 -0
- package/dist/guard/rules/external/npm-dependency-policy.js +294 -0
- package/dist/guard/rules/external/rules.d.ts +2 -0
- package/dist/guard/rules/external/rules.js +231 -0
- package/dist/guard/rules/external/shared/config.d.ts +3 -0
- package/dist/guard/rules/external/shared/config.js +14 -0
- package/dist/guard/rules/external/shared/diagnostic.d.ts +4 -0
- package/dist/guard/rules/external/shared/diagnostic.js +12 -0
- package/dist/guard/rules/external/shared/records.d.ts +4 -0
- package/dist/guard/rules/external/shared/records.js +46 -0
- package/dist/guard/rules/external/shared/ts-ast.d.ts +8 -0
- package/dist/guard/rules/external/shared/ts-ast.js +103 -0
- package/dist/guard/rules/external/shared/types.d.ts +159 -0
- package/dist/guard/rules/external/shared/types.js +1 -0
- package/dist/guard/rules/external/shared/validate-layer-key.d.ts +2 -0
- package/dist/guard/rules/external/shared/validate-layer-key.js +35 -0
- package/dist/guard/rules/external/story-rules.d.ts +15 -0
- package/dist/guard/rules/external/story-rules.js +59 -0
- package/dist/guard/rules/shared/extension/api-entry-tuple-rules.d.ts +7 -0
- package/dist/guard/rules/shared/extension/api-entry-tuple-rules.js +6 -0
- package/dist/guard/rules/shared/extension/collect.d.ts +5 -0
- package/dist/guard/rules/shared/extension/collect.js +231 -0
- package/dist/guard/rules/shared/extension/database-reference-rules.d.ts +4 -0
- package/dist/guard/rules/shared/extension/database-reference-rules.js +5 -0
- package/dist/guard/rules/shared/extension/database-source-rules.d.ts +17 -0
- package/dist/guard/rules/shared/extension/database-source-rules.js +595 -0
- package/dist/guard/rules/shared/extension/database-structure-rules.d.ts +3 -0
- package/dist/guard/rules/shared/extension/database-structure-rules.js +63 -0
- package/dist/guard/rules/shared/extension/server-index-source-rules.d.ts +2 -0
- package/dist/guard/rules/shared/extension/server-index-source-rules.js +91 -0
- package/dist/guard/rules/shared/extension/shared-consumer-rules.d.ts +23 -0
- package/dist/guard/rules/shared/extension/shared-consumer-rules.js +158 -0
- package/dist/guard/rules/shared/extension/shared-structure-rules.d.ts +6 -0
- package/dist/guard/rules/shared/extension/shared-structure-rules.js +27 -0
- package/dist/guard/rules/shared/extension/validate-database.d.ts +4 -0
- package/dist/guard/rules/shared/extension/validate-database.js +15 -0
- package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.d.ts +2 -0
- package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.js +9 -0
- package/dist/guard/rules/shared/extension/validate-shared.d.ts +18 -0
- package/dist/guard/rules/shared/extension/validate-shared.js +149 -0
- package/dist/host-protocol.d.ts +2 -0
- package/dist/host-protocol.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/verify/artifact-recovery-rules.d.ts +39 -0
- package/dist/verify/artifact-recovery-rules.js +48 -0
- package/dist/verify/artifact-session.d.ts +91 -0
- package/dist/verify/artifact-session.js +443 -0
- package/dist/verify/checkout-environment-rules.d.ts +2 -0
- package/dist/verify/checkout-environment-rules.js +25 -0
- package/dist/verify/checkout-environment.d.ts +8 -0
- package/dist/verify/checkout-environment.js +24 -0
- package/dist/verify/commit-candidate-rules.d.ts +3 -0
- package/dist/verify/commit-candidate-rules.js +33 -0
- package/dist/verify/commit-gate.d.ts +64 -0
- package/dist/verify/commit-gate.js +207 -0
- package/dist/verify/delivery-verification.d.ts +3 -0
- package/dist/verify/delivery-verification.js +21 -0
- package/dist/verify/e2e-registry-rules.d.ts +21 -0
- package/dist/verify/e2e-registry-rules.js +33 -0
- package/dist/verify/e2e-registry.d.ts +2 -0
- package/dist/verify/e2e-registry.js +45 -0
- package/dist/verify/full-command.d.ts +35 -0
- package/dist/verify/full-command.js +138 -0
- package/dist/verify/impact-plan-rules.d.ts +61 -0
- package/dist/verify/impact-plan-rules.js +185 -0
- package/dist/verify/impact-plan.d.ts +10 -0
- package/dist/verify/impact-plan.js +151 -0
- package/dist/verify/index.d.ts +22 -0
- package/dist/verify/index.js +22 -0
- package/dist/verify/repository-recipe-rules.d.ts +31 -0
- package/dist/verify/repository-recipe-rules.js +60 -0
- package/dist/verify/repository-recipe.d.ts +3 -0
- package/dist/verify/repository-recipe.js +58 -0
- package/dist/verify/static-validation-rules.d.ts +7 -0
- package/dist/verify/static-validation-rules.js +36 -0
- package/dist/verify/story-selection-rules.d.ts +57 -0
- package/dist/verify/story-selection-rules.js +125 -0
- package/dist/verify/types.d.ts +63 -0
- package/dist/verify/types.js +18 -0
- package/dist/verify/verification-candidate.d.ts +1 -0
- package/dist/verify/verification-candidate.js +20 -0
- package/dist/verify/verification-identity.d.ts +6 -0
- package/dist/verify/verification-identity.js +26 -0
- package/dist/verify/verification-proof-rules.d.ts +35 -0
- package/dist/verify/verification-proof-rules.js +45 -0
- package/dist/verify/verify-full-command-rules.d.ts +18 -0
- package/dist/verify/verify-full-command-rules.js +77 -0
- package/dist/verify/verify-full-runner.d.ts +32 -0
- package/dist/verify/verify-full-runner.js +251 -0
- package/package.json +115 -4
- package/README.md +0 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export { readStagedPushVerification, readPushBranch } from "./delivery-verification.js";
|
|
2
|
+
import { type VerificationWorkspaceIdentity } from "./verification-identity.js";
|
|
3
|
+
export { normalizeVerificationWorkspaceIdentity, type VerificationWorkspaceIdentity } from "./verification-identity.js";
|
|
4
|
+
export declare function resolveVerificationStateRoot(workspaceRoot: string, input: VerificationWorkspaceIdentity): string;
|
|
5
|
+
export type TaskCommitGateErrorCode = "task.dev_process_file_staged" | "e2e.development_staged" | "e2e.temp_staged" | "repo.guard.failed" | "verify.proof.missing" | "verify.proof.stale" | "verify.proof.insufficient";
|
|
6
|
+
export type TaskCommitGateError = {
|
|
7
|
+
code: TaskCommitGateErrorCode;
|
|
8
|
+
message: string;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export type TaskCommitGateResult = {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
devKey?: string;
|
|
14
|
+
workspaceId?: string;
|
|
15
|
+
stagedFiles: string[];
|
|
16
|
+
proofPath: string | null;
|
|
17
|
+
errors: TaskCommitGateError[];
|
|
18
|
+
};
|
|
19
|
+
export declare function resolveVerifyProofRoot(workspaceRoot: string, devKey: string): string;
|
|
20
|
+
export declare function resolveVerifyProofPath(input: {
|
|
21
|
+
workspaceRoot: string;
|
|
22
|
+
devKey?: string;
|
|
23
|
+
workspaceId?: string;
|
|
24
|
+
}): string;
|
|
25
|
+
export declare function resolvePushProofPath(input: {
|
|
26
|
+
workspaceRoot: string;
|
|
27
|
+
devKey?: string;
|
|
28
|
+
workspaceId?: string;
|
|
29
|
+
}): string;
|
|
30
|
+
export type PushVerificationProof = {
|
|
31
|
+
schemaVersion: 1;
|
|
32
|
+
workspaceId: string;
|
|
33
|
+
headSha: string;
|
|
34
|
+
treeSha: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function writePushVerificationProof(input: {
|
|
38
|
+
workspaceRoot: string;
|
|
39
|
+
workspaceId: string;
|
|
40
|
+
headSha: string;
|
|
41
|
+
treeSha: string;
|
|
42
|
+
}): Promise<string>;
|
|
43
|
+
export declare function validatePushVerificationProof(input: {
|
|
44
|
+
workspaceRoot: string;
|
|
45
|
+
workspaceId: string;
|
|
46
|
+
headSha: string;
|
|
47
|
+
treeSha: string;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
ok: boolean;
|
|
50
|
+
proofPath: string;
|
|
51
|
+
reason?: string;
|
|
52
|
+
}>;
|
|
53
|
+
export declare function runTaskCommitGate(input: {
|
|
54
|
+
workspaceRoot: string;
|
|
55
|
+
devKey?: string;
|
|
56
|
+
workspaceId?: string;
|
|
57
|
+
requireVerifyProof?: boolean;
|
|
58
|
+
}): Promise<TaskCommitGateResult>;
|
|
59
|
+
/**
|
|
60
|
+
* 只读取已暂存 diff 的 raw 记录,确保待提交源码变化后必须重跑 verify full。
|
|
61
|
+
* 不能使用 `git write-tree`:它可能刷新 index 并创建 index.lock,反而让校验影响工作区。
|
|
62
|
+
*/
|
|
63
|
+
export declare function computeStagedChangesHash(workspaceRoot: string): Promise<string>;
|
|
64
|
+
export declare function listStagedFiles(workspaceRoot: string): Promise<string[]>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
export { readStagedPushVerification, readPushBranch } from "./delivery-verification.js";
|
|
2
|
+
import { assertVerificationCandidateIsIsolated } from "./verification-candidate.js";
|
|
3
|
+
import { executeRepoGuard } from "../guard/repo.js";
|
|
4
|
+
import { matchesVerificationProofIdentity, matchesVerificationProofCoverage } from "./verification-proof-rules.js";
|
|
5
|
+
import { findStagedProcessIssue } from "./commit-candidate-rules.js";
|
|
6
|
+
import { execFile } from "node:child_process";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { createVerificationImpactPlan } from "./impact-plan.js";
|
|
11
|
+
import { normalizeVerificationWorkspaceIdentity } from "./verification-identity.js";
|
|
12
|
+
export { normalizeVerificationWorkspaceIdentity } from "./verification-identity.js";
|
|
13
|
+
import { readCheckoutVerificationRuntime } from "./checkout-environment.js";
|
|
14
|
+
export function resolveVerificationStateRoot(workspaceRoot, input) {
|
|
15
|
+
const identity = normalizeVerificationWorkspaceIdentity(input);
|
|
16
|
+
return identity.workspaceId
|
|
17
|
+
? path.join(workspaceRoot, ".cache", "state", "workspaces", identity.workspaceId, "verify")
|
|
18
|
+
: path.join(workspaceRoot, ".cache", "state", identity.devKey, "verify");
|
|
19
|
+
}
|
|
20
|
+
export function resolveVerifyProofRoot(workspaceRoot, devKey) {
|
|
21
|
+
return path.join(resolveVerificationStateRoot(workspaceRoot, { devKey }), "commit");
|
|
22
|
+
}
|
|
23
|
+
export function resolveVerifyProofPath(input) {
|
|
24
|
+
return path.join(resolveVerificationStateRoot(input.workspaceRoot, input), "commit", "latest.json");
|
|
25
|
+
}
|
|
26
|
+
export function resolvePushProofPath(input) {
|
|
27
|
+
return path.join(resolveVerificationStateRoot(input.workspaceRoot, input), "push", "latest.json");
|
|
28
|
+
}
|
|
29
|
+
export async function writePushVerificationProof(input) {
|
|
30
|
+
const proofPath = resolvePushProofPath(input);
|
|
31
|
+
await mkdir(path.dirname(proofPath), { recursive: true });
|
|
32
|
+
const proof = {
|
|
33
|
+
schemaVersion: 1,
|
|
34
|
+
workspaceId: input.workspaceId,
|
|
35
|
+
headSha: input.headSha,
|
|
36
|
+
treeSha: input.treeSha,
|
|
37
|
+
createdAt: new Date().toISOString(),
|
|
38
|
+
};
|
|
39
|
+
await writeFile(proofPath, `${JSON.stringify(proof, null, 2)}\n`, "utf8");
|
|
40
|
+
return proofPath;
|
|
41
|
+
}
|
|
42
|
+
export async function validatePushVerificationProof(input) {
|
|
43
|
+
const proofPath = resolvePushProofPath(input);
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(await readFile(proofPath, "utf8"));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return { ok: false, proofPath, reason: "缺少推送门禁证明(push/latest.json),请先通过 agent-tool task push 执行推送门禁。" };
|
|
50
|
+
}
|
|
51
|
+
const proof = parsed;
|
|
52
|
+
if (!proof
|
|
53
|
+
|| proof.schemaVersion !== 1
|
|
54
|
+
|| proof.workspaceId !== input.workspaceId
|
|
55
|
+
|| proof.headSha !== input.headSha
|
|
56
|
+
|| proof.treeSha !== input.treeSha) {
|
|
57
|
+
return { ok: false, proofPath, reason: "推送门禁证明与当前 HEAD 提交或工作树不匹配,请重新执行推送门禁。" };
|
|
58
|
+
}
|
|
59
|
+
return { ok: true, proofPath };
|
|
60
|
+
}
|
|
61
|
+
export async function runTaskCommitGate(input) {
|
|
62
|
+
const identity = normalizeVerificationWorkspaceIdentity(input);
|
|
63
|
+
const stagedFiles = await listStagedFiles(input.workspaceRoot);
|
|
64
|
+
const errors = [];
|
|
65
|
+
const processIssue = findStagedProcessIssue(stagedFiles);
|
|
66
|
+
if (processIssue)
|
|
67
|
+
return buildResult({ ...identity, stagedFiles, proofPath: null, errors: [processIssue] });
|
|
68
|
+
if (input.requireVerifyProof === false)
|
|
69
|
+
return buildResult({ ...identity, stagedFiles, proofPath: null, errors });
|
|
70
|
+
// 本地 git commit 统一保持秒级轻量守卫;全量单测与 Story 门禁在 rebase origin/main 后的 task push 阶段执行。
|
|
71
|
+
await assertVerificationCandidateIsIsolated(input.workspaceRoot);
|
|
72
|
+
const guard = await executeRepoGuard({
|
|
73
|
+
args: [],
|
|
74
|
+
cwd: input.workspaceRoot,
|
|
75
|
+
workspaceRoot: input.workspaceRoot,
|
|
76
|
+
stdout: () => { },
|
|
77
|
+
stderr: () => { },
|
|
78
|
+
});
|
|
79
|
+
if (guard.counts.error > 0) {
|
|
80
|
+
errors.push({
|
|
81
|
+
code: "repo.guard.failed",
|
|
82
|
+
message: "仓库 repo guard 未通过。",
|
|
83
|
+
details: { diagnostics: guard.diagnostics },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return buildResult({ ...identity, stagedFiles, proofPath: null, errors });
|
|
87
|
+
}
|
|
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
|
+
/**
|
|
133
|
+
* 只读取已暂存 diff 的 raw 记录,确保待提交源码变化后必须重跑 verify full。
|
|
134
|
+
* 不能使用 `git write-tree`:它可能刷新 index 并创建 index.lock,反而让校验影响工作区。
|
|
135
|
+
*/
|
|
136
|
+
export async function computeStagedChangesHash(workspaceRoot) {
|
|
137
|
+
const rawDiff = await git(workspaceRoot, ["diff", "--cached", "--raw", "--no-abbrev"]);
|
|
138
|
+
return createHash("sha256").update(rawDiff).digest("hex");
|
|
139
|
+
}
|
|
140
|
+
export async function listStagedFiles(workspaceRoot) {
|
|
141
|
+
const output = await git(workspaceRoot, ["diff", "--cached", "--name-only", "--diff-filter=ACDMRT"]);
|
|
142
|
+
return output.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
143
|
+
}
|
|
144
|
+
function buildResult(input) {
|
|
145
|
+
return {
|
|
146
|
+
...input,
|
|
147
|
+
ok: input.errors.length === 0,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
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
|
+
async function git(cwd, args) {
|
|
167
|
+
return await new Promise((resolve, reject) => {
|
|
168
|
+
execFile("git", ["-c", "core.quotePath=false", ...args], {
|
|
169
|
+
cwd,
|
|
170
|
+
env: createGitEnv(),
|
|
171
|
+
timeout: 30_000,
|
|
172
|
+
}, (error, stdout, stderr) => {
|
|
173
|
+
if (error) {
|
|
174
|
+
reject(new Error(`git ${args.join(" ")} failed: ${stderr || error.message}`));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
resolve(stdout);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function createGitEnv() {
|
|
182
|
+
const env = { ...process.env };
|
|
183
|
+
for (const key of GIT_LOCAL_ENV_KEYS) {
|
|
184
|
+
delete env[key];
|
|
185
|
+
}
|
|
186
|
+
// Commit gate 只读取既有暂存树,绝不能为了刷新索引元数据而写入 index 或创建
|
|
187
|
+
// index.lock;验证过程不得修改、阻塞或影响待提交的工作区状态。
|
|
188
|
+
env.GIT_OPTIONAL_LOCKS = "0";
|
|
189
|
+
return env;
|
|
190
|
+
}
|
|
191
|
+
const GIT_LOCAL_ENV_KEYS = [
|
|
192
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
193
|
+
"GIT_CONFIG",
|
|
194
|
+
"GIT_CONFIG_PARAMETERS",
|
|
195
|
+
"GIT_CONFIG_COUNT",
|
|
196
|
+
"GIT_OBJECT_DIRECTORY",
|
|
197
|
+
"GIT_DIR",
|
|
198
|
+
"GIT_WORK_TREE",
|
|
199
|
+
"GIT_IMPLICIT_WORK_TREE",
|
|
200
|
+
"GIT_GRAFT_FILE",
|
|
201
|
+
"GIT_INDEX_FILE",
|
|
202
|
+
"GIT_NO_REPLACE_OBJECTS",
|
|
203
|
+
"GIT_REPLACE_REF_BASE",
|
|
204
|
+
"GIT_PREFIX",
|
|
205
|
+
"GIT_SHALLOW_FILE",
|
|
206
|
+
"GIT_COMMON_DIR",
|
|
207
|
+
];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { kuafuManifestSchema } from "@kuafucloud/product-build/repository/kuafu-manifest";
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
/** 推送校验策略取自索引中的 kuafu.json,默认执行轻量化全量推送门禁(push-gate)。 */
|
|
6
|
+
export async function readStagedPushVerification(workspaceRoot) {
|
|
7
|
+
const options = { cwd: workspaceRoot, encoding: "utf8" };
|
|
8
|
+
const indexed = await execFileAsync("git", ["ls-files", "--cached", "-z", "--", "kuafu.json"], options);
|
|
9
|
+
if (!indexed.stdout)
|
|
10
|
+
return "push-gate";
|
|
11
|
+
const content = await execFileAsync("git", ["show", ":kuafu.json"], options);
|
|
12
|
+
return kuafuManifestSchema.parse(JSON.parse(content.stdout)).push?.verification ?? "push-gate";
|
|
13
|
+
}
|
|
14
|
+
export async function readPushBranch(workspaceRoot) {
|
|
15
|
+
const options = { cwd: workspaceRoot, encoding: "utf8" };
|
|
16
|
+
const indexed = await execFileAsync("git", ["ls-files", "--cached", "-z", "--", "kuafu.json"], options);
|
|
17
|
+
if (!indexed.stdout)
|
|
18
|
+
return "main";
|
|
19
|
+
const content = await execFileAsync("git", ["show", ":kuafu.json"], options);
|
|
20
|
+
return kuafuManifestSchema.parse(JSON.parse(content.stdout)).push?.branch ?? "main";
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type VerificationE2ESuiteV1 = {
|
|
2
|
+
id: string;
|
|
3
|
+
owners: string[];
|
|
4
|
+
dependencies: string[];
|
|
5
|
+
surface: "browser" | "app-simulator" | "mini-program" | "electron";
|
|
6
|
+
artifactProducts: string[];
|
|
7
|
+
tests: string[];
|
|
8
|
+
standaloneProductId?: string;
|
|
9
|
+
serialGroup?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* affected 与 full 共用的版本化 E2E registry。这里声明领域闭包,不从 Product
|
|
13
|
+
* 名称推断 viewport、端口或 Runtime;runner 只按 suite id 解析实际资源。
|
|
14
|
+
*/
|
|
15
|
+
export declare const VERIFICATION_E2E_SUITES_V1: readonly VerificationE2ESuiteV1[];
|
|
16
|
+
export declare function selectVerificationE2ESuites(projects: readonly string[], full: boolean): string[];
|
|
17
|
+
export declare function resolveVerificationE2ESuites(ids: readonly string[]): VerificationE2ESuiteV1[];
|
|
18
|
+
/**
|
|
19
|
+
* registry 是版本化的执行契约,不能只验证 selector 形状:每个被选中的
|
|
20
|
+
* suite 都必须至少落到一个持久化测试文件,否则 affected/full 会产生假绿。
|
|
21
|
+
*/
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* affected 与 full 共用的版本化 E2E registry。这里声明领域闭包,不从 Product
|
|
3
|
+
* 名称推断 viewport、端口或 Runtime;runner 只按 suite id 解析实际资源。
|
|
4
|
+
*/
|
|
5
|
+
export const VERIFICATION_E2E_SUITES_V1 = [];
|
|
6
|
+
export function selectVerificationE2ESuites(projects, full) {
|
|
7
|
+
const affected = new Set(projects);
|
|
8
|
+
return VERIFICATION_E2E_SUITES_V1
|
|
9
|
+
.filter((suite) => full || [...suite.owners, ...suite.dependencies].some((project) => affected.has(project)))
|
|
10
|
+
.map((suite) => suite.id);
|
|
11
|
+
}
|
|
12
|
+
export function resolveVerificationE2ESuites(ids) {
|
|
13
|
+
const byId = new Map(VERIFICATION_E2E_SUITES_V1.map((suite) => [suite.id, suite]));
|
|
14
|
+
if (byId.size !== VERIFICATION_E2E_SUITES_V1.length) {
|
|
15
|
+
throw new Error("verification.e2e_closure_invalid: duplicate suite id");
|
|
16
|
+
}
|
|
17
|
+
return ids.map((id) => {
|
|
18
|
+
const suite = byId.get(id);
|
|
19
|
+
if (!suite)
|
|
20
|
+
throw new Error(`verification.e2e_closure_invalid: unknown suite ${id}`);
|
|
21
|
+
if (suite.tests.length === 0 || suite.tests.some((test) => !test.endsWith(".test.ts") && !test.endsWith("/**/*.test.ts"))) {
|
|
22
|
+
throw new Error(`verification.e2e_closure_invalid: suite ${id} has invalid test selectors`);
|
|
23
|
+
}
|
|
24
|
+
if (suite.standaloneProductId && !suite.artifactProducts.includes(suite.standaloneProductId)) {
|
|
25
|
+
throw new Error(`verification.e2e_closure_invalid: suite ${id} local product is not an artifact owner`);
|
|
26
|
+
}
|
|
27
|
+
return suite;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* registry 是版本化的执行契约,不能只验证 selector 形状:每个被选中的
|
|
32
|
+
* suite 都必须至少落到一个持久化测试文件,否则 affected/full 会产生假绿。
|
|
33
|
+
*/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { resolveVerificationE2ESuites } from "./e2e-registry-rules.js";
|
|
2
|
+
export * from "./e2e-registry-rules.js";
|
|
3
|
+
export async function assertVerificationE2EClosure(workspaceRoot, ids) {
|
|
4
|
+
const suites = resolveVerificationE2ESuites(ids);
|
|
5
|
+
for (const suite of suites) {
|
|
6
|
+
const matches = await Promise.all(suite.tests.map(async (selector) => {
|
|
7
|
+
if (selector.endsWith("/**/*.test.ts")) {
|
|
8
|
+
const root = selector.replace(/\/\*\*\/\*\.test\.ts$/u, "");
|
|
9
|
+
return await containsPersistentTest(path.join(workspaceRoot, root));
|
|
10
|
+
}
|
|
11
|
+
// 精确 selector 不应递归目录,也不能由同目录其它测试代替。
|
|
12
|
+
try {
|
|
13
|
+
return (await stat(path.join(workspaceRoot, selector))).isFile();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error.code === "ENOENT")
|
|
17
|
+
return false;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
if (!matches.some(Boolean)) {
|
|
22
|
+
throw new Error(`verification.e2e_closure_invalid: suite ${suite.id} resolves to zero tests`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function containsPersistentTest(directory) {
|
|
27
|
+
let entries;
|
|
28
|
+
try {
|
|
29
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.code === "ENOENT")
|
|
33
|
+
return false;
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
if (entry.isFile() && entry.name.endsWith(".test.ts"))
|
|
38
|
+
return true;
|
|
39
|
+
if (entry.isDirectory() && await containsPersistentTest(path.join(directory, entry.name)))
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
import { readdir, stat } from "node:fs/promises";
|
|
45
|
+
import path from "node:path";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type VerifyFullDatabaseBackend = "do" | "postgres";
|
|
2
|
+
export declare const WORKSPACE_CORE_BROWSER_COMMAND = "pnpm --dir products/host run test:workspace-core";
|
|
3
|
+
export declare const BROWSER_TEST_COMMAND = "node --import tsx products/host/scripts/test-browser.mjs";
|
|
4
|
+
export declare function createDefaultPushVerifyPlan(input?: {
|
|
5
|
+
repositoryGuardCommand?: string;
|
|
6
|
+
repositoryBuildCommand?: string;
|
|
7
|
+
}): {
|
|
8
|
+
beforePrepareCommands: string[];
|
|
9
|
+
commands: string[];
|
|
10
|
+
workerInputsAfter: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function createDefaultPushVerifyCommand(input?: Parameters<typeof createDefaultPushVerifyPlan>[0]): string;
|
|
13
|
+
export declare function createDefaultVerifyFullPlan(input?: {
|
|
14
|
+
databaseBackend?: string | null;
|
|
15
|
+
repositoryGuardCommand?: string;
|
|
16
|
+
repositoryBuildCommand?: string;
|
|
17
|
+
}): {
|
|
18
|
+
beforePrepareCommands: string[];
|
|
19
|
+
commands: string[];
|
|
20
|
+
workerInputsAfter: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function createDefaultVerifyFullCommand(input?: Parameters<typeof createDefaultVerifyFullPlan>[0]): string;
|
|
23
|
+
export declare function createHostArtifactSessionCommand(commands: string[], releaseOnSuccess?: boolean, beforePrepareCommands?: string[], workerInputsAfter?: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* 发布 Workflow 的“全量校验”只验证冻结源码的质量,不能嵌套执行全仓构建
|
|
26
|
+
* 或浏览器验收:构建属于下一阶段,而浏览器验收会再次创建 DevManager / Release
|
|
27
|
+
* Job,形成递归。提交前的 `verify full` 仍保留完整 L3/L4 门禁语义。
|
|
28
|
+
*/
|
|
29
|
+
export declare function createDefaultReleaseVerifyPlan(input?: {
|
|
30
|
+
repositoryGuardCommand?: string;
|
|
31
|
+
}): {
|
|
32
|
+
beforePrepareCommands: string[];
|
|
33
|
+
commands: never[];
|
|
34
|
+
};
|
|
35
|
+
export declare function createDefaultReleaseVerifyCommand(input?: Parameters<typeof createDefaultReleaseVerifyPlan>[0]): string;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const E2E_DATABASE_BACKEND_ENV = "PLATFORM_E2E_DATABASE_BACKEND";
|
|
2
|
+
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
|
+
// 先核对真实任务图的写入依赖排他,再让只读检查使用有界并行;保留全部依赖边。
|
|
4
|
+
const REPOSITORY_TYPECHECK = "node --import tsx packages/host-tooling/scripts/verify-static-checks.mjs check-types";
|
|
5
|
+
const REPOSITORY_LINT = "node --import tsx packages/host-tooling/scripts/verify-static-checks.mjs lint";
|
|
6
|
+
// test目标自身禁止结果缓存,依赖build继续按源码身份复用;不能用全图skip禁用构建缓存。
|
|
7
|
+
const PARALLEL_REPOSITORY_UNITS = "pnpm exec nx run-many --target=test:unit --all --parallel=3 --nx-bail=true";
|
|
8
|
+
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
|
+
const PLATFORM_WORKSPACE_MARKER = "packages/platform-tool/package.json";
|
|
11
|
+
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
|
+
// Browser E2E 使用隔离的 Test Host Renderer;它不是安装态 Host 的运行模式。
|
|
13
|
+
export const BROWSER_TEST_COMMAND = "node --import tsx products/host/scripts/test-browser.mjs";
|
|
14
|
+
// Host 本地宿主集成测试必须消费当前源码新打出的正常安装态候选,不能复用上次的 unpacked App,
|
|
15
|
+
// 也不能把 Browser Test Host 的标记打进候选包。
|
|
16
|
+
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
|
+
const HOST_INTEGRATION_TESTS = "PLATFORM_E2E_PREBUILT=1 pnpm --dir products/host run test:integration";
|
|
19
|
+
export function createDefaultPushVerifyPlan(input) {
|
|
20
|
+
const beforePrepareCommands = [
|
|
21
|
+
"node packages/host-tooling/scripts/verify-test-layers.mjs",
|
|
22
|
+
PARALLEL_REPOSITORY_UNITS,
|
|
23
|
+
REPOSITORY_TYPECHECK,
|
|
24
|
+
REPOSITORY_LINT,
|
|
25
|
+
"pnpm exec eslint .",
|
|
26
|
+
input?.repositoryGuardCommand ?? "./agent-tool guard repo --verify-facades",
|
|
27
|
+
PLATFORM_ARCHITECTURE_GATE,
|
|
28
|
+
...(input?.repositoryGuardCommand ? ["node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check"] : []),
|
|
29
|
+
input?.repositoryBuildCommand ?? "./agent-tool build repo",
|
|
30
|
+
];
|
|
31
|
+
const commands = [
|
|
32
|
+
"./agent-tool verify story",
|
|
33
|
+
];
|
|
34
|
+
return { beforePrepareCommands, commands, workerInputsAfter: 1 };
|
|
35
|
+
}
|
|
36
|
+
export function createDefaultPushVerifyCommand(input) {
|
|
37
|
+
const plan = createDefaultPushVerifyPlan(input);
|
|
38
|
+
const platformCommand = createHostArtifactSessionCommand(plan.commands, false, plan.beforePrepareCommands, plan.workerInputsAfter);
|
|
39
|
+
const storyCheck = "if find . -maxdepth 5 -name '*.story.ts' -not -path '*/node_modules/*' | grep -q .; then ./agent-tool verify story; fi";
|
|
40
|
+
const facadeCheck = "if [ -f node_modules/@kuafucloud/product-build/bin/product-build.mjs ] && [ -d packages/extensions ]; then node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check; fi";
|
|
41
|
+
const repositoryCommand = `${input?.repositoryGuardCommand ?? "./agent-tool guard repo"} && ${facadeCheck} && pnpm run verify && ${storyCheck}`;
|
|
42
|
+
const missingVerifyCommand = "echo 'verify push: non-platform repository must define package.json scripts.verify' >&2; exit 1";
|
|
43
|
+
return [
|
|
44
|
+
"export NX_DAEMON=false NX_NO_NETWORK_REQUESTS=true NX_TUI=false",
|
|
45
|
+
`if [ -f ${PLATFORM_WORKSPACE_MARKER} ]; then ${platformCommand}; elif ${REPOSITORY_VERIFY_SCRIPT_CHECK}; then ${repositoryCommand}; else ${missingVerifyCommand}; fi`,
|
|
46
|
+
].join("; ");
|
|
47
|
+
}
|
|
48
|
+
export function createDefaultVerifyFullPlan(input) {
|
|
49
|
+
const dbBackend = normalizeDatabaseBackend(input?.databaseBackend) ?? "do";
|
|
50
|
+
const storyVerifyCommand = dbBackend === "do"
|
|
51
|
+
? "./agent-tool verify story"
|
|
52
|
+
: `./agent-tool verify story --db ${dbBackend}`;
|
|
53
|
+
const beforePrepareCommands = [
|
|
54
|
+
"node packages/host-tooling/scripts/verify-test-layers.mjs",
|
|
55
|
+
PARALLEL_REPOSITORY_UNITS,
|
|
56
|
+
REPOSITORY_TYPECHECK,
|
|
57
|
+
REPOSITORY_LINT,
|
|
58
|
+
"pnpm exec eslint .",
|
|
59
|
+
input?.repositoryGuardCommand ?? "./agent-tool guard repo --verify-facades",
|
|
60
|
+
PLATFORM_ARCHITECTURE_GATE,
|
|
61
|
+
...(input?.repositoryGuardCommand ? ["node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check"] : []),
|
|
62
|
+
input?.repositoryBuildCommand ?? "./agent-tool build repo",
|
|
63
|
+
];
|
|
64
|
+
const commands = [
|
|
65
|
+
// 方案 19 & 20:全量产品故事验证(DO SQLite 专属故事环境,Postgres 明确拒绝)
|
|
66
|
+
storyVerifyCommand,
|
|
67
|
+
// 生成正常安装态候选并运行 Host 本地原生宿主集成测试。
|
|
68
|
+
CONSOLE_INSTALLED_HOST_CANDIDATE,
|
|
69
|
+
HOST_INTEGRATION_TESTS,
|
|
70
|
+
];
|
|
71
|
+
return { beforePrepareCommands, commands, workerInputsAfter: 1 };
|
|
72
|
+
}
|
|
73
|
+
export function createDefaultVerifyFullCommand(input) {
|
|
74
|
+
const plan = createDefaultVerifyFullPlan(input);
|
|
75
|
+
const platformCommand = createHostArtifactSessionCommand(plan.commands, false, plan.beforePrepareCommands, plan.workerInputsAfter);
|
|
76
|
+
// 自有脚本负责业务测试;生成物与仓库基线不能因 full 分支而跳过。
|
|
77
|
+
const repositoryCommand = `${input?.repositoryGuardCommand ?? "./agent-tool guard repo"} && node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check && pnpm run verify`;
|
|
78
|
+
const missingVerifyCommand = "echo 'verify full: non-platform repository must define package.json scripts.verify' >&2; exit 1";
|
|
79
|
+
return [
|
|
80
|
+
"export NX_DAEMON=false NX_NO_NETWORK_REQUESTS=true NX_TUI=false",
|
|
81
|
+
`if [ -f ${PLATFORM_WORKSPACE_MARKER} ]; then ${platformCommand}; elif ${REPOSITORY_VERIFY_SCRIPT_CHECK}; then ${repositoryCommand}; else ${missingVerifyCommand}; fi`,
|
|
82
|
+
].join("; ");
|
|
83
|
+
}
|
|
84
|
+
export function createHostArtifactSessionCommand(commands, releaseOnSuccess = false, beforePrepareCommands = [], workerInputsAfter) {
|
|
85
|
+
// 一个父级调用计划跨 Nx/Core/Electron 持有正式输入。
|
|
86
|
+
// JSON 是命令数据;按 shell 单引号规则编码,不能靠 JSON.stringify 充当 shell 转义。
|
|
87
|
+
const plan = `'${JSON.stringify(beforePrepareCommands.length || workerInputsAfter !== undefined ? { beforePrepareCommands, commands, ...(workerInputsAfter === undefined ? {} : { workerInputsAfter }) } : commands).replaceAll("'", "'\"'\"'")}'`;
|
|
88
|
+
return `node --import tsx products/host/scripts/test-artifact-session.mjs ${plan}${releaseOnSuccess ? " --release-on-success" : ""}`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 发布 Workflow 的“全量校验”只验证冻结源码的质量,不能嵌套执行全仓构建
|
|
92
|
+
* 或浏览器验收:构建属于下一阶段,而浏览器验收会再次创建 DevManager / Release
|
|
93
|
+
* Job,形成递归。提交前的 `verify full` 仍保留完整 L3/L4 门禁语义。
|
|
94
|
+
*/
|
|
95
|
+
export function createDefaultReleaseVerifyPlan(input) {
|
|
96
|
+
const beforePrepareCommands = [
|
|
97
|
+
"node packages/host-tooling/scripts/verify-test-layers.mjs",
|
|
98
|
+
PARALLEL_REPOSITORY_UNITS,
|
|
99
|
+
REPOSITORY_TYPECHECK,
|
|
100
|
+
REPOSITORY_LINT,
|
|
101
|
+
"pnpm exec eslint .",
|
|
102
|
+
input?.repositoryGuardCommand ?? "./agent-tool guard repo --verify-facades",
|
|
103
|
+
PLATFORM_ARCHITECTURE_GATE,
|
|
104
|
+
...(input?.repositoryGuardCommand ? ["node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check"] : []),
|
|
105
|
+
];
|
|
106
|
+
return { beforePrepareCommands, commands: [] };
|
|
107
|
+
}
|
|
108
|
+
export function createDefaultReleaseVerifyCommand(input) {
|
|
109
|
+
const plan = createDefaultReleaseVerifyPlan(input);
|
|
110
|
+
const platformCommand = createHostArtifactSessionCommand(plan.commands, true, plan.beforePrepareCommands);
|
|
111
|
+
const repositoryCommand = `${input?.repositoryGuardCommand ?? "./agent-tool guard repo"} && node node_modules/@kuafucloud/product-build/bin/product-build.mjs facades --cwd . --check && pnpm run verify`;
|
|
112
|
+
const missingVerifyCommand = "echo 'verify release: non-platform repository must define package.json scripts.verify' >&2; exit 1";
|
|
113
|
+
return [
|
|
114
|
+
"export NX_DAEMON=false NX_NO_NETWORK_REQUESTS=true NX_TUI=false",
|
|
115
|
+
`if [ -f ${PLATFORM_WORKSPACE_MARKER} ]; then ${platformCommand}; elif ${REPOSITORY_VERIFY_SCRIPT_CHECK}; then ${repositoryCommand}; else ${missingVerifyCommand}; fi`,
|
|
116
|
+
].join("; ");
|
|
117
|
+
}
|
|
118
|
+
function normalizeDatabaseBackend(value) {
|
|
119
|
+
const normalized = value?.trim().toLowerCase();
|
|
120
|
+
if (!normalized) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
if (normalized === "do" || normalized === "postgres") {
|
|
124
|
+
return normalized;
|
|
125
|
+
}
|
|
126
|
+
throw new Error(`Unsupported database backend: ${value}. Use "do" or "postgres".`);
|
|
127
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { NativeToolVerificationRecipe } from "./repository-recipe-rules.js";
|
|
2
|
+
export declare const VERIFICATION_CLASSIFIER_VERSION = "1.0.0";
|
|
3
|
+
export declare const AFFECTED_PROJECT_LIMIT = 12;
|
|
4
|
+
export declare const AFFECTED_PROJECT_RATIO = 0.4;
|
|
5
|
+
export type VerificationScope = "auto" | "full";
|
|
6
|
+
export type VerificationMode = "affected" | "full";
|
|
7
|
+
export type StagedChangeKind = "A" | "C" | "D" | "M" | "R" | "T";
|
|
8
|
+
export type VerificationChangedPath = {
|
|
9
|
+
kind: StagedChangeKind;
|
|
10
|
+
path: string;
|
|
11
|
+
oldPath?: string;
|
|
12
|
+
};
|
|
13
|
+
export type VerificationProjectNode = {
|
|
14
|
+
name: string;
|
|
15
|
+
root: string;
|
|
16
|
+
targets: string[];
|
|
17
|
+
tags: string[];
|
|
18
|
+
verification?: {
|
|
19
|
+
type: string;
|
|
20
|
+
targetExemptions: Partial<Record<"build" | "lint" | "test" | "check-types", string>>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type VerificationProjectGraph = {
|
|
24
|
+
nodes: Record<string, VerificationProjectNode>;
|
|
25
|
+
dependencies: Record<string, string[]>;
|
|
26
|
+
};
|
|
27
|
+
export type VerificationImpactPlanV1 = {
|
|
28
|
+
repositoryRecipe?: NativeToolVerificationRecipe;
|
|
29
|
+
schemaVersion: 1;
|
|
30
|
+
classifierVersion: string;
|
|
31
|
+
requestedScope: VerificationScope;
|
|
32
|
+
resolvedMode: VerificationMode;
|
|
33
|
+
headSha: string;
|
|
34
|
+
stagedChangesHash: string;
|
|
35
|
+
changedPaths: VerificationChangedPath[];
|
|
36
|
+
directProjects: string[];
|
|
37
|
+
affectedProjects: string[];
|
|
38
|
+
affectedProducts: string[];
|
|
39
|
+
targetsByProject: Record<string, string[]>;
|
|
40
|
+
e2eTargets: string[];
|
|
41
|
+
alwaysRunChecks: string[];
|
|
42
|
+
escalationReasons: string[];
|
|
43
|
+
nxGraphDigest: string;
|
|
44
|
+
planDigest: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function buildVerificationImpactPlan(input: {
|
|
47
|
+
requestedScope: VerificationScope;
|
|
48
|
+
changedPaths: VerificationChangedPath[];
|
|
49
|
+
graph: VerificationProjectGraph;
|
|
50
|
+
headSha?: string;
|
|
51
|
+
stagedChangesHash?: string;
|
|
52
|
+
e2eRegistryEnabled?: boolean;
|
|
53
|
+
repositoryRecipe?: NativeToolVerificationRecipe;
|
|
54
|
+
}): VerificationImpactPlanV1;
|
|
55
|
+
export declare const STANDARD_PROJECT_TARGETS: readonly ["check-types", "lint", "build", "test"];
|
|
56
|
+
export declare function stableChanges(changes: VerificationChangedPath[]): {
|
|
57
|
+
oldPath?: string;
|
|
58
|
+
path: string;
|
|
59
|
+
kind: StagedChangeKind;
|
|
60
|
+
}[];
|
|
61
|
+
export declare function normalizePath(value: string): string;
|