@attalabs/vinaya 0.44.1 → 0.47.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.
Files changed (143) hide show
  1. package/README.md +6 -4
  2. package/dist/checks/bin/check-body-bare-digits.js +233 -195
  3. package/dist/checks/bin/check-branch-topology.js +70 -23
  4. package/dist/checks/bin/check-brief-shape.js +233 -195
  5. package/dist/checks/bin/check-changeset-coverage.js +94 -16
  6. package/dist/checks/bin/check-ci-shard-coverage.js +3 -0
  7. package/dist/checks/bin/check-closes-n.js +128 -34
  8. package/dist/checks/bin/check-coherence.js +336 -245
  9. package/dist/checks/bin/check-dispatch-readiness.js +3623 -463
  10. package/dist/checks/bin/check-doc-claims.js +233 -195
  11. package/dist/checks/bin/check-doc-coverage-push.js +243 -196
  12. package/dist/checks/bin/check-doc-coverage.js +243 -196
  13. package/dist/checks/bin/check-doctrine-no-procedures.js +233 -195
  14. package/dist/checks/bin/check-doctrine-portability.js +233 -195
  15. package/dist/checks/bin/check-evidence-fresh.js +9983 -1995
  16. package/dist/checks/bin/check-exec-bits.js +3 -0
  17. package/dist/checks/bin/check-first-push-dispatch.js +301 -224
  18. package/dist/checks/bin/check-issue-milestone-attach.js +65 -10
  19. package/dist/checks/bin/check-issue-objectives-numbering.js +233 -195
  20. package/dist/checks/bin/check-issue-parts-coverage.js +65 -10
  21. package/dist/checks/bin/check-issue-surface-globs.js +1032 -236
  22. package/dist/checks/bin/check-issue-title-grammar.js +5 -1
  23. package/dist/checks/bin/check-no-disk-state.js +5 -1
  24. package/dist/checks/bin/check-pr-premise-reassert.js +10 -1
  25. package/dist/checks/bin/check-pr-report-density.js +5 -1
  26. package/dist/checks/bin/check-principal-test-plan-wait.js +253 -201
  27. package/dist/checks/bin/check-quoted-command.js +233 -195
  28. package/dist/checks/bin/check-reader-resolvable-prose.js +233 -195
  29. package/dist/checks/bin/check-registry-gates.js +131 -34
  30. package/dist/checks/bin/check-retired-vocabulary.js +233 -195
  31. package/dist/checks/bin/check-review-gate.js +233 -195
  32. package/dist/checks/bin/check-single-plan-pr.js +5 -1
  33. package/dist/checks/bin/check-surface-scope.js +107 -32
  34. package/dist/checks/bin/check-test-plan.js +253 -201
  35. package/dist/checks/bin/check-token-collection-wired.js +3 -0
  36. package/dist/checks/bin/check-workspace-escape.js +3 -0
  37. package/dist/checks/bin/verify-coherence.js +237 -148
  38. package/dist/checks/bin/verify-dispatch.js +870 -66
  39. package/dist/checks/bin/verify-docs.js +13 -6
  40. package/dist/harness.js +57 -10
  41. package/dist/index.js +16617 -7187
  42. package/dist/lib/pre-push-cache-test-run.js +4487 -2170
  43. package/dist/lib/pre-push-changed-files.js +251 -12
  44. package/dist/lib/pre-push-mode.js +69 -19
  45. package/dist/lib/pre-push-progress-dir.js +10265 -2853
  46. package/dist/lib/pre-push-record-tests.js +67 -19
  47. package/dist/lib/pre-push-select-tests.js +520 -222
  48. package/dist/lib/push-progress-observer.js +9176 -1757
  49. package/dist/process.js +2 -0
  50. package/dist/programs/archive.js +8948 -1547
  51. package/dist/programs/audit.js +9176 -1772
  52. package/dist/programs/check.js +9248 -1845
  53. package/dist/programs/commit-msg.js +8984 -1583
  54. package/dist/programs/dev-review-loop.js +15612 -7634
  55. package/dist/programs/dispatch.js +9977 -2726
  56. package/dist/programs/log-emit.js +9011 -1660
  57. package/dist/programs/log-selftest.js +8908 -1507
  58. package/dist/programs/log-send.js +9081 -1594
  59. package/dist/programs/pr-report.js +9476 -1820
  60. package/dist/programs/pr-snapshot.js +8916 -1515
  61. package/dist/programs/pr-verify-evidence.js +9481 -1825
  62. package/dist/programs/pr.js +11709 -4033
  63. package/dist/programs/review-post.js +11140 -3496
  64. package/dist/programs/review-status.js +8996 -1533
  65. package/dist/programs/run-engine.js +22031 -18759
  66. package/dist/programs/sync.js +9030 -1629
  67. package/dist/programs/task-brief.js +10185 -1821
  68. package/dist/programs/task-sweep.js +9266 -1621
  69. package/dist/programs/task-tools-serve.js +77118 -16678
  70. package/dist/programs/tokens.js +8966 -1565
  71. package/dist/programs/waiver.js +8983 -1582
  72. package/dist/types/harness/kernel/dev-process-socket/loader/load-process.d.ts +1 -1
  73. package/dist/types/harness/processes/vinaya-strict/tools/legacy-markers.d.ts +8 -0
  74. package/dist/types/harness/processes/vinaya-strict/tools/task-contract/brief-validation.d.ts +3 -3
  75. package/dist/types/harness/processes/vinaya-strict/tools/task-contract/objectives.d.ts +5 -6
  76. package/dist/vinaya-strict/checks/registry.ts +2 -2
  77. package/dist/vinaya-strict/executing/developer/developer-doctrine-shape.test.ts +8 -0
  78. package/dist/vinaya-strict/executing/developer/developer-turn-result.ts +1 -1
  79. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.test.ts +2 -2
  80. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.ts +30 -20
  81. package/dist/vinaya-strict/executing/developer/reference.md +5 -3
  82. package/dist/vinaya-strict/integration/config/vinaya-config-section.ts +29 -7
  83. package/dist/vinaya-strict/integration/policies/vinaya-policies.ts +4 -4
  84. package/dist/vinaya-strict/integration/process/process-integration.ts +5 -1
  85. package/dist/vinaya-strict/process.yaml +6 -1
  86. package/dist/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
  87. package/dist/vinaya-strict/thinking/plan-reviewer/grants.yaml +19 -0
  88. package/dist/vinaya-strict/thinking/plan-reviewer/output.schema.json +388 -0
  89. package/dist/vinaya-strict/thinking/planner/doctrine.md +4 -1
  90. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.test.ts +10 -2
  91. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.ts +5 -1
  92. package/dist/vinaya-strict/thinking/planner/tools/open-issue.test.ts +198 -34
  93. package/dist/vinaya-strict/thinking/planner/tools/open-issue.ts +120 -193
  94. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.test.ts +629 -15
  95. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.ts +726 -62
  96. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.test.ts +505 -5
  97. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.ts +636 -21
  98. package/package.json +3 -2
  99. package/studio-standalone/apps/vinaya-studio/.next/BUILD_ID +1 -1
  100. package/studio-standalone/apps/vinaya-studio/.next/build-manifest.json +2 -2
  101. package/studio-standalone/apps/vinaya-studio/.next/prerender-manifest.json +3 -3
  102. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  103. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.html +1 -1
  104. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.rsc +1 -1
  105. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  106. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  107. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  108. package/studio-standalone/apps/vinaya-studio/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  109. package/studio-standalone/apps/vinaya-studio/.next/server/app/milestones/page_client-reference-manifest.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/.next/server/app/page_client-reference-manifest.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/.next/server/app/tasks/page_client-reference-manifest.js +1 -1
  112. package/studio-standalone/apps/vinaya-studio/.next/server/chunks/209.js +2 -2
  113. package/studio-standalone/apps/vinaya-studio/.next/server/chunks/951.js +1 -1
  114. package/studio-standalone/apps/vinaya-studio/.next/server/middleware-build-manifest.js +1 -1
  115. package/studio-standalone/apps/vinaya-studio/.next/server/pages/500.html +1 -1
  116. package/studio-standalone/apps/vinaya-studio/.next/server/preview-props.json +3 -3
  117. package/studio-standalone/apps/vinaya-studio/.next/server/server-reference-manifest.json +1 -1
  118. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-c365f0ef8268ad13.js +1 -0
  119. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/19-aa314f13784dcc58.js +4 -0
  120. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{layout-dfa2186095e797bd.js → layout-f038e8deecb2bf5f.js} +1 -1
  121. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/milestones/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
  122. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{page-6ae258f663623b2a.js → page-7a06aa3cdd046fa8.js} +1 -1
  123. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/tasks/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
  124. package/studio-standalone/apps/vinaya-studio/.next/static/css/8eb5ed5b65b9692e.css +1 -0
  125. package/studio-standalone/apps/vinaya-studio/log-follow.mjs +708 -93
  126. package/studio-standalone/apps/vinaya-studio/log-sync-folder-source.mjs +699 -84
  127. package/studio-standalone/apps/vinaya-studio/studio-server.mjs +4692 -3116
  128. package/vinaya-strict/artifacts/templates/brief-template.md +4 -0
  129. package/vinaya-strict/artifacts/templates/issue-rationale-template.md +7 -3
  130. package/vinaya-strict/artifacts/templates/pr-report-template.md +1 -1
  131. package/vinaya-strict/doctrine/contracts/planner-developer.md +2 -1
  132. package/vinaya-strict/doctrine/enforcement.md +4 -4
  133. package/vinaya-strict/doctrine/roles/principal.md +1 -1
  134. package/vinaya-strict/doctrine/state-machine.md +7 -2
  135. package/vinaya-strict/executing/developer/reference.md +5 -3
  136. package/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
  137. package/vinaya-strict/thinking/planner/doctrine.md +4 -1
  138. package/vinaya-strict/thinking/planner/reference.md +29 -8
  139. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-23bea4cac9687151.js +0 -1
  140. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/853-1d5548ff3a55a75f.js +0 -4
  141. package/studio-standalone/apps/vinaya-studio/.next/static/css/fb16828fc3128d4c.css +0 -1
  142. /package/studio-standalone/apps/vinaya-studio/.next/static/{3URbt6IPajL5OOhijN1-x → bJrgAp9Kl4JsCUYkeAYez}/_buildManifest.js +0 -0
  143. /package/studio-standalone/apps/vinaya-studio/.next/static/{3URbt6IPajL5OOhijN1-x → bJrgAp9Kl4JsCUYkeAYez}/_ssgManifest.js +0 -0
