@kici-dev/compiler 0.0.0 → 0.1.2
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 +202 -0
- package/README.md +1 -6
- package/dist/assets/api-TJJVHrjC.json +118 -0
- package/dist/assets/descriptor-BTtjzN9L.json +1382 -0
- package/dist/assets/package-BpQF9kR8.json +74 -0
- package/dist/assets/package-Ceo2h27X.json +89 -0
- package/dist/assets/source_context-D0atuL28.json +20 -0
- package/dist/assets/type-BFqO8SCZ.json +202 -0
- package/dist/auth/headless-detect.d.ts +14 -0
- package/dist/auth/headless-detect.js +25 -0
- package/dist/chunk-gOLHoazu.js +4 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +193 -0
- package/dist/commands/cancel.d.ts +22 -0
- package/dist/commands/cancel.js +124 -0
- package/dist/commands/compile.d.ts +17 -0
- package/dist/commands/compile.js +99 -0
- package/dist/commands/docs.d.ts +26 -0
- package/dist/commands/docs.js +60 -0
- package/dist/commands/drain-worker.d.ts +19 -0
- package/dist/commands/drain-worker.js +45 -0
- package/dist/commands/endpoints.d.ts +53 -0
- package/dist/commands/endpoints.js +185 -0
- package/dist/commands/fixture.d.ts +14 -0
- package/dist/commands/fixture.js +104 -0
- package/dist/commands/hook.d.ts +20 -0
- package/dist/commands/hook.js +97 -0
- package/dist/commands/index.d.ts +33 -0
- package/dist/commands/index.js +20 -0
- package/dist/commands/init.d.ts +35 -0
- package/dist/commands/init.js +393 -0
- package/dist/commands/login.d.ts +23 -0
- package/dist/commands/login.js +144 -0
- package/dist/commands/logout.d.ts +18 -0
- package/dist/commands/logout.js +55 -0
- package/dist/commands/org.d.ts +27 -0
- package/dist/commands/org.js +126 -0
- package/dist/commands/run.d.ts +21 -0
- package/dist/commands/run.js +562 -0
- package/dist/commands/secrets-list.d.ts +16 -0
- package/dist/commands/secrets-list.js +85 -0
- package/dist/commands/status.d.ts +30 -0
- package/dist/commands/status.js +210 -0
- package/dist/commands/test.d.ts +61 -0
- package/dist/commands/test.js +220 -0
- package/dist/commands/types.d.ts +18 -0
- package/dist/commands/types.js +74 -0
- package/dist/commands/watch.d.ts +14 -0
- package/dist/commands/watch.js +97 -0
- package/dist/commands/workflows.d.ts +28 -0
- package/dist/commands/workflows.js +154 -0
- package/dist/comment-created.json +30 -0
- package/dist/create-branch.json +17 -0
- package/dist/delete-branch.json +15 -0
- package/dist/dispatch.json +15 -0
- package/dist/errors/capability-gap.d.ts +50 -0
- package/dist/errors/capability-gap.js +54 -0
- package/dist/errors/codes.d.ts +25 -0
- package/dist/errors/formatter.d.ts +32 -0
- package/dist/errors/formatter.js +35 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.js +4 -0
- package/dist/execution/executor.d.ts +61 -0
- package/dist/execution/executor.js +230 -0
- package/dist/execution/index.d.ts +4 -0
- package/dist/execution/index.js +3 -0
- package/dist/execution/sdk-alias.d.ts +33 -0
- package/dist/execution/sdk-alias.js +102 -0
- package/dist/fixtures/compiler.d.ts +47 -0
- package/dist/fixtures/compiler.js +177 -0
- package/dist/fixtures/defaults/comment-created.json +30 -0
- package/dist/fixtures/defaults/create-branch.json +17 -0
- package/dist/fixtures/defaults/delete-branch.json +15 -0
- package/dist/fixtures/defaults/dispatch.json +15 -0
- package/dist/fixtures/defaults/fork.json +19 -0
- package/dist/fixtures/defaults/index.d.ts +16 -0
- package/dist/fixtures/defaults/index.js +105 -0
- package/dist/fixtures/defaults/index.ts +145 -0
- package/dist/fixtures/defaults/pr-closed.json +28 -0
- package/dist/fixtures/defaults/pr-opened.json +27 -0
- package/dist/fixtures/defaults/pr-reopened.json +27 -0
- package/dist/fixtures/defaults/pr-synchronize.json +27 -0
- package/dist/fixtures/defaults/push.json +16 -0
- package/dist/fixtures/defaults/release-published.json +23 -0
- package/dist/fixtures/defaults/review-comment-created.json +36 -0
- package/dist/fixtures/defaults/review-submitted.json +35 -0
- package/dist/fixtures/defaults/star-created.json +15 -0
- package/dist/fixtures/defaults/status.json +26 -0
- package/dist/fixtures/defaults/tag-push.json +20 -0
- package/dist/fixtures/defaults/watch-started.json +15 -0
- package/dist/fixtures/defaults/workflow-run-completed.json +23 -0
- package/dist/fork.json +19 -0
- package/dist/format.d.ts +5 -0
- package/dist/format.js +20 -0
- package/dist/generators/secrets-dts.d.ts +29 -0
- package/dist/generators/secrets-dts.js +67 -0
- package/dist/hooks/detector.d.ts +39 -0
- package/dist/hooks/detector.js +133 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/installer.d.ts +24 -0
- package/dist/hooks/installer.js +328 -0
- package/dist/hooks/templates.d.ts +26 -0
- package/dist/hooks/templates.js +63 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/llm-context/llms-full.txt +9974 -0
- package/dist/llm-context/llms.txt +61 -0
- package/dist/local-executor/dag-scheduler.d.ts +44 -0
- package/dist/local-executor/dag-scheduler.js +183 -0
- package/dist/local-executor/index.d.ts +23 -0
- package/dist/local-executor/index.js +309 -0
- package/dist/local-executor/job-runner.d.ts +40 -0
- package/dist/local-executor/job-runner.js +307 -0
- package/dist/local-executor/output-streamer.d.ts +31 -0
- package/dist/local-executor/output-streamer.js +166 -0
- package/dist/local-executor/payload-generator.d.ts +16 -0
- package/dist/local-executor/payload-generator.js +138 -0
- package/dist/local-executor/picker.d.ts +33 -0
- package/dist/local-executor/picker.js +109 -0
- package/dist/local-executor/secret-loader.d.ts +18 -0
- package/dist/local-executor/secret-loader.js +105 -0
- package/dist/local-executor/types.d.ts +80 -0
- package/dist/local-executor/types.js +2 -0
- package/dist/local-executor/workflow-lock.d.ts +81 -0
- package/dist/local-executor/workflow-lock.js +0 -0
- package/dist/lockfile/generator.d.ts +39 -0
- package/dist/lockfile/generator.js +688 -0
- package/dist/lockfile/hash-files.d.ts +14 -0
- package/dist/lockfile/hash-files.js +50 -0
- package/dist/lockfile/hasher.d.ts +36 -0
- package/dist/lockfile/hasher.js +46 -0
- package/dist/lockfile/index.d.ts +3 -0
- package/dist/lockfile/index.js +4 -0
- package/dist/lockfile/purity-analyzer.d.ts +25 -0
- package/dist/lockfile/purity-analyzer.js +204 -0
- package/dist/package-F7UXSDHW.json +74 -0
- package/dist/postinstall.d.ts +9 -0
- package/dist/postinstall.js +60 -0
- package/dist/pr-closed.json +28 -0
- package/dist/pr-opened.json +27 -0
- package/dist/pr-reopened.json +27 -0
- package/dist/pr-synchronize.json +27 -0
- package/dist/push.json +16 -0
- package/dist/release-published.json +23 -0
- package/dist/remote/client.d.ts +204 -0
- package/dist/remote/client.js +203 -0
- package/dist/remote/config.d.ts +54 -0
- package/dist/remote/config.js +92 -0
- package/dist/remote/encryption.d.ts +35 -0
- package/dist/remote/encryption.js +87 -0
- package/dist/remote/history.d.ts +91 -0
- package/dist/remote/history.js +146 -0
- package/dist/remote/oauth.d.ts +65 -0
- package/dist/remote/oauth.js +302 -0
- package/dist/remote/observer.d.ts +81 -0
- package/dist/remote/observer.js +174 -0
- package/dist/remote/output/json.d.ts +13 -0
- package/dist/remote/output/json.js +36 -0
- package/dist/remote/output/junit.d.ts +18 -0
- package/dist/remote/output/junit.js +50 -0
- package/dist/remote/output/streaming.d.ts +57 -0
- package/dist/remote/output/streaming.js +124 -0
- package/dist/remote/output/summary.d.ts +39 -0
- package/dist/remote/output/summary.js +99 -0
- package/dist/remote/uploader.d.ts +87 -0
- package/dist/remote/uploader.js +197 -0
- package/dist/review-comment-created.json +36 -0
- package/dist/review-submitted.json +35 -0
- package/dist/star-created.json +15 -0
- package/dist/status.json +26 -0
- package/dist/tag-push.json +20 -0
- package/dist/templates/agents-md.d.ts +8 -0
- package/dist/templates/agents-md.js +130 -0
- package/dist/templates/index.d.ts +43 -0
- package/dist/templates/index.js +48 -0
- package/dist/templates/package-json.d.ts +18 -0
- package/dist/templates/package-json.js +34 -0
- package/dist/templates/tsconfig-json.d.ts +9 -0
- package/dist/templates/tsconfig-json.js +26 -0
- package/dist/templates/workflows/hello-world.d.ts +2 -0
- package/dist/templates/workflows/hello-world.js +16 -0
- package/dist/templates/workflows/hello-world.ts +21 -0
- package/dist/templates/workflows/pr-checks.d.ts +2 -0
- package/dist/templates/workflows/pr-checks.js +40 -0
- package/dist/templates/workflows/pr-checks.ts +57 -0
- package/dist/test-runner/dry-run.d.ts +12 -0
- package/dist/test-runner/dry-run.js +66 -0
- package/dist/test-runner/event-types.d.ts +86 -0
- package/dist/test-runner/event-types.js +330 -0
- package/dist/test-runner/git-detector.d.ts +15 -0
- package/dist/test-runner/git-detector.js +30 -0
- package/dist/test-runner/index.d.ts +13 -0
- package/dist/test-runner/index.js +11 -0
- package/dist/test-runner/job-executor.d.ts +48 -0
- package/dist/test-runner/job-executor.js +245 -0
- package/dist/test-runner/output-formatter.d.ts +47 -0
- package/dist/test-runner/output-formatter.js +92 -0
- package/dist/test-runner/payload-builder.d.ts +20 -0
- package/dist/test-runner/payload-builder.js +216 -0
- package/dist/test-runner/rule-evaluator.d.ts +14 -0
- package/dist/test-runner/rule-evaluator.js +31 -0
- package/dist/test-runner/secrets-file.d.ts +24 -0
- package/dist/test-runner/secrets-file.js +62 -0
- package/dist/test-runner/step-context.d.ts +15 -0
- package/dist/test-runner/step-context.js +140 -0
- package/dist/test-runner/summary.d.ts +7 -0
- package/dist/types.d.ts +525 -0
- package/dist/types.js +33 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.js +3 -0
- package/dist/validation/validator.d.ts +26 -0
- package/dist/validation/validator.js +164 -0
- package/dist/watch-started.json +15 -0
- package/dist/workflow-run-completed.json +23 -0
- package/dist/workflows/hello-world.ts +21 -0
- package/dist/workflows/pr-checks.ts +57 -0
- package/hack/postinstall.mjs +105 -0
- package/package.json +60 -6
- package/sbom.spdx.json +10997 -0
- package/index.js +0 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type ColorFn = (text: string) => string;
|
|
2
|
+
/**
|
|
3
|
+
* Output formatter that prefixes messages with colored job labels.
|
|
4
|
+
*/
|
|
5
|
+
declare class OutputFormatter {
|
|
6
|
+
private jobIndex;
|
|
7
|
+
private colorMap;
|
|
8
|
+
/**
|
|
9
|
+
* Get consistent color for a job name.
|
|
10
|
+
*/
|
|
11
|
+
getJobColor(jobName: string): ColorFn;
|
|
12
|
+
/**
|
|
13
|
+
* Log a message with job prefix.
|
|
14
|
+
*/
|
|
15
|
+
logJobLine(jobName: string, message: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Log step start.
|
|
18
|
+
*/
|
|
19
|
+
logStepStart(jobName: string, stepName: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Log step completion.
|
|
22
|
+
*/
|
|
23
|
+
logStepComplete(jobName: string, stepName: string, durationMs: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Log step error.
|
|
26
|
+
*/
|
|
27
|
+
logStepError(jobName: string, stepName: string, error: Error): void;
|
|
28
|
+
/**
|
|
29
|
+
* Log job start.
|
|
30
|
+
*/
|
|
31
|
+
logJobStart(jobName: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Log job complete.
|
|
34
|
+
*/
|
|
35
|
+
logJobComplete(jobName: string, durationMs: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Log job failure.
|
|
38
|
+
*/
|
|
39
|
+
logJobFailure(jobName: string, durationMs: number, error: Error): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log rule evaluation.
|
|
42
|
+
*/
|
|
43
|
+
logRuleResult(jobName: string, ruleLabel: string, passed: boolean): void;
|
|
44
|
+
}
|
|
45
|
+
export declare const formatter: OutputFormatter;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=output-formatter.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { logger } from "@kici-dev/shared";
|
|
4
|
+
//#region src/test-runner/output-formatter.ts
|
|
5
|
+
const JOB_COLORS = [
|
|
6
|
+
pc.cyan,
|
|
7
|
+
pc.green,
|
|
8
|
+
pc.yellow,
|
|
9
|
+
pc.magenta,
|
|
10
|
+
pc.blue
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Output formatter that prefixes messages with colored job labels.
|
|
14
|
+
*/
|
|
15
|
+
var OutputFormatter = class {
|
|
16
|
+
jobIndex = 0;
|
|
17
|
+
colorMap = /* @__PURE__ */ new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Get consistent color for a job name.
|
|
20
|
+
*/
|
|
21
|
+
getJobColor(jobName) {
|
|
22
|
+
if (!this.colorMap.has(jobName)) {
|
|
23
|
+
const color = JOB_COLORS[this.jobIndex % JOB_COLORS.length];
|
|
24
|
+
this.colorMap.set(jobName, color);
|
|
25
|
+
this.jobIndex++;
|
|
26
|
+
}
|
|
27
|
+
return this.colorMap.get(jobName);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Log a message with job prefix.
|
|
31
|
+
*/
|
|
32
|
+
logJobLine(jobName, message) {
|
|
33
|
+
const prefix = this.getJobColor(jobName)(`[${jobName}]`);
|
|
34
|
+
const lines = message.split("\n");
|
|
35
|
+
for (const line of lines) if (line.trim()) logger.info(`${prefix} ${line}`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Log step start.
|
|
39
|
+
*/
|
|
40
|
+
logStepStart(jobName, stepName) {
|
|
41
|
+
const color = this.getJobColor(jobName);
|
|
42
|
+
logger.info(color(`[${jobName}]`) + pc.gray(` -> ${stepName}`));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Log step completion.
|
|
46
|
+
*/
|
|
47
|
+
logStepComplete(jobName, stepName, durationMs) {
|
|
48
|
+
const color = this.getJobColor(jobName);
|
|
49
|
+
logger.info(color(`[${jobName}]`) + pc.green(` ✓ ${stepName}`) + pc.gray(` (${durationMs}ms)`));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Log step error.
|
|
53
|
+
*/
|
|
54
|
+
logStepError(jobName, stepName, error) {
|
|
55
|
+
const color = this.getJobColor(jobName);
|
|
56
|
+
logger.error(color(`[${jobName}]`) + pc.red(` ✗ ${stepName}: ${error.message}`));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Log job start.
|
|
60
|
+
*/
|
|
61
|
+
logJobStart(jobName) {
|
|
62
|
+
const color = this.getJobColor(jobName);
|
|
63
|
+
logger.info(color(`[${jobName}]`) + pc.bold(" Starting..."));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Log job complete.
|
|
67
|
+
*/
|
|
68
|
+
logJobComplete(jobName, durationMs) {
|
|
69
|
+
const color = this.getJobColor(jobName);
|
|
70
|
+
logger.info(color(`[${jobName}]`) + pc.green(" ✓ Complete") + pc.gray(` (${durationMs}ms)`));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Log job failure.
|
|
74
|
+
*/
|
|
75
|
+
logJobFailure(jobName, durationMs, error) {
|
|
76
|
+
const color = this.getJobColor(jobName);
|
|
77
|
+
logger.error(color(`[${jobName}]`) + pc.red(` ✗ Failed: ${error.message}`) + pc.gray(` (${durationMs}ms)`));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Log rule evaluation.
|
|
81
|
+
*/
|
|
82
|
+
logRuleResult(jobName, ruleLabel, passed) {
|
|
83
|
+
const color = this.getJobColor(jobName);
|
|
84
|
+
const status = passed ? pc.green("✓ passed") : pc.red("✗ failed");
|
|
85
|
+
logger.info(color(`[${jobName}]`) + pc.gray(` rule "${ruleLabel}": `) + status);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const formatter = new OutputFormatter();
|
|
89
|
+
//#endregion
|
|
90
|
+
export { formatter };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=output-formatter.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SimulatedEvent } from '@kici-dev/engine';
|
|
2
|
+
export interface PayloadOptions {
|
|
3
|
+
/** Path to custom fixture file */
|
|
4
|
+
payload?: string;
|
|
5
|
+
/** Override branch name */
|
|
6
|
+
branch?: string;
|
|
7
|
+
/** Override PR number */
|
|
8
|
+
pr?: number;
|
|
9
|
+
/** Override repository (owner/name) */
|
|
10
|
+
repo?: string;
|
|
11
|
+
/** Override commit SHA */
|
|
12
|
+
sha?: string;
|
|
13
|
+
/** Simulate changed file paths for onChangedFiles trigger matching */
|
|
14
|
+
files?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build event payload from default fixture, custom file, and CLI overrides.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildEventPayload(eventArg: string, options: PayloadOptions): Promise<SimulatedEvent>;
|
|
20
|
+
//# sourceMappingURL=payload-builder.d.ts.map
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
import { getDefaultFixture } from "../fixtures/defaults/index.js";
|
|
3
|
+
import { detectRepoFromGit } from "./git-detector.js";
|
|
4
|
+
import { parseEventArg } from "./event-types.js";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
//#region src/test-runner/payload-builder.ts
|
|
7
|
+
/**
|
|
8
|
+
* Deep merge objects (simple implementation for fixture overrides).
|
|
9
|
+
*/
|
|
10
|
+
function deepMerge(base, overrides) {
|
|
11
|
+
const result = { ...base };
|
|
12
|
+
for (const [key, value] of Object.entries(overrides)) if (value !== void 0 && value !== null) if (typeof value === "object" && !Array.isArray(value) && result[key] && typeof result[key] === "object") result[key] = deepMerge(result[key], value);
|
|
13
|
+
else result[key] = value;
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build event payload from default fixture, custom file, and CLI overrides.
|
|
18
|
+
*/
|
|
19
|
+
async function buildEventPayload(eventArg, options) {
|
|
20
|
+
const eventType = parseEventArg(eventArg);
|
|
21
|
+
if (isInternalEventType(eventType)) return buildInternalEventPayload(eventType, options);
|
|
22
|
+
let payload;
|
|
23
|
+
if (options.payload) {
|
|
24
|
+
const content = await readFile(options.payload, "utf-8");
|
|
25
|
+
payload = JSON.parse(content);
|
|
26
|
+
} else payload = getDefaultFixture(eventArg);
|
|
27
|
+
const repoInfo = options.repo ? null : await detectRepoFromGit();
|
|
28
|
+
const overrides = {};
|
|
29
|
+
if (options.repo) {
|
|
30
|
+
const [owner, name] = options.repo.split("/");
|
|
31
|
+
overrides.repository = {
|
|
32
|
+
owner: { login: owner },
|
|
33
|
+
name,
|
|
34
|
+
full_name: options.repo
|
|
35
|
+
};
|
|
36
|
+
} else if (repoInfo) overrides.repository = {
|
|
37
|
+
owner: { login: repoInfo.owner },
|
|
38
|
+
name: repoInfo.name,
|
|
39
|
+
full_name: `${repoInfo.owner}/${repoInfo.name}`
|
|
40
|
+
};
|
|
41
|
+
if (options.sha) switch (eventType.type) {
|
|
42
|
+
case "push":
|
|
43
|
+
case "tag":
|
|
44
|
+
overrides.after = options.sha;
|
|
45
|
+
break;
|
|
46
|
+
case "status":
|
|
47
|
+
overrides.sha = options.sha;
|
|
48
|
+
break;
|
|
49
|
+
case "pull_request":
|
|
50
|
+
case "review":
|
|
51
|
+
case "review_comment":
|
|
52
|
+
overrides.pull_request = { head: { sha: options.sha } };
|
|
53
|
+
break;
|
|
54
|
+
case "workflow_run":
|
|
55
|
+
overrides.workflow_run = { head_sha: options.sha };
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (options.branch) switch (eventType.type) {
|
|
59
|
+
case "push":
|
|
60
|
+
overrides.ref = `refs/heads/${options.branch}`;
|
|
61
|
+
break;
|
|
62
|
+
case "tag":
|
|
63
|
+
overrides.ref = `refs/tags/${options.branch}`;
|
|
64
|
+
break;
|
|
65
|
+
case "pull_request":
|
|
66
|
+
case "review":
|
|
67
|
+
case "review_comment":
|
|
68
|
+
overrides.pull_request = {
|
|
69
|
+
...overrides.pull_request ?? {},
|
|
70
|
+
base: { ref: options.branch }
|
|
71
|
+
};
|
|
72
|
+
break;
|
|
73
|
+
case "release":
|
|
74
|
+
overrides.release = { target_commitish: options.branch };
|
|
75
|
+
break;
|
|
76
|
+
case "create":
|
|
77
|
+
case "delete":
|
|
78
|
+
overrides.ref = options.branch;
|
|
79
|
+
break;
|
|
80
|
+
case "workflow_run":
|
|
81
|
+
overrides.workflow_run = {
|
|
82
|
+
...overrides.workflow_run ?? {},
|
|
83
|
+
head_branch: options.branch
|
|
84
|
+
};
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (options.pr && (eventType.type === "pull_request" || eventType.type === "review" || eventType.type === "review_comment")) {
|
|
88
|
+
overrides.number = options.pr;
|
|
89
|
+
overrides.pull_request = {
|
|
90
|
+
...overrides.pull_request ?? {},
|
|
91
|
+
number: options.pr
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const mergedPayload = deepMerge(payload, overrides);
|
|
95
|
+
let targetBranch = "main";
|
|
96
|
+
let sourceBranch;
|
|
97
|
+
const defaultBranch = mergedPayload.repository?.default_branch ?? "main";
|
|
98
|
+
switch (eventType.type) {
|
|
99
|
+
case "push":
|
|
100
|
+
targetBranch = (mergedPayload.ref ?? "refs/heads/main").replace("refs/heads/", "");
|
|
101
|
+
break;
|
|
102
|
+
case "tag":
|
|
103
|
+
targetBranch = (mergedPayload.ref ?? "refs/tags/v0.0.0").replace("refs/tags/", "");
|
|
104
|
+
break;
|
|
105
|
+
case "pull_request": {
|
|
106
|
+
const pr = mergedPayload.pull_request;
|
|
107
|
+
targetBranch = (pr?.base)?.ref ?? defaultBranch;
|
|
108
|
+
sourceBranch = (pr?.head)?.ref;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case "comment":
|
|
112
|
+
targetBranch = (mergedPayload.issue?.pull_request)?.base_ref ?? defaultBranch;
|
|
113
|
+
break;
|
|
114
|
+
case "review":
|
|
115
|
+
case "review_comment": {
|
|
116
|
+
const pr = mergedPayload.pull_request;
|
|
117
|
+
targetBranch = (pr?.base)?.ref ?? defaultBranch;
|
|
118
|
+
sourceBranch = (pr?.head)?.ref;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case "release":
|
|
122
|
+
targetBranch = mergedPayload.release?.target_commitish ?? defaultBranch;
|
|
123
|
+
break;
|
|
124
|
+
case "dispatch":
|
|
125
|
+
targetBranch = defaultBranch;
|
|
126
|
+
break;
|
|
127
|
+
case "create":
|
|
128
|
+
case "delete":
|
|
129
|
+
targetBranch = mergedPayload.ref ?? defaultBranch;
|
|
130
|
+
if ("refType" in eventType && eventType.refType) mergedPayload.ref_type = eventType.refType;
|
|
131
|
+
break;
|
|
132
|
+
case "status":
|
|
133
|
+
targetBranch = mergedPayload.branches?.[0]?.name ?? defaultBranch;
|
|
134
|
+
break;
|
|
135
|
+
case "workflow_run":
|
|
136
|
+
targetBranch = mergedPayload.workflow_run?.head_branch ?? defaultBranch;
|
|
137
|
+
break;
|
|
138
|
+
case "fork":
|
|
139
|
+
case "star":
|
|
140
|
+
case "watch":
|
|
141
|
+
targetBranch = defaultBranch;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
type: eventType.type,
|
|
146
|
+
action: "action" in eventType ? eventType.action : void 0,
|
|
147
|
+
payload: mergedPayload,
|
|
148
|
+
targetBranch,
|
|
149
|
+
sourceBranch,
|
|
150
|
+
changedFiles: options.files ?? []
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Type guard for internal (non-GitHub) event types.
|
|
155
|
+
*/
|
|
156
|
+
function isInternalEventType(eventType) {
|
|
157
|
+
return [
|
|
158
|
+
"kici_event",
|
|
159
|
+
"workflow_complete",
|
|
160
|
+
"job_complete",
|
|
161
|
+
"generic_webhook",
|
|
162
|
+
"schedule",
|
|
163
|
+
"lifecycle"
|
|
164
|
+
].includes(eventType.type);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Build SimulatedEvent for internal event types.
|
|
168
|
+
* These events don't have GitHub webhook fixtures -- payload is constructed directly.
|
|
169
|
+
*/
|
|
170
|
+
async function buildInternalEventPayload(eventType, options) {
|
|
171
|
+
let payload;
|
|
172
|
+
if (options.payload) {
|
|
173
|
+
const content = await readFile(options.payload, "utf-8");
|
|
174
|
+
payload = JSON.parse(content);
|
|
175
|
+
} else switch (eventType.type) {
|
|
176
|
+
case "kici_event":
|
|
177
|
+
payload = { eventName: eventType.eventName };
|
|
178
|
+
break;
|
|
179
|
+
case "workflow_complete":
|
|
180
|
+
payload = {
|
|
181
|
+
workflowName: eventType.workflowName,
|
|
182
|
+
status: eventType.status
|
|
183
|
+
};
|
|
184
|
+
break;
|
|
185
|
+
case "job_complete":
|
|
186
|
+
payload = {
|
|
187
|
+
workflowName: eventType.workflowName,
|
|
188
|
+
jobName: eventType.jobName,
|
|
189
|
+
status: eventType.status
|
|
190
|
+
};
|
|
191
|
+
break;
|
|
192
|
+
case "generic_webhook":
|
|
193
|
+
payload = eventType.source ? { source: eventType.source } : {};
|
|
194
|
+
break;
|
|
195
|
+
case "schedule":
|
|
196
|
+
payload = {
|
|
197
|
+
cronExpression: eventType.cronExpression ?? "*",
|
|
198
|
+
timezone: eventType.timezone ?? "UTC"
|
|
199
|
+
};
|
|
200
|
+
break;
|
|
201
|
+
case "lifecycle":
|
|
202
|
+
payload = { lifecycleEvent: eventType.lifecycleEvent };
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
type: eventType.type,
|
|
207
|
+
action: void 0,
|
|
208
|
+
payload,
|
|
209
|
+
targetBranch: "main",
|
|
210
|
+
changedFiles: options.files ?? []
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { buildEventPayload };
|
|
215
|
+
|
|
216
|
+
//# sourceMappingURL=payload-builder.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Rule, RuleContext, EventPayload } from '@kici-dev/sdk';
|
|
2
|
+
import type { RuleEvaluationResult } from '@kici-dev/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Create RuleContext for rule evaluation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createRuleContext(event: EventPayload, changedFiles?: string[]): RuleContext;
|
|
7
|
+
/**
|
|
8
|
+
* Evaluate rules with formatting output.
|
|
9
|
+
* Wraps the SDK's evaluateRules() with a callback that logs each rule result.
|
|
10
|
+
*/
|
|
11
|
+
declare function evaluateRulesWithFormatting(rules: Rule[], context: RuleContext, jobName: string): Promise<RuleEvaluationResult>;
|
|
12
|
+
export { evaluateRulesWithFormatting as evaluateRules };
|
|
13
|
+
export type { RuleEvaluationResult };
|
|
14
|
+
//# sourceMappingURL=rule-evaluator.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
import { formatter } from "./output-formatter.js";
|
|
3
|
+
import { initZx } from "@kici-dev/shared";
|
|
4
|
+
import { evaluateRules } from "@kici-dev/sdk";
|
|
5
|
+
import { $ } from "zx";
|
|
6
|
+
//#region src/test-runner/rule-evaluator.ts
|
|
7
|
+
initZx();
|
|
8
|
+
/**
|
|
9
|
+
* Create RuleContext for rule evaluation.
|
|
10
|
+
*/
|
|
11
|
+
function createRuleContext(event, changedFiles = []) {
|
|
12
|
+
return {
|
|
13
|
+
event,
|
|
14
|
+
changedFiles,
|
|
15
|
+
env: { ...process.env },
|
|
16
|
+
$
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Evaluate rules with formatting output.
|
|
21
|
+
* Wraps the SDK's evaluateRules() with a callback that logs each rule result.
|
|
22
|
+
*/
|
|
23
|
+
async function evaluateRulesWithFormatting(rules, context, jobName) {
|
|
24
|
+
return evaluateRules(rules, context, jobName, (result) => {
|
|
25
|
+
formatter.logRuleResult(jobName, result.label, result.passed);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createRuleContext, evaluateRulesWithFormatting as evaluateRules };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=rule-evaluator.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface ParsedSecrets {
|
|
2
|
+
flat: Record<string, string>;
|
|
3
|
+
contexts: Record<string, Record<string, string>>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parse an INI-style secrets file content.
|
|
7
|
+
*
|
|
8
|
+
* Format:
|
|
9
|
+
* # Comments start with #
|
|
10
|
+
* KEY=VALUE -> flat secrets (before any section)
|
|
11
|
+
* [sectionName] -> starts a context section
|
|
12
|
+
* KEY=VALUE -> context secrets (within a section)
|
|
13
|
+
*
|
|
14
|
+
* Keys are trimmed. Values are everything after the first `=`, trimmed.
|
|
15
|
+
* Section names may contain hyphens, underscores, etc.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseSecretsFile(content: string): ParsedSecrets;
|
|
18
|
+
/**
|
|
19
|
+
* Load and parse a .kici/.secrets file.
|
|
20
|
+
*
|
|
21
|
+
* Returns empty secrets if the file does not exist.
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadSecretsFile(kiciDir: string): Promise<ParsedSecrets>;
|
|
24
|
+
//# sourceMappingURL=secrets-file.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/test-runner/secrets-file.ts
|
|
5
|
+
/**
|
|
6
|
+
* Parse an INI-style secrets file content.
|
|
7
|
+
*
|
|
8
|
+
* Format:
|
|
9
|
+
* # Comments start with #
|
|
10
|
+
* KEY=VALUE -> flat secrets (before any section)
|
|
11
|
+
* [sectionName] -> starts a context section
|
|
12
|
+
* KEY=VALUE -> context secrets (within a section)
|
|
13
|
+
*
|
|
14
|
+
* Keys are trimmed. Values are everything after the first `=`, trimmed.
|
|
15
|
+
* Section names may contain hyphens, underscores, etc.
|
|
16
|
+
*/
|
|
17
|
+
function parseSecretsFile(content) {
|
|
18
|
+
const flat = {};
|
|
19
|
+
const contexts = {};
|
|
20
|
+
let currentSection = null;
|
|
21
|
+
for (const rawLine of content.split("\n")) {
|
|
22
|
+
const line = rawLine.trim();
|
|
23
|
+
if (line === "" || line.startsWith("#")) continue;
|
|
24
|
+
const sectionMatch = line.match(/^\[([^\]]+)\]$/);
|
|
25
|
+
if (sectionMatch) {
|
|
26
|
+
currentSection = sectionMatch[1].trim();
|
|
27
|
+
if (!contexts[currentSection]) contexts[currentSection] = {};
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const eqIndex = line.indexOf("=");
|
|
31
|
+
if (eqIndex === -1) continue;
|
|
32
|
+
const key = line.slice(0, eqIndex).trim();
|
|
33
|
+
const value = line.slice(eqIndex + 1).trim();
|
|
34
|
+
if (currentSection === null) flat[key] = value;
|
|
35
|
+
else contexts[currentSection][key] = value;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
flat,
|
|
39
|
+
contexts
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Load and parse a .kici/.secrets file.
|
|
44
|
+
*
|
|
45
|
+
* Returns empty secrets if the file does not exist.
|
|
46
|
+
*/
|
|
47
|
+
async function loadSecretsFile(kiciDir) {
|
|
48
|
+
const secretsPath = path.join(kiciDir, ".secrets");
|
|
49
|
+
try {
|
|
50
|
+
return parseSecretsFile(await readFile(secretsPath, "utf-8"));
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") return {
|
|
53
|
+
flat: {},
|
|
54
|
+
contexts: {}
|
|
55
|
+
};
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { loadSecretsFile, parseSecretsFile };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=secrets-file.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StepContext, WorkflowInfo, JobInfo, MatrixValues } from '@kici-dev/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Create a step context for local test execution.
|
|
4
|
+
*
|
|
5
|
+
* `repoRoot` pins `ctx.$` to the workflow's repository root so steps running
|
|
6
|
+
* via local-dispatch behave the same as on the agent path (see
|
|
7
|
+
* `packages/agent/src/execution/sandbox/workflow-runner.ts`). Without this,
|
|
8
|
+
* `ctx.$` would inherit `process.cwd()` — i.e. wherever the user invoked
|
|
9
|
+
* `kici` — which silently breaks any step that uses relative paths.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createStepContext(workflowInfo: WorkflowInfo, jobInfo: JobInfo, repoRoot: string, inputs?: Record<string, unknown>, matrix?: MatrixValues, testSecrets?: {
|
|
12
|
+
flat: Record<string, string>;
|
|
13
|
+
contexts: Record<string, Record<string, string>>;
|
|
14
|
+
}, environment?: string, rawPayload?: Record<string, unknown>, provider?: string): StepContext;
|
|
15
|
+
//# sourceMappingURL=step-context.d.ts.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import "../chunk-gOLHoazu.js";
|
|
2
|
+
import { formatter } from "./output-formatter.js";
|
|
3
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { initZx } from "@kici-dev/shared";
|
|
6
|
+
import { createStepSecrets, resolveJobOutputs, resolveStepOutputs } from "@kici-dev/sdk";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { $ } from "zx";
|
|
9
|
+
//#region src/test-runner/step-context.ts
|
|
10
|
+
initZx();
|
|
11
|
+
/**
|
|
12
|
+
* Create a logger that prefixes output with job name.
|
|
13
|
+
*/
|
|
14
|
+
function createTestLogger(jobName) {
|
|
15
|
+
return {
|
|
16
|
+
info: (message, ...args) => {
|
|
17
|
+
const formatted = args.length > 0 ? `${message} ${args.join(" ")}` : message;
|
|
18
|
+
formatter.logJobLine(jobName, formatted);
|
|
19
|
+
},
|
|
20
|
+
warn: (message, ...args) => {
|
|
21
|
+
const formatted = args.length > 0 ? `${message} ${args.join(" ")}` : message;
|
|
22
|
+
formatter.logJobLine(jobName, `⚠ ${formatted}`);
|
|
23
|
+
},
|
|
24
|
+
error: (message, ...args) => {
|
|
25
|
+
const formatted = args.length > 0 ? `${message} ${args.join(" ")}` : message;
|
|
26
|
+
formatter.logJobLine(jobName, `✗ ${formatted}`);
|
|
27
|
+
},
|
|
28
|
+
debug: (message, ...args) => {
|
|
29
|
+
if (process.env.KICI_DEBUG === "true") {
|
|
30
|
+
const formatted = args.length > 0 ? `${message} ${args.join(" ")}` : message;
|
|
31
|
+
formatter.logJobLine(jobName, `[debug] ${formatted}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a step context for local test execution.
|
|
38
|
+
*
|
|
39
|
+
* `repoRoot` pins `ctx.$` to the workflow's repository root so steps running
|
|
40
|
+
* via local-dispatch behave the same as on the agent path (see
|
|
41
|
+
* `packages/agent/src/execution/sandbox/workflow-runner.ts`). Without this,
|
|
42
|
+
* `ctx.$` would inherit `process.cwd()` — i.e. wherever the user invoked
|
|
43
|
+
* `kici` — which silently breaks any step that uses relative paths.
|
|
44
|
+
*/
|
|
45
|
+
function createStepContext(workflowInfo, jobInfo, repoRoot, inputs = {}, matrix, testSecrets, environment, rawPayload, provider) {
|
|
46
|
+
const flat = testSecrets?.flat ?? {};
|
|
47
|
+
const namespacedSecrets = testSecrets?.contexts ?? {};
|
|
48
|
+
const mergedFlat = { ...flat };
|
|
49
|
+
for (const contextSecrets of Object.values(namespacedSecrets)) Object.assign(mergedFlat, contextSecrets);
|
|
50
|
+
const env = { ...process.env };
|
|
51
|
+
const scoped$ = $({ cwd: repoRoot });
|
|
52
|
+
let tmpdirPath = null;
|
|
53
|
+
const exposedEnvVars = /* @__PURE__ */ new Set();
|
|
54
|
+
let mountCounter = 0;
|
|
55
|
+
let exitHandlerRegistered = false;
|
|
56
|
+
const onProcessExit = () => {
|
|
57
|
+
for (const envVar of exposedEnvVars) {
|
|
58
|
+
delete env[envVar];
|
|
59
|
+
delete process.env[envVar];
|
|
60
|
+
}
|
|
61
|
+
exposedEnvVars.clear();
|
|
62
|
+
if (tmpdirPath !== null) {
|
|
63
|
+
try {
|
|
64
|
+
rmSync(tmpdirPath, {
|
|
65
|
+
recursive: true,
|
|
66
|
+
force: true
|
|
67
|
+
});
|
|
68
|
+
} catch {}
|
|
69
|
+
tmpdirPath = null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const secretsHandle = createStepSecrets(mergedFlat, env, void 0, {
|
|
73
|
+
host: {
|
|
74
|
+
async writeMountedFile(args) {
|
|
75
|
+
if (tmpdirPath === null) tmpdirPath = mkdtempSync(join(tmpdir(), "kici-secret-files-"));
|
|
76
|
+
if (!exitHandlerRegistered) {
|
|
77
|
+
process.once("exit", onProcessExit);
|
|
78
|
+
exitHandlerRegistered = true;
|
|
79
|
+
}
|
|
80
|
+
mountCounter += 1;
|
|
81
|
+
const filename = args.name ?? `secret-${mountCounter}`;
|
|
82
|
+
const filePath = join(tmpdirPath, filename);
|
|
83
|
+
writeFileSync(filePath, args.content);
|
|
84
|
+
chmodSync(filePath, args.mode);
|
|
85
|
+
return filePath;
|
|
86
|
+
},
|
|
87
|
+
trackExposedEnv(envVar) {
|
|
88
|
+
exposedEnvVars.add(envVar);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
cleanup: async () => {
|
|
92
|
+
if (exitHandlerRegistered) {
|
|
93
|
+
process.off("exit", onProcessExit);
|
|
94
|
+
exitHandlerRegistered = false;
|
|
95
|
+
}
|
|
96
|
+
onProcessExit();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
$: scoped$,
|
|
101
|
+
log: createTestLogger(jobInfo.name),
|
|
102
|
+
env,
|
|
103
|
+
setEnv: (key, value) => {
|
|
104
|
+
env[key] = value;
|
|
105
|
+
process.env[key] = value;
|
|
106
|
+
},
|
|
107
|
+
addPath: (dir) => {
|
|
108
|
+
const updated = `${dir}:${env.PATH ?? process.env.PATH ?? ""}`;
|
|
109
|
+
env.PATH = updated;
|
|
110
|
+
process.env.PATH = updated;
|
|
111
|
+
},
|
|
112
|
+
inputs,
|
|
113
|
+
workflow: workflowInfo,
|
|
114
|
+
job: jobInfo,
|
|
115
|
+
matrix,
|
|
116
|
+
isTestRun: false,
|
|
117
|
+
environment,
|
|
118
|
+
...rawPayload && { rawPayload },
|
|
119
|
+
...provider && { provider },
|
|
120
|
+
secrets: secretsHandle.secrets,
|
|
121
|
+
emit: async () => {
|
|
122
|
+
return { deliveryId: "local-test-noop" };
|
|
123
|
+
},
|
|
124
|
+
outputsOf: (ref) => {
|
|
125
|
+
return resolveStepOutputs(ref);
|
|
126
|
+
},
|
|
127
|
+
jobOutputs: (ref) => {
|
|
128
|
+
return resolveJobOutputs(ref);
|
|
129
|
+
},
|
|
130
|
+
setSecretOutput: () => {},
|
|
131
|
+
kici: { infrastructure: { list: () => Promise.resolve({
|
|
132
|
+
scalers: [],
|
|
133
|
+
agents: []
|
|
134
|
+
}) } }
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { createStepContext };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=step-context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WorkflowResult } from './job-executor.js';
|
|
2
|
+
import type { WorkflowDecision } from '@kici-dev/engine';
|
|
3
|
+
/**
|
|
4
|
+
* Display final execution summary.
|
|
5
|
+
*/
|
|
6
|
+
export declare function displaySummary(results: WorkflowResult[], decisions: WorkflowDecision[]): void;
|
|
7
|
+
//# sourceMappingURL=summary.d.ts.map
|