@theholocron/cli 5.0.0-alpha.272 → 5.0.0-alpha.274
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 +3 -1
- package/dist/cli.mjs +443 -95
- package/dist/cli.mjs.map +1 -1
- package/dist/{index-DSzAZQdK.d.mts → index-CmNllp81.d.mts} +1 -1
- package/dist/{index-CwxYoWzS.d.mts → index-EayNimLh.d.mts} +6 -0
- package/dist/index.d.mts +2 -2
- package/dist/plugin/capabilities.d.mts +1 -1
- package/dist/presets.d.mts +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -550,6 +550,8 @@ commands and the config are provider-neutral; Discord is the first provider.
|
|
|
550
550
|
| `holocron doctor notifications [--built-only] [--deliver]` | Step by step: does the server match the layout, do the secrets exist, and does a person (not the bot) own it. A full run also leaves one `🧪 test:` post in the layout's `testChannel`; `--built-only` posts nothing; `--deliver` posts to every channel and removes each post |
|
|
551
551
|
| `holocron doctor variables` | Do the Actions variables `repo.variables` declares exist, with those values (and, for the organization's, that visibility)? One row for the repository and one for the organization, each only when declared. Read-only. An undeclared variable counts only with `prune`; a scope that cannot be read (no provider, no org token) is a skip, not a failure |
|
|
552
552
|
| `holocron doctor environments` | Do the deployment environments exist? The ones `repo 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 |
|
|
553
|
+
| `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 host 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 |
|
|
554
|
+
| `holocron doctor monitoring` | Do the checks the `monitoring` provider declares exist in its account, matched by name, with the URL, method and (when stated) frequency, locations, activated, should-fail, body and assertions the config sets? One row. A check in the account that is not declared is never a problem. A provider that cannot list its checks, failed to load or has no token is a skip |
|
|
553
555
|
| `holocron doctor secrets` | Do the secrets the config says must exist (`repo.secrets`, plus the notification layout's webhook and role secrets and the Chromatic token) exist? One row for the repository, the organization and each environment, each only when something is expected there. Names only; an undeclared secret is never a problem. A scope that cannot be read is a skip |
|
|
554
556
|
| `holocron doctor tokens` | For every token a configured plugin lists (every plugin that resolves one: GitHub's nine, Discord's three, Sentry's two, ...), looked up as the plugin does (its env var, the vendor's, then keyring) and verified with its `verifyToken`: set and accepted is ok (with how long is left, when the token expires), set and rejected fails, a token with 7 days or fewer left fails with `expires in N days: renew it`, not set is a skip. No token is printed. What a token may do is not checked, because GitHub does not return a fine-grained token's permissions |
|
|
555
557
|
| `holocron doctor --all` | Runs every deep check (`doctor notifications`, `doctor variables`, ...) and prints one row each, then `N ok, N fail, N skipped` counted in checks. Exits 1 when any check failed. A check that cannot run (no provider, no token) is a skip with the reason. Read-only: notifications runs as `--built-only`, so it posts nothing |
|
|
@@ -774,7 +776,7 @@ the local override exists to exempt.
|
|
|
774
776
|
`package bump-versions`, `sync github`, `repo upgrade node`,
|
|
775
777
|
`repo upgrade deps`, `new plugin`, `auth`, `notifications setup`,
|
|
776
778
|
`notifications channel add`, `notifications link`,
|
|
777
|
-
`notifications sync-roles`, `doctor environments`, `doctor notifications`, `doctor secrets`, `doctor tokens`, `doctor variables`
|
|
779
|
+
`notifications sync-roles`, `doctor dns`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor secrets`, `doctor tokens`, `doctor variables`
|
|
778
780
|
- `src/commands/doctor-checks/` and `src/commands/deep-checks/` — the shared row
|
|
779
781
|
renderer and `declaredVsActual` helper, and `DEEP_CHECKS`, the registry every
|
|
780
782
|
`doctor <capability>` is listed in
|
package/dist/cli.mjs
CHANGED
|
@@ -221,8 +221,10 @@ const COMMAND_CONTEXTS = {
|
|
|
221
221
|
"doctor all": "workspace",
|
|
222
222
|
"doctor notifications": "workspace",
|
|
223
223
|
"doctor environments": "workspace",
|
|
224
|
+
"doctor dns": "workspace",
|
|
224
225
|
"doctor secrets": "workspace",
|
|
225
226
|
"doctor tokens": "workspace",
|
|
227
|
+
"doctor monitoring": "workspace",
|
|
226
228
|
"doctor variables": "workspace",
|
|
227
229
|
probe: "workspace",
|
|
228
230
|
deploy: "workspace",
|
|
@@ -1422,6 +1424,13 @@ const doctorAllEntry = {
|
|
|
1422
1424
|
supportsDryRun: false,
|
|
1423
1425
|
spawnArgs: ["doctor", "--all"]
|
|
1424
1426
|
};
|
|
1427
|
+
// src/commands/doctor-dns/doctor-dns.entry.ts
|
|
1428
|
+
const doctorDnsEntry = {
|
|
1429
|
+
name: "doctor dns",
|
|
1430
|
+
description: "Check that the DNS records the config makes setup write exist and point where they should (read-only)",
|
|
1431
|
+
positionals: [],
|
|
1432
|
+
supportsDryRun: false
|
|
1433
|
+
};
|
|
1425
1434
|
// src/commands/doctor-environments/doctor-environments.entry.ts
|
|
1426
1435
|
const doctorEnvironmentsEntry = {
|
|
1427
1436
|
name: "doctor environments",
|
|
@@ -1429,6 +1438,13 @@ const doctorEnvironmentsEntry = {
|
|
|
1429
1438
|
positionals: [],
|
|
1430
1439
|
supportsDryRun: false
|
|
1431
1440
|
};
|
|
1441
|
+
// src/commands/doctor-monitoring/doctor-monitoring.entry.ts
|
|
1442
|
+
const doctorMonitoringEntry = {
|
|
1443
|
+
name: "doctor monitoring",
|
|
1444
|
+
description: "Check the monitoring checks the config declares against the ones the provider holds (read-only)",
|
|
1445
|
+
positionals: [],
|
|
1446
|
+
supportsDryRun: false
|
|
1447
|
+
};
|
|
1432
1448
|
// src/commands/doctor-notifications/doctor-notifications.entry.ts
|
|
1433
1449
|
const doctorNotificationsEntry = {
|
|
1434
1450
|
name: "doctor notifications",
|
|
@@ -1667,8 +1683,10 @@ const COMMAND_REGISTRY = [
|
|
|
1667
1683
|
supportsDryRun: true
|
|
1668
1684
|
},
|
|
1669
1685
|
notificationsChannelAddEntry,
|
|
1686
|
+
doctorMonitoringEntry,
|
|
1670
1687
|
doctorNotificationsEntry,
|
|
1671
1688
|
doctorEnvironmentsEntry,
|
|
1689
|
+
doctorDnsEntry,
|
|
1672
1690
|
doctorSecretsEntry,
|
|
1673
1691
|
doctorTokensEntry,
|
|
1674
1692
|
doctorVariablesEntry,
|
|
@@ -4428,6 +4446,246 @@ function layoutSecretNames(layout) {
|
|
|
4428
4446
|
const fromRoles = (layout.roles ?? []).flatMap((role) => role.secret ? [role.secret] : []);
|
|
4429
4447
|
return [...fromChannels, ...fromRoles];
|
|
4430
4448
|
}
|
|
4449
|
+
// src/commands/notifications-setup/avatar-problem.ts
|
|
4450
|
+
/** The first reason a feed's `avatar` cannot work, or undefined. `feed` names the key for the message (`monitoring`, `errors`). */
|
|
4451
|
+
function avatarProblem(channel, feed, picture) {
|
|
4452
|
+
if (typeof picture !== "object") return void 0;
|
|
4453
|
+
if (!picture.url && !picture.image) return `channel \`${channel}\`: \`feeds.${feed}.avatar\` needs a \`url\`, an \`image\`, or both`;
|
|
4454
|
+
if (picture.url && !/^https:\/\//i.test(picture.url)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.url\` must be an https:// URL`;
|
|
4455
|
+
if (picture.image && /^https?:\/\//i.test(picture.image)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.image\` must be a file in the repo, not a URL`;
|
|
4456
|
+
}
|
|
4457
|
+
/** The webhook name a channel's error feed uses: its own, else the provider's name, capitalised (`Sentry`). */
|
|
4458
|
+
function errorsFeedWebhook(feed, errors) {
|
|
4459
|
+
return (typeof feed === "object" ? feed.webhook : void 0) ?? capitalised(errors.providerName);
|
|
4460
|
+
}
|
|
4461
|
+
const capitalised = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
4462
|
+
/** The Worker binding that holds the webhook URL for a source (the contract `apps/comlink` reads). */
|
|
4463
|
+
const relayWebhookBinding = (source) => `COMLINK_${source.toUpperCase()}_WEBHOOK`;
|
|
4464
|
+
/** The Worker binding that holds a source's signing secret (the contract `apps/comlink` reads). */
|
|
4465
|
+
const relaySecretBinding = (source) => `COMLINK_${source.toUpperCase()}_SECRET`;
|
|
4466
|
+
/** Whether any channel in the layout is fed by the error tracker. */
|
|
4467
|
+
function wantsRelay(layout) {
|
|
4468
|
+
return (layout.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.feeds?.errors));
|
|
4469
|
+
}
|
|
4470
|
+
/**
|
|
4471
|
+
* The first reason the relay cannot be deployed, or undefined. One source has one webhook, so only one channel can be
|
|
4472
|
+
* fed by it; and the Worker needs somewhere to answer.
|
|
4473
|
+
*/
|
|
4474
|
+
function relayProblem(layout, errors, monitoring) {
|
|
4475
|
+
const fed = (layout.categories ?? []).flatMap((c) => c.channels ?? []).filter((ch) => ch.feeds?.errors);
|
|
4476
|
+
if (fed.length === 0) return void 0;
|
|
4477
|
+
if (!layout.relay?.host) return `channel \`${fed[0].name}\` is fed by the error tracker, which needs \`relay.host\` — where the relay Worker answers`;
|
|
4478
|
+
if (fed.length > 1) return `channels ${fed.map((c) => `\`${c.name}\``).join(" and ")} are all fed by the error tracker, but its relay posts to one channel — feed one`;
|
|
4479
|
+
const channel = fed[0];
|
|
4480
|
+
const errorsFeed = channel.feeds.errors;
|
|
4481
|
+
const picture = typeof errorsFeed === "object" ? errorsFeed.avatar : void 0;
|
|
4482
|
+
const pictureProblem = avatarProblem(channel.name, "errors", picture);
|
|
4483
|
+
if (pictureProblem) return pictureProblem;
|
|
4484
|
+
if (errors) {
|
|
4485
|
+
const feed = errorsFeedWebhook(errorsFeed, errors).toLowerCase();
|
|
4486
|
+
const own = (typeof channel.webhook === "object" ? channel.webhook.name : void 0) ?? channel.name;
|
|
4487
|
+
if (channel.webhook && feed === own.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the channel's own webhook are both named ${own} — rename one`;
|
|
4488
|
+
const monitoringFeed = channel.feeds.monitoring;
|
|
4489
|
+
if (monitoring && monitoringFeed) {
|
|
4490
|
+
const other = (typeof monitoringFeed === "object" ? monitoringFeed.webhook : void 0) ?? capitalised(monitoring.providerName);
|
|
4491
|
+
if (feed === other.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the monitoring webhook are both named ${other} — rename one`;
|
|
4492
|
+
}
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
/**
|
|
4496
|
+
* What to hand the `dns` capability as the zone: the layout's, else the host itself. The provider looks a name up from
|
|
4497
|
+
* the full name towards the apex until it finds a zone it holds, so this is right for any suffix (`example.co.uk`).
|
|
4498
|
+
*/
|
|
4499
|
+
const relayZone = (relay) => relay.zone ?? relay.host;
|
|
4500
|
+
/**
|
|
4501
|
+
* Deploy the Worker with its webhook secret and its route, then point the host at it with a proxied placeholder record
|
|
4502
|
+
* (the Worker answers before any origin is asked). The built file is read first and the DNS record comes last, so a
|
|
4503
|
+
* missing build or a failed deploy leaves the host untouched.
|
|
4504
|
+
*/
|
|
4505
|
+
async function deployRelay(input) {
|
|
4506
|
+
const { relay, workers, dns } = input;
|
|
4507
|
+
const path = join(input.repoRoot, relay.code ?? "apps/comlink/dist/worker.js");
|
|
4508
|
+
let code;
|
|
4509
|
+
try {
|
|
4510
|
+
code = await (input.readCode ?? ((p) => readFile(p, "utf8")))(path);
|
|
4511
|
+
} catch {
|
|
4512
|
+
throw new Error(`the relay Worker is not built (${relay.code ?? "apps/comlink/dist/worker.js"}) — run \`pnpm --filter @theholocron/comlink run delivery.build\``);
|
|
4513
|
+
}
|
|
4514
|
+
const script = relay.script ?? "comlink";
|
|
4515
|
+
await workers.deployScript(script, {
|
|
4516
|
+
code,
|
|
4517
|
+
secrets: {
|
|
4518
|
+
[relayWebhookBinding(input.source)]: input.webhook,
|
|
4519
|
+
...input.signingSecret ? { [relaySecretBinding(input.source)]: input.signingSecret } : {}
|
|
4520
|
+
},
|
|
4521
|
+
routes: [`${relay.host}/*`]
|
|
4522
|
+
});
|
|
4523
|
+
await dns.upsertRecord(relayZone(relay), {
|
|
4524
|
+
type: "AAAA",
|
|
4525
|
+
name: relay.host,
|
|
4526
|
+
content: "100::",
|
|
4527
|
+
ttl: 1,
|
|
4528
|
+
proxied: true
|
|
4529
|
+
});
|
|
4530
|
+
return {
|
|
4531
|
+
host: relay.host,
|
|
4532
|
+
script
|
|
4533
|
+
};
|
|
4534
|
+
}
|
|
4535
|
+
// src/commands/setup/preview-config-of.ts
|
|
4536
|
+
/**
|
|
4537
|
+
* The preview configuration (the Pages project and the preview domain) that drives project and DNS provisioning.
|
|
4538
|
+
* `delivery.deploy`, `knowledge.docs` and `knowledge.components` all share the same combined production and preview
|
|
4539
|
+
* mechanism, so any one of them can carry it. `null` when none does.
|
|
4540
|
+
*/
|
|
4541
|
+
function previewConfigOf(config) {
|
|
4542
|
+
const entry = (config.tasks ?? []).map((e) => typeof e === "string" ? { name: e } : e).find((e) => e.name === "delivery.deploy" || e.name === "knowledge.docs" || e.name === "knowledge.components");
|
|
4543
|
+
return entry?.with ? extractPreviewConfig(entry.with, {
|
|
4544
|
+
org: config.org,
|
|
4545
|
+
domain: config.domain
|
|
4546
|
+
}) : null;
|
|
4547
|
+
}
|
|
4548
|
+
// src/commands/doctor-dns/expected-dns-records.ts
|
|
4549
|
+
/**
|
|
4550
|
+
* The DNS records the config makes `holocron repo setup` and `notifications setup` write, as far as they can be
|
|
4551
|
+
* known without writing anything: the preview domain's apex and wildcard CNAMEs (on a Cloudflare deployment), the
|
|
4552
|
+
* docs host a wiki provider asks for, and the relay Worker's proxied placeholder. A record that
|
|
4553
|
+
* `Deployment.ensureCustomDomain()` returns is left out, since asking for it creates the domain.
|
|
4554
|
+
*/
|
|
4555
|
+
function expectedDnsRecords(config, sources) {
|
|
4556
|
+
const expected = [];
|
|
4557
|
+
const preview = previewConfigOf(config);
|
|
4558
|
+
if (preview?.domain && sources.deployment?.providerName === "cloudflare") {
|
|
4559
|
+
const content = `${preview.project}.pages.dev`;
|
|
4560
|
+
for (const name of [preview.domain, `*.${preview.domain}`]) expected.push({
|
|
4561
|
+
zone: preview.domain,
|
|
4562
|
+
record: {
|
|
4563
|
+
type: "CNAME",
|
|
4564
|
+
name,
|
|
4565
|
+
content
|
|
4566
|
+
}
|
|
4567
|
+
});
|
|
4568
|
+
}
|
|
4569
|
+
const docs = sources.wiki?.dnsRecord?.();
|
|
4570
|
+
if (docs) {
|
|
4571
|
+
const { type, name, content } = docs.record;
|
|
4572
|
+
expected.push({
|
|
4573
|
+
zone: docs.zone,
|
|
4574
|
+
record: {
|
|
4575
|
+
type,
|
|
4576
|
+
name,
|
|
4577
|
+
content,
|
|
4578
|
+
...sources.wiki?.proxyConfig?.() ? { proxied: true } : {}
|
|
4579
|
+
}
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4582
|
+
for (const { relay } of sources.layouts) if (relay) expected.push({
|
|
4583
|
+
zone: relayZone(relay),
|
|
4584
|
+
record: {
|
|
4585
|
+
type: "AAAA",
|
|
4586
|
+
name: relay.host,
|
|
4587
|
+
content: "100::",
|
|
4588
|
+
proxied: true
|
|
4589
|
+
}
|
|
4590
|
+
});
|
|
4591
|
+
return expected;
|
|
4592
|
+
}
|
|
4593
|
+
// src/commands/doctor-dns/doctor-dns.ts
|
|
4594
|
+
/**
|
|
4595
|
+
* `holocron doctor dns` — do the DNS records the config makes setup write exist, pointing where they should?
|
|
4596
|
+
*
|
|
4597
|
+
* Read-only. One row per zone, each record looked up by type and name (case-insensitively) in what the `dns`
|
|
4598
|
+
* provider lists for the zone. A record that is missing, points elsewhere, or is not proxied where it must be is a
|
|
4599
|
+
* problem; a record in the zone that is not expected never is. With no `dns` provider and records expected, the
|
|
4600
|
+
* rows are skips with the reason; a provider with no token for the read skips its zone.
|
|
4601
|
+
*/
|
|
4602
|
+
/** `CNAME *.example.com`: a record is its type and its name, however the provider spells the case or the final dot. */
|
|
4603
|
+
const keyOf = (record) => `${record.type} ${record.name.toLowerCase().replace(/\.$/, "")}`;
|
|
4604
|
+
const sameContent = (a, b) => a.toLowerCase().replace(/\.$/, "") === b.toLowerCase().replace(/\.$/, "");
|
|
4605
|
+
async function runDoctorDns(input) {
|
|
4606
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
4607
|
+
const logger = input.logger ?? getLogger();
|
|
4608
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
4609
|
+
await loader.load();
|
|
4610
|
+
assertPluginsResolvable(loader, "doctor dns");
|
|
4611
|
+
const expected = expectedDnsRecords(input.loaded.resolved, {
|
|
4612
|
+
...loader.has("deployment") ? { deployment: loader.get("deployment") } : {},
|
|
4613
|
+
...loader.has("wiki") ? { wiki: loader.get("wiki") } : {},
|
|
4614
|
+
layouts: (loader.has("notifications") ? loader.get("notifications") : []).flatMap((p) => p.layout ? [p.layout] : [])
|
|
4615
|
+
});
|
|
4616
|
+
const zones = [...new Set(expected.map((e) => e.zone))];
|
|
4617
|
+
const rows = [];
|
|
4618
|
+
if (zones.length === 0) rows.push({
|
|
4619
|
+
id: "dns",
|
|
4620
|
+
title: "dns",
|
|
4621
|
+
status: "ok",
|
|
4622
|
+
detail: "none declared",
|
|
4623
|
+
problems: []
|
|
4624
|
+
});
|
|
4625
|
+
else if (!loader.has("dns")) {
|
|
4626
|
+
const why = whyMissing(loader, "dns", "no `dns` provider to check them with");
|
|
4627
|
+
for (const zone of zones) rows.push(row$2(zone, "skip", why));
|
|
4628
|
+
} else {
|
|
4629
|
+
const dns = loader.get("dns");
|
|
4630
|
+
for (const zone of zones) rows.push(await checkZone(dns, zone, expected.filter((e) => e.zone === zone).map((e) => e.record)));
|
|
4631
|
+
}
|
|
4632
|
+
printCheckRows(rows, print);
|
|
4633
|
+
const summary = summariseChecks(rows);
|
|
4634
|
+
printCheckSummary(summary, print);
|
|
4635
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
4636
|
+
logger.info({
|
|
4637
|
+
...summary,
|
|
4638
|
+
status
|
|
4639
|
+
}, "doctor dns");
|
|
4640
|
+
return {
|
|
4641
|
+
status,
|
|
4642
|
+
rows,
|
|
4643
|
+
summary,
|
|
4644
|
+
...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
|
|
4645
|
+
};
|
|
4646
|
+
}
|
|
4647
|
+
function row$2(zone, status, detail, problems = []) {
|
|
4648
|
+
return {
|
|
4649
|
+
id: `dns-${zone}`,
|
|
4650
|
+
title: `${zone} records exist`,
|
|
4651
|
+
status,
|
|
4652
|
+
detail,
|
|
4653
|
+
problems
|
|
4654
|
+
};
|
|
4655
|
+
}
|
|
4656
|
+
async function checkZone(dns, zone, wanted) {
|
|
4657
|
+
try {
|
|
4658
|
+
const have = await dns.listRecords(zone);
|
|
4659
|
+
const problems = declaredVsActual(new Map(wanted.map((w) => [keyOf(w), w])), new Map(have.map((h) => [keyOf(h), h])), {
|
|
4660
|
+
noun: "record",
|
|
4661
|
+
flagExtra: false,
|
|
4662
|
+
equal: (want, found) => sameContent(want.content, found.content) && (want.proxied !== true || found.proxied === true),
|
|
4663
|
+
show: (r) => `${r.content}${r.proxied ? " (proxied)" : ""}`
|
|
4664
|
+
});
|
|
4665
|
+
return problems.length > 0 ? row$2(zone, "fail", `${problems.length} problem(s)`, problems) : row$2(zone, "ok", `${wanted.length} of ${wanted.length} exist`);
|
|
4666
|
+
} catch (err) {
|
|
4667
|
+
return err instanceof MissingTokenError ? row$2(zone, "skip", err.message) : row$2(zone, "fail", errorMessage(err));
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
// src/commands/doctor-dns/doctor-dns.command.ts
|
|
4671
|
+
const doctorDnsCommand = {
|
|
4672
|
+
command: "dns",
|
|
4673
|
+
describe: "Check that the DNS records the config makes setup write exist and point where they should (read-only)",
|
|
4674
|
+
handler: async (argv) => {
|
|
4675
|
+
const tokens = tokenContext(argv.token);
|
|
4676
|
+
if (!tokens) return;
|
|
4677
|
+
const loaded = await loadConfig(argv.cwd);
|
|
4678
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
4679
|
+
if ((await runDoctorDns({
|
|
4680
|
+
loaded,
|
|
4681
|
+
context: {
|
|
4682
|
+
repoRoot: argv.cwd,
|
|
4683
|
+
...tokens,
|
|
4684
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
4685
|
+
}
|
|
4686
|
+
})).status === "fail") process.exitCode = 1;
|
|
4687
|
+
}
|
|
4688
|
+
};
|
|
4431
4689
|
// src/commands/setup/setup-environments.ts
|
|
4432
4690
|
/** The deployment environments `holocron repo setup` creates when an `environments` provider is configured. */
|
|
4433
4691
|
const SETUP_ENVIRONMENTS = ["staging", "production"];
|
|
@@ -4440,8 +4698,8 @@ const SETUP_ENVIRONMENTS = ["staging", "production"];
|
|
|
4440
4698
|
* set on one that exists. An environment that exists but is not expected is never a problem. With no provider and
|
|
4441
4699
|
* nothing named, nothing is declared; with no provider but some named, the row is a skip with the reason.
|
|
4442
4700
|
*/
|
|
4443
|
-
const ID = "environments";
|
|
4444
|
-
const TITLE = "environments exist";
|
|
4701
|
+
const ID$1 = "environments";
|
|
4702
|
+
const TITLE$1 = "environments exist";
|
|
4445
4703
|
async function runDoctorEnvironments(input) {
|
|
4446
4704
|
const print = input.print ?? ((line) => console.log(line));
|
|
4447
4705
|
const logger = input.logger ?? getLogger();
|
|
@@ -4465,8 +4723,8 @@ async function runDoctorEnvironments(input) {
|
|
|
4465
4723
|
}
|
|
4466
4724
|
async function checkEnvironments(loader, named) {
|
|
4467
4725
|
const make = (status, detail, problems = []) => ({
|
|
4468
|
-
id: ID,
|
|
4469
|
-
title: TITLE,
|
|
4726
|
+
id: ID$1,
|
|
4727
|
+
title: TITLE$1,
|
|
4470
4728
|
status,
|
|
4471
4729
|
detail,
|
|
4472
4730
|
problems
|
|
@@ -4503,6 +4761,160 @@ const doctorEnvironmentsCommand = {
|
|
|
4503
4761
|
})).status === "fail") process.exitCode = 1;
|
|
4504
4762
|
}
|
|
4505
4763
|
};
|
|
4764
|
+
// src/commands/doctor-monitoring/doctor-monitoring.ts
|
|
4765
|
+
/**
|
|
4766
|
+
* `holocron doctor monitoring` — do the checks the `monitoring` provider declares exist in its account, as declared?
|
|
4767
|
+
*
|
|
4768
|
+
* Read-only. One row for the declared checks: each must exist by name, and what the config sets on it (URL, method,
|
|
4769
|
+
* frequency, locations, activated, should-fail, body, assertions) must be what the provider holds. A setting the
|
|
4770
|
+
* config leaves out is not compared, and a check in the account that is not declared is never a problem, since the
|
|
4771
|
+
* account may hold checks made by hand or by another tool. A provider that cannot list its checks, a missing
|
|
4772
|
+
* provider that failed to load, or a missing token is a skip with the reason, not a failure.
|
|
4773
|
+
*
|
|
4774
|
+
* Out of scope: the alert channel and its subscriptions (the notification layout declares those, see
|
|
4775
|
+
* `doctor notifications`) and any check that a message really arrives.
|
|
4776
|
+
*/
|
|
4777
|
+
const ID = "monitoring-checks";
|
|
4778
|
+
const TITLE = "monitoring checks match";
|
|
4779
|
+
async function runDoctorMonitoring(input) {
|
|
4780
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
4781
|
+
const logger = input.logger ?? getLogger();
|
|
4782
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
4783
|
+
await loader.load();
|
|
4784
|
+
assertPluginsResolvable(loader, "doctor monitoring");
|
|
4785
|
+
const rows = [await checkRow(loader)];
|
|
4786
|
+
printCheckRows(rows, print);
|
|
4787
|
+
const summary = summariseChecks(rows);
|
|
4788
|
+
printCheckSummary(summary, print);
|
|
4789
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
4790
|
+
logger.info({
|
|
4791
|
+
...summary,
|
|
4792
|
+
status
|
|
4793
|
+
}, "doctor monitoring");
|
|
4794
|
+
return {
|
|
4795
|
+
status,
|
|
4796
|
+
rows,
|
|
4797
|
+
summary,
|
|
4798
|
+
...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") } : {}
|
|
4799
|
+
};
|
|
4800
|
+
}
|
|
4801
|
+
async function checkRow(loader) {
|
|
4802
|
+
const skip = (detail) => ({
|
|
4803
|
+
id: ID,
|
|
4804
|
+
title: TITLE,
|
|
4805
|
+
status: "skip",
|
|
4806
|
+
detail,
|
|
4807
|
+
problems: []
|
|
4808
|
+
});
|
|
4809
|
+
if (!loader.has("monitoring")) {
|
|
4810
|
+
if (loader.loadFailures().some((f) => f.key === "monitoring")) return skip(whyMissing(loader, "monitoring", "no `monitoring` provider is available"));
|
|
4811
|
+
return {
|
|
4812
|
+
id: ID,
|
|
4813
|
+
title: TITLE,
|
|
4814
|
+
status: "ok",
|
|
4815
|
+
detail: "none declared",
|
|
4816
|
+
problems: []
|
|
4817
|
+
};
|
|
4818
|
+
}
|
|
4819
|
+
const monitoring = loader.get("monitoring");
|
|
4820
|
+
if (monitoring.checks.length === 0) return {
|
|
4821
|
+
id: ID,
|
|
4822
|
+
title: TITLE,
|
|
4823
|
+
status: "ok",
|
|
4824
|
+
detail: "none declared",
|
|
4825
|
+
problems: []
|
|
4826
|
+
};
|
|
4827
|
+
if (!monitoring.listChecks) return skip("provider does not implement listChecks");
|
|
4828
|
+
try {
|
|
4829
|
+
const problems = compareChecks(monitoring.checks, await monitoring.listChecks());
|
|
4830
|
+
if (problems.length > 0) return {
|
|
4831
|
+
id: ID,
|
|
4832
|
+
title: TITLE,
|
|
4833
|
+
status: "fail",
|
|
4834
|
+
detail: `${problems.length} problem(s)`,
|
|
4835
|
+
problems
|
|
4836
|
+
};
|
|
4837
|
+
const n = monitoring.checks.length;
|
|
4838
|
+
return {
|
|
4839
|
+
id: ID,
|
|
4840
|
+
title: TITLE,
|
|
4841
|
+
status: "ok",
|
|
4842
|
+
detail: `${n} of ${n} match`,
|
|
4843
|
+
problems: []
|
|
4844
|
+
};
|
|
4845
|
+
} catch (err) {
|
|
4846
|
+
if (err instanceof MissingTokenError) return skip(err.message);
|
|
4847
|
+
return {
|
|
4848
|
+
id: ID,
|
|
4849
|
+
title: TITLE,
|
|
4850
|
+
status: "fail",
|
|
4851
|
+
detail: errorMessage(err),
|
|
4852
|
+
problems: []
|
|
4853
|
+
};
|
|
4854
|
+
}
|
|
4855
|
+
}
|
|
4856
|
+
/** One assertion as a line: `status_code equals 405`, `header[x-a] contains b`. */
|
|
4857
|
+
function showAssertion(a) {
|
|
4858
|
+
return [
|
|
4859
|
+
a.property === void 0 ? a.source : `${a.source}[${a.property}]`,
|
|
4860
|
+
a.comparison,
|
|
4861
|
+
...a.target === void 0 ? [] : [a.target]
|
|
4862
|
+
].join(" ");
|
|
4863
|
+
}
|
|
4864
|
+
/** The settings of a check the config states, as comparable text; a setting it leaves out is not in the map. */
|
|
4865
|
+
function settings(check, declared) {
|
|
4866
|
+
const out = /* @__PURE__ */ new Map();
|
|
4867
|
+
const set = (key, value, present) => {
|
|
4868
|
+
if (present) out.set(key, value === void 0 ? "none" : String(value));
|
|
4869
|
+
};
|
|
4870
|
+
set("url", check.url, true);
|
|
4871
|
+
set("method", check.method ?? "GET", true);
|
|
4872
|
+
set("frequency", check.frequency, !declared || check.frequency !== void 0);
|
|
4873
|
+
set("activated", check.activated, !declared || check.activated !== void 0);
|
|
4874
|
+
set("shouldFail", check.shouldFail, !declared || check.shouldFail !== void 0);
|
|
4875
|
+
set("body", check.body, !declared || check.body !== void 0);
|
|
4876
|
+
set("locations", [...check.locations ?? []].sort().join(", "), !declared || check.locations !== void 0);
|
|
4877
|
+
set("assertions", (check.assertions ?? []).map(showAssertion).sort().join("; "), !declared || check.assertions !== void 0);
|
|
4878
|
+
return out;
|
|
4879
|
+
}
|
|
4880
|
+
function compareChecks(declared, have) {
|
|
4881
|
+
const byName = new Map(have.map((c) => [c.name, c]));
|
|
4882
|
+
const problems = declaredVsActual(new Map(declared.map((c) => [c.name, c])), byName, {
|
|
4883
|
+
noun: "check",
|
|
4884
|
+
flagExtra: false,
|
|
4885
|
+
equal: () => true
|
|
4886
|
+
});
|
|
4887
|
+
for (const want of declared) {
|
|
4888
|
+
const found = byName.get(want.name);
|
|
4889
|
+
if (!found) continue;
|
|
4890
|
+
const wanted = settings(want, true);
|
|
4891
|
+
const actual = new Map([...settings(found, false)].filter(([key]) => wanted.has(key)));
|
|
4892
|
+
problems.push(...declaredVsActual(wanted, actual, {
|
|
4893
|
+
noun: `check ${want.name}`,
|
|
4894
|
+
flagExtra: false,
|
|
4895
|
+
show: (value) => value === "" ? "none" : value
|
|
4896
|
+
}));
|
|
4897
|
+
}
|
|
4898
|
+
return problems;
|
|
4899
|
+
}
|
|
4900
|
+
// src/commands/doctor-monitoring/doctor-monitoring.command.ts
|
|
4901
|
+
const doctorMonitoringCommand = {
|
|
4902
|
+
command: "monitoring",
|
|
4903
|
+
describe: "Check the monitoring checks the config declares against the ones the provider holds (read-only)",
|
|
4904
|
+
handler: async (argv) => {
|
|
4905
|
+
const tokens = tokenContext(argv.token);
|
|
4906
|
+
if (!tokens) return;
|
|
4907
|
+
const loaded = await loadConfig(argv.cwd);
|
|
4908
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
4909
|
+
if ((await runDoctorMonitoring({
|
|
4910
|
+
loaded,
|
|
4911
|
+
context: {
|
|
4912
|
+
repoRoot: argv.cwd,
|
|
4913
|
+
...tokens
|
|
4914
|
+
}
|
|
4915
|
+
})).status === "fail") process.exitCode = 1;
|
|
4916
|
+
}
|
|
4917
|
+
};
|
|
4506
4918
|
// src/commands/doctor-notifications/doctor-notifications.args.ts
|
|
4507
4919
|
const doctorNotificationsArgs = (y) => y.option("scope", {
|
|
4508
4920
|
type: "string",
|
|
@@ -6208,6 +6620,32 @@ const DEEP_CHECKS = [
|
|
|
6208
6620
|
};
|
|
6209
6621
|
}
|
|
6210
6622
|
},
|
|
6623
|
+
{
|
|
6624
|
+
name: "monitoring",
|
|
6625
|
+
capability: "monitoring",
|
|
6626
|
+
command: doctorMonitoringCommand,
|
|
6627
|
+
async run(input) {
|
|
6628
|
+
const report = await runDoctorMonitoring(input);
|
|
6629
|
+
return {
|
|
6630
|
+
status: report.status,
|
|
6631
|
+
summary: report.summary,
|
|
6632
|
+
...report.reason ? { reason: report.reason } : {}
|
|
6633
|
+
};
|
|
6634
|
+
}
|
|
6635
|
+
},
|
|
6636
|
+
{
|
|
6637
|
+
name: "dns",
|
|
6638
|
+
capability: "dns",
|
|
6639
|
+
command: doctorDnsCommand,
|
|
6640
|
+
async run(input) {
|
|
6641
|
+
const report = await runDoctorDns(input);
|
|
6642
|
+
return {
|
|
6643
|
+
status: report.status,
|
|
6644
|
+
summary: report.summary,
|
|
6645
|
+
...report.reason ? { reason: report.reason } : {}
|
|
6646
|
+
};
|
|
6647
|
+
}
|
|
6648
|
+
},
|
|
6211
6649
|
{
|
|
6212
6650
|
name: "secrets",
|
|
6213
6651
|
capability: "secrets",
|
|
@@ -8811,92 +9249,6 @@ async function lockConfig(filepath) {
|
|
|
8811
9249
|
release: () => unlink(path).catch(() => void 0)
|
|
8812
9250
|
};
|
|
8813
9251
|
}
|
|
8814
|
-
// src/commands/notifications-setup/avatar-problem.ts
|
|
8815
|
-
/** The first reason a feed's `avatar` cannot work, or undefined. `feed` names the key for the message (`monitoring`, `errors`). */
|
|
8816
|
-
function avatarProblem(channel, feed, picture) {
|
|
8817
|
-
if (typeof picture !== "object") return void 0;
|
|
8818
|
-
if (!picture.url && !picture.image) return `channel \`${channel}\`: \`feeds.${feed}.avatar\` needs a \`url\`, an \`image\`, or both`;
|
|
8819
|
-
if (picture.url && !/^https:\/\//i.test(picture.url)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.url\` must be an https:// URL`;
|
|
8820
|
-
if (picture.image && /^https?:\/\//i.test(picture.image)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.image\` must be a file in the repo, not a URL`;
|
|
8821
|
-
}
|
|
8822
|
-
/** The webhook name a channel's error feed uses: its own, else the provider's name, capitalised (`Sentry`). */
|
|
8823
|
-
function errorsFeedWebhook(feed, errors) {
|
|
8824
|
-
return (typeof feed === "object" ? feed.webhook : void 0) ?? capitalised(errors.providerName);
|
|
8825
|
-
}
|
|
8826
|
-
const capitalised = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
8827
|
-
/** The Worker binding that holds the webhook URL for a source (the contract `apps/comlink` reads). */
|
|
8828
|
-
const relayWebhookBinding = (source) => `COMLINK_${source.toUpperCase()}_WEBHOOK`;
|
|
8829
|
-
/** The Worker binding that holds a source's signing secret (the contract `apps/comlink` reads). */
|
|
8830
|
-
const relaySecretBinding = (source) => `COMLINK_${source.toUpperCase()}_SECRET`;
|
|
8831
|
-
/** Whether any channel in the layout is fed by the error tracker. */
|
|
8832
|
-
function wantsRelay(layout) {
|
|
8833
|
-
return (layout.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.feeds?.errors));
|
|
8834
|
-
}
|
|
8835
|
-
/**
|
|
8836
|
-
* The first reason the relay cannot be deployed, or undefined. One source has one webhook, so only one channel can be
|
|
8837
|
-
* fed by it; and the Worker needs somewhere to answer.
|
|
8838
|
-
*/
|
|
8839
|
-
function relayProblem(layout, errors, monitoring) {
|
|
8840
|
-
const fed = (layout.categories ?? []).flatMap((c) => c.channels ?? []).filter((ch) => ch.feeds?.errors);
|
|
8841
|
-
if (fed.length === 0) return void 0;
|
|
8842
|
-
if (!layout.relay?.host) return `channel \`${fed[0].name}\` is fed by the error tracker, which needs \`relay.host\` — where the relay Worker answers`;
|
|
8843
|
-
if (fed.length > 1) return `channels ${fed.map((c) => `\`${c.name}\``).join(" and ")} are all fed by the error tracker, but its relay posts to one channel — feed one`;
|
|
8844
|
-
const channel = fed[0];
|
|
8845
|
-
const errorsFeed = channel.feeds.errors;
|
|
8846
|
-
const picture = typeof errorsFeed === "object" ? errorsFeed.avatar : void 0;
|
|
8847
|
-
const pictureProblem = avatarProblem(channel.name, "errors", picture);
|
|
8848
|
-
if (pictureProblem) return pictureProblem;
|
|
8849
|
-
if (errors) {
|
|
8850
|
-
const feed = errorsFeedWebhook(errorsFeed, errors).toLowerCase();
|
|
8851
|
-
const own = (typeof channel.webhook === "object" ? channel.webhook.name : void 0) ?? channel.name;
|
|
8852
|
-
if (channel.webhook && feed === own.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the channel's own webhook are both named ${own} — rename one`;
|
|
8853
|
-
const monitoringFeed = channel.feeds.monitoring;
|
|
8854
|
-
if (monitoring && monitoringFeed) {
|
|
8855
|
-
const other = (typeof monitoringFeed === "object" ? monitoringFeed.webhook : void 0) ?? capitalised(monitoring.providerName);
|
|
8856
|
-
if (feed === other.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the monitoring webhook are both named ${other} — rename one`;
|
|
8857
|
-
}
|
|
8858
|
-
}
|
|
8859
|
-
}
|
|
8860
|
-
/**
|
|
8861
|
-
* What to hand the `dns` capability as the zone: the layout's, else the host itself. The provider looks a name up from
|
|
8862
|
-
* the full name towards the apex until it finds a zone it holds, so this is right for any suffix (`example.co.uk`).
|
|
8863
|
-
*/
|
|
8864
|
-
const relayZone = (relay) => relay.zone ?? relay.host;
|
|
8865
|
-
/**
|
|
8866
|
-
* Deploy the Worker with its webhook secret and its route, then point the host at it with a proxied placeholder record
|
|
8867
|
-
* (the Worker answers before any origin is asked). The built file is read first and the DNS record comes last, so a
|
|
8868
|
-
* missing build or a failed deploy leaves the host untouched.
|
|
8869
|
-
*/
|
|
8870
|
-
async function deployRelay(input) {
|
|
8871
|
-
const { relay, workers, dns } = input;
|
|
8872
|
-
const path = join(input.repoRoot, relay.code ?? "apps/comlink/dist/worker.js");
|
|
8873
|
-
let code;
|
|
8874
|
-
try {
|
|
8875
|
-
code = await (input.readCode ?? ((p) => readFile(p, "utf8")))(path);
|
|
8876
|
-
} catch {
|
|
8877
|
-
throw new Error(`the relay Worker is not built (${relay.code ?? "apps/comlink/dist/worker.js"}) — run \`pnpm --filter @theholocron/comlink run delivery.build\``);
|
|
8878
|
-
}
|
|
8879
|
-
const script = relay.script ?? "comlink";
|
|
8880
|
-
await workers.deployScript(script, {
|
|
8881
|
-
code,
|
|
8882
|
-
secrets: {
|
|
8883
|
-
[relayWebhookBinding(input.source)]: input.webhook,
|
|
8884
|
-
...input.signingSecret ? { [relaySecretBinding(input.source)]: input.signingSecret } : {}
|
|
8885
|
-
},
|
|
8886
|
-
routes: [`${relay.host}/*`]
|
|
8887
|
-
});
|
|
8888
|
-
await dns.upsertRecord(relayZone(relay), {
|
|
8889
|
-
type: "AAAA",
|
|
8890
|
-
name: relay.host,
|
|
8891
|
-
content: "100::",
|
|
8892
|
-
ttl: 1,
|
|
8893
|
-
proxied: true
|
|
8894
|
-
});
|
|
8895
|
-
return {
|
|
8896
|
-
host: relay.host,
|
|
8897
|
-
script
|
|
8898
|
-
};
|
|
8899
|
-
}
|
|
8900
9252
|
// src/commands/notifications-setup/with-elevation.ts
|
|
8901
9253
|
/**
|
|
8902
9254
|
* Runs an edit that may need a permission the bot should not keep. When the provider says it does
|
|
@@ -13751,11 +14103,7 @@ async function runSetup(input) {
|
|
|
13751
14103
|
if (loader.has("deployment")) {
|
|
13752
14104
|
const deploy = loader.get("deployment");
|
|
13753
14105
|
print(style.step("deployment"));
|
|
13754
|
-
const
|
|
13755
|
-
const previewCfg = deployEntry?.with ? extractPreviewConfig(deployEntry.with, {
|
|
13756
|
-
org: config.org,
|
|
13757
|
-
domain: config.domain
|
|
13758
|
-
}) : null;
|
|
14106
|
+
const previewCfg = previewConfigOf(config);
|
|
13759
14107
|
const ensureCustomDomain = async (projectId, hostname) => {
|
|
13760
14108
|
if (!deploy.ensureCustomDomain) return;
|
|
13761
14109
|
const customDomainDns = { value: null };
|