@taprootio/site-authoring 0.36.2 → 0.37.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.
@@ -35,6 +35,29 @@ export async function mediaImagesGet(invocation) {
35
35
  return successResult(VERB_MEDIA_IMAGES_GET, siteId, { image });
36
36
  }
37
37
 
38
+ /**
39
+ * What a refused description write means to its caller (TR01372 shares it with `pages push
40
+ * --describe-missing-images`): a moved revision, an existing default under the condition, or text the server
41
+ * refused, each as its own code. Any other failure is returned as it is.
42
+ */
43
+ export function translateImageDescriptionRefusal(error) {
44
+ if (error instanceof ApiError && error.hasField("ExpectedRevision")) {
45
+ return new SiteAuthoringError("media.image_description_conflict",
46
+ "The description changed. Read it with 'media images get', reconcile the text, and supply that revision.",
47
+ { field: "expectedRevision", status: error.status });
48
+ }
49
+ if (error instanceof ApiError && error.hasField("OnlyIfMissing")) {
50
+ return new SiteAuthoringError("media.image_description_exists", "This image already has a default description; nothing changed.",
51
+ { field: "onlyIfMissing", status: error.status });
52
+ }
53
+ if (error instanceof ApiError && error.hasField("DefaultDescription")) {
54
+ return new SiteAuthoringError("media.image_description_invalid",
55
+ error.descriptionFor("DefaultDescription") ?? "Taproot refused the default description.",
56
+ { field: "defaultDescription", status: error.status });
57
+ }
58
+ return error;
59
+ }
60
+
38
61
  export async function mediaImagesDescribe(invocation) {
39
62
  const imageId = requireImageId(invocation.imageId);
40
63
  const body = imageDescriptionOptions(invocation);
@@ -45,21 +68,7 @@ export async function mediaImagesDescribe(invocation) {
45
68
  try {
46
69
  return await updateSiteImageDescription(client, siteId, imageId, body);
47
70
  } catch (error) {
48
- if (error instanceof ApiError && error.hasField("ExpectedRevision")) {
49
- throw new SiteAuthoringError("media.image_description_conflict",
50
- "The description changed. Read it with 'media images get', reconcile the text, and supply that revision.",
51
- { field: "expectedRevision", status: error.status });
52
- }
53
- if (error instanceof ApiError && error.hasField("OnlyIfMissing")) {
54
- throw new SiteAuthoringError("media.image_description_exists", "This image already has a default description; nothing changed.",
55
- { field: "onlyIfMissing", status: error.status });
56
- }
57
- if (error instanceof ApiError && error.hasField("DefaultDescription")) {
58
- throw new SiteAuthoringError("media.image_description_invalid",
59
- error.descriptionFor("DefaultDescription") ?? "Taproot refused the default description.",
60
- { field: "defaultDescription", status: error.status });
61
- }
62
- throw error;
71
+ throw translateImageDescriptionRefusal(error);
63
72
  }
64
73
  });
65
74
  onProgress(`Saved image ${image.imageId}, description revision ${image.descriptionRevision}. Deploy to update published usages.`);
