@theholocron/cli 5.0.0-alpha.552 → 5.0.0-alpha.554

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
@@ -717,7 +717,7 @@ commands and the config are provider-neutral; Discord is the first provider.
717
717
  | `holocron doctor wiki` | Does the wiki the config declares exist, and does it match the sources? Rows: `organization is set` (`fern/fern.config.json` against the declared `fernOrg`), `docs site is declared` (the `instances:` url and `custom-domain` of `fern/docs.yml`), `docs site answers` and `custom domain answers` (one unauthenticated GET each: a 404 or 5xx fails, a 401/403 passes as restricted, no answer is a skip), `navigation pages exist` (every `path:` of the navigation is on disk), an `info` row for pages under `docs/wiki` the navigation leaves out, and `published pages` (the site's sitemap lists at least as many pages as the navigation; fewer fails and names the wiki workflow). Reads through the optional `Wiki.inspect()`; never publishes, writes or sends a token. A provider that cannot inspect, or a site that cannot be reached, is a skip. Read-only |
718
718
  | `holocron doctor errors` | Does the error tracker have the organization, projects, keys and alert rules the config relies on? Rows: `organization exists`, and for each project a notifications layout's `relay.errors.projects` declares, `project <slug> exists` (a 404 fails), `project <slug> has a key` (a client key, so an SDK has a DSN; none fails) and `project <slug> has an alert rule` (at least one enabled rule watches its issues; none fails). The Comlink relay's integration and rule stay in `doctor notifications`. Reads through the optional `Errors.inspect()` and returns counts only, never a DSN or key. A missing token or `org`, or alert rules the token cannot read, is a skip. Read-only |
719
719
  | `holocron doctor workers` | Do the Workers and deployment projects the config declares exist, route and deploy healthily? Declared Workers are the relay Worker of a notifications layout that feeds an error tracker and the reverse proxy of a wiki with a custom domain. Rows per Worker: `<name> Worker is deployed and routed` (the script exists with a route for its host), `has its bindings` (by name, a value is never read) and `latest deployment is healthy` (the newest deployment serves all traffic). Rows per deployment project (the preview project, else one named like the repo): `<project> project exists`, `has its custom domain` (when one is declared) and `latest deployment is healthy` (the newest production deployment is ready; one that errored fails, one still building is information). Reads through the optional `Workers.inspectScript` / `latestDeployment` / `proxyScriptName` and `Deployment.listProjects` / `listDomains` / `latestDeployment`; never deploys or prints a token. A missing token, a 401 or 403, or a provider that cannot read it is a skip. Read-only |
720
- | `holocron doctor environments` | Do the deployment environments exist? The ones `setup` creates (`staging`, `production`, when an `environments` provider is configured) plus every environment `repo.secrets.environments` names. One row. A missing one fails; an extra one is never a problem; no provider with some named is a skip |
720
+ | `holocron doctor environments` | Do the deployment environments exist? The ones `repo.environments` declares (their reviewers, wait timer and self-review rule are compared too) plus every environment `repo.secrets.environments` names; none declared is an ok. One row. A missing one fails; an extra one is never a problem; no provider with some expected is a skip |
721
721
  | `holocron doctor project [--post [channel]]` | Does each board `providers.projects.boards` declares exist and match its template? One row per board, status list, field, view and automation rule; the board's extras and the items `reconcile project` would fix (no status, closed but not done, open blocker but not blocked, blocked without a blocker) are `info` rows, never a failure. A template file that does not read fails, naming the file. Read-only; `--post` shares the failing rows through the `notifications` bot. |
722
722
  | `holocron doctor repo` | Do the repository settings `setup` writes match the config? One row per group the config declares: description and homepage, default branch and merge settings, topics, custom properties, team access, branch protection (and, for `strict`, a `repo-ci-pin` row comparing the App `ci / Required checks` is pinned to with the opt-in `ci.pin`; skipped, saying the option is off, when unset); labels and security settings are always checked, plus a `repo-area-labels` row when `repo.labels.areas` is declared (a declared area with no `area:<name>` label fails; an undeclared `area:` label is an `info` note). Read-only. Reads through optional `Source` methods (`getRepoInfo`, `getProperties`, `listLabels`, `listTeamAccess`, `getRulesetDetail`, `getSecurity`); a group that cannot be read is a skip, not a failure |
723
723
  | `holocron doctor dns` | Do the DNS records the config makes setup write exist, pointing where they should? The preview domain's apex and wildcard CNAMEs (Cloudflare), the docs site a wiki provider asks for, and the relay Worker's proxied placeholder; one row per zone. A missing record, another target or a missing proxy fails; an extra record never does. A record `ensureCustomDomain()` returns is not checked, because asking for it creates the domain |
package/dist/cli.mjs CHANGED
@@ -2916,8 +2916,8 @@ const COMMIT_TYPES = [
2916
2916
  "style",
2917
2917
  "revert"
2918
2918
  ];
2919
- const isObject$3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2920
- const KEYS$1 = [
2919
+ const isObject$4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2920
+ const KEYS$2 = [
2921
2921
  "name",
2922
2922
  "description",
2923
2923
  "color",
@@ -2936,8 +2936,8 @@ function validateIssueTypes(value, at = "issueTypes") {
2936
2936
  const seen = /* @__PURE__ */ new Set();
2937
2937
  return value.map((entry, index) => {
2938
2938
  const where = `${at}[${index}]`;
2939
- if (!isObject$3(entry)) throw new ConfigError$1(`${where} must be an object with a "name"`);
2940
- for (const key of Object.keys(entry)) if (!KEYS$1.includes(key)) throw new ConfigError$1(`${where}: "${key}" is not an issue Type option. Known: ${KEYS$1.join(", ")}`);
2939
+ if (!isObject$4(entry)) throw new ConfigError$1(`${where} must be an object with a "name"`);
2940
+ for (const key of Object.keys(entry)) if (!KEYS$2.includes(key)) throw new ConfigError$1(`${where}: "${key}" is not an issue Type option. Known: ${KEYS$2.join(", ")}`);
2941
2941
  const { name, description, color, enabled, label, commit } = entry;
2942
2942
  if (typeof name !== "string" || name.trim() === "") throw new ConfigError$1(`${where}: "name" must be a non-empty string`);
2943
2943
  const key = name.trim().toLowerCase();
@@ -2957,6 +2957,66 @@ function validateIssueTypes(value, at = "issueTypes") {
2957
2957
  };
2958
2958
  });
2959
2959
  }
2960
+ /** GitHub's longest wait timer: 30 days, in minutes. */
2961
+ const MAX_WAIT_TIMER = 43200;
2962
+ const KEYS$1 = /* @__PURE__ */ new Set([
2963
+ "name",
2964
+ "reviewers",
2965
+ "waitTimer",
2966
+ "preventSelfReview"
2967
+ ]);
2968
+ const REVIEWER_KEYS = /* @__PURE__ */ new Set(["type", "id"]);
2969
+ const isObject$3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2970
+ /** Checks one reviewer of the Environment spelled `named`, and records it in `seen` so none is listed twice. */
2971
+ function validateReviewer(raw, named, seen) {
2972
+ if (!isObject$3(raw)) throw new ConfigError$1(`${named}: a reviewer must be an object`);
2973
+ const extra = Object.keys(raw).find((key) => !REVIEWER_KEYS.has(key));
2974
+ if (extra !== void 0) throw new ConfigError$1(`${named}: a reviewer has no \`${extra}\` (a numeric \`id\`, not a login)`);
2975
+ const { type, id } = raw;
2976
+ if (type !== "User" && type !== "Team") throw new ConfigError$1(`${named}: a reviewer's \`type\` is "User" or "Team"`);
2977
+ if (typeof id !== "number" || !Number.isInteger(id) || id <= 0) throw new ConfigError$1(`${named}: a reviewer's \`id\` is GitHub's numeric id, a positive whole number`);
2978
+ const key = `${type}:${id}`;
2979
+ if (seen.has(key)) throw new ConfigError$1(`${named}: reviewer ${key} is listed twice`);
2980
+ seen.add(key);
2981
+ }
2982
+ /** Checks one entry of `repo.environments`, which is at position `index` and whose name is not yet in `seen`. */
2983
+ function validateEntry(raw, index, seen) {
2984
+ const at = `\`repo.environments[${index}]\``;
2985
+ if (!isObject$3(raw)) throw new ConfigError$1(`${at} must be an object`);
2986
+ const unknown = Object.keys(raw).find((key) => !KEYS$1.has(key));
2987
+ if (unknown !== void 0) throw new ConfigError$1(`${at} has no \`${unknown}\` (use ${[...KEYS$1].map((k) => `\`${k}\``).join(", ")})`);
2988
+ const { name, waitTimer, preventSelfReview, reviewers } = raw;
2989
+ if (typeof name !== "string" || name.trim() === "") throw new ConfigError$1(`${at} needs a \`name\``);
2990
+ const lower = name.toLowerCase();
2991
+ if (seen.has(lower)) throw new ConfigError$1(`${at}: ${JSON.stringify(name)} is declared twice (names ignore case)`);
2992
+ seen.add(lower);
2993
+ const named = `\`repo.environments[${name}]\``;
2994
+ if (waitTimer !== void 0) {
2995
+ if (typeof waitTimer !== "number" || !Number.isInteger(waitTimer) || waitTimer < 0 || waitTimer > 43200) throw new ConfigError$1(`${named}: \`waitTimer\` is a whole number of minutes from 0 to ${MAX_WAIT_TIMER}`);
2996
+ }
2997
+ if (preventSelfReview !== void 0 && typeof preventSelfReview !== "boolean") throw new ConfigError$1(`${named}: \`preventSelfReview\` is true or false`);
2998
+ if (reviewers === void 0) return;
2999
+ if (!Array.isArray(reviewers)) throw new ConfigError$1(`${named}: \`reviewers\` must be a list`);
3000
+ const list = reviewers;
3001
+ if (list.length > 6) throw new ConfigError$1(`${named}: GitHub allows at most 6 reviewers, got ${list.length}`);
3002
+ const seenReviewers = /* @__PURE__ */ new Set();
3003
+ for (const reviewer of list) validateReviewer(reviewer, named, seenReviewers);
3004
+ }
3005
+ /**
3006
+ * Check `repo.environments` (#2674): each entry names an Environment once (names ignore case) and uses only the keys of
3007
+ * `RepoEnvironment`; a reviewer is a `User` or a `Team` with a positive whole `id` (a login would be ignored by GitHub),
3008
+ * at most six and none twice; `waitTimer` is a whole number of minutes from 0 to 43200; `preventSelfReview` is a boolean.
3009
+ *
3010
+ * @param environments - `repo.environments`, if the config has it.
3011
+ * @throws {ConfigError} Naming the path of the first problem found.
3012
+ */
3013
+ function validateRepoEnvironments(environments) {
3014
+ if (environments === void 0) return;
3015
+ const list = environments;
3016
+ if (!Array.isArray(list)) throw new ConfigError$1("`repo.environments` must be a list");
3017
+ const seen = /* @__PURE__ */ new Set();
3018
+ list.forEach((entry, index) => validateEntry(entry, index, seen));
3019
+ }
2960
3020
  // src/config/validate-repo-labels/validate-repo-labels.ts
