@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,151 @@
|
|
|
1
|
+
import { resolveProfileConfig } from "./config.js";
|
|
2
|
+
export async function runGuard(input) {
|
|
3
|
+
const resolvedProfile = resolveProfileConfig({
|
|
4
|
+
config: input.config,
|
|
5
|
+
profileName: input.profileName,
|
|
6
|
+
});
|
|
7
|
+
const selectedRuleIds = resolvedProfile.rules.map((item) => item.id);
|
|
8
|
+
const cache = new Map();
|
|
9
|
+
const diagnostics = [];
|
|
10
|
+
for (const ruleSelection of resolvedProfile.rules) {
|
|
11
|
+
const rule = input.ruleRegistry[ruleSelection.id];
|
|
12
|
+
if (!rule) {
|
|
13
|
+
throw new Error(`Unknown guard rule "${ruleSelection.id}".`);
|
|
14
|
+
}
|
|
15
|
+
const parsedOptions = parseRuleOptions(rule, ruleSelection.options);
|
|
16
|
+
const ruleContext = {
|
|
17
|
+
workspaceRoot: input.workspaceRoot,
|
|
18
|
+
profileName: input.profileName,
|
|
19
|
+
options: parsedOptions,
|
|
20
|
+
cache,
|
|
21
|
+
loadCache: async (key, loader) => {
|
|
22
|
+
if (cache.has(key)) {
|
|
23
|
+
return cache.get(key);
|
|
24
|
+
}
|
|
25
|
+
const value = await loader();
|
|
26
|
+
cache.set(key, value);
|
|
27
|
+
return value;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const ruleDiagnostics = (await rule.run(ruleContext)) ?? [];
|
|
31
|
+
for (const diagnostic of ruleDiagnostics) {
|
|
32
|
+
diagnostics.push({
|
|
33
|
+
...diagnostic,
|
|
34
|
+
ruleId: diagnostic.ruleId || rule.meta.id,
|
|
35
|
+
severity: diagnostic.severity ?? ruleSelection.severity,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const filteredDiagnostics = applyWhitelist(diagnostics, input.config.whitelist ?? [], new Set(selectedRuleIds));
|
|
40
|
+
filteredDiagnostics.sort(compareDiagnostics);
|
|
41
|
+
const counts = countDiagnostics(filteredDiagnostics);
|
|
42
|
+
return {
|
|
43
|
+
workspaceRoot: input.workspaceRoot,
|
|
44
|
+
profileName: input.profileName,
|
|
45
|
+
diagnostics: filteredDiagnostics,
|
|
46
|
+
counts,
|
|
47
|
+
selectedRuleIds,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function parseRuleOptions(rule, input) {
|
|
51
|
+
if (!rule.schema) {
|
|
52
|
+
return input ?? {};
|
|
53
|
+
}
|
|
54
|
+
return rule.schema.parse(input ?? {});
|
|
55
|
+
}
|
|
56
|
+
function applyWhitelist(diagnostics, whitelist, selectedRuleIds) {
|
|
57
|
+
const activeRuleIds = new Set(selectedRuleIds);
|
|
58
|
+
for (const diagnostic of diagnostics) {
|
|
59
|
+
activeRuleIds.add(diagnostic.ruleId);
|
|
60
|
+
}
|
|
61
|
+
const matchedIndexes = new Set();
|
|
62
|
+
const filtered = diagnostics.filter((diagnostic) => {
|
|
63
|
+
const index = whitelist.findIndex((entry) => {
|
|
64
|
+
if (!activeRuleIds.has(entry.rule)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (entry.rule !== diagnostic.ruleId) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (entry.path !== diagnostic.filePath) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (entry.lineNumber !== undefined &&
|
|
74
|
+
entry.lineNumber !== diagnostic.line) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (entry.messageIncludes &&
|
|
78
|
+
!diagnostic.message.includes(entry.messageIncludes)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
if (index < 0) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
matchedIndexes.add(index);
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
whitelist.forEach((entry, index) => {
|
|
90
|
+
if (!activeRuleIds.has(entry.rule)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (matchedIndexes.has(index)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
filtered.push({
|
|
97
|
+
ruleId: "whitelist-entry-unused",
|
|
98
|
+
severity: "error",
|
|
99
|
+
filePath: "guard.config.ts",
|
|
100
|
+
line: 1,
|
|
101
|
+
message: [
|
|
102
|
+
`Whitelist entry #${index + 1} is unused.`,
|
|
103
|
+
`rule="${entry.rule}"`,
|
|
104
|
+
`path="${entry.path}"`,
|
|
105
|
+
`reason="${entry.reason}"`,
|
|
106
|
+
].join(" "),
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return filtered;
|
|
110
|
+
}
|
|
111
|
+
function compareDiagnostics(left, right) {
|
|
112
|
+
if (left.filePath !== right.filePath) {
|
|
113
|
+
return left.filePath.localeCompare(right.filePath);
|
|
114
|
+
}
|
|
115
|
+
if (left.line !== right.line) {
|
|
116
|
+
return left.line - right.line;
|
|
117
|
+
}
|
|
118
|
+
if (left.severity !== right.severity) {
|
|
119
|
+
return severityRank(left.severity) - severityRank(right.severity);
|
|
120
|
+
}
|
|
121
|
+
return left.ruleId.localeCompare(right.ruleId);
|
|
122
|
+
}
|
|
123
|
+
function severityRank(severity) {
|
|
124
|
+
if (severity === "error") {
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
if (severity === "warning") {
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
return 2;
|
|
131
|
+
}
|
|
132
|
+
function countDiagnostics(diagnostics) {
|
|
133
|
+
const counts = {
|
|
134
|
+
total: diagnostics.length,
|
|
135
|
+
error: 0,
|
|
136
|
+
warning: 0,
|
|
137
|
+
note: 0,
|
|
138
|
+
};
|
|
139
|
+
for (const diagnostic of diagnostics) {
|
|
140
|
+
if (diagnostic.severity === "error") {
|
|
141
|
+
counts.error += 1;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (diagnostic.severity === "warning") {
|
|
145
|
+
counts.warning += 1;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
counts.note += 1;
|
|
149
|
+
}
|
|
150
|
+
return counts;
|
|
151
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function formatGuardSarifValue(result, platformVersion) {
|
|
3
|
+
const rules = uniqueRuleIds(result.diagnostics).map((ruleId) => ({
|
|
4
|
+
id: ruleId,
|
|
5
|
+
shortDescription: {
|
|
6
|
+
text: ruleId,
|
|
7
|
+
},
|
|
8
|
+
}));
|
|
9
|
+
const sarif = {
|
|
10
|
+
version: "2.1.0",
|
|
11
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
12
|
+
runs: [
|
|
13
|
+
{
|
|
14
|
+
tool: {
|
|
15
|
+
driver: {
|
|
16
|
+
name: "agent-tool guard repo",
|
|
17
|
+
informationUri: "https://kuafucloud.dev",
|
|
18
|
+
semanticVersion: platformVersion,
|
|
19
|
+
rules,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
results: result.diagnostics.map((diagnostic) => toSarifResult(result.workspaceRoot, diagnostic)),
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
return JSON.stringify(sarif, null, 2);
|
|
27
|
+
}
|
|
28
|
+
function toSarifResult(workspaceRoot, diagnostic) {
|
|
29
|
+
const uri = path.isAbsolute(diagnostic.filePath)
|
|
30
|
+
? toPosixPath(path.relative(workspaceRoot, diagnostic.filePath))
|
|
31
|
+
: toPosixPath(diagnostic.filePath);
|
|
32
|
+
return {
|
|
33
|
+
ruleId: diagnostic.ruleId,
|
|
34
|
+
level: toSarifLevel(diagnostic.severity),
|
|
35
|
+
message: {
|
|
36
|
+
text: diagnostic.message,
|
|
37
|
+
},
|
|
38
|
+
locations: [
|
|
39
|
+
{
|
|
40
|
+
physicalLocation: {
|
|
41
|
+
artifactLocation: {
|
|
42
|
+
uri,
|
|
43
|
+
},
|
|
44
|
+
region: {
|
|
45
|
+
startLine: diagnostic.line,
|
|
46
|
+
startColumn: diagnostic.column ?? 1,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function toSarifLevel(severity) {
|
|
54
|
+
if (severity === "error") {
|
|
55
|
+
return "error";
|
|
56
|
+
}
|
|
57
|
+
if (severity === "warning") {
|
|
58
|
+
return "warning";
|
|
59
|
+
}
|
|
60
|
+
return "note";
|
|
61
|
+
}
|
|
62
|
+
function uniqueRuleIds(diagnostics) {
|
|
63
|
+
return [...new Set(diagnostics.map((diagnostic) => diagnostic.ruleId))].sort((left, right) => left.localeCompare(right));
|
|
64
|
+
}
|
|
65
|
+
function toPosixPath(value) {
|
|
66
|
+
return value.split(path.sep).join("/");
|
|
67
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function formatGuardText(result) {
|
|
2
|
+
if (result.diagnostics.length === 0) {
|
|
3
|
+
return [
|
|
4
|
+
"repo-guard passed",
|
|
5
|
+
`profile=${result.profileName}`,
|
|
6
|
+
`rules=${result.selectedRuleIds.length}`,
|
|
7
|
+
"issues=0",
|
|
8
|
+
].join(" ");
|
|
9
|
+
}
|
|
10
|
+
const lines = [result.counts.error > 0 ? "repo-guard failed:" : "repo-guard passed:"];
|
|
11
|
+
for (const diagnostic of result.diagnostics) {
|
|
12
|
+
lines.push(`${diagnostic.filePath}:${diagnostic.line} [${diagnostic.ruleId}] ${diagnostic.message}`);
|
|
13
|
+
}
|
|
14
|
+
lines.push([
|
|
15
|
+
"summary",
|
|
16
|
+
`total=${result.counts.total}`,
|
|
17
|
+
`error=${result.counts.error}`,
|
|
18
|
+
`warning=${result.counts.warning}`,
|
|
19
|
+
`note=${result.counts.note}`,
|
|
20
|
+
].join(" "));
|
|
21
|
+
return lines.join("\n");
|
|
22
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export type GuardSeverity = "error" | "warning" | "note";
|
|
3
|
+
export type GuardRuleLevel = "L0" | "L1" | "L2" | "L3";
|
|
4
|
+
export type GuardOutputFormat = "text" | "sarif";
|
|
5
|
+
export type GuardDiagnostic = {
|
|
6
|
+
ruleId: string;
|
|
7
|
+
severity: GuardSeverity;
|
|
8
|
+
filePath: string;
|
|
9
|
+
line: number;
|
|
10
|
+
column?: number;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export type GuardRuleMeta = {
|
|
14
|
+
id: string;
|
|
15
|
+
title: string;
|
|
16
|
+
level: GuardRuleLevel;
|
|
17
|
+
description?: string;
|
|
18
|
+
};
|
|
19
|
+
export type GuardRuleContext<TOptions = unknown> = {
|
|
20
|
+
workspaceRoot: string;
|
|
21
|
+
profileName: string;
|
|
22
|
+
options: TOptions;
|
|
23
|
+
cache: Map<string, unknown>;
|
|
24
|
+
loadCache: <T>(key: string, loader: () => Promise<T> | T) => Promise<T>;
|
|
25
|
+
};
|
|
26
|
+
export type GuardRuleDefinition<TOptions = unknown> = {
|
|
27
|
+
meta: GuardRuleMeta;
|
|
28
|
+
schema?: z.ZodType<TOptions>;
|
|
29
|
+
defaultSeverity?: GuardSeverity;
|
|
30
|
+
run: (context: GuardRuleContext<TOptions>) => Promise<GuardDiagnostic[] | void> | GuardDiagnostic[] | void;
|
|
31
|
+
};
|
|
32
|
+
export type GuardRuleRegistry = Record<string, GuardRuleDefinition>;
|
|
33
|
+
export type GuardWhitelistEntry = {
|
|
34
|
+
rule: string;
|
|
35
|
+
path: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
lineNumber?: number;
|
|
38
|
+
messageIncludes?: string;
|
|
39
|
+
};
|
|
40
|
+
export type GuardRuleSelection = string | {
|
|
41
|
+
id: string;
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
severity?: GuardSeverity;
|
|
44
|
+
options?: unknown;
|
|
45
|
+
};
|
|
46
|
+
export type GuardRuleSetConfig = {
|
|
47
|
+
rules: GuardRuleSelection[];
|
|
48
|
+
};
|
|
49
|
+
export type GuardProfileConfig = {
|
|
50
|
+
extends?: string[];
|
|
51
|
+
ruleSets: string[];
|
|
52
|
+
outputs?: GuardOutputFormat[];
|
|
53
|
+
rules?: Record<string, {
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
severity?: GuardSeverity;
|
|
56
|
+
options?: unknown;
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
59
|
+
export type GuardConfig = {
|
|
60
|
+
profiles: Record<string, GuardProfileConfig>;
|
|
61
|
+
ruleSets: Record<string, GuardRuleSetConfig>;
|
|
62
|
+
whitelist?: GuardWhitelistEntry[];
|
|
63
|
+
outputs?: {
|
|
64
|
+
defaultFormat?: GuardOutputFormat;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export type ResolvedRuleSelection = {
|
|
68
|
+
id: string;
|
|
69
|
+
severity: GuardSeverity;
|
|
70
|
+
options: unknown;
|
|
71
|
+
};
|
|
72
|
+
export type ResolvedProfileConfig = {
|
|
73
|
+
name: string;
|
|
74
|
+
outputs: GuardOutputFormat[];
|
|
75
|
+
rules: ResolvedRuleSelection[];
|
|
76
|
+
};
|
|
77
|
+
export type GuardRunInput = {
|
|
78
|
+
workspaceRoot: string;
|
|
79
|
+
profileName: string;
|
|
80
|
+
config: GuardConfig;
|
|
81
|
+
ruleRegistry: GuardRuleRegistry;
|
|
82
|
+
};
|
|
83
|
+
export type GuardRunResult = {
|
|
84
|
+
workspaceRoot: string;
|
|
85
|
+
profileName: string;
|
|
86
|
+
diagnostics: GuardDiagnostic[];
|
|
87
|
+
counts: {
|
|
88
|
+
total: number;
|
|
89
|
+
error: number;
|
|
90
|
+
warning: number;
|
|
91
|
+
note: number;
|
|
92
|
+
};
|
|
93
|
+
selectedRuleIds: string[];
|
|
94
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const SYSTEM_GIT_HOOKS_DIR = "/opt/kuafu/git-hooks";
|
|
2
|
+
export type GitHookInstallScope = "local" | "system";
|
|
3
|
+
export type GitHookInstallResult = {
|
|
4
|
+
assetPath: string;
|
|
5
|
+
hookPath: string;
|
|
6
|
+
hooksPath: string;
|
|
7
|
+
previousHooksPath: string | null;
|
|
8
|
+
repositoryRoot: string | null;
|
|
9
|
+
scope: GitHookInstallScope;
|
|
10
|
+
};
|
|
11
|
+
export type GitHookInstallOptions = {
|
|
12
|
+
/** local 模式的仓库起点;system 模式不依赖该路径是 Git Repository。 */
|
|
13
|
+
cwd: string;
|
|
14
|
+
scope: GitHookInstallScope;
|
|
15
|
+
/** 仅供制品验证与单元测试注入,正式命令始终使用 DevTool canonical Asset。 */
|
|
16
|
+
assetPath?: string;
|
|
17
|
+
/** 仅供 Development Image 测试注入,正式 system 安装固定使用 /opt/kuafu/git-hooks。 */
|
|
18
|
+
systemHooksDir?: string;
|
|
19
|
+
/** 允许测试把 git --system 隔离到临时配置文件。 */
|
|
20
|
+
environment?: NodeJS.ProcessEnv;
|
|
21
|
+
/** system 模式生产值必须为 0;测试可以注入模拟的有效 uid。 */
|
|
22
|
+
effectiveUid?: number;
|
|
23
|
+
/** system 模式生产 owner 固定为 root:root;测试可以注入当前进程 owner。 */
|
|
24
|
+
systemOwner?: {
|
|
25
|
+
gid: number;
|
|
26
|
+
uid: number;
|
|
27
|
+
};
|
|
28
|
+
/** 依赖准备:linked worktree 只读核验基础仓已安装的入口。 */
|
|
29
|
+
prepare?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function installGitHooks(options: GitHookInstallOptions): GitHookInstallResult;
|
|
32
|
+
export declare function resolveCanonicalHookAsset(): string;
|
|
33
|
+
/** 由 bare 仓初始化或升级入口安装;统一写入单主干 push 钩子并清理历史双分支配置。 */
|
|
34
|
+
export declare function installCommonGitHooks(gitPath: string, environment: NodeJS.ProcessEnv, options?: {
|
|
35
|
+
branch?: string;
|
|
36
|
+
}): void;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { assertSystemHookAuthority } from "./install-rules.js";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { accessSync, existsSync, chmodSync, chownSync, constants, copyFileSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
export const SYSTEM_GIT_HOOKS_DIR = "/opt/kuafu/git-hooks";
|
|
9
|
+
export function installGitHooks(options) {
|
|
10
|
+
const assetPath = options.assetPath ?? resolveCanonicalHookAsset();
|
|
11
|
+
validateCanonicalAsset(assetPath);
|
|
12
|
+
if (options.scope === "system") {
|
|
13
|
+
return installSystemGitHooks(options, assetPath);
|
|
14
|
+
}
|
|
15
|
+
return installLocalGitHooks(options, assetPath);
|
|
16
|
+
}
|
|
17
|
+
export function resolveCanonicalHookAsset() {
|
|
18
|
+
const manifest = createRequire(import.meta.url).resolve("@kuafucloud/repo-kit/package.json");
|
|
19
|
+
return path.join(path.dirname(manifest), "assets", "git-hooks", "prepare-commit-msg");
|
|
20
|
+
}
|
|
21
|
+
/** 由 bare 仓初始化或升级入口安装;统一写入单主干 push 钩子并清理历史双分支配置。 */
|
|
22
|
+
export function installCommonGitHooks(gitPath, environment, options) {
|
|
23
|
+
const configured = readGitConfig(["-C", gitPath, "config", "--local", "--get", "core.hooksPath"], environment);
|
|
24
|
+
const hooks = path.join(gitPath, options || (configured && path.resolve(gitPath, configured) === path.join(gitPath, "kuafucloud-hooks")) ? "kuafucloud-hooks" : "hooks");
|
|
25
|
+
if (configured && path.resolve(gitPath, configured) !== hooks)
|
|
26
|
+
throw new Error("公共仓使用自定义 hooksPath,请先迁移现有 Git hooks。");
|
|
27
|
+
if (options) {
|
|
28
|
+
const commit = resolveCanonicalHookAsset();
|
|
29
|
+
const target = path.join(hooks, path.basename(commit));
|
|
30
|
+
if (!existsSync(target) || !readFileSync(target).equals(readFileSync(commit)))
|
|
31
|
+
installAssetAtomically(commit, hooks, target);
|
|
32
|
+
validateInstalledHook(commit, target);
|
|
33
|
+
}
|
|
34
|
+
installSharedPushGuard(gitPath, hooks, environment);
|
|
35
|
+
unsetLocalConfig(gitPath, "kuafu.developmentBranch", environment);
|
|
36
|
+
unsetLocalConfig(gitPath, "kuafu.promotionBranch", environment);
|
|
37
|
+
if (options?.branch) {
|
|
38
|
+
setLocalConfig(gitPath, "kuafu.pushBranch", options.branch, environment);
|
|
39
|
+
}
|
|
40
|
+
if (!configured && options)
|
|
41
|
+
runGit(["-C", gitPath, "config", "--local", "core.hooksPath", hooks], environment);
|
|
42
|
+
}
|
|
43
|
+
function setLocalConfig(cwd, key, value, environment) {
|
|
44
|
+
if (readGitConfig(["-C", cwd, "config", "--local", "--get", key], environment) !== value)
|
|
45
|
+
runGit(["-C", cwd, "config", "--local", key, value], environment);
|
|
46
|
+
}
|
|
47
|
+
function unsetLocalConfig(cwd, key, environment) {
|
|
48
|
+
if (readGitConfig(["-C", cwd, "config", "--local", "--get", key], environment) !== null) {
|
|
49
|
+
try {
|
|
50
|
+
runGit(["-C", cwd, "config", "--local", "--unset-all", key], environment);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// ignore if already absent
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function installSharedPushGuard(cwd, hooks, environment) {
|
|
58
|
+
const assets = path.dirname(resolveCanonicalHookAsset());
|
|
59
|
+
for (const name of ["check-push.cjs", "pre-push"]) {
|
|
60
|
+
const asset = path.join(assets, name), target = path.join(hooks, name);
|
|
61
|
+
const installed = existsSync(target) ? readFileSync(target) : null;
|
|
62
|
+
if (!installed || !installed.equals(readFileSync(asset)))
|
|
63
|
+
installAssetAtomically(asset, hooks, target);
|
|
64
|
+
validateInstalledHook(asset, target);
|
|
65
|
+
}
|
|
66
|
+
setLocalConfig(cwd, "kuafu.pushNode", environment.NODE_BINARY || process.execPath, environment);
|
|
67
|
+
}
|
|
68
|
+
function installLocalGitHooks(options, assetPath) {
|
|
69
|
+
const environment = options.environment ?? process.env;
|
|
70
|
+
const repositoryRoot = runGit(["-C", options.cwd, "rev-parse", "--show-toplevel"], environment);
|
|
71
|
+
const gitCommonDir = runGit(["-C", repositoryRoot, "rev-parse", "--path-format=absolute", "--git-common-dir"], environment);
|
|
72
|
+
const hooksPath = path.join(gitCommonDir, "kuafucloud-hooks");
|
|
73
|
+
const hookPath = path.join(hooksPath, "prepare-commit-msg");
|
|
74
|
+
const previousHooksPath = readGitConfig(["-C", repositoryRoot, "config", "--local", "--path", "--get", "core.hooksPath"], environment);
|
|
75
|
+
validateRepositoryAgentTool(repositoryRoot);
|
|
76
|
+
const gitDir = runGit(["-C", repositoryRoot, "rev-parse", "--absolute-git-dir"], environment);
|
|
77
|
+
const checkOnly = options.prepare === true && path.resolve(gitDir) !== path.resolve(gitCommonDir);
|
|
78
|
+
if (!checkOnly) {
|
|
79
|
+
if (!existsSync(hookPath) || !readFileSync(hookPath).equals(readFileSync(assetPath)) || !(statSync(hookPath).mode & 0o111)) {
|
|
80
|
+
installAssetAtomically(assetPath, hooksPath, hookPath);
|
|
81
|
+
}
|
|
82
|
+
if (previousHooksPath !== hooksPath)
|
|
83
|
+
runGit(["-C", repositoryRoot, "config", "--local", "core.hooksPath", hooksPath], environment);
|
|
84
|
+
}
|
|
85
|
+
const configuredHooksPath = runGit(["-C", repositoryRoot, "config", "--local", "--path", "--get", "core.hooksPath"], environment);
|
|
86
|
+
const effectiveHooksPath = runGit(["-C", repositoryRoot, "config", "--path", "--get", "core.hooksPath"], environment);
|
|
87
|
+
assertSamePath(configuredHooksPath, hooksPath, "repository local core.hooksPath");
|
|
88
|
+
assertSamePath(effectiveHooksPath, hooksPath, "effective core.hooksPath");
|
|
89
|
+
validateHooksDirectory(hooksPath);
|
|
90
|
+
validateInstalledHook(assetPath, hookPath);
|
|
91
|
+
const manifest = path.join(repositoryRoot, "kuafu.json");
|
|
92
|
+
if (existsSync(manifest) && JSON.parse(readFileSync(manifest, "utf8")).push?.branch) {
|
|
93
|
+
const pushAsset = path.join(path.dirname(resolveCanonicalHookAsset()), "pre-push");
|
|
94
|
+
const pushTarget = path.join(hooksPath, "pre-push");
|
|
95
|
+
if (!checkOnly)
|
|
96
|
+
installSharedPushGuard(repositoryRoot, hooksPath, environment);
|
|
97
|
+
validateInstalledHook(pushAsset, pushTarget);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
assetPath,
|
|
101
|
+
hookPath,
|
|
102
|
+
hooksPath,
|
|
103
|
+
previousHooksPath,
|
|
104
|
+
repositoryRoot,
|
|
105
|
+
scope: "local",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function installSystemGitHooks(options, assetPath) {
|
|
109
|
+
const environment = options.environment ?? process.env;
|
|
110
|
+
const effectiveUid = options.effectiveUid ?? process.getuid?.();
|
|
111
|
+
assertSystemHookAuthority(effectiveUid);
|
|
112
|
+
const hooksPath = path.resolve(options.systemHooksDir ?? SYSTEM_GIT_HOOKS_DIR);
|
|
113
|
+
const hookPath = path.join(hooksPath, "prepare-commit-msg");
|
|
114
|
+
const owner = options.systemOwner ?? { gid: 0, uid: 0 };
|
|
115
|
+
const previousHooksPath = readGitConfig(["config", "--system", "--path", "--get", "core.hooksPath"], environment);
|
|
116
|
+
installAssetAtomically(assetPath, hooksPath, hookPath, owner);
|
|
117
|
+
runGit(["config", "--system", "core.hooksPath", hooksPath], environment);
|
|
118
|
+
const configuredHooksPath = runGit(["config", "--system", "--path", "--get", "core.hooksPath"], environment);
|
|
119
|
+
assertSamePath(configuredHooksPath, hooksPath, "system core.hooksPath");
|
|
120
|
+
validateHooksDirectory(hooksPath, owner);
|
|
121
|
+
validateInstalledHook(assetPath, hookPath, owner);
|
|
122
|
+
return {
|
|
123
|
+
assetPath,
|
|
124
|
+
hookPath,
|
|
125
|
+
hooksPath,
|
|
126
|
+
previousHooksPath,
|
|
127
|
+
repositoryRoot: null,
|
|
128
|
+
scope: "system",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function installAssetAtomically(assetPath, hooksPath, hookPath, owner) {
|
|
132
|
+
mkdirSync(hooksPath, { mode: 0o755, recursive: true });
|
|
133
|
+
chmodSync(hooksPath, 0o755);
|
|
134
|
+
if (owner) {
|
|
135
|
+
chownSync(hooksPath, owner.uid, owner.gid);
|
|
136
|
+
}
|
|
137
|
+
const temporaryPath = path.join(hooksPath, `.prepare-commit-msg.${process.pid}.${randomUUID()}.tmp`);
|
|
138
|
+
try {
|
|
139
|
+
copyFileSync(assetPath, temporaryPath, constants.COPYFILE_EXCL);
|
|
140
|
+
chmodSync(temporaryPath, 0o755);
|
|
141
|
+
if (owner) {
|
|
142
|
+
chownSync(temporaryPath, owner.uid, owner.gid);
|
|
143
|
+
}
|
|
144
|
+
renameSync(temporaryPath, hookPath);
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
try {
|
|
148
|
+
unlinkSync(temporaryPath);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// rename 成功或临时文件尚未创建时无需清理。
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function validateCanonicalAsset(assetPath) {
|
|
156
|
+
accessSync(assetPath, constants.R_OK);
|
|
157
|
+
const content = readFileSync(assetPath, "utf8");
|
|
158
|
+
if (!content.includes('exec "$repo_root/agent-tool" guard commit') && !content.includes("kuafu-verify check")) {
|
|
159
|
+
throw new Error(`Invalid prepare-commit-msg Hook Asset: ${assetPath}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function validateInstalledHook(assetPath, hookPath, owner) {
|
|
163
|
+
accessSync(hookPath, constants.R_OK | constants.X_OK);
|
|
164
|
+
const stats = statSync(hookPath);
|
|
165
|
+
if ((stats.mode & 0o777) !== 0o755) {
|
|
166
|
+
throw new Error(`Installed Git Hook must have mode 0755: ${hookPath}`);
|
|
167
|
+
}
|
|
168
|
+
if (owner && (stats.uid !== owner.uid || stats.gid !== owner.gid)) {
|
|
169
|
+
throw new Error(`Installed Git Hook owner mismatch: expected ${owner.uid}:${owner.gid}, got ${stats.uid}:${stats.gid}.`);
|
|
170
|
+
}
|
|
171
|
+
if (!readFileSync(hookPath).equals(readFileSync(assetPath))) {
|
|
172
|
+
throw new Error(`Installed Git Hook differs from canonical Asset: ${hookPath}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function validateHooksDirectory(hooksPath, owner) {
|
|
176
|
+
const stats = statSync(hooksPath);
|
|
177
|
+
if (!stats.isDirectory() || (stats.mode & 0o777) !== 0o755) {
|
|
178
|
+
throw new Error(`Git Hooks directory must be a directory with mode 0755: ${hooksPath}`);
|
|
179
|
+
}
|
|
180
|
+
if (owner && (stats.uid !== owner.uid || stats.gid !== owner.gid)) {
|
|
181
|
+
throw new Error(`Git Hooks directory owner mismatch: expected ${owner.uid}:${owner.gid}, got ${stats.uid}:${stats.gid}.`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function validateRepositoryAgentTool(repositoryRoot) {
|
|
185
|
+
const agentToolPath = path.join(repositoryRoot, "agent-tool");
|
|
186
|
+
try {
|
|
187
|
+
accessSync(agentToolPath, constants.X_OK);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
throw new Error(`Repository Agent Tool is missing or not executable: ${agentToolPath}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function readGitConfig(args, environment) {
|
|
194
|
+
try {
|
|
195
|
+
return runGit(args, environment) || null;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function runGit(args, environment) {
|
|
202
|
+
return execFileSync("git", args, {
|
|
203
|
+
encoding: "utf8",
|
|
204
|
+
env: environment,
|
|
205
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
206
|
+
}).trim();
|
|
207
|
+
}
|
|
208
|
+
function assertSamePath(actual, expected, description) {
|
|
209
|
+
if (path.resolve(actual) !== path.resolve(expected)) {
|
|
210
|
+
throw new Error(`${description} mismatch: expected ${expected}, got ${actual}.`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const checkPushTargets: (root: string, updates: string, configuredBranch?: string) => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveCanonicalHookAsset } from "./install.js";
|
|
4
|
+
const guard = createRequire(import.meta.url)(path.join(path.dirname(resolveCanonicalHookAsset()), "check-push.cjs"));
|
|
5
|
+
export const checkPushTargets = guard.checkPushTargets;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./core/index.js";
|
|
2
|
+
export * from "./repo.js";
|
|
3
|
+
export * from "./product-roots.js";
|
|
4
|
+
export { externalRuleRegistry } from "./rules/external/index.js";
|
|
5
|
+
export { registerSharedUnitRuleInspector, validateShared, type SharedUnitRuleInspector } from "./rules/shared/extension/validate-shared.js";
|
|
6
|
+
export * from "./rules/shared/extension/collect.js";
|
|
7
|
+
export * from "./rules/shared/extension/validate-database.js";
|
|
8
|
+
export * from "./rules/shared/extension/validate-server-index-api-entry-satisfies.js";
|
|
9
|
+
export * from "./rules/external/shared/types.js";
|
|
10
|
+
export * from "./rules/external/shared/ts-ast.js";
|
|
11
|
+
export * from "./rules/external/shared/records.js";
|
|
12
|
+
export * from "./rules/external/extension/types.js";
|
|
13
|
+
export * from "./hooks/install.js";
|
|
14
|
+
export * from "./hooks/push.js";
|
|
15
|
+
export { dependencyBoundaryRule } from "./rules/external/boundary/check.js";
|
|
16
|
+
export * from "./rules/external/story-rules.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./core/index.js";
|
|
2
|
+
export * from "./repo.js";
|
|
3
|
+
export * from "./product-roots.js";
|
|
4
|
+
export { externalRuleRegistry } from "./rules/external/index.js";
|
|
5
|
+
export { registerSharedUnitRuleInspector, validateShared } from "./rules/shared/extension/validate-shared.js";
|
|
6
|
+
export * from "./rules/shared/extension/collect.js";
|
|
7
|
+
export * from "./rules/shared/extension/validate-database.js";
|
|
8
|
+
export * from "./rules/shared/extension/validate-server-index-api-entry-satisfies.js";
|
|
9
|
+
export * from "./rules/external/shared/types.js";
|
|
10
|
+
export * from "./rules/external/shared/ts-ast.js";
|
|
11
|
+
export * from "./rules/external/shared/records.js";
|
|
12
|
+
export * from "./rules/external/extension/types.js";
|
|
13
|
+
export * from "./hooks/install.js";
|
|
14
|
+
export * from "./hooks/push.js";
|
|
15
|
+
export { dependencyBoundaryRule } from "./rules/external/boundary/check.js";
|
|
16
|
+
export * from "./rules/external/story-rules.js";
|