@@ -1,3 +1,13 @@
1
+ import {
2
+ completedWritesForDescribe,
3
+ describedImagesBlock,
4
+ describeMissingImages,
5
+ evaluateImagePrecheck,
6
+ fitPrecheckToBudget,
7
+ placedImageIdsForPages,
8
+ planImageDescriptions,
9
+ readImageRecords,
10
+ } from "../site-health-precheck.js";
1
11
  import {
2
12
  createPage,
3
13
  getPage,
@@ -28,7 +38,7 @@ import { placedFormKeys, readFormIndex, withFormIds } from "../form-references.j
28
38
  import { workspaceFormKeys } from "../forms-workspace.js";
29
39
  import { ApiError } from "../transport.js";
30
40
  import { waitForProcessing } from "./media-upload.js";
31
- import { SiteAuthoringError } from "../errors.js";
41
+ import { outcomeUnknown, SiteAuthoringError } from "../errors.js";
32
42
  import { DESCRIPTION_MAXIMUM_LENGTH, DESCRIPTION_WARN_LENGTH, descriptionWarnings } from "../page-metadata.js";
33
43
  import { stableJson } from "../footer-draft-hash.js";
34
44
  import { CHECK_AREA, collectProblems, planStale, problemsOf, refuseProblems } from "../problems.js";
@@ -145,20 +155,7 @@ import {
145
155
  // of any length.
146
156
  const ITEMS_BYTES = 32 * 1024;
147
157
  const LIST_BYTES = 8 * 1024;
148
- // A send that ended this way may still have written the page.
149
- const OUTCOME_UNKNOWN_CODES = new Set([
150
- "transport.mutation_ambiguous",
151
- "transport.response_read",
152
- "transport.response_too_large",
153
- "transport.invalid_json",
154
- "api.page_contract",
155
- ]);
156
-
157
- export function outcomeUnknown(error) {
158
- // A cancelled retry of a write, and a server error on a write the transport
159
- // does not replay, leave the same question open.
160
- return OUTCOME_UNKNOWN_CODES.has(error.code) || error.ambiguousMutation === true || error.httpStatus >= 500;
161
- }
158
+ export { outcomeUnknown } from "../errors.js";
162
159
 
163
160
  /** The creates this workspace sent without hearing back, by page path. */
164
161
  function pendingCreates(manifest) {
@@ -1603,6 +1600,59 @@ export function plannedPageItem(page) {
1603
1600
  return { file: page.file, path: displayPagePath(page.pagePath), action: page.unchanged ? "unchanged" : page.action };
1604
1601
  }
1605
1602
 
1603
+ /**
1604
+ * The pre-staging image check (TR01371): one read of the site's records for every image the selected pages place,
1605
+ * taken once after the push's problems are refused and before anything is written. A failed read never fails the
1606
+ * push. `apply` already holds the plan, so it carries no check.
1607
+ */
1608
+ async function startImagePrecheck(invocation, client, siteId, planned) {
1609
+ if (invocation.plannedPages !== undefined) return undefined;
1610
+ const pages = placedImageIdsForPages(planned);
1611
+ return { pages, state: await readImageRecords(client, siteId, pages.flatMap((page) => page.imageIds)) };
1612
+ }
1613
+
1614
+ /**
1615
+ * The flagged push's report of what it would set (a dry run) or did set, with the skip reason of every other
1616
+ * candidate, plus the warning that a failed read left images unchecked. Absent without the flag, and under apply.
1617
+ */
1618
+ function describedImagesFor(precheck, plan, outcome, onProgress) {
1619
+ if (outcome === undefined) {
1620
+ outcome = {
1621
+ set: plan.filter((item) => item.description !== undefined).map((item) => ({ imageId: item.imageId, description: item.description })),
1622
+ skipped: plan.filter((item) => item.description === undefined).map((item) => ({ imageId: item.imageId, reason: item.reason })),
1623
+ };
1624
+ }
1625
+ const unread = outcome.skipped.filter((item) => item.reason === "not_read").length;
1626
+ if (precheck.state.reason !== undefined) {
1627
+ onProgress(
1628
+ `Warning: --describe-missing-images could not read every image record (${precheck.state.reason.code}); `
1629
+ + `${unread} image(s) were skipped as not_read.`,
1630
+ );
1631
+ }
1632
+ return describedImagesBlock(outcome, precheck.state);
1633
+ }
1634
+
1635
+ /**
1636
+ * Adds `siteHealthPrecheck` to the result, built from the records as they are now (so a later step that updates
1637
+ * them in place is reflected), printing its progress lines, and fitted to the output bound.
1638
+ */
1639
+ export function withImagePrecheck(result, precheck, onProgress) {
1640
+ if (precheck === undefined) return result;
1641
+ const block = evaluateImagePrecheck(precheck.state, precheck.pages, onProgress);
1642
+ // A block the result already carries (the describe flag's `describedImages`) shrinks with the new one, after it.
1643
+ const { describedImages, ...base } = result;
1644
+ const blocks = { siteHealthPrecheck: block, ...(describedImages === undefined ? {} : { describedImages }) };
1645
+ return {
1646
+ ...base,
1647
+ ...fitPrecheckToBudget(base, blocks, [
1648
+ "siteHealthPrecheck.notInSiteLibrary",
1649
+ "siteHealthPrecheck.imageFindings",
1650
+ "describedImages.set",
1651
+ "describedImages.skipped",
1652
+ ]),
1653
+ };
1654
+ }
1655
+
1606
1656
  export async function pagesPush(invocation) {
1607
1657
  const session = await openSession(invocation);
1608
1658
  const { client, config, siteId, now, onProgress } = session;
@@ -1725,8 +1775,12 @@ export async function pagesPush(invocation) {
1725
1775
  const warnings = { ...autolinkWarnings(sending, onProgress), ...descriptionWarnings(sending, onProgress) };
1726
1776
  if (dryRun) {
1727
1777
  refuseProblems(plan.problems, "pages push --dry-run found problems and sent nothing");
1778
+ const precheck = await startImagePrecheck(invocation, client, siteId, planned);
1779
+ const describedImages = invocation.describeMissingImages === true && precheck !== undefined
1780
+ ? describedImagesFor(precheck, planImageDescriptions(precheck.state, precheck.pages), undefined, onProgress)
1781
+ : undefined;
1728
1782
  onProgress("Dry run: nothing was sent.");
1729
- return successResult(VERB_PAGES_PUSH, siteId, {
1783
+ return withImagePrecheck(successResult(VERB_PAGES_PUSH, siteId, {
1730
1784
  dryRun: true,
1731
1785
  pages: {
1732
1786
  total: planned.length,
@@ -1739,9 +1793,13 @@ export async function pagesPush(invocation) {
1739
1793
  ...reportedList("items", planned.map(plannedPageItem), ITEMS_BYTES),
1740
1794
  },
1741
1795
  ...warnings,
1742
- });
1796
+ ...(describedImages === undefined ? {} : { describedImages }),
1797
+ }), precheck, onProgress);
1743
1798
  }
1744
1799
  refuseProblems(plan.problems, "pages push sent nothing");
1800
+ // Before the video posters are copied, so a poster this push places is outside the check; the stored report
1801
+ // after staging covers it.
1802
+ const precheck = await startImagePrecheck(invocation, client, siteId, planned);
1745
1803
  await copyVideoEmbedPosters(client, siteId, planned, { onProgress, now });
1746
1804
 
1747
1805
  // Phase two: send. The manifest is written back even if a later page fails,
@@ -1899,6 +1957,35 @@ export async function pagesPush(invocation) {
1899
1957
  if (manifestDirty) await writeManifest(config.workspaceDir, manifest);
1900
1958
  }
1901
1959
 
1960
+ // The flag sets missing image defaults only now, after the pages are saved, so a refused push sets nothing. A
1961
+ // failure here fails the command, and the pages saved above stay saved.
1962
+ let describedImages;
1963
+ if (invocation.describeMissingImages === true && precheck !== undefined) {
1964
+ const plan = planImageDescriptions(precheck.state, precheck.pages);
1965
+ let outcome;
1966
+ try {
1967
+ outcome = await describeMissingImages({ client, siteId, state: precheck.state, plan });
1968
+ } catch (error) {
1969
+ if (error?.describeOutcome !== undefined && typeof error.withCompletedWrites === "function") {
1970
+ error.withCompletedWrites(completedWritesForDescribe({
1971
+ outcome: error.describeOutcome,
1972
+ savedPages: applied.map((entry) => `page ${entry.path || "/"}: ${entry.action}`),
1973
+ }));
1974
+ }
1975
+ throw error;
1976
+ }
1977
+ describedImages = describedImagesFor(precheck, plan, outcome, onProgress);
1978
+ if (outcome.set.length > 0) {
1979
+ onProgress(`Set the default description of ${outcome.set.length} image(s). Deploy to update published usages.`);
1980
+ }
1981
+ }
1982
+ // With nothing set the next step is what it always was. After images were set, a page still holding a draft
1983
+ // (sent now, or sent earlier and not approved) is approved first: deploying would stage the older approved content.
1984
+ const imagesSet = describedImages !== undefined && describedImages.set.total > 0;
1985
+ const awaitingApproval = applied.length > 0 || (imagesSet && planned.some((page) =>
1986
+ page.unchanged && livePages.find((live) => live.pageId === page.pageId)?.hasDraft === true));
1987
+ const nextStep = awaitingApproval ? "approve" : imagesSet ? "deploy --staging" : undefined;
1988
+
1902
1989
  // Pages are authorless unless a source names an author, and an owner
1903
1990
  // otherwise finds the missing byline only after publishing (TR01196).
1904
1991
  const authorless = applied.filter((entry) => entry.action === "created" && entry.author === undefined);
@@ -1909,7 +1996,7 @@ export async function pagesPush(invocation) {
1909
1996
  + "<handle or email>', then push again; 'taproot-site authors list' shows who can be named.",
1910
1997
  );
1911
1998
  }
1912
- return successResult(VERB_PAGES_PUSH, siteId, {
1999
+ return withImagePrecheck(successResult(VERB_PAGES_PUSH, siteId, {
1913
2000
  pages: {
1914
2001
  total: planned.length,
1915
2002
  unchanged: planned.filter((page) => page.unchanged).length,
@@ -1935,7 +2022,8 @@ export async function pagesPush(invocation) {
1935
2022
  // `pages push` writes drafts. Nothing reaches an audience until `approve`
1936
2023
  // stages them and `deploy` publishes the site.
1937
2024
  // Nothing to approve when every page was unchanged and nothing was sent.
1938
- ...(applied.length > 0 ? { nextStep: "approve" } : {}),
1939
- });
2025
+ ...(nextStep === undefined ? {} : { nextStep }),
2026
+ ...(describedImages === undefined ? {} : { describedImages }),
2027
+ }), precheck, onProgress);
1940
2028
  });
1941
2029
  }
@@ -23,7 +23,8 @@ import {
23
23
  SURFACE_DOCS_PRESENTATION,
24
24
  VERB_STATUS,
25
25
  } from "../constants.js";
26
- import { boundedList, openSession, successResult } from "../session.js";
26
+ import { boundedByBytes, boundedList, openSession, successResult } from "../session.js";
27
+ import { readFailureCode } from "./health.js";
27
28
 
28
29
  /**
29
30
  * `status` — the platform authoring switch, CLI release, deployments,
@@ -33,6 +34,8 @@ const MAXIMUM_DEPLOYMENTS = 20;
33
34
  const MAXIMUM_FAILED_IMAGES = 50;
34
35
  const MAXIMUM_BLOCKERS = 50;
35
36
  const MAXIMUM_HEALTH_FINDINGS = 100;
37
+ // Each image finding lists its affected pages, so a full report would pass the result bound without this.
38
+ const MAXIMUM_HEALTH_IMAGE_BYTES = 16 * 1024;
36
39
 
37
40
  const PLATFORM_UNKNOWN_NOTE =
38
41
  "Taproot never reported the platform authoring switch on this run: either no sign-in token exchange happened "
@@ -127,6 +130,38 @@ const DOCS_SITE_NOT_COVERED_NOTE =
127
130
  "This is a managed Docs site: its pages come from the Docs artifact, so the image library and site-health "
128
131
  + "reads do not apply and were not made.";
129
132
 
133
+ /**
134
+ * The staged release's report as a summary (TR01363); `health --staging` has the findings and their fixes. A
135
+ * failed read never fails `status`, which still answers from production, so it is reported as unavailable.
136
+ */
137
+ async function summarizeStagedHealth(client, siteId, stagedDeploymentId, onProgress) {
138
+ if (stagedDeploymentId === undefined) {
139
+ return { available: false, reason: "No stored staging report exists yet; deploy --staging creates one." };
140
+ }
141
+ onProgress("Reading the stored staging health report.");
142
+ let staged;
143
+ try {
144
+ staged = await getSiteHealth(client, siteId, { deploymentId: stagedDeploymentId });
145
+ } catch (error) {
146
+ const reason = `The staged Site Health report could not be read (${readFailureCode(error)}).`;
147
+ onProgress(`Warning: ${reason}`);
148
+ return { available: false, reason };
149
+ }
150
+ if (!["complete", "incomplete"].includes(staged.status) || !staged.deploymentId) {
151
+ return { available: false, status: staged.status, reason: "The staged release has no complete supported assessment." };
152
+ }
153
+ return {
154
+ available: true,
155
+ status: staged.status,
156
+ deploymentId: staged.deploymentId,
157
+ checkedAt: staged.checkedAt,
158
+ errors: staged.errorCount,
159
+ warnings: staged.warningCount,
160
+ ...(staged.truncated ? { truncated: true } : {}),
161
+ details: "Run 'taproot-site health --staging' for the findings, the ones new since production, and their fixes.",
162
+ };
163
+ }
164
+
130
165
  export async function status(invocation) {
131
166
  const { client, siteId, surface, platform, release, onProgress } = await openSession(invocation);
132
167
  const presentationOnly = surface === SURFACE_DOCS_PRESENTATION;
@@ -167,6 +202,10 @@ export async function status(invocation) {
167
202
  health = await getSiteHealth(client, siteId);
168
203
  }
169
204
  const reportedFindings = boundedList(health.findings, MAXIMUM_HEALTH_FINDINGS);
205
+ const reportedImageFindings = boundedByBytes(health.images ?? [], MAXIMUM_HEALTH_IMAGE_BYTES);
206
+ const stagedSiteHealth = presentationOnly
207
+ ? { covered: false, reason: DOCS_SITE_NOT_COVERED_NOTE }
208
+ : await summarizeStagedHealth(client, siteId, health.stagedDeploymentId, onProgress);
170
209
 
171
210
  const byState = {};
172
211
  for (const image of images) {
@@ -244,10 +283,12 @@ export async function status(invocation) {
244
283
  warnings: health.warningCount,
245
284
  pages: health.pageCount,
246
285
  findings: reportedFindings.items,
247
- imageFindings: health.images,
286
+ imageFindings: reportedImageFindings.items,
287
+ ...(reportedImageFindings.truncated ? { imageFindingsTruncated: true } : {}),
248
288
  ...(reportedFindings.truncated || health.truncated ? { findingsTruncated: true } : {}),
249
289
  } : { reason: health.status === "not_checked" ? "Not checked yet; deploy the site to create a report." : "A complete supported deployment assessment is unavailable." }),
250
290
  },
291
+ stagedSiteHealth,
251
292
  });
252
293
  });
