@boxxy/review-noslop 0.2.12 → 0.3.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 CHANGED
@@ -30,11 +30,12 @@ The package runs on [Bun](https://bun.sh) 1.3 or newer.
30
30
  which only the server has.
31
31
  - `buildCommand(round)` gives a command that writes `noslop-review.json` in the pull request's
32
32
  checkout. A first round runs a full review. A later round runs `--fixes-only`, and runs a plain
33
- review when that run judged no fix.
33
+ review when that run judged no fix and `noslop findings` succeeds.
34
34
  - `accept(round, result)` posts the result with `sendResult` from `@noslop/cli/post`, then reads the
35
35
  findings still open with `check` from `@noslop/cli/check`.
36
36
  - `accept` reads a result that it can't post as `not-covered` and posts nothing. That covers a
37
- result for an old head and a fixes-only run that judged no fix.
37
+ result for an old head and a fixes-only run that judged no fix. When `noslop findings` failed in
38
+ that run, the reading's `reason` holds noslop's error, such as a missing `github.app`.
38
39
  - `accept` throws only when GitHub gives no answer, so the session sends the file again.
39
40
 
40
41
  ## Documentation
@@ -9,5 +9,6 @@ export type ParsedReviewBody = {
9
9
  readonly kind: 'not-covered';
10
10
  readonly head: CommitSha;
11
11
  readonly cost: GateCost;
12
+ readonly reason?: string;
12
13
  };
13
14
  export declare function parseReviewBody(round: GateRound, body: JsonValue): ParsedReviewBody;
@@ -4,6 +4,7 @@ export interface StubNoslopAnswers {
4
4
  readonly plain: string | null;
5
5
  readonly findings: {
6
6
  readonly stdout: string;
7
+ readonly stderr: string;
7
8
  readonly exitCode: number;
8
9
  };
9
10
  readonly head: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxxy/review-noslop",
3
- "version": "0.2.12",
3
+ "version": "0.3.0",
4
4
  "description": "boxxy's review gate on noslop: the review command, and the check and post of its result",
5
5
  "homepage": "https://github.com/zgeoff/boxxy/tree/main/adapters/review-noslop#readme",
6
6
  "bugs": "https://github.com/zgeoff/boxxy/issues",
@@ -30,7 +30,7 @@
30
30
  "typecheck": "tsrs --noEmit"
31
31
  },
32
32
  "dependencies": {
33
- "@boxxy/model": "0.2.12",
33
+ "@boxxy/model": "0.3.0",
34
34
  "@noslop/cli": "0.4.30",
35
35
  "ts-pattern": "5.9.2",
36
36
  "zod": "4.6.7"
@@ -9,9 +9,9 @@ export const reviewFileName = 'noslop-review.json';
9
9
  // nothing; `--adapter claude` uses the model sign-in the host's broker gives.
10
10
  const script = `
11
11
  const args = __ARGS__;
12
- const run = (argv) => {
13
- const child = Bun.spawnSync(argv, { stdout: 'pipe', stderr: 'inherit' });
14
- return { exitCode: child.exitCode, text: child.stdout.toString() };
12
+ const run = (argv, stderr = 'inherit') => {
13
+ const child = Bun.spawnSync(argv, { stdout: 'pipe', stderr });
14
+ return { exitCode: child.exitCode, text: child.stdout.toString(), error: child.stderr?.toString() ?? '' };
15
15
  };
16
16
  const parse = (text) => {
17
17
  try { return JSON.parse(text); } catch { return null; }
@@ -19,16 +19,18 @@ const parse = (text) => {
19
19
  const target = ['--pr', String(args.pr), '--repo', args.repo];
20
20
  const options = [...target, '--adapter', 'claude', '--report', 'json', '--json'];
21
21
  let review = parse(run(['noslop', 'review', args.mode, ...options]).text);
22
- if (args.mode === '--fixes-only' && (review?.fixChecks ?? []).length === 0) {
22
+ const listed = run(['noslop', 'findings', ...target, '--json'], 'pipe');
23
+ process.stderr.write(listed.error);
24
+ if (args.mode === '--fixes-only' && (review?.fixChecks ?? []).length === 0 && listed.exitCode === 0) {
23
25
  review = parse(run(['noslop', 'review', ...options]).text);
24
26
  }
25
- const listed = run(['noslop', 'findings', ...target, '--json']);
26
27
  const head = run(['git', 'rev-parse', 'HEAD']).text.trim();
27
- await Bun.write(args.file, JSON.stringify({ head, review, findings: { exitCode: listed.exitCode, list: parse(listed.text) } }));
28
+ await Bun.write(args.file, JSON.stringify({ head, review, findings: { exitCode: listed.exitCode, list: parse(listed.text), error: listed.error.trim() } }));
28
29
  `;
29
30
 
30
31
  // A first review reads the whole pull request. A later one checks the fixes, and falls back to a
31
- // plain review when no `fixed` answer got a verdict, because that run read nothing at its head.
32
+ // plain review when no `fixed` answer got a verdict and `noslop findings` succeeds. A failed
33
+ // `findings` means noslop read no earlier review, so a plain review would read the whole PR.
32
34
  export function buildReviewCommand(round: GateRound): string {
33
35
  const mode = match(round.cause)
34
36
  .with('first', () => '--full')
@@ -19,7 +19,9 @@ export function createNoslopReviewGate(options: NoslopReviewGateOptions): Review
19
19
  const parsed = parseReviewBody(round, result);
20
20
 
21
21
  if (parsed.kind === 'not-covered') {
22
- return { status: 'not-covered', head: parsed.head, cost: parsed.cost };
22
+ return parsed.reason === undefined
23
+ ? { status: 'not-covered', head: parsed.head, cost: parsed.cost }
24
+ : { status: 'not-covered', head: parsed.head, cost: parsed.cost, reason: parsed.reason };
23
25
  }
24
26
 
25
27
  const cost = buildGateCost(parsed.review);
@@ -6,11 +6,16 @@ import { z } from 'zod';
6
6
  import { buildGateCost } from './build-gate-cost.ts';
7
7
 
8
8
  // The file the review command writes: the git head of the checkout, the review's JSON, and the
9
- // output of `noslop findings` with its exit code. A part the command could not read is null.
9
+ // output of `noslop findings` with its exit code and stderr. A part the command could not read is
10
+ // null.
10
11
  const reviewBodySchema = z.object({
11
12
  head: z.string().nullable(),
12
13
  review: z.unknown(),
13
- findings: z.object({ exitCode: z.number().int().nullable(), list: z.unknown() }),
14
+ findings: z.object({
15
+ exitCode: z.number().int().nullable(),
16
+ list: z.unknown(),
17
+ error: z.string().default(''),
18
+ }),
14
19
  });
15
20
 
16
21
  export type ParsedReviewBody =
@@ -22,7 +27,14 @@ export type ParsedReviewBody =
22
27
  // null when `noslop findings` failed or printed no list
23
28
  readonly list: FindingList | null;
24
29
  }
25
- | { readonly kind: 'not-covered'; readonly head: CommitSha; readonly cost: GateCost };
30
+ | {
31
+ readonly kind: 'not-covered';
32
+ readonly head: CommitSha;
33
+ readonly cost: GateCost;
34
+
35
+ // why the session ran no review of the head, when the owner has to act
36
+ readonly reason?: string;
37
+ };
26
38
 
27
39
  const noHead = brandSchemas.commitSha.parse('0'.repeat(40));
28
40
 
@@ -54,10 +66,23 @@ export function parseReviewBody(round: GateRound, body: JsonValue): ParsedReview
54
66
  return { kind: 'not-covered', head: noHead, cost: buildGateCost(review.data) };
55
67
  }
56
68
 
57
- if (!isRoundPullRequest(round, review.data) || isFixesOnlyWithNoVerdict(review.data)) {
69
+ if (!isRoundPullRequest(round, review.data)) {
58
70
  return { kind: 'not-covered', head: head.data, cost: buildGateCost(review.data) };
59
71
  }
60
72
 
73
+ if (isFixesOnlyWithNoVerdict(review.data)) {
74
+ const findings = envelope.data.findings;
75
+
76
+ return findings.exitCode === 0
77
+ ? { kind: 'not-covered', head: head.data, cost: buildGateCost(review.data) }
78
+ : {
79
+ kind: 'not-covered',
80
+ head: head.data,
81
+ cost: buildGateCost(review.data),
82
+ reason: buildUntrustedReason(findings.exitCode, findings.error),
83
+ };
84
+ }
85
+
61
86
  const list = findingListSchema.safeParse(envelope.data.findings.list);
62
87
 
63
88
  return {
@@ -79,3 +104,9 @@ function isRoundPullRequest(round: GateRound, review: ReviewResult): boolean {
79
104
  function isFixesOnlyWithNoVerdict(review: ReviewResult): boolean {
80
105
  return review.fixesOnly === true && (review.fixChecks ?? []).length === 0;
81
106
  }
107
+
108
+ // Without the earlier findings, a plain review would read the whole pull request again, so the
109
+ // session runs none, and the owner reads why in the item's attempts.
110
+ function buildUntrustedReason(exitCode: number | null, error: string): string {
111
+ return `The fixes-only review judged no fix, and \`noslop findings\` failed with exit code ${exitCode ?? 'none'}, so the session ran no plain review: without the earlier findings, a plain review would read the whole pull request again. When noslop names \`github.app\`, set \`github.app\` in the base branch's noslop config to the slug of the App that posts the reviews. noslop said: ${error === '' ? 'nothing' : error}`;
112
+ }
@@ -7,7 +7,11 @@ export interface StubNoslopAnswers {
7
7
  readonly full: string | null;
8
8
  readonly fixesOnly: string | null;
9
9
  readonly plain: string | null;
10
- readonly findings: { readonly stdout: string; readonly exitCode: number };
10
+ readonly findings: {
11
+ readonly stdout: string;
12
+ readonly stderr: string;
13
+ readonly exitCode: number;
14
+ };
11
15
 
12
16
  // what `git rev-parse HEAD` prints
13
17
  readonly head: string;
@@ -47,7 +51,7 @@ export async function createStubNoslop(
47
51
  ` "review --full") cat '${await answerPath('full', answers.full)}' ;;`,
48
52
  ` "review --fixes-only") cat '${await answerPath('fixes-only', answers.fixesOnly)}' ;;`,
49
53
  ` "review --pr") cat '${await answerPath('plain', answers.plain)}' ;;`,
50
- ` "findings --pr") cat '${await answerPath('findings', answers.findings.stdout)}'; exit ${answers.findings.exitCode} ;;`,
54
+ ` "findings --pr") cat '${await answerPath('findings', answers.findings.stdout)}'; cat '${await answerPath('findings-stderr', answers.findings.stderr)}' >&2; exit ${answers.findings.exitCode} ;;`,
51
55
  'esac',
52
56
  '',
53
57
  ].join('\n');