@taprootio/site-authoring 0.41.1 → 0.55.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.
Files changed (78) hide show
  1. package/README.md +50 -0
  2. package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
  3. package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
  4. package/package.json +4 -3
  5. package/src/api.js +170 -11
  6. package/src/appearance-contract.js +278 -8
  7. package/src/authored-tag-names.js +88 -0
  8. package/src/block-flow.js +103 -1
  9. package/src/brand-color.js +39 -4
  10. package/src/breadcrumb-artwork.js +234 -0
  11. package/src/breadcrumb-separators.js +11 -0
  12. package/src/changelog.json +154 -0
  13. package/src/chrome-features.js +152 -0
  14. package/src/chrome-input.js +147 -0
  15. package/src/chrome-output.js +92 -0
  16. package/src/chrome-paint-catalog-taproot.json +52 -0
  17. package/src/chrome-report.js +173 -0
  18. package/src/cli.js +48 -17
  19. package/src/content/components.js +27 -4
  20. package/src/content/external-link.js +2 -1
  21. package/src/content/markdown.js +271 -101
  22. package/src/content/tiptap-prosemirror.ts +125 -43
  23. package/src/content/validate-document.js +4 -1
  24. package/src/content-inset.js +48 -0
  25. package/src/errors.js +1 -0
  26. package/src/espalier-shared.js +26 -0
  27. package/src/field-suggestions.js +40 -0
  28. package/src/fixture-init.js +22 -5
  29. package/src/font-catalog.js +11 -1
  30. package/src/footer-brand-inputs.js +25 -2
  31. package/src/footer-content.js +38 -0
  32. package/src/footer-contract.js +11 -0
  33. package/src/footer-cta-styles.js +6 -0
  34. package/src/footer-draft-hash.js +4 -2
  35. package/src/footer-fit.js +62 -15
  36. package/src/footer-workspace.js +60 -16
  37. package/src/header-presentation.js +16 -0
  38. package/src/latest-posts-tags.js +57 -0
  39. package/src/page-structure-checks.js +5 -0
  40. package/src/page-tag-badge-modes.js +6 -0
  41. package/src/page-tag-writes.js +158 -0
  42. package/src/page-type-tags.js +16 -0
  43. package/src/presentation-reference.js +312 -86
  44. package/src/recipe-page-options.js +22 -0
  45. package/src/recipe-step-contract.js +164 -0
  46. package/src/recipe-step-contract.json +65 -0
  47. package/src/reference-help.js +164 -78
  48. package/src/session.js +39 -24
  49. package/src/setting-reference.js +239 -48
  50. package/src/settings-catalog.js +63 -0
  51. package/src/site-check-findings.js +25 -5
  52. package/src/site-check-rules.json +3 -1
  53. package/src/site-health-findings.js +13 -13
  54. package/src/site-navigation-groups.js +70 -0
  55. package/src/styling-fixed-values.js +71 -0
  56. package/src/tag-destination-warnings.js +35 -0
  57. package/src/template-token-reach.json +242 -0
  58. package/src/theme-proposals.js +18 -27
  59. package/src/theme-resolve.js +305 -51
  60. package/src/theme-validation.js +126 -6
  61. package/src/token-reach.js +222 -0
  62. package/src/typed-page-reference.js +72 -15
  63. package/src/typed-pages.js +171 -71
  64. package/src/verbs/deploy.js +6 -0
  65. package/src/verbs/footer-push.js +30 -5
  66. package/src/verbs/forms-push.js +11 -3
  67. package/src/verbs/pages-delete.js +19 -10
  68. package/src/verbs/pages-push.js +125 -36
  69. package/src/verbs/plan.js +10 -4
  70. package/src/verbs/pull.js +277 -67
  71. package/src/verbs/staging-review.js +27 -1
  72. package/src/verbs/status.js +22 -0
  73. package/src/verbs/theme-push.js +249 -120
  74. package/src/verbs/theme-resolve.js +310 -47
  75. package/src/verbs/validate.js +71 -17
  76. package/src/workspace-check.js +37 -4
  77. package/src/workspace.js +37 -1
  78. package/test/fixtures/default-site-theme.json +516 -0