253
294
  }
@@ -1,9 +1,9 @@
1
1
  import { lstat, realpath } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
- import { NAVIGATION_MAXIMUM_DEPTH } from "../api.js";
4
+ import { NAVIGATION_MAXIMUM_DEPTH, withRefusalGuidance } from "../api.js";
5
5
  import { loadSiteConfig } from "../config.js";
6
- import { VERB_VALIDATE } from "../constants.js";
6
+ import { SURFACE_DOCS_PRESENTATION, VERB_VALIDATE } from "../constants.js";
7
7
  import { freeFormRootPresentation } from "../content/free-form-sections.js";
8
8
  import { autolinkWarnings } from "../content/link-warnings.js";
9
9
  import { isCanonicalUuid, SiteAuthoringError } from "../errors.js";
@@ -21,8 +21,20 @@ import { FORMS_DIRECTORY } from "../forms-contract.js";
21
21
  import { authorWarnings, descriptionWarnings } from "../page-metadata.js";
22
22
  import { CHECK_AREA, collectProblems, refuseProblems } from "../problems.js";
23
23
  import { isRedirectMapRevision, REDIRECT_KIND_GONE, REDIRECTS_FILE_NAME } from "../redirects-contract.js";
24
- import { boundedList, successResult } from "../session.js";
25
- import { evaluateOfflineSiteChecks } from "../site-check-findings.js";
24
+ import { boundedList, openSession, successResult } from "../session.js";
25
+ import {
26
+ evaluateOfflineSiteChecks,
27
+ IMAGE_CHECK_DIRECTORY_ARGUMENT,
28
+ IMAGE_CHECK_DOCS_SITE,
29
+ IMAGE_CHECK_NOT_REQUESTED,
30
+ imageCheckSkipped,
31
+ } from "../site-check-findings.js";
32
+ import {
33
+ evaluateImagePrecheck,
34
+ fitPrecheckToBudget,
35
+ placedImageIdsForPages,
36
+ readImageRecords,
37
+ } from "../site-health-precheck.js";
26
38
  import { SETTINGS_GROUPS } from "../settings-catalog.js";