@@ -1,13 +1,15 @@
1
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, unlinkSync, writeFileSync } from 'node:fs'
1
+ import { spawnSync } from 'node:child_process'
2
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, unlinkSync, writeFileSync } from 'node:fs'
2
3
  import { tmpdir } from 'node:os'
3
4
  import { join } from 'node:path'
4
- import { describe, expect, it, vi } from 'vitest'
5
+ import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
5
6
  import {
6
7
  type AmendDepsDeps,
7
8
  type AmendDepsFlags,
8
9
  appliesTaskIssueGate,
9
- blastRadiusErrorsForWrite,
10
+ createRefusalReason,
10
11
  edgesEqual,
12
+ formatFinding,
11
13
  formatLeftoverPrint,
12
14
  type LeftoverFacts,
13
15
  locateBody,
@@ -22,7 +24,9 @@ import {
22
24
  taskIdFromTitle,
23
25
  validateAmendFlags
24
26
  } from './open-issue'
25
- import { BRIEF_SECTIONS_SINCE_ISSUE } from '../../../tools/task-contract/issue-validation'
27
+ import { makeCheckError } from '@harness/workflow/tools/task-contract/forge/forge-write'
28
+ import type { CheckError } from '@harness/kernel/gates/checks/contract'
29
+ import { createIssue, editIssue } from './planner-operations'
26
30
 
27
31
  describe('appliesTaskIssueGate (task-run-v1 21, #541, round 2 review SECURITY HIGH)', () => {
28
32
  it('applies on a vinaya/tranche:* label alone, even with a body carrying no task-shaped content', () => {
@@ -209,6 +213,17 @@ describe('regular-file body-file input is unaffected by the fix', () => {
209
213
  })
210
214
  })
211
215
 
216
+ describe('createRefusalReason', () => {
217
+ it('refuses a create that carries a tranche label, naming plan_publish', () => {
218
+ expect(createRefusalReason(['vinaya/tranche:demo'], false)).toContain('plan_publish')
219
+ })
220
+
221
+ it('lets a labelless create and any edit go on', () => {
222
+ expect(createRefusalReason(['vinaya/tier:1'], false)).toBeNull()
223
+ expect(createRefusalReason(['vinaya/tranche:demo'], true)).toBeNull()
224
+ })
225
+ })
226
+
212
227
  describe('resolveMilestoneToAttach (sample-tranche-v1 task 1 follow-up)', () => {
213
228
  const activeLookup = vi.fn((slug: string) =>
214
229
  slug === 'sample-tranche-v1' ? { number: 9, title: 'sample-tranche-v1' } : null
@@ -484,47 +499,88 @@ function makeDeps(overrides: Partial<AmendDepsDeps> = {}): {
484
499
  fail: (m) => {
485
500
  throw new Error(m)
486
501
  },
502
+ // The validation itself is proved against the real one below; these cases are about the amendment's own steps.
503
+ validate: async () => ({ errors: [], blocking: false, renderSkipped: null }),
487
504
  ...overrides
488
505
  }
489
506
  return { deps, edited, logs }
490
507
  }
491
508
 
492
509
  describe('runAmendDeps', () => {
493
- it('refuses when the target is not a task Issue (no vinaya/tranche:* label)', () => {
510
+ it('refuses when the target is not a task Issue (no vinaya/tranche:* label)', async () => {
494
511
  const { deps, edited } = makeDeps({ fetchLabels: () => ['vinaya/tier:1'] })
495
- expect(() => runAmendDeps(parseAmendArgs(['429', '--depends-on', '2', '--note', 'x']), deps)).toThrow(
512
+ await expect(runAmendDeps(parseAmendArgs(['429', '--depends-on', '2', '--note', 'x']), deps)).rejects.toThrow(
496
513
  /targets task Issues only/
497
514
  )
498
515
  expect(edited).toHaveLength(0)
499
516
  })
500
517
 
501
- it('refuses a missing --note (flag validation) with no forge write', () => {
518
+ it('refuses a missing --note (flag validation) with no forge write', async () => {
502
519
  const { deps, edited } = makeDeps()
503
- expect(() => runAmendDeps(parseAmendArgs(['429', '--depends-on', '2']), deps)).toThrow(/non-empty `--note`/)
520
+ await expect(runAmendDeps(parseAmendArgs(['429', '--depends-on', '2']), deps)).rejects.toThrow(/non-empty `--note`/)
504
521
  expect(edited).toHaveLength(0)
505
522
  })
506
523
 
507
- it('refuses on a round-trip mismatch and writes nothing (the gate, on real data)', () => {
524
+ it('refuses on a round-trip mismatch and writes nothing (the gate, on real data)', async () => {
508
525
  // `sample-tranche-v1 #368, 5` — the bare `5` inherits the qualifier
509
526
  // on parse (→ `sample-tranche-v1 5`), so the read-back != requested.
510
527
  const { deps, edited } = makeDeps()
511
- expect(() =>
528
+ await expect(
512
529
  runAmendDeps(parseAmendArgs(['429', '--depends-on', 'sample-tranche-v1 #368, 5', '--note', 'x']), deps)
513
- ).toThrow(/round-trip FAILED for Depends-on/)
530
+ ).rejects.toThrow(/round-trip FAILED for Depends-on/)
531
+ expect(edited).toHaveLength(0)
532
+ })
533
+
534
+ it('writes nothing, and prints the finding with its check name, when the validation reports a blocking finding', async () => {
535
+ const blocking = makeCheckError('issue-pinned-importers', 'an importer of a pinned file is undecided', 'Decide it.')
536
+ const { deps, edited, logs } = makeDeps({
537
+ validate: async () => ({ errors: [blocking], blocking: true, renderSkipped: null })
538
+ })
539
+ await expect(
540
+ runAmendDeps(parseAmendArgs(['429', '--depends-on', '2, 3', '--note', 'Task 3 dropped.']), deps)
541
+ ).rejects.toThrow(/Nothing written/)
514
542
  expect(edited).toHaveLength(0)
543
+ expect(logs.some((l) => l.includes('[issue-pinned-importers]'))).toBe(true)
544
+ })
545
+
546
+ it('writes nothing on a blocking finding in a dry run either', async () => {
547
+ const blocking = makeCheckError('issue-pinned-importers', 'an importer of a pinned file is undecided', 'Decide it.')
548
+ const { deps, logs } = makeDeps({
549
+ validate: async () => ({ errors: [blocking], blocking: true, renderSkipped: null })
550
+ })
551
+ await expect(
552
+ runAmendDeps(parseAmendArgs(['429', '--depends-on', '2', '--note', 'x', '--dry-run']), deps)
553
+ ).rejects.toThrow(/Nothing written/)
554
+ expect(logs).not.toContain('round-trip PASS')
555
+ })
556
+
557
+ it('writes the amended body only when the validation, given that body and the Issue, reports no blocking finding', async () => {
558
+ const seen: Array<{ body: string | null; labels: string[]; number: number | null }> = []
559
+ const { deps, edited } = makeDeps({
560
+ validate: async (body, _title, labels, _retry, number) => {
561
+ seen.push({ body, labels, number })
562
+ return { errors: [], blocking: false, renderSkipped: null }
563
+ }
564
+ })
565
+ await runAmendDeps(parseAmendArgs(['429', '--depends-on', '2, 3', '--note', 'Task 3 dropped.']), deps)
566
+ expect(edited).toHaveLength(1)
567
+ expect(seen).toHaveLength(1)
568
+ expect(seen[0]?.body).toBe(edited[0]?.body)
569
+ expect(seen[0]?.number).toBe(429)
570
+ expect(seen[0]?.labels).toContain('vinaya/tranche:other-tranche-v1')
515
571
  })
516
572
 
517
- it('dry-run prints the body + round-trip PASS and performs NO forge write', () => {
573
+ it('dry-run prints the body + round-trip PASS and performs NO forge write', async () => {
518
574
  const { deps, edited, logs } = makeDeps()
519
- runAmendDeps(parseAmendArgs(['429', '--depends-on', '2, 3', '--note', 'Task 3 dropped.', '--dry-run']), deps)
575
+ await runAmendDeps(parseAmendArgs(['429', '--depends-on', '2, 3', '--note', 'Task 3 dropped.', '--dry-run']), deps)
520
576
  expect(edited).toHaveLength(0)
521
577
  expect(logs).toContain('round-trip PASS')
522
578
  expect(logs.some((l) => l.includes('`Depends-on: 2, 3`'))).toBe(true)
523
579
  })
524
580
 
525
- it('a real run ships the amended body once and logs the edge change', () => {
581
+ it('a real run ships the amended body once and logs the edge change', async () => {
526
582
  const { deps, edited, logs } = makeDeps()
527
- runAmendDeps(parseAmendArgs(['429', '--depends-on', '2, 3', '--note', 'Task 3 dropped.']), deps)
583
+ await runAmendDeps(parseAmendArgs(['429', '--depends-on', '2, 3', '--note', 'Task 3 dropped.']), deps)
528
584
  expect(edited).toHaveLength(1)
529
585
  expect(edited[0]?.issue).toBe('429')
530
586
  expect(edited[0]?.body).toContain('**Amendment (2026-07-13, Planner)')
@@ -676,26 +732,134 @@ describe('readSharedPackages', () => {
676
732
  })
677
733
  })
678
734
 
679
- describe('blastRadiusErrorsForWrite', () => {
680
- const shared = ['packages/ui']
681
- const registry = [{ name: 'vinaya', path: 'apps/vinaya' }]
682
- const surfaceBody = '## Surface\n\nin: packages/ui/**\nout: —\n\n**Project:** vinaya\n'
683
-
684
- it('judges a create (no Issue ref) from `## Surface`', () => {
685
- const errors = blastRadiusErrorsForWrite(surfaceBody, [], shared, registry, null)
686
- expect(errors).toHaveLength(1)
687
- expect(errors[0]).toMatch(/packages\/ui/)
688
- })
689
-
690
- it('judges an edit above the cutover from `## Surface`, the same as a create', () => {
691
- const ref = String(BRIEF_SECTIONS_SINCE_ISSUE + 1)
692
- expect(blastRadiusErrorsForWrite(surfaceBody, [], shared, registry, ref)).toEqual(
693
- blastRadiusErrorsForWrite(surfaceBody, [], shared, registry, null)
735
+ // The script against the Planner tools, on one body: the real validation, behind a fake GitHub command line
736
+ // first on the path, so nothing reaches the forge and no rule is stubbed.
737
+ describe('the script decides through the validation the Planner tools call', () => {
738
+ const SCRIPT = join(__dirname, 'open-issue.ts')
739
+ const LABEL = 'vinaya/tranche:fixture-v1'
740
+ const TITLE = '[fixture-v1] 1 — Fix(planner): a fixture task'
741
+ // An importer of a pinned file the Surface neither reaches nor excludes: `open-issue.ts` imports `amend-rationale-deps.ts`.
742
+ const PINNED = 'harness/processes/vinaya-strict/thinking/planner/tools/amend-rationale-deps.ts'
743
+ const BODY = [
744
+ '**Project:** vinaya',
745
+ '',
746
+ '## Objectives',
747
+ '',
748
+ 'O1. The fixture decides through the one validation.',
749
+ '',
750
+ '## Surface',
751
+ '',
752
+ 'in: harness/processes/vinaya-strict/tests',
753
+ 'out: —',
754
+ '',
755
+ '## Parts',
756
+ '',
757
+ 'Part 1 (O1) — the only part.',
758
+ '',
759
+ `**Boundary** — Pinned files: \`${PINNED}\`. Out: other work.`
760
+ ].join('\n')
761
+
762
+ let dir = ''
763
+ let bodyFile = ''
764
+ let savedPath: string | undefined
765
+ let savedRepo: string | undefined
766
+ let savedCwd = ''
767
+
768
+ beforeAll(() => {
769
+ dir = mkdtempSync(join(tmpdir(), 'open-issue-gate-'))
770
+ bodyFile = join(dir, 'body.md')
771
+ writeFileSync(bodyFile, BODY, 'utf8')
772
+ mkdirSync(join(dir, 'bin'))
773
+ writeFileSync(
774
+ join(dir, 'bin', 'gh'),
775
+ [
776
+ '#!/bin/sh',
777
+ `if [ "$1" = "issue" ] && [ "$2" = "view" ]; then echo '{"number":2218,"title":"${TITLE}","body":"","labels":[{"name":"${LABEL}"}]}'; exit 0; fi`,
778
+ `if [ "$2" = "list" ]; then echo '[]'; exit 0; fi`,
779
+ // The Principal read of the default branch's configuration, and an Issue with no comments.
780
+ `if [ "$1" = "api" ] && [ "\${2#*contents/vinaya.config.json}" != "$2" ]; then echo '${Buffer.from(JSON.stringify({ principals: ['fixture-principal'] })).toString('base64')}'; exit 0; fi`,
781
+ `if [ "$1" = "api" ] && [ "\${2#*/comments}" != "$2" ]; then echo '[]'; exit 0; fi`,
782
+ 'exit 1',
783
+ ''
784
+ ].join('\n')
694
785
  )
786
+ chmodSync(join(dir, 'bin', 'gh'), 0o755)
787
+ savedPath = process.env.PATH
788
+ savedRepo = process.env.VINAYA_REPO
789
+ // The script works from the repository root; the in-process side must resolve tracked files from the same root, whatever directory the test runs from.
790
+ savedCwd = process.cwd()
791
+ process.chdir(join(__dirname, '../../../../../..'))
792
+ process.env.PATH = `${join(dir, 'bin')}:${process.env.PATH ?? ''}`
793
+ process.env.VINAYA_REPO = 'test-owner/test-repo'
794
+ })
795
+
796
+ afterAll(() => {
797
+ process.env.PATH = savedPath
798
+ process.chdir(savedCwd)
799
+ if (savedRepo === undefined) delete process.env.VINAYA_REPO
800
+ else process.env.VINAYA_REPO = savedRepo
801
+ rmSync(dir, { recursive: true, force: true })
695
802
  })
696
803
 
697
- it('keeps an edit of an Issue numbered below the cutover on the prose scan', () => {
698
- const ref = `https://github.com/o/r/issues/${BRIEF_SECTIONS_SINCE_ISSUE - 1}`
699
- expect(blastRadiusErrorsForWrite(surfaceBody, [], shared, registry, ref)).toEqual([])
700
- })
804
+ /** Runs the script as a program and returns its exit code and the finding lines it printed. */
805
+ function runScript(args: string[]): { status: number | null; findings: string[]; stderr: string } {
806
+ const r = spawnSync(process.execPath, [SCRIPT, ...args], {
807
+ encoding: 'utf8',
808
+ env: process.env,
809
+ timeout: 240_000
810
+ })
811
+ const findings = r.stderr.split('\n').filter((l) => /^ {2}[✗!] \[/.test(l))
812
+ return { status: r.status, findings, stderr: r.stderr }
813
+ }
814
+
815
+ const findingsOf = (outcome: Awaited<ReturnType<typeof createIssue>>): CheckError[] => {
816
+ if (outcome.ok) throw new Error('the Planner tools accepted the body')
817
+ return outcome.findings
818
+ }
819
+
820
+ const printed = (findings: CheckError[]): string[] => findings.map((e) => formatFinding(e))
821
+
822
+ it('refuses an undecided importer on validate-only, naming the check, with the findings the Planner tools return', async () => {
823
+ const tools = await createIssue({
824
+ ghArgs: ['--title', TITLE, '--body-file', bodyFile, '--label', LABEL],
825
+ validateOnly: true
826
+ })
827
+ expect(tools.ok).toBe(false)
828
+ const expected = printed(findingsOf(tools))
829
+ const importer = expected.find((l) => l.includes('Surface/importers'))
830
+ expect(importer).toBeDefined()
831
+
832
+ const script = runScript(['--validate-only', '--title', TITLE, '--body-file', bodyFile, '--label', LABEL])
833
+ expect(script.status).toBe(1)
834
+ expect(script.findings).toEqual(expected)
835
+ expect(script.stderr).toContain(importer as string)
836
+ expect(script.stderr).toMatch(/\[[a-z0-9-]+\] issue-validation Surface\/importers/)
837
+ }, 300_000)
838
+
839
+ it('refuses the same body on create with the same findings, and sends nothing to the forge', async () => {
840
+ const tools = await createIssue({
841
+ ghArgs: ['--title', TITLE, '--body-file', bodyFile, '--label', LABEL],
842
+ validateOnly: true
843
+ })
844
+ const script = runScript(['--title', TITLE, '--body-file', bodyFile, '--label', LABEL])
845
+ expect(script.status).toBe(1)
846
+ expect(script.findings).toEqual(printed(findingsOf(tools)))
847
+ expect(script.stderr).toContain('Nothing was sent to the forge')
848
+ }, 300_000)
849
+
850
+ it('refuses the same body on edit with the findings the Planner edit returns', async () => {
851
+ const tools = await editIssue({ args: ['2218', '--body-file', bodyFile], validateOnly: true })
852
+ expect(tools.ok).toBe(false)
853
+ const script = runScript(['edit', '2218', '--body-file', bodyFile])
854
+ expect(script.status).toBe(1)
855
+ expect(script.findings).toEqual(printed(findingsOf(tools)))
856
+ }, 300_000)
857
+
858
+ it('runs the validation once the Log sink factory is installed: the program stops on no missing-factory error', () => {
859
+ const script = runScript(['--validate-only', '--title', TITLE, '--body-file', bodyFile, '--label', LABEL])
860
+ // The program ran the validation to its findings and refused on them, rather than dying on a missing factory.
861
+ expect(script.status).toBe(1)
862
+ expect(script.findings.length).toBeGreaterThan(0)
863
+ expect(script.stderr).not.toMatch(/sink factory/i)
864
+ }, 300_000)
701
865
  })