@@ -4,32 +4,44 @@ import {
4
4
  APPEARANCE_SCALAR_FIELDS,
5
5
  appearanceScalarInput,
6
6
  buildAppearanceScalarOperations,
7
+ refuseRetiredScalarFonts,
8
+ checkTagDestinationTargets,
9
+ normalizeTagDestinations,
10
+ readBreadcrumbArtworkSettings,
11
+ tagDestinationCatalogSlugs,
7
12
  footerPresentationOverlay,
8
13
  } from "../appearance-contract.js";
14
+ import { captureChromeResources, selectNameReportEligibility } from "../chrome-input.js";
15
+ import { completeChromeReport } from "../chrome-report.js";
9
16
  import { REFUSAL_UNCLASSIFIED, VERB_THEME_PUSH } from "../constants.js";
10
17
  import { MISSING_SETTING_MESSAGE, SiteAuthoringError } from "../errors.js";
11
- import { projectFooterSettingsForWorkspace } from "../footer-contract.js";
18
+ import { projectFooterSettingsForWorkspace, validateFooterDocument } from "../footer-contract.js";
12
19
  import {
13
20
  advanceFooterManifest,
14
21
  clearPendingPresentationSave,
22
+ compareFooterContent,
15
23
  computePresentationChangeSetHash,
24
+ hasFooterContentEdits,
16
25
  readAppearanceWorkspaceContext,
17
26
  readPendingPresentationSave,
18
27
  readPresentationBaseline,
19
28
  recordPendingPresentationSave,
29
+ reportFooterPreview,
20
30
  requireFooterContentPushed,
21
31
  } from "../footer-workspace.js";
22
32
  import { describeJsonDifferences } from "../json-path-diff.js";
23
- import { boundedList, openSession, successResult, warnIfExternalWritesPaused } from "../session.js";
33
+ import { boundedList, resolveSiteSession, successResult, warnIfExternalWritesPaused } from "../session.js";
24
34
  import {
25
35
  projectSettingsGroup,
36
+ requireKnownAppearanceSettings,
26
37
  SETTINGS_GROUPS,
27
38
  SETTINGS_TYPE_BRAND,
28
39
  SETTINGS_TYPE_SITE_HEADER,
29
40
  SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
30
41
  SETTINGS_TYPE_TAPROOT_STYLES,
31
42
  } from "../settings-catalog.js";
32
- import { missingThemeFields, requireSurfaceContexts, validateAndLintThemePair } from "../theme-validation.js";
43
+ import { missingThemeFields, requireSurfaceContexts, validateAndLintThemePair, withChromeWarnings } from "../theme-validation.js";
44
+ import { missingTagDestinations, reportTagDestinationWarnings } from "../tag-destination-warnings.js";
33
45
  import { ApiError } from "../transport.js";
34
46
  import {
35
47
  readWorkspaceJson,
@@ -62,7 +74,7 @@ function fail(code, message, field) {
62
74
  throw new SiteAuthoringError(code, message, { field });
63
75
  }
64
76
 
65
- export async function readSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId = siteId) {
77
+ export async function readBoundSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId = siteId) {
66
78
  const file = `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[settingsType]}`;
67
79
  if (!await workspaceFileExists(workspaceDir, file)) {
68
80
  fail("theme.settings_missing", `Workspace file '${file}' is missing. Run 'taproot-site pull' first.`, file);
@@ -80,7 +92,14 @@ export async function readSettingsDocument(workspaceDir, siteId, settingsType, e
80
92
  file,
81
93
  );
82
94
  }
83
- return document.settings;
95
+ return document;
96
+ }
97
+
98
+ export async function readSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId) {
99
+ const { settings } = await readBoundSettingsDocument(workspaceDir, siteId, settingsType, expectedEntityId);
100
+ return settingsType === SETTINGS_TYPE_TAPROOT_STYLES
101
+ ? readBreadcrumbArtworkSettings(workspaceDir, settings)
102
+ : settings;
84
103
  }
85
104
 
86
105
  /** The theme paths the styles document lacks, both schemes, in the order theme push reports them. */