2961
3021
  /** What an area name may be: the rest of `area:<name>`, so no colon, comma, space or leading symbol. */
2962
3022
  const AREA_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
@@ -3337,6 +3397,7 @@ function resolveConfig(raw) {
3337
3397
  if (raw.ideas !== void 0) validateIdeas(raw.ideas);
3338
3398
  if (raw.issueTypes !== void 0) validateIssueTypes(raw.issueTypes);
3339
3399
  validateRepoLabels(raw.repo?.labels);
3400
+ validateRepoEnvironments(raw.repo?.environments);
3340
3401
  validateRequiredChecks(raw.repo?.requiredChecks);
3341
3402
  validateVariablesSync(raw.repo?.variables);
3342
3403
  validateSecretsDeploy(raw.repo?.secrets);
@@ -12793,9 +12854,56 @@ const doctorDnsCommand = {
12793
12854
  })).status === "fail") process.exitCode = 1;
12794
12855
  }
12795
12856
  };
12796
- // src/commands/setup/setup-environments.ts
12797
- /** The deployment environments `holocron setup` creates when an `environments` provider is configured. */
12798
- const SETUP_ENVIRONMENTS = ["staging", "production"];
12857
+ // src/commands/setup/declared-environments/declared-environments.ts
12858
+ /**
12859
+ * The Environments `setup` makes and `doctor environments` expects: the ones `repo.environments` declares, and no
12860
+ * others (#2674). Each carries only the settings that were written, so a setting left out is never changed. `setup` used to
12861
+ * make a fixed pair, `staging` and `production`, in every repository whether or not a job used them; it makes only what a
12862
+ * repository declares now, and never deletes one that exists.
12863
+ *
12864
+ * @param declared - `repo.environments`, if the config has it.
12865
+ */
12866
+ function declaredEnvironments(declared) {
12867
+ return (declared ?? []).map((entry) => ({
12868
+ name: entry.name,
12869
+ ...entry.reviewers !== void 0 ? { reviewers: entry.reviewers.map(({ type, id }) => ({
12870
+ type,
12871
+ id
12872
+ })) } : {},
12873
+ ...entry.waitTimer !== void 0 ? { waitTimer: entry.waitTimer } : {},
12874
+ ...entry.preventSelfReview !== void 0 ? { preventSelfReview: entry.preventSelfReview } : {}
12875
+ }));
12876
+ }
12877
+ // src/commands/doctor-environments/environment-problems/environment-problems.ts
12878
+ const spell = (reviewer) => `${reviewer.type}:${reviewer.id}`;
12879
+ /**
12880
+ * Where the Environments that exist differ from the ones `repo.environments` declares (#2674): a reviewer missing or
12881
+ * extra, a different wait timer, a different self-review rule. Only a setting the declaration writes is compared, so one
12882
+ * left out is never a problem, and an Environment that is missing altogether is the existence check's to report.
12883
+ *
12884
+ * @param declared - `repo.environments`.
12885
+ * @param have - What the provider lists.
12886
+ * @returns One line per difference, naming the Environment; empty when everything declared holds.
12887
+ */
12888
+ function environmentProblems(declared, have) {
12889
+ const byName = new Map(have.map((env) => [env.name.toLowerCase(), env]));
12890
+ const problems = [];
12891
+ for (const want of declared) {
12892
+ const actual = byName.get(want.name.toLowerCase());
12893
+ if (!actual) continue;
12894
+ if (want.reviewers !== void 0) {
12895
+ const wanted = new Set(want.reviewers.map(spell));
12896
+ const found = new Set((actual.reviewers ?? []).map(spell));
12897
+ const missing = [...wanted].filter((key) => !found.has(key));
12898
+ const extra = [...found].filter((key) => !wanted.has(key));
12899
+ if (missing.length > 0) problems.push(`${want.name}: required reviewers lack ${missing.join(", ")}`);
12900
+ if (extra.length > 0) problems.push(`${want.name}: required reviewers have ${extra.join(", ")}, which the config does not declare`);
12901
+ }
12902
+ if (want.waitTimer !== void 0 && (actual.waitTimer ?? 0) !== want.waitTimer) problems.push(`${want.name}: wait timer is ${actual.waitTimer ?? 0} minutes, the config says ${want.waitTimer}`);
12903
+ if (want.preventSelfReview !== void 0 && (actual.preventSelfReview ?? false) !== want.preventSelfReview) problems.push(`${want.name}: prevent self-review is ${actual.preventSelfReview ?? false}, the config says ${want.preventSelfReview}`);
12904
+ }
12905
+ return problems;
12906
+ }
12799
12907
  // src/commands/doctor-environments/doctor-environments.ts
