@taprootio/site-authoring 0.41.0 → 0.42.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.
@@ -2,6 +2,8 @@ import { lstat, realpath } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
4
  import { NAVIGATION_MAXIMUM_DEPTH, withRefusalGuidance } from "../api.js";
5
+ import { CHROME_OFFLINE_PAGE_LIMITATION, CHROME_REPORT_NAME_RULE, selectNameReportEligibility } from "../chrome-input.js";
6
+ import { completeChromeReport } from "../chrome-report.js";
5
7
  import { loadSiteConfig } from "../config.js";
6
8
  import { SURFACE_DOCS_PRESENTATION, VERB_VALIDATE } from "../constants.js";
7
9
  import { freeFormRootPresentation } from "../content/free-form-sections.js";
@@ -18,7 +20,7 @@ import {
18
20
  import { initializeFixture } from "../fixture-init.js";
19
21
  import { evaluateLogoSurfaceChecks } from "../logo-surface-checks.js";
20
22
  import { loadThemeEngines } from "../theme-resolve.js";
21
- import { readFooterBrandInputs } from "../footer-brand-inputs.js";
23
+ import { footerBrandInputsFromSettings } from "../footer-brand-inputs.js";
22
24
  import { buildFooterFitInput } from "../footer-fit.js";
23
25
  import { appearanceManifestEntry, footerManifestEntry } from "../footer-workspace.js";
24
26
  import { FORMS_DIRECTORY } from "../forms-contract.js";
@@ -41,6 +43,7 @@ import {
41
43
  readImageRecords,
42
44
  } from "../site-health-precheck.js";
43
45
  import { SETTINGS_GROUPS } from "../settings-catalog.js";
46
+ import { withChromeWarnings } from "../theme-validation.js";
44
47
  import { checkWorkspace } from "../workspace-check.js";
45
48
  import {
46
49
  displayPagePath,
@@ -73,6 +76,7 @@ const SITE_CHECKS_NOT_PROVEN =
73
76
  + "applies, or siteChecks.checkedInEditor, which only the page editor evaluates (a cover, a description field, or a "
74
77
  + "description's length); images an integration places, or a video poster a push copies, which the stored report "
75
78
  + "after staging covers";
79
+ const DOCS_CHROME_NOT_PROVEN = "navigation or footer-page-link contrast, because the settings-only workspace has no local navigation or page inventory";
76
80
  const FIXTURE_ROOT_KEYS = new Set(FIXTURE_ROOT_FIELDS);
77
81
  const FIXTURE_METADATA_KEYS = new Set(FIXTURE_METADATA_FIELDS);
78
82
 
@@ -687,10 +691,17 @@ function pageHints(checked, onProgress) {
687
691
  * The offline site checks (TR01085) over the planned pages: the rules the shared
688
692
  * catalogue lists for `validate`, with the rest named as checked by the site.
689
693
  */
690
- async function offlineSiteChecks(checked, manifest, onProgress, imageCheck, workspaceDir, loadLogoEngines) {
691
- const footerInput = checked.footer === undefined
694
+ async function offlineSiteChecks(checked, manifest, mediaManifest, onProgress, imageCheck, options) {
695
+ const { reportChrome, nameReportEnabled, loadLogoEngines } = options;
696
+ const footer = checked.footer?.footerSettings;
697
+ const footerInput = footer === undefined
692
698
  ? undefined
693
- : buildFooterFitInput(checked.footer.footerSettings, await readFooterBrandInputs(workspaceDir, checked.footer.footerSettings));
699
+ : buildFooterFitInput(footer, footerBrandInputsFromSettings(
700
+ checked.presentation?.header,
701
+ checked.presentation?.style,
702
+ mediaManifest.media,
703
+ footer,
704
+ ));
694
705
  const evaluated = evaluateOfflineSiteChecks({
695
706
  planned: checked.settingsOnly ? [] : checked.pages?.planned,
696
707
  footerInput,
@@ -704,10 +715,42 @@ async function offlineSiteChecks(checked, manifest, onProgress, imageCheck, work
704
715
  const logos = await evaluateLogoSurfaceChecks({
705
716
  styles: checked.presentation?.style,
706
717
  header: checked.presentation?.header,
707
- footer: checked.footer?.footerSettings,
718
+ footer,
708
719
  onProgress,
709
720
  }, { loadEngines: loadLogoEngines });
710
- return mergeOfflineSiteChecks(evaluated, logos);
721
+ const merged = mergeOfflineSiteChecks(evaluated, logos);
722
+ if (!reportChrome) {
723
+ merged.siteChecks.ranOffline = merged.siteChecks.ranOffline.filter((id) => id !== CHROME_REPORT_NAME_RULE);
724
+ return merged;
725
+ }
726
+
727
+ return mergeOfflineSiteChecks(merged, {
728
+ findings: { total: 0, errors: 0, warnings: 0, items: [] },
729
+ siteChecks: {
730
+ ...(checked.settingsOnly ? { ranOffline: [CHROME_REPORT_NAME_RULE] } : {}),
731
+ ...(nameReportEnabled === undefined ? { skipped: [CHROME_REPORT_NAME_RULE] } : {}),
732
+ },
733
+ });
734
+ }
735
+
736
+ async function completeValidationWarnings(checked, resources, options, onProgress) {
737
+ if (options.reportChrome && resources.valid) {
738
+ const appearance = checked.presentation;
739
+ const { warnings } = await completeChromeReport({
740
+ themes: appearance.themes,
741
+ appearance,
742
+ resources: {
743
+ manifest: resources.manifest,
744
+ mediaManifest: resources.mediaManifest,
745
+ footerSettings: checked.footer?.footerSettings,
746
+ navigation: checked.navigation,
747
+ settingsOnly: checked.settingsOnly,
748
+ },
749
+ nameReportEnabled: options.nameReportEnabled,
750
+ }, { loadFit: options.loadChromeFit });
751
+ appearance.themes = withChromeWarnings(appearance.themes, warnings);
752
+ }
753
+ reportThemeWarnings(checked.presentation, onProgress);
711
754
  }
712
755
 
713
756
  /**
@@ -752,12 +795,19 @@ function emptyBlock(pages) {
752
795
  };
753
796
  }
754
797
 
755
- export async function validateFixture(invocation = {}, { loadLogoEngines = loadThemeEngines } = {}) {
798
+ export async function validateFixture(invocation = {}, {
799
+ loadLogoEngines = loadThemeEngines,
800
+ loadChromeFit,
801
+ reportChrome = true,
802
+ } = {}) {
756
803
  // Refused before any file is read: a directory, or a fixture to export, has no site to read.
757
804
  if (invocation.fromSite === true && (invocation.init || invocation.fixturePath !== undefined)) {
758
805
  throw siteNeedsWorkspaceError(Boolean(invocation.init));
759
806
  }
760
- if (invocation.init) return await initializeFixture(invocation, next => validateFixture(next, { loadLogoEngines }));
807
+ if (invocation.init) {
808
+ return await initializeFixture(invocation, next => validateFixture(next, { loadLogoEngines, reportChrome: false }));
809
+ }
810
+ const reporting = { loadLogoEngines, loadChromeFit, reportChrome };
761
811
  const onProgress = typeof invocation.onProgress === "function" ? invocation.onProgress : () => {};
762
812
  const cwd = invocation.cwd ?? process.cwd();
763
813
  if (invocation.fixturePath === undefined) {
@@ -769,7 +819,7 @@ export async function validateFixture(invocation = {}, { loadLogoEngines = loadT
769
819
  "siteId",
770
820
  );
771
821
  }
772
- return await validatePulledWorkspace(config.workspaceDir, config.siteId, invocation, onProgress, { config, loadLogoEngines });
822
+ return await validatePulledWorkspace(config.workspaceDir, config.siteId, invocation, onProgress, { config, ...reporting });
773
823
  }
774
824
  const fixtureRoot = await resolveFixtureRoot(cwd, invocation.fixturePath);
775
825
  if (
@@ -780,7 +830,7 @@ export async function validateFixture(invocation = {}, { loadLogoEngines = loadT
780
830
  if (!isCanonicalUuid(siteId)) {
781
831
  fail("workspace.manifest_invalid", `${MANIFEST_FILE_NAME} does not record a canonical site id.`, "siteId");
782
832
  }
783
- return await validatePulledWorkspace(fixtureRoot, siteId, invocation, onProgress, { directoryArgument: true, loadLogoEngines });
833
+ return await validatePulledWorkspace(fixtureRoot, siteId, invocation, onProgress, { directoryArgument: true, ...reporting });
784
834
  }
785
835
 
786
836
  onProgress(`Reading ${FIXTURE_MANIFEST_FILE_NAME}.`);
@@ -819,7 +869,6 @@ export async function validateFixture(invocation = {}, { loadLogoEngines = loadT
819
869
  onProgress,
820
870
  });
821
871
  problems.push(...checked.problems);
822
- reportThemeWarnings(checked.presentation, onProgress);
823
872
 
824
873
  const manifestByFile = new Map(manifest.pages.map((entry) => [entry.file, entry]));
825
874
  const validatedPages = [];
@@ -837,6 +886,8 @@ export async function validateFixture(invocation = {}, { loadLogoEngines = loadT
837
886
  // A forms folder that failed to read is already its own problem.
838
887
  if (checked.forms !== undefined) requireFixtureFormsBound(manifest.forms, checked.forms);
839
888
  });
889
+ const options = { ...reporting, nameReportEnabled: selectNameReportEligibility({ manifest }) };
890
+ await completeValidationWarnings(checked, { manifest, mediaManifest, valid: problems.length === 0 }, options, onProgress);
840
891
  refuseProblems(problems, "validate found problems in the fixture");
841
892
 
842
893
  const hints = pageHints(checked, onProgress);
@@ -844,7 +895,7 @@ export async function validateFixture(invocation = {}, { loadLogoEngines = loadT
844
895
  ...autolinkWarnings(checked.pages?.planned, onProgress),
845
896
  ...descriptionWarnings(checked.pages?.planned, onProgress),
846
897
  ...authorWarnings(checked.pages?.planned, onProgress),
847
- ...await offlineSiteChecks(checked, manifest, onProgress, imageCheckSkipped(IMAGE_CHECK_DIRECTORY_ARGUMENT), fixtureRoot, loadLogoEngines),
898
+ ...await offlineSiteChecks(checked, manifest, mediaManifest, onProgress, imageCheckSkipped(IMAGE_CHECK_DIRECTORY_ARGUMENT), options),
848
899
  };
849
900
  onProgress(
850
901
  `Validated ${validatedPages.length} page(s), ${checked.navigation.items} navigation item(s), two themes, appearance, and footer without credentials or mutation.`,
@@ -886,7 +937,7 @@ export async function validateFixture(invocation = {}, { loadLogoEngines = loadT
886
937
  * runs before it sends anything, for every page and setting at once, against
887
938
  * what the manifests recorded at the pull — no credential and no request.
888
939
  */
889
- async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgress, { config, directoryArgument = false, loadLogoEngines }) {
940
+ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgress, { config, directoryArgument = false, ...reporting }) {
890
941
  onProgress(`Reading ${MANIFEST_FILE_NAME}.`);
891
942
  const manifest = await readManifest(workspaceDir, siteId);
892
943
  const mediaManifest = await readMediaManifest(workspaceDir, siteId);
@@ -898,7 +949,8 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
898
949
  content: invocation.content,
899
950
  onProgress,
900
951
  });
901
- reportThemeWarnings(checked.presentation, onProgress);
952
+ const options = { ...reporting, nameReportEnabled: selectNameReportEligibility({ manifest }) };
953
+ await completeValidationWarnings(checked, { manifest, mediaManifest, valid: checked.problems.length === 0 }, options, onProgress);
902
954
  refuseProblems(checked.problems, "validate found problems in the workspace");
903
955
 
904
956
  // Only --site reads the site; without it the image rule is skipped with the reason (TR01371).
@@ -915,7 +967,7 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
915
967
  ...descriptionWarnings(checked.pages.planned, onProgress),
916
968
  ...authorWarnings(checked.pages.planned, onProgress),
917
969
  }),
918
- ...await offlineSiteChecks(checked, manifest, onProgress, site.imageCheck, workspaceDir, loadLogoEngines),
970
+ ...await offlineSiteChecks(checked, manifest, mediaManifest, onProgress, site.imageCheck, options),
919
971
  };
920
972
  // The Docs settings checks do not own the skipped image reason reported by --site.
921
973
  const docsReason = checked.settingsOnly && invocation.fromSite === true
@@ -961,6 +1013,7 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
961
1013
  doesNotProve: [
962
1014
  "credential authorization or live site ownership",
963
1015
  "pages, revisions, or videos that changed on the site since the pull",
1016
+ checked.settingsOnly ? DOCS_CHROME_NOT_PROVEN : CHROME_OFFLINE_PAGE_LIMITATION,
964
1017
  "server normalization and pull round trips",
965
1018
  SITE_CHECKS_NOT_PROVEN,
966
1019
  "preview or published rendering",
@@ -79,7 +79,8 @@ export async function checkWorkspace({
79
79
  ? undefined
80
80
  : await collectProblems(problems, { area: CHECK_AREA.footer, file: FOOTER_SETTINGS_FILE }, async () =>
81
81
  validateFooterWorkspaceDocument(
82
- await readWorkspaceJson(workspaceDir, FOOTER_SETTINGS_FILE, WORKSPACE_LIMITS.settingsBytes),
82
+ presentation?.publishingDocument
83
+ ?? await readWorkspaceJson(workspaceDir, FOOTER_SETTINGS_FILE, WORKSPACE_LIMITS.settingsBytes),
83
84
  siteId,
84
85
  {
85
86
  expectedEntityId: binding.settingsEntityIds?.get(SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES),