@boxxy/verifier-wringer 0.0.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # @boxxy/verifier-wringer
1
+ <div align="center">
2
+ <h1>@boxxy/verifier-wringer</h1>
2
3
 
3
- A placeholder. CI publishes the real versions from https://github.com/zgeoff/boxxy.
4
+ <p>
5
+ <a href="https://www.npmjs.com/package/@boxxy/verifier-wringer"><img src="https://img.shields.io/npm/v/@boxxy/verifier-wringer" alt="npm version"></a>
6
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
7
+ </p>
8
+
9
+ <p>
10
+ <a href="../../docs/design/boxxy/README.md">Documentation</a>
11
+ </p>
12
+ </div>
13
+
14
+ boxxy's `Verifier` port on wringer: it reads the verify gate check at a pull request's head and the
15
+ wringer report in the pull request's body.
16
+
17
+ ## Install
18
+
19
+ Install the package from [npm](https://www.npmjs.com/package/@boxxy/verifier-wringer) with Bun:
20
+
21
+ ```bash
22
+ bun add @boxxy/verifier-wringer
23
+ ```
24
+
25
+ The package runs on [Bun](https://bun.sh) 1.3 or newer.
26
+
27
+ ## Features
28
+
29
+ - `createWringerVerifier({ forge, gateCheck })` returns a `Verifier`. The app passes its forge and
30
+ the name of the gate check, such as `verify / gate`.
31
+ - `readAt(pullRequest, head)` reads the latest run of the gate check at `head`. A passed gate reads
32
+ `verified` and a failed gate reads `incomplete`, each with the features of the report.
33
+ - A head with no gate check run, or one still running, cancelled or skipped, reads `not-covered`.
34
+ The adapter then never reads the body. A commit status of the gate's name never counts.
35
+ - A finished gate with no report in the body, or a report that does not parse, reads `incomplete`
36
+ with no features.
37
+ - The adapter does no I/O of its own. It reads the forge, and parses the report with wringer's
38
+ `parseReportBlock`.
39
+
40
+ ## Documentation
41
+
42
+ [The verifier](../../docs/design/boxxy/review-and-merge.md#the-verifier) describes how the verdict
43
+ reaches the merge.
@@ -0,0 +1,3 @@
1
+ import type { Verifier } from '@boxxy/model';
2
+ import type { WringerVerifierOptions } from './types.ts';
3
+ export declare function createWringerVerifier(options: WringerVerifierOptions): Verifier;
@@ -0,0 +1,2 @@
1
+ export { createWringerVerifier } from './create-wringer-verifier.ts';
2
+ export type { WringerVerifierOptions } from './types.ts';
@@ -0,0 +1,9 @@
1
+ import type { FeatureStatus, Report } from '@wringer/core';
2
+ interface MockWringerReportInput {
3
+ readonly features: readonly {
4
+ readonly name: string;
5
+ readonly status: FeatureStatus;
6
+ }[];
7
+ }
8
+ export declare function buildMockWringerReport(input: MockWringerReportInput): Report;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Forge } from '@boxxy/model';
2
+ export interface WringerVerifierOptions {
3
+ readonly forge: Pick<Forge, 'readChecks' | 'readPullRequestBody'>;
4
+ readonly gateCheck: string;
5
+ }
package/package.json CHANGED
@@ -1,13 +1,52 @@
1
1
  {
2
2
  "name": "@boxxy/verifier-wringer",
3
- "version": "0.0.1",
3
+ "version": "0.2.4",
4
+ "description": "boxxy's verifier on wringer: reads the verify gate check and the report in a pull request",
5
+ "homepage": "https://github.com/zgeoff/boxxy/tree/main/adapters/verifier-wringer#readme",
6
+ "bugs": "https://github.com/zgeoff/boxxy/issues",
4
7
  "license": "MIT",
5
8
  "repository": {
6
9
  "type": "git",
7
10
  "url": "git+https://github.com/zgeoff/boxxy.git",
8
11
  "directory": "adapters/verifier-wringer"
9
12
  },
13
+ "files": [
14
+ "src",
15
+ "!src/**/*.test.ts",
16
+ "dist"
17
+ ],
18
+ "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./src/index.ts"
23
+ }
24
+ },
10
25
  "publishConfig": {
11
26
  "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "rm -rf dist && tsrs -p tsconfig.build.json",
30
+ "typecheck": "tsrs --noEmit"
31
+ },
32
+ "dependencies": {
33
+ "@boxxy/model": "0.2.4",
34
+ "@wringer/core": "0.2.0"
35
+ },
36
+ "devDependencies": {
37
+ "@boxxy/dispatch": "0.2.4",
38
+ "@faker-js/faker": "10.6.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@faker-js/faker": "10.6.0"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@faker-js/faker": {
45
+ "optional": true
46
+ }
47
+ },
48
+ "engines": {
49
+ "bun": ">=1.3",
50
+ "node": ">=24"
12
51
  }