12800
12908
  /**
12801
12909
  * `holocron doctor environments` — do the deployment environments the config relies on exist?
@@ -12813,7 +12921,7 @@ async function runDoctorEnvironments(input) {
12813
12921
  const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
12814
12922
  await loader.load();
12815
12923
  assertPluginsResolvable(loader, "doctor environments");
12816
- const row = await checkEnvironments(loader, Object.keys(input.loaded.resolved.repo?.secrets?.environments ?? {}));
12924
+ const row = await checkEnvironments(loader, Object.keys(input.loaded.resolved.repo?.secrets?.environments ?? {}), input.loaded.resolved.repo?.environments ?? []);
12817
12925
  printCheckRows([row], print);
12818
12926
  const summary = summariseChecks([row]);
12819
12927
  printCheckSummary(summary, print);
@@ -12828,7 +12936,7 @@ async function runDoctorEnvironments(input) {
12828
12936
  ...row.status === "skip" ? { reason: row.detail } : {}
12829
12937
  };
12830
12938
  }
12831
- async function checkEnvironments(loader, named) {
12939
+ async function checkEnvironments(loader, named, declared) {
12832
12940
  const make = (status, detail, problems = []) => ({
12833
12941
  id: ID$6,
12834
12942
  title: TITLE$6,
@@ -12836,14 +12944,15 @@ async function checkEnvironments(loader, named) {
12836
12944
  detail,
12837
12945
  problems
12838
12946
  });
12839
- if (!loader.has("environments")) return named.length === 0 ? make("ok", "none declared") : make("skip", whyMissing(loader, "environments", "no `environments` provider to check them with"));
12840
- const names = [...new Set([...SETUP_ENVIRONMENTS, ...named].map((n) => n.toLowerCase()))];
12947
+ const names = [...new Set([...declaredEnvironments(declared).map((env) => env.name), ...named].map((n) => n.toLowerCase()))];
12948
+ if (names.length === 0) return make("ok", "none declared");
12949
+ if (!loader.has("environments")) return make("skip", whyMissing(loader, "environments", "no `environments` provider to check them with"));
12841
12950
  try {
12842
12951
  const have = await loader.get("environments").listEnvironments();
12843
- const problems = declaredVsActual(new Map(names.map((name) => [name, true])), new Map(have.map((env) => [env.name.toLowerCase(), true])), {
12952
+ const problems = [...declaredVsActual(new Map(names.map((name) => [name, true])), new Map(have.map((env) => [env.name.toLowerCase(), true])), {
12844
12953
  noun: "environment",
12845
12954
  flagExtra: false
12846
- });
12955
+ }), ...environmentProblems(declared, have)];
12847
12956
  return problems.length > 0 ? make("fail", `${problems.length} problem(s)`, problems) : make("ok", `${names.length} of ${names.length} exist`);
12848
12957
  } catch (err) {
12849
12958
  const noToken = missingTokenReason(err);
@@ -24423,9 +24532,9 @@ async function runSetup(input) {
24423
24532
  if (loader.has("environments")) {
24424
24533
  const envs = loader.get("environments");
24425
24534
  print(style.step("environments"));
24426
- for (const envName of SETUP_ENVIRONMENTS) {
24427
- steps.push(await runStep("environments", `upsert ${envName}`, dryRun, async () => {
24428
- await envs.upsertEnvironment({ name: envName });
24535
+ for (const environment of declaredEnvironments(config.repo?.environments)) {
24536
+ steps.push(await runStep("environments", `upsert ${environment.name}`, dryRun, async () => {
24537
+ await envs.upsertEnvironment(environment);
24429
24538
  }));
24430
24539
  print(formatStep(steps[steps.length - 1]));
24431
24540
  }