@@ -117,9 +136,9 @@ export async function validateThemeWorkspace(
117
136
  siteId,
118
137
  knownImageIds,
119
138
  expectedEntityIds,
120
- { deferContextValidation = false } = {},
139
+ { deferContextValidation = false, fixtureExport = false } = {},
121
140
  ) {
122
- const [style, brand, header, publishing] = await Promise.all([
141
+ const [style, brand, header, publishingDocument] = await Promise.all([
123
142
  readSettingsDocument(
124
143
  workspaceDir,
125
144
  siteId,
@@ -138,18 +157,28 @@ export async function validateThemeWorkspace(
138
157
  SETTINGS_TYPE_SITE_HEADER,
139
158
  expectedEntityIds?.get(SETTINGS_TYPE_SITE_HEADER),
140
159
  ),
141
- readSettingsDocument(
160
+ readBoundSettingsDocument(
142
161
  workspaceDir,
143
162
  siteId,
144
163
  SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
145
164
  expectedEntityIds?.get(SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES),
146
165
  ),
147
166
  ]);
167
+ const { settings: publishing } = publishingDocument;
168
+ for (const name of ["tagDestinations", "recipeMetadataDestinations"]) {
169
+ if (Object.hasOwn(publishing, name)) {
170
+ publishing[name] = normalizeTagDestinations(publishing[name], `site-publishing-preferences.${name}`);
171
+ }
172
+ }
148
173
  const documents = {
149
174
  [SETTINGS_TYPE_TAPROOT_STYLES]: style,
150
175
  [SETTINGS_TYPE_BRAND]: brand,
151
176
  [SETTINGS_TYPE_SITE_HEADER]: header,
177
+ [SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]: publishing,
152
178
  };
179
+ refuseRetiredScalarFonts(style);
180
+ // Fixture export validates again after projecting the source onto the settings catalog.
181
+ if (!fixtureExport) requireKnownAppearanceSettings(documents);
153
182
  // Preflight the complete required-key inventory before any value validator
154
183
  // can stop at a malformed value in an earlier group. Optional presentation
155
184
  // fields retain their empty default.
@@ -181,7 +210,7 @@ export async function validateThemeWorkspace(
181
210
  documents,
182
211
  knownImageIds,
183
212
  );
184
- return { style, brand, header, publishing, themes, scalarOperations, footerPresentation };
213
+ return { style, brand, header, publishing, publishingDocument, themes, scalarOperations, footerPresentation };
185
214
  }
186
215
 
187
216
  /**
@@ -248,11 +277,7 @@ function translateSaveRefusal(error) {
248
277
  * file, and the site's copy projected the way `pull` writes it — so the paths
249
278
  * reported are paths in the files an author edits.
250
279
  */
251
- function ownedDocuments(validated, presentation) {
252
- const projected = {};
253
- for (const group of SETTINGS_GROUPS) {
254
- projected[group.settingsType] = projectSettingsGroup(group, presentation);
255
- }
280
+ function ownedDocuments(validated, projected) {
256
281
  const fieldDefinitions = new Map(
257
282
  APPEARANCE_SCALAR_FIELDS.map(field => [`${field.settingsType}:${field.name}`, field]),
258
283
  );
@@ -266,10 +291,12 @@ function ownedDocuments(validated, presentation) {
266
291
  remote: Object.fromEntries(names.map((name) => [name, valueOf(settingsType, remote, name)])),
267
292
  });
268
293
  const scalarNames = (settingsType) =>
269
- APPEARANCE_SCALAR_FIELDS.filter((field) => field.settingsType === settingsType).map((field) => field.name);
270
- const footerPresentation = footer => ({
294
+ APPEARANCE_SCALAR_FIELDS.filter((field) => field.settingsType === settingsType
295
+ && (!field.onlyIfPresent || Object.hasOwn(validated.publishing, field.name))).map((field) => field.name);
296
+ const publishingDocument = document => ({
297
+ ...document,
271
298
  footerSettings: Object.fromEntries(
272
- APPEARANCE_FOOTER_FIELDS.map(field => [field.name, footer?.[field.name] ?? field.default]),
299
+ APPEARANCE_FOOTER_FIELDS.map(field => [field.name, document.footerSettings?.[field.name] ?? field.default]),
273
300
  ),
274
301
  });
275
302
  return [
@@ -286,17 +313,18 @@ function ownedDocuments(validated, presentation) {
286
313
  projected[SETTINGS_TYPE_SITE_HEADER],
287
314
  scalarNames(SETTINGS_TYPE_SITE_HEADER),
288
315
  ),
289
- {
290
- file: `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]}`,
291
- local: footerPresentation(validated.publishing.footerSettings),
292
- remote: footerPresentation(projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].footerSettings),
293
- },
316
+ owned(
317
+ SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
318
+ publishingDocument(validated.publishing),
319
+ publishingDocument(projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]),
320
+ [...scalarNames(SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES), "footerSettings"],
321
+ ),
294
322
  ];
295
323
  }
296
324
 
297
325
  /** The JSON paths at which each settings file differs from the site, remote first. */
298
- function describeDifferences(validated, presentation) {
299
- return ownedDocuments(validated, presentation).map((document_) => {
326
+ function describeDifferences(validated, projected) {
327
+ return ownedDocuments(validated, projected).map((document_) => {
300
328
  const differences = describeJsonDifferences(document_.remote, document_.local);
301
329
  return {
302
330
  file: document_.file,
@@ -363,10 +391,33 @@ export async function comparePresentation(client, siteId, validated, manifest) {
363
391
  const changeSetHash = computePresentationChangeSetHash(changeSet);
364
392
  const pending = readPendingPresentationSave(manifest);
365
393
  const replayable = pending !== undefined && pending.changeSetHash === changeSetHash;
366
- const differences = describeDifferences(validated, current);
394
+ const projected = Object.fromEntries(SETTINGS_GROUPS.map((group) => [
395
+ group.settingsType, projectSettingsGroup(group, current),
396
+ ]));
397
+ if (validated.publishing.tagDestinations !== undefined) {
398
+ checkTagDestinationTargets(
399
+ validated.publishing.tagDestinations,
400
+ projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].tagDestinations,
401
+ manifest,
402
+ undefined,
403
+ tagDestinationCatalogSlugs(current.tagDestinationCatalog),
404
+ );
405
+ }
406
+ if (validated.publishing.recipeMetadataDestinations !== undefined) {
407
+ checkTagDestinationTargets(
408
+ validated.publishing.recipeMetadataDestinations,
409
+ projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].recipeMetadataDestinations,
410
+ manifest,
411
+ undefined,
412
+ undefined,
413
+ true,
414
+ );
415
+ }
416
+ const differences = describeDifferences(validated, projected);
367
417
  return {
368
418
  baseline,
369
419
  current,
420
+ currentFooter: projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].footerSettings,
370
421
  stale,
371
422
  changeSet,
372
423
  changeSetHash,
@@ -378,32 +429,7 @@ export async function comparePresentation(client, siteId, validated, manifest) {
378
429
  };
379
430
  }
380
431
 
381
- export async function themePush(invocation) {
382
- const session = await openSession(invocation);
383
- const { client, config, siteId, onProgress } = session;
384
- const dryRun = invocation.dryRun === true;
385
- // One advisory line before this verb does any work, and only when the
386
- // exchange said the platform is paused. It changes nothing else: the write
387
- // still runs and its refusal still classifies as platform_paused (TR00692).
388
- if (!dryRun) warnIfExternalWritesPaused(session, VERB_THEME_PUSH);
389
- const appearanceContext = await readAppearanceWorkspaceContext(config.workspaceDir, siteId);
390
- const validated = await validateThemeWorkspace(
391
- config.workspaceDir,
392
- siteId,
393
- appearanceContext.knownImageIds,
394
- undefined,
395
- { deferContextValidation: true },
396
- );
397
- const { publishing, themes, scalarOperations } = validated;
398
- // The save's response replaces the workspace footer document, so refuse
399
- // while it still carries footer-content edits that footer push has not
400
- // saved. Context-only differences are theme push's own to write.
401
- requireFooterContentPushed(appearanceContext.footer, publishing.footerSettings);
402
- const baseline = readPresentationBaseline(appearanceContext.manifest);
403
- if (!dryRun && baseline === undefined) {
404
- throw presentationPullRequired();
405
- }
406
- onProgress(`Validated the complete light/dark theme pair and ${scalarOperations.length} appearance settings.`);
432
+ function reportPushWarnings(themes, onProgress) {
407
433
  for (const warning of themes.warnings) onProgress(`Espalier warning: ${warning}`);
408
434
  if (themes.warningsTruncated) {
409
435
  const hidden = themes.warningCount - themes.warnings.length;
@@ -411,77 +437,27 @@ export async function themePush(invocation) {
411
437
  `${hidden} more Espalier warning(s) not shown; resolve the ones above and run theme push --dry-run to see them.`,
412
438
  );
413
439
  }
414
- const warnings = {
440
+ return {
415
441
  items: themes.warnings,
416
442
  count: themes.warningCount,
417
443
  ...(themes.warningsTruncated ? { truncated: true } : {}),
418
444
  };
445
+ }
419
446
 
420
- // The fresh read serves both modes: the dry run compares against it, and
421
- // the push checks the complete post-save context state. Nothing before
422
- // this point, and nothing in a dry run after it, writes to the site.
423
- const comparison = await withRefusalGuidance(
424
- onProgress,
425
- "theme push",
426
- async () => await comparePresentation(client, siteId, validated, appearanceContext.manifest),
427
- );
428
- const { current, stale, changeSet, changeSetHash, pending, replayable, replaying, differences, changed } = comparison;
429
-
430
- if (dryRun) {
431
- for (const entry of differences) {
432
- if (entry.paths.length === 0 && entry.truncated !== true) continue;
433
- onProgress(`${entry.file} differs at: ${entry.paths.join(", ")}${entry.truncated ? ", and more" : ""}.`);
434
- }
435
- if (!changed) onProgress("The workspace's presentation matches the site; a push would change nothing.");
436
- if (baseline === undefined) {
437
- onProgress(
438
- "The pull manifest records no presentation baseline; a push would refuse until the workspace is re-pulled.",
439
- );
440
- } else if (replaying) {
441
- onProgress(
442
- `The site's presentation revision moved since this workspace was pulled (${baseline.revision} → `
443
- + `${current.revision}), and the manifest records a save of this same change set whose response was `
444
- + "lost; a push would replay it under its original baseline rather than refuse.",
445
- );
446
- } else if (stale) {
447
- onProgress(
448
- `The site's presentation revision moved since this workspace was pulled (${baseline.revision} → `
449
- + `${current.revision}); a push would be refused. Keep copies of the edited files, pull, and re-apply.`,
450
- );
451
- }
452
- onProgress("Dry run: nothing was written.");
453
- return successResult(VERB_THEME_PUSH, siteId, {
454
- dryRun: true,
455
- revision: {
456
- ...(baseline === undefined ? {} : { baseline: baseline.revision }),
457
- current: current.revision,
458
- stale: baseline === undefined ? undefined : stale,
459
- },
460
- ...(pending === undefined ? {} : {
461
- pendingSave: {
462
- ...(pending.startedAt === undefined ? {} : { startedAt: pending.startedAt }),
463
- sameChangeSet: replayable,
464
- },
465
- }),
466
- changed,
467
- differences,
468
- warnings,
469
- });
470
- }
471
-
472
- if (stale && !replaying) {
473
- // Refused here, before any request that could write, with the same
474
- // guidance the server's fence would give — and with the paths that
475
- // differ, which the server cannot know.
476
- if (pending !== undefined) {
477
- onProgress(
478
- "The manifest records an earlier save of a different change set whose response was lost; the site may hold "
479
- + "it. The pull that refreshes the baseline shows what the site holds now.",
480
- );
481
- }
482
- throw presentationMovedRefusal(comparison);
483
- }
447
+ async function completePushWarnings(appearance, resources, evidence, onProgress, chromeDependencies) {
448
+ const { themes } = appearance;
449
+ const { warnings } = await completeChromeReport({
450
+ themes,
451
+ appearance,
452
+ resources,
453
+ nameReportEnabled: selectNameReportEligibility(evidence),
454
+ }, chromeDependencies);
455
+ return reportPushWarnings(withChromeWarnings(themes, warnings), onProgress);
456
+ }
484
457
 
458
+ async function saveComparedPresentation(session, comparison) {
459
+ const { client, config, siteId, onProgress } = session;
460
+ const { baseline, changeSet, changeSetHash, pending, replaying } = comparison;
485
461
  const expectedRevision = replaying ? pending.expectedRevision : baseline.revision;
486
462
  if (replaying) {
487
463
  onProgress(
@@ -535,8 +511,10 @@ export async function themePush(invocation) {
535
511
  }
536
512
  throw translateSaveRefusal(error);
537
513
  }
514
+ return saved;
515
+ }
538
516
 
539
- const { presentation, applied } = saved;
517
+ async function adoptSavedFooter(workspaceDir, siteId, presentation, publishing) {
540
518
  const savedFooter = presentation.sitePublishingPreferences?.footerSettings;
541
519
  if (!isPlainObject(savedFooter)) {
542
520
  throw new SiteAuthoringError(
@@ -551,18 +529,169 @@ export async function themePush(invocation) {
551
529
  // a failure here leaves a stale baseline that refuses the next push rather
552
530
  // than one that overwrites the save.
553
531
  const projectedFooter = projectFooterSettingsForWorkspace(savedFooter);
532
+ const { tagDestinations, recipeMetadataDestinations } = presentation.sitePublishingPreferences ?? {};
533
+ const settings = { ...publishing, footerSettings: projectedFooter };
534
+ for (const [name, destinations] of Object.entries({ tagDestinations, recipeMetadataDestinations })) {
535
+ if (destinations !== undefined || settings[name] !== undefined) settings[name] = destinations ?? {};
536
+ }
554
537
  await writeWorkspaceJson(
555
- config.workspaceDir,
538
+ workspaceDir,
556
539
  `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]}`,
557
540
  {
558
541
  entityId: siteId,
559
542
  settingsType: SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
560
- settings: { ...publishing, footerSettings: projectedFooter },
543
+ settings,
561
544
  },
562
545
  );
563
- await advanceFooterManifest(config.workspaceDir, siteId, projectedFooter, undefined, {
546
+ await advanceFooterManifest(workspaceDir, siteId, projectedFooter, undefined, {
564
547
  presentationRevision: presentation.revision,
548
+ tagDestinations,
549
+ recipeMetadataDestinations,
550
+ authoredTagSlugs: tagDestinationCatalogSlugs(presentation.tagDestinationCatalog),
551
+ });
552
+ return projectedFooter;
553
+ }
554
+
555
+ export async function themePush(invocation, chromeDependencies) {
556
+ const resolved = await resolveSiteSession(invocation);
557
+ const { config, siteId } = resolved;
558
+ const dryRun = invocation.dryRun === true;
559
+ const appearanceContext = await readAppearanceWorkspaceContext(config.workspaceDir, siteId);
560
+ const validated = await validateThemeWorkspace(
561
+ config.workspaceDir,
562
+ siteId,
563
+ appearanceContext.knownImageIds,
564
+ undefined,
565
+ { deferContextValidation: true },
566
+ );
567
+ const { publishing, scalarOperations } = validated;
568
+ // The save's response replaces the workspace footer document, so refuse
569
+ // while it still carries footer-content edits that footer push has not
570
+ // saved. Context-only differences are theme push's own to write.
571
+ if (!dryRun) requireFooterContentPushed(appearanceContext.footer, publishing.footerSettings);
572
+ const proposedFooter = dryRun && hasFooterContentEdits(appearanceContext.footer, publishing.footerSettings)
573
+ ? validateFooterDocument(publishing.footerSettings, appearanceContext)
574
+ : undefined;
575
+ const baseline = readPresentationBaseline(appearanceContext.manifest);
576
+ if (!dryRun && baseline === undefined) {
577
+ throw presentationPullRequired();
578
+ }
579
+ const session = await resolved.open();
580
+ const { client, onProgress } = session;
581
+ if (!dryRun) warnIfExternalWritesPaused(session, VERB_THEME_PUSH);
582
+ onProgress(`Validated the complete light/dark theme pair and ${scalarOperations.length} appearance settings.`);
583
+ let comparison;
584
+ let resources;
585
+ let saved;
586
+ try {
587
+ // Both modes check the complete proposed context state against the site.
588
+ comparison = await withRefusalGuidance(
589
+ onProgress,
590
+ "theme push",
591
+ async () => await comparePresentation(client, siteId, validated, appearanceContext.manifest),
592
+ );
593
+ if (!dryRun && comparison.stale && !comparison.replaying) {
594
+ // Report the paths that differ before sending a request that could write.
595
+ if (comparison.pending !== undefined) {
596
+ onProgress(
597
+ "The manifest records an earlier save of a different change set whose response was lost; the site may hold "
598
+ + "it. The pull that refreshes the baseline shows what the site holds now.",
599
+ );
600
+ }
601
+ throw presentationMovedRefusal(comparison);
602
+ }
603
+
604
+ // Keep the optional snapshot on this side of the save. Report completion
605
+ // never reads settings or manifests after the response has arrived.
606
+ resources = await captureChromeResources({ ...appearanceContext, siteId, workspaceDir: config.workspaceDir });
607
+ if (!dryRun) saved = await saveComparedPresentation(session, comparison);
608
+ } catch (error) {
609
+ reportPushWarnings(validated.themes, onProgress);
610
+ throw error;
611
+ }
612
+ const { current, stale, pending, replayable, replaying, differences, changed } = comparison;
613
+ const { manifest } = appearanceContext;
614
+
615
+ if (dryRun) {
616
+ const proposedPublishing = { ...current.sitePublishingPreferences, ...publishing };
617
+ const tagDestinationWarnings = reportTagDestinationWarnings(missingTagDestinations(proposedPublishing, manifest), onProgress);
618
+ const footerContent = proposedFooter === undefined
619
+ ? undefined
620
+ : compareFooterContent(appearanceContext.footer, comparison.currentFooter, proposedFooter);
621
+ const warnings = await completePushWarnings(
622
+ validated,
623
+ {
624
+ ...resources,
625
+ footerSettings: proposedFooter ?? comparison.currentFooter,
626
+ presentation: current,
627
+ badgeSettings: proposedPublishing,
628
+ },
629
+ { current, manifest },
630
+ onProgress,
631
+ chromeDependencies,
632
+ );
633
+ for (const entry of differences) {
634
+ if (entry.paths.length === 0 && entry.truncated !== true) continue;
635
+ onProgress(`${entry.file} differs at: ${entry.paths.join(", ")}${entry.truncated ? ", and more" : ""}.`);
636
+ }
637
+ if (footerContent !== undefined) {
638
+ reportFooterPreview(footerContent, onProgress);
639
+ onProgress("Run footer push to save footer content before a live theme push.");
640
+ }
641
+ if (!changed) onProgress("The workspace's presentation matches the site; a theme push would change nothing.");
642
+ if (baseline === undefined) {
643
+ onProgress(
644
+ "The pull manifest records no presentation baseline; a push would refuse until the workspace is re-pulled.",
645
+ );
646
+ } else if (replaying) {
647
+ onProgress(
648
+ `The site's presentation revision moved since this workspace was pulled (${baseline.revision} → `
649
+ + `${current.revision}), and the manifest records a save of this same change set whose response was `
650
+ + "lost; a push would replay it under its original baseline rather than refuse.",
651
+ );
652
+ } else if (stale) {
653
+ onProgress(
654
+ `The site's presentation revision moved since this workspace was pulled (${baseline.revision} → `
655
+ + `${current.revision}); a push would be refused. Keep copies of the edited files, pull, and re-apply.`,
656
+ );
657
+ }
658
+ onProgress("Dry run: nothing was written.");
659
+ return successResult(VERB_THEME_PUSH, siteId, {
660
+ dryRun: true,
661
+ revision: {
662
+ ...(baseline === undefined ? {} : { baseline: baseline.revision }),
663
+ current: current.revision,
664
+ stale: baseline === undefined ? undefined : stale,
665
+ },
666
+ ...(pending === undefined ? {} : {
667
+ pendingSave: {
668
+ ...(pending.startedAt === undefined ? {} : { startedAt: pending.startedAt }),
669
+ sameChangeSet: replayable,
670
+ },
671
+ }),
672
+ changed,
673
+ differences,
674
+ ...(footerContent === undefined ? {} : { footerContent }),
675
+ ...(tagDestinationWarnings === undefined ? {} : { tagDestinationWarnings }),
676
+ warnings,
677
+ });
678
+ }
679
+
680
+ const { presentation, applied } = saved;
681
+ const projectedFooter = await adoptSavedFooter(config.workspaceDir, siteId, presentation, publishing).catch((error) => {
682
+ reportPushWarnings(validated.themes, onProgress);
683
+ throw error;
565
684
  });
685
+ const warnings = await completePushWarnings(
686
+ {
687
+ ...validated,
688
+ footerPresentation: { context: projectedFooter.context, logoVariant: projectedFooter.logoVariant },
689
+ },
690
+ { ...resources, footerSettings: projectedFooter, presentation },
691
+ { saved, current, manifest },
692
+ onProgress,
693
+ chromeDependencies,
694
+ );
566
695
  onProgress(
567
696
  applied
568
697
  ? "Saved the complete presentation in one transaction: surface contexts and logo choices, appearance settings, and both "