@milkenjoyer/toolchain 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -1
- package/dist/formal.d.mts +60 -0
- package/dist/formal.mjs +628 -0
- package/dist/hooks.mjs +2 -2
- package/dist/proof.mjs +6 -6
- package/dist/verdict.d.mts +3 -0
- package/dist/verdict.mjs +39 -0
- package/dist/verification-6s2chr4X.mjs +111 -0
- package/dist/verification-p2rSx5lc.d.mts +40 -0
- package/dist/verification.d.mts +2 -28
- package/dist/verification.mjs +1 -97
- package/package.json +6 -1
- package/src/formal/cfg.ts +111 -0
- package/src/formal/checks.ts +203 -0
- package/src/formal/semantics.ts +145 -0
- package/src/formal/specs.ts +166 -0
- package/src/formal/tla.ts +284 -0
- package/src/formal.ts +75 -0
- package/src/verdict.ts +50 -0
- package/src/verification.ts +50 -22
package/src/verdict.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { NodeServices } from "@effect/platform-node";
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
4
|
+
import * as Console from "effect/Console";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Exit from "effect/Exit";
|
|
7
|
+
|
|
8
|
+
import { autoPass, github, readPullRequest } from "./verification.ts";
|
|
9
|
+
|
|
10
|
+
export const checkVerdict = Effect.gen(function* () {
|
|
11
|
+
const request = yield* readPullRequest;
|
|
12
|
+
if (request === undefined) return 0;
|
|
13
|
+
const { octokit, owner, repo, number, sha, pr } = request;
|
|
14
|
+
const reason = autoPass(pr);
|
|
15
|
+
if (reason === undefined) {
|
|
16
|
+
yield* Console.log(
|
|
17
|
+
`PR #${number} at ${sha} waits for an independent live verdict.`
|
|
18
|
+
);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const description = `PASS: auto, ${reason}`.slice(0, 139);
|
|
22
|
+
yield* github(() =>
|
|
23
|
+
octokit.rest.repos.createCommitStatus({
|
|
24
|
+
owner,
|
|
25
|
+
repo,
|
|
26
|
+
sha,
|
|
27
|
+
context: "verdict",
|
|
28
|
+
state: "success",
|
|
29
|
+
description,
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
yield* Console.log(
|
|
33
|
+
`Posted verdict: success on PR #${number} at ${sha}: ${description}`
|
|
34
|
+
);
|
|
35
|
+
return 0;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (import.meta.main) {
|
|
39
|
+
const exit = await Effect.runPromiseExit(
|
|
40
|
+
checkVerdict.pipe(Effect.provide(NodeServices.layer))
|
|
41
|
+
);
|
|
42
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
43
|
+
else {
|
|
44
|
+
const error = Cause.squash(exit.cause);
|
|
45
|
+
process.stderr.write(
|
|
46
|
+
`${error instanceof Error ? error.message : String(error)}\n`
|
|
47
|
+
);
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/verification.ts
CHANGED
|
@@ -35,18 +35,22 @@ const exemptions: ReadonlyArray<{
|
|
|
35
35
|
applies: (pr) =>
|
|
36
36
|
pr.files !== undefined &&
|
|
37
37
|
pr.files.length > 0 &&
|
|
38
|
-
pr.files.every(
|
|
39
|
-
|
|
40
|
-
file.split("/").
|
|
41
|
-
|
|
38
|
+
pr.files.every(
|
|
39
|
+
(file) =>
|
|
40
|
+
!file.split("/").includes("skills") &&
|
|
41
|
+
/^(?:LICENSE.*|.*\.(?:md|mdx|png|jpg|jpeg|gif|webp|avif|svg|ico|mp4|webm|mov|mp3|wav|ogg|woff|woff2|ttf|otf))$/iu.test(
|
|
42
|
+
file.split("/").at(-1) ?? ""
|
|
43
|
+
)
|
|
42
44
|
),
|
|
43
45
|
},
|
|
44
46
|
];
|
|
45
47
|
|
|
48
|
+
export const autoPass = (pr: PullRequest): string | undefined =>
|
|
49
|
+
exemptions.find((entry) => entry.applies(pr))?.reason;
|
|
50
|
+
|
|
46
51
|
export const verdict = (pr: PullRequest): Verdict => {
|
|
47
|
-
const exemption =
|
|
48
|
-
if (exemption !== undefined)
|
|
49
|
-
return { _tag: "Exempt", reason: exemption.reason };
|
|
52
|
+
const exemption = autoPass(pr);
|
|
53
|
+
if (exemption !== undefined) return { _tag: "Exempt", reason: exemption };
|
|
50
54
|
const lines = (pr.body ?? "")
|
|
51
55
|
.replaceAll(/<!--[\s\S]*?-->/gu, "")
|
|
52
56
|
.split(/\r?\n/u);
|
|
@@ -70,11 +74,11 @@ export const verdict = (pr: PullRequest): Verdict => {
|
|
|
70
74
|
: { _tag: "Unproven", reason: "names no run" };
|
|
71
75
|
};
|
|
72
76
|
|
|
73
|
-
class VerificationError extends Data.TaggedError("VerificationError")<{
|
|
77
|
+
export class VerificationError extends Data.TaggedError("VerificationError")<{
|
|
74
78
|
readonly message: string;
|
|
75
79
|
}> {}
|
|
76
80
|
|
|
77
|
-
const github = <A>(request: () => Promise<A>) =>
|
|
81
|
+
export const github = <A>(request: () => Promise<A>) =>
|
|
78
82
|
Effect.tryPromise({
|
|
79
83
|
try: request,
|
|
80
84
|
catch: (cause) =>
|
|
@@ -96,13 +100,22 @@ const PullRequestEvent = Schema.fromJsonString(
|
|
|
96
100
|
})
|
|
97
101
|
);
|
|
98
102
|
|
|
99
|
-
export
|
|
103
|
+
export type PullRequestContext = {
|
|
104
|
+
readonly octokit: Octokit;
|
|
105
|
+
readonly owner: string;
|
|
106
|
+
readonly repo: string;
|
|
107
|
+
readonly number: number;
|
|
108
|
+
readonly sha: string;
|
|
109
|
+
readonly pr: PullRequest;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const readPullRequest = Effect.gen(function* () {
|
|
100
113
|
const event = yield* Config.String("GITHUB_EVENT_NAME").pipe(
|
|
101
114
|
Config.withDefault("")
|
|
102
115
|
);
|
|
103
116
|
if (event !== "pull_request") {
|
|
104
117
|
yield* Console.log("Not a pull_request event, so there is no PR to check.");
|
|
105
|
-
return
|
|
118
|
+
return undefined;
|
|
106
119
|
}
|
|
107
120
|
const fs = yield* FileSystem;
|
|
108
121
|
const eventPath = yield* Config.String("GITHUB_EVENT_PATH");
|
|
@@ -135,24 +148,39 @@ export const checkVerification = Effect.gen(function* () {
|
|
|
135
148
|
basehead: `${pr.base.sha}...${pr.head.sha}`,
|
|
136
149
|
})
|
|
137
150
|
);
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
const request: PullRequestContext = {
|
|
152
|
+
octokit,
|
|
153
|
+
owner,
|
|
154
|
+
repo,
|
|
155
|
+
number: pr.number,
|
|
156
|
+
sha: pr.head.sha,
|
|
157
|
+
pr: {
|
|
158
|
+
author: pr.user.login,
|
|
159
|
+
body: pr.body,
|
|
160
|
+
files:
|
|
161
|
+
data.files === undefined || data.files.length >= 300
|
|
162
|
+
? undefined
|
|
163
|
+
: data.files.map((file) => file.filename),
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
return request;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export const checkVerification = Effect.gen(function* () {
|
|
170
|
+
const request = yield* readPullRequest;
|
|
171
|
+
if (request === undefined) return 0;
|
|
172
|
+
const { number } = request;
|
|
173
|
+
const result = verdict(request.pr);
|
|
146
174
|
if (result._tag === "Exempt") {
|
|
147
|
-
yield* Console.log(`PR #${
|
|
175
|
+
yield* Console.log(`PR #${number} is exempt: ${result.reason}.`);
|
|
148
176
|
return 0;
|
|
149
177
|
}
|
|
150
178
|
if (result._tag === "Proven") {
|
|
151
|
-
yield* Console.log(`PR #${
|
|
179
|
+
yield* Console.log(`PR #${number}'s ## Verification names a run.`);
|
|
152
180
|
return 0;
|
|
153
181
|
}
|
|
154
182
|
yield* Console.error(
|
|
155
|
-
`PR #${
|
|
183
|
+
`PR #${number} ${result.reason}. Add a ## Verification section naming each real run (the command or verifier recipe in backticks) and its outcome, then push again after editing the body: a rerun reads the body from the original event.`
|
|
156
184
|
);
|
|
157
185
|
return 1;
|
|
158
186
|
});
|