@astryxdesign/cli 0.7.2-canary.22c592a → 0.7.2-canary.25548b9

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
@@ -447,8 +447,8 @@ Every response has a `type` discriminant. The full set is below (generated from
447
447
  | `build.kit` | The template to start from and its kit: query, hasResults, matchCount (never a cap), directMatch, start {name, package, command, basis, reason, alternatives, ...} (the start and each alternative name the package that owns the template), pages (search's closest templates), blocks and domain as SearchResultEntry[] (each naming its package), frame and foundation (Core component names), and hint {reason, commands} when thin. |
448
448
  | `swizzle.list` | The names of swizzlable components discoverable from cwd's @astryxdesign/core. The envelope's package is @astryxdesign/core. |
449
449
  | `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the written file names, whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package. |
450
- | `gap-report.categories` | The fixed gap category values and human-readable labels. |
451
- | `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals. |
450
+ | `gap-report.categories` | The fixed gap category values and human-readable labels; when a loaded integration names its own issues URL, meta.destinations lists every destination ({to, default, issuesUrl}) and meta.ask tells an agent to ask the person. |
451
+ | `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals; without --to, when a loaded integration names its own issues URL, destinations and ask as on gap-report.categories. |
452
452
  | `template.list` | The effective discovered TemplateListEntry[] for pages and blocks. A winning replacement entry includes optional `replaces`, naming the Core id omitted from the default list. |
453
453
  | `template.show` | The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media). |
454
454
  | `template.skeleton` | A layout skeleton (structural tags with spatial annotations) plus the template's description and the components it composes. The envelope's package names the npm package that owns the template. |
@@ -468,8 +468,8 @@ Every response has a `type` discriminant. The full set is below (generated from
468
468
  | `theme.palette.generate` | An author-reviewable OKLCH palette candidate, its reproducibility receipt, summary counts, and optional candidate/receipt file-write result. |
469
469
  | `upgrade.list` | Every available codemod, oldest→newest, as {name, package, title, version, optional}; returned for --list without running anything. |
470
470
  | `upgrade.registry` | The copied-composition receipt for --registry: applied, ok, the counts (found, current, wouldUpdate, updated, wouldMerge, merged, wouldRefreshReceipt, receiptsRefreshed, conflicts, missing, invalid, failed), and items. |
471
- | `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. |
472
- | `upgrade.run` | The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. |
471
+ | `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. no_codemods and config_fixable carry cliBehindCore ({cliVersion, command}) when the installed Core is newer than the CLI, which then has no codemods for the releases after its own version. |
472
+ | `upgrade.run` | The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run. |
473
473
  | `manifest` | The CLI capability manifest: name, version, apiVersion, description, globalOptions, commands (each name, description, arguments, options, json, aliases?, responseTypes?, examples?, exitCodes? as [{code, when}], subcommands?), jsonSupported, and the flat responseTypes index. |
474
474
  | `help` | Help, in one of two shapes. A bare `astryx --json` returns the root manifest: name, version, commands (the command names), jsonSupported, and manifest (the full payload `astryx manifest --json` returns). `--help --json` on any command, or `astryx help [command] --json`, returns that command's help: command, description, usage, options (each flags, description, and defaultValue and choices when set), and subcommands (each name and description). data.manifest marks the first shape; data.usage marks the second. |
475
475
  | `version` | The CLI version, for `astryx --version --json`: {version}. |
@@ -60,6 +60,9 @@ export const GAP_REPORT_CATEGORIES: readonly (Readonly<{
60
60
  label: "Other";
61
61
  }>)[];
62
62
  export const PUBLIC_CONFIRMATION_MESSAGE: "Rerun with --confirm-public to file this report.";
63
+ /** What an agent does when more than one destination exists. */
64
+ export const ASK_DESTINATION_MESSAGE: "Ask the person where to file this report, then pass their choice with --to <package>. Never pick a package destination yourself; leave --to out to use the default.";
65
+ export type GapReportDestination = import("./gap-report.type.mjs").GapReportDestination;
63
66
  export type ReportTarget = {
64
67
  package: string;
65
68
  version: string | null;
@@ -19,6 +19,8 @@ export const doc = {
19
19
  'Sends a gap report to every configured handler: the project config handler first, then each integration handler in config order. ' +
20
20
  'Each handler has 30 s to finish, and its output goes to stderr. Public handlers run only with confirmPublic; internal handlers always run. ' +
21
21
  "With no handler, it files a GitHub issue for the owning package only with confirmPublic (without it nothing is sent), or returns the package's issues URL when that is not on GitHub. " +
22
+ "With options.to, the report goes only to that integration's issues URL instead, under the same confirmPublic rule. " +
23
+ 'When loaded integrations name their own issues URLs, the response lists every destination with a line telling an agent to ask the person where to file; pass their choice as options.to, never a package the agent picked itself. ' +
22
24
  'The report records whether an agent or a person ran it, and the response lists each handler outcome in order.',
23
25
  importPath: '@astryxdesign/cli/api',
24
26
  signature:
@@ -67,14 +69,20 @@ export const doc = {
67
69
  name: 'options.confirmPublic',
68
70
  type: 'boolean',
69
71
  description:
70
- 'Allow public delivery: public handlers run, and with no handler a GitHub issue is filed through the gh CLI.',
72
+ 'Allow public delivery: public handlers run, and a GitHub issues URL gets an issue filed through the gh CLI.',
71
73
  default: 'false',
72
74
  },
75
+ {
76
+ name: 'options.to',
77
+ type: 'string',
78
+ description:
79
+ 'A destination the person chose: a loaded integration whose manifest names an issues URL. The report goes only to that issues URL; handlers do not run.',
80
+ },
73
81
  {
74
82
  name: 'options.listCategories',
75
83
  type: 'boolean',
76
84
  description:
77
- 'Return categories without resolving a route or writing; the component and every other option are refused with ERR_INVALID_ARGUMENT.',
85
+ 'Return categories, and the destinations in meta when there is more than one, without resolving a route or writing; the component and every other option are refused with ERR_INVALID_ARGUMENT.',
78
86
  default: 'false',
79
87
  },
80
88
  {
@@ -115,7 +123,7 @@ export const doc = {
115
123
  },
116
124
  {
117
125
  code: 'ERR_UNKNOWN_PACKAGE',
118
- when: 'the explicitly selected package is not loaded',
126
+ when: 'the explicitly selected package is not loaded, or options.to names no destination (the error lists the destinations)',
119
127
  },
120
128
  {
121
129
  code: 'ERR_NOT_FOUND',
@@ -55,6 +55,14 @@ export const GAP_REPORT_CATEGORIES = Object.freeze([
55
55
  export const PUBLIC_CONFIRMATION_MESSAGE =
56
56
  'Rerun with --confirm-public to file this report.';
57
57
 
58
+ /** What an agent does when more than one destination exists. */
59
+ export const ASK_DESTINATION_MESSAGE =
60
+ 'Ask the person where to file this report, then pass their choice with --to <package>. Never pick a package destination yourself; leave --to out to use the default.';
61
+
62
+ /**
63
+ * @typedef {import('./gap-report.type.mjs').GapReportDestination} GapReportDestination
64
+ */
65
+
58
66
  /**
59
67
  * @typedef {object} ReportTarget
60
68
  * @property {string} package
@@ -537,15 +545,14 @@ function githubRoute(issuesUrl) {
537
545
  }
538
546
 
539
547
  /**
540
- * Built-in GitHub fallback — runs only when the effective handler set is empty.
541
- * Requires confirmPublic.
548
+ * File a report on GitHub with `gh` — for the zero-handler fallback and for a
549
+ * destination the caller names. Requires confirmPublic.
542
550
  *
543
- * @param {ReportTarget} target
544
551
  * @param {{component: string, categoryLabel: string, intention: string, detail?: string, source: string, timestamp: string}} report
545
552
  * @param {{repo: string}} github
546
553
  * @returns {Promise<Pick<import('./gap-report.type.mjs').GapReportDelivery, 'status'|'url'|'message'>>}
547
554
  */
548
- async function runGithubFallback(target, report, github) {
555
+ async function runGithubFallback(report, github) {
549
556
  const {execFile} = await import('node:child_process');
550
557
  const title = `[gap] ${report.component}: ${report.intention.slice(0, 70)}`;
551
558
  const body = [
@@ -607,6 +614,87 @@ async function runGithubFallback(target, report, github) {
607
614
  }
608
615
  }
609
616
 
617
+ /**
618
+ * Send a report to an issues URL: a GitHub issues URL is filed with `gh` only
619
+ * with consent; any other URL comes back as routed_only. Serves the
620
+ * zero-handler fallback (spec:AST-031/FR8) and a destination named with `to`
621
+ * (architecture:cli-surface INV36).
622
+ *
623
+ * @param {string} issuesUrl
624
+ * @param {{component: string, categoryLabel: string, intention: string, detail?: string, source: string, timestamp: string}} report
625
+ * @param {boolean} confirmPublic
626
+ * @returns {Promise<import('./gap-report.type.mjs').GapReportDelivery>}
627
+ */
628
+ async function deliverToIssuesUrl(issuesUrl, report, confirmPublic) {
629
+ const github = githubRoute(issuesUrl);
630
+ if (github != null && !confirmPublic) {
631
+ return {
632
+ handlerType: 'fallback',
633
+ handler: 'github',
634
+ audience: 'public',
635
+ status: 'consent_required',
636
+ url: null,
637
+ message: PUBLIC_CONFIRMATION_MESSAGE,
638
+ };
639
+ }
640
+ if (github) {
641
+ return {
642
+ handlerType: 'fallback',
643
+ handler: 'github',
644
+ audience: 'public',
645
+ ...(await runGithubFallback(report, github)),
646
+ };
647
+ }
648
+ return {
649
+ handlerType: 'fallback',
650
+ handler: 'issuesUrl',
651
+ audience: null,
652
+ status: 'routed_only',
653
+ url: issuesUrl,
654
+ message:
655
+ 'No automatic handler is available; open the routed URL to file this report.',
656
+ };
657
+ }
658
+
659
+ /**
660
+ * Where a report can go: the default (the handlers, or with none the owning
661
+ * package's issues URL), then each loaded integration that names its own
662
+ * issues URL (architecture:cli-surface INV36).
663
+ *
664
+ * @param {Project} project
665
+ * @returns {GapReportDestination[]}
666
+ */
667
+ function listDestinations(project) {
668
+ /** @type {GapReportDestination[]} */
669
+ const destinations = [{to: null, default: true, issuesUrl: null}];
670
+ for (const integration of project.loadedIntegrations) {
671
+ if (integration.__loadError || !integration.issuesUrl) continue;
672
+ if (destinations.some(destination => destination.to === integration.name))
673
+ continue;
674
+ destinations.push({
675
+ to: integration.name,
676
+ default: false,
677
+ issuesUrl: integration.issuesUrl,
678
+ });
679
+ }
680
+ return destinations;
681
+ }
682
+
683
+ /**
684
+ * The destinations of the project at `cwd`, or only the default when no
685
+ * project loads there.
686
+ * @param {string|undefined} cwd
687
+ * @returns {Promise<GapReportDestination[]>}
688
+ */
689
+ async function destinationsAt(cwd) {
690
+ try {
691
+ const {resolve} = await import('node:path');
692
+ return listDestinations(await Project.load(resolve(cwd ?? process.cwd())));
693
+ } catch {
694
+ return [{to: null, default: true, issuesUrl: null}];
695
+ }
696
+ }
697
+
610
698
  /**
611
699
  * Compute the aggregate status from the deliveries.
612
700
  * @param {import('./gap-report.type.mjs').GapReportDelivery[]} deliveries
@@ -665,6 +753,7 @@ export async function gapReport(component, options = {}) {
665
753
  options.detail ? '--additional-context' : null,
666
754
  options.package ? '--package' : null,
667
755
  options.confirmPublic ? '--confirm-public' : null,
756
+ options.to != null ? '--to' : null,
668
757
  ].filter(Boolean);
669
758
  if (ignored.length > 0) {
670
759
  throw new AstryxError(
@@ -673,9 +762,13 @@ export async function gapReport(component, options = {}) {
673
762
  ERROR_CODES.ERR_INVALID_ARGUMENT,
674
763
  );
675
764
  }
765
+ const destinations = await destinationsAt(options.cwd);
676
766
  return {
677
767
  type: 'gap-report.categories',
678
768
  data: GAP_REPORT_CATEGORIES.map(category => ({...category})),
769
+ ...(destinations.length > 1
770
+ ? {meta: {destinations, ask: ASK_DESTINATION_MESSAGE}}
771
+ : {}),
679
772
  };
680
773
  }
681
774
 
@@ -704,7 +797,33 @@ export async function gapReport(component, options = {}) {
704
797
  options.package,
705
798
  );
706
799
 
707
- const entries = collectGapReportHandlers(project);
800
+ const destinations = listDestinations(project);
801
+ /** @type {GapReportDestination | undefined} */
802
+ let chosen;
803
+ // `to: null` is absent, like `package: null`; any other value is matched
804
+ // against the destinations as given, so an empty or unknown one lists them.
805
+ if (options.to != null) {
806
+ const to = options.to;
807
+ chosen = destinations.find(
808
+ destination => !destination.default && destination.to === to,
809
+ );
810
+ if (!chosen) {
811
+ const choices = destinations.filter(destination => !destination.default);
812
+ const named = JSON.stringify(String(to).slice(0, 214));
813
+ throw new AstryxError(
814
+ choices.length > 0
815
+ ? `No gap-report destination ${named}. Choose one of: ${choices.map(destination => destination.to).join(', ')}; or leave out --to for the default.`
816
+ : `No gap-report destination ${named}: no loaded integration names an issues URL. Leave out --to for the default.`,
817
+ choices.map(destination => ({
818
+ name: /** @type {string} */ (destination.to),
819
+ reason: /** @type {string} */ (destination.issuesUrl),
820
+ })),
821
+ ERROR_CODES.ERR_UNKNOWN_PACKAGE,
822
+ );
823
+ }
824
+ }
825
+
826
+ const entries = chosen ? [] : collectGapReportHandlers(project);
708
827
 
709
828
  const timestamp = new Date().toISOString();
710
829
  const source = captureEnv().invocationSource;
@@ -731,8 +850,24 @@ export async function gapReport(component, options = {}) {
731
850
 
732
851
  /** @type {import('./gap-report.type.mjs').GapReportDelivery[]} */
733
852
  const deliveries = [];
853
+ const routeReport = {
854
+ component: resolvedComponent,
855
+ categoryLabel: categoryEntry.label,
856
+ intention,
857
+ detail,
858
+ source,
859
+ timestamp,
860
+ };
734
861
 
735
- if (entries.length > 0) {
862
+ if (chosen) {
863
+ deliveries.push(
864
+ await deliverToIssuesUrl(
865
+ /** @type {string} */ (chosen.issuesUrl),
866
+ routeReport,
867
+ options.confirmPublic === true,
868
+ ),
869
+ );
870
+ } else if (entries.length > 0) {
736
871
  deliveries.push(
737
872
  ...(await deliverGapReportHandlers(entries, report, {
738
873
  confirmPublic: options.confirmPublic === true,
@@ -746,47 +881,13 @@ export async function gapReport(component, options = {}) {
746
881
  ERROR_CODES.ERR_NOT_FOUND,
747
882
  );
748
883
  }
749
-
750
- const github = githubRoute(target.issuesUrl);
751
- if (github != null && options.confirmPublic !== true) {
752
- deliveries.push({
753
- handlerType: 'fallback',
754
- handler: 'github',
755
- audience: 'public',
756
- status: 'consent_required',
757
- url: null,
758
- message: PUBLIC_CONFIRMATION_MESSAGE,
759
- });
760
- } else if (github) {
761
- const outcome = await runGithubFallback(
762
- target,
763
- {
764
- component: resolvedComponent,
765
- categoryLabel: categoryEntry.label,
766
- intention,
767
- detail,
768
- source,
769
- timestamp,
770
- },
771
- github,
772
- );
773
- deliveries.push({
774
- handlerType: 'fallback',
775
- handler: 'github',
776
- audience: 'public',
777
- ...outcome,
778
- });
779
- } else {
780
- deliveries.push({
781
- handlerType: 'fallback',
782
- handler: 'issuesUrl',
783
- audience: null,
784
- status: 'routed_only',
785
- url: target.issuesUrl,
786
- message:
787
- 'No automatic handler is available; open the routed URL to file this report.',
788
- });
789
- }
884
+ deliveries.push(
885
+ await deliverToIssuesUrl(
886
+ target.issuesUrl,
887
+ routeReport,
888
+ options.confirmPublic === true,
889
+ ),
890
+ );
790
891
  }
791
892
 
792
893
  const filedCount = deliveries.filter(d => d.status === 'filed').length;
@@ -800,10 +901,13 @@ export async function gapReport(component, options = {}) {
800
901
  data: {
801
902
  status,
802
903
  package: target.package,
803
- issuesUrl: target.issuesUrl,
904
+ issuesUrl: chosen ? chosen.issuesUrl : target.issuesUrl,
804
905
  deliveries,
805
906
  filedCount,
806
907
  routedOnlyCount,
908
+ ...(!chosen && destinations.length > 1
909
+ ? {destinations, ask: ASK_DESTINATION_MESSAGE}
910
+ : {}),
807
911
  },
808
912
  };
809
913
  }
@@ -7,6 +7,7 @@ import * as path from 'node:path';
7
7
  import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
8
8
  import {Project} from '../../foundation/config/project.mjs';
9
9
  import {
10
+ ASK_DESTINATION_MESSAGE,
10
11
  GAP_REPORT_CATEGORIES,
11
12
  PUBLIC_CONFIRMATION_MESSAGE,
12
13
  collectGapReportHandlers,
@@ -1022,6 +1023,238 @@ console.log('https://github.com/acme/widgets/issues/42');
1022
1023
  });
1023
1024
  });
1024
1025
 
1026
+ describe('gapReport destinations and --to', () => {
1027
+ /** A shared internal handler that records each call in a marker file. */
1028
+ function addSharedHandler() {
1029
+ const marker = path.join(projectDir, 'shared-called');
1030
+ addIntegration({
1031
+ name: '@test/shared',
1032
+ audience: 'internal',
1033
+ handleBody: `(await import('node:fs')).writeFileSync(${JSON.stringify(marker)}, 'x'); return {status: 'filed', message: 'shared'};`,
1034
+ });
1035
+ return marker;
1036
+ }
1037
+
1038
+ function addWidgets(issuesUrl = 'https://github.com/acme/widgets/issues') {
1039
+ addIntegration({name: '@test/widgets', handler: false, issuesUrl});
1040
+ }
1041
+
1042
+ it('keeps the default route and lists the destinations with the ask line', async () => {
1043
+ const marker = addSharedHandler();
1044
+ addWidgets();
1045
+ configure(['@test/shared', '@test/widgets']);
1046
+ const argsFile = stubGh();
1047
+
1048
+ const result = await gapReport('General', {
1049
+ ...reportOptions,
1050
+ confirmPublic: true,
1051
+ cwd: projectDir,
1052
+ });
1053
+
1054
+ expect(result.data.deliveries).toEqual([
1055
+ expect.objectContaining({handler: '@test/shared', status: 'filed'}),
1056
+ ]);
1057
+ expect(fs.existsSync(marker)).toBe(true);
1058
+ expect(fs.existsSync(argsFile)).toBe(false);
1059
+ expect(result.data.destinations).toEqual([
1060
+ {to: null, default: true, issuesUrl: null},
1061
+ {
1062
+ to: '@test/widgets',
1063
+ default: false,
1064
+ issuesUrl: 'https://github.com/acme/widgets/issues',
1065
+ },
1066
+ ]);
1067
+ expect(result.data.ask).toBe(ASK_DESTINATION_MESSAGE);
1068
+ expect(ASK_DESTINATION_MESSAGE).toMatch(/ask the person/i);
1069
+ });
1070
+
1071
+ it('lists no destinations when no integration names an issuesUrl', async () => {
1072
+ addSharedHandler();
1073
+ configure(['@test/shared']);
1074
+
1075
+ const result = await gapReport('General', {
1076
+ ...reportOptions,
1077
+ cwd: projectDir,
1078
+ });
1079
+
1080
+ expect(result.data).not.toHaveProperty('destinations');
1081
+ expect(result.data).not.toHaveProperty('ask');
1082
+ });
1083
+
1084
+ it('files with the chosen integration GitHub issuesUrl only with consent, and runs no handler', async () => {
1085
+ const marker = addSharedHandler();
1086
+ addWidgets();
1087
+ configure(['@test/shared', '@test/widgets']);
1088
+ const argsFile = stubGh();
1089
+
1090
+ const pending = await gapReport('General', {
1091
+ ...reportOptions,
1092
+ to: '@test/widgets',
1093
+ cwd: projectDir,
1094
+ });
1095
+ expect(pending.data.deliveries).toEqual([
1096
+ {
1097
+ handlerType: 'fallback',
1098
+ handler: 'github',
1099
+ audience: 'public',
1100
+ status: 'consent_required',
1101
+ url: null,
1102
+ message: PUBLIC_CONFIRMATION_MESSAGE,
1103
+ },
1104
+ ]);
1105
+ expect(pending.data.issuesUrl).toBe(
1106
+ 'https://github.com/acme/widgets/issues',
1107
+ );
1108
+ expect(pending.data).not.toHaveProperty('destinations');
1109
+ expect(fs.existsSync(argsFile)).toBe(false);
1110
+
1111
+ const filed = await gapReport('General', {
1112
+ ...reportOptions,
1113
+ to: '@test/widgets',
1114
+ confirmPublic: true,
1115
+ cwd: projectDir,
1116
+ });
1117
+ expect(filed.data.deliveries).toHaveLength(1);
1118
+ expect(filed.data.deliveries[0]).toMatchObject({
1119
+ handlerType: 'fallback',
1120
+ handler: 'github',
1121
+ status: 'filed',
1122
+ });
1123
+ const args = JSON.parse(fs.readFileSync(argsFile, 'utf8'));
1124
+ expect(args.slice(0, 4)).toEqual([
1125
+ 'issue',
1126
+ 'create',
1127
+ '--repo',
1128
+ 'acme/widgets',
1129
+ ]);
1130
+ expect(fs.existsSync(marker)).toBe(false);
1131
+ });
1132
+
1133
+ it('routes a chosen non-GitHub issuesUrl as routed_only', async () => {
1134
+ addSharedHandler();
1135
+ addWidgets('https://tracker.example/widgets');
1136
+ configure(['@test/shared', '@test/widgets']);
1137
+
1138
+ const result = await gapReport('General', {
1139
+ ...reportOptions,
1140
+ to: '@test/widgets',
1141
+ cwd: projectDir,
1142
+ });
1143
+
1144
+ expect(result.data.deliveries).toEqual([
1145
+ expect.objectContaining({
1146
+ handlerType: 'fallback',
1147
+ handler: 'issuesUrl',
1148
+ status: 'routed_only',
1149
+ url: 'https://tracker.example/widgets',
1150
+ }),
1151
+ ]);
1152
+ expect(result.data.status).toBe('routed_only');
1153
+ });
1154
+
1155
+ it.each([
1156
+ ['a package that is not loaded', '@test/nope'],
1157
+ ['a loaded integration without an issuesUrl', '@test/shared'],
1158
+ ])(
1159
+ 'refuses --to naming %s, lists the choices, and sends nothing',
1160
+ async (_label, to) => {
1161
+ const marker = addSharedHandler();
1162
+ addWidgets();
1163
+ configure(['@test/shared', '@test/widgets']);
1164
+
1165
+ await expect(
1166
+ gapReport('General', {...reportOptions, to, cwd: projectDir}),
1167
+ ).rejects.toMatchObject({
1168
+ code: 'ERR_UNKNOWN_PACKAGE',
1169
+ suggestions: [
1170
+ {
1171
+ name: '@test/widgets',
1172
+ reason: 'https://github.com/acme/widgets/issues',
1173
+ },
1174
+ ],
1175
+ });
1176
+ expect(fs.existsSync(marker)).toBe(false);
1177
+ },
1178
+ );
1179
+
1180
+ it.each([
1181
+ ['an empty value', ''],
1182
+ ['a blank value', ' '],
1183
+ ['an over-long value', `@test/${'a'.repeat(300)}`],
1184
+ ])('refuses %s for --to with the destination list', async (_label, to) => {
1185
+ const marker = addSharedHandler();
1186
+ addWidgets();
1187
+ configure(['@test/shared', '@test/widgets']);
1188
+
1189
+ await expect(
1190
+ gapReport('General', {...reportOptions, to, cwd: projectDir}),
1191
+ ).rejects.toMatchObject({
1192
+ code: 'ERR_UNKNOWN_PACKAGE',
1193
+ suggestions: [{name: '@test/widgets'}],
1194
+ });
1195
+ expect(fs.existsSync(marker)).toBe(false);
1196
+ });
1197
+
1198
+ it('treats to: null as absent', async () => {
1199
+ const marker = addSharedHandler();
1200
+ addWidgets();
1201
+ configure(['@test/shared', '@test/widgets']);
1202
+
1203
+ const result = await gapReport('General', {
1204
+ ...reportOptions,
1205
+ to: /** @type {any} */ (null),
1206
+ cwd: projectDir,
1207
+ });
1208
+
1209
+ expect(result.data.deliveries).toHaveLength(1);
1210
+ expect(fs.existsSync(marker)).toBe(true);
1211
+ expect(result.data.destinations).toHaveLength(2);
1212
+ });
1213
+
1214
+ it('lists the destinations with the categories', async () => {
1215
+ addSharedHandler();
1216
+ addWidgets();
1217
+ configure(['@test/shared', '@test/widgets']);
1218
+
1219
+ const listed = await gapReport(undefined, {
1220
+ listCategories: true,
1221
+ cwd: projectDir,
1222
+ });
1223
+
1224
+ expect(listed.data).toEqual(GAP_REPORT_CATEGORIES);
1225
+ expect(listed.meta).toEqual({
1226
+ destinations: [
1227
+ {to: null, default: true, issuesUrl: null},
1228
+ {
1229
+ to: '@test/widgets',
1230
+ default: false,
1231
+ issuesUrl: 'https://github.com/acme/widgets/issues',
1232
+ },
1233
+ ],
1234
+ ask: ASK_DESTINATION_MESSAGE,
1235
+ });
1236
+ });
1237
+
1238
+ it('adds no meta to the categories when there is only the default', async () => {
1239
+ configure([]);
1240
+ const listed = await gapReport(undefined, {
1241
+ listCategories: true,
1242
+ cwd: projectDir,
1243
+ });
1244
+ expect(listed).not.toHaveProperty('meta');
1245
+ });
1246
+
1247
+ it('refuses --to with --list-categories', async () => {
1248
+ await expect(
1249
+ gapReport(undefined, {
1250
+ listCategories: true,
1251
+ to: '@test/widgets',
1252
+ cwd: projectDir,
1253
+ }),
1254
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
1255
+ });
1256
+ });
1257
+
1025
1258
  describe('gapReport target selection', () => {
1026
1259
  it('routes to the unique component owner', async () => {
1027
1260
  addIntegration({
@@ -35,10 +35,42 @@ export type GapReportOptions = {
35
35
  * Return the category vocabulary without routing or writing.
36
36
  */
37
37
  listCategories?: boolean | undefined;
38
+ /**
39
+ * A destination the person chose: a loaded integration
40
+ * whose manifest names an issues URL. The report goes only there.
41
+ */
42
+ to?: string | undefined;
43
+ };
44
+ /**
45
+ * Where a report can go. The default entry (`to: null`) is the configured
46
+ * handlers, or with none the owning package's issues URL.
47
+ */
48
+ export type GapReportDestination = {
49
+ /**
50
+ * The value to pass as `to`; null for the default.
51
+ */
52
+ to: string | null;
53
+ /**
54
+ * Whether this is the default destination.
55
+ */
56
+ default: boolean;
57
+ /**
58
+ * The integration's issues URL; null for the
59
+ * default.
60
+ */
61
+ issuesUrl: string | null;
38
62
  };
39
63
  export type GapReportCategoriesResponse = {
40
64
  type: "gap-report.categories";
41
65
  data: GapReportCategoryEntry[];
66
+ /**
67
+ * Present when a destination besides the default exists: every destination,
68
+ * and the line telling an agent to ask the person.
69
+ */
70
+ meta?: {
71
+ destinations: GapReportDestination[];
72
+ ask: string;
73
+ } | undefined;
42
74
  };
43
75
  export type GapReportAggregateStatus = "filed" | "partial" | "failed" | "routed_only" | "consent_required" | "skipped";
44
76
  export type GapReportDeliveryStatus = "filed" | "routed_only" | "skipped" | "failed" | "consent_required";
@@ -81,6 +113,15 @@ export type GapReportReceipt = {
81
113
  * Count of handlers that routed only.
82
114
  */
83
115
  routedOnlyCount: number;
116
+ /**
117
+ * For a run without `to`,
118
+ * when a destination besides the default exists: every destination.
119
+ */
120
+ destinations?: GapReportDestination[] | undefined;
121
+ /**
122
+ * With `destinations`: ask the person where to file.
123
+ */
124
+ ask?: string | undefined;
84
125
  };
85
126
  export type GapReportReceiptResponse = {
86
127
  type: "gap-report.file";