27
39
  import { checkWorkspace } from "../workspace-check.js";
28
40
  import {
@@ -49,6 +61,13 @@ import {
49
61
  import { documentImageIds, isAuthorableTemplateType, placedVideoIds } from "../typed-pages.js";
50
62
 
51
63
  const MAXIMUM_REPORTED = 200;
64
+ // What no validate run proves about the site checks: the ones the site itself answers, the deploy's and the editor's.
65
+ const SITE_CHECKS_NOT_PROVEN =
66
+ "image description defaults (unless --site reads the site's image records), and the site checks listed in siteChecks.checkedBySite (missing images, forms), which 'taproot-site status' and "
67
+ + "'taproot-site health' report from the stored deployment report, siteChecks.checkedAtDeploy, which only a deploy "
68
+ + "applies, or siteChecks.checkedInEditor, which only the page editor evaluates (a cover, a description field, or a "
69
+ + "description's length); images an integration places, or a video poster a push copies, which the stored report "
70
+ + "after staging covers";
52
71
  const FIXTURE_ROOT_KEYS = new Set(FIXTURE_ROOT_FIELDS);
53
72
  const FIXTURE_METADATA_KEYS = new Set(FIXTURE_METADATA_FIELDS);
54
73
 
@@ -56,6 +75,16 @@ function fail(code, message, field, exitCode) {
56
75
  throw new SiteAuthoringError(code, message, { field, exitCode });
57
76
  }
58
77
 
78
+ /** `validate --site` reads the site for the workspace the configuration names, so a directory or --init has none. */
79
+ export function siteNeedsWorkspaceError(init) {
80
+ return new SiteAuthoringError(
81
+ "validate.site_needs_workspace",
82
+ "validate --site reads the site for the workspace taproot-site.json names, so it takes no directory and no "
83
+ + "--init: a directory has no configuration to read the site with. Run it from the workspace.",
84
+ { field: init ? "init" : "fixturePath", exitCode: 2 },
85
+ );
86
+ }
87
+
59
88
  function isPlainObject(value) {
60
89
  return value !== null && typeof value === "object" && !Array.isArray(value);
61
90
  }
@@ -653,18 +682,65 @@ function pageHints(checked, onProgress) {
653
682
  * The offline site checks (TR01085) over the planned pages: the rules the shared
654
683
  * catalogue lists for `validate`, with the rest named as checked by the site.
655
684
  */
656
- function offlineSiteChecks(checked, manifest, onProgress) {
685
+ function offlineSiteChecks(checked, manifest, onProgress, imageCheck) {
657
686
  if (checked.settingsOnly) return {};
658
687
  return evaluateOfflineSiteChecks({
659
688
  planned: checked.pages?.planned,
660
689
  pagePaths: manifest.pages.map((entry) => normalizePagePath(entry?.path)).filter((value) => value !== undefined),
661
690
  pagesComplete: manifest.pagesTruncated !== true,
662
691
  formKeysChecked: checked.formKeysChecked === true,
692
+ imageCheck,
663
693
  onProgress,
664
694
  });
665
695
  }
666
696
 
697
+ /**
698
+ * `validate --site`: reads the site's records for the images the workspace places and reports the ones with no
699
+ * default description (TR01371). Runs after the workspace's own problems are refused, so those come before any
700
+ * credential error. A Docs workspace, and a workspace placing no images, open no session and make no request.
701
+ */
702
+ async function readSiteImages(checked, invocation, onProgress, config) {
703
+ if (checked.settingsOnly || config?.authoringSurface === SURFACE_DOCS_PRESENTATION) {
704
+ return { imageCheck: imageCheckSkipped(IMAGE_CHECK_DOCS_SITE) };
705
+ }
706
+ const pages = placedImageIdsForPages(checked.pages.planned);
707
+ const ids = pages.flatMap((page) => page.imageIds);
708
+ if (ids.length === 0) return { imageCheck: { ran: true }, pages, block: emptyBlock(pages), opened: false };
709
+ // The configuration this workspace was validated against, not a reread one: a site switched meanwhile must not be
710
+ // the one whose images are read.
711
+ const session = await openSession({ ...invocation, resolvedConfig: config });
712
+ onProgress("Reading the site's records for the images this workspace places.");
713
+ const state = await withRefusalGuidance(onProgress, "validate", async () => {
714
+ const read = await readImageRecords(session.client, session.siteId, ids);
715
+ // A key the site refused is a failure of this verb, with the server's own description (the read made the
716
+ // first request, so a revoked key shows up here).
717
+ if (read.refusalError !== undefined) throw read.refusalError;
718
+ return read;
719
+ });
720
+ const block = evaluateImagePrecheck(state, pages, onProgress);
721
+ return {
722
+ imageCheck: state.reason === undefined ? { ran: true } : { ran: false, code: state.reason.code, message: state.reason.message },
723
+ pages,
724
+ block: state.status === "not_checked" ? undefined : block,
725
+ opened: true,
726
+ };
727
+ }
728
+
729
+ function emptyBlock(pages) {
730
+ return {
731
+ status: "checked",
732
+ checkedPages: pages.length,
733
+ imageFindings: { total: 0, items: [] },
734
+ notInSiteLibrary: { total: 0, items: [] },
735
+ skipped: [],
736
+ };
737
+ }
738
+
667
739
  export async function validateFixture(invocation = {}) {
740
+ // Refused before any file is read: a directory, or a fixture to export, has no site to read.
741
+ if (invocation.fromSite === true && (invocation.init || invocation.fixturePath !== undefined)) {
742
+ throw siteNeedsWorkspaceError(Boolean(invocation.init));
743
+ }
668
744
  if (invocation.init) return await initializeFixture(invocation, validateFixture);
669
745
  const onProgress = typeof invocation.onProgress === "function" ? invocation.onProgress : () => {};
670
746
  const cwd = invocation.cwd ?? process.cwd();
@@ -677,7 +753,7 @@ export async function validateFixture(invocation = {}) {
677
753
  "siteId",
678
754
  );
679
755
  }
680
- return await validatePulledWorkspace(config.workspaceDir, config.siteId, invocation, onProgress);
756
+ return await validatePulledWorkspace(config.workspaceDir, config.siteId, invocation, onProgress, { config });
681
757
  }
682
758
  const fixtureRoot = await resolveFixtureRoot(cwd, invocation.fixturePath);
683
759
  if (
@@ -688,7 +764,7 @@ export async function validateFixture(invocation = {}) {
688
764
  if (!isCanonicalUuid(siteId)) {
689
765
  fail("workspace.manifest_invalid", `${MANIFEST_FILE_NAME} does not record a canonical site id.`, "siteId");
690
766
  }
691
- return await validatePulledWorkspace(fixtureRoot, siteId, invocation, onProgress);
767
+ return await validatePulledWorkspace(fixtureRoot, siteId, invocation, onProgress, { directoryArgument: true });
692
768
  }
693
769
 
694
770
  onProgress(`Reading ${FIXTURE_MANIFEST_FILE_NAME}.`);
@@ -752,7 +828,7 @@ export async function validateFixture(invocation = {}) {
752
828
  ...autolinkWarnings(checked.pages?.planned, onProgress),
753
829
  ...descriptionWarnings(checked.pages?.planned, onProgress),
754
830
  ...authorWarnings(checked.pages?.planned, onProgress),
755
- ...offlineSiteChecks(checked, manifest, onProgress),
831
+ ...offlineSiteChecks(checked, manifest, onProgress, imageCheckSkipped(IMAGE_CHECK_DIRECTORY_ARGUMENT)),
756
832
  };
757
833
  onProgress(
758
834
  `Validated ${validatedPages.length} page(s), ${checked.navigation.items} navigation item(s), two themes, appearance, and footer without credentials or mutation.`,
@@ -782,9 +858,7 @@ export async function validateFixture(invocation = {}) {
782
858
  "credential authorization or live site ownership",
783
859
  "remote concurrency or current revisions",
784
860
  "server normalization and pull round trips",
785
- "the site checks listed in siteChecks.checkedBySite (images, forms), which 'taproot-site status' reports under "
786
- + "siteHealth, siteChecks.checkedAtDeploy, which only a deploy applies, or siteChecks.checkedInEditor, "
787
- + "which only the page editor evaluates (a cover, a description field, or a description's length)",
861
+ SITE_CHECKS_NOT_PROVEN,
788
862
  "preview or published rendering",
789
863
  ],
790
864
  nextStep: "Run a real pull and authorized preview before approval or deployment.",
@@ -796,7 +870,7 @@ export async function validateFixture(invocation = {}) {
796
870
  * runs before it sends anything, for every page and setting at once, against
797
871
  * what the manifests recorded at the pull — no credential and no request.
798
872
  */
799
- async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgress) {
873
+ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgress, { config, directoryArgument = false }) {
800
874
  onProgress(`Reading ${MANIFEST_FILE_NAME}.`);
801
875
  const manifest = await readManifest(workspaceDir, siteId);
802
876
  const mediaManifest = await readMediaManifest(workspaceDir, siteId);
@@ -811,6 +885,10 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
811
885
  reportThemeWarnings(checked.presentation, onProgress);
812
886
  refuseProblems(checked.problems, "validate found problems in the workspace");
813
887
 
888
+ // Only --site reads the site; without it the image rule is skipped with the reason (TR01371).
889
+ const site = invocation.fromSite === true
890
+ ? await readSiteImages(checked, invocation, onProgress, config)
891
+ : { imageCheck: imageCheckSkipped(directoryArgument ? IMAGE_CHECK_DIRECTORY_ARGUMENT : IMAGE_CHECK_NOT_REQUESTED) };
814
892
  const pages = checked.settingsOnly
815
893
  ? []
816
894
  : checked.pages.planned.map((page) => ({ file: page.file, path: displayPagePath(page.pagePath) }));
@@ -821,20 +899,36 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
821
899
  ...autolinkWarnings(checked.pages.planned, onProgress),
822
900
  ...descriptionWarnings(checked.pages.planned, onProgress),
823
901
  ...authorWarnings(checked.pages.planned, onProgress),
824
- ...offlineSiteChecks(checked, manifest, onProgress),
902
+ ...offlineSiteChecks(checked, manifest, onProgress, site.imageCheck),
825
903
  };
904
+ // A Docs workspace has no `siteChecks` to carry the reason, so it is said at the top level.
905
+ const docsReason = checked.settingsOnly && invocation.fromSite === true
906
+ ? {
907
+ imageCheckReason: {
908
+ code: site.imageCheck.code,
909
+ ...(site.imageCheck.message === undefined ? {} : { message: site.imageCheck.message }),
910
+ },
911
+ }
912
+ : {};
913
+ const readSite = site.opened === true;
914
+ const noImages = invocation.fromSite === true && site.opened === false;
826
915
  onProgress(
827
916
  checked.settingsOnly
828
917
  ? "Validated the workspace's two themes, appearance, and footer without credentials or mutation."
829
918
  : `Validated ${pages.length} page(s), ${checked.navigation.items} navigation item(s), two themes, appearance, and `
830
- + "footer without credentials or mutation.",
919
+ + (readSite
920
+ ? "footer, reading the site's image records without mutation."
921
+ : noImages
922
+ ? "footer without credentials or mutation; the workspace places no images, so the site was not read."
923
+ : "footer without credentials or mutation."),
831
924
  );
832
- return successResult(VERB_VALIDATE, siteId, {
833
- offline: true,
925
+ const base = successResult(VERB_VALIDATE, siteId, {
926
+ offline: !readSite,
834
927
  workspace: { manifest: MANIFEST_FILE_NAME, settingsOnly: checked.settingsOnly },
835
928
  ...validatedSummary(checked, pages),
836
929
  hints,
837
930
  ...warnings,
931
+ ...docsReason,
838
932
  proves: [
839
933
  "every page source: metadata, Markdown conversion, media references, content vocabulary, and section contexts",
840
934
  "page paths, templates, and system pages against the pages the pull recorded",
@@ -842,16 +936,26 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
842
936
  "redirect-map shape, normalization, chains, loops, and workspace page paths",
843
937
  "complete theme, appearance, header, brand, and footer semantics",
844
938
  "form files against the shared field schema",
939
+ ...(site.block === undefined ? [] : [
940
+ site.imageCheck.ran
941
+ ? "which placed images have no default description, from the site's own image records (imageFindings)"
942
+ : "which of the placed images that were read have no default description (imageFindings); some records could not be read",
943
+ ]),
845
944
  ],
846
945
  doesNotProve: [
847
946
  "credential authorization or live site ownership",
848
947
  "pages, revisions, or videos that changed on the site since the pull",
849
948
  "server normalization and pull round trips",
850
- "the site checks listed in siteChecks.checkedBySite (images, forms), which 'taproot-site status' reports under "
851
- + "siteHealth, siteChecks.checkedAtDeploy, which only a deploy applies, or siteChecks.checkedInEditor, "
852
- + "which only the page editor evaluates (a cover, a description field, or a description's length)",
949
+ SITE_CHECKS_NOT_PROVEN,
853
950
  "preview or published rendering",
854
951
  ],
855
952
  nextStep: "Run 'taproot-site plan' to check the workspace against the live site and see the ordered apply.",
856
953
  });
954
+ if (site.block === undefined) return base;
955
+ const fitted = fitPrecheckToBudget(
956
+ base,
957
+ { imageFindings: site.block.imageFindings, notInSiteLibrary: site.block.notInSiteLibrary },
958
+ ["notInSiteLibrary", "imageFindings"],
959
+ );
960
+ return { ...base, ...fitted };
857
961
  }