13
52
  }
@@ -0,0 +1,54 @@
1
+ import type { CheckReading, CommitSha, Verifier, VerifyReading } from '@boxxy/model';
2
+ import { parseReportBlock } from '@wringer/core';
3
+ import type { WringerVerifierOptions } from './types.ts';
4
+
5
+ // The `Verifier` port on wringer. The gate check in CI computes the fingerprint, which needs a
6
+ // checkout, so the verifier trusts the gate's conclusion and takes the features from the report.
7
+ export function createWringerVerifier(options: WringerVerifierOptions): Verifier {
8
+ return {
9
+ readAt: async (pullRequest, head) => {
10
+ const checks = await options.forge.readChecks(pullRequest.repo, head);
11
+
12
+ const gate = pickGateState(checks.get(options.gateCheck));
13
+
14
+ if (gate === null) {
15
+ return { status: 'not-covered', head };
16
+ }
17
+
18
+ const body = await options.forge.readPullRequestBody(pullRequest);
19
+
20
+ return buildVerifyReading(head, gate, body);
21
+ },
22
+ };
23
+ }
24
+
25
+ // Only the workflow's check run counts: any token that may write statuses could post a commit
26
+ // status of the gate's name. A cancelled or skipped run gave no verdict, as a run still going.
27
+ function pickGateState(gate: CheckReading | undefined): 'success' | 'failure' | null {
28
+ if (gate?.source !== 'check-run') {
29
+ return null;
30
+ }
31
+
32
+ return gate.state === 'success' || gate.state === 'failure' ? gate.state : null;
33
+ }
34
+
35
+ function buildVerifyReading(
36
+ head: CommitSha,
37
+ gate: 'success' | 'failure',
38
+ body: string,
39
+ ): VerifyReading {
40
+ const parsed = parseReportBlock(body);
41
+
42
+ if (!parsed.ok) {
43
+ return { status: 'incomplete', head, features: [] };
44
+ }
45
+
46
+ return {
47
+ status: gate === 'success' ? 'verified' : 'incomplete',
48
+ head,
49
+ features: parsed.report.features.map((feature) => ({
50
+ name: feature.name,
51
+ status: feature.status,
52
+ })),
53
+ };
54
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createWringerVerifier } from './create-wringer-verifier.ts';
2
+ export type { WringerVerifierOptions } from './types.ts';
@@ -0,0 +1,40 @@
1
+ import { faker } from '@faker-js/faker';
2
+ import type { FeatureStatus, Report } from '@wringer/core';
3
+
4
+ interface MockWringerReportInput {
5
+ readonly features: readonly { readonly name: string; readonly status: FeatureStatus }[];
6
+ }
7
+
8
+ // A wringer report against `origin/main` at a random fingerprint. A `verified` or `stale` feature
9
+ // carries a verdict, and only an `unchanged` feature is unchanged.
10
+ export function buildMockWringerReport(input: MockWringerReportInput): Report {
11
+ const fingerprint = faker.string.hexadecimal({ length: 16, casing: 'lower', prefix: '' });
12
+
13
+ return {
14
+ version: 1,
15
+ base: 'origin/main',
16
+ fingerprint,
17
+ complete: input.features.every(
18
+ (feature) => feature.status === 'verified' || feature.status === 'unchanged',
19
+ ),
20
+ features: input.features.map((feature) => ({
21
+ name: feature.name,
22
+ changed: feature.status !== 'unchanged',
23
+ status: feature.status,
24
+ verdict:
25
+ feature.status === 'verified' || feature.status === 'stale'
26
+ ? {
27
+ feature: feature.name,
28
+ fingerprint:
29
+ feature.status === 'verified'
30
+ ? fingerprint
31
+ : faker.string.hexadecimal({ length: 16, casing: 'lower', prefix: '' }),
32
+ run: `run-${faker.string.alphanumeric(8)}`,
33
+ at: faker.date.recent().toISOString(),
34
+ evidence: [],
35
+ }
36
+ : null,
37
+ })),
38
+ unmapped: [],
39
+ };
40
+ }
package/src/types.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { Forge } from '@boxxy/model';
2
+
3
+ export interface WringerVerifierOptions {
4
+ readonly forge: Pick<Forge, 'readChecks' | 'readPullRequestBody'>;
5
+
6
+ // the name of the check run that runs `bun verify gate`, such as `verify / gate`
7
+ readonly gateCheck: string;
